svgui
1.9
|
00001 00002 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00003 00004 /* 00005 Sonic Visualiser 00006 An audio file viewer and annotation editor. 00007 Centre for Digital Music, Queen Mary, University of London. 00008 This file copyright 2006 QMUL. 00009 00010 This program is free software; you can redistribute it and/or 00011 modify it under the terms of the GNU General Public License as 00012 published by the Free Software Foundation; either version 2 of the 00013 License, or (at your option) any later version. See the file 00014 COPYING included with this distribution for more information. 00015 */ 00016 00017 #ifndef _SPECTRUM_LAYER_H_ 00018 #define _SPECTRUM_LAYER_H_ 00019 00020 #include "SliceLayer.h" 00021 00022 #include "base/Window.h" 00023 00024 #include "data/model/DenseTimeValueModel.h" 00025 00026 #include <QColor> 00027 #include <QMutex> 00028 00029 class FFTModel; 00030 00031 class SpectrumLayer : public SliceLayer 00032 { 00033 Q_OBJECT 00034 00035 public: 00036 SpectrumLayer(); 00037 ~SpectrumLayer(); 00038 00039 void setModel(DenseTimeValueModel *model); 00040 virtual const Model *getModel() const { return m_originModel; } 00041 00042 virtual bool getCrosshairExtents(View *, QPainter &, QPoint cursorPos, 00043 std::vector<QRect> &extents) const; 00044 virtual void paintCrosshairs(View *, QPainter &, QPoint) const; 00045 00046 virtual QString getFeatureDescription(View *v, QPoint &) const; 00047 00048 virtual void paint(View *v, QPainter &paint, QRect rect) const; 00049 00050 virtual VerticalPosition getPreferredFrameCountPosition() const { 00051 return PositionTop; 00052 } 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 virtual void setProperties(const QXmlAttributes &); 00066 00067 virtual bool getValueExtents(float &min, float &max, 00068 bool &logarithmic, QString &unit) const; 00069 00070 virtual bool getXScaleValue(const View *v, int x, 00071 float &value, QString &unit) const; 00072 00073 virtual bool getYScaleValue(const View *, int y, 00074 float &value, QString &unit) const; 00075 00076 virtual bool getYScaleDifference(const View *, int y0, int y1, 00077 float &diff, QString &unit) const; 00078 00079 virtual bool isLayerScrollable(const View *) const { return false; } 00080 00081 void setChannel(int); 00082 int getChannel() const { return m_channel; } 00083 00084 void setWindowSize(int); 00085 int getWindowSize() const { return m_windowSize; } 00086 00087 void setWindowHopLevel(int level); 00088 int getWindowHopLevel() const { return m_windowHopLevel; } 00089 00090 void setWindowType(WindowType type); 00091 WindowType getWindowType() const { return m_windowType; } 00092 00093 void setShowPeaks(bool); 00094 bool getShowPeaks() const { return m_showPeaks; } 00095 00096 virtual int getVerticalScaleWidth(View *, bool, QPainter &) const { return 0; } 00097 00098 virtual void toXml(QTextStream &stream, QString indent = "", 00099 QString extraAttributes = "") const; 00100 00101 protected slots: 00102 void preferenceChanged(PropertyContainer::PropertyName name); 00103 00104 protected: 00105 // make this SliceLayer method unavailable to the general public 00106 // virtual void setModel(DenseThreeDimensionalModel *model) { 00107 // SliceLayer::setModel(model); 00108 // } 00109 00110 DenseTimeValueModel *m_originModel; 00111 int m_channel; 00112 bool m_channelSet; 00113 int m_windowSize; 00114 WindowType m_windowType; 00115 int m_windowHopLevel; 00116 bool m_showPeaks; 00117 mutable bool m_newFFTNeeded; 00118 00119 mutable QMutex m_fftMutex; 00120 00121 void setupFFT(); 00122 00123 virtual void getBiasCurve(BiasCurve &) const; 00124 BiasCurve m_biasCurve; 00125 00126 virtual float getXForBin(int bin, int totalBins, float w) const; 00127 virtual int getBinForX(float x, int totalBins, float w) const; 00128 00129 float getFrequencyForX(float x, float w) const; 00130 float getXForFrequency(float freq, float w) const; 00131 00132 int getWindowIncrement() const { 00133 if (m_windowHopLevel == 0) return m_windowSize; 00134 else if (m_windowHopLevel == 1) return (m_windowSize * 3) / 4; 00135 else return m_windowSize / (1 << (m_windowHopLevel - 1)); 00136 } 00137 }; 00138 00139 #endif