annotate layer/WaveformLayer.h @ 312:6de6f78b13a1

* Make it possible to drop audio files, layer files, session files and images onto SV panes. Need to do a bit more work on where we expect the dropped file to go, particularly in the case of audio files -- at the moment they're always opened in new panes, but it may be better to by default replace whatever is in the target pane.
author Chris Cannam
date Wed, 10 Oct 2007 15:18:02 +0000
parents cd2492c5fe45
children c0b9eec70639
rev   line source
Chris@58 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@59 4 Sonic Visualiser
Chris@59 5 An audio file viewer and annotation editor.
Chris@59 6 Centre for Digital Music, Queen Mary, University of London.
Chris@182 7 This file copyright 2006 Chris Cannam and QMUL.
Chris@0 8
Chris@59 9 This program is free software; you can redistribute it and/or
Chris@59 10 modify it under the terms of the GNU General Public License as
Chris@59 11 published by the Free Software Foundation; either version 2 of the
Chris@59 12 License, or (at your option) any later version. See the file
Chris@59 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@30 16 #ifndef _WAVEFORM_LAYER_H_
Chris@30 17 #define _WAVEFORM_LAYER_H_
Chris@0 18
Chris@0 19 #include <QRect>
Chris@0 20
Chris@287 21 #include "SingleColourLayer.h"
Chris@0 22
Chris@128 23 #include "data/model/RangeSummarisableTimeValueModel.h"
Chris@0 24
Chris@0 25 class View;
Chris@0 26 class QPainter;
Chris@0 27 class QPixmap;
Chris@0 28
Chris@287 29 class WaveformLayer : public SingleColourLayer
Chris@0 30 {
Chris@0 31 Q_OBJECT
Chris@0 32
Chris@0 33 public:
Chris@44 34 WaveformLayer();
Chris@0 35 ~WaveformLayer();
Chris@0 36
Chris@156 37 virtual const ZoomConstraint *getZoomConstraint() const {
Chris@156 38 return m_model ? m_model->getZoomConstraint() : 0;
Chris@156 39 }
Chris@0 40 virtual const Model *getModel() const { return m_model; }
Chris@44 41 virtual void paint(View *v, QPainter &paint, QRect rect) const;
Chris@0 42
Chris@44 43 virtual QString getFeatureDescription(View *v, QPoint &) const;
Chris@25 44
Chris@287 45 virtual ColourSignificance getLayerColourSignificance() const {
Chris@287 46 return ColourAndBackgroundSignificant;
Chris@287 47 }
Chris@287 48
Chris@44 49 virtual int getVerticalScaleWidth(View *v, QPainter &) const;
Chris@44 50 virtual void paintVerticalScale(View *v, QPainter &paint, QRect rect) const;
Chris@0 51
Chris@0 52 void setModel(const RangeSummarisableTimeValueModel *model);
Chris@0 53
Chris@0 54 virtual PropertyList getProperties() const;
Chris@87 55 virtual QString getPropertyLabel(const PropertyName &) const;
Chris@0 56 virtual PropertyType getPropertyType(const PropertyName &) const;
Chris@0 57 virtual QString getPropertyGroupName(const PropertyName &) const;
Chris@0 58 virtual int getPropertyRangeAndValue(const PropertyName &,
Chris@216 59 int *min, int *max, int *deflt) const;
Chris@0 60 virtual QString getPropertyValueLabel(const PropertyName &,
Chris@0 61 int value) const;
Chris@167 62 virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const;
Chris@0 63 virtual void setProperty(const PropertyName &, int value);
Chris@0 64
Chris@0 65 /**
Chris@0 66 * Set the gain multiplier for sample values in this view.
Chris@0 67 *
Chris@0 68 * The default is 1.0.
Chris@0 69 */
Chris@0 70 void setGain(float gain);
Chris@0 71 float getGain() const { return m_gain; }
Chris@0 72
Chris@0 73 /**
Chris@67 74 * Toggle automatic normalization of the currently visible waveform.
Chris@67 75 */
Chris@67 76 void setAutoNormalize(bool);
Chris@67 77 bool getAutoNormalize() const { return m_autoNormalize; }
Chris@67 78
Chris@67 79 /**
Chris@0 80 * Set whether to display mean values as a lighter-coloured area
Chris@0 81 * beneath the peaks. Rendering will be slightly faster without
Chris@0 82 * but arguably prettier with.
Chris@0 83 *
Chris@0 84 * The default is to display means.
Chris@0 85 */
Chris@0 86 void setShowMeans(bool);
Chris@0 87 bool getShowMeans() const { return m_showMeans; }
Chris@0 88
Chris@0 89 /**
Chris@0 90 * Set whether to use shades of grey (or of the base colour) to
Chris@0 91 * provide additional perceived vertical resolution (i.e. using
Chris@0 92 * half-filled pixels to represent levels that only just meet the
Chris@0 93 * pixel unit boundary). This provides a small improvement in
Chris@0 94 * waveform quality at a small cost in rendering speed.
Chris@0 95 *
Chris@0 96 * The default is to use greyscale.
Chris@0 97 */
Chris@0 98 void setUseGreyscale(bool);
Chris@0 99 bool getUseGreyscale() const { return m_greyscale; }
Chris@0 100
Chris@0 101
Chris@67 102 enum ChannelMode { SeparateChannels, MixChannels, MergeChannels };
Chris@0 103
Chris@0 104 /**
Chris@0 105 * Specify whether multi-channel audio data should be displayed
Chris@67 106 * with a separate axis per channel (SeparateChannels), with a
Chris@0 107 * single synthetic axis showing channel 0 above the axis and
Chris@67 108 * channel 1 below (MergeChannels), or with a single axis showing
Chris@67 109 * the average of the channels (MixChannels).
Chris@0 110 *
Chris@0 111 * MergeChannels does not work for files with more than 2
Chris@0 112 * channels.
Chris@0 113 *
Chris@0 114 * The default is SeparateChannels.
Chris@0 115 */
Chris@0 116 void setChannelMode(ChannelMode);
Chris@0 117 ChannelMode getChannelMode() const { return m_channelMode; }
Chris@0 118
Chris@0 119
Chris@0 120 /**
Chris@0 121 * Specify the channel to use from the source model. A value of
Chris@0 122 * -1 means to show all available channels (laid out to the
Chris@0 123 * channel mode). The default is -1.
Chris@0 124 */
Chris@0 125 void setChannel(int);
Chris@0 126 int getChannel() const { return m_channel; }
Chris@0 127
Chris@0 128
Chris@0 129 enum Scale { LinearScale, MeterScale, dBScale };
Chris@0 130
Chris@0 131 /**
Chris@0 132 * Specify the vertical scale for sample levels. With LinearScale,
Chris@0 133 * the scale is directly proportional to the raw [-1, +1)
Chris@0 134 * floating-point audio sample values. With dBScale the
Chris@0 135 * vertical scale is proportional to dB level (truncated at
Chris@0 136 * -50dB). MeterScale provides a hybrid variable scale based on
Chris@0 137 * IEC meter scale, intended to provide a clear overview at
Chris@0 138 * relatively small heights.
Chris@0 139 *
Chris@0 140 * Note that the effective gain (see setGain()) is applied before
Chris@0 141 * vertical scaling.
Chris@0 142 *
Chris@0 143 * The default is LinearScale.
Chris@0 144 */
Chris@0 145 void setScale(Scale);
Chris@0 146 Scale getScale() const { return m_scale; }
Chris@0 147
Chris@0 148 /**
Chris@0 149 * Enable or disable aggressive pixmap cacheing. If enabled,
Chris@0 150 * waveforms will be rendered to an off-screen pixmap and
Chris@0 151 * refreshed from there instead of being redrawn from the peak
Chris@0 152 * data each time. This may be faster if the data and zoom level
Chris@0 153 * do not change often, but it may be slower for frequently zoomed
Chris@0 154 * data and it will only work if the waveform is the "bottom"
Chris@0 155 * layer on the displayed widget, as each refresh will erase
Chris@0 156 * anything beneath the waveform.
Chris@0 157 *
Chris@0 158 * This is intended specifically for a panner widget display in
Chris@0 159 * which the waveform never moves, zooms, or changes, but some
Chris@0 160 * graphic such as a panner outline is frequently redrawn over the
Chris@0 161 * waveform. This situation would necessitate a lot of waveform
Chris@0 162 * refresh if the default cacheing strategy was used.
Chris@0 163 *
Chris@0 164 * The default is not to use aggressive cacheing.
Chris@0 165 */
Chris@0 166 void setAggressiveCacheing(bool);
Chris@0 167 bool getAggressiveCacheing() const { return m_aggressive; }
Chris@0 168
Chris@67 169 virtual bool isLayerScrollable(const View *) const;
Chris@67 170
Chris@115 171 virtual int getCompletion(View *) const;
Chris@0 172
Chris@101 173 virtual bool getValueExtents(float &min, float &max,
Chris@101 174 bool &log, QString &unit) const;
Chris@79 175
Chris@267 176 virtual bool getYScaleValue(const View *v, int y,
Chris@261 177 float &value, QString &unit) const;
Chris@274 178
Chris@274 179 virtual bool getYScaleDifference(const View *v, int y0, int y1,
Chris@274 180 float &diff, QString &unit) const;
Chris@261 181
Chris@6 182 virtual QString toXmlString(QString indent = "",
Chris@6 183 QString extraAttributes = "") const;
Chris@6 184
Chris@287 185 virtual void setProperties(const QXmlAttributes &attributes);
Chris@11 186
Chris@133 187 virtual int getVerticalZoomSteps(int &defaultStep) const;
Chris@133 188 virtual int getCurrentVerticalZoomStep() const;
Chris@133 189 virtual void setVerticalZoomStep(int);
Chris@133 190
Chris@0 191 protected:
Chris@0 192 int dBscale(float sample, int m) const;
Chris@0 193
Chris@0 194 const RangeSummarisableTimeValueModel *m_model; // I do not own this
Chris@0 195
Chris@0 196 /// Return value is number of channels displayed
Chris@67 197 size_t getChannelArrangement(size_t &min, size_t &max,
Chris@67 198 bool &merging, bool &mixing) const;
Chris@0 199
Chris@274 200 int getYForValue(const View *v, float value, size_t channel) const;
Chris@68 201
Chris@274 202 float getValueForY(const View *v, int y, size_t &channel) const;
Chris@261 203
Chris@287 204 virtual void flagBaseColourChanged() { m_cacheValid = false; }
Chris@287 205
Chris@6 206 float m_gain;
Chris@67 207 bool m_autoNormalize;
Chris@6 208 bool m_showMeans;
Chris@6 209 bool m_greyscale;
Chris@6 210 ChannelMode m_channelMode;
Chris@6 211 int m_channel;
Chris@6 212 Scale m_scale;
Chris@6 213 bool m_aggressive;
Chris@0 214
Chris@67 215 mutable std::vector<float> m_effectiveGains;
Chris@67 216
Chris@0 217 mutable QPixmap *m_cache;
Chris@0 218 mutable bool m_cacheValid;
Chris@0 219 mutable int m_cacheZoomLevel;
Chris@0 220 };
Chris@0 221
Chris@0 222 #endif