comparison layer/SpectrumLayer.h @ 1238:4d0ca1ab4cd0

Some work to make spectrum layers (and slice layers generally) zoomable in the frequency axis. Also fixes a number of view id mixups in SliceLayer which broke offset calculations for the x axis scale.
author Chris Cannam
date Tue, 07 Feb 2017 14:55:19 +0000
parents 366ffdf719cd
children b7d3bd4ff43b
comparison
equal deleted inserted replaced
1237:2cc9e0e5df51 1238:4d0ca1ab4cd0
12 published by the Free Software Foundation; either version 2 of the 12 published by the Free Software Foundation; either version 2 of the
13 License, or (at your option) any later version. See the file 13 License, or (at your option) any later version. See the file
14 COPYING included with this distribution for more information. 14 COPYING included with this distribution for more information.
15 */ 15 */
16 16
17 #ifndef _SPECTRUM_LAYER_H_ 17 #ifndef SV_SPECTRUM_LAYER_H
18 #define _SPECTRUM_LAYER_H_ 18 #define SV_SPECTRUM_LAYER_H
19 19
20 #include "SliceLayer.h" 20 #include "SliceLayer.h"
21 21
22 #include "base/Window.h" 22 #include "base/Window.h"
23 23
24 #include "data/model/DenseTimeValueModel.h" 24 #include "data/model/DenseTimeValueModel.h"
25 25
26 #include "PianoScale.h"
27
26 #include <QColor> 28 #include <QColor>
27 #include <QMutex> 29 #include <QMutex>
28 30
29 class FFTModel; 31 class FFTModel;
30 32
31 class SpectrumLayer : public SliceLayer 33 class SpectrumLayer : public SliceLayer,
34 public PianoScale::HorizontalScaleProvider
32 { 35 {
33 Q_OBJECT 36 Q_OBJECT
34 37
35 public: 38 public:
36 SpectrumLayer(); 39 SpectrumLayer();
62 int value) const; 65 int value) const;
63 virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const; 66 virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const;
64 virtual void setProperty(const PropertyName &, int value); 67 virtual void setProperty(const PropertyName &, int value);
65 virtual void setProperties(const QXmlAttributes &); 68 virtual void setProperties(const QXmlAttributes &);
66 69
67 virtual bool getValueExtents(double &min, double &max,
68 bool &logarithmic, QString &unit) const;
69
70 virtual bool getXScaleValue(const LayerGeometryProvider *v, int x, 70 virtual bool getXScaleValue(const LayerGeometryProvider *v, int x,
71 double &value, QString &unit) const; 71 double &value, QString &unit) const;
72 72
73 virtual bool getYScaleValue(const LayerGeometryProvider *, int y, 73 virtual bool getYScaleValue(const LayerGeometryProvider *, int y,
74 double &value, QString &unit) const; 74 double &value, QString &unit) const;
94 bool getShowPeaks() const { return m_showPeaks; } 94 bool getShowPeaks() const { return m_showPeaks; }
95 95
96 virtual void toXml(QTextStream &stream, QString indent = "", 96 virtual void toXml(QTextStream &stream, QString indent = "",
97 QString extraAttributes = "") const; 97 QString extraAttributes = "") const;
98 98
99 virtual double getFrequencyForX(const LayerGeometryProvider *,
100 double x) const override;
101 virtual double getXForFrequency(const LayerGeometryProvider *,
102 double freq) const override;
103
99 protected slots: 104 protected slots:
100 void preferenceChanged(PropertyContainer::PropertyName name); 105 void preferenceChanged(PropertyContainer::PropertyName name);
101 106
102 protected: 107 protected:
103 // make this SliceLayer method unavailable to the general public
104 // virtual void setModel(DenseThreeDimensionalModel *model) {
105 // SliceLayer::setModel(model);
106 // }
107
108 DenseTimeValueModel *m_originModel; 108 DenseTimeValueModel *m_originModel;
109 int m_channel; 109 int m_channel;
110 bool m_channelSet; 110 bool m_channelSet;
111 int m_windowSize; 111 int m_windowSize;
112 WindowType m_windowType; 112 WindowType m_windowType;
119 void setupFFT(); 119 void setupFFT();
120 120
121 virtual void getBiasCurve(BiasCurve &) const; 121 virtual void getBiasCurve(BiasCurve &) const;
122 BiasCurve m_biasCurve; 122 BiasCurve m_biasCurve;
123 123
124 virtual double getXForBin(int bin, int totalBins, double w) const;
125 virtual int getBinForX(double x, int totalBins, double w) const;
126
127 double getFrequencyForX(double x, double w) const;
128 double getXForFrequency(double freq, double w) const;
129
130 int getWindowIncrement() const { 124 int getWindowIncrement() const {
131 if (m_windowHopLevel == 0) return m_windowSize; 125 if (m_windowHopLevel == 0) return m_windowSize;
132 else if (m_windowHopLevel == 1) return (m_windowSize * 3) / 4; 126 else if (m_windowHopLevel == 1) return (m_windowSize * 3) / 4;
133 else return m_windowSize / (1 << (m_windowHopLevel - 1)); 127 else return m_windowSize / (1 << (m_windowHopLevel - 1));
134 } 128 }