svgui  1.9
WaveformLayer.h
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     Sonic Visualiser
00005     An audio file viewer and annotation editor.
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file copyright 2006 Chris Cannam and QMUL.
00008     
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014 */
00015 
00016 #ifndef _WAVEFORM_LAYER_H_
00017 #define _WAVEFORM_LAYER_H_
00018 
00019 #include <QRect>
00020 
00021 #include "SingleColourLayer.h"
00022 
00023 #include "data/model/RangeSummarisableTimeValueModel.h"
00024 
00025 class View;
00026 class QPainter;
00027 class QPixmap;
00028 
00029 class WaveformLayer : public SingleColourLayer
00030 {
00031     Q_OBJECT
00032 
00033 public:
00034     WaveformLayer();
00035     ~WaveformLayer();
00036 
00037     virtual const ZoomConstraint *getZoomConstraint() const {
00038         return m_model ? m_model->getZoomConstraint() : 0;
00039     }
00040     virtual const Model *getModel() const { return m_model; }
00041     virtual void paint(View *v, QPainter &paint, QRect rect) const;
00042 
00043     virtual QString getFeatureDescription(View *v, QPoint &) const;
00044 
00045     virtual ColourSignificance getLayerColourSignificance() const {
00046         return ColourAndBackgroundSignificant;
00047     }
00048 
00049     virtual int getVerticalScaleWidth(View *v, bool detailed, QPainter &) const;
00050     virtual void paintVerticalScale(View *v, bool detailed, QPainter &paint, QRect rect) const;
00051 
00052     void setModel(const RangeSummarisableTimeValueModel *model);
00053 
00054     virtual PropertyList getProperties() const;
00055     virtual QString getPropertyLabel(const PropertyName &) const;
00056     virtual QString getPropertyIconName(const PropertyName &) const;
00057     virtual PropertyType getPropertyType(const PropertyName &) const;
00058     virtual QString getPropertyGroupName(const PropertyName &) const;
00059     virtual int getPropertyRangeAndValue(const PropertyName &,
00060                                          int *min, int *max, int *deflt) const;
00061     virtual QString getPropertyValueLabel(const PropertyName &,
00062                                           int value) const;
00063     virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const;
00064     virtual void setProperty(const PropertyName &, int value);
00065 
00071     void setGain(float gain);
00072     float getGain() const { return m_gain; }
00073 
00077     void setAutoNormalize(bool);
00078     bool getAutoNormalize() const { return m_autoNormalize; }
00079 
00087     void setShowMeans(bool);
00088     bool getShowMeans() const { return m_showMeans; }
00089 
00099     void setUseGreyscale(bool);
00100     bool getUseGreyscale() const { return m_greyscale; }
00101 
00102 
00103     enum ChannelMode { SeparateChannels, MixChannels, MergeChannels };
00104 
00117     void setChannelMode(ChannelMode);
00118     ChannelMode getChannelMode() const { return m_channelMode; }
00119 
00120 
00126     void setChannel(int);
00127     int getChannel() const { return m_channel; }
00128 
00129 
00130     enum Scale { LinearScale, MeterScale, dBScale };
00131 
00146     void setScale(Scale);
00147     Scale getScale() const { return m_scale; }
00148 
00159     void setMiddleLineHeight(float height);
00160     float getMiddleLineHeight() const { return m_middleLineHeight; }
00161 
00180     void setAggressiveCacheing(bool);
00181     bool getAggressiveCacheing() const { return m_aggressive; }
00182 
00183     virtual bool isLayerScrollable(const View *) const;
00184 
00185     virtual int getCompletion(View *) const;
00186 
00187     virtual bool getValueExtents(float &min, float &max,
00188                                  bool &log, QString &unit) const;
00189 
00190     virtual bool getYScaleValue(const View *v, int y,
00191                                 float &value, QString &unit) const;
00192     
00193     virtual bool getYScaleDifference(const View *v, int y0, int y1,
00194                                      float &diff, QString &unit) const;
00195 
00196     virtual void toXml(QTextStream &stream, QString indent = "",
00197                        QString extraAttributes = "") const;
00198 
00199     virtual void setProperties(const QXmlAttributes &attributes);
00200 
00201     virtual int getVerticalZoomSteps(int &defaultStep) const;
00202     virtual int getCurrentVerticalZoomStep() const;
00203     virtual void setVerticalZoomStep(int);
00204 
00205 protected:
00206     int dBscale(float sample, int m) const;
00207 
00208     const RangeSummarisableTimeValueModel *m_model; // I do not own this
00209 
00211     int getChannelArrangement(int &min, int &max,
00212                                  bool &merging, bool &mixing) const;
00213 
00214     int getYForValue(const View *v, float value, int channel) const;
00215 
00216     float getValueForY(const View *v, int y, int &channel) const;
00217 
00218     bool getSourceFramesForX(View *v, int x, int modelZoomLevel,
00219                              int &f0, int &f1) const;
00220 
00221     float getNormalizeGain(View *v, int channel) const;
00222 
00223     virtual void flagBaseColourChanged() { m_cacheValid = false; }
00224 
00225     float        m_gain;
00226     bool         m_autoNormalize;
00227     bool         m_showMeans;
00228     bool         m_greyscale;
00229     ChannelMode  m_channelMode;
00230     int          m_channel;
00231     Scale        m_scale;
00232     float        m_middleLineHeight;
00233     bool         m_aggressive;
00234 
00235     mutable std::vector<float> m_effectiveGains;
00236 
00237     mutable QPixmap *m_cache;
00238     mutable bool m_cacheValid;
00239     mutable int m_cacheZoomLevel;
00240 };
00241 
00242 #endif