annotate layer/WaveformLayer.h @ 16:02a718909b2d

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