annotate layer/SpectrumLayer.h @ 1238:4d0ca1ab4cd0

Some work to make spectrum layers (and slice layers generally) zoomable in the frequency axis. Also fixes a number of view id mixups in SliceLayer which broke offset calculations for the x axis scale.
author Chris Cannam
date Tue, 07 Feb 2017 14:55:19 +0000
parents 366ffdf719cd
children b7d3bd4ff43b
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@1238 26 #include "PianoScale.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@1238 34 public PianoScale::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);
Chris@193 43 virtual const Model *getModel() const { return m_originModel; }
Chris@133 44
Chris@918 45 virtual bool getCrosshairExtents(LayerGeometryProvider *, QPainter &, QPoint cursorPos,
Chris@254 46 std::vector<QRect> &extents) const;
Chris@918 47 virtual void paintCrosshairs(LayerGeometryProvider *, QPainter &, QPoint) const;
Chris@254 48
Chris@918 49 virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const;
Chris@199 50
Chris@916 51 virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const;
Chris@275 52
Chris@277 53 virtual VerticalPosition getPreferredFrameCountPosition() const {
Chris@277 54 return PositionTop;
Chris@277 55 }
Chris@277 56
Chris@153 57 virtual PropertyList getProperties() const;
Chris@153 58 virtual QString getPropertyLabel(const PropertyName &) const;
Chris@335 59 virtual QString getPropertyIconName(const PropertyName &) const;
Chris@153 60 virtual PropertyType getPropertyType(const PropertyName &) const;
Chris@153 61 virtual QString getPropertyGroupName(const PropertyName &) const;
Chris@153 62 virtual int getPropertyRangeAndValue(const PropertyName &,
Chris@216 63 int *min, int *max, int *deflt) const;
Chris@153 64 virtual QString getPropertyValueLabel(const PropertyName &,
Chris@153 65 int value) const;
Chris@167 66 virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const;
Chris@153 67 virtual void setProperty(const PropertyName &, int value);
Chris@133 68 virtual void setProperties(const QXmlAttributes &);
Chris@133 69
Chris@918 70 virtual bool getXScaleValue(const LayerGeometryProvider *v, int x,
Chris@905 71 double &value, QString &unit) const;
Chris@260 72
Chris@918 73 virtual bool getYScaleValue(const LayerGeometryProvider *, int y,
Chris@905 74 double &value, QString &unit) const;
Chris@274 75
Chris@918 76 virtual bool getYScaleDifference(const LayerGeometryProvider *, int y0, int y1,
Chris@905 77 double &diff, QString &unit) const;
Chris@274 78
Chris@918 79 virtual bool isLayerScrollable(const LayerGeometryProvider *) const { return false; }
Chris@133 80
Chris@153 81 void setChannel(int);
Chris@153 82 int getChannel() const { return m_channel; }
Chris@153 83
Chris@805 84 void setWindowSize(int);
Chris@805 85 int getWindowSize() const { return m_windowSize; }
Chris@153 86
Chris@805 87 void setWindowHopLevel(int level);
Chris@805 88 int getWindowHopLevel() const { return m_windowHopLevel; }
Chris@153 89
Chris@153 90 void setWindowType(WindowType type);
Chris@153 91 WindowType getWindowType() const { return m_windowType; }
Chris@153 92
Chris@284 93 void setShowPeaks(bool);
Chris@284 94 bool getShowPeaks() const { return m_showPeaks; }
Chris@284 95
Chris@316 96 virtual void toXml(QTextStream &stream, QString indent = "",
Chris@316 97 QString extraAttributes = "") const;
Chris@153 98
Chris@1238 99 virtual double getFrequencyForX(const LayerGeometryProvider *,
Chris@1238 100 double x) const override;
Chris@1238 101 virtual double getXForFrequency(const LayerGeometryProvider *,
Chris@1238 102 double freq) const override;
Chris@1238 103
Chris@153 104 protected slots:
Chris@153 105 void preferenceChanged(PropertyContainer::PropertyName name);
Chris@133 106
Chris@133 107 protected:
Chris@193 108 DenseTimeValueModel *m_originModel;
Chris@153 109 int m_channel;
Chris@153 110 bool m_channelSet;
Chris@805 111 int m_windowSize;
Chris@153 112 WindowType m_windowType;
Chris@805 113 int m_windowHopLevel;
Chris@284 114 bool m_showPeaks;
Chris@275 115 mutable bool m_newFFTNeeded;
Chris@153 116
Chris@349 117 mutable QMutex m_fftMutex;
Chris@349 118
Chris@193 119 void setupFFT();
Chris@153 120
Chris@254 121 virtual void getBiasCurve(BiasCurve &) const;
Chris@254 122 BiasCurve m_biasCurve;
Chris@254 123
Chris@805 124 int getWindowIncrement() const {
Chris@153 125 if (m_windowHopLevel == 0) return m_windowSize;
Chris@153 126 else if (m_windowHopLevel == 1) return (m_windowSize * 3) / 4;
Chris@153 127 else return m_windowSize / (1 << (m_windowHopLevel - 1));
Chris@153 128 }
Chris@133 129 };
Chris@133 130
Chris@133 131 #endif