00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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(size_t);
00085 size_t getWindowSize() const { return m_windowSize; }
00086
00087 void setWindowHopLevel(size_t level);
00088 size_t 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 void toXml(QTextStream &stream, QString indent = "",
00097 QString extraAttributes = "") const;
00098
00099 protected slots:
00100 void preferenceChanged(PropertyContainer::PropertyName name);
00101
00102 protected:
00103
00104
00105
00106
00107
00108 DenseTimeValueModel *m_originModel;
00109 int m_channel;
00110 bool m_channelSet;
00111 size_t m_windowSize;
00112 WindowType m_windowType;
00113 size_t m_windowHopLevel;
00114 bool m_showPeaks;
00115 mutable bool m_newFFTNeeded;
00116
00117 mutable QMutex m_fftMutex;
00118
00119 void setupFFT();
00120
00121 virtual void getBiasCurve(BiasCurve &) const;
00122 BiasCurve m_biasCurve;
00123
00124 virtual float getXForBin(int bin, int totalBins, float w) const;
00125 virtual int getBinForX(float x, int totalBins, float w) const;
00126
00127 float getFrequencyForX(float x, float w) const;
00128 float getXForFrequency(float freq, float w) const;
00129
00130 size_t getWindowIncrement() const {
00131 if (m_windowHopLevel == 0) return m_windowSize;
00132 else if (m_windowHopLevel == 1) return (m_windowSize * 3) / 4;
00133 else return m_windowSize / (1 << (m_windowHopLevel - 1));
00134 }
00135 };
00136
00137 #endif