SliceLayer.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006 QMUL.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef SV_SLICE_LAYER_H
17 #define SV_SLICE_LAYER_H
18 
19 #include "SingleColourLayer.h"
20 
21 #include "base/Window.h"
22 
23 #include "data/model/DenseThreeDimensionalModel.h"
24 
25 #include <QColor>
26 
28 {
29  Q_OBJECT
30 
31 public:
32  SliceLayer();
33  ~SliceLayer();
34 
35  ModelId getModel() const override { return {}; }
36 
37  void setSliceableModel(ModelId model);
38 
39  void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override;
40 
41  QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override;
42 
43  int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const override;
44  void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const override;
45 
48  }
49 
50  bool hasLightBackground() const override;
51 
52  PropertyList getProperties() const override;
53  QString getPropertyLabel(const PropertyName &) const override;
54  QString getPropertyIconName(const PropertyName &) const override;
55  PropertyType getPropertyType(const PropertyName &) const override;
56  QString getPropertyGroupName(const PropertyName &) const override;
57  int getPropertyRangeAndValue(const PropertyName &,
58  int *min, int *max, int *deflt) const override;
59  QString getPropertyValueLabel(const PropertyName &,
60  int value) const override;
61  RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const override;
62  void setProperty(const PropertyName &, int value) override;
63  void setProperties(const QXmlAttributes &) override;
64 
65  bool getValueExtents(double &min, double &max,
66  bool &logarithmic, QString &unit) const override;
67 
68  bool getDisplayExtents(double &min, double &max) const override;
69  bool setDisplayExtents(double min, double max) override;
70 
71  int getVerticalZoomSteps(int &defaultStep) const override;
72  int getCurrentVerticalZoomStep() const override;
73  void setVerticalZoomStep(int) override;
74  RangeMapper *getNewVerticalZoomRangeMapper() const override;
75 
76  virtual bool hasTimeXAxis() const override { return false; }
77 
78  virtual void zoomToRegion(const LayerGeometryProvider *, QRect) override;
79 
80  bool isLayerScrollable(const LayerGeometryProvider *) const override { return false; }
81 
83 
85 
87 
89 
90  bool usesSolidColour() const { return m_plotStyle == PlotFilledBlocks; }
91 
92  void setFillColourMap(int);
93  int getFillColourMap() const { return m_colourMap; }
94 
97 
100 
101  void setPlotStyle(PlotStyle style);
102  PlotStyle getPlotStyle() const { return m_plotStyle; }
103 
104  void setBinScale(BinScale scale);
105  BinScale getBinScale() const { return m_binScale; }
106 
107  void setThreshold(float);
108  float getThreshold() const { return m_threshold; }
109 
110  void setGain(float gain);
111  float getGain() const;
112 
113  void setNormalize(bool n);
114  bool getNormalize() const;
115 
116  void toXml(QTextStream &stream, QString indent = "",
117  QString extraAttributes = "") const override;
118 
119 public slots:
120  void sliceableModelReplaced(ModelId, ModelId);
121 
122 protected:
124  virtual double getXForBin(const LayerGeometryProvider *, double bin) const;
125 
127  virtual double getBinForX(const LayerGeometryProvider *, double x) const;
128 
132  double p, double pmin, double pmax) const;
133 
137  double x, double pmin, double pmax) const;
138 
139  virtual double getYForValue(const LayerGeometryProvider *v, double value, double &norm) const;
140  virtual double getValueForY(const LayerGeometryProvider *v, double y) const;
141 
142  virtual QString getFeatureDescriptionAux(LayerGeometryProvider *v, QPoint &,
143  bool includeBinDescription,
144  int &minbin, int &maxbin,
145  int &range) const;
146 
147  // This curve may, of course, be flat -- the spectrum uses it for
148  // normalizing the fft results by the fft size (with 1/(fftsize/2)
149  // in each bin).
150  typedef std::vector<float> BiasCurve;
151  virtual void getBiasCurve(BiasCurve &) const { return; }
152 
153  virtual float getThresholdDb() const;
154 
155  int getDefaultColourHint(bool dark, bool &impose) override;
156 
157  // Determine how the bins are lined up
158  // horizontally. BinsCentredOnScalePoint means we operate like a
159  // spectrum, where a bin maps to a specific frequency, and so the
160  // bin should be visually centred on the scale point that
161  // corresponds to that frequency. BinsSpanScalePoints means we
162  // have numbered or labelled bins that are not mapped to a
163  // continuous scale, like a typical chromagram output, and so bin
164  // N spans from scale point N to N+1. This is a fundamental
165  // quality of the class or input data, not a user-configurable
166  // property.
167  //
171  };
172 
173  ModelId m_sliceableModel; // a DenseThreeDimensionalModel
182  float m_threshold;
184  float m_gain;
185  int m_minbin;
186  int m_maxbin;
187  mutable std::vector<int> m_scalePoints;
188  mutable int m_scalePaintHeight;
189  mutable std::map<int, int> m_xorigins; // LayerGeometryProvider id -> x
190  mutable std::map<int, int> m_yorigins; // LayerGeometryProvider id -> y
191  mutable std::map<int, int> m_heights; // LayerGeometryProvider id -> h
192  mutable sv_frame_t m_currentf0;
193  mutable sv_frame_t m_currentf1;
194  mutable std::vector<float> m_values;
195 };
196 
197 #endif
EnergyScale m_energyScale
Definition: SliceLayer.h:177
sv_frame_t m_currentf0
Definition: SliceLayer.h:192
bool getDisplayExtents(double &min, double &max) const override
Return the minimum and maximum values within the visible area for the y axis of this layer...
float getGain() const
void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const override
Definition: SliceLayer.cpp:684
void setFillColourMap(int)
Definition: SliceLayer.cpp:987
int getCurrentVerticalZoomStep() const override
Get the current vertical zoom step.
virtual bool hasTimeXAxis() const override
Return true if the X axis on the layer is time proportional to audio frames, false otherwise...
Definition: SliceLayer.h:76
bool getValueExtents(double &min, double &max, bool &logarithmic, QString &unit) const override
Return the minimum and maximum values for the y axis of the model in this layer, as well as whether t...
int getVerticalZoomSteps(int &defaultStep) const override
Get the number of vertical zoom steps available for this layer.
bool setDisplayExtents(double min, double max) override
Set the displayed minimum and maximum values for the y axis to the given range, if supported...
int getFillColourMap() const
Definition: SliceLayer.h:93
sv_frame_t m_currentf1
Definition: SliceLayer.h:193
virtual double getValueForY(const LayerGeometryProvider *v, double y) const
Definition: SliceLayer.cpp:372
bool hasLightBackground() const override
Return true if the layer currently has a dark colour on a light background, false if it has a light c...
Definition: SliceLayer.cpp:729
void setSliceableModel(ModelId model)
Definition: SliceLayer.cpp:59
void setVerticalZoomStep(int) override
Set the vertical zoom step.
PropertyType getPropertyType(const PropertyName &) const override
Definition: SliceLayer.cpp:774
float m_initialThreshold
Definition: SliceLayer.h:183
bool m_colourInverted
Definition: SliceLayer.h:176
ModelId m_sliceableModel
Definition: SliceLayer.h:173
void setSamplingMode(SamplingMode)
PropertyList getProperties() const override
Definition: SliceLayer.cpp:740
EnergyScale getEnergyScale() const
Definition: SliceLayer.h:96
std::map< int, int > m_heights
Definition: SliceLayer.h:191
BinScale getBinScale() const
Definition: SliceLayer.h:105
QString getPropertyIconName(const PropertyName &) const override
Definition: SliceLayer.cpp:767
void setThreshold(float)
ColourSignificance
Definition: Layer.h:348
ModelId getModel() const override
Return the ID of the model represented in this layer.
Definition: SliceLayer.h:35
int m_scalePaintHeight
Definition: SliceLayer.h:188
QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override
Definition: SliceLayer.cpp:94
QString getPropertyValueLabel(const PropertyName &, int value) const override
Definition: SliceLayer.cpp:890
std::vector< int > m_scalePoints
Definition: SliceLayer.h:187
virtual float getThresholdDb() const
PlotStyle m_plotStyle
Definition: SliceLayer.h:179
Interface for classes that provide geometry information (such as size, start frame, and a large number of other properties) about the disposition of a layer.
int m_colourMap
Definition: SliceLayer.h:175
BinScale m_binScale
Definition: SliceLayer.h:180
RangeMapper * getNewPropertyRangeMapper(const PropertyName &) const override
Definition: SliceLayer.cpp:934
int m_minbin
Definition: SliceLayer.h:185
void setNormalize(bool n)
int m_maxbin
Definition: SliceLayer.h:186
bool m_normalize
Definition: SliceLayer.h:181
std::vector< float > m_values
Definition: SliceLayer.h:194
double getXForScalePoint(const LayerGeometryProvider *, double p, double pmin, double pmax) const
Convert a point such as a bin number into x-coord, given max & min.
Definition: SliceLayer.cpp:196
virtual double getYForValue(const LayerGeometryProvider *v, double value, double &norm) const
Definition: SliceLayer.cpp:320
PlotStyle getPlotStyle() const
Definition: SliceLayer.h:102
virtual double getBinForX(const LayerGeometryProvider *, double x) const
Convert an x-coord into (possibly non-integral) bin. May be overridden.
Definition: SliceLayer.cpp:265
void setPlotStyle(PlotStyle style)
bool isLayerScrollable(const LayerGeometryProvider *) const override
This should return true if the layer can safely be scrolled automatically by a given view (simply cop...
Definition: SliceLayer.h:80
QString getPropertyLabel(const PropertyName &) const override
Definition: SliceLayer.cpp:754
float getThreshold() const
Definition: SliceLayer.h:108
RangeMapper * getNewVerticalZoomRangeMapper() const override
Create and return a range mapper for vertical zoom step values.
void setBinScale(BinScale scale)
double getScalePointForX(const LayerGeometryProvider *, double x, double pmin, double pmax) const
Convert an x-coord into a point such as a bin number, given max & min.
Definition: SliceLayer.cpp:271
float m_threshold
Definition: SliceLayer.h:182
void setGain(float gain)
virtual void zoomToRegion(const LayerGeometryProvider *, QRect) override
Update the X and Y axis scales, where appropriate, to focus on the given rectangular region...
std::vector< float > BiasCurve
Definition: SliceLayer.h:150
void setEnergyScale(EnergyScale)
Definition: SliceLayer.cpp:995
BinAlignment m_binAlignment
Definition: SliceLayer.h:174
int getDefaultColourHint(bool dark, bool &impose) override
void setProperty(const PropertyName &, int value) override
Definition: SliceLayer.cpp:946
SamplingMode m_samplingMode
Definition: SliceLayer.h:178
bool getNormalize() const
void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override
Paint the given rectangle of this layer onto the given view using the given painter, superimposing it on top of any existing material in that view.
Definition: SliceLayer.cpp:409
SamplingMode getSamplingMode() const
Definition: SliceLayer.h:99
void setProperties(const QXmlAttributes &) override
Set the particular properties of a layer (those specific to the subclass) from a set of XML attribute...
virtual QString getFeatureDescriptionAux(LayerGeometryProvider *v, QPoint &, bool includeBinDescription, int &minbin, int &maxbin, int &range) const
Definition: SliceLayer.cpp:101
virtual double getXForBin(const LayerGeometryProvider *, double bin) const
Convert a (possibly non-integral) bin into x-coord. May be overridden.
Definition: SliceLayer.cpp:190
float m_gain
Definition: SliceLayer.h:184
ColourSignificance getLayerColourSignificance() const override
Implements Layer::getLayerColourSignificance()
Definition: SliceLayer.h:46
void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const override
virtual void getBiasCurve(BiasCurve &) const
Definition: SliceLayer.h:151
std::map< int, int > m_xorigins
Definition: SliceLayer.h:189
QString getPropertyGroupName(const PropertyName &) const override
Definition: SliceLayer.cpp:788
int getPropertyRangeAndValue(const PropertyName &, int *min, int *max, int *deflt) const override
Definition: SliceLayer.cpp:801
int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const override
Definition: SliceLayer.cpp:665
bool usesSolidColour() const
Definition: SliceLayer.h:90
void sliceableModelReplaced(ModelId, ModelId)
Definition: SliceLayer.cpp:84
std::map< int, int > m_yorigins
Definition: SliceLayer.h:190