WaveformLayer.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 Chris Cannam and 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_WAVEFORM_LAYER_H
17 #define SV_WAVEFORM_LAYER_H
18 
19 #include <QRect>
20 
21 #include "SingleColourLayer.h"
22 
23 #include "base/ZoomLevel.h"
24 
25 #include "data/model/RangeSummarisableTimeValueModel.h"
26 
27 class View;
28 class QPainter;
29 class QPixmap;
30 
32 {
33  Q_OBJECT
34 
35 public:
36  WaveformLayer();
38 
39  const ZoomConstraint *getZoomConstraint() const override;
40  ModelId getModel() const override { return m_model; }
41  void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override;
42 
43  QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override;
44 
47  }
48 
49  int getVerticalScaleWidth(LayerGeometryProvider *v, bool detailed, QPainter &) const override;
50  void paintVerticalScale(LayerGeometryProvider *v, bool detailed, QPainter &paint, QRect rect) const override;
51 
52  void setModel(ModelId model); // a RangeSummarisableTimeValueModel
53 
54  PropertyList getProperties() const override;
55  QString getPropertyLabel(const PropertyName &) const override;
56  QString getPropertyIconName(const PropertyName &) const override;
57  PropertyType getPropertyType(const PropertyName &) const override;
58  QString getPropertyGroupName(const PropertyName &) const override;
59  int getPropertyRangeAndValue(const PropertyName &,
60  int *min, int *max, int *deflt) const override;
61  QString getPropertyValueLabel(const PropertyName &,
62  int value) const override;
63  RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const override;
64  void setProperty(const PropertyName &, int value) override;
65 
71  void setGain(float gain);
72  float getGain() const { return m_gain; }
73 
77  void setAutoNormalize(bool);
78  bool getAutoNormalize() const { return m_autoNormalize; }
79 
87  void setShowMeans(bool);
88  bool getShowMeans() const { return m_showMeans; }
89 
91 
106 
107 
113  void setChannel(int);
114  int getChannel() const { return m_channel; }
115 
116 
118 
133  void setScale(Scale);
134  Scale getScale() const { return m_scale; }
135 
146  void setMiddleLineHeight(double);
147  double getMiddleLineHeight() const { return m_middleLineHeight; }
148 
167  void setAggressiveCacheing(bool);
168  bool getAggressiveCacheing() const { return m_aggressive; }
169 
170  bool isLayerScrollable(const LayerGeometryProvider *) const override;
171 
172  int getCompletion(LayerGeometryProvider *) const override;
173 
174  bool getValueExtents(double &min, double &max,
175  bool &log, QString &unit) const override;
176 
177  bool getDisplayExtents(double & min, double &max) const override;
178 
179  bool getYScaleValue(const LayerGeometryProvider *v, int y,
180  double &value, QString &unit) const override;
181 
182  bool getYScaleDifference(const LayerGeometryProvider *v, int y0, int y1,
183  double &diff, QString &unit) const override;
184 
185  void toXml(QTextStream &stream, QString indent = "",
186  QString extraAttributes = "") const override;
187 
188  void setProperties(const QXmlAttributes &attributes) override;
189 
190  int getVerticalZoomSteps(int &defaultStep) const override;
191  int getCurrentVerticalZoomStep() const override;
192  void setVerticalZoomStep(int) override;
193 
194  bool canExistWithoutModel() const override { return true; }
195 
196 protected:
197  double dBscale(double sample, int m) const;
198 
199  ModelId m_model;
200 
201  typedef std::vector<RangeSummarisableTimeValueModel::RangeBlock> RangeVec;
202 
204  int getChannelArrangement(int &min, int &max,
205  bool &merging, bool &mixing) const;
206 
207  void paintChannel
208  (LayerGeometryProvider *, QPainter *paint, QRect rect, int channel,
209  const RangeVec &ranges,
210  int blockSize, sv_frame_t frame0, sv_frame_t frame1) const;
211 
212  void paintChannelScaleGuides(LayerGeometryProvider *, QPainter *paint,
213  QRect rect, int channel) const;
214 
215  void getSummaryRanges(int minChannel, int maxChannel,
216  bool mixingOrMerging,
217  sv_frame_t f0, sv_frame_t f1,
218  int blockSize, RangeVec &ranges) const;
219 
220  void getOversampledRanges(int minChannel, int maxChannel,
221  bool mixingOrMerging,
222  sv_frame_t f0, sv_frame_t f1,
223  int oversampleBy, RangeVec &ranges) const;
224 
225  int getYForValue(const LayerGeometryProvider *v, double value, int channel) const;
226 
227  double getValueForY(const LayerGeometryProvider *v, int y, int &channel) const;
228 
229  bool getSourceFramesForX(LayerGeometryProvider *v, int x, int modelZoomLevel,
230  sv_frame_t &f0, sv_frame_t &f1) const;
231 
232  float getNormalizeGain(LayerGeometryProvider *v, int channel) const;
233 
234  void flagBaseColourChanged() override { m_cacheValid = false; }
235 
236  float m_gain;
245 
246  static double m_dBMin;
247 
248  mutable std::vector<float> m_effectiveGains;
249 
250  mutable QPixmap *m_cache;
251  mutable bool m_cacheValid;
252  mutable ZoomLevel m_cacheZoomLevel;
253 };
254 
255 #endif
PropertyType getPropertyType(const PropertyName &) const override
const ZoomConstraint * getZoomConstraint() const override
Return a zoom constraint object defining the supported zoom levels for this layer.
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...
bool isLayerScrollable(const LayerGeometryProvider *) const override
This should return true if the layer can safely be scrolled automatically by a given view (simply cop...
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.
bool getAutoNormalize() const
Definition: WaveformLayer.h:78
double getMiddleLineHeight() const
Scale getScale() const
bool getShowMeans() const
Definition: WaveformLayer.h:88
void setChannel(int)
Specify the channel to use from the source model.
bool getYScaleValue(const LayerGeometryProvider *v, int y, double &value, QString &unit) const override
Return the value and unit at the given y coordinate in the given view.
int getChannel() const
int getChannelArrangement(int &min, int &max, bool &merging, bool &mixing) const
Return value is number of channels displayed.
double m_middleLineHeight
int getPropertyRangeAndValue(const PropertyName &, int *min, int *max, int *deflt) const override
void setMiddleLineHeight(double)
Specify the height of the middle of the waveform track or tracks within the layer, from 0.0 to 1.0.
void setModel(ModelId model)
int getYForValue(const LayerGeometryProvider *v, double value, int channel) const
ColourSignificance getLayerColourSignificance() const override
Implements Layer::getLayerColourSignificance()
Definition: WaveformLayer.h:45
void setAutoNormalize(bool)
Toggle automatic normalization of the currently visible waveform.
int getVerticalZoomSteps(int &defaultStep) const override
Get the number of vertical zoom steps available for this layer.
ChannelMode m_channelMode
float getGain() const
Definition: WaveformLayer.h:72
std::vector< float > m_effectiveGains
ChannelMode getChannelMode() const
QString getPropertyLabel(const PropertyName &) const override
std::vector< RangeSummarisableTimeValueModel::RangeBlock > RangeVec
PropertyList getProperties() const override
ColourSignificance
Definition: Layer.h:348
void setScale(Scale)
Specify the vertical scale for sample levels.
QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override
void getOversampledRanges(int minChannel, int maxChannel, bool mixingOrMerging, sv_frame_t f0, sv_frame_t f1, int oversampleBy, RangeVec &ranges) const
bool getYScaleDifference(const LayerGeometryProvider *v, int y0, int y1, double &diff, QString &unit) const override
Return the difference between the values at the given y coordinates in the given view, and the unit of the difference.
bool getAggressiveCacheing() const
QString getPropertyIconName(const PropertyName &) const override
void flagBaseColourChanged() override
void paintVerticalScale(LayerGeometryProvider *v, bool detailed, QPainter &paint, QRect rect) const override
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.
void setVerticalZoomStep(int) override
Set the vertical zoom step.
void setProperty(const PropertyName &, int value) override
void setGain(float gain)
Set the gain multiplier for sample values in this view.
void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const override
bool getSourceFramesForX(LayerGeometryProvider *v, int x, int modelZoomLevel, sv_frame_t &f0, sv_frame_t &f1) const
int getCompletion(LayerGeometryProvider *) const override
Return the proportion of background work complete in drawing this view, as a percentage – in most ca...
QString getPropertyValueLabel(const PropertyName &, int value) const override
void paintChannelScaleGuides(LayerGeometryProvider *, QPainter *paint, QRect rect, int channel) const
ModelId getModel() const override
Return the ID of the model represented in this layer.
Definition: WaveformLayer.h:40
RangeMapper * getNewPropertyRangeMapper(const PropertyName &) const override
int getCurrentVerticalZoomStep() const override
Get the current vertical zoom step.
float getNormalizeGain(LayerGeometryProvider *v, int channel) const
QString getPropertyGroupName(const PropertyName &) const override
double dBscale(double sample, int m) const
static double m_dBMin
bool canExistWithoutModel() const override
Return true if this layer type can function without a model being set.
int getVerticalScaleWidth(LayerGeometryProvider *v, bool detailed, QPainter &) const override
void paintChannel(LayerGeometryProvider *, QPainter *paint, QRect rect, int channel, const RangeVec &ranges, int blockSize, sv_frame_t frame0, sv_frame_t frame1) const
View is the base class of widgets that display one or more overlaid views of data against a horizonta...
Definition: View.h:55
void getSummaryRanges(int minChannel, int maxChannel, bool mixingOrMerging, sv_frame_t f0, sv_frame_t f1, int blockSize, RangeVec &ranges) const
void setShowMeans(bool)
Set whether to display mean values as a lighter-coloured area beneath the peaks.
void setProperties(const QXmlAttributes &attributes) override
Set the particular properties of a layer (those specific to the subclass) from a set of XML attribute...
QPixmap * m_cache
ZoomLevel m_cacheZoomLevel
void setAggressiveCacheing(bool)
Enable or disable aggressive pixmap cacheing.
bool getValueExtents(double &min, double &max, bool &log, 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...
void setChannelMode(ChannelMode)
Specify whether multi-channel audio data should be displayed with a separate axis per channel (Separa...
double getValueForY(const LayerGeometryProvider *v, int y, int &channel) const