comparison layer/SpectrogramLayer.h @ 1058:9a13bc339fa9 spectrogram-minor-refactor

Mid-refactor to pull out the bulk of paintDrawBuffer into chunks
author Chris Cannam
date Mon, 13 Jun 2016 16:17:44 +0100
parents 5e5873c24142
children e1c2dcc7790e
comparison
equal deleted inserted replaced
1057:218be6cf2d4f 1058:9a13bc339fa9
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/MagnitudeRange.h"
21 #include "base/RealTime.h" 22 #include "base/RealTime.h"
22 #include "base/Thread.h" 23 #include "base/Thread.h"
23 #include "base/PropertyContainer.h" 24 #include "base/PropertyContainer.h"
24 #include "data/model/PowerOfSqrtTwoZoomConstraint.h" 25 #include "data/model/PowerOfSqrtTwoZoomConstraint.h"
25 #include "data/model/DenseTimeValueModel.h" 26 #include "data/model/DenseTimeValueModel.h"
358 mutable ViewFFTMap m_fftModels; 359 mutable ViewFFTMap m_fftModels;
359 mutable PeakCacheMap m_peakCaches; 360 mutable PeakCacheMap m_peakCaches;
360 const int m_peakCacheDivisor; 361 const int m_peakCacheDivisor;
361 mutable Model *m_sliceableModel; 362 mutable Model *m_sliceableModel;
362 363
363 class MagnitudeRange {
364 public:
365 MagnitudeRange() : m_min(0), m_max(0) { }
366 bool operator==(const MagnitudeRange &r) {
367 return r.m_min == m_min && r.m_max == m_max;
368 }
369 bool isSet() const { return (m_min != 0.f || m_max != 0.f); }
370 void set(float min, float max) {
371 m_min = min;
372 m_max = max;
373 if (m_max < m_min) m_max = m_min;
374 }
375 bool sample(float f) {
376 bool changed = false;
377 if (isSet()) {
378 if (f < m_min) { m_min = f; changed = true; }
379 if (f > m_max) { m_max = f; changed = true; }
380 } else {
381 m_max = m_min = f;
382 changed = true;
383 }
384 return changed;
385 }
386 bool sample(const MagnitudeRange &r) {
387 bool changed = false;
388 if (isSet()) {
389 if (r.m_min < m_min) { m_min = r.m_min; changed = true; }
390 if (r.m_max > m_max) { m_max = r.m_max; changed = true; }
391 } else {
392 m_min = r.m_min;
393 m_max = r.m_max;
394 changed = true;
395 }
396 return changed;
397 }
398 float getMin() const { return m_min; }
399 float getMax() const { return m_max; }
400 private:
401 float m_min;
402 float m_max;
403 };
404
405 typedef std::map<int, MagnitudeRange> ViewMagMap; // key is view id 364 typedef std::map<int, MagnitudeRange> ViewMagMap; // key is view id
406 mutable ViewMagMap m_viewMags; 365 mutable ViewMagMap m_viewMags;
407 mutable std::vector<MagnitudeRange> m_columnMags; 366 mutable std::vector<MagnitudeRange> m_columnMags;
408 void invalidateMagnitudes(); 367 void invalidateMagnitudes();
409 bool updateViewMagnitudes(LayerGeometryProvider *v) const; 368 bool updateViewMagnitudes(LayerGeometryProvider *v) const;
369
410 int paintDrawBuffer(LayerGeometryProvider *v, int w, int h, 370 int paintDrawBuffer(LayerGeometryProvider *v, int w, int h,
411 const std::vector<int> &binforx, 371 const std::vector<int> &binforx,
412 const std::vector<double> &binfory, 372 const std::vector<double> &binfory,
413 bool usePeaksCache, 373 bool usePeaksCache,
414 MagnitudeRange &overallMag, 374 MagnitudeRange &overallMag,
425 MagnitudeRange &overallMag, 385 MagnitudeRange &overallMag,
426 bool &overallMagChanged, 386 bool &overallMagChanged,
427 bool rightToLeft, 387 bool rightToLeft,
428 double softTimeLimit) const; 388 double softTimeLimit) const;
429 389
430 virtual void updateMeasureRectYCoords(LayerGeometryProvider *v, const MeasureRect &r) const; 390 void normalise(std::vector<float> &, Normalization norm) const;
431 virtual void setMeasureRectYCoord(LayerGeometryProvider *v, MeasureRect &r, bool start, int y) const; 391
392 std::vector<float> getColumnFromFFTModel(FFTModel *model,
393 int sx,
394 int minbin,
395 int bincount) const;
396
397 std::vector<float> getColumnFromGenericModel(DenseThreeDimensionalModel *model,
398 int sx,
399 int minbin,
400 int bincount) const;
401
402 void scaleColumn(std::vector<float> &col) const;
403
404 virtual void updateMeasureRectYCoords(LayerGeometryProvider *v,
405 const MeasureRect &r) const;
406 virtual void setMeasureRectYCoord(LayerGeometryProvider *v,
407 MeasureRect &r, bool start, int y) const;
432 }; 408 };
433 409
434 #endif 410 #endif