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, QPainter &) const;
00050     virtual void paintVerticalScale(View *v, 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 
00167     void setAggressiveCacheing(bool);
00168     bool getAggressiveCacheing() const { return m_aggressive; }
00169 
00170     virtual bool isLayerScrollable(const View *) const;
00171 
00172     virtual int getCompletion(View *) const;
00173 
00174     virtual bool getValueExtents(float &min, float &max,
00175                                  bool &log, QString &unit) const;
00176 
00177     virtual bool getYScaleValue(const View *v, int y,
00178                                 float &value, QString &unit) const;
00179     
00180     virtual bool getYScaleDifference(const View *v, int y0, int y1,
00181                                      float &diff, QString &unit) const;
00182 
00183     virtual void toXml(QTextStream &stream, QString indent = "",
00184                        QString extraAttributes = "") const;
00185 
00186     virtual void setProperties(const QXmlAttributes &attributes);
00187 
00188     virtual int getVerticalZoomSteps(int &defaultStep) const;
00189     virtual int getCurrentVerticalZoomStep() const;
00190     virtual void setVerticalZoomStep(int);
00191 
00192 protected:
00193     int dBscale(float sample, int m) const;
00194 
00195     const RangeSummarisableTimeValueModel *m_model; // I do not own this
00196 
00198     size_t getChannelArrangement(size_t &min, size_t &max,
00199                                  bool &merging, bool &mixing) const;
00200 
00201     int getYForValue(const View *v, float value, size_t channel) const;
00202 
00203     float getValueForY(const View *v, int y, size_t &channel) const;
00204 
00205     bool getSourceFramesForX(View *v, int x, size_t modelZoomLevel,
00206                              size_t &f0, size_t &f1) const;
00207 
00208     float getNormalizeGain(View *v, int channel) const;
00209 
00210     virtual void flagBaseColourChanged() { m_cacheValid = false; }
00211 
00212     float        m_gain;
00213     bool         m_autoNormalize;
00214     bool         m_showMeans;
00215     bool         m_greyscale;
00216     ChannelMode  m_channelMode;
00217     int          m_channel;
00218     Scale        m_scale;
00219     bool         m_aggressive;
00220 
00221     mutable std::vector<float> m_effectiveGains;
00222 
00223     mutable QPixmap *m_cache;
00224     mutable bool m_cacheValid;
00225     mutable int m_cacheZoomLevel;
00226 };
00227 
00228 #endif

Generated on Wed Feb 20 15:45:30 2008 for SonicVisualiser by  doxygen 1.5.1