annotate layer/WaveformLayer.h @ 282:d9319859a4cf tip

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