svgui  1.9
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 _WAVEFORM_LAYER_H_
17 #define _WAVEFORM_LAYER_H_
18 
19 #include <QRect>
20 
21 #include "SingleColourLayer.h"
22 
23 #include "data/model/RangeSummarisableTimeValueModel.h"
24 
25 class View;
26 class QPainter;
27 class QPixmap;
28 
30 {
31  Q_OBJECT
32 
33 public:
34  WaveformLayer();
36 
37  virtual const ZoomConstraint *getZoomConstraint() const {
38  return m_model ? m_model->getZoomConstraint() : 0;
39  }
40  virtual const Model *getModel() const { return m_model; }
41  virtual void paint(View *v, QPainter &paint, QRect rect) const;
42 
43  virtual QString getFeatureDescription(View *v, QPoint &) const;
44 
47  }
48 
49  virtual int getVerticalScaleWidth(View *v, bool detailed, QPainter &) const;
50  virtual void paintVerticalScale(View *v, bool detailed, QPainter &paint, QRect rect) const;
51 
52  void setModel(const RangeSummarisableTimeValueModel *model);
53 
54  virtual PropertyList getProperties() const;
55  virtual QString getPropertyLabel(const PropertyName &) const;
56  virtual QString getPropertyIconName(const PropertyName &) const;
57  virtual PropertyType getPropertyType(const PropertyName &) const;
58  virtual QString getPropertyGroupName(const PropertyName &) const;
59  virtual int getPropertyRangeAndValue(const PropertyName &,
60  int *min, int *max, int *deflt) const;
61  virtual QString getPropertyValueLabel(const PropertyName &,
62  int value) const;
63  virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const;
64  virtual void setProperty(const PropertyName &, int value);
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 
99  void setUseGreyscale(bool);
100  bool getUseGreyscale() const { return m_greyscale; }
101 
102 
104 
119 
120 
126  void setChannel(int);
127  int getChannel() const { return m_channel; }
128 
129 
131 
146  void setScale(Scale);
147  Scale getScale() const { return m_scale; }
148 
159  void setMiddleLineHeight(float height);
160  float getMiddleLineHeight() const { return m_middleLineHeight; }
161 
180  void setAggressiveCacheing(bool);
181  bool getAggressiveCacheing() const { return m_aggressive; }
182 
183  virtual bool isLayerScrollable(const View *) const;
184 
185  virtual int getCompletion(View *) const;
186 
187  virtual bool getValueExtents(float &min, float &max,
188  bool &log, QString &unit) const;
189 
190  virtual bool getYScaleValue(const View *v, int y,
191  float &value, QString &unit) const;
192 
193  virtual bool getYScaleDifference(const View *v, int y0, int y1,
194  float &diff, QString &unit) const;
195 
196  virtual void toXml(QTextStream &stream, QString indent = "",
197  QString extraAttributes = "") const;
198 
199  virtual void setProperties(const QXmlAttributes &attributes);
200 
201  virtual int getVerticalZoomSteps(int &defaultStep) const;
202  virtual int getCurrentVerticalZoomStep() const;
203  virtual void setVerticalZoomStep(int);
204 
205 protected:
206  int dBscale(float sample, int m) const;
207 
208  const RangeSummarisableTimeValueModel *m_model; // I do not own this
209 
211  int getChannelArrangement(int &min, int &max,
212  bool &merging, bool &mixing) const;
213 
214  int getYForValue(const View *v, float value, int channel) const;
215 
216  float getValueForY(const View *v, int y, int &channel) const;
217 
218  bool getSourceFramesForX(View *v, int x, int modelZoomLevel,
219  int &f0, int &f1) const;
220 
221  float getNormalizeGain(View *v, int channel) const;
222 
223  virtual void flagBaseColourChanged() { m_cacheValid = false; }
224 
225  float m_gain;
234 
235  mutable std::vector<float> m_effectiveGains;
236 
237  mutable QPixmap *m_cache;
238  mutable bool m_cacheValid;
239  mutable int m_cacheZoomLevel;
240 };
241 
242 #endif
virtual void setVerticalZoomStep(int)
Set the vertical zoom step.
void setModel(const RangeSummarisableTimeValueModel *model)
virtual QString getPropertyValueLabel(const PropertyName &, int value) const
virtual int getPropertyRangeAndValue(const PropertyName &, int *min, int *max, int *deflt) const
virtual QString getPropertyGroupName(const PropertyName &) const
virtual RangeMapper * getNewPropertyRangeMapper(const PropertyName &) const
float getGain() const
Definition: WaveformLayer.h:72
bool getShowMeans() const
Definition: WaveformLayer.h:88
virtual PropertyType getPropertyType(const PropertyName &) const
void setChannel(int)
Specify the channel to use from the source model.
bool getSourceFramesForX(View *v, int x, int modelZoomLevel, int &f0, int &f1) const
int getYForValue(const View *v, float value, int channel) const
virtual int getVerticalScaleWidth(View *v, bool detailed, QPainter &) const
void setAutoNormalize(bool)
Toggle automatic normalization of the currently visible waveform.
virtual void paint(View *v, QPainter &paint, QRect rect) const
Paint the given rectangle of this layer onto the given view using the given painter,...
void setMiddleLineHeight(float height)
Specify the height of the middle of the waveform track or tracks within the layer,...
ChannelMode m_channelMode
std::vector< float > m_effectiveGains
virtual QString getFeatureDescription(View *v, QPoint &) const
virtual int getVerticalZoomSteps(int &defaultStep) const
Get the number of vertical zoom steps available for this layer.
virtual void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const
Convert the layer's data (though not those of the model it refers to) into XML for file output.
ColourSignificance
Definition: Layer.h:304
void setScale(Scale)
Specify the vertical scale for sample levels.
Scale getScale() const
virtual int getCurrentVerticalZoomStep() const
Get the current vertical zoom step.
virtual int getCompletion(View *) const
Return the proportion of background work complete in drawing this view, as a percentage – in most cas...
void setGain(float gain)
Set the gain multiplier for sample values in this view.
int getChannelArrangement(int &min, int &max, bool &merging, bool &mixing) const
Return value is number of channels displayed.
virtual void flagBaseColourChanged()
virtual ColourSignificance getLayerColourSignificance() const
Implements Layer::getLayerColourSignificance()
Definition: WaveformLayer.h:45
float getValueForY(const View *v, int y, int &channel) const
const RangeSummarisableTimeValueModel * m_model
virtual bool getYScaleDifference(const View *v, int y0, int y1, float &diff, QString &unit) const
Return the difference between the values at the given y coordinates in the given view,...
virtual void paintVerticalScale(View *v, bool detailed, QPainter &paint, QRect rect) const
int getChannel() const
virtual bool isLayerScrollable(const View *) const
This should return true if the layer can safely be scrolled automatically by a given view (simply cop...
virtual bool getValueExtents(float &min, float &max, bool &log, QString &unit) const
Return the minimum and maximum values for the y axis of the model in this layer, as well as whether t...
virtual void setProperty(const PropertyName &, int value)
bool getUseGreyscale() const
virtual const ZoomConstraint * getZoomConstraint() const
Return a zoom constraint object defining the supported zoom levels for this layer.
Definition: WaveformLayer.h:37
virtual void setProperties(const QXmlAttributes &attributes)
Set the particular properties of a layer (those specific to the subclass) from a set of XML attribute...
View is the base class of widgets that display one or more overlaid views of data against a horizonta...
Definition: View.h:50
virtual PropertyList getProperties() const
virtual QString getPropertyLabel(const PropertyName &) const
float m_middleLineHeight
ChannelMode getChannelMode() const
void setShowMeans(bool)
Set whether to display mean values as a lighter-coloured area beneath the peaks.
bool getAggressiveCacheing() const
QPixmap * m_cache
virtual QString getPropertyIconName(const PropertyName &) const
int dBscale(float sample, int m) const
void setAggressiveCacheing(bool)
Enable or disable aggressive pixmap cacheing.
float getMiddleLineHeight() const
bool getAutoNormalize() const
Definition: WaveformLayer.h:78
virtual const Model * getModel() const
Definition: WaveformLayer.h:40
void setUseGreyscale(bool)
Set whether to use shades of grey (or of the base colour) to provide additional perceived vertical re...
void setChannelMode(ChannelMode)
Specify whether multi-channel audio data should be displayed with a separate axis per channel (Separa...
float getNormalizeGain(View *v, int channel) const
virtual bool getYScaleValue(const View *v, int y, float &value, QString &unit) const
Return the value and unit at the given y coordinate in the given view.