Mercurial > hg > svcore
comparison data/model/Dense3DModelPeakCache.h @ 1766:85b9b466a59f
Merge from branch by-id
author | Chris Cannam |
---|---|
date | Wed, 17 Jul 2019 14:24:51 +0100 |
parents | 6d09d68165a4 |
children | 59d9dcfd67c2 |
comparison
equal
deleted
inserted
replaced
1730:649ac57c5a2d | 1766:85b9b466a59f |
---|---|
22 class Dense3DModelPeakCache : public DenseThreeDimensionalModel | 22 class Dense3DModelPeakCache : public DenseThreeDimensionalModel |
23 { | 23 { |
24 Q_OBJECT | 24 Q_OBJECT |
25 | 25 |
26 public: | 26 public: |
27 Dense3DModelPeakCache(const DenseThreeDimensionalModel *source, | 27 Dense3DModelPeakCache(ModelId source, // a DenseThreeDimensionalModel |
28 int columnsPerPeak); | 28 int columnsPerPeak); |
29 ~Dense3DModelPeakCache(); | 29 ~Dense3DModelPeakCache(); |
30 | 30 |
31 bool isOK() const override { | 31 bool isOK() const override { |
32 return m_source && m_source->isOK(); | 32 auto source = ModelById::get(m_source); |
33 return source && source->isOK(); | |
33 } | 34 } |
34 | 35 |
35 sv_samplerate_t getSampleRate() const override { | 36 sv_samplerate_t getSampleRate() const override { |
36 return m_source->getSampleRate(); | 37 auto source = ModelById::get(m_source); |
38 return source ? source->getSampleRate() : 0; | |
37 } | 39 } |
38 | 40 |
39 sv_frame_t getStartFrame() const override { | 41 sv_frame_t getStartFrame() const override { |
40 return m_source->getStartFrame(); | 42 auto source = ModelById::get(m_source); |
43 return source ? source->getStartFrame() : 0; | |
41 } | 44 } |
42 | 45 |
43 sv_frame_t getTrueEndFrame() const override { | 46 sv_frame_t getTrueEndFrame() const override { |
44 return m_source->getTrueEndFrame(); | 47 auto source = ModelById::get(m_source); |
48 return source ? source->getTrueEndFrame() : 0; | |
45 } | 49 } |
46 | 50 |
47 int getResolution() const override { | 51 int getResolution() const override { |
48 return m_source->getResolution() * m_columnsPerPeak; | 52 auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source); |
53 return source ? source->getResolution() * m_columnsPerPeak : 1; | |
49 } | 54 } |
50 | 55 |
51 virtual int getColumnsPerPeak() const { | 56 virtual int getColumnsPerPeak() const { |
52 return m_columnsPerPeak; | 57 return m_columnsPerPeak; |
53 } | 58 } |
54 | 59 |
55 int getWidth() const override { | 60 int getWidth() const override { |
56 int sourceWidth = m_source->getWidth(); | 61 auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source); |
62 if (!source) return 0; | |
63 int sourceWidth = source->getWidth(); | |
57 if ((sourceWidth % m_columnsPerPeak) == 0) { | 64 if ((sourceWidth % m_columnsPerPeak) == 0) { |
58 return sourceWidth / m_columnsPerPeak; | 65 return sourceWidth / m_columnsPerPeak; |
59 } else { | 66 } else { |
60 return sourceWidth / m_columnsPerPeak + 1; | 67 return sourceWidth / m_columnsPerPeak + 1; |
61 } | 68 } |
62 } | 69 } |
63 | 70 |
64 int getHeight() const override { | 71 int getHeight() const override { |
65 return m_source->getHeight(); | 72 auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source); |
73 return source ? source->getHeight() : 0; | |
66 } | 74 } |
67 | 75 |
68 float getMinimumLevel() const override { | 76 float getMinimumLevel() const override { |
69 return m_source->getMinimumLevel(); | 77 auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source); |
78 return source ? source->getMinimumLevel() : 0.f; | |
70 } | 79 } |
71 | 80 |
72 float getMaximumLevel() const override { | 81 float getMaximumLevel() const override { |
73 return m_source->getMaximumLevel(); | 82 auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source); |
83 return source ? source->getMaximumLevel() : 1.f; | |
74 } | 84 } |
75 | 85 |
76 /** | 86 /** |
77 * Retrieve the peaks column at peak-cache column number col. This | 87 * Retrieve the peaks column at peak-cache column number col. This |
78 * will consist of the peak values in the underlying model from | 88 * will consist of the peak values in the underlying model from |
82 Column getColumn(int col) const override; | 92 Column getColumn(int col) const override; |
83 | 93 |
84 float getValueAt(int col, int n) const override; | 94 float getValueAt(int col, int n) const override; |
85 | 95 |
86 QString getBinName(int n) const override { | 96 QString getBinName(int n) const override { |
87 return m_source->getBinName(n); | 97 auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source); |
98 return source ? source->getBinName(n) : ""; | |
88 } | 99 } |
89 | 100 |
90 bool shouldUseLogValueScale() const override { | 101 bool shouldUseLogValueScale() const override { |
91 return m_source->shouldUseLogValueScale(); | 102 auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source); |
103 return source ? source->shouldUseLogValueScale() : false; | |
92 } | 104 } |
93 | 105 |
94 QString getTypeName() const override { return tr("Dense 3-D Peak Cache"); } | 106 QString getTypeName() const override { return tr("Dense 3-D Peak Cache"); } |
95 | 107 |
96 int getCompletion() const override { | 108 int getCompletion() const override { |
97 return m_source->getCompletion(); | 109 auto source = ModelById::get(m_source); |
110 return source ? source->getCompletion() : 100; | |
98 } | 111 } |
99 | 112 |
100 QString toDelimitedDataString(QString, DataExportOptions, | 113 QString toDelimitedDataString(QString, DataExportOptions, |
101 sv_frame_t, sv_frame_t) const override { | 114 sv_frame_t, sv_frame_t) const override { |
102 return ""; | 115 return ""; |
103 } | 116 } |
104 | 117 |
105 protected slots: | 118 protected slots: |
106 void sourceModelChanged(); | 119 void sourceModelChanged(ModelId); |
107 void sourceModelAboutToBeDeleted(); | |
108 | 120 |
109 private: | 121 private: |
110 const DenseThreeDimensionalModel *m_source; | 122 ModelId m_source; |
111 mutable EditableDenseThreeDimensionalModel *m_cache; | 123 mutable std::unique_ptr<EditableDenseThreeDimensionalModel> m_cache; |
112 mutable std::vector<bool> m_coverage; // must be bool, for space efficiency | 124 mutable std::vector<bool> m_coverage; // must be bool, for space efficiency |
113 // (vector of bool uses 1-bit elements) | 125 // (vector of bool uses 1-bit elements) |
114 int m_columnsPerPeak; | 126 int m_columnsPerPeak; |
115 | 127 |
116 bool haveColumn(int column) const; | 128 bool haveColumn(int column) const; |