SpectrumLayer.h
Go to the documentation of this file.
1 
2 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
3 
4 /*
5  Sonic Visualiser
6  An audio file viewer and annotation editor.
7  Centre for Digital Music, Queen Mary, University of London.
8  This file copyright 2006 QMUL.
9 
10  This program is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License as
12  published by the Free Software Foundation; either version 2 of the
13  License, or (at your option) any later version. See the file
14  COPYING included with this distribution for more information.
15 */
16 
17 #ifndef SV_SPECTRUM_LAYER_H
18 #define SV_SPECTRUM_LAYER_H
19 
20 #include "SliceLayer.h"
21 
22 #include "base/Window.h"
23 
24 #include "data/model/DenseTimeValueModel.h"
25 
27 
28 #include <QColor>
29 #include <QMutex>
30 
31 class SpectrumLayer : public SliceLayer,
33 {
34  Q_OBJECT
35 
36 public:
37  SpectrumLayer();
39 
40  void setModel(ModelId model); // a DenseTimeValueModel
41  virtual ModelId getModel() const override { return m_originModel; }
42 
43  virtual bool getCrosshairExtents(LayerGeometryProvider *, QPainter &, QPoint cursorPos,
44  std::vector<QRect> &extents) const override;
45  virtual void paintCrosshairs(LayerGeometryProvider *, QPainter &, QPoint) const override;
46 
47  virtual int getHorizontalScaleHeight(LayerGeometryProvider *, QPainter &) const override;
48  virtual void paintHorizontalScale(LayerGeometryProvider *, QPainter &, int xorigin) const;
49 
50  virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override;
51 
52  virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override;
53 
55  return PositionTop;
56  }
57 
58  virtual PropertyList getProperties() const override;
59  virtual QString getPropertyLabel(const PropertyName &) const override;
60  virtual QString getPropertyIconName(const PropertyName &) const override;
61  virtual PropertyType getPropertyType(const PropertyName &) const override;
62  virtual QString getPropertyGroupName(const PropertyName &) const override;
63  virtual int getPropertyRangeAndValue(const PropertyName &,
64  int *min, int *max, int *deflt) const override;
65  virtual QString getPropertyValueLabel(const PropertyName &,
66  int value) const override;
67  virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const override;
68  virtual void setProperty(const PropertyName &, int value) override;
69  virtual void setProperties(const QXmlAttributes &) override;
70 
71  virtual bool setDisplayExtents(double min, double max) override;
72 
73  virtual bool getXScaleValue(const LayerGeometryProvider *v, int x,
74  double &value, QString &unit) const override;
75 
76  virtual bool getYScaleValue(const LayerGeometryProvider *, int y,
77  double &value, QString &unit) const override;
78 
79  virtual bool getYScaleDifference(const LayerGeometryProvider *, int y0, int y1,
80  double &diff, QString &unit) const override;
81 
82  virtual bool isLayerScrollable(const LayerGeometryProvider *) const override { return false; }
83 
84  void setChannel(int);
85  int getChannel() const { return m_channel; }
86 
87  void setWindowSize(int);
88  int getWindowSize() const { return m_windowSize; }
89 
90  void setWindowHopLevel(int level);
91  int getWindowHopLevel() const { return m_windowHopLevel; }
92 
93  void setOversampling(int oversampling);
94  int getOversampling() const;
95 
96  int getFFTSize() const { return getWindowSize() * getOversampling(); }
97 
98  void setWindowType(WindowType type);
99  WindowType getWindowType() const { return m_windowType; }
100 
101  void setShowPeaks(bool);
102  bool getShowPeaks() const { return m_showPeaks; }
103 
104  bool needsTextLabelHeight() const override { return true; }
105 
106  virtual void toXml(QTextStream &stream, QString indent = "",
107  QString extraAttributes = "") const override;
108 
109  virtual double getFrequencyForX(const LayerGeometryProvider *, double x)
110  const override;
111  virtual double getXForFrequency(const LayerGeometryProvider *, double freq)
112  const override;
113 
114 protected slots:
115  void preferenceChanged(PropertyContainer::PropertyName name);
116 
117 protected:
118  ModelId m_originModel; // a DenseTimeValueModel
122  WindowType m_windowType;
126  mutable bool m_newFFTNeeded;
127 
128  double m_freqOfMinBin; // used to ensure accurate
129  // alignment when changing
130  // fft size
131 
132  mutable QMutex m_fftMutex;
133 
134  void setupFFT();
135 
136  virtual double getBinForFrequency(double freq) const;
137  virtual double getFrequencyForBin(double bin) const;
138 
139  virtual double getXForBin(const LayerGeometryProvider *, double bin)
140  const override;
141  virtual double getBinForX(const LayerGeometryProvider *, double x)
142  const override;
143 
144  virtual void getBiasCurve(BiasCurve &) const override;
146 
147  int getWindowIncrement() const {
148  if (m_windowHopLevel == 0) return m_windowSize;
149  else if (m_windowHopLevel == 1) return (m_windowSize * 3) / 4;
150  else return m_windowSize / (1 << (m_windowHopLevel - 1));
151  }
152 };
153 
154 #endif
virtual void setProperty(const PropertyName &, int value) override
virtual ModelId getModel() const override
Return the ID of the model represented in this layer.
Definition: SpectrumLayer.h:41
void setChannel(int)
void setWindowSize(int)
int getOversampling() const
virtual void getBiasCurve(BiasCurve &) const override
bool needsTextLabelHeight() const override
True if this layer will need to place text labels when it is painted.
virtual RangeMapper * getNewPropertyRangeMapper(const PropertyName &) const override
virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override
virtual double getXForBin(const LayerGeometryProvider *, double bin) const override
Convert a (possibly non-integral) bin into x-coord. May be overridden.
VerticalPosition
Definition: Layer.h:140
virtual double getXForFrequency(const LayerGeometryProvider *, double freq) const override
int getWindowSize() const
Definition: SpectrumLayer.h:88
virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override
Paint the given rectangle of this layer onto the given view using the given painter, superimposing it on top of any existing material in that view.
Interface for classes that provide geometry information (such as size, start frame, and a large number of other properties) about the disposition of a layer.
virtual int getHorizontalScaleHeight(LayerGeometryProvider *, QPainter &) const override
int getWindowIncrement() const
void preferenceChanged(PropertyContainer::PropertyName name)
virtual QString getPropertyValueLabel(const PropertyName &, int value) const override
virtual double getFrequencyForX(const LayerGeometryProvider *, double x) const override
bool getShowPeaks() const
virtual bool getYScaleValue(const LayerGeometryProvider *, int y, double &value, QString &unit) const override
Return the value and unit at the given y coordinate in the given view.
virtual int getPropertyRangeAndValue(const PropertyName &, int *min, int *max, int *deflt) const override
BiasCurve m_biasCurve
virtual VerticalPosition getPreferredFrameCountPosition() const override
Definition: SpectrumLayer.h:54
double m_freqOfMinBin
virtual bool getYScaleDifference(const LayerGeometryProvider *, int y0, int y1, double &diff, QString &unit) const override
Return the difference between the values at the given y coordinates in the given view, and the unit of the difference.
virtual PropertyType getPropertyType(const PropertyName &) const override
WindowType getWindowType() const
Definition: SpectrumLayer.h:99
virtual double getFrequencyForBin(double bin) const
virtual double getBinForX(const LayerGeometryProvider *, double x) const override
Convert an x-coord into (possibly non-integral) bin. May be overridden.
virtual void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const override
int getFFTSize() const
Definition: SpectrumLayer.h:96
virtual bool setDisplayExtents(double min, double max) override
Set the displayed minimum and maximum values for the y axis to the given range, if supported...
void setModel(ModelId model)
ModelId m_originModel
WindowType m_windowType
virtual void paintCrosshairs(LayerGeometryProvider *, QPainter &, QPoint) const override
std::vector< float > BiasCurve
Definition: SliceLayer.h:150
virtual void paintHorizontalScale(LayerGeometryProvider *, QPainter &, int xorigin) const
virtual PropertyList getProperties() const override
void setOversampling(int oversampling)
virtual bool getXScaleValue(const LayerGeometryProvider *v, int x, double &value, QString &unit) const override
Return the value and unit at the given x coordinate in the given view.
int getWindowHopLevel() const
Definition: SpectrumLayer.h:91
int getChannel() const
Definition: SpectrumLayer.h:85
void setWindowType(WindowType type)
void setWindowHopLevel(int level)
void setShowPeaks(bool)
virtual double getBinForFrequency(double freq) const
virtual void setProperties(const QXmlAttributes &) override
Set the particular properties of a layer (those specific to the subclass) from a set of XML attribute...
virtual QString getPropertyGroupName(const PropertyName &) const override
virtual QString getPropertyLabel(const PropertyName &) const override
virtual bool getCrosshairExtents(LayerGeometryProvider *, QPainter &, QPoint cursorPos, std::vector< QRect > &extents) const override
virtual bool isLayerScrollable(const LayerGeometryProvider *) const override
This should return true if the layer can safely be scrolled automatically by a given view (simply cop...
Definition: SpectrumLayer.h:82
virtual QString getPropertyIconName(const PropertyName &) const override
Interface to be implemented by objects, such as layers or objects they delegate to, in which the X axis corresponds to frequency.