Chris@152
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@152
|
2
|
Chris@152
|
3 /*
|
Chris@152
|
4 Sonic Visualiser
|
Chris@152
|
5 An audio file viewer and annotation editor.
|
Chris@152
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@202
|
7 This file copyright 2006 Chris Cannam and QMUL.
|
Chris@152
|
8
|
Chris@152
|
9 This program is free software; you can redistribute it and/or
|
Chris@152
|
10 modify it under the terms of the GNU General Public License as
|
Chris@152
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@152
|
12 License, or (at your option) any later version. See the file
|
Chris@152
|
13 COPYING included with this distribution for more information.
|
Chris@152
|
14 */
|
Chris@152
|
15
|
Chris@152
|
16 #ifndef _EDITABLE_DENSE_THREE_DIMENSIONAL_MODEL_H_
|
Chris@152
|
17 #define _EDITABLE_DENSE_THREE_DIMENSIONAL_MODEL_H_
|
Chris@152
|
18
|
Chris@152
|
19 #include "DenseThreeDimensionalModel.h"
|
Chris@152
|
20
|
Chris@536
|
21 #include <QReadWriteLock>
|
Chris@536
|
22
|
Chris@533
|
23 #include <vector>
|
Chris@533
|
24
|
Chris@152
|
25 class EditableDenseThreeDimensionalModel : public DenseThreeDimensionalModel
|
Chris@152
|
26 {
|
Chris@152
|
27 Q_OBJECT
|
Chris@152
|
28
|
Chris@152
|
29 public:
|
Chris@535
|
30
|
Chris@535
|
31 // EditableDenseThreeDimensionalModel supports a basic compression
|
Chris@535
|
32 // method that reduces the size of multirate data (e.g. wavelet
|
Chris@535
|
33 // transform outputs) that are stored as plain 3d grids by about
|
Chris@535
|
34 // 60% or thereabouts. However, it can only be used for models
|
Chris@535
|
35 // whose columns are set in order from 0 and never subsequently
|
Chris@535
|
36 // changed. If the model is going to be actually edited, it must
|
Chris@535
|
37 // have NoCompression.
|
Chris@535
|
38
|
Chris@535
|
39 enum CompressionType
|
Chris@535
|
40 {
|
Chris@535
|
41 NoCompression,
|
Chris@535
|
42 BasicMultirateCompression
|
Chris@535
|
43 };
|
Chris@535
|
44
|
Chris@1040
|
45 EditableDenseThreeDimensionalModel(sv_samplerate_t sampleRate,
|
Chris@929
|
46 int resolution,
|
Chris@929
|
47 int yBinCount,
|
Chris@535
|
48 CompressionType compression,
|
Chris@152
|
49 bool notifyOnAdd = true);
|
Chris@152
|
50
|
Chris@152
|
51 virtual bool isOK() const;
|
Chris@152
|
52
|
Chris@1040
|
53 virtual sv_samplerate_t getSampleRate() const;
|
Chris@1038
|
54 virtual sv_frame_t getStartFrame() const;
|
Chris@1038
|
55 virtual sv_frame_t getEndFrame() const;
|
Chris@152
|
56
|
Chris@152
|
57 /**
|
Chris@611
|
58 * Set the frame offset of the first column.
|
Chris@611
|
59 */
|
Chris@1038
|
60 virtual void setStartFrame(sv_frame_t);
|
Chris@611
|
61
|
Chris@611
|
62 /**
|
Chris@152
|
63 * Return the number of sample frames covered by each set of bins.
|
Chris@152
|
64 */
|
Chris@929
|
65 virtual int getResolution() const;
|
Chris@152
|
66
|
Chris@152
|
67 /**
|
Chris@152
|
68 * Set the number of sample frames covered by each set of bins.
|
Chris@152
|
69 */
|
Chris@929
|
70 virtual void setResolution(int sz);
|
Chris@152
|
71
|
Chris@152
|
72 /**
|
Chris@182
|
73 * Return the number of columns.
|
Chris@182
|
74 */
|
Chris@929
|
75 virtual int getWidth() const;
|
Chris@182
|
76
|
Chris@182
|
77 /**
|
Chris@152
|
78 * Return the number of bins in each set of bins.
|
Chris@152
|
79 */
|
Chris@929
|
80 virtual int getHeight() const;
|
Chris@152
|
81
|
Chris@152
|
82 /**
|
Chris@152
|
83 * Set the number of bins in each set of bins.
|
Chris@152
|
84 */
|
Chris@929
|
85 virtual void setHeight(int sz);
|
Chris@152
|
86
|
Chris@152
|
87 /**
|
Chris@152
|
88 * Return the minimum value of the value in each bin.
|
Chris@152
|
89 */
|
Chris@152
|
90 virtual float getMinimumLevel() const;
|
Chris@152
|
91
|
Chris@152
|
92 /**
|
Chris@152
|
93 * Set the minimum value of the value in a bin.
|
Chris@152
|
94 */
|
Chris@152
|
95 virtual void setMinimumLevel(float sz);
|
Chris@152
|
96
|
Chris@152
|
97 /**
|
Chris@152
|
98 * Return the maximum value of the value in each bin.
|
Chris@152
|
99 */
|
Chris@152
|
100 virtual float getMaximumLevel() const;
|
Chris@152
|
101
|
Chris@152
|
102 /**
|
Chris@152
|
103 * Set the maximum value of the value in a bin.
|
Chris@152
|
104 */
|
Chris@152
|
105 virtual void setMaximumLevel(float sz);
|
Chris@152
|
106
|
Chris@182
|
107 /**
|
Chris@182
|
108 * Get the set of bin values at the given column.
|
Chris@152
|
109 */
|
Chris@929
|
110 virtual Column getColumn(int x) const;
|
Chris@152
|
111
|
Chris@152
|
112 /**
|
Chris@182
|
113 * Get a single value, from the n'th bin of the given column.
|
Chris@152
|
114 */
|
Chris@929
|
115 virtual float getValueAt(int x, int n) const;
|
Chris@152
|
116
|
Chris@152
|
117 /**
|
Chris@182
|
118 * Set the entire set of bin values at the given column.
|
Chris@152
|
119 */
|
Chris@929
|
120 virtual void setColumn(int x, const Column &values);
|
Chris@152
|
121
|
Chris@881
|
122 /**
|
Chris@881
|
123 * Return the name of bin n. This is a single label per bin that
|
Chris@881
|
124 * does not vary from one column to the next.
|
Chris@881
|
125 */
|
Chris@929
|
126 virtual QString getBinName(int n) const;
|
Chris@881
|
127
|
Chris@881
|
128 /**
|
Chris@881
|
129 * Set the name of bin n.
|
Chris@881
|
130 */
|
Chris@929
|
131 virtual void setBinName(int n, QString);
|
Chris@881
|
132
|
Chris@881
|
133 /**
|
Chris@881
|
134 * Set the names of all bins.
|
Chris@881
|
135 */
|
Chris@152
|
136 virtual void setBinNames(std::vector<QString> names);
|
Chris@152
|
137
|
Chris@881
|
138 /**
|
Chris@886
|
139 * Return true if the bins have values as well as names. (The
|
Chris@886
|
140 * values may have been derived from the names, e.g. by parsing
|
Chris@886
|
141 * numbers from them.) If this returns true, getBinValue() may be
|
Chris@886
|
142 * used to retrieve the values.
|
Chris@886
|
143 */
|
Chris@886
|
144 virtual bool hasBinValues() const;
|
Chris@886
|
145
|
Chris@886
|
146 /**
|
Chris@886
|
147 * Return the value of bin n, if any. This is a "vertical scale"
|
Chris@886
|
148 * value which does not vary from one column to the next. This is
|
Chris@886
|
149 * only meaningful if hasBinValues() returns true.
|
Chris@886
|
150 */
|
Chris@929
|
151 virtual float getBinValue(int n) const;
|
Chris@886
|
152
|
Chris@886
|
153 /**
|
Chris@886
|
154 * Set the values of all bins (separate from their labels). These
|
Chris@886
|
155 * are "vertical scale" values which do not vary from one column
|
Chris@886
|
156 * to the next.
|
Chris@886
|
157 */
|
Chris@886
|
158 virtual void setBinValues(std::vector<float> values);
|
Chris@886
|
159
|
Chris@886
|
160 /**
|
Chris@886
|
161 * Obtain the name of the unit of the values returned from
|
Chris@886
|
162 * getBinValue(), if any.
|
Chris@886
|
163 */
|
Chris@886
|
164 virtual QString getBinValueUnit() const;
|
Chris@886
|
165
|
Chris@886
|
166 /**
|
Chris@886
|
167 * Set the name of the unit of the values return from
|
Chris@886
|
168 * getBinValue() if any.
|
Chris@886
|
169 */
|
Chris@886
|
170 virtual void setBinValueUnit(QString unit);
|
Chris@886
|
171
|
Chris@886
|
172 /**
|
Chris@881
|
173 * Return true if the distribution of values in the bins is such
|
Chris@881
|
174 * as to suggest a log scale (mapping to colour etc) may be better
|
Chris@881
|
175 * than a linear one.
|
Chris@881
|
176 */
|
Chris@478
|
177 bool shouldUseLogValueScale() const;
|
Chris@478
|
178
|
Chris@333
|
179 virtual void setCompletion(int completion, bool update = true);
|
Chris@152
|
180 virtual int getCompletion() const { return m_completion; }
|
Chris@152
|
181
|
Chris@345
|
182 QString getTypeName() const { return tr("Editable Dense 3-D"); }
|
Chris@345
|
183
|
Chris@318
|
184 virtual QString toDelimitedDataString(QString delimiter) const;
|
Chris@1038
|
185 virtual QString toDelimitedDataStringSubset(QString delimiter, sv_frame_t f0, sv_frame_t f1) const;
|
Chris@318
|
186
|
Chris@152
|
187 virtual void toXml(QTextStream &out,
|
Chris@152
|
188 QString indent = "",
|
Chris@152
|
189 QString extraAttributes = "") const;
|
Chris@152
|
190
|
Chris@152
|
191 protected:
|
Chris@1154
|
192 typedef std::vector<Column> ValueMatrix;
|
Chris@152
|
193 ValueMatrix m_data;
|
Chris@152
|
194
|
Chris@535
|
195 // m_trunc is used for simple compression. If at least the top N
|
Chris@535
|
196 // elements of column x (for N = some proportion of the column
|
Chris@535
|
197 // height) are equal to those of an earlier column x', then
|
Chris@535
|
198 // m_trunc[x] will contain x-x' and column x will be truncated so
|
Chris@535
|
199 // as to remove the duplicate elements. If the equal elements are
|
Chris@535
|
200 // at the bottom, then m_trunc[x] will contain x'-x (a negative
|
Chris@535
|
201 // value). If m_trunc[x] is 0 then the whole of column x is
|
Chris@535
|
202 // stored.
|
Chris@535
|
203 std::vector<signed char> m_trunc;
|
Chris@929
|
204 void truncateAndStore(int index, const Column & values);
|
Chris@929
|
205 Column expandAndRetrieve(int index) const;
|
Chris@534
|
206
|
Chris@152
|
207 std::vector<QString> m_binNames;
|
Chris@886
|
208 std::vector<float> m_binValues;
|
Chris@886
|
209 QString m_binValueUnit;
|
Chris@152
|
210
|
Chris@1038
|
211 sv_frame_t m_startFrame;
|
Chris@1040
|
212 sv_samplerate_t m_sampleRate;
|
Chris@929
|
213 int m_resolution;
|
Chris@929
|
214 int m_yBinCount;
|
Chris@535
|
215 CompressionType m_compression;
|
Chris@152
|
216 float m_minimum;
|
Chris@152
|
217 float m_maximum;
|
Chris@256
|
218 bool m_haveExtents;
|
Chris@152
|
219 bool m_notifyOnAdd;
|
Chris@1110
|
220 sv_frame_t m_sinceLastNotifyMin;
|
Chris@1110
|
221 sv_frame_t m_sinceLastNotifyMax;
|
Chris@152
|
222 int m_completion;
|
Chris@152
|
223
|
Chris@536
|
224 mutable QReadWriteLock m_lock;
|
Chris@152
|
225 };
|
Chris@152
|
226
|
Chris@152
|
227 #endif
|