annotate layer/SpectrumLayer.h @ 1332:6dac67c3ed82 zoom

Refactor out paintChannel
author Chris Cannam
date Fri, 21 Sep 2018 14:01:09 +0100
parents fc9d9f1103fa
children d79e21855aef
rev   line source
Chris@133 1
Chris@133 2 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@133 3
Chris@133 4 /*
Chris@133 5 Sonic Visualiser
Chris@133 6 An audio file viewer and annotation editor.
Chris@133 7 Centre for Digital Music, Queen Mary, University of London.
Chris@182 8 This file copyright 2006 QMUL.
Chris@133 9
Chris@133 10 This program is free software; you can redistribute it and/or
Chris@133 11 modify it under the terms of the GNU General Public License as
Chris@133 12 published by the Free Software Foundation; either version 2 of the
Chris@133 13 License, or (at your option) any later version. See the file
Chris@133 14 COPYING included with this distribution for more information.
Chris@133 15 */
Chris@133 16
Chris@1238 17 #ifndef SV_SPECTRUM_LAYER_H
Chris@1238 18 #define SV_SPECTRUM_LAYER_H
Chris@133 19
Chris@193 20 #include "SliceLayer.h"
Chris@133 21
Chris@153 22 #include "base/Window.h"
Chris@153 23
Chris@133 24 #include "data/model/DenseTimeValueModel.h"
Chris@133 25
Chris@1276 26 #include "HorizontalScaleProvider.h"
Chris@1238 27
Chris@133 28 #include <QColor>
Chris@349 29 #include <QMutex>
Chris@133 30
Chris@133 31 class FFTModel;
Chris@133 32
Chris@1238 33 class SpectrumLayer : public SliceLayer,
Chris@1276 34 public HorizontalScaleProvider
Chris@133 35 {
Chris@133 36 Q_OBJECT
Chris@133 37
Chris@133 38 public:
Chris@133 39 SpectrumLayer();
Chris@133 40 ~SpectrumLayer();
Chris@133 41
Chris@133 42 void setModel(DenseTimeValueModel *model);
cannam@1241 43 virtual const Model *getModel() const override { return m_originModel; }
Chris@133 44
Chris@918 45 virtual bool getCrosshairExtents(LayerGeometryProvider *, QPainter &, QPoint cursorPos,
cannam@1241 46 std::vector<QRect> &extents) const override;
cannam@1241 47 virtual void paintCrosshairs(LayerGeometryProvider *, QPainter &, QPoint) const override;
Chris@254 48
Chris@1281 49 virtual int getHorizontalScaleHeight(LayerGeometryProvider *, QPainter &) const;
Chris@1281 50 virtual void paintHorizontalScale(LayerGeometryProvider *, QPainter &, int xorigin) const;
Chris@1281 51
cannam@1241 52 virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override;
Chris@199 53
cannam@1241 54 virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override;
Chris@275 55
cannam@1241 56 virtual VerticalPosition getPreferredFrameCountPosition() const override {
Chris@1266 57 return PositionTop;
Chris@277 58 }
Chris@277 59
cannam@1241 60 virtual PropertyList getProperties() const override;
cannam@1241 61 virtual QString getPropertyLabel(const PropertyName &) const override;
cannam@1241 62 virtual QString getPropertyIconName(const PropertyName &) const override;
cannam@1241 63 virtual PropertyType getPropertyType(const PropertyName &) const override;
cannam@1241 64 virtual QString getPropertyGroupName(const PropertyName &) const override;
Chris@153 65 virtual int getPropertyRangeAndValue(const PropertyName &,
cannam@1241 66 int *min, int *max, int *deflt) const override;
Chris@153 67 virtual QString getPropertyValueLabel(const PropertyName &,
Chris@1266 68 int value) const override;
cannam@1241 69 virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const override;
cannam@1241 70 virtual void setProperty(const PropertyName &, int value) override;
cannam@1241 71 virtual void setProperties(const QXmlAttributes &) override;
Chris@133 72
Chris@918 73 virtual bool getXScaleValue(const LayerGeometryProvider *v, int x,
cannam@1241 74 double &value, QString &unit) const override;
Chris@260 75
Chris@918 76 virtual bool getYScaleValue(const LayerGeometryProvider *, int y,
cannam@1241 77 double &value, QString &unit) const override;
Chris@274 78
Chris@918 79 virtual bool getYScaleDifference(const LayerGeometryProvider *, int y0, int y1,
cannam@1241 80 double &diff, QString &unit) const override;
Chris@274 81
cannam@1241 82 virtual bool isLayerScrollable(const LayerGeometryProvider *) const override { return false; }
Chris@133 83
Chris@153 84 void setChannel(int);
Chris@153 85 int getChannel() const { return m_channel; }
Chris@153 86
Chris@805 87 void setWindowSize(int);
Chris@805 88 int getWindowSize() const { return m_windowSize; }
Chris@153 89
Chris@805 90 void setWindowHopLevel(int level);
Chris@805 91 int getWindowHopLevel() const { return m_windowHopLevel; }
Chris@153 92
Chris@153 93 void setWindowType(WindowType type);
Chris@153 94 WindowType getWindowType() const { return m_windowType; }
Chris@153 95
Chris@284 96 void setShowPeaks(bool);
Chris@284 97 bool getShowPeaks() const { return m_showPeaks; }
Chris@284 98
Chris@316 99 virtual void toXml(QTextStream &stream, QString indent = "",
cannam@1241 100 QString extraAttributes = "") const override;
Chris@153 101
Chris@1281 102 virtual double getFrequencyForX(const LayerGeometryProvider *, double x)
Chris@1281 103 const override;
Chris@1281 104 virtual double getXForFrequency(const LayerGeometryProvider *, double freq)
Chris@1281 105 const override;
Chris@1238 106
Chris@153 107 protected slots:
Chris@153 108 void preferenceChanged(PropertyContainer::PropertyName name);
Chris@133 109
Chris@133 110 protected:
Chris@193 111 DenseTimeValueModel *m_originModel;
Chris@153 112 int m_channel;
Chris@153 113 bool m_channelSet;
Chris@805 114 int m_windowSize;
Chris@153 115 WindowType m_windowType;
Chris@805 116 int m_windowHopLevel;
Chris@284 117 bool m_showPeaks;
Chris@275 118 mutable bool m_newFFTNeeded;
Chris@153 119
Chris@349 120 mutable QMutex m_fftMutex;
Chris@349 121
Chris@193 122 void setupFFT();
Chris@153 123
cannam@1241 124 virtual void getBiasCurve(BiasCurve &) const override;
Chris@254 125 BiasCurve m_biasCurve;
Chris@254 126
Chris@805 127 int getWindowIncrement() const {
Chris@153 128 if (m_windowHopLevel == 0) return m_windowSize;
Chris@153 129 else if (m_windowHopLevel == 1) return (m_windowSize * 3) / 4;
Chris@153 130 else return m_windowSize / (1 << (m_windowHopLevel - 1));
Chris@153 131 }
Chris@133 132 };
Chris@133 133
Chris@133 134 #endif