annotate layer/SliceLayer.h @ 1389:1eb560b363e7 spectrogramparam

Make "zoom to region" work sensibly for slice/spectrum layers; ensure that min/max bin are remapped properly when changing fft size
author Chris Cannam
date Tue, 13 Nov 2018 14:06:48 +0000
parents fc3d89f88690
children 3c99083a4d83
rev   line source
Chris@133 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@133 2
Chris@133 3 /*
Chris@133 4 Sonic Visualiser
Chris@133 5 An audio file viewer and annotation editor.
Chris@133 6 Centre for Digital Music, Queen Mary, University of London.
Chris@182 7 This file copyright 2006 QMUL.
Chris@133 8
Chris@133 9 This program is free software; you can redistribute it and/or
Chris@133 10 modify it under the terms of the GNU General Public License as
Chris@133 11 published by the Free Software Foundation; either version 2 of the
Chris@133 12 License, or (at your option) any later version. See the file
Chris@133 13 COPYING included with this distribution for more information.
Chris@133 14 */
Chris@133 15
Chris@1284 16 #ifndef SV_SLICE_LAYER_H
Chris@1284 17 #define SV_SLICE_LAYER_H
Chris@133 18
Chris@287 19 #include "SingleColourLayer.h"
Chris@133 20
Chris@153 21 #include "base/Window.h"
Chris@153 22
Chris@193 23 #include "data/model/DenseThreeDimensionalModel.h"
Chris@133 24
Chris@133 25 #include <QColor>
Chris@133 26
Chris@287 27 class SliceLayer : public SingleColourLayer
Chris@133 28 {
Chris@133 29 Q_OBJECT
Chris@133 30
Chris@133 31 public:
Chris@193 32 SliceLayer();
Chris@193 33 ~SliceLayer();
Chris@133 34
Chris@193 35 virtual const Model *getModel() const { return 0; }
Chris@193 36
Chris@193 37 void setSliceableModel(const Model *model);
Chris@193 38
Chris@916 39 virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const;
Chris@133 40
Chris@918 41 virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const;
Chris@198 42
Chris@918 43 virtual int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const;
Chris@918 44 virtual void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const;
Chris@195 45
Chris@1383 46 virtual int getHorizontalScaleHeight(LayerGeometryProvider *, QPainter &) const { return 0; }
Chris@1383 47
Chris@287 48 virtual ColourSignificance getLayerColourSignificance() const {
Chris@287 49 return ColourAndBackgroundSignificant;
Chris@287 50 }
Chris@287 51
Chris@1281 52 virtual bool hasLightBackground() const;
Chris@1281 53
Chris@153 54 virtual PropertyList getProperties() const;
Chris@153 55 virtual QString getPropertyLabel(const PropertyName &) const;
Chris@335 56 virtual QString getPropertyIconName(const PropertyName &) const;
Chris@153 57 virtual PropertyType getPropertyType(const PropertyName &) const;
Chris@153 58 virtual QString getPropertyGroupName(const PropertyName &) const;
Chris@153 59 virtual int getPropertyRangeAndValue(const PropertyName &,
Chris@216 60 int *min, int *max, int *deflt) const;
Chris@153 61 virtual QString getPropertyValueLabel(const PropertyName &,
Chris@1266 62 int value) const;
Chris@167 63 virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const;
Chris@153 64 virtual void setProperty(const PropertyName &, int value);
Chris@133 65 virtual void setProperties(const QXmlAttributes &);
Chris@133 66
Chris@905 67 virtual bool getValueExtents(double &min, double &max,
Chris@133 68 bool &logarithmic, QString &unit) const;
Chris@133 69
Chris@1238 70 virtual bool getDisplayExtents(double &min, double &max) const;
Chris@1238 71 virtual bool setDisplayExtents(double min, double max);
Chris@1238 72
Chris@1238 73 virtual int getVerticalZoomSteps(int &defaultStep) const;
Chris@1238 74 virtual int getCurrentVerticalZoomStep() const;
Chris@1238 75 virtual void setVerticalZoomStep(int);
Chris@1238 76 virtual RangeMapper *getNewVerticalZoomRangeMapper() const;
Chris@1238 77
Chris@1389 78 virtual bool hasTimeXAxis() const override { return false; }
Chris@1389 79
Chris@1389 80 virtual void zoomToRegion(const LayerGeometryProvider *, QRect) override;
Chris@217 81
Chris@918 82 virtual bool isLayerScrollable(const LayerGeometryProvider *) const { return false; }
Chris@133 83
Chris@538 84 enum EnergyScale { LinearScale, MeterScale, dBScale, AbsoluteScale };
Chris@153 85
Chris@193 86 enum SamplingMode { NearestSample, SampleMean, SamplePeak };
Chris@153 87
Chris@197 88 enum PlotStyle { PlotLines, PlotSteps, PlotBlocks, PlotFilledBlocks };
Chris@153 89
Chris@193 90 enum BinScale { LinearBins, LogBins, InvertedLogBins };
Chris@153 91
Chris@1281 92 bool usesSolidColour() const { return m_plotStyle == PlotFilledBlocks; }
Chris@1281 93
Chris@197 94 void setFillColourMap(int);
Chris@197 95 int getFillColourMap() const { return m_colourMap; }
Chris@197 96
Chris@153 97 void setEnergyScale(EnergyScale);
Chris@153 98 EnergyScale getEnergyScale() const { return m_energyScale; }
Chris@153 99
Chris@193 100 void setSamplingMode(SamplingMode);
Chris@193 101 SamplingMode getSamplingMode() const { return m_samplingMode; }
Chris@153 102
Chris@193 103 void setPlotStyle(PlotStyle style);
Chris@193 104 PlotStyle getPlotStyle() const { return m_plotStyle; }
Chris@193 105
Chris@193 106 void setBinScale(BinScale scale);
Chris@193 107 BinScale getBinScale() const { return m_binScale; }
Chris@153 108
Chris@284 109 void setThreshold(float);
Chris@905 110 float getThreshold() const { return m_threshold; }
Chris@284 111
Chris@153 112 void setGain(float gain);
Chris@153 113 float getGain() const;
Chris@153 114
Chris@153 115 void setNormalize(bool n);
Chris@153 116 bool getNormalize() const;
Chris@153 117
Chris@316 118 virtual void toXml(QTextStream &stream, QString indent = "",
Chris@316 119 QString extraAttributes = "") const;
Chris@153 120
Chris@193 121 public slots:
Chris@193 122 void sliceableModelReplaced(const Model *, const Model *);
Chris@193 123 void modelAboutToBeDeleted(Model *);
Chris@133 124
Chris@133 125 protected:
Chris@1386 126 /// Convert a (possibly non-integral) bin into x-coord. May be overridden
Chris@1238 127 virtual double getXForBin(const LayerGeometryProvider *, double bin) const;
Chris@1386 128
Chris@1386 129 /// Convert an x-coord into (possibly non-integral) bin. May be overridden
Chris@1238 130 virtual double getBinForX(const LayerGeometryProvider *, double x) const;
Chris@274 131
Chris@1386 132 /// Convert a point such as a bin number into x-coord, given max &
Chris@1386 133 /// min. For use by getXForBin etc
Chris@1386 134 double getXForScalePoint(const LayerGeometryProvider *,
Chris@1386 135 double p, double pmin, double pmax) const;
Chris@1386 136
Chris@1386 137 /// Convert an x-coord into a point such as a bin number, given
Chris@1386 138 /// max & min. For use by getBinForX etc
Chris@1386 139 double getScalePointForX(const LayerGeometryProvider *,
Chris@1386 140 double x, double pmin, double pmax) const;
Chris@1386 141
Chris@1238 142 virtual double getYForValue(const LayerGeometryProvider *v, double value, double &norm) const;
Chris@1238 143 virtual double getValueForY(const LayerGeometryProvider *v, double y) const;
Chris@198 144
Chris@918 145 virtual QString getFeatureDescriptionAux(LayerGeometryProvider *v, QPoint &,
Chris@805 146 bool includeBinDescription,
Chris@805 147 int &minbin, int &maxbin,
Chris@805 148 int &range) const;
Chris@199 149
Chris@254 150 // This curve may, of course, be flat -- the spectrum uses it for
Chris@254 151 // normalizing the fft results by the fft size (with 1/(fftsize/2)
Chris@254 152 // in each bin).
Chris@254 153 typedef std::vector<float> BiasCurve;
Chris@254 154 virtual void getBiasCurve(BiasCurve &) const { return; }
Chris@254 155
Chris@284 156 virtual float getThresholdDb() const;
Chris@284 157
Chris@287 158 virtual int getDefaultColourHint(bool dark, bool &impose);
Chris@287 159
Chris@193 160 const DenseThreeDimensionalModel *m_sliceableModel;
Chris@197 161 int m_colourMap;
Chris@1362 162 bool m_colourInverted;
Chris@193 163 EnergyScale m_energyScale;
Chris@193 164 SamplingMode m_samplingMode;
Chris@193 165 PlotStyle m_plotStyle;
Chris@193 166 BinScale m_binScale;
Chris@193 167 bool m_normalize;
Chris@284 168 float m_threshold;
Chris@284 169 float m_initialThreshold;
Chris@193 170 float m_gain;
Chris@1238 171 int m_minbin;
Chris@1238 172 int m_maxbin;
Chris@195 173 mutable std::vector<int> m_scalePoints;
Chris@1284 174 mutable int m_scalePaintHeight;
Chris@1238 175 mutable std::map<int, int> m_xorigins; // LayerGeometryProvider id -> x
Chris@1238 176 mutable std::map<int, int> m_yorigins; // LayerGeometryProvider id -> y
Chris@1238 177 mutable std::map<int, int> m_heights; // LayerGeometryProvider id -> h
Chris@906 178 mutable sv_frame_t m_currentf0;
Chris@906 179 mutable sv_frame_t m_currentf1;
Chris@198 180 mutable std::vector<float> m_values;
Chris@133 181 };
Chris@133 182
Chris@133 183 #endif