Mercurial > hg > svgui
comparison layer/SpectrogramLayer.h @ 1045:f535f6e5dbb0 alignment-simple
Merge in from SV 3.0-integration branches
author | Chris Cannam |
---|---|
date | Wed, 02 Mar 2016 17:25:27 +0000 |
parents | bfce7940c017 |
children | 5e5873c24142 |
comparison
equal
deleted
inserted
replaced
976:f2c63ec85901 | 1045:f535f6e5dbb0 |
---|---|
11 published by the Free Software Foundation; either version 2 of the | 11 published by the Free Software Foundation; either version 2 of the |
12 License, or (at your option) any later version. See the file | 12 License, or (at your option) any later version. See the file |
13 COPYING included with this distribution for more information. | 13 COPYING included with this distribution for more information. |
14 */ | 14 */ |
15 | 15 |
16 #ifndef _SPECTROGRAM_LAYER_H_ | 16 #ifndef SPECTROGRAM_LAYER_H |
17 #define _SPECTROGRAM_LAYER_H_ | 17 #define SPECTROGRAM_LAYER_H |
18 | 18 |
19 #include "SliceableLayer.h" | 19 #include "SliceableLayer.h" |
20 #include "base/Window.h" | 20 #include "base/Window.h" |
21 #include "base/RealTime.h" | 21 #include "base/RealTime.h" |
22 #include "base/Thread.h" | 22 #include "base/Thread.h" |
23 #include "base/PropertyContainer.h" | 23 #include "base/PropertyContainer.h" |
24 #include "data/model/PowerOfSqrtTwoZoomConstraint.h" | 24 #include "data/model/PowerOfSqrtTwoZoomConstraint.h" |
25 #include "data/model/DenseTimeValueModel.h" | 25 #include "data/model/DenseTimeValueModel.h" |
26 #include "data/model/FFTModel.h" | 26 #include "data/model/FFTModel.h" |
27 | 27 |
28 #include "ScrollableImageCache.h" | |
29 | |
28 #include <QMutex> | 30 #include <QMutex> |
29 #include <QWaitCondition> | 31 #include <QWaitCondition> |
30 #include <QImage> | 32 #include <QImage> |
31 #include <QPixmap> | 33 #include <QPixmap> |
32 | 34 |
55 SpectrogramLayer(Configuration = FullRangeDb); | 57 SpectrogramLayer(Configuration = FullRangeDb); |
56 ~SpectrogramLayer(); | 58 ~SpectrogramLayer(); |
57 | 59 |
58 virtual const ZoomConstraint *getZoomConstraint() const { return this; } | 60 virtual const ZoomConstraint *getZoomConstraint() const { return this; } |
59 virtual const Model *getModel() const { return m_model; } | 61 virtual const Model *getModel() const { return m_model; } |
60 virtual void paint(View *v, QPainter &paint, QRect rect) const; | 62 virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const; |
61 virtual void setSynchronousPainting(bool synchronous); | 63 virtual void setSynchronousPainting(bool synchronous); |
62 | 64 |
63 virtual int getVerticalScaleWidth(View *v, bool detailed, QPainter &) const; | 65 virtual int getVerticalScaleWidth(LayerGeometryProvider *v, bool detailed, QPainter &) const; |
64 virtual void paintVerticalScale(View *v, bool detailed, QPainter &paint, QRect rect) const; | 66 virtual void paintVerticalScale(LayerGeometryProvider *v, bool detailed, QPainter &paint, QRect rect) const; |
65 | 67 |
66 virtual bool getCrosshairExtents(View *, QPainter &, QPoint cursorPos, | 68 virtual bool getCrosshairExtents(LayerGeometryProvider *, QPainter &, QPoint cursorPos, |
67 std::vector<QRect> &extents) const; | 69 std::vector<QRect> &extents) const; |
68 virtual void paintCrosshairs(View *, QPainter &, QPoint) const; | 70 virtual void paintCrosshairs(LayerGeometryProvider *, QPainter &, QPoint) const; |
69 | 71 |
70 virtual QString getFeatureDescription(View *v, QPoint &) const; | 72 virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const; |
71 | 73 |
72 virtual bool snapToFeatureFrame(View *v, sv_frame_t &frame, | 74 virtual bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, |
73 int &resolution, | 75 int &resolution, |
74 SnapType snap) const; | 76 SnapType snap) const; |
75 | 77 |
76 virtual void measureDoubleClick(View *, QMouseEvent *); | 78 virtual void measureDoubleClick(LayerGeometryProvider *, QMouseEvent *); |
77 | 79 |
78 virtual bool hasLightBackground() const; | 80 virtual bool hasLightBackground() const; |
79 | 81 |
80 void setModel(const DenseTimeValueModel *model); | 82 void setModel(const DenseTimeValueModel *model); |
81 | 83 |
86 virtual QString getPropertyGroupName(const PropertyName &) const; | 88 virtual QString getPropertyGroupName(const PropertyName &) const; |
87 virtual int getPropertyRangeAndValue(const PropertyName &, | 89 virtual int getPropertyRangeAndValue(const PropertyName &, |
88 int *min, int *max, int *deflt) const; | 90 int *min, int *max, int *deflt) const; |
89 virtual QString getPropertyValueLabel(const PropertyName &, | 91 virtual QString getPropertyValueLabel(const PropertyName &, |
90 int value) const; | 92 int value) const; |
93 virtual QString getPropertyValueIconName(const PropertyName &, | |
94 int value) const; | |
91 virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const; | 95 virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const; |
92 virtual void setProperty(const PropertyName &, int value); | 96 virtual void setProperty(const PropertyName &, int value); |
93 | 97 |
94 /** | 98 /** |
95 * Specify the channel to use from the source model. | 99 * Specify the channel to use from the source model. |
168 /** | 172 /** |
169 * Specify the processing of frequency bins for the y axis. | 173 * Specify the processing of frequency bins for the y axis. |
170 */ | 174 */ |
171 void setBinDisplay(BinDisplay); | 175 void setBinDisplay(BinDisplay); |
172 BinDisplay getBinDisplay() const; | 176 BinDisplay getBinDisplay() const; |
173 | 177 |
174 /** | 178 enum Normalization { |
175 * Normalize each column to its maximum value, independent of its | 179 NoNormalization, |
176 * neighbours. | 180 NormalizeColumns, |
177 */ | 181 NormalizeVisibleArea, |
178 void setNormalizeColumns(bool n); | 182 NormalizeHybrid |
179 bool getNormalizeColumns() const; | 183 }; |
180 | 184 |
181 /** | 185 /** |
182 * Normalize each value against the maximum in the visible region. | 186 * Specify the normalization mode for bin values. |
183 */ | 187 */ |
184 void setNormalizeVisibleArea(bool n); | 188 void setNormalization(Normalization); |
185 bool getNormalizeVisibleArea() const; | 189 Normalization getNormalization() const; |
186 | 190 |
187 /** | 191 /** |
188 * Normalize each column to its maximum value, and then scale by | 192 * Specify the colour map. See ColourMapper for the colour map |
189 * the log of the (absolute) maximum value. | 193 * values. |
190 */ | 194 */ |
191 void setNormalizeHybrid(bool n); | |
192 bool getNormalizeHybrid() const; | |
193 | |
194 void setColourMap(int map); | 195 void setColourMap(int map); |
195 int getColourMap() const; | 196 int getColourMap() const; |
196 | 197 |
197 /** | 198 /** |
198 * Specify the colourmap rotation for the colour scale. | 199 * Specify the colourmap rotation for the colour scale. |
208 | 209 |
209 virtual ColourSignificance getLayerColourSignificance() const { | 210 virtual ColourSignificance getLayerColourSignificance() const { |
210 return ColourHasMeaningfulValue; | 211 return ColourHasMeaningfulValue; |
211 } | 212 } |
212 | 213 |
213 double getYForFrequency(const View *v, double frequency) const; | 214 double getYForFrequency(const LayerGeometryProvider *v, double frequency) const; |
214 double getFrequencyForY(const View *v, int y) const; | 215 double getFrequencyForY(const LayerGeometryProvider *v, int y) const; |
215 | 216 |
216 virtual int getCompletion(View *v) const; | 217 virtual int getCompletion(LayerGeometryProvider *v) const; |
217 virtual QString getError(View *v) const; | 218 virtual QString getError(LayerGeometryProvider *v) const; |
218 | 219 |
219 virtual bool getValueExtents(double &min, double &max, | 220 virtual bool getValueExtents(double &min, double &max, |
220 bool &logarithmic, QString &unit) const; | 221 bool &logarithmic, QString &unit) const; |
221 | 222 |
222 virtual bool getDisplayExtents(double &min, double &max) const; | 223 virtual bool getDisplayExtents(double &min, double &max) const; |
223 | 224 |
224 virtual bool setDisplayExtents(double min, double max); | 225 virtual bool setDisplayExtents(double min, double max); |
225 | 226 |
226 virtual bool getYScaleValue(const View *, int, double &, QString &) const; | 227 virtual bool getYScaleValue(const LayerGeometryProvider *, int, double &, QString &) const; |
227 | 228 |
228 virtual void toXml(QTextStream &stream, QString indent = "", | 229 virtual void toXml(QTextStream &stream, QString indent = "", |
229 QString extraAttributes = "") const; | 230 QString extraAttributes = "") const; |
230 | 231 |
231 void setProperties(const QXmlAttributes &attributes); | 232 void setProperties(const QXmlAttributes &attributes); |
232 | 233 |
233 virtual void setLayerDormant(const View *v, bool dormant); | 234 virtual void setLayerDormant(const LayerGeometryProvider *v, bool dormant); |
234 | 235 |
235 virtual bool isLayerScrollable(const View *) const { return false; } | 236 virtual bool isLayerScrollable(const LayerGeometryProvider *) const { return false; } |
236 | 237 |
237 virtual int getVerticalZoomSteps(int &defaultStep) const; | 238 virtual int getVerticalZoomSteps(int &defaultStep) const; |
238 virtual int getCurrentVerticalZoomStep() const; | 239 virtual int getCurrentVerticalZoomStep() const; |
239 virtual void setVerticalZoomStep(int); | 240 virtual void setVerticalZoomStep(int); |
240 virtual RangeMapper *getNewVerticalZoomRangeMapper() const; | 241 virtual RangeMapper *getNewVerticalZoomRangeMapper() const; |
245 void cacheInvalid(); | 246 void cacheInvalid(); |
246 void cacheInvalid(sv_frame_t startFrame, sv_frame_t endFrame); | 247 void cacheInvalid(sv_frame_t startFrame, sv_frame_t endFrame); |
247 | 248 |
248 void preferenceChanged(PropertyContainer::PropertyName name); | 249 void preferenceChanged(PropertyContainer::PropertyName name); |
249 | 250 |
250 void fillTimerTimedOut(); | |
251 | |
252 protected: | 251 protected: |
253 const DenseTimeValueModel *m_model; // I do not own this | 252 const DenseTimeValueModel *m_model; // I do not own this |
254 | 253 |
255 int m_channel; | 254 int m_channel; |
256 int m_windowSize; | 255 int m_windowSize; |
257 WindowType m_windowType; | 256 WindowType m_windowType; |
258 int m_windowHopLevel; | 257 int m_windowHopLevel; |
259 int m_zeroPadLevel; | 258 int m_zeroPadLevel; |
260 int m_fftSize; | 259 int m_fftSize; |
261 float m_gain; | 260 float m_gain; |
262 float m_initialGain; | 261 float m_initialGain; |
263 float m_threshold; | 262 float m_threshold; |
264 float m_initialThreshold; | 263 float m_initialThreshold; |
265 int m_colourRotation; | 264 int m_colourRotation; |
266 int m_initialRotation; | 265 int m_initialRotation; |
267 int m_minFrequency; | 266 int m_minFrequency; |
268 int m_maxFrequency; | 267 int m_maxFrequency; |
269 int m_initialMaxFrequency; | 268 int m_initialMaxFrequency; |
270 ColourScale m_colourScale; | 269 ColourScale m_colourScale; |
271 int m_colourMap; | 270 int m_colourMap; |
272 QColor m_crosshairColour; | 271 QColor m_crosshairColour; |
273 FrequencyScale m_frequencyScale; | 272 FrequencyScale m_frequencyScale; |
274 BinDisplay m_binDisplay; | 273 BinDisplay m_binDisplay; |
275 bool m_normalizeColumns; | 274 Normalization m_normalization; |
276 bool m_normalizeVisibleArea; | |
277 bool m_normalizeHybrid; | |
278 int m_lastEmittedZoomStep; | 275 int m_lastEmittedZoomStep; |
279 bool m_synchronous; | 276 bool m_synchronous; |
280 | 277 |
281 mutable bool m_haveDetailedScale; | 278 mutable bool m_haveDetailedScale; |
282 mutable int m_lastPaintBlockWidth; | |
283 mutable RealTime m_lastPaintTime; | |
284 | 279 |
285 enum { NO_VALUE = 0 }; // colour index for unused pixels | 280 enum { NO_VALUE = 0 }; // colour index for unused pixels |
286 | 281 |
287 class Palette | 282 class Palette |
288 { | 283 { |
299 QColor m_colours[256]; | 294 QColor m_colours[256]; |
300 }; | 295 }; |
301 | 296 |
302 Palette m_palette; | 297 Palette m_palette; |
303 | 298 |
304 /** | 299 typedef std::map<int, ScrollableImageCache> ViewImageCache; // key is view id |
305 * ImageCache covers the area of the view, at view resolution. | |
306 * Not all of it is necessarily valid at once (it is refreshed | |
307 * in parts when scrolling, for example). | |
308 */ | |
309 struct ImageCache | |
310 { | |
311 QImage image; | |
312 QRect validArea; | |
313 sv_frame_t startFrame; | |
314 int zoomLevel; | |
315 }; | |
316 typedef std::map<const View *, ImageCache> ViewImageCache; | |
317 void invalidateImageCaches(); | 300 void invalidateImageCaches(); |
318 void invalidateImageCaches(sv_frame_t startFrame, sv_frame_t endFrame); | |
319 mutable ViewImageCache m_imageCaches; | 301 mutable ViewImageCache m_imageCaches; |
302 ScrollableImageCache &getImageCacheReference(const LayerGeometryProvider *) const; | |
320 | 303 |
321 /** | 304 /** |
322 * When painting, we draw directly onto the draw buffer and then | 305 * When painting, we draw directly onto the draw buffer and then |
323 * copy this to the part of the image cache that needed refreshing | 306 * copy this to the part of the image cache that needed refreshing |
324 * before copying the image cache onto the window. (Remind me why | 307 * before copying the image cache onto the window. (Remind me why |
325 * we don't draw directly onto the cache?) | 308 * we don't draw directly onto the cache?) |
326 */ | 309 */ |
327 mutable QImage m_drawBuffer; | 310 mutable QImage m_drawBuffer; |
328 | 311 |
329 mutable QTimer *m_updateTimer; | |
330 | |
331 mutable sv_frame_t m_candidateFillStartFrame; | |
332 bool m_exiting; | 312 bool m_exiting; |
333 | 313 |
334 void initialisePalette(); | 314 void initialisePalette(); |
335 void rotatePalette(int distance); | 315 void rotatePalette(int distance); |
336 | 316 |
337 unsigned char getDisplayValue(View *v, double input) const; | 317 unsigned char getDisplayValue(LayerGeometryProvider *v, double input) const; |
338 | 318 |
339 int getColourScaleWidth(QPainter &) const; | 319 int getColourScaleWidth(QPainter &) const; |
340 | 320 |
341 void illuminateLocalFeatures(View *v, QPainter &painter) const; | 321 void illuminateLocalFeatures(LayerGeometryProvider *v, QPainter &painter) const; |
342 | 322 |
343 double getEffectiveMinFrequency() const; | 323 double getEffectiveMinFrequency() const; |
344 double getEffectiveMaxFrequency() const; | 324 double getEffectiveMaxFrequency() const; |
345 | 325 |
346 // Note that the getYBin... methods return the nominal bin in the | 326 // Note that the getYBin... methods return the nominal bin in the |
347 // un-smoothed spectrogram. This is not necessarily the same bin | 327 // un-smoothed spectrogram. This is not necessarily the same bin |
348 // as is pulled from the spectrogram and drawn at the given | 328 // as is pulled from the spectrogram and drawn at the given |
349 // position, if the spectrogram has oversampling smoothing. Use | 329 // position, if the spectrogram has oversampling smoothing. Use |
350 // getSmoothedYBinRange to obtain that. | 330 // getSmoothedYBinRange to obtain that. |
351 | 331 |
352 bool getXBinRange(View *v, int x, double &windowMin, double &windowMax) const; | 332 bool getXBinRange(LayerGeometryProvider *v, int x, double &windowMin, double &windowMax) const; |
353 bool getYBinRange(View *v, int y, double &freqBinMin, double &freqBinMax) const; | 333 bool getYBinRange(LayerGeometryProvider *v, int y, double &freqBinMin, double &freqBinMax) const; |
354 bool getSmoothedYBinRange(View *v, int y, double &freqBinMin, double &freqBinMax) const; | 334 bool getSmoothedYBinRange(LayerGeometryProvider *v, int y, double &freqBinMin, double &freqBinMax) const; |
355 | 335 |
356 bool getYBinSourceRange(View *v, int y, double &freqMin, double &freqMax) const; | 336 bool getYBinSourceRange(LayerGeometryProvider *v, int y, double &freqMin, double &freqMax) const; |
357 bool getAdjustedYBinSourceRange(View *v, int x, int y, | 337 bool getAdjustedYBinSourceRange(LayerGeometryProvider *v, int x, int y, |
358 double &freqMin, double &freqMax, | 338 double &freqMin, double &freqMax, |
359 double &adjFreqMin, double &adjFreqMax) const; | 339 double &adjFreqMin, double &adjFreqMax) const; |
360 bool getXBinSourceRange(View *v, int x, RealTime &timeMin, RealTime &timeMax) const; | 340 bool getXBinSourceRange(LayerGeometryProvider *v, int x, RealTime &timeMin, RealTime &timeMax) const; |
361 bool getXYBinSourceRange(View *v, int x, int y, double &min, double &max, | 341 bool getXYBinSourceRange(LayerGeometryProvider *v, int x, int y, double &min, double &max, |
362 double &phaseMin, double &phaseMax) const; | 342 double &phaseMin, double &phaseMax) const; |
363 | 343 |
364 int getWindowIncrement() const { | 344 int getWindowIncrement() const { |
365 if (m_windowHopLevel == 0) return m_windowSize; | 345 if (m_windowHopLevel == 0) return m_windowSize; |
366 else if (m_windowHopLevel == 1) return (m_windowSize * 3) / 4; | 346 else if (m_windowHopLevel == 1) return (m_windowSize * 3) / 4; |
367 else return m_windowSize / (1 << (m_windowHopLevel - 1)); | 347 else return m_windowSize / (1 << (m_windowHopLevel - 1)); |
368 } | 348 } |
369 | 349 |
370 int getZeroPadLevel(const View *v) const; | 350 int getZeroPadLevel(const LayerGeometryProvider *v) const; |
371 int getFFTSize(const View *v) const; | 351 int getFFTSize(const LayerGeometryProvider *v) const; |
372 FFTModel *getFFTModel(const View *v) const; | 352 FFTModel *getFFTModel(const LayerGeometryProvider *v) const; |
373 Dense3DModelPeakCache *getPeakCache(const View *v) const; | 353 Dense3DModelPeakCache *getPeakCache(const LayerGeometryProvider *v) const; |
374 void invalidateFFTModels(); | 354 void invalidateFFTModels(); |
375 | 355 |
376 typedef std::pair<FFTModel *, sv_frame_t> FFTFillPair; // model, last fill | 356 typedef std::map<int, FFTModel *> ViewFFTMap; // key is view id |
377 typedef std::map<const View *, FFTFillPair> ViewFFTMap; | 357 typedef std::map<int, Dense3DModelPeakCache *> PeakCacheMap; // key is view id |
378 typedef std::map<const View *, Dense3DModelPeakCache *> PeakCacheMap; | |
379 mutable ViewFFTMap m_fftModels; | 358 mutable ViewFFTMap m_fftModels; |
380 mutable PeakCacheMap m_peakCaches; | 359 mutable PeakCacheMap m_peakCaches; |
381 mutable Model *m_sliceableModel; | 360 mutable Model *m_sliceableModel; |
382 | 361 |
383 class MagnitudeRange { | 362 class MagnitudeRange { |
420 private: | 399 private: |
421 float m_min; | 400 float m_min; |
422 float m_max; | 401 float m_max; |
423 }; | 402 }; |
424 | 403 |
425 typedef std::map<const View *, MagnitudeRange> ViewMagMap; | 404 typedef std::map<int, MagnitudeRange> ViewMagMap; // key is view id |
426 mutable ViewMagMap m_viewMags; | 405 mutable ViewMagMap m_viewMags; |
427 mutable std::vector<MagnitudeRange> m_columnMags; | 406 mutable std::vector<MagnitudeRange> m_columnMags; |
428 void invalidateMagnitudes(); | 407 void invalidateMagnitudes(); |
429 bool updateViewMagnitudes(View *v) const; | 408 bool updateViewMagnitudes(LayerGeometryProvider *v) const; |
430 bool paintDrawBuffer(View *v, int w, int h, | 409 int paintDrawBuffer(LayerGeometryProvider *v, int w, int h, |
431 const std::vector<int> &binforx, | 410 const std::vector<int> &binforx, |
432 const std::vector<double> &binfory, | 411 const std::vector<double> &binfory, |
433 bool usePeaksCache, | 412 bool usePeaksCache, |
434 MagnitudeRange &overallMag, | 413 MagnitudeRange &overallMag, |
435 bool &overallMagChanged) const; | 414 bool &overallMagChanged, |
436 bool paintDrawBufferPeakFrequencies(View *v, int w, int h, | 415 bool rightToLeft, |
437 const std::vector<int> &binforx, | 416 double softTimeLimit) const; |
438 int minbin, | 417 int paintDrawBufferPeakFrequencies(LayerGeometryProvider *v, int w, int h, |
439 int maxbin, | 418 const std::vector<int> &binforx, |
440 double displayMinFreq, | 419 int minbin, |
441 double displayMaxFreq, | 420 int maxbin, |
442 bool logarithmic, | 421 double displayMinFreq, |
443 MagnitudeRange &overallMag, | 422 double displayMaxFreq, |
444 bool &overallMagChanged) const; | 423 bool logarithmic, |
445 | 424 MagnitudeRange &overallMag, |
446 virtual void updateMeasureRectYCoords(View *v, const MeasureRect &r) const; | 425 bool &overallMagChanged, |
447 virtual void setMeasureRectYCoord(View *v, MeasureRect &r, bool start, int y) const; | 426 bool rightToLeft, |
427 double softTimeLimit) const; | |
428 | |
429 virtual void updateMeasureRectYCoords(LayerGeometryProvider *v, const MeasureRect &r) const; | |
430 virtual void setMeasureRectYCoord(LayerGeometryProvider *v, MeasureRect &r, bool start, int y) const; | |
448 }; | 431 }; |
449 | 432 |
450 #endif | 433 #endif |