Mercurial > hg > svgui
comparison layer/WaveformLayer.h @ 0:2a4f26e85b4c
initial import
author | Chris Cannam |
---|---|
date | Tue, 10 Jan 2006 16:33:16 +0000 |
parents | |
children | 37b110168acf |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:2a4f26e85b4c |
---|---|
1 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 A waveform viewer and audio annotation editor. | |
5 Chris Cannam, Queen Mary University of London, 2005 | |
6 | |
7 This is experimental software. Not for distribution. | |
8 */ | |
9 | |
10 #ifndef _WAVEFORM_VIEW_H_ | |
11 #define _WAVEFORM_VIEW_H_ | |
12 | |
13 #include <QRect> | |
14 #include <QColor> | |
15 | |
16 #include "base/Layer.h" | |
17 | |
18 #include "model/RangeSummarisableTimeValueModel.h" | |
19 | |
20 class View; | |
21 class QPainter; | |
22 class QPixmap; | |
23 | |
24 class WaveformLayer : public Layer | |
25 { | |
26 Q_OBJECT | |
27 | |
28 public: | |
29 WaveformLayer(View *w); | |
30 ~WaveformLayer(); | |
31 | |
32 virtual const ZoomConstraint *getZoomConstraint() const { return m_model; } | |
33 virtual const Model *getModel() const { return m_model; } | |
34 virtual void paint(QPainter &paint, QRect rect) const; | |
35 | |
36 virtual int getVerticalScaleWidth(QPainter &) const; | |
37 virtual void paintVerticalScale(QPainter &paint, QRect rect) const; | |
38 | |
39 void setModel(const RangeSummarisableTimeValueModel *model); | |
40 | |
41 virtual PropertyList getProperties() const; | |
42 virtual PropertyType getPropertyType(const PropertyName &) const; | |
43 virtual QString getPropertyGroupName(const PropertyName &) const; | |
44 virtual int getPropertyRangeAndValue(const PropertyName &, | |
45 int *min, int *max) const; | |
46 virtual QString getPropertyValueLabel(const PropertyName &, | |
47 int value) const; | |
48 virtual void setProperty(const PropertyName &, int value); | |
49 | |
50 /** | |
51 * Set the gain multiplier for sample values in this view. | |
52 * | |
53 * The default is 1.0. | |
54 */ | |
55 void setGain(float gain); | |
56 float getGain() const { return m_gain; } | |
57 | |
58 /** | |
59 * Set the basic display colour for waveforms. | |
60 * | |
61 * The default is black. | |
62 *!!! NB should default to white if the associated View !hasLightBackground() | |
63 */ | |
64 void setBaseColour(QColor); | |
65 QColor getBaseColour() const { return m_colour; } | |
66 | |
67 /** | |
68 * Set whether to display mean values as a lighter-coloured area | |
69 * beneath the peaks. Rendering will be slightly faster without | |
70 * but arguably prettier with. | |
71 * | |
72 * The default is to display means. | |
73 */ | |
74 void setShowMeans(bool); | |
75 bool getShowMeans() const { return m_showMeans; } | |
76 | |
77 /** | |
78 * Set whether to use shades of grey (or of the base colour) to | |
79 * provide additional perceived vertical resolution (i.e. using | |
80 * half-filled pixels to represent levels that only just meet the | |
81 * pixel unit boundary). This provides a small improvement in | |
82 * waveform quality at a small cost in rendering speed. | |
83 * | |
84 * The default is to use greyscale. | |
85 */ | |
86 void setUseGreyscale(bool); | |
87 bool getUseGreyscale() const { return m_greyscale; } | |
88 | |
89 | |
90 enum ChannelMode { SeparateChannels, MergeChannels }; | |
91 | |
92 /** | |
93 * Specify whether multi-channel audio data should be displayed | |
94 * with a separate axis per channel (SeparateChannels), or with a | |
95 * single synthetic axis showing channel 0 above the axis and | |
96 * channel 1 below (MergeChannels). | |
97 * | |
98 * MergeChannels does not work for files with more than 2 | |
99 * channels. | |
100 * | |
101 * The default is SeparateChannels. | |
102 */ | |
103 void setChannelMode(ChannelMode); | |
104 ChannelMode getChannelMode() const { return m_channelMode; } | |
105 | |
106 | |
107 /** | |
108 * Specify the channel to use from the source model. A value of | |
109 * -1 means to show all available channels (laid out to the | |
110 * channel mode). The default is -1. | |
111 */ | |
112 void setChannel(int); | |
113 int getChannel() const { return m_channel; } | |
114 | |
115 | |
116 enum Scale { LinearScale, MeterScale, dBScale }; | |
117 | |
118 /** | |
119 * Specify the vertical scale for sample levels. With LinearScale, | |
120 * the scale is directly proportional to the raw [-1, +1) | |
121 * floating-point audio sample values. With dBScale the | |
122 * vertical scale is proportional to dB level (truncated at | |
123 * -50dB). MeterScale provides a hybrid variable scale based on | |
124 * IEC meter scale, intended to provide a clear overview at | |
125 * relatively small heights. | |
126 * | |
127 * Note that the effective gain (see setGain()) is applied before | |
128 * vertical scaling. | |
129 * | |
130 * The default is LinearScale. | |
131 */ | |
132 void setScale(Scale); | |
133 Scale getScale() const { return m_scale; } | |
134 | |
135 /** | |
136 * Enable or disable aggressive pixmap cacheing. If enabled, | |
137 * waveforms will be rendered to an off-screen pixmap and | |
138 * refreshed from there instead of being redrawn from the peak | |
139 * data each time. This may be faster if the data and zoom level | |
140 * do not change often, but it may be slower for frequently zoomed | |
141 * data and it will only work if the waveform is the "bottom" | |
142 * layer on the displayed widget, as each refresh will erase | |
143 * anything beneath the waveform. | |
144 * | |
145 * This is intended specifically for a panner widget display in | |
146 * which the waveform never moves, zooms, or changes, but some | |
147 * graphic such as a panner outline is frequently redrawn over the | |
148 * waveform. This situation would necessitate a lot of waveform | |
149 * refresh if the default cacheing strategy was used. | |
150 * | |
151 * The default is not to use aggressive cacheing. | |
152 */ | |
153 void setAggressiveCacheing(bool); | |
154 bool getAggressiveCacheing() const { return m_aggressive; } | |
155 | |
156 virtual int getCompletion() const; | |
157 | |
158 virtual QString getPropertyContainerIconName() const { return "waveform"; } | |
159 | |
160 protected: | |
161 int dBscale(float sample, int m) const; | |
162 | |
163 const RangeSummarisableTimeValueModel *m_model; // I do not own this | |
164 | |
165 /// Return value is number of channels displayed | |
166 size_t getChannelArrangement(size_t &min, size_t &max, bool &merging) const; | |
167 | |
168 float m_gain; | |
169 QColor m_colour; | |
170 bool m_showMeans; | |
171 bool m_greyscale; | |
172 ChannelMode m_channelMode; | |
173 int m_channel; | |
174 Scale m_scale; | |
175 bool m_aggressive; | |
176 | |
177 mutable QPixmap *m_cache; | |
178 mutable bool m_cacheValid; | |
179 mutable int m_cacheZoomLevel; | |
180 }; | |
181 | |
182 #endif |