annotate layer/SpectrogramLayer.h @ 1106:8abdefce36a6 spectrogram-minor-refactor

Remove all of the "old" paint logic from SpectrogramLayer, even where it hasn't been completely replaced yet
author Chris Cannam
date Thu, 14 Jul 2016 17:03:40 +0100
parents ea5ae9dd10ba
children 6d720fe1c8cc
rev   line source
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@1106 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@0 270 bool m_exiting;
Chris@0 271
Chris@40 272 int getColourScaleWidth(QPainter &) const;
Chris@40 273
Chris@918 274 void illuminateLocalFeatures(LayerGeometryProvider *v, QPainter &painter) const;
Chris@121 275
Chris@905 276 double getEffectiveMinFrequency() const;
Chris@905 277 double getEffectiveMaxFrequency() const;
Chris@38 278
Chris@918 279 bool getXBinRange(LayerGeometryProvider *v, int x, double &windowMin, double &windowMax) const;
Chris@918 280 bool getYBinRange(LayerGeometryProvider *v, int y, double &freqBinMin, double &freqBinMax) const;
Chris@0 281
Chris@918 282 bool getYBinSourceRange(LayerGeometryProvider *v, int y, double &freqMin, double &freqMax) const;
Chris@918 283 bool getAdjustedYBinSourceRange(LayerGeometryProvider *v, int x, int y,
Chris@905 284 double &freqMin, double &freqMax,
Chris@905 285 double &adjFreqMin, double &adjFreqMax) const;
Chris@918 286 bool getXBinSourceRange(LayerGeometryProvider *v, int x, RealTime &timeMin, RealTime &timeMax) const;
Chris@918 287 bool getXYBinSourceRange(LayerGeometryProvider *v, int x, int y, double &min, double &max,
Chris@905 288 double &phaseMin, double &phaseMax) const;
Chris@0 289
Chris@805 290 int getWindowIncrement() const {
Chris@97 291 if (m_windowHopLevel == 0) return m_windowSize;
Chris@97 292 else if (m_windowHopLevel == 1) return (m_windowSize * 3) / 4;
Chris@97 293 else return m_windowSize / (1 << (m_windowHopLevel - 1));
Chris@0 294 }
Chris@113 295
Chris@1086 296 int getFFTOversampling() const;
Chris@1087 297 int getFFTSize() const; // m_windowSize * getFFTOversampling()
Chris@115 298
Chris@1089 299 mutable FFTModel *m_fftModel; //!!! should not be mutable, see getFFTModel()?
Chris@1088 300 mutable Dense3DModelPeakCache *m_peakCache;
Chris@1054 301 const int m_peakCacheDivisor;
Chris@119 302
Chris@1030 303 typedef std::map<int, MagnitudeRange> ViewMagMap; // key is view id
Chris@119 304 mutable ViewMagMap m_viewMags;
Chris@119 305 mutable std::vector<MagnitudeRange> m_columnMags;
Chris@119 306 void invalidateMagnitudes();
Chris@918 307 bool updateViewMagnitudes(LayerGeometryProvider *v) const;
Chris@1089 308
Chris@1089 309 typedef std::map<int, Colour3DPlotRenderer *> ViewRendererMap; // key is view id
Chris@1089 310 mutable ViewRendererMap m_renderers;
Chris@1089 311 Colour3DPlotRenderer *getRenderer(LayerGeometryProvider *) const;
Chris@1106 312 void invalidateRenderers();
Chris@1058 313
Chris@1088 314 FFTModel *getFFTModel() const;
Chris@1088 315 Dense3DModelPeakCache *getPeakCache() const;
Chris@1088 316 void invalidateFFTModel();
Chris@1089 317
Chris@1106 318 void paintWithRenderer(LayerGeometryProvider *v, QPainter &paint, QRect rect) const;
Chris@1058 319
Chris@1058 320 virtual void updateMeasureRectYCoords(LayerGeometryProvider *v,
Chris@1058 321 const MeasureRect &r) const;
Chris@1058 322 virtual void setMeasureRectYCoord(LayerGeometryProvider *v,
Chris@1058 323 MeasureRect &r, bool start, int y) const;
Chris@0 324 };
Chris@0 325
Chris@0 326 #endif