svgui  1.9
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 _SPECTRUM_LAYER_H_
18 #define _SPECTRUM_LAYER_H_
19 
20 #include "SliceLayer.h"
21 
22 #include "base/Window.h"
23 
24 #include "data/model/DenseTimeValueModel.h"
25 
26 #include <QColor>
27 #include <QMutex>
28 
29 class FFTModel;
30 
31 class SpectrumLayer : public SliceLayer
32 {
33  Q_OBJECT
34 
35 public:
36  SpectrumLayer();
38 
39  void setModel(DenseTimeValueModel *model);
40  virtual const Model *getModel() const { return m_originModel; }
41 
42  virtual bool getCrosshairExtents(View *, QPainter &, QPoint cursorPos,
43  std::vector<QRect> &extents) const;
44  virtual void paintCrosshairs(View *, QPainter &, QPoint) const;
45 
46  virtual QString getFeatureDescription(View *v, QPoint &) const;
47 
48  virtual void paint(View *v, QPainter &paint, QRect rect) const;
49 
51  return PositionTop;
52  }
53 
54  virtual PropertyList getProperties() const;
55  virtual QString getPropertyLabel(const PropertyName &) const;
56  virtual QString getPropertyIconName(const PropertyName &) const;
57  virtual PropertyType getPropertyType(const PropertyName &) const;
58  virtual QString getPropertyGroupName(const PropertyName &) const;
59  virtual int getPropertyRangeAndValue(const PropertyName &,
60  int *min, int *max, int *deflt) const;
61  virtual QString getPropertyValueLabel(const PropertyName &,
62  int value) const;
63  virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const;
64  virtual void setProperty(const PropertyName &, int value);
65  virtual void setProperties(const QXmlAttributes &);
66 
67  virtual bool getValueExtents(float &min, float &max,
68  bool &logarithmic, QString &unit) const;
69 
70  virtual bool getXScaleValue(const View *v, int x,
71  float &value, QString &unit) const;
72 
73  virtual bool getYScaleValue(const View *, int y,
74  float &value, QString &unit) const;
75 
76  virtual bool getYScaleDifference(const View *, int y0, int y1,
77  float &diff, QString &unit) const;
78 
79  virtual bool isLayerScrollable(const View *) const { return false; }
80 
81  void setChannel(int);
82  int getChannel() const { return m_channel; }
83 
84  void setWindowSize(int);
85  int getWindowSize() const { return m_windowSize; }
86 
87  void setWindowHopLevel(int level);
88  int getWindowHopLevel() const { return m_windowHopLevel; }
89 
90  void setWindowType(WindowType type);
91  WindowType getWindowType() const { return m_windowType; }
92 
93  void setShowPeaks(bool);
94  bool getShowPeaks() const { return m_showPeaks; }
95 
96  virtual int getVerticalScaleWidth(View *, bool, QPainter &) const { return 0; }
97 
98  virtual void toXml(QTextStream &stream, QString indent = "",
99  QString extraAttributes = "") const;
100 
101 protected slots:
102  void preferenceChanged(PropertyContainer::PropertyName name);
103 
104 protected:
105  // make this SliceLayer method unavailable to the general public
106 // virtual void setModel(DenseThreeDimensionalModel *model) {
107 // SliceLayer::setModel(model);
108 // }
109 
110  DenseTimeValueModel *m_originModel;
114  WindowType m_windowType;
117  mutable bool m_newFFTNeeded;
118 
119  mutable QMutex m_fftMutex;
120 
121  void setupFFT();
122 
123  virtual void getBiasCurve(BiasCurve &) const;
125 
126  virtual float getXForBin(int bin, int totalBins, float w) const;
127  virtual int getBinForX(float x, int totalBins, float w) const;
128 
129  float getFrequencyForX(float x, float w) const;
130  float getXForFrequency(float freq, float w) const;
131 
132  int getWindowIncrement() const {
133  if (m_windowHopLevel == 0) return m_windowSize;
134  else if (m_windowHopLevel == 1) return (m_windowSize * 3) / 4;
135  else return m_windowSize / (1 << (m_windowHopLevel - 1));
136  }
137 };
138 
139 #endif
virtual float getXForBin(int bin, int totalBins, float w) const
virtual const Model * getModel() const
Definition: SpectrumLayer.h:40
int getWindowSize() const
Definition: SpectrumLayer.h:85
virtual PropertyList getProperties() const
float getXForFrequency(float freq, float w) const
void setChannel(int)
virtual bool getValueExtents(float &min, float &max, bool &logarithmic, QString &unit) const
Return the minimum and maximum values for the y axis of the model in this layer, as well as whether t...
void setWindowSize(int)
virtual QString getFeatureDescription(View *v, QPoint &) const
virtual bool getCrosshairExtents(View *, QPainter &, QPoint cursorPos, std::vector< QRect > &extents) const
virtual QString getPropertyGroupName(const PropertyName &) const
float getFrequencyForX(float x, float w) const
virtual VerticalPosition getPreferredFrameCountPosition() const
Definition: SpectrumLayer.h:50
virtual void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const
Convert the layer's data (though not those of the model it refers to) into XML for file output.
virtual bool getXScaleValue(const View *v, int x, float &value, QString &unit) const
Return the value and unit at the given x coordinate in the given view.
virtual bool isLayerScrollable(const View *) const
This should return true if the layer can safely be scrolled automatically by a given view (simply cop...
Definition: SpectrumLayer.h:79
virtual int getVerticalScaleWidth(View *, bool, QPainter &) const
Definition: SpectrumLayer.h:96
WindowType getWindowType() const
Definition: SpectrumLayer.h:91
virtual void paintCrosshairs(View *, QPainter &, QPoint) const
virtual void getBiasCurve(BiasCurve &) const
VerticalPosition
Definition: Layer.h:106
int getWindowIncrement() const
void preferenceChanged(PropertyContainer::PropertyName name)
virtual int getPropertyRangeAndValue(const PropertyName &, int *min, int *max, int *deflt) const
virtual void setProperties(const QXmlAttributes &)
Set the particular properties of a layer (those specific to the subclass) from a set of XML attribute...
virtual QString getPropertyIconName(const PropertyName &) const
BiasCurve m_biasCurve
virtual QString getPropertyValueLabel(const PropertyName &, int value) const
virtual void setProperty(const PropertyName &, int value)
virtual bool getYScaleValue(const View *, int y, float &value, QString &unit) const
Return the value and unit at the given y coordinate in the given view.
virtual bool getYScaleDifference(const View *, int y0, int y1, float &diff, QString &unit) const
Return the difference between the values at the given y coordinates in the given view,...
virtual int getBinForX(float x, int totalBins, float w) const
virtual RangeMapper * getNewPropertyRangeMapper(const PropertyName &) const
WindowType m_windowType
virtual QString getPropertyLabel(const PropertyName &) const
DenseTimeValueModel * m_originModel
std::vector< float > BiasCurve
Definition: SliceLayer.h:126
View is the base class of widgets that display one or more overlaid views of data against a horizonta...
Definition: View.h:50
int getChannel() const
Definition: SpectrumLayer.h:82
bool getShowPeaks() const
Definition: SpectrumLayer.h:94
int getWindowHopLevel() const
Definition: SpectrumLayer.h:88
void setWindowType(WindowType type)
void setWindowHopLevel(int level)
void setShowPeaks(bool)
virtual void paint(View *v, QPainter &paint, QRect rect) const
Paint the given rectangle of this layer onto the given view using the given painter,...
virtual PropertyType getPropertyType(const PropertyName &) const
void setModel(DenseTimeValueModel *model)