Chris@133: Chris@133: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@133: Chris@133: /* Chris@133: Sonic Visualiser Chris@133: An audio file viewer and annotation editor. Chris@133: Centre for Digital Music, Queen Mary, University of London. Chris@182: This file copyright 2006 QMUL. Chris@133: Chris@133: This program is free software; you can redistribute it and/or Chris@133: modify it under the terms of the GNU General Public License as Chris@133: published by the Free Software Foundation; either version 2 of the Chris@133: License, or (at your option) any later version. See the file Chris@133: COPYING included with this distribution for more information. Chris@133: */ Chris@133: Chris@1238: #ifndef SV_SPECTRUM_LAYER_H Chris@1238: #define SV_SPECTRUM_LAYER_H Chris@133: Chris@193: #include "SliceLayer.h" Chris@133: Chris@153: #include "base/Window.h" Chris@153: Chris@133: #include "data/model/DenseTimeValueModel.h" Chris@133: Chris@1276: #include "HorizontalScaleProvider.h" Chris@1238: Chris@133: #include Chris@349: #include Chris@133: Chris@1238: class SpectrumLayer : public SliceLayer, Chris@1276: public HorizontalScaleProvider Chris@133: { Chris@133: Q_OBJECT Chris@133: Chris@133: public: Chris@133: SpectrumLayer(); Chris@133: ~SpectrumLayer(); Chris@133: Chris@133: void setModel(DenseTimeValueModel *model); cannam@1241: virtual const Model *getModel() const override { return m_originModel; } Chris@133: Chris@918: virtual bool getCrosshairExtents(LayerGeometryProvider *, QPainter &, QPoint cursorPos, cannam@1241: std::vector &extents) const override; cannam@1241: virtual void paintCrosshairs(LayerGeometryProvider *, QPainter &, QPoint) const override; Chris@254: Chris@1383: virtual int getHorizontalScaleHeight(LayerGeometryProvider *, QPainter &) const override; Chris@1281: virtual void paintHorizontalScale(LayerGeometryProvider *, QPainter &, int xorigin) const; Chris@1281: cannam@1241: virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override; Chris@199: cannam@1241: virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override; Chris@275: cannam@1241: virtual VerticalPosition getPreferredFrameCountPosition() const override { Chris@1266: return PositionTop; Chris@277: } Chris@277: cannam@1241: virtual PropertyList getProperties() const override; cannam@1241: virtual QString getPropertyLabel(const PropertyName &) const override; cannam@1241: virtual QString getPropertyIconName(const PropertyName &) const override; cannam@1241: virtual PropertyType getPropertyType(const PropertyName &) const override; cannam@1241: virtual QString getPropertyGroupName(const PropertyName &) const override; Chris@153: virtual int getPropertyRangeAndValue(const PropertyName &, cannam@1241: int *min, int *max, int *deflt) const override; Chris@153: virtual QString getPropertyValueLabel(const PropertyName &, Chris@1266: int value) const override; cannam@1241: virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const override; cannam@1241: virtual void setProperty(const PropertyName &, int value) override; cannam@1241: virtual void setProperties(const QXmlAttributes &) override; Chris@133: Chris@1403: virtual bool setDisplayExtents(double min, double max) override; Chris@1403: Chris@918: virtual bool getXScaleValue(const LayerGeometryProvider *v, int x, cannam@1241: double &value, QString &unit) const override; Chris@260: Chris@918: virtual bool getYScaleValue(const LayerGeometryProvider *, int y, cannam@1241: double &value, QString &unit) const override; Chris@274: Chris@918: virtual bool getYScaleDifference(const LayerGeometryProvider *, int y0, int y1, cannam@1241: double &diff, QString &unit) const override; Chris@274: cannam@1241: virtual bool isLayerScrollable(const LayerGeometryProvider *) const override { return false; } Chris@133: Chris@153: void setChannel(int); Chris@153: int getChannel() const { return m_channel; } Chris@153: Chris@805: void setWindowSize(int); Chris@805: int getWindowSize() const { return m_windowSize; } Chris@153: Chris@805: void setWindowHopLevel(int level); Chris@805: int getWindowHopLevel() const { return m_windowHopLevel; } Chris@153: Chris@1382: void setOversampling(int oversampling); Chris@1382: int getOversampling() const; Chris@1382: Chris@1382: int getFFTSize() const { return getWindowSize() * getOversampling(); } Chris@1382: Chris@153: void setWindowType(WindowType type); Chris@153: WindowType getWindowType() const { return m_windowType; } Chris@1382: Chris@284: void setShowPeaks(bool); Chris@284: bool getShowPeaks() const { return m_showPeaks; } Chris@284: Chris@1406: bool needsTextLabelHeight() const override { return true; } Chris@1392: Chris@316: virtual void toXml(QTextStream &stream, QString indent = "", cannam@1241: QString extraAttributes = "") const override; Chris@153: Chris@1281: virtual double getFrequencyForX(const LayerGeometryProvider *, double x) Chris@1281: const override; Chris@1281: virtual double getXForFrequency(const LayerGeometryProvider *, double freq) Chris@1281: const override; Chris@1238: Chris@153: protected slots: Chris@153: void preferenceChanged(PropertyContainer::PropertyName name); Chris@133: Chris@133: protected: Chris@193: DenseTimeValueModel *m_originModel; Chris@153: int m_channel; Chris@153: bool m_channelSet; Chris@1362: int m_windowSize; Chris@153: WindowType m_windowType; Chris@1362: int m_windowHopLevel; Chris@1382: int m_oversampling; Chris@284: bool m_showPeaks; Chris@275: mutable bool m_newFFTNeeded; Chris@153: Chris@1403: double m_freqOfMinBin; // used to ensure accurate Chris@1403: // alignment when changing Chris@1403: // fft size Chris@1403: Chris@349: mutable QMutex m_fftMutex; Chris@349: Chris@193: void setupFFT(); Chris@153: Chris@1386: virtual double getBinForFrequency(double freq) const; Chris@1386: virtual double getFrequencyForBin(double bin) const; Chris@1386: Chris@1386: virtual double getXForBin(const LayerGeometryProvider *, double bin) Chris@1386: const override; Chris@1386: virtual double getBinForX(const LayerGeometryProvider *, double x) Chris@1386: const override; Chris@1386: cannam@1241: virtual void getBiasCurve(BiasCurve &) const override; Chris@254: BiasCurve m_biasCurve; Chris@254: Chris@805: int getWindowIncrement() const { Chris@153: if (m_windowHopLevel == 0) return m_windowSize; Chris@153: else if (m_windowHopLevel == 1) return (m_windowSize * 3) / 4; Chris@153: else return m_windowSize / (1 << (m_windowHopLevel - 1)); Chris@153: } Chris@133: }; Chris@133: Chris@133: #endif