Chris@58
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@59
|
4 Sonic Visualiser
|
Chris@59
|
5 An audio file viewer and annotation editor.
|
Chris@59
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@182
|
7 This file copyright 2006 Chris Cannam and QMUL.
|
Chris@0
|
8
|
Chris@59
|
9 This program is free software; you can redistribute it and/or
|
Chris@59
|
10 modify it under the terms of the GNU General Public License as
|
Chris@59
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@59
|
12 License, or (at your option) any later version. See the file
|
Chris@59
|
13 COPYING included with this distribution for more information.
|
Chris@0
|
14 */
|
Chris@0
|
15
|
Chris@1068
|
16 #ifndef COLOUR_3D_PLOT_LAYER_H
|
Chris@1068
|
17 #define COLOUR_3D_PLOT_LAYER_H
|
Chris@0
|
18
|
Chris@193
|
19 #include "SliceableLayer.h"
|
Chris@1082
|
20 #include "VerticalBinLayer.h"
|
Chris@0
|
21
|
Chris@1097
|
22 #include "ColourScale.h"
|
Chris@1097
|
23 #include "Colour3DPlotRenderer.h"
|
Chris@1097
|
24
|
Chris@128
|
25 #include "data/model/DenseThreeDimensionalModel.h"
|
Chris@0
|
26
|
Chris@0
|
27 class View;
|
Chris@0
|
28 class QPainter;
|
Chris@0
|
29 class QImage;
|
Chris@0
|
30
|
Chris@0
|
31 /**
|
Chris@0
|
32 * This is a view that displays dense 3-D data (time, some sort of
|
Chris@0
|
33 * binned y-axis range, value) as a colour plot with value mapped to
|
Chris@0
|
34 * colour range. Its source is a DenseThreeDimensionalModel.
|
Chris@0
|
35 *
|
Chris@0
|
36 * This was the original implementation for the spectrogram view, but
|
Chris@1068
|
37 * it was replaced for that purpose with a more efficient
|
Chris@1068
|
38 * implementation that derived the spectrogram itself from a
|
Chris@1068
|
39 * DenseTimeValueModel instead of using a three-dimensional model.
|
Chris@0
|
40 */
|
Chris@1110
|
41 class Colour3DPlotLayer : public VerticalBinLayer
|
Chris@0
|
42 {
|
Chris@0
|
43 Q_OBJECT
|
Chris@0
|
44
|
Chris@0
|
45 public:
|
Chris@44
|
46 Colour3DPlotLayer();
|
Chris@0
|
47 ~Colour3DPlotLayer();
|
Chris@0
|
48
|
Chris@1469
|
49 ModelId getModel() const override { return m_model; }
|
Chris@1469
|
50
|
Chris@1469
|
51 const ZoomConstraint *getZoomConstraint() const override;
|
Chris@1469
|
52
|
Chris@1469
|
53 void paint(LayerGeometryProvider *v,
|
Chris@1469
|
54 QPainter &paint, QRect rect) const override;
|
Chris@1406
|
55 void setSynchronousPainting(bool synchronous) override;
|
Chris@0
|
56
|
Chris@1469
|
57 int getVerticalScaleWidth(LayerGeometryProvider *v,
|
Chris@1469
|
58 bool, QPainter &) const override;
|
Chris@1469
|
59 void paintVerticalScale(LayerGeometryProvider *v,
|
Chris@1469
|
60 bool, QPainter &paint, QRect rect) const override;
|
Chris@25
|
61
|
Chris@1469
|
62 QString getFeatureDescription(LayerGeometryProvider *v,
|
Chris@1469
|
63 QPoint &) const override;
|
Chris@25
|
64
|
Chris@1406
|
65 bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
|
Chris@1469
|
66 int &resolution,
|
Chris@1469
|
67 SnapType snap) const override;
|
Chris@24
|
68
|
Chris@1469
|
69 void setLayerDormant(const LayerGeometryProvider *v,
|
Chris@1469
|
70 bool dormant) override;
|
Chris@475
|
71
|
Chris@1406
|
72 bool isLayerScrollable(const LayerGeometryProvider *v) const override;
|
Chris@25
|
73
|
Chris@1406
|
74 ColourSignificance getLayerColourSignificance() const override {
|
Chris@287
|
75 return ColourHasMeaningfulValue;
|
Chris@287
|
76 }
|
Chris@183
|
77
|
Chris@1469
|
78 void setModel(ModelId model); // a DenseThreeDimensionalModel
|
Chris@0
|
79
|
Chris@1469
|
80 int getCompletion(LayerGeometryProvider *) const override;
|
Chris@24
|
81
|
Chris@1406
|
82 PropertyList getProperties() const override;
|
Chris@1406
|
83 PropertyType getPropertyType(const PropertyName &) const override;
|
Chris@1406
|
84 QString getPropertyLabel(const PropertyName &) const override;
|
Chris@1406
|
85 QString getPropertyIconName(const PropertyName &) const override;
|
Chris@1406
|
86 QString getPropertyGroupName(const PropertyName &) const override;
|
Chris@1406
|
87 int getPropertyRangeAndValue(const PropertyName &,
|
Chris@1469
|
88 int *min, int *max, int *deflt) const override;
|
Chris@1406
|
89 QString getPropertyValueLabel(const PropertyName &,
|
Chris@1469
|
90 int value) const override;
|
Chris@1406
|
91 QString getPropertyValueIconName(const PropertyName &,
|
Chris@1469
|
92 int value) const override;
|
Chris@1406
|
93 RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const override;
|
Chris@1406
|
94 void setProperty(const PropertyName &, int value) override;
|
Chris@1406
|
95 void setProperties(const QXmlAttributes &) override;
|
Chris@11
|
96
|
Chris@1105
|
97 void setColourScale(ColourScaleType);
|
Chris@1105
|
98 ColourScaleType getColourScale() const { return m_colourScale; }
|
Chris@159
|
99
|
Chris@197
|
100 void setColourMap(int map);
|
Chris@197
|
101 int getColourMap() const;
|
Chris@197
|
102
|
Chris@534
|
103 /**
|
Chris@534
|
104 * Set the gain multiplier for sample values in this view.
|
Chris@534
|
105 * The default is 1.0.
|
Chris@534
|
106 */
|
Chris@534
|
107 void setGain(float gain);
|
Chris@534
|
108 float getGain() const;
|
Chris@531
|
109
|
Chris@531
|
110 /**
|
Chris@531
|
111 * Specify the scale for the y axis.
|
Chris@531
|
112 */
|
Chris@1103
|
113 void setBinScale(BinScale);
|
Chris@1103
|
114 BinScale getBinScale() const;
|
Chris@531
|
115
|
Chris@719
|
116 /**
|
Chris@1104
|
117 * Specify the normalization mode for individual columns.
|
Chris@719
|
118 */
|
Chris@1104
|
119 void setNormalization(ColumnNormalization);
|
Chris@1104
|
120 ColumnNormalization getNormalization() const;
|
Chris@1104
|
121
|
Chris@1104
|
122 /**
|
Chris@1104
|
123 * Specify whether to normalize the visible area.
|
Chris@1104
|
124 */
|
Chris@1104
|
125 void setNormalizeVisibleArea(bool);
|
Chris@1104
|
126 bool getNormalizeVisibleArea() const;
|
Chris@719
|
127
|
Chris@357
|
128 void setInvertVertical(bool i);
|
Chris@357
|
129 bool getInvertVertical() const;
|
Chris@357
|
130
|
Chris@465
|
131 void setOpaque(bool i);
|
Chris@465
|
132 bool getOpaque() const;
|
Chris@465
|
133
|
Chris@535
|
134 void setSmooth(bool i);
|
Chris@535
|
135 bool getSmooth() const;
|
Chris@535
|
136
|
Chris@1453
|
137 bool hasLightBackground() const override;
|
Chris@1453
|
138
|
Chris@1406
|
139 bool getValueExtents(double &min, double &max,
|
Chris@1469
|
140 bool &logarithmic, QString &unit) const override;
|
Chris@444
|
141
|
Chris@1406
|
142 bool getDisplayExtents(double &min, double &max) const override;
|
Chris@1406
|
143 bool setDisplayExtents(double min, double max) override;
|
Chris@444
|
144
|
Chris@1406
|
145 bool getYScaleValue(const LayerGeometryProvider *, int /* y */,
|
Chris@1469
|
146 double &/* value */, QString &/* unit */) const override;
|
Chris@725
|
147
|
Chris@1406
|
148 int getVerticalZoomSteps(int &defaultStep) const override;
|
Chris@1406
|
149 int getCurrentVerticalZoomStep() const override;
|
Chris@1406
|
150 void setVerticalZoomStep(int) override;
|
Chris@1406
|
151 RangeMapper *getNewVerticalZoomRangeMapper() const override;
|
Chris@444
|
152
|
Chris@1469
|
153 ModelId getSliceableModel() const override { return m_model; }
|
Chris@193
|
154
|
Chris@1406
|
155 void toXml(QTextStream &stream, QString indent = "",
|
Chris@1469
|
156 QString extraAttributes = "") const override;
|
Chris@197
|
157
|
Chris@0
|
158 protected slots:
|
Chris@1453
|
159 void handleModelChanged();
|
Chris@1453
|
160 void handleModelChangedWithin(sv_frame_t, sv_frame_t);
|
Chris@0
|
161
|
Chris@0
|
162 protected:
|
Chris@1469
|
163 ModelId m_model; // A DenseThreeDimensionalModel
|
Chris@0
|
164
|
Chris@1105
|
165 ColourScaleType m_colourScale;
|
Chris@1104
|
166 bool m_colourScaleSet;
|
Chris@1104
|
167 int m_colourMap;
|
Chris@1362
|
168 bool m_colourInverted;
|
Chris@1104
|
169 float m_gain;
|
Chris@1103
|
170 BinScale m_binScale;
|
Chris@1104
|
171 ColumnNormalization m_normalization; // of individual columns
|
Chris@1104
|
172 bool m_normalizeVisibleArea;
|
Chris@1104
|
173 bool m_invertVertical;
|
Chris@1104
|
174 bool m_opaque;
|
Chris@1104
|
175 bool m_smooth;
|
Chris@1104
|
176 int m_peakResolution;
|
Chris@197
|
177
|
Chris@725
|
178 // Minimum and maximum bin numbers visible within the view. We
|
Chris@725
|
179 // always snap to whole bins at view edges.
|
Chris@1104
|
180 int m_miny;
|
Chris@1104
|
181 int m_maxy;
|
Chris@1100
|
182
|
Chris@1104
|
183 bool m_synchronous;
|
Chris@1104
|
184
|
Chris@1105
|
185 static ColourScaleType convertToColourScale(int value);
|
Chris@1105
|
186 static int convertFromColourScale(ColourScaleType);
|
Chris@1104
|
187 static std::pair<ColumnNormalization, bool> convertToColumnNorm(int value);
|
Chris@1104
|
188 static int convertFromColumnNorm(ColumnNormalization norm, bool visible);
|
Chris@1101
|
189
|
Chris@1100
|
190 mutable Dense3DModelPeakCache *m_peakCache;
|
Chris@1100
|
191 const int m_peakCacheDivisor;
|
Chris@1469
|
192 void invalidatePeakCache();
|
Chris@1100
|
193 Dense3DModelPeakCache *getPeakCache() const;
|
Chris@1100
|
194
|
Chris@1121
|
195 typedef std::map<int, MagnitudeRange> ViewMagMap; // key is view id
|
Chris@1121
|
196 mutable ViewMagMap m_viewMags;
|
Chris@1235
|
197 mutable ViewMagMap m_lastRenderedMags; // when in normalizeVisibleArea mode
|
Chris@1235
|
198 void invalidateMagnitudes();
|
Chris@1121
|
199
|
Chris@1100
|
200 typedef std::map<int, Colour3DPlotRenderer *> ViewRendererMap; // key is view id
|
Chris@1100
|
201 mutable ViewRendererMap m_renderers;
|
Chris@1121
|
202
|
Chris@1113
|
203 Colour3DPlotRenderer *getRenderer(const LayerGeometryProvider *) const;
|
Chris@1107
|
204 void invalidateRenderers();
|
Chris@1100
|
205
|
Chris@725
|
206 /**
|
Chris@725
|
207 * Return the y coordinate at which the given bin "starts"
|
Chris@725
|
208 * (i.e. at the bottom of the bin, if the given bin is an integer
|
Chris@725
|
209 * and the vertical scale is the usual way up). Bin number may be
|
Chris@725
|
210 * fractional, to obtain a position part-way through a bin.
|
Chris@725
|
211 */
|
Chris@1406
|
212 double getYForBin(const LayerGeometryProvider *, double bin) const override;
|
Chris@903
|
213
|
Chris@903
|
214 /**
|
Chris@725
|
215 * Return the bin number, possibly fractional, at the given y
|
Chris@725
|
216 * coordinate. Note that the whole numbers occur at the positions
|
Chris@725
|
217 * at which the bins "start" (i.e. the bottom of the visible bin,
|
Chris@725
|
218 * if the vertical scale is the usual way up).
|
Chris@725
|
219 */
|
Chris@1406
|
220 double getBinForY(const LayerGeometryProvider *, double y) const override;
|
Chris@159
|
221
|
Chris@469
|
222 int getColourScaleWidth(QPainter &) const;
|
Chris@1101
|
223
|
Chris@1107
|
224 void paintWithRenderer(LayerGeometryProvider *v, QPainter &paint, QRect rect) const;
|
Chris@0
|
225 };
|
Chris@0
|
226
|
Chris@0
|
227 #endif
|