comparison layer/SpectrogramLayer.h @ 1043:fccee028a522 3.0-integration

Merge from branch "spectrogram-minor-refactor"
author Chris Cannam
date Thu, 04 Feb 2016 11:18:08 +0000
parents bfce7940c017
children 5e5873c24142
comparison
equal deleted inserted replaced
1042:cd9e76e755bf 1043:fccee028a522
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
28 #include "ScrollableImageCache.h"
27 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>
248 250
249 protected: 251 protected:
250 const DenseTimeValueModel *m_model; // I do not own this 252 const DenseTimeValueModel *m_model; // I do not own this
251 253
252 int m_channel; 254 int m_channel;
253 int m_windowSize; 255 int m_windowSize;
254 WindowType m_windowType; 256 WindowType m_windowType;
255 int m_windowHopLevel; 257 int m_windowHopLevel;
256 int m_zeroPadLevel; 258 int m_zeroPadLevel;
257 int m_fftSize; 259 int m_fftSize;
258 float m_gain; 260 float m_gain;
259 float m_initialGain; 261 float m_initialGain;
260 float m_threshold; 262 float m_threshold;
261 float m_initialThreshold; 263 float m_initialThreshold;
262 int m_colourRotation; 264 int m_colourRotation;
263 int m_initialRotation; 265 int m_initialRotation;
264 int m_minFrequency; 266 int m_minFrequency;
265 int m_maxFrequency; 267 int m_maxFrequency;
266 int m_initialMaxFrequency; 268 int m_initialMaxFrequency;
267 ColourScale m_colourScale; 269 ColourScale m_colourScale;
268 int m_colourMap; 270 int m_colourMap;
269 QColor m_crosshairColour; 271 QColor m_crosshairColour;
270 FrequencyScale m_frequencyScale; 272 FrequencyScale m_frequencyScale;
271 BinDisplay m_binDisplay; 273 BinDisplay m_binDisplay;
272 Normalization m_normalization; 274 Normalization m_normalization;
273 int m_lastEmittedZoomStep; 275 int m_lastEmittedZoomStep;
274 bool m_synchronous; 276 bool m_synchronous;
275 277
276 mutable bool m_haveDetailedScale; 278 mutable bool m_haveDetailedScale;
277 mutable int m_lastPaintBlockWidth;
278 mutable RealTime m_lastPaintTime;
279 279
280 enum { NO_VALUE = 0 }; // colour index for unused pixels 280 enum { NO_VALUE = 0 }; // colour index for unused pixels
281 281
282 class Palette 282 class Palette
283 { 283 {
294 QColor m_colours[256]; 294 QColor m_colours[256];
295 }; 295 };
296 296
297 Palette m_palette; 297 Palette m_palette;
298 298
299 /** 299 typedef std::map<int, ScrollableImageCache> ViewImageCache; // key is view id
300 * ImageCache covers the area of the view, at view resolution.
301 * Not all of it is necessarily valid at once (it is refreshed
302 * in parts when scrolling, for example).
303 */
304 struct ImageCache
305 {
306 QImage image;
307 QRect validArea;
308 sv_frame_t startFrame;
309 int zoomLevel;
310 };
311 typedef std::map<const View *, ImageCache> ViewImageCache;
312 void invalidateImageCaches(); 300 void invalidateImageCaches();
313 void invalidateImageCaches(sv_frame_t startFrame, sv_frame_t endFrame);
314 mutable ViewImageCache m_imageCaches; 301 mutable ViewImageCache m_imageCaches;
302 ScrollableImageCache &getImageCacheReference(const LayerGeometryProvider *) const;
315 303
316 /** 304 /**
317 * When painting, we draw directly onto the draw buffer and then 305 * When painting, we draw directly onto the draw buffer and then
318 * 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
319 * before copying the image cache onto the window. (Remind me why 307 * before copying the image cache onto the window. (Remind me why
363 int getFFTSize(const LayerGeometryProvider *v) const; 351 int getFFTSize(const LayerGeometryProvider *v) const;
364 FFTModel *getFFTModel(const LayerGeometryProvider *v) const; 352 FFTModel *getFFTModel(const LayerGeometryProvider *v) const;
365 Dense3DModelPeakCache *getPeakCache(const LayerGeometryProvider *v) const; 353 Dense3DModelPeakCache *getPeakCache(const LayerGeometryProvider *v) const;
366 void invalidateFFTModels(); 354 void invalidateFFTModels();
367 355
368 typedef std::map<const View *, FFTModel *> ViewFFTMap; 356 typedef std::map<int, FFTModel *> ViewFFTMap; // key is view id
369 typedef std::map<const View *, Dense3DModelPeakCache *> PeakCacheMap; 357 typedef std::map<int, Dense3DModelPeakCache *> PeakCacheMap; // key is view id
370 mutable ViewFFTMap m_fftModels; 358 mutable ViewFFTMap m_fftModels;
371 mutable PeakCacheMap m_peakCaches; 359 mutable PeakCacheMap m_peakCaches;
372 mutable Model *m_sliceableModel; 360 mutable Model *m_sliceableModel;
373 361
374 class MagnitudeRange { 362 class MagnitudeRange {
411 private: 399 private:
412 float m_min; 400 float m_min;
413 float m_max; 401 float m_max;
414 }; 402 };
415 403
416 typedef std::map<const LayerGeometryProvider *, MagnitudeRange> ViewMagMap; 404 typedef std::map<int, MagnitudeRange> ViewMagMap; // key is view id
417 mutable ViewMagMap m_viewMags; 405 mutable ViewMagMap m_viewMags;
418 mutable std::vector<MagnitudeRange> m_columnMags; 406 mutable std::vector<MagnitudeRange> m_columnMags;
419 void invalidateMagnitudes(); 407 void invalidateMagnitudes();
420 bool updateViewMagnitudes(LayerGeometryProvider *v) const; 408 bool updateViewMagnitudes(LayerGeometryProvider *v) const;
421 bool paintDrawBuffer(LayerGeometryProvider *v, int w, int h, 409 int paintDrawBuffer(LayerGeometryProvider *v, int w, int h,
422 const std::vector<int> &binforx, 410 const std::vector<int> &binforx,
423 const std::vector<double> &binfory, 411 const std::vector<double> &binfory,
424 bool usePeaksCache, 412 bool usePeaksCache,
425 MagnitudeRange &overallMag, 413 MagnitudeRange &overallMag,
426 bool &overallMagChanged) const; 414 bool &overallMagChanged,
427 bool paintDrawBufferPeakFrequencies(LayerGeometryProvider *v, int w, int h, 415 bool rightToLeft,
428 const std::vector<int> &binforx, 416 double softTimeLimit) const;
429 int minbin, 417 int paintDrawBufferPeakFrequencies(LayerGeometryProvider *v, int w, int h,
430 int maxbin, 418 const std::vector<int> &binforx,
431 double displayMinFreq, 419 int minbin,
432 double displayMaxFreq, 420 int maxbin,
433 bool logarithmic, 421 double displayMinFreq,
434 MagnitudeRange &overallMag, 422 double displayMaxFreq,
435 bool &overallMagChanged) const; 423 bool logarithmic,
424 MagnitudeRange &overallMag,
425 bool &overallMagChanged,
426 bool rightToLeft,
427 double softTimeLimit) const;
436 428
437 virtual void updateMeasureRectYCoords(LayerGeometryProvider *v, const MeasureRect &r) const; 429 virtual void updateMeasureRectYCoords(LayerGeometryProvider *v, const MeasureRect &r) const;
438 virtual void setMeasureRectYCoord(LayerGeometryProvider *v, MeasureRect &r, bool start, int y) const; 430 virtual void setMeasureRectYCoord(LayerGeometryProvider *v, MeasureRect &r, bool start, int y) const;
439 }; 431 };
440 432