comparison layer/SpectrogramLayer.h @ 997:296ccd36f626 tony-2.0-integration

Merge through to branch for Tony 2.0
author Chris Cannam
date Thu, 20 Aug 2015 14:54:21 +0100
parents 4f4f0e158ecf
children 2bd5eb6a6c6b
comparison
equal deleted inserted replaced
943:788b7623bfca 997:296ccd36f626
55 SpectrogramLayer(Configuration = FullRangeDb); 55 SpectrogramLayer(Configuration = FullRangeDb);
56 ~SpectrogramLayer(); 56 ~SpectrogramLayer();
57 57
58 virtual const ZoomConstraint *getZoomConstraint() const { return this; } 58 virtual const ZoomConstraint *getZoomConstraint() const { return this; }
59 virtual const Model *getModel() const { return m_model; } 59 virtual const Model *getModel() const { return m_model; }
60 virtual void paint(View *v, QPainter &paint, QRect rect) const; 60 virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const;
61 virtual void setSynchronousPainting(bool synchronous); 61 virtual void setSynchronousPainting(bool synchronous);
62 62
63 virtual int getVerticalScaleWidth(View *v, bool detailed, QPainter &) const; 63 virtual int getVerticalScaleWidth(LayerGeometryProvider *v, bool detailed, QPainter &) const;
64 virtual void paintVerticalScale(View *v, bool detailed, QPainter &paint, QRect rect) const; 64 virtual void paintVerticalScale(LayerGeometryProvider *v, bool detailed, QPainter &paint, QRect rect) const;
65 65
66 virtual bool getCrosshairExtents(View *, QPainter &, QPoint cursorPos, 66 virtual bool getCrosshairExtents(LayerGeometryProvider *, QPainter &, QPoint cursorPos,
67 std::vector<QRect> &extents) const; 67 std::vector<QRect> &extents) const;
68 virtual void paintCrosshairs(View *, QPainter &, QPoint) const; 68 virtual void paintCrosshairs(LayerGeometryProvider *, QPainter &, QPoint) const;
69 69
70 virtual QString getFeatureDescription(View *v, QPoint &) const; 70 virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const;
71 71
72 virtual bool snapToFeatureFrame(View *v, sv_frame_t &frame, 72 virtual bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
73 int &resolution, 73 int &resolution,
74 SnapType snap) const; 74 SnapType snap) const;
75 75
76 virtual void measureDoubleClick(View *, QMouseEvent *); 76 virtual void measureDoubleClick(LayerGeometryProvider *, QMouseEvent *);
77 77
78 virtual bool hasLightBackground() const; 78 virtual bool hasLightBackground() const;
79 79
80 void setModel(const DenseTimeValueModel *model); 80 void setModel(const DenseTimeValueModel *model);
81 81
86 virtual QString getPropertyGroupName(const PropertyName &) const; 86 virtual QString getPropertyGroupName(const PropertyName &) const;
87 virtual int getPropertyRangeAndValue(const PropertyName &, 87 virtual int getPropertyRangeAndValue(const PropertyName &,
88 int *min, int *max, int *deflt) const; 88 int *min, int *max, int *deflt) const;
89 virtual QString getPropertyValueLabel(const PropertyName &, 89 virtual QString getPropertyValueLabel(const PropertyName &,
90 int value) const; 90 int value) const;
91 virtual QString getPropertyValueIconName(const PropertyName &,
92 int value) const;
91 virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const; 93 virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const;
92 virtual void setProperty(const PropertyName &, int value); 94 virtual void setProperty(const PropertyName &, int value);
93 95
94 /** 96 /**
95 * Specify the channel to use from the source model. 97 * Specify the channel to use from the source model.
168 /** 170 /**
169 * Specify the processing of frequency bins for the y axis. 171 * Specify the processing of frequency bins for the y axis.
170 */ 172 */
171 void setBinDisplay(BinDisplay); 173 void setBinDisplay(BinDisplay);
172 BinDisplay getBinDisplay() const; 174 BinDisplay getBinDisplay() const;
173 175
174 /** 176 enum Normalization {
175 * Normalize each column to its maximum value, independent of its 177 NoNormalization,
176 * neighbours. 178 NormalizeColumns,
177 */ 179 NormalizeVisibleArea,
178 void setNormalizeColumns(bool n); 180 NormalizeHybrid
179 bool getNormalizeColumns() const; 181 };
180 182
181 /** 183 /**
182 * Normalize each value against the maximum in the visible region. 184 * Specify the normalization mode for bin values.
183 */ 185 */
184 void setNormalizeVisibleArea(bool n); 186 void setNormalization(Normalization);
185 bool getNormalizeVisibleArea() const; 187 Normalization getNormalization() const;
186 188
187 /** 189 /**
188 * Normalize each column to its maximum value, and then scale by 190 * Specify the colour map. See ColourMapper for the colour map
189 * the log of the (absolute) maximum value. 191 * values.
190 */ 192 */
191 void setNormalizeHybrid(bool n);
192 bool getNormalizeHybrid() const;
193
194 void setColourMap(int map); 193 void setColourMap(int map);
195 int getColourMap() const; 194 int getColourMap() const;
196 195
197 /** 196 /**
198 * Specify the colourmap rotation for the colour scale. 197 * Specify the colourmap rotation for the colour scale.
208 207
209 virtual ColourSignificance getLayerColourSignificance() const { 208 virtual ColourSignificance getLayerColourSignificance() const {
210 return ColourHasMeaningfulValue; 209 return ColourHasMeaningfulValue;
211 } 210 }
212 211
213 double getYForFrequency(const View *v, double frequency) const; 212 double getYForFrequency(const LayerGeometryProvider *v, double frequency) const;
214 double getFrequencyForY(const View *v, int y) const; 213 double getFrequencyForY(const LayerGeometryProvider *v, int y) const;
215 214
216 virtual int getCompletion(View *v) const; 215 virtual int getCompletion(LayerGeometryProvider *v) const;
217 virtual QString getError(View *v) const; 216 virtual QString getError(LayerGeometryProvider *v) const;
218 217
219 virtual bool getValueExtents(double &min, double &max, 218 virtual bool getValueExtents(double &min, double &max,
220 bool &logarithmic, QString &unit) const; 219 bool &logarithmic, QString &unit) const;
221 220
222 virtual bool getDisplayExtents(double &min, double &max) const; 221 virtual bool getDisplayExtents(double &min, double &max) const;
223 222
224 virtual bool setDisplayExtents(double min, double max); 223 virtual bool setDisplayExtents(double min, double max);
225 224
226 virtual bool getYScaleValue(const View *, int, double &, QString &) const; 225 virtual bool getYScaleValue(const LayerGeometryProvider *, int, double &, QString &) const;
227 226
228 virtual void toXml(QTextStream &stream, QString indent = "", 227 virtual void toXml(QTextStream &stream, QString indent = "",
229 QString extraAttributes = "") const; 228 QString extraAttributes = "") const;
230 229
231 void setProperties(const QXmlAttributes &attributes); 230 void setProperties(const QXmlAttributes &attributes);
232 231
233 virtual void setLayerDormant(const View *v, bool dormant); 232 virtual void setLayerDormant(const LayerGeometryProvider *v, bool dormant);
234 233
235 virtual bool isLayerScrollable(const View *) const { return false; } 234 virtual bool isLayerScrollable(const LayerGeometryProvider *) const { return false; }
236 235
237 virtual int getVerticalZoomSteps(int &defaultStep) const; 236 virtual int getVerticalZoomSteps(int &defaultStep) const;
238 virtual int getCurrentVerticalZoomStep() const; 237 virtual int getCurrentVerticalZoomStep() const;
239 virtual void setVerticalZoomStep(int); 238 virtual void setVerticalZoomStep(int);
240 virtual RangeMapper *getNewVerticalZoomRangeMapper() const; 239 virtual RangeMapper *getNewVerticalZoomRangeMapper() const;
244 protected slots: 243 protected slots:
245 void cacheInvalid(); 244 void cacheInvalid();
246 void cacheInvalid(sv_frame_t startFrame, sv_frame_t endFrame); 245 void cacheInvalid(sv_frame_t startFrame, sv_frame_t endFrame);
247 246
248 void preferenceChanged(PropertyContainer::PropertyName name); 247 void preferenceChanged(PropertyContainer::PropertyName name);
249
250 void fillTimerTimedOut();
251 248
252 protected: 249 protected:
253 const DenseTimeValueModel *m_model; // I do not own this 250 const DenseTimeValueModel *m_model; // I do not own this
254 251
255 int m_channel; 252 int m_channel;
270 ColourScale m_colourScale; 267 ColourScale m_colourScale;
271 int m_colourMap; 268 int m_colourMap;
272 QColor m_crosshairColour; 269 QColor m_crosshairColour;
273 FrequencyScale m_frequencyScale; 270 FrequencyScale m_frequencyScale;
274 BinDisplay m_binDisplay; 271 BinDisplay m_binDisplay;
275 bool m_normalizeColumns; 272 Normalization m_normalization;
276 bool m_normalizeVisibleArea;
277 bool m_normalizeHybrid;
278 int m_lastEmittedZoomStep; 273 int m_lastEmittedZoomStep;
279 bool m_synchronous; 274 bool m_synchronous;
280 275
281 mutable bool m_haveDetailedScale; 276 mutable bool m_haveDetailedScale;
282 mutable int m_lastPaintBlockWidth; 277 mutable int m_lastPaintBlockWidth;
324 * before copying the image cache onto the window. (Remind me why 319 * before copying the image cache onto the window. (Remind me why
325 * we don't draw directly onto the cache?) 320 * we don't draw directly onto the cache?)
326 */ 321 */
327 mutable QImage m_drawBuffer; 322 mutable QImage m_drawBuffer;
328 323
329 mutable QTimer *m_updateTimer;
330
331 mutable sv_frame_t m_candidateFillStartFrame;
332 bool m_exiting; 324 bool m_exiting;
333 325
334 void initialisePalette(); 326 void initialisePalette();
335 void rotatePalette(int distance); 327 void rotatePalette(int distance);
336 328
337 unsigned char getDisplayValue(View *v, double input) const; 329 unsigned char getDisplayValue(LayerGeometryProvider *v, double input) const;
338 330
339 int getColourScaleWidth(QPainter &) const; 331 int getColourScaleWidth(QPainter &) const;
340 332
341 void illuminateLocalFeatures(View *v, QPainter &painter) const; 333 void illuminateLocalFeatures(LayerGeometryProvider *v, QPainter &painter) const;
342 334
343 double getEffectiveMinFrequency() const; 335 double getEffectiveMinFrequency() const;
344 double getEffectiveMaxFrequency() const; 336 double getEffectiveMaxFrequency() const;
345 337
346 // Note that the getYBin... methods return the nominal bin in the 338 // Note that the getYBin... methods return the nominal bin in the
347 // un-smoothed spectrogram. This is not necessarily the same bin 339 // un-smoothed spectrogram. This is not necessarily the same bin
348 // as is pulled from the spectrogram and drawn at the given 340 // as is pulled from the spectrogram and drawn at the given
349 // position, if the spectrogram has oversampling smoothing. Use 341 // position, if the spectrogram has oversampling smoothing. Use
350 // getSmoothedYBinRange to obtain that. 342 // getSmoothedYBinRange to obtain that.
351 343
352 bool getXBinRange(View *v, int x, double &windowMin, double &windowMax) const; 344 bool getXBinRange(LayerGeometryProvider *v, int x, double &windowMin, double &windowMax) const;
353 bool getYBinRange(View *v, int y, double &freqBinMin, double &freqBinMax) const; 345 bool getYBinRange(LayerGeometryProvider *v, int y, double &freqBinMin, double &freqBinMax) const;
354 bool getSmoothedYBinRange(View *v, int y, double &freqBinMin, double &freqBinMax) const; 346 bool getSmoothedYBinRange(LayerGeometryProvider *v, int y, double &freqBinMin, double &freqBinMax) const;
355 347
356 bool getYBinSourceRange(View *v, int y, double &freqMin, double &freqMax) const; 348 bool getYBinSourceRange(LayerGeometryProvider *v, int y, double &freqMin, double &freqMax) const;
357 bool getAdjustedYBinSourceRange(View *v, int x, int y, 349 bool getAdjustedYBinSourceRange(LayerGeometryProvider *v, int x, int y,
358 double &freqMin, double &freqMax, 350 double &freqMin, double &freqMax,
359 double &adjFreqMin, double &adjFreqMax) const; 351 double &adjFreqMin, double &adjFreqMax) const;
360 bool getXBinSourceRange(View *v, int x, RealTime &timeMin, RealTime &timeMax) const; 352 bool getXBinSourceRange(LayerGeometryProvider *v, int x, RealTime &timeMin, RealTime &timeMax) const;
361 bool getXYBinSourceRange(View *v, int x, int y, double &min, double &max, 353 bool getXYBinSourceRange(LayerGeometryProvider *v, int x, int y, double &min, double &max,
362 double &phaseMin, double &phaseMax) const; 354 double &phaseMin, double &phaseMax) const;
363 355
364 int getWindowIncrement() const { 356 int getWindowIncrement() const {
365 if (m_windowHopLevel == 0) return m_windowSize; 357 if (m_windowHopLevel == 0) return m_windowSize;
366 else if (m_windowHopLevel == 1) return (m_windowSize * 3) / 4; 358 else if (m_windowHopLevel == 1) return (m_windowSize * 3) / 4;
367 else return m_windowSize / (1 << (m_windowHopLevel - 1)); 359 else return m_windowSize / (1 << (m_windowHopLevel - 1));
368 } 360 }
369 361
370 int getZeroPadLevel(const View *v) const; 362 int getZeroPadLevel(const LayerGeometryProvider *v) const;
371 int getFFTSize(const View *v) const; 363 int getFFTSize(const LayerGeometryProvider *v) const;
372 FFTModel *getFFTModel(const View *v) const; 364 FFTModel *getFFTModel(const LayerGeometryProvider *v) const;
373 Dense3DModelPeakCache *getPeakCache(const View *v) const; 365 Dense3DModelPeakCache *getPeakCache(const LayerGeometryProvider *v) const;
374 void invalidateFFTModels(); 366 void invalidateFFTModels();
375 367
376 typedef std::pair<FFTModel *, sv_frame_t> FFTFillPair; // model, last fill 368 typedef std::map<const View *, FFTModel *> ViewFFTMap;
377 typedef std::map<const View *, FFTFillPair> ViewFFTMap;
378 typedef std::map<const View *, Dense3DModelPeakCache *> PeakCacheMap; 369 typedef std::map<const View *, Dense3DModelPeakCache *> PeakCacheMap;
379 mutable ViewFFTMap m_fftModels; 370 mutable ViewFFTMap m_fftModels;
380 mutable PeakCacheMap m_peakCaches; 371 mutable PeakCacheMap m_peakCaches;
381 mutable Model *m_sliceableModel; 372 mutable Model *m_sliceableModel;
382 373
420 private: 411 private:
421 float m_min; 412 float m_min;
422 float m_max; 413 float m_max;
423 }; 414 };
424 415
425 typedef std::map<const View *, MagnitudeRange> ViewMagMap; 416 typedef std::map<const LayerGeometryProvider *, MagnitudeRange> ViewMagMap;
426 mutable ViewMagMap m_viewMags; 417 mutable ViewMagMap m_viewMags;
427 mutable std::vector<MagnitudeRange> m_columnMags; 418 mutable std::vector<MagnitudeRange> m_columnMags;
428 void invalidateMagnitudes(); 419 void invalidateMagnitudes();
429 bool updateViewMagnitudes(View *v) const; 420 bool updateViewMagnitudes(LayerGeometryProvider *v) const;
430 bool paintDrawBuffer(View *v, int w, int h, 421 bool paintDrawBuffer(LayerGeometryProvider *v, int w, int h,
431 const std::vector<int> &binforx, 422 const std::vector<int> &binforx,
432 const std::vector<double> &binfory, 423 const std::vector<double> &binfory,
433 bool usePeaksCache, 424 bool usePeaksCache,
434 MagnitudeRange &overallMag, 425 MagnitudeRange &overallMag,
435 bool &overallMagChanged) const; 426 bool &overallMagChanged) const;
436 bool paintDrawBufferPeakFrequencies(View *v, int w, int h, 427 bool paintDrawBufferPeakFrequencies(LayerGeometryProvider *v, int w, int h,
437 const std::vector<int> &binforx, 428 const std::vector<int> &binforx,
438 int minbin, 429 int minbin,
439 int maxbin, 430 int maxbin,
440 double displayMinFreq, 431 double displayMinFreq,
441 double displayMaxFreq, 432 double displayMaxFreq,
442 bool logarithmic, 433 bool logarithmic,
443 MagnitudeRange &overallMag, 434 MagnitudeRange &overallMag,
444 bool &overallMagChanged) const; 435 bool &overallMagChanged) const;
445 436
446 virtual void updateMeasureRectYCoords(View *v, const MeasureRect &r) const; 437 virtual void updateMeasureRectYCoords(LayerGeometryProvider *v, const MeasureRect &r) const;
447 virtual void setMeasureRectYCoord(View *v, MeasureRect &r, bool start, int y) const; 438 virtual void setMeasureRectYCoord(LayerGeometryProvider *v, MeasureRect &r, bool start, int y) const;
448 }; 439 };
449 440
450 #endif 441 #endif