Chris@58
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@59
|
4 Sonic Visualiser
|
Chris@59
|
5 An audio file viewer and annotation editor.
|
Chris@59
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@182
|
7 This file copyright 2006 Chris Cannam and QMUL.
|
Chris@0
|
8
|
Chris@59
|
9 This program is free software; you can redistribute it and/or
|
Chris@59
|
10 modify it under the terms of the GNU General Public License as
|
Chris@59
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@59
|
12 License, or (at your option) any later version. See the file
|
Chris@59
|
13 COPYING included with this distribution for more information.
|
Chris@0
|
14 */
|
Chris@0
|
15
|
Chris@1030
|
16 #ifndef SPECTROGRAM_LAYER_H
|
Chris@1030
|
17 #define SPECTROGRAM_LAYER_H
|
Chris@0
|
18
|
Chris@193
|
19 #include "SliceableLayer.h"
|
Chris@0
|
20 #include "base/Window.h"
|
Chris@1058
|
21 #include "base/MagnitudeRange.h"
|
Chris@71
|
22 #include "base/RealTime.h"
|
Chris@92
|
23 #include "base/Thread.h"
|
Chris@122
|
24 #include "base/PropertyContainer.h"
|
Chris@128
|
25 #include "data/model/PowerOfSqrtTwoZoomConstraint.h"
|
Chris@128
|
26 #include "data/model/DenseTimeValueModel.h"
|
Chris@130
|
27 #include "data/model/FFTModel.h"
|
Chris@0
|
28
|
Chris@1030
|
29 #include "ScrollableImageCache.h"
|
Chris@1085
|
30 #include "VerticalBinLayer.h"
|
Chris@1092
|
31 #include "ColourScale.h"
|
Chris@1093
|
32 #include "Colour3DPlotRenderer.h"
|
Chris@1030
|
33
|
Chris@0
|
34 #include <QMutex>
|
Chris@0
|
35 #include <QWaitCondition>
|
Chris@95
|
36 #include <QImage>
|
Chris@95
|
37 #include <QPixmap>
|
Chris@0
|
38
|
Chris@0
|
39 class View;
|
Chris@0
|
40 class QPainter;
|
Chris@0
|
41 class QImage;
|
Chris@0
|
42 class QPixmap;
|
Chris@0
|
43 class QTimer;
|
Chris@130
|
44 class FFTModel;
|
Chris@484
|
45 class Dense3DModelPeakCache;
|
Chris@0
|
46
|
Chris@0
|
47 /**
|
Chris@0
|
48 * SpectrogramLayer represents waveform data (obtained from a
|
Chris@0
|
49 * DenseTimeValueModel) in spectrogram form.
|
Chris@0
|
50 */
|
Chris@0
|
51
|
Chris@193
|
52 class SpectrogramLayer : public SliceableLayer,
|
Chris@1085
|
53 public VerticalBinLayer,
|
Chris@31
|
54 public PowerOfSqrtTwoZoomConstraint
|
Chris@0
|
55 {
|
Chris@0
|
56 Q_OBJECT
|
Chris@0
|
57
|
Chris@0
|
58 public:
|
Chris@37
|
59 enum Configuration { FullRangeDb, MelodicRange, MelodicPeaks };
|
Chris@0
|
60
|
Chris@44
|
61 SpectrogramLayer(Configuration = FullRangeDb);
|
Chris@0
|
62 ~SpectrogramLayer();
|
Chris@0
|
63
|
Chris@0
|
64 virtual const ZoomConstraint *getZoomConstraint() const { return this; }
|
Chris@0
|
65 virtual const Model *getModel() const { return m_model; }
|
Chris@916
|
66 virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const;
|
Chris@389
|
67 virtual void setSynchronousPainting(bool synchronous);
|
Chris@0
|
68
|
Chris@918
|
69 virtual int getVerticalScaleWidth(LayerGeometryProvider *v, bool detailed, QPainter &) const;
|
Chris@918
|
70 virtual void paintVerticalScale(LayerGeometryProvider *v, bool detailed, QPainter &paint, QRect rect) const;
|
Chris@0
|
71
|
Chris@918
|
72 virtual bool getCrosshairExtents(LayerGeometryProvider *, QPainter &, QPoint cursorPos,
|
Chris@77
|
73 std::vector<QRect> &extents) const;
|
Chris@918
|
74 virtual void paintCrosshairs(LayerGeometryProvider *, QPainter &, QPoint) const;
|
Chris@77
|
75
|
Chris@918
|
76 virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const;
|
Chris@0
|
77
|
Chris@918
|
78 virtual bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
|
Chris@805
|
79 int &resolution,
|
Chris@28
|
80 SnapType snap) const;
|
Chris@13
|
81
|
Chris@918
|
82 virtual void measureDoubleClick(LayerGeometryProvider *, QMouseEvent *);
|
Chris@283
|
83
|
Chris@224
|
84 virtual bool hasLightBackground() const;
|
Chris@224
|
85
|
Chris@0
|
86 void setModel(const DenseTimeValueModel *model);
|
Chris@0
|
87
|
Chris@0
|
88 virtual PropertyList getProperties() const;
|
Chris@87
|
89 virtual QString getPropertyLabel(const PropertyName &) const;
|
Chris@335
|
90 virtual QString getPropertyIconName(const PropertyName &) const;
|
Chris@0
|
91 virtual PropertyType getPropertyType(const PropertyName &) const;
|
Chris@0
|
92 virtual QString getPropertyGroupName(const PropertyName &) const;
|
Chris@0
|
93 virtual int getPropertyRangeAndValue(const PropertyName &,
|
Chris@216
|
94 int *min, int *max, int *deflt) const;
|
Chris@0
|
95 virtual QString getPropertyValueLabel(const PropertyName &,
|
Chris@0
|
96 int value) const;
|
Chris@862
|
97 virtual QString getPropertyValueIconName(const PropertyName &,
|
Chris@862
|
98 int value) const;
|
Chris@167
|
99 virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const;
|
Chris@0
|
100 virtual void setProperty(const PropertyName &, int value);
|
Chris@0
|
101
|
Chris@0
|
102 /**
|
Chris@0
|
103 * Specify the channel to use from the source model.
|
Chris@0
|
104 * A value of -1 means to mix all available channels.
|
Chris@0
|
105 * The default is channel 0.
|
Chris@0
|
106 */
|
Chris@0
|
107 void setChannel(int);
|
Chris@0
|
108 int getChannel() const;
|
Chris@0
|
109
|
Chris@805
|
110 void setWindowSize(int);
|
Chris@805
|
111 int getWindowSize() const;
|
Chris@0
|
112
|
Chris@805
|
113 void setWindowHopLevel(int level);
|
Chris@805
|
114 int getWindowHopLevel() const;
|
Chris@0
|
115
|
Chris@0
|
116 void setWindowType(WindowType type);
|
Chris@0
|
117 WindowType getWindowType() const;
|
Chris@0
|
118
|
Chris@0
|
119 /**
|
Chris@110
|
120 * Set the gain multiplier for sample values in this view.
|
Chris@0
|
121 * The default is 1.0.
|
Chris@0
|
122 */
|
Chris@0
|
123 void setGain(float gain);
|
Chris@0
|
124 float getGain() const;
|
Chris@0
|
125
|
Chris@37
|
126 /**
|
Chris@110
|
127 * Set the threshold for sample values to qualify for being shown
|
Chris@110
|
128 * in the FFT, in voltage units.
|
Chris@37
|
129 *
|
Chris@37
|
130 * The default is 0.0.
|
Chris@37
|
131 */
|
Chris@37
|
132 void setThreshold(float threshold);
|
Chris@37
|
133 float getThreshold() const;
|
Chris@37
|
134
|
Chris@805
|
135 void setMinFrequency(int);
|
Chris@805
|
136 int getMinFrequency() const;
|
Chris@37
|
137
|
Chris@805
|
138 void setMaxFrequency(int); // 0 -> no maximum
|
Chris@805
|
139 int getMaxFrequency() const;
|
Chris@0
|
140
|
Chris@0
|
141 /**
|
Chris@1092
|
142 * Specify the scale for sample levels. See ColourScale and
|
Chris@1092
|
143 * WaveformLayer for comparison and details of meter and dB
|
Chris@1092
|
144 * scaling. The default is LogColourScale.
|
Chris@0
|
145 */
|
Chris@1105
|
146 void setColourScale(ColourScaleType);
|
Chris@1105
|
147 ColourScaleType getColourScale() const;
|
Chris@0
|
148
|
Chris@0
|
149 /**
|
Chris@0
|
150 * Specify the scale for the y axis.
|
Chris@0
|
151 */
|
Chris@1103
|
152 void setBinScale(BinScale);
|
Chris@1103
|
153 BinScale getBinScale() const;
|
Chris@0
|
154
|
Chris@35
|
155 /**
|
Chris@35
|
156 * Specify the processing of frequency bins for the y axis.
|
Chris@35
|
157 */
|
Chris@1103
|
158 void setBinDisplay(BinDisplay);
|
Chris@1103
|
159 BinDisplay getBinDisplay() const;
|
Chris@862
|
160
|
Chris@719
|
161 /**
|
Chris@1104
|
162 * Specify the normalization mode for individual columns.
|
Chris@719
|
163 */
|
Chris@1104
|
164 void setNormalization(ColumnNormalization);
|
Chris@1104
|
165 ColumnNormalization getNormalization() const;
|
Chris@1104
|
166
|
Chris@1104
|
167 /**
|
Chris@1104
|
168 * Specify whether to normalize the visible area.
|
Chris@1104
|
169 */
|
Chris@1104
|
170 void setNormalizeVisibleArea(bool);
|
Chris@1104
|
171 bool getNormalizeVisibleArea() const;
|
Chris@120
|
172
|
Chris@719
|
173 /**
|
Chris@862
|
174 * Specify the colour map. See ColourMapper for the colour map
|
Chris@862
|
175 * values.
|
Chris@719
|
176 */
|
Chris@197
|
177 void setColourMap(int map);
|
Chris@197
|
178 int getColourMap() const;
|
Chris@0
|
179
|
Chris@9
|
180 /**
|
Chris@9
|
181 * Specify the colourmap rotation for the colour scale.
|
Chris@9
|
182 */
|
Chris@9
|
183 void setColourRotation(int);
|
Chris@9
|
184 int getColourRotation() const;
|
Chris@9
|
185
|
Chris@0
|
186 virtual VerticalPosition getPreferredFrameCountPosition() const {
|
Chris@0
|
187 return PositionTop;
|
Chris@0
|
188 }
|
Chris@0
|
189
|
Chris@15
|
190 virtual bool isLayerOpaque() const { return true; }
|
Chris@287
|
191
|
Chris@287
|
192 virtual ColourSignificance getLayerColourSignificance() const {
|
Chris@287
|
193 return ColourHasMeaningfulValue;
|
Chris@287
|
194 }
|
Chris@15
|
195
|
Chris@918
|
196 double getYForFrequency(const LayerGeometryProvider *v, double frequency) const;
|
Chris@918
|
197 double getFrequencyForY(const LayerGeometryProvider *v, int y) const;
|
Chris@42
|
198
|
Chris@1085
|
199 //!!! VerticalBinLayer methods. Note overlap with get*BinRange()
|
Chris@1085
|
200 double getYForBin(LayerGeometryProvider *, double bin) const;
|
Chris@1085
|
201 double getBinForY(LayerGeometryProvider *, double y) const;
|
Chris@1085
|
202
|
Chris@918
|
203 virtual int getCompletion(LayerGeometryProvider *v) const;
|
Chris@918
|
204 virtual QString getError(LayerGeometryProvider *v) const;
|
Chris@0
|
205
|
Chris@905
|
206 virtual bool getValueExtents(double &min, double &max,
|
Chris@101
|
207 bool &logarithmic, QString &unit) const;
|
Chris@101
|
208
|
Chris@905
|
209 virtual bool getDisplayExtents(double &min, double &max) const;
|
Chris@79
|
210
|
Chris@905
|
211 virtual bool setDisplayExtents(double min, double max);
|
Chris@120
|
212
|
Chris@918
|
213 virtual bool getYScaleValue(const LayerGeometryProvider *, int, double &, QString &) const;
|
Chris@261
|
214
|
Chris@316
|
215 virtual void toXml(QTextStream &stream, QString indent = "",
|
Chris@316
|
216 QString extraAttributes = "") const;
|
Chris@6
|
217
|
Chris@11
|
218 void setProperties(const QXmlAttributes &attributes);
|
Chris@11
|
219
|
Chris@918
|
220 virtual void setLayerDormant(const LayerGeometryProvider *v, bool dormant);
|
Chris@29
|
221
|
Chris@918
|
222 virtual bool isLayerScrollable(const LayerGeometryProvider *) const { return false; }
|
Chris@94
|
223
|
Chris@133
|
224 virtual int getVerticalZoomSteps(int &defaultStep) const;
|
Chris@133
|
225 virtual int getCurrentVerticalZoomStep() const;
|
Chris@133
|
226 virtual void setVerticalZoomStep(int);
|
Chris@187
|
227 virtual RangeMapper *getNewVerticalZoomRangeMapper() const;
|
Chris@133
|
228
|
Chris@193
|
229 virtual const Model *getSliceableModel() const;
|
Chris@193
|
230
|
Chris@0
|
231 protected slots:
|
Chris@0
|
232 void cacheInvalid();
|
Chris@906
|
233 void cacheInvalid(sv_frame_t startFrame, sv_frame_t endFrame);
|
Chris@122
|
234
|
Chris@122
|
235 void preferenceChanged(PropertyContainer::PropertyName name);
|
Chris@0
|
236
|
Chris@0
|
237 protected:
|
Chris@0
|
238 const DenseTimeValueModel *m_model; // I do not own this
|
Chris@484
|
239
|
Chris@35
|
240 int m_channel;
|
Chris@1023
|
241 int m_windowSize;
|
Chris@35
|
242 WindowType m_windowType;
|
Chris@1023
|
243 int m_windowHopLevel;
|
Chris@35
|
244 float m_gain;
|
Chris@215
|
245 float m_initialGain;
|
Chris@37
|
246 float m_threshold;
|
Chris@215
|
247 float m_initialThreshold;
|
Chris@35
|
248 int m_colourRotation;
|
Chris@215
|
249 int m_initialRotation;
|
Chris@1023
|
250 int m_minFrequency;
|
Chris@1023
|
251 int m_maxFrequency;
|
Chris@1023
|
252 int m_initialMaxFrequency;
|
Chris@1105
|
253 ColourScaleType m_colourScale;
|
Chris@197
|
254 int m_colourMap;
|
Chris@77
|
255 QColor m_crosshairColour;
|
Chris@1104
|
256 BinScale m_binScale;
|
Chris@1104
|
257 BinDisplay m_binDisplay;
|
Chris@1104
|
258 ColumnNormalization m_normalization; // of individual columns
|
Chris@1104
|
259 bool m_normalizeVisibleArea;
|
Chris@133
|
260 int m_lastEmittedZoomStep;
|
Chris@389
|
261 bool m_synchronous;
|
Chris@0
|
262
|
Chris@608
|
263 mutable bool m_haveDetailedScale;
|
Chris@215
|
264
|
Chris@1105
|
265 static ColourScaleType convertToColourScale(int value);
|
Chris@1105
|
266 static int convertFromColourScale(ColourScaleType);
|
Chris@1104
|
267 static std::pair<ColumnNormalization, bool> convertToColumnNorm(int value);
|
Chris@1104
|
268 static int convertFromColumnNorm(ColumnNormalization norm, bool visible);
|
Chris@1104
|
269
|
Chris@38
|
270 enum { NO_VALUE = 0 }; // colour index for unused pixels
|
Chris@38
|
271
|
Chris@197
|
272 class Palette
|
Chris@86
|
273 {
|
Chris@86
|
274 public:
|
Chris@86
|
275 QColor getColour(unsigned char index) const {
|
Chris@86
|
276 return m_colours[index];
|
Chris@86
|
277 }
|
Chris@86
|
278
|
Chris@86
|
279 void setColour(unsigned char index, QColor colour) {
|
Chris@86
|
280 m_colours[index] = colour;
|
Chris@86
|
281 }
|
Chris@86
|
282
|
Chris@86
|
283 private:
|
Chris@86
|
284 QColor m_colours[256];
|
Chris@86
|
285 };
|
Chris@86
|
286
|
Chris@197
|
287 Palette m_palette;
|
Chris@31
|
288
|
Chris@1030
|
289 typedef std::map<int, ScrollableImageCache> ViewImageCache; // key is view id
|
Chris@478
|
290 void invalidateImageCaches();
|
Chris@478
|
291 mutable ViewImageCache m_imageCaches;
|
Chris@1030
|
292 ScrollableImageCache &getImageCacheReference(const LayerGeometryProvider *) const;
|
Chris@477
|
293
|
Chris@477
|
294 /**
|
Chris@477
|
295 * When painting, we draw directly onto the draw buffer and then
|
Chris@478
|
296 * copy this to the part of the image cache that needed refreshing
|
Chris@478
|
297 * before copying the image cache onto the window. (Remind me why
|
Chris@1073
|
298 * we don't draw directly onto the cache?) (Answer: it's because
|
Chris@1073
|
299 * we usually apply scaling and smoothing in the x axis when
|
Chris@1073
|
300 * copying from draw buffer to cache)
|
Chris@477
|
301 */
|
Chris@95
|
302 mutable QImage m_drawBuffer;
|
Chris@0
|
303
|
Chris@0
|
304 bool m_exiting;
|
Chris@0
|
305
|
Chris@197
|
306 void initialisePalette();
|
Chris@197
|
307 void rotatePalette(int distance);
|
Chris@0
|
308
|
Chris@918
|
309 unsigned char getDisplayValue(LayerGeometryProvider *v, double input) const;
|
Chris@40
|
310
|
Chris@40
|
311 int getColourScaleWidth(QPainter &) const;
|
Chris@40
|
312
|
Chris@918
|
313 void illuminateLocalFeatures(LayerGeometryProvider *v, QPainter &painter) const;
|
Chris@121
|
314
|
Chris@905
|
315 double getEffectiveMinFrequency() const;
|
Chris@905
|
316 double getEffectiveMaxFrequency() const;
|
Chris@38
|
317
|
Chris@918
|
318 bool getXBinRange(LayerGeometryProvider *v, int x, double &windowMin, double &windowMax) const;
|
Chris@918
|
319 bool getYBinRange(LayerGeometryProvider *v, int y, double &freqBinMin, double &freqBinMax) const;
|
Chris@0
|
320
|
Chris@918
|
321 bool getYBinSourceRange(LayerGeometryProvider *v, int y, double &freqMin, double &freqMax) const;
|
Chris@918
|
322 bool getAdjustedYBinSourceRange(LayerGeometryProvider *v, int x, int y,
|
Chris@905
|
323 double &freqMin, double &freqMax,
|
Chris@905
|
324 double &adjFreqMin, double &adjFreqMax) const;
|
Chris@918
|
325 bool getXBinSourceRange(LayerGeometryProvider *v, int x, RealTime &timeMin, RealTime &timeMax) const;
|
Chris@918
|
326 bool getXYBinSourceRange(LayerGeometryProvider *v, int x, int y, double &min, double &max,
|
Chris@905
|
327 double &phaseMin, double &phaseMax) const;
|
Chris@0
|
328
|
Chris@805
|
329 int getWindowIncrement() const {
|
Chris@97
|
330 if (m_windowHopLevel == 0) return m_windowSize;
|
Chris@97
|
331 else if (m_windowHopLevel == 1) return (m_windowSize * 3) / 4;
|
Chris@97
|
332 else return m_windowSize / (1 << (m_windowHopLevel - 1));
|
Chris@0
|
333 }
|
Chris@113
|
334
|
Chris@1086
|
335 int getFFTOversampling() const;
|
Chris@1087
|
336 int getFFTSize() const; // m_windowSize * getFFTOversampling()
|
Chris@115
|
337
|
Chris@1089
|
338 mutable FFTModel *m_fftModel; //!!! should not be mutable, see getFFTModel()?
|
Chris@1088
|
339 mutable Dense3DModelPeakCache *m_peakCache;
|
Chris@1054
|
340 const int m_peakCacheDivisor;
|
Chris@119
|
341
|
Chris@1030
|
342 typedef std::map<int, MagnitudeRange> ViewMagMap; // key is view id
|
Chris@119
|
343 mutable ViewMagMap m_viewMags;
|
Chris@119
|
344 mutable std::vector<MagnitudeRange> m_columnMags;
|
Chris@119
|
345 void invalidateMagnitudes();
|
Chris@918
|
346 bool updateViewMagnitudes(LayerGeometryProvider *v) const;
|
Chris@1089
|
347
|
Chris@1089
|
348 typedef std::map<int, Colour3DPlotRenderer *> ViewRendererMap; // key is view id
|
Chris@1089
|
349 mutable ViewRendererMap m_renderers;
|
Chris@1089
|
350 Colour3DPlotRenderer *getRenderer(LayerGeometryProvider *) const;
|
Chris@1058
|
351
|
Chris@1088
|
352 FFTModel *getFFTModel() const;
|
Chris@1088
|
353 Dense3DModelPeakCache *getPeakCache() const;
|
Chris@1088
|
354 void invalidateFFTModel();
|
Chris@1089
|
355
|
Chris@1089
|
356 void paintAlternative(LayerGeometryProvider *v, QPainter &paint, QRect rect) const;
|
Chris@1088
|
357
|
Chris@1024
|
358 int paintDrawBuffer(LayerGeometryProvider *v, int w, int h,
|
Chris@1024
|
359 const std::vector<int> &binforx,
|
Chris@1024
|
360 const std::vector<double> &binfory,
|
Chris@1024
|
361 bool usePeaksCache,
|
Chris@1024
|
362 MagnitudeRange &overallMag,
|
Chris@1026
|
363 bool &overallMagChanged,
|
Chris@1039
|
364 bool rightToLeft,
|
Chris@1039
|
365 double softTimeLimit) const;
|
Chris@1024
|
366 int paintDrawBufferPeakFrequencies(LayerGeometryProvider *v, int w, int h,
|
Chris@1024
|
367 const std::vector<int> &binforx,
|
Chris@1024
|
368 int minbin,
|
Chris@1024
|
369 int maxbin,
|
Chris@1024
|
370 double displayMinFreq,
|
Chris@1024
|
371 double displayMaxFreq,
|
Chris@1024
|
372 bool logarithmic,
|
Chris@1024
|
373 MagnitudeRange &overallMag,
|
Chris@1026
|
374 bool &overallMagChanged,
|
Chris@1039
|
375 bool rightToLeft,
|
Chris@1039
|
376 double softTimeLimit) const;
|
Chris@273
|
377
|
Chris@1058
|
378 std::vector<float> getColumnFromFFTModel(FFTModel *model,
|
Chris@1058
|
379 int sx,
|
Chris@1058
|
380 int minbin,
|
Chris@1058
|
381 int bincount) const;
|
Chris@1058
|
382
|
Chris@1058
|
383 std::vector<float> getColumnFromGenericModel(DenseThreeDimensionalModel *model,
|
Chris@1058
|
384 int sx,
|
Chris@1058
|
385 int minbin,
|
Chris@1058
|
386 int bincount) const;
|
Chris@1058
|
387
|
Chris@1059
|
388 void recordColumnExtents(const std::vector<float> &col,
|
Chris@1059
|
389 int sx,
|
Chris@1059
|
390 MagnitudeRange &overallMag,
|
Chris@1059
|
391 bool &overallMagChanged) const;
|
Chris@1058
|
392
|
Chris@1058
|
393 virtual void updateMeasureRectYCoords(LayerGeometryProvider *v,
|
Chris@1058
|
394 const MeasureRect &r) const;
|
Chris@1058
|
395 virtual void setMeasureRectYCoord(LayerGeometryProvider *v,
|
Chris@1058
|
396 MeasureRect &r, bool start, int y) const;
|
Chris@0
|
397 };
|
Chris@0
|
398
|
Chris@0
|
399 #endif
|