comparison layer/SpectrogramLayer.h @ 44:ad214997dddb

* Refactor Layer classes so as no longer to store a single View pointer; instead they need to be able to draw themselves on any View on demand. Layers with caches (e.g. spectrogram) will need to be further refactored so as to maintain a per-View cache * Begin refactoring MainWindow by pulling out the document stuff (set of layers, models etc) into a Document class. Not yet in use. This revision is fairly unstable.
author Chris Cannam
date Thu, 02 Mar 2006 16:58:49 +0000
parents 1bdf285c4eac
children 2e2ad8510e52
comparison
equal deleted inserted replaced
43:78515b1e29eb 44:ad214997dddb
41 Q_OBJECT 41 Q_OBJECT
42 42
43 public: 43 public:
44 enum Configuration { FullRangeDb, MelodicRange, MelodicPeaks }; 44 enum Configuration { FullRangeDb, MelodicRange, MelodicPeaks };
45 45
46 SpectrogramLayer(View *w, Configuration = FullRangeDb); 46 SpectrogramLayer(Configuration = FullRangeDb);
47 ~SpectrogramLayer(); 47 ~SpectrogramLayer();
48 48
49 virtual const ZoomConstraint *getZoomConstraint() const { return this; } 49 virtual const ZoomConstraint *getZoomConstraint() const { return this; }
50 virtual const Model *getModel() const { return m_model; } 50 virtual const Model *getModel() const { return m_model; }
51 virtual void paint(QPainter &paint, QRect rect) const; 51 virtual void paint(View *v, QPainter &paint, QRect rect) const;
52 52
53 virtual int getVerticalScaleWidth(QPainter &) const; 53 virtual int getVerticalScaleWidth(View *v, QPainter &) const;
54 virtual void paintVerticalScale(QPainter &paint, QRect rect) const; 54 virtual void paintVerticalScale(View *v, QPainter &paint, QRect rect) const;
55 55
56 virtual QString getFeatureDescription(QPoint &) const; 56 virtual QString getFeatureDescription(View *v, QPoint &) const;
57 57
58 virtual bool snapToFeatureFrame(int &frame, 58 virtual bool snapToFeatureFrame(View *v, int &frame,
59 size_t &resolution, 59 size_t &resolution,
60 SnapType snap) const; 60 SnapType snap) const;
61 61
62 void setModel(const DenseTimeValueModel *model); 62 void setModel(const DenseTimeValueModel *model);
63 63
167 return PositionTop; 167 return PositionTop;
168 } 168 }
169 169
170 virtual bool isLayerOpaque() const { return true; } 170 virtual bool isLayerOpaque() const { return true; }
171 171
172 float getYForFrequency(float frequency) const; 172 float getYForFrequency(View *v, float frequency) const;
173 float getFrequencyForY(int y) const; 173 float getFrequencyForY(View *v, int y) const;
174 174
175 virtual int getCompletion() const; 175 virtual int getCompletion() const;
176 176
177 virtual QString toXmlString(QString indent = "", 177 virtual QString toXmlString(QString indent = "",
178 QString extraAttributes = "") const; 178 QString extraAttributes = "") const;
179 179
180 void setProperties(const QXmlAttributes &attributes); 180 void setProperties(const QXmlAttributes &attributes);
181 181
182 virtual void setLayerDormant(bool dormant); 182 virtual void setLayerDormant(const bool dormant);
183 183
184 protected slots: 184 protected slots:
185 void cacheInvalid(); 185 void cacheInvalid();
186 void cacheInvalid(size_t startFrame, size_t endFrame); 186 void cacheInvalid(size_t startFrame, size_t endFrame);
187 187
241 float getMagnitudeAt(size_t x, size_t y) const { 241 float getMagnitudeAt(size_t x, size_t y) const {
242 return getNormalizedMagnitudeAt(x, y) * m_factor[x]; 242 return getNormalizedMagnitudeAt(x, y) * m_factor[x];
243 } 243 }
244 244
245 float getNormalizedMagnitudeAt(size_t x, size_t y) const { 245 float getNormalizedMagnitudeAt(size_t x, size_t y) const {
246 return float(m_magnitude[y][x]) / 65535.0; 246 return float(m_magnitude[x][y]) / 65535.0;
247 } 247 }
248 248
249 float getPhaseAt(size_t x, size_t y) const { 249 float getPhaseAt(size_t x, size_t y) const {
250 int16_t i = (int16_t)m_phase[y][x]; 250 int16_t i = (int16_t)m_phase[x][y];
251 return (float(i) / 32767.0) * M_PI; 251 return (float(i) / 32767.0) * M_PI;
252 } 252 }
253 253
254 bool isLocalPeak(size_t x, size_t y) const { 254 bool isLocalPeak(size_t x, size_t y) const {
255 if (y > 0 && m_magnitude[y][x] < m_magnitude[y-1][x]) return false; 255 if (y > 0 && m_magnitude[x][y] < m_magnitude[x][y-1]) return false;
256 if (y < m_height-1 && m_magnitude[y][x] < m_magnitude[y+1][x]) return false; 256 if (y < m_height-1 && m_magnitude[x][y] < m_magnitude[x][y+1]) return false;
257 return true; 257 return true;
258 } 258 }
259 259
260 bool isOverThreshold(size_t x, size_t y, float threshold) const { 260 bool isOverThreshold(size_t x, size_t y, float threshold) const {
261 if (threshold == 0.0) return true; 261 if (threshold == 0.0) return true;
271 setNormalizedMagnitudeAt(x, y, mag / m_factor[x]); 271 setNormalizedMagnitudeAt(x, y, mag / m_factor[x]);
272 } 272 }
273 273
274 void setNormalizedMagnitudeAt(size_t x, size_t y, float norm) { 274 void setNormalizedMagnitudeAt(size_t x, size_t y, float norm) {
275 if (x < m_width && y < m_height) { 275 if (x < m_width && y < m_height) {
276 m_magnitude[y][x] = uint16_t(norm * 65535.0); 276 m_magnitude[x][y] = uint16_t(norm * 65535.0);
277 } 277 }
278 } 278 }
279 279
280 void setPhaseAt(size_t x, size_t y, float phase) { 280 void setPhaseAt(size_t x, size_t y, float phase) {
281 // phase in range -pi -> pi 281 // phase in range -pi -> pi
282 if (x < m_width && y < m_height) { 282 if (x < m_width && y < m_height) {
283 m_phase[y][x] = uint16_t(int16_t((phase * 32767) / M_PI)); 283 m_phase[x][y] = uint16_t(int16_t((phase * 32767) / M_PI));
284 } 284 }
285 } 285 }
286 286
287 QColor getColour(unsigned char index) const { 287 QColor getColour(unsigned char index) const {
288 return m_colours[index]; 288 return m_colours[index];
334 QWaitCondition m_condition; 334 QWaitCondition m_condition;
335 mutable QMutex m_mutex; 335 mutable QMutex m_mutex;
336 336
337 CacheFillThread *m_fillThread; 337 CacheFillThread *m_fillThread;
338 QTimer *m_updateTimer; 338 QTimer *m_updateTimer;
339 mutable size_t m_candidateFillStartFrame;
339 size_t m_lastFillExtent; 340 size_t m_lastFillExtent;
340 bool m_exiting; 341 bool m_exiting;
341 342
342 void setCacheColourmap(); 343 void setCacheColourmap();
343 void rotateCacheColourmap(int distance); 344 void rotateCacheColourmap(int distance);
365 int getColourScaleWidth(QPainter &) const; 366 int getColourScaleWidth(QPainter &) const;
366 367
367 float getEffectiveMinFrequency() const; 368 float getEffectiveMinFrequency() const;
368 float getEffectiveMaxFrequency() const; 369 float getEffectiveMaxFrequency() const;
369 370
370 bool getYBinRange(int y, float &freqBinMin, float &freqBinMax) const;
371
372 struct LayerRange { 371 struct LayerRange {
373 long startFrame; 372 long startFrame;
374 int zoomLevel; 373 int zoomLevel;
375 size_t modelStart; 374 size_t modelStart;
376 size_t modelEnd; 375 size_t modelEnd;
377 }; 376 };
378 bool getXBinRange(int x, float &windowMin, float &windowMax) const; 377 bool getXBinRange(View *v, int x, float &windowMin, float &windowMax) const;
379 378 bool getYBinRange(View *v, int y, float &freqBinMin, float &freqBinMax) const;
380 bool getYBinSourceRange(int y, float &freqMin, float &freqMax) const; 379
381 bool getAdjustedYBinSourceRange(int x, int y, 380 bool getYBinSourceRange(View *v, int y, float &freqMin, float &freqMax) const;
381 bool getAdjustedYBinSourceRange(View *v, int x, int y,
382 float &freqMin, float &freqMax, 382 float &freqMin, float &freqMax,
383 float &adjFreqMin, float &adjFreqMax) const; 383 float &adjFreqMin, float &adjFreqMax) const;
384 bool getXBinSourceRange(int x, RealTime &timeMin, RealTime &timeMax) const; 384 bool getXBinSourceRange(View *v, int x, RealTime &timeMin, RealTime &timeMax) const;
385 bool getXYBinSourceRange(int x, int y, float &min, float &max, 385 bool getXYBinSourceRange(View *v, int x, int y, float &min, float &max,
386 float &phaseMin, float &phaseMax) const; 386 float &phaseMin, float &phaseMax) const;
387 387
388 size_t getWindowIncrement() const { 388 size_t getWindowIncrement() const {
389 return m_windowSize - m_windowSize * m_windowOverlap / 100; 389 return m_windowSize - m_windowSize * m_windowOverlap / 100;
390 } 390 }