Chris@133
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@133
|
2
|
Chris@133
|
3 /*
|
Chris@133
|
4 Sonic Visualiser
|
Chris@133
|
5 An audio file viewer and annotation editor.
|
Chris@133
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@195
|
7 This file copyright 2006-2007 QMUL.
|
Chris@133
|
8
|
Chris@133
|
9 This program is free software; you can redistribute it and/or
|
Chris@133
|
10 modify it under the terms of the GNU General Public License as
|
Chris@133
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@133
|
12 License, or (at your option) any later version. See the file
|
Chris@133
|
13 COPYING included with this distribution for more information.
|
Chris@133
|
14 */
|
Chris@133
|
15
|
Chris@193
|
16 #include "SliceLayer.h"
|
Chris@133
|
17
|
Chris@133
|
18 #include "view/View.h"
|
Chris@153
|
19 #include "base/AudioLevel.h"
|
Chris@167
|
20 #include "base/RangeMapper.h"
|
Chris@195
|
21 #include "base/RealTime.h"
|
Chris@376
|
22 #include "ColourMapper.h"
|
Chris@376
|
23 #include "ColourDatabase.h"
|
Chris@195
|
24
|
Chris@195
|
25 #include "PaintAssistant.h"
|
Chris@133
|
26
|
Chris@1383
|
27 #include "base/Profiler.h"
|
Chris@1383
|
28
|
Chris@133
|
29 #include <QPainter>
|
Chris@133
|
30 #include <QPainterPath>
|
Chris@316
|
31 #include <QTextStream>
|
Chris@316
|
32
|
Chris@133
|
33
|
Chris@193
|
34 SliceLayer::SliceLayer() :
|
Chris@193
|
35 m_sliceableModel(0),
|
Chris@1281
|
36 m_colourMap(int(ColourMapper::Ice)),
|
Chris@1362
|
37 m_colourInverted(false),
|
Chris@153
|
38 m_energyScale(dBScale),
|
Chris@198
|
39 m_samplingMode(SampleMean),
|
Chris@1233
|
40 m_plotStyle(PlotLines),
|
Chris@193
|
41 m_binScale(LinearBins),
|
Chris@153
|
42 m_normalize(false),
|
Chris@284
|
43 m_threshold(0.0),
|
Chris@284
|
44 m_initialThreshold(0.0),
|
Chris@198
|
45 m_gain(1.0),
|
Chris@1238
|
46 m_minbin(0),
|
Chris@1238
|
47 m_maxbin(0),
|
Chris@198
|
48 m_currentf0(0),
|
Chris@198
|
49 m_currentf1(0)
|
Chris@133
|
50 {
|
Chris@133
|
51 }
|
Chris@133
|
52
|
Chris@193
|
53 SliceLayer::~SliceLayer()
|
Chris@133
|
54 {
|
Chris@193
|
55
|
Chris@133
|
56 }
|
Chris@133
|
57
|
Chris@133
|
58 void
|
Chris@193
|
59 SliceLayer::setSliceableModel(const Model *model)
|
Chris@133
|
60 {
|
Chris@193
|
61 const DenseThreeDimensionalModel *sliceable =
|
Chris@193
|
62 dynamic_cast<const DenseThreeDimensionalModel *>(model);
|
Chris@193
|
63
|
Chris@193
|
64 if (model && !sliceable) {
|
Chris@682
|
65 cerr << "WARNING: SliceLayer::setSliceableModel(" << model
|
Chris@682
|
66 << "): model is not a DenseThreeDimensionalModel" << endl;
|
Chris@193
|
67 }
|
Chris@193
|
68
|
Chris@193
|
69 if (m_sliceableModel == sliceable) return;
|
Chris@193
|
70
|
Chris@193
|
71 m_sliceableModel = sliceable;
|
Chris@193
|
72
|
Chris@1255
|
73 if (!m_sliceableModel) return;
|
Chris@1255
|
74
|
Chris@320
|
75 connectSignals(m_sliceableModel);
|
Chris@193
|
76
|
Chris@1238
|
77 m_minbin = 0;
|
Chris@1238
|
78 m_maxbin = m_sliceableModel->getHeight();
|
Chris@1238
|
79
|
Chris@193
|
80 emit modelReplaced();
|
Chris@1238
|
81 emit layerParametersChanged();
|
Chris@153
|
82 }
|
Chris@153
|
83
|
Chris@153
|
84 void
|
Chris@193
|
85 SliceLayer::sliceableModelReplaced(const Model *orig, const Model *replacement)
|
Chris@153
|
86 {
|
Chris@587
|
87 SVDEBUG << "SliceLayer::sliceableModelReplaced(" << orig << ", " << replacement << ")" << endl;
|
Chris@153
|
88
|
Chris@193
|
89 if (orig == m_sliceableModel) {
|
Chris@193
|
90 setSliceableModel
|
Chris@193
|
91 (dynamic_cast<const DenseThreeDimensionalModel *>(replacement));
|
Chris@153
|
92 }
|
Chris@153
|
93 }
|
Chris@153
|
94
|
Chris@153
|
95 void
|
Chris@193
|
96 SliceLayer::modelAboutToBeDeleted(Model *m)
|
Chris@153
|
97 {
|
Chris@587
|
98 SVDEBUG << "SliceLayer::modelAboutToBeDeleted(" << m << ")" << endl;
|
Chris@153
|
99
|
Chris@193
|
100 if (m == m_sliceableModel) {
|
Chris@193
|
101 setSliceableModel(0);
|
Chris@153
|
102 }
|
Chris@133
|
103 }
|
Chris@133
|
104
|
Chris@198
|
105 QString
|
Chris@918
|
106 SliceLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &p) const
|
Chris@198
|
107 {
|
Chris@199
|
108 int minbin, maxbin, range;
|
Chris@805
|
109 return getFeatureDescriptionAux(v, p, true, minbin, maxbin, range);
|
Chris@199
|
110 }
|
Chris@199
|
111
|
Chris@199
|
112 QString
|
Chris@918
|
113 SliceLayer::getFeatureDescriptionAux(LayerGeometryProvider *v, QPoint &p,
|
Chris@805
|
114 bool includeBinDescription,
|
Chris@805
|
115 int &minbin, int &maxbin, int &range) const
|
Chris@199
|
116 {
|
Chris@199
|
117 minbin = 0;
|
Chris@199
|
118 maxbin = 0;
|
Chris@198
|
119 if (!m_sliceableModel) return "";
|
Chris@198
|
120
|
Chris@1256
|
121 minbin = int(getBinForX(v, p.x()));
|
Chris@1256
|
122 maxbin = int(getBinForX(v, p.x() + 1));
|
Chris@1238
|
123
|
Chris@198
|
124 int mh = m_sliceableModel->getHeight();
|
Chris@199
|
125 if (minbin >= mh) minbin = mh - 1;
|
Chris@199
|
126 if (maxbin >= mh) maxbin = mh - 1;
|
Chris@199
|
127 if (minbin < 0) minbin = 0;
|
Chris@199
|
128 if (maxbin < 0) maxbin = 0;
|
Chris@198
|
129
|
Chris@906
|
130 sv_samplerate_t sampleRate = m_sliceableModel->getSampleRate();
|
Chris@198
|
131
|
Chris@906
|
132 sv_frame_t f0 = m_currentf0;
|
Chris@906
|
133 sv_frame_t f1 = m_currentf1;
|
Chris@198
|
134
|
Chris@198
|
135 RealTime rt0 = RealTime::frame2RealTime(f0, sampleRate);
|
Chris@198
|
136 RealTime rt1 = RealTime::frame2RealTime(f1, sampleRate);
|
Chris@198
|
137
|
Chris@906
|
138 range = int(f1 - f0 + 1);
|
Chris@198
|
139
|
Chris@280
|
140 QString rtrangestr = QString("%1 s").arg((rt1 - rt0).toText().c_str());
|
Chris@280
|
141
|
Chris@199
|
142 if (includeBinDescription) {
|
Chris@198
|
143
|
Chris@1238
|
144 int i0 = minbin - m_minbin;
|
Chris@1238
|
145 int i1 = maxbin - m_minbin;
|
Chris@1238
|
146
|
Chris@906
|
147 float minvalue = 0.0;
|
Chris@1238
|
148 if (in_range_for(m_values, i0)) minvalue = m_values[i0];
|
Chris@198
|
149
|
Chris@199
|
150 float maxvalue = minvalue;
|
Chris@1238
|
151 if (in_range_for(m_values, i1)) maxvalue = m_values[i1];
|
Chris@1238
|
152
|
Chris@199
|
153 if (minvalue > maxvalue) std::swap(minvalue, maxvalue);
|
Chris@199
|
154
|
Chris@199
|
155 QString binstr;
|
Chris@199
|
156 if (maxbin != minbin) {
|
Chris@199
|
157 binstr = tr("%1 - %2").arg(minbin+1).arg(maxbin+1);
|
Chris@199
|
158 } else {
|
Chris@199
|
159 binstr = QString("%1").arg(minbin+1);
|
Chris@199
|
160 }
|
Chris@199
|
161
|
Chris@199
|
162 QString valuestr;
|
Chris@199
|
163 if (maxvalue != minvalue) {
|
Chris@199
|
164 valuestr = tr("%1 - %2").arg(minvalue).arg(maxvalue);
|
Chris@199
|
165 } else {
|
Chris@199
|
166 valuestr = QString("%1").arg(minvalue);
|
Chris@199
|
167 }
|
Chris@199
|
168
|
Chris@280
|
169 QString description = tr("Time:\t%1 - %2\nRange:\t%3 samples (%4)\nBin:\t%5\n%6 value:\t%7")
|
Chris@199
|
170 .arg(QString::fromStdString(rt0.toText(true)))
|
Chris@199
|
171 .arg(QString::fromStdString(rt1.toText(true)))
|
Chris@199
|
172 .arg(range)
|
Chris@280
|
173 .arg(rtrangestr)
|
Chris@199
|
174 .arg(binstr)
|
Chris@199
|
175 .arg(m_samplingMode == NearestSample ? tr("First") :
|
Chris@199
|
176 m_samplingMode == SampleMean ? tr("Mean") : tr("Peak"))
|
Chris@199
|
177 .arg(valuestr);
|
Chris@199
|
178
|
Chris@199
|
179 return description;
|
Chris@199
|
180
|
Chris@199
|
181 } else {
|
Chris@199
|
182
|
Chris@280
|
183 QString description = tr("Time:\t%1 - %2\nRange:\t%3 samples (%4)")
|
Chris@199
|
184 .arg(QString::fromStdString(rt0.toText(true)))
|
Chris@199
|
185 .arg(QString::fromStdString(rt1.toText(true)))
|
Chris@280
|
186 .arg(range)
|
Chris@280
|
187 .arg(rtrangestr);
|
Chris@199
|
188
|
Chris@199
|
189 return description;
|
Chris@199
|
190 }
|
Chris@198
|
191 }
|
Chris@198
|
192
|
Chris@906
|
193 double
|
Chris@1238
|
194 SliceLayer::getXForBin(const LayerGeometryProvider *v, double bin) const
|
Chris@198
|
195 {
|
Chris@1386
|
196 return getXForScalePoint(v, bin, m_minbin, m_maxbin);
|
Chris@1386
|
197 }
|
Chris@1386
|
198
|
Chris@1386
|
199 double
|
Chris@1386
|
200 SliceLayer::getXForScalePoint(const LayerGeometryProvider *v,
|
Chris@1386
|
201 double p, double pmin, double pmax) const
|
Chris@1386
|
202 {
|
Chris@906
|
203 double x = 0;
|
Chris@198
|
204
|
Chris@1386
|
205 p -= pmin;
|
Chris@1386
|
206 if (p < 0) p = 0;
|
Chris@1238
|
207
|
Chris@1386
|
208 double extent = pmax - pmin;
|
Chris@1386
|
209 if (extent < 0) extent = 0;
|
Chris@1238
|
210
|
Chris@1238
|
211 int pw = v->getPaintWidth();
|
Chris@1238
|
212 int origin = m_xorigins[v->getId()];
|
Chris@1238
|
213 int w = pw - origin;
|
Chris@1238
|
214 if (w < 1) w = 1;
|
Chris@1238
|
215
|
Chris@198
|
216 switch (m_binScale) {
|
Chris@198
|
217
|
Chris@198
|
218 case LinearBins:
|
Chris@1386
|
219 x = (w * p) / extent;
|
Chris@198
|
220 break;
|
Chris@198
|
221
|
Chris@198
|
222 case LogBins:
|
Chris@1281
|
223 // The 0.8 here is an awkward compromise. Our x-coord is
|
Chris@1281
|
224 // proportional to log of bin number, with the x-coord "of a
|
Chris@1281
|
225 // bin" being that of the left edge of the bin range. We can't
|
Chris@1281
|
226 // start counting bins from 0, as that would give us x = -Inf
|
Chris@1281
|
227 // and hide the first bin entirely. But if we start from 1, we
|
Chris@1281
|
228 // are giving a lot of space to the first bin, which in most
|
Chris@1281
|
229 // display modes won't be used because the "point" location
|
Chris@1281
|
230 // for that bin is in the middle of it. Yet in some modes
|
Chris@1281
|
231 // we'll still want it. A compromise is to count our first bin
|
Chris@1281
|
232 // as "a bit less than 1", so that most of it is visible but a
|
Chris@1281
|
233 // bit is tactfully cropped at the left edge so it doesn't
|
Chris@1281
|
234 // take up so much space.
|
Chris@1386
|
235 x = (w * log10(p + 0.8)) / log10(extent + 0.8);
|
Chris@198
|
236 break;
|
Chris@198
|
237
|
Chris@198
|
238 case InvertedLogBins:
|
Chris@1386
|
239 x = w - (w * log10(extent - p - 1)) / log10(extent);
|
Chris@198
|
240 break;
|
Chris@198
|
241 }
|
Chris@1238
|
242
|
Chris@1238
|
243 return x + origin;
|
Chris@198
|
244 }
|
Chris@198
|
245
|
Chris@1238
|
246 double
|
Chris@1238
|
247 SliceLayer::getBinForX(const LayerGeometryProvider *v, double x) const
|
Chris@198
|
248 {
|
Chris@1386
|
249 return getScalePointForX(v, x, m_minbin, m_maxbin);
|
Chris@1386
|
250 }
|
Chris@198
|
251
|
Chris@1386
|
252 double
|
Chris@1386
|
253 SliceLayer::getScalePointForX(const LayerGeometryProvider *v,
|
Chris@1386
|
254 double x, double pmin, double pmax) const
|
Chris@1386
|
255 {
|
Chris@1386
|
256 double p = 0;
|
Chris@1386
|
257
|
Chris@1386
|
258 double extent = pmax - pmin;
|
Chris@1386
|
259 if (extent < 0) extent = 0;
|
Chris@1238
|
260
|
Chris@1238
|
261 int pw = v->getPaintWidth();
|
Chris@1238
|
262 int origin = m_xorigins[v->getId()];
|
Chris@1238
|
263
|
Chris@1238
|
264 int w = pw - origin;
|
Chris@1238
|
265 if (w < 1) w = 1;
|
Chris@1238
|
266
|
Chris@1238
|
267 x = x - origin;
|
Chris@1238
|
268 if (x < 0) x = 0;
|
Chris@1256
|
269
|
Chris@1256
|
270 double eps = 1e-10;
|
Chris@1238
|
271
|
Chris@198
|
272 switch (m_binScale) {
|
Chris@198
|
273
|
Chris@198
|
274 case LinearBins:
|
Chris@1386
|
275 p = (x * extent) / w + eps;
|
Chris@198
|
276 break;
|
Chris@198
|
277
|
Chris@198
|
278 case LogBins:
|
Chris@1386
|
279 // See comment in getXForScalePoint
|
Chris@1386
|
280 p = pow(10.0, (x * log10(extent + 0.8)) / w) - 0.8 + eps;
|
Chris@198
|
281 break;
|
Chris@198
|
282
|
Chris@198
|
283 case InvertedLogBins:
|
Chris@1386
|
284 p = extent + 1 - pow(10.0, (log10(extent) * (w - x)) / double(w)) + eps;
|
Chris@198
|
285 break;
|
Chris@198
|
286 }
|
Chris@198
|
287
|
Chris@1386
|
288 return p + pmin;
|
Chris@198
|
289 }
|
Chris@198
|
290
|
Chris@906
|
291 double
|
Chris@1238
|
292 SliceLayer::getYForValue(const LayerGeometryProvider *v, double value, double &norm) const
|
Chris@274
|
293 {
|
Chris@906
|
294 norm = 0.0;
|
Chris@274
|
295
|
Chris@1238
|
296 if (m_yorigins.find(v->getId()) == m_yorigins.end()) return 0;
|
Chris@274
|
297
|
Chris@274
|
298 value *= m_gain;
|
Chris@274
|
299
|
Chris@1238
|
300 int yorigin = m_yorigins[v->getId()];
|
Chris@1238
|
301 int h = m_heights[v->getId()];
|
Chris@906
|
302 double thresh = getThresholdDb();
|
Chris@274
|
303
|
Chris@906
|
304 double y = 0.0;
|
Chris@274
|
305
|
Chris@274
|
306 if (h <= 0) return y;
|
Chris@274
|
307
|
Chris@274
|
308 switch (m_energyScale) {
|
Chris@274
|
309
|
Chris@274
|
310 case dBScale:
|
Chris@274
|
311 {
|
Chris@906
|
312 double db = thresh;
|
Chris@906
|
313 if (value > 0.0) db = 10.0 * log10(fabs(value));
|
Chris@274
|
314 if (db < thresh) db = thresh;
|
Chris@274
|
315 norm = (db - thresh) / -thresh;
|
Chris@906
|
316 y = yorigin - (double(h) * norm);
|
Chris@274
|
317 break;
|
Chris@274
|
318 }
|
Chris@274
|
319
|
Chris@274
|
320 case MeterScale:
|
Chris@274
|
321 y = AudioLevel::multiplier_to_preview(value, h);
|
Chris@906
|
322 norm = double(y) / double(h);
|
Chris@274
|
323 y = yorigin - y;
|
Chris@274
|
324 break;
|
Chris@274
|
325
|
Chris@538
|
326 case AbsoluteScale:
|
Chris@906
|
327 value = fabs(value);
|
Chris@1264
|
328 #if (__GNUC__ >= 7)
|
Chris@1263
|
329 __attribute__ ((fallthrough));
|
Chris@1263
|
330 #endif
|
Chris@538
|
331
|
Chris@805
|
332 case LinearScale:
|
Chris@274
|
333 default:
|
Chris@538
|
334 norm = (value - m_threshold);
|
Chris@284
|
335 if (norm < 0) norm = 0;
|
Chris@906
|
336 y = yorigin - (double(h) * norm);
|
Chris@274
|
337 break;
|
Chris@274
|
338 }
|
Chris@274
|
339
|
Chris@274
|
340 return y;
|
Chris@274
|
341 }
|
Chris@274
|
342
|
Chris@906
|
343 double
|
Chris@1238
|
344 SliceLayer::getValueForY(const LayerGeometryProvider *v, double y) const
|
Chris@274
|
345 {
|
Chris@906
|
346 double value = 0.0;
|
Chris@274
|
347
|
Chris@1238
|
348 if (m_yorigins.find(v->getId()) == m_yorigins.end()) return value;
|
Chris@274
|
349
|
Chris@1238
|
350 int yorigin = m_yorigins[v->getId()];
|
Chris@1238
|
351 int h = m_heights[v->getId()];
|
Chris@906
|
352 double thresh = getThresholdDb();
|
Chris@274
|
353
|
Chris@274
|
354 if (h <= 0) return value;
|
Chris@274
|
355
|
Chris@274
|
356 y = yorigin - y;
|
Chris@274
|
357
|
Chris@274
|
358 switch (m_energyScale) {
|
Chris@274
|
359
|
Chris@274
|
360 case dBScale:
|
Chris@274
|
361 {
|
Chris@906
|
362 double db = ((y / h) * -thresh) + thresh;
|
Chris@906
|
363 value = pow(10.0, db/10.0);
|
Chris@274
|
364 break;
|
Chris@274
|
365 }
|
Chris@274
|
366
|
Chris@274
|
367 case MeterScale:
|
Chris@906
|
368 value = AudioLevel::preview_to_multiplier(int(lrint(y)), h);
|
Chris@274
|
369 break;
|
Chris@805
|
370
|
Chris@805
|
371 case LinearScale:
|
Chris@805
|
372 case AbsoluteScale:
|
Chris@274
|
373 default:
|
Chris@284
|
374 value = y / h + m_threshold;
|
Chris@274
|
375 }
|
Chris@274
|
376
|
Chris@274
|
377 return value / m_gain;
|
Chris@274
|
378 }
|
Chris@274
|
379
|
Chris@133
|
380 void
|
Chris@916
|
381 SliceLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
|
Chris@133
|
382 {
|
Chris@1383
|
383 if (!m_sliceableModel ||
|
Chris@1383
|
384 !m_sliceableModel->isOK() ||
|
Chris@254
|
385 !m_sliceableModel->isReady()) return;
|
Chris@133
|
386
|
Chris@1383
|
387 Profiler profiler("SliceLayer::paint()");
|
Chris@1383
|
388
|
Chris@195
|
389 paint.save();
|
Chris@1383
|
390 paint.setRenderHint(QPainter::Antialiasing, true);
|
Chris@538
|
391 paint.setBrush(Qt::NoBrush);
|
Chris@195
|
392
|
Chris@195
|
393 if (v->getViewManager() && v->getViewManager()->shouldShowScaleGuides()) {
|
Chris@195
|
394 if (!m_scalePoints.empty()) {
|
Chris@195
|
395 paint.setPen(QColor(240, 240, 240)); //!!! and dark background?
|
Chris@1284
|
396 int ratio = int(round(double(v->getPaintHeight()) /
|
Chris@1284
|
397 m_scalePaintHeight));
|
Chris@805
|
398 for (int i = 0; i < (int)m_scalePoints.size(); ++i) {
|
Chris@1284
|
399 paint.drawLine(0, m_scalePoints[i] * ratio,
|
Chris@1284
|
400 rect.width(), m_scalePoints[i] * ratio);
|
Chris@195
|
401 }
|
Chris@195
|
402 }
|
Chris@195
|
403 }
|
Chris@195
|
404
|
Chris@1387
|
405 int mh = m_sliceableModel->getHeight();
|
Chris@1387
|
406
|
Chris@1233
|
407 if (m_plotStyle == PlotBlocks) {
|
Chris@1233
|
408 // Must use actual zero-width pen, too slow otherwise
|
Chris@1233
|
409 paint.setPen(QPen(getBaseQColor(), 0));
|
Chris@1233
|
410 } else {
|
Chris@1387
|
411 // Similarly, if there are very many bins here, let's drop to
|
Chris@1387
|
412 // a precise 1-pixel-width pen
|
Chris@1387
|
413 if (mh > 10000) {
|
Chris@1387
|
414 paint.setPen(QPen(getBaseQColor(), 1));
|
Chris@1387
|
415 } else {
|
Chris@1387
|
416 paint.setPen(PaintAssistant::scalePen(getBaseQColor()));
|
Chris@1387
|
417 }
|
Chris@1233
|
418 }
|
Chris@195
|
419
|
Chris@607
|
420 int xorigin = getVerticalScaleWidth(v, true, paint) + 1;
|
Chris@1238
|
421 m_xorigins[v->getId()] = xorigin; // for use in getFeatureDescription
|
Chris@133
|
422
|
Chris@1383
|
423 int yorigin = v->getPaintHeight() - getHorizontalScaleHeight(v, paint) -
|
Chris@1383
|
424 paint.fontMetrics().height();
|
Chris@195
|
425 int h = yorigin - paint.fontMetrics().height() - 8;
|
Chris@133
|
426
|
Chris@1238
|
427 m_yorigins[v->getId()] = yorigin; // for getYForValue etc
|
Chris@1238
|
428 m_heights[v->getId()] = h;
|
Chris@274
|
429
|
Chris@274
|
430 if (h <= 0) return;
|
Chris@274
|
431
|
Chris@133
|
432 QPainterPath path;
|
Chris@133
|
433
|
Chris@1238
|
434 int bin0 = 0;
|
Chris@133
|
435
|
Chris@1238
|
436 if (m_maxbin > m_minbin) {
|
Chris@1238
|
437 mh = m_maxbin - m_minbin;
|
Chris@1238
|
438 bin0 = m_minbin;
|
Chris@1238
|
439 }
|
Chris@1238
|
440
|
Chris@193
|
441 int divisor = 0;
|
Chris@193
|
442
|
Chris@198
|
443 m_values.clear();
|
Chris@805
|
444 for (int bin = 0; bin < mh; ++bin) {
|
Chris@906
|
445 m_values.push_back(0.0);
|
Chris@193
|
446 }
|
Chris@193
|
447
|
Chris@906
|
448 sv_frame_t f0 = v->getCentreFrame();
|
Chris@193
|
449 int f0x = v->getXForFrame(f0);
|
Chris@195
|
450 f0 = v->getFrameForX(f0x);
|
Chris@906
|
451 sv_frame_t f1 = v->getFrameForX(f0x + 1);
|
Chris@195
|
452 if (f1 > f0) --f1;
|
Chris@193
|
453
|
Chris@682
|
454 // cerr << "centre frame " << v->getCentreFrame() << ", x " << f0x << ", f0 " << f0 << ", f1 " << f1 << endl;
|
Chris@274
|
455
|
Chris@805
|
456 int res = m_sliceableModel->getResolution();
|
Chris@906
|
457 int col0 = int(f0 / res);
|
Chris@805
|
458 int col1 = col0;
|
Chris@906
|
459 if (m_samplingMode != NearestSample) col1 = int(f1 / res);
|
Chris@274
|
460 f0 = col0 * res;
|
Chris@274
|
461 f1 = (col1 + 1) * res - 1;
|
Chris@274
|
462
|
Chris@682
|
463 // cerr << "resolution " << res << ", col0 " << col0 << ", col1 " << col1 << ", f0 " << f0 << ", f1 " << f1 << endl;
|
Chris@1383
|
464 // cerr << "mh = " << mh << endl;
|
Chris@193
|
465
|
Chris@198
|
466 m_currentf0 = f0;
|
Chris@198
|
467 m_currentf1 = f1;
|
Chris@198
|
468
|
Chris@254
|
469 BiasCurve curve;
|
Chris@254
|
470 getBiasCurve(curve);
|
Chris@906
|
471 int cs = int(curve.size());
|
Chris@254
|
472
|
Chris@805
|
473 for (int col = col0; col <= col1; ++col) {
|
Chris@1383
|
474 DenseThreeDimensionalModel::Column column =
|
Chris@1383
|
475 m_sliceableModel->getColumn(col);
|
Chris@805
|
476 for (int bin = 0; bin < mh; ++bin) {
|
Chris@1383
|
477 float value = column[bin0 + bin];
|
Chris@254
|
478 if (bin < cs) value *= curve[bin];
|
Chris@193
|
479 if (m_samplingMode == SamplePeak) {
|
Chris@198
|
480 if (value > m_values[bin]) m_values[bin] = value;
|
Chris@193
|
481 } else {
|
Chris@198
|
482 m_values[bin] += value;
|
Chris@193
|
483 }
|
Chris@153
|
484 }
|
Chris@193
|
485 ++divisor;
|
Chris@193
|
486 }
|
Chris@193
|
487
|
Chris@906
|
488 float max = 0.0;
|
Chris@805
|
489 for (int bin = 0; bin < mh; ++bin) {
|
Chris@847
|
490 if (m_samplingMode == SampleMean && divisor > 0) {
|
Chris@906
|
491 m_values[bin] /= float(divisor);
|
Chris@847
|
492 }
|
Chris@198
|
493 if (m_values[bin] > max) max = m_values[bin];
|
Chris@193
|
494 }
|
Chris@906
|
495 if (max != 0.0 && m_normalize) {
|
Chris@805
|
496 for (int bin = 0; bin < mh; ++bin) {
|
Chris@198
|
497 m_values[bin] /= max;
|
Chris@193
|
498 }
|
Chris@193
|
499 }
|
Chris@193
|
500
|
Chris@1238
|
501 double nx = getXForBin(v, bin0);
|
Chris@193
|
502
|
Chris@1362
|
503 ColourMapper mapper(m_colourMap, m_colourInverted, 0, 1);
|
Chris@197
|
504
|
Chris@1383
|
505 double ytop = 0, ybottom = 0;
|
Chris@1383
|
506 bool firstBinOfPixel = true;
|
Chris@1384
|
507
|
Chris@1384
|
508 QColor prevColour = v->getBackground();
|
Chris@1384
|
509 double prevPx = 0;
|
Chris@1384
|
510 double prevYtop = 0;
|
Chris@1383
|
511
|
Chris@805
|
512 for (int bin = 0; bin < mh; ++bin) {
|
Chris@193
|
513
|
Chris@906
|
514 double x = nx;
|
Chris@1238
|
515 nx = getXForBin(v, bin + bin0 + 1);
|
Chris@193
|
516
|
Chris@906
|
517 double value = m_values[bin];
|
Chris@906
|
518 double norm = 0.0;
|
Chris@1238
|
519 double y = getYForValue(v, value, norm);
|
Chris@133
|
520
|
Chris@1383
|
521 if (y < ytop || firstBinOfPixel) {
|
Chris@1383
|
522 ytop = y;
|
Chris@1383
|
523 }
|
Chris@1383
|
524 if (y > ybottom || firstBinOfPixel) {
|
Chris@1383
|
525 ybottom = y;
|
Chris@1383
|
526 }
|
Chris@193
|
527
|
Chris@1383
|
528 if (int(nx) != int(x) || bin+1 == mh) {
|
Chris@1383
|
529
|
Chris@1383
|
530 if (m_plotStyle == PlotLines) {
|
Chris@1383
|
531
|
Chris@1384
|
532 double px = (x + nx) / 2;
|
Chris@1383
|
533
|
Chris@1383
|
534 if (bin == 0) {
|
Chris@1383
|
535 path.moveTo(px, y);
|
Chris@1383
|
536 } else {
|
Chris@1383
|
537 if (ytop != ybottom) {
|
Chris@1383
|
538 path.lineTo(px, ybottom);
|
Chris@1383
|
539 path.lineTo(px, ytop);
|
Chris@1383
|
540 path.moveTo(px, ybottom);
|
Chris@1383
|
541 } else {
|
Chris@1383
|
542 path.lineTo(px, ytop);
|
Chris@1383
|
543 }
|
Chris@1383
|
544 }
|
Chris@1383
|
545
|
Chris@1383
|
546 } else if (m_plotStyle == PlotSteps) {
|
Chris@1383
|
547
|
Chris@1383
|
548 if (bin == 0) {
|
Chris@1383
|
549 path.moveTo(x, y);
|
Chris@1383
|
550 } else {
|
Chris@1383
|
551 path.lineTo(x, ytop);
|
Chris@1383
|
552 }
|
Chris@1383
|
553 path.lineTo(nx, ytop);
|
Chris@1383
|
554
|
Chris@1383
|
555 } else if (m_plotStyle == PlotBlocks) {
|
Chris@1383
|
556
|
Chris@1384
|
557 // work in pixel coords here, as we don't want the
|
Chris@1384
|
558 // vertical edges to be antialiased
|
Chris@1384
|
559
|
Chris@1384
|
560 path.moveTo(QPoint(int(x), int(yorigin)));
|
Chris@1384
|
561 path.lineTo(QPoint(int(x), int(ytop)));
|
Chris@1384
|
562 path.lineTo(QPoint(int(nx), int(ytop)));
|
Chris@1384
|
563 path.lineTo(QPoint(int(nx), int(yorigin)));
|
Chris@1384
|
564 path.lineTo(QPoint(int(x), int(yorigin)));
|
Chris@1383
|
565
|
Chris@1383
|
566 } else if (m_plotStyle == PlotFilledBlocks) {
|
Chris@1383
|
567
|
Chris@1384
|
568 QColor c = mapper.map(norm);
|
Chris@1384
|
569 paint.setPen(Qt::NoPen);
|
Chris@1384
|
570
|
Chris@1384
|
571 // work in pixel coords here, as we don't want the
|
Chris@1384
|
572 // vertical edges to be antialiased
|
Chris@1384
|
573
|
Chris@1384
|
574 if (nx > x + 1) {
|
Chris@1384
|
575
|
Chris@1384
|
576 double px = (x + nx) / 2;
|
Chris@1384
|
577
|
Chris@1384
|
578 QVector<QPoint> pp;
|
Chris@1384
|
579
|
Chris@1384
|
580 if (bin > 0) {
|
Chris@1384
|
581 paint.setBrush(prevColour);
|
Chris@1384
|
582 pp.clear();
|
Chris@1384
|
583 pp << QPoint(int(prevPx), int(yorigin));
|
Chris@1384
|
584 pp << QPoint(int(prevPx), int(prevYtop));
|
Chris@1384
|
585 pp << QPoint(int((px + prevPx) / 2),
|
Chris@1384
|
586 int((ytop + prevYtop) / 2));
|
Chris@1384
|
587 pp << QPoint(int((px + prevPx) / 2),
|
Chris@1384
|
588 int(yorigin));
|
Chris@1384
|
589 paint.drawConvexPolygon(QPolygon(pp));
|
Chris@1384
|
590
|
Chris@1384
|
591 paint.setBrush(c);
|
Chris@1384
|
592 pp.clear();
|
Chris@1384
|
593 pp << QPoint(int((px + prevPx) / 2),
|
Chris@1384
|
594 int(yorigin));
|
Chris@1384
|
595 pp << QPoint(int((px + prevPx) / 2),
|
Chris@1384
|
596 int((ytop + prevYtop) / 2));
|
Chris@1384
|
597 pp << QPoint(int(px), int(ytop));
|
Chris@1384
|
598 pp << QPoint(int(px), int(yorigin));
|
Chris@1384
|
599 paint.drawConvexPolygon(QPolygon(pp));
|
Chris@1384
|
600 }
|
Chris@1384
|
601
|
Chris@1384
|
602 prevPx = px;
|
Chris@1384
|
603 prevColour = c;
|
Chris@1384
|
604 prevYtop = ytop;
|
Chris@1384
|
605
|
Chris@1384
|
606 } else {
|
Chris@1384
|
607
|
Chris@1384
|
608 paint.fillRect(QRect(int(x), int(ytop),
|
Chris@1384
|
609 int(nx) - int(x),
|
Chris@1384
|
610 int(yorigin) - int(ytop)),
|
Chris@1384
|
611 c);
|
Chris@1384
|
612 }
|
Chris@193
|
613 }
|
Chris@193
|
614
|
Chris@1383
|
615 firstBinOfPixel = true;
|
Chris@193
|
616
|
Chris@1383
|
617 } else {
|
Chris@1383
|
618 firstBinOfPixel = false;
|
Chris@133
|
619 }
|
Chris@133
|
620 }
|
Chris@133
|
621
|
Chris@197
|
622 if (m_plotStyle != PlotFilledBlocks) {
|
Chris@197
|
623 paint.drawPath(path);
|
Chris@197
|
624 }
|
Chris@133
|
625 paint.restore();
|
Chris@195
|
626 }
|
Chris@195
|
627
|
Chris@195
|
628 int
|
Chris@918
|
629 SliceLayer::getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &paint) const
|
Chris@195
|
630 {
|
Chris@1238
|
631 int width;
|
Chris@538
|
632 if (m_energyScale == LinearScale || m_energyScale == AbsoluteScale) {
|
Chris@1266
|
633 width = std::max(paint.fontMetrics().width("0.0") + 13,
|
Chris@1238
|
634 paint.fontMetrics().width("x10-10"));
|
Chris@195
|
635 } else {
|
Chris@1238
|
636 width = std::max(paint.fontMetrics().width(tr("0dB")),
|
Chris@1238
|
637 paint.fontMetrics().width(tr("-Inf"))) + 13;
|
Chris@195
|
638 }
|
Chris@1238
|
639 return width;
|
Chris@195
|
640 }
|
Chris@195
|
641
|
Chris@195
|
642 void
|
Chris@918
|
643 SliceLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const
|
Chris@195
|
644 {
|
Chris@906
|
645 double thresh = m_threshold;
|
Chris@538
|
646 if (m_energyScale != LinearScale && m_energyScale != AbsoluteScale) {
|
Chris@284
|
647 thresh = AudioLevel::dB_to_multiplier(getThresholdDb());
|
Chris@195
|
648 }
|
Chris@195
|
649
|
Chris@195
|
650 // int h = (rect.height() * 3) / 4;
|
Chris@195
|
651 // int y = (rect.height() / 2) - (h / 2);
|
Chris@195
|
652
|
Chris@1383
|
653 int yorigin = v->getPaintHeight() - getHorizontalScaleHeight(v, paint) -
|
Chris@1383
|
654 paint.fontMetrics().height();
|
Chris@195
|
655 int h = yorigin - paint.fontMetrics().height() - 8;
|
Chris@195
|
656 if (h < 0) return;
|
Chris@195
|
657
|
Chris@195
|
658 QRect actual(rect.x(), rect.y() + yorigin - h, rect.width(), h);
|
Chris@195
|
659
|
Chris@220
|
660 int mult = 1;
|
Chris@220
|
661
|
Chris@195
|
662 PaintAssistant::paintVerticalLevelScale
|
Chris@195
|
663 (paint, actual, thresh, 1.0 / m_gain,
|
Chris@195
|
664 PaintAssistant::Scale(m_energyScale),
|
Chris@220
|
665 mult,
|
Chris@195
|
666 const_cast<std::vector<int> *>(&m_scalePoints));
|
Chris@220
|
667
|
Chris@1284
|
668 // Ugly hack (but then everything about this scale drawing is a
|
Chris@1284
|
669 // bit ugly). In pixel-doubling hi-dpi scenarios, the scale is
|
Chris@1284
|
670 // painted at pixel-doubled resolution but we do explicit
|
Chris@1284
|
671 // pixel-doubling ourselves when painting the layer content. We
|
Chris@1284
|
672 // make a note of this here so that we can compare with the
|
Chris@1284
|
673 // equivalent dimension in the paint method when deciding where to
|
Chris@1284
|
674 // place scale continuation lines.
|
Chris@1284
|
675 m_scalePaintHeight = v->getPaintHeight();
|
Chris@1284
|
676
|
Chris@220
|
677 if (mult != 1 && mult != 0) {
|
Chris@906
|
678 int log = int(lrint(log10(mult)));
|
Chris@220
|
679 QString a = tr("x10");
|
Chris@220
|
680 QString b = QString("%1").arg(-log);
|
Chris@220
|
681 paint.drawText(3, 8 + paint.fontMetrics().ascent(), a);
|
Chris@220
|
682 paint.drawText(3 + paint.fontMetrics().width(a),
|
Chris@220
|
683 3 + paint.fontMetrics().ascent(), b);
|
Chris@220
|
684 }
|
Chris@133
|
685 }
|
Chris@133
|
686
|
Chris@1281
|
687 bool
|
Chris@1281
|
688 SliceLayer::hasLightBackground() const
|
Chris@1281
|
689 {
|
Chris@1281
|
690 if (usesSolidColour()) {
|
Chris@1362
|
691 ColourMapper mapper(m_colourMap, m_colourInverted, 0, 1);
|
Chris@1281
|
692 return mapper.hasLightBackground();
|
Chris@1281
|
693 } else {
|
Chris@1281
|
694 return SingleColourLayer::hasLightBackground();
|
Chris@1281
|
695 }
|
Chris@1281
|
696 }
|
Chris@1281
|
697
|
Chris@153
|
698 Layer::PropertyList
|
Chris@193
|
699 SliceLayer::getProperties() const
|
Chris@153
|
700 {
|
Chris@287
|
701 PropertyList list = SingleColourLayer::getProperties();
|
Chris@538
|
702 list.push_back("Bin Scale");
|
Chris@193
|
703 list.push_back("Plot Type");
|
Chris@153
|
704 list.push_back("Scale");
|
Chris@153
|
705 list.push_back("Normalize");
|
Chris@284
|
706 list.push_back("Threshold");
|
Chris@153
|
707 list.push_back("Gain");
|
Chris@153
|
708
|
Chris@153
|
709 return list;
|
Chris@153
|
710 }
|
Chris@153
|
711
|
Chris@153
|
712 QString
|
Chris@193
|
713 SliceLayer::getPropertyLabel(const PropertyName &name) const
|
Chris@153
|
714 {
|
Chris@193
|
715 if (name == "Plot Type") return tr("Plot Type");
|
Chris@290
|
716 if (name == "Scale") return tr("Scale");
|
Chris@153
|
717 if (name == "Normalize") return tr("Normalize");
|
Chris@284
|
718 if (name == "Threshold") return tr("Threshold");
|
Chris@153
|
719 if (name == "Gain") return tr("Gain");
|
Chris@193
|
720 if (name == "Sampling Mode") return tr("Sampling Mode");
|
Chris@538
|
721 if (name == "Bin Scale") return tr("Bin Scale");
|
Chris@287
|
722 return SingleColourLayer::getPropertyLabel(name);
|
Chris@153
|
723 }
|
Chris@153
|
724
|
Chris@335
|
725 QString
|
Chris@335
|
726 SliceLayer::getPropertyIconName(const PropertyName &name) const
|
Chris@335
|
727 {
|
Chris@335
|
728 if (name == "Normalize") return "normalise";
|
Chris@335
|
729 return "";
|
Chris@335
|
730 }
|
Chris@335
|
731
|
Chris@153
|
732 Layer::PropertyType
|
Chris@193
|
733 SliceLayer::getPropertyType(const PropertyName &name) const
|
Chris@153
|
734 {
|
Chris@153
|
735 if (name == "Gain") return RangeProperty;
|
Chris@153
|
736 if (name == "Normalize") return ToggleProperty;
|
Chris@284
|
737 if (name == "Threshold") return RangeProperty;
|
Chris@287
|
738 if (name == "Plot Type") return ValueProperty;
|
Chris@290
|
739 if (name == "Scale") return ValueProperty;
|
Chris@287
|
740 if (name == "Sampling Mode") return ValueProperty;
|
Chris@287
|
741 if (name == "Bin Scale") return ValueProperty;
|
Chris@1281
|
742 if (name == "Colour" && usesSolidColour()) return ColourMapProperty;
|
Chris@287
|
743 return SingleColourLayer::getPropertyType(name);
|
Chris@153
|
744 }
|
Chris@153
|
745
|
Chris@153
|
746 QString
|
Chris@193
|
747 SliceLayer::getPropertyGroupName(const PropertyName &name) const
|
Chris@153
|
748 {
|
Chris@153
|
749 if (name == "Scale" ||
|
Chris@153
|
750 name == "Normalize" ||
|
Chris@193
|
751 name == "Sampling Mode" ||
|
Chris@284
|
752 name == "Threshold" ||
|
Chris@193
|
753 name == "Gain") return tr("Scale");
|
Chris@193
|
754 if (name == "Plot Type" ||
|
Chris@538
|
755 name == "Bin Scale") return tr("Bins");
|
Chris@287
|
756 return SingleColourLayer::getPropertyGroupName(name);
|
Chris@153
|
757 }
|
Chris@153
|
758
|
Chris@153
|
759 int
|
Chris@193
|
760 SliceLayer::getPropertyRangeAndValue(const PropertyName &name,
|
Chris@216
|
761 int *min, int *max, int *deflt) const
|
Chris@153
|
762 {
|
Chris@216
|
763 int val = 0;
|
Chris@153
|
764
|
Chris@216
|
765 int garbage0, garbage1, garbage2;
|
Chris@153
|
766 if (!min) min = &garbage0;
|
Chris@153
|
767 if (!max) max = &garbage1;
|
Chris@248
|
768 if (!deflt) deflt = &garbage2;
|
Chris@153
|
769
|
Chris@153
|
770 if (name == "Gain") {
|
Chris@153
|
771
|
Chris@1266
|
772 *min = -50;
|
Chris@1266
|
773 *max = 50;
|
Chris@216
|
774 *deflt = 0;
|
Chris@153
|
775
|
Chris@1238
|
776 // cerr << "gain is " << m_gain << ", mode is " << m_samplingMode << endl;
|
Chris@193
|
777
|
Chris@1266
|
778 val = int(lrint(log10(m_gain) * 20.0));
|
Chris@1266
|
779 if (val < *min) val = *min;
|
Chris@1266
|
780 if (val > *max) val = *max;
|
Chris@153
|
781
|
Chris@284
|
782 } else if (name == "Threshold") {
|
Chris@284
|
783
|
Chris@1266
|
784 *min = -80;
|
Chris@1266
|
785 *max = 0;
|
Chris@284
|
786
|
Chris@906
|
787 *deflt = int(lrint(AudioLevel::multiplier_to_dB(m_initialThreshold)));
|
Chris@1266
|
788 if (*deflt < *min) *deflt = *min;
|
Chris@1266
|
789 if (*deflt > *max) *deflt = *max;
|
Chris@284
|
790
|
Chris@1266
|
791 val = int(lrint(AudioLevel::multiplier_to_dB(m_threshold)));
|
Chris@1266
|
792 if (val < *min) val = *min;
|
Chris@1266
|
793 if (val > *max) val = *max;
|
Chris@284
|
794
|
Chris@153
|
795 } else if (name == "Normalize") {
|
Chris@1266
|
796
|
Chris@1266
|
797 val = (m_normalize ? 1 : 0);
|
Chris@216
|
798 *deflt = 0;
|
Chris@153
|
799
|
Chris@1281
|
800 } else if (name == "Colour" && usesSolidColour()) {
|
Chris@197
|
801
|
Chris@287
|
802 *min = 0;
|
Chris@287
|
803 *max = ColourMapper::getColourMapCount() - 1;
|
Chris@1281
|
804 *deflt = int(ColourMapper::Ice);
|
Chris@287
|
805
|
Chris@287
|
806 val = m_colourMap;
|
Chris@153
|
807
|
Chris@153
|
808 } else if (name == "Scale") {
|
Chris@153
|
809
|
Chris@1266
|
810 *min = 0;
|
Chris@1266
|
811 *max = 3;
|
Chris@216
|
812 *deflt = (int)dBScale;
|
Chris@153
|
813
|
Chris@1266
|
814 val = (int)m_energyScale;
|
Chris@153
|
815
|
Chris@193
|
816 } else if (name == "Sampling Mode") {
|
Chris@153
|
817
|
Chris@1266
|
818 *min = 0;
|
Chris@1266
|
819 *max = 2;
|
Chris@216
|
820 *deflt = (int)SampleMean;
|
Chris@193
|
821
|
Chris@1266
|
822 val = (int)m_samplingMode;
|
Chris@153
|
823
|
Chris@193
|
824 } else if (name == "Plot Type") {
|
Chris@193
|
825
|
Chris@193
|
826 *min = 0;
|
Chris@197
|
827 *max = 3;
|
Chris@216
|
828 *deflt = (int)PlotSteps;
|
Chris@193
|
829
|
Chris@216
|
830 val = (int)m_plotStyle;
|
Chris@193
|
831
|
Chris@193
|
832 } else if (name == "Bin Scale") {
|
Chris@193
|
833
|
Chris@193
|
834 *min = 0;
|
Chris@198
|
835 *max = 2;
|
Chris@216
|
836 *deflt = (int)LinearBins;
|
Chris@198
|
837 // *max = 1; // I don't think we really do want to offer inverted log
|
Chris@193
|
838
|
Chris@216
|
839 val = (int)m_binScale;
|
Chris@193
|
840
|
Chris@153
|
841 } else {
|
Chris@1266
|
842 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt);
|
Chris@153
|
843 }
|
Chris@153
|
844
|
Chris@216
|
845 return val;
|
Chris@153
|
846 }
|
Chris@153
|
847
|
Chris@153
|
848 QString
|
Chris@193
|
849 SliceLayer::getPropertyValueLabel(const PropertyName &name,
|
Chris@1281
|
850 int value) const
|
Chris@153
|
851 {
|
Chris@1281
|
852 if (name == "Colour" && usesSolidColour()) {
|
Chris@1362
|
853 return ColourMapper::getColourMapLabel(value);
|
Chris@153
|
854 }
|
Chris@153
|
855 if (name == "Scale") {
|
Chris@1266
|
856 switch (value) {
|
Chris@1266
|
857 default:
|
Chris@1266
|
858 case 0: return tr("Linear");
|
Chris@1266
|
859 case 1: return tr("Meter");
|
Chris@1266
|
860 case 2: return tr("Log");
|
Chris@1266
|
861 case 3: return tr("Absolute");
|
Chris@1266
|
862 }
|
Chris@153
|
863 }
|
Chris@193
|
864 if (name == "Sampling Mode") {
|
Chris@1266
|
865 switch (value) {
|
Chris@1266
|
866 default:
|
Chris@1266
|
867 case 0: return tr("Any");
|
Chris@1266
|
868 case 1: return tr("Mean");
|
Chris@1266
|
869 case 2: return tr("Peak");
|
Chris@1266
|
870 }
|
Chris@193
|
871 }
|
Chris@193
|
872 if (name == "Plot Type") {
|
Chris@1266
|
873 switch (value) {
|
Chris@1266
|
874 default:
|
Chris@1266
|
875 case 0: return tr("Lines");
|
Chris@1266
|
876 case 1: return tr("Steps");
|
Chris@1266
|
877 case 2: return tr("Blocks");
|
Chris@1266
|
878 case 3: return tr("Colours");
|
Chris@1266
|
879 }
|
Chris@193
|
880 }
|
Chris@193
|
881 if (name == "Bin Scale") {
|
Chris@1266
|
882 switch (value) {
|
Chris@1266
|
883 default:
|
Chris@1266
|
884 case 0: return tr("Linear");
|
Chris@1266
|
885 case 1: return tr("Log");
|
Chris@1266
|
886 case 2: return tr("Rev Log");
|
Chris@1266
|
887 }
|
Chris@153
|
888 }
|
Chris@287
|
889 return SingleColourLayer::getPropertyValueLabel(name, value);
|
Chris@153
|
890 }
|
Chris@153
|
891
|
Chris@167
|
892 RangeMapper *
|
Chris@193
|
893 SliceLayer::getNewPropertyRangeMapper(const PropertyName &name) const
|
Chris@167
|
894 {
|
Chris@167
|
895 if (name == "Gain") {
|
Chris@167
|
896 return new LinearRangeMapper(-50, 50, -25, 25, tr("dB"));
|
Chris@167
|
897 }
|
Chris@284
|
898 if (name == "Threshold") {
|
Chris@284
|
899 return new LinearRangeMapper(-80, 0, -80, 0, tr("dB"));
|
Chris@284
|
900 }
|
Chris@287
|
901 return SingleColourLayer::getNewPropertyRangeMapper(name);
|
Chris@167
|
902 }
|
Chris@167
|
903
|
Chris@133
|
904 void
|
Chris@193
|
905 SliceLayer::setProperty(const PropertyName &name, int value)
|
Chris@133
|
906 {
|
Chris@153
|
907 if (name == "Gain") {
|
Chris@1266
|
908 setGain(powf(10, float(value)/20.0f));
|
Chris@284
|
909 } else if (name == "Threshold") {
|
Chris@1266
|
910 if (value == -80) setThreshold(0.0f);
|
Chris@1266
|
911 else setThreshold(float(AudioLevel::dB_to_multiplier(value)));
|
Chris@1281
|
912 } else if (name == "Colour" && usesSolidColour()) {
|
Chris@287
|
913 setFillColourMap(value);
|
Chris@153
|
914 } else if (name == "Scale") {
|
Chris@1266
|
915 switch (value) {
|
Chris@1266
|
916 default:
|
Chris@1266
|
917 case 0: setEnergyScale(LinearScale); break;
|
Chris@1266
|
918 case 1: setEnergyScale(MeterScale); break;
|
Chris@1266
|
919 case 2: setEnergyScale(dBScale); break;
|
Chris@1266
|
920 case 3: setEnergyScale(AbsoluteScale); break;
|
Chris@1266
|
921 }
|
Chris@193
|
922 } else if (name == "Plot Type") {
|
Chris@1266
|
923 setPlotStyle(PlotStyle(value));
|
Chris@193
|
924 } else if (name == "Sampling Mode") {
|
Chris@1266
|
925 switch (value) {
|
Chris@1266
|
926 default:
|
Chris@1266
|
927 case 0: setSamplingMode(NearestSample); break;
|
Chris@1266
|
928 case 1: setSamplingMode(SampleMean); break;
|
Chris@1266
|
929 case 2: setSamplingMode(SamplePeak); break;
|
Chris@1266
|
930 }
|
Chris@193
|
931 } else if (name == "Bin Scale") {
|
Chris@1266
|
932 switch (value) {
|
Chris@1266
|
933 default:
|
Chris@1266
|
934 case 0: setBinScale(LinearBins); break;
|
Chris@1266
|
935 case 1: setBinScale(LogBins); break;
|
Chris@1266
|
936 case 2: setBinScale(InvertedLogBins); break;
|
Chris@1266
|
937 }
|
Chris@153
|
938 } else if (name == "Normalize") {
|
Chris@1266
|
939 setNormalize(value ? true : false);
|
Chris@287
|
940 } else {
|
Chris@287
|
941 SingleColourLayer::setProperty(name, value);
|
Chris@153
|
942 }
|
Chris@153
|
943 }
|
Chris@153
|
944
|
Chris@153
|
945 void
|
Chris@197
|
946 SliceLayer::setFillColourMap(int map)
|
Chris@197
|
947 {
|
Chris@197
|
948 if (m_colourMap == map) return;
|
Chris@197
|
949 m_colourMap = map;
|
Chris@197
|
950 emit layerParametersChanged();
|
Chris@197
|
951 }
|
Chris@197
|
952
|
Chris@197
|
953 void
|
Chris@193
|
954 SliceLayer::setEnergyScale(EnergyScale scale)
|
Chris@153
|
955 {
|
Chris@153
|
956 if (m_energyScale == scale) return;
|
Chris@153
|
957 m_energyScale = scale;
|
Chris@153
|
958 emit layerParametersChanged();
|
Chris@153
|
959 }
|
Chris@153
|
960
|
Chris@153
|
961 void
|
Chris@193
|
962 SliceLayer::setSamplingMode(SamplingMode mode)
|
Chris@153
|
963 {
|
Chris@193
|
964 if (m_samplingMode == mode) return;
|
Chris@193
|
965 m_samplingMode = mode;
|
Chris@153
|
966 emit layerParametersChanged();
|
Chris@153
|
967 }
|
Chris@153
|
968
|
Chris@153
|
969 void
|
Chris@193
|
970 SliceLayer::setPlotStyle(PlotStyle style)
|
Chris@153
|
971 {
|
Chris@193
|
972 if (m_plotStyle == style) return;
|
Chris@197
|
973 bool colourTypeChanged = (style == PlotFilledBlocks ||
|
Chris@197
|
974 m_plotStyle == PlotFilledBlocks);
|
Chris@193
|
975 m_plotStyle = style;
|
Chris@197
|
976 if (colourTypeChanged) {
|
Chris@197
|
977 emit layerParameterRangesChanged();
|
Chris@197
|
978 }
|
Chris@153
|
979 emit layerParametersChanged();
|
Chris@153
|
980 }
|
Chris@153
|
981
|
Chris@153
|
982 void
|
Chris@193
|
983 SliceLayer::setBinScale(BinScale scale)
|
Chris@153
|
984 {
|
Chris@193
|
985 if (m_binScale == scale) return;
|
Chris@193
|
986 m_binScale = scale;
|
Chris@153
|
987 emit layerParametersChanged();
|
Chris@153
|
988 }
|
Chris@153
|
989
|
Chris@153
|
990 void
|
Chris@193
|
991 SliceLayer::setNormalize(bool n)
|
Chris@153
|
992 {
|
Chris@153
|
993 if (m_normalize == n) return;
|
Chris@153
|
994 m_normalize = n;
|
Chris@153
|
995 emit layerParametersChanged();
|
Chris@153
|
996 }
|
Chris@153
|
997
|
Chris@153
|
998 void
|
Chris@284
|
999 SliceLayer::setThreshold(float thresh)
|
Chris@284
|
1000 {
|
Chris@284
|
1001 if (m_threshold == thresh) return;
|
Chris@284
|
1002 m_threshold = thresh;
|
Chris@284
|
1003 emit layerParametersChanged();
|
Chris@284
|
1004 }
|
Chris@284
|
1005
|
Chris@284
|
1006 void
|
Chris@193
|
1007 SliceLayer::setGain(float gain)
|
Chris@153
|
1008 {
|
Chris@153
|
1009 if (m_gain == gain) return;
|
Chris@153
|
1010 m_gain = gain;
|
Chris@153
|
1011 emit layerParametersChanged();
|
Chris@153
|
1012 }
|
Chris@153
|
1013
|
Chris@284
|
1014 float
|
Chris@284
|
1015 SliceLayer::getThresholdDb() const
|
Chris@284
|
1016 {
|
Chris@284
|
1017 if (m_threshold == 0.0) return -80.f;
|
Chris@906
|
1018 float db = float(AudioLevel::multiplier_to_dB(m_threshold));
|
Chris@284
|
1019 return db;
|
Chris@284
|
1020 }
|
Chris@284
|
1021
|
Chris@287
|
1022 int
|
Chris@287
|
1023 SliceLayer::getDefaultColourHint(bool darkbg, bool &impose)
|
Chris@287
|
1024 {
|
Chris@287
|
1025 impose = false;
|
Chris@287
|
1026 return ColourDatabase::getInstance()->getColourIndex
|
Chris@287
|
1027 (QString(darkbg ? "Bright Blue" : "Blue"));
|
Chris@287
|
1028 }
|
Chris@287
|
1029
|
Chris@316
|
1030 void
|
Chris@316
|
1031 SliceLayer::toXml(QTextStream &stream,
|
Chris@316
|
1032 QString indent, QString extraAttributes) const
|
Chris@153
|
1033 {
|
Chris@153
|
1034 QString s;
|
Chris@153
|
1035
|
Chris@1362
|
1036 s += QString("energyScale=\"%1\" "
|
Chris@1362
|
1037 "samplingMode=\"%2\" "
|
Chris@1362
|
1038 "plotStyle=\"%3\" "
|
Chris@1362
|
1039 "binScale=\"%4\" "
|
Chris@1362
|
1040 "gain=\"%5\" "
|
Chris@1362
|
1041 "threshold=\"%6\" "
|
Chris@1362
|
1042 "normalize=\"%7\" %8 ")
|
Chris@1266
|
1043 .arg(m_energyScale)
|
Chris@193
|
1044 .arg(m_samplingMode)
|
Chris@598
|
1045 .arg(m_plotStyle)
|
Chris@598
|
1046 .arg(m_binScale)
|
Chris@153
|
1047 .arg(m_gain)
|
Chris@598
|
1048 .arg(m_threshold)
|
Chris@1238
|
1049 .arg(m_normalize ? "true" : "false")
|
Chris@1238
|
1050 .arg(QString("minbin=\"%1\" "
|
Chris@1238
|
1051 "maxbin=\"%2\"")
|
Chris@1238
|
1052 .arg(m_minbin)
|
Chris@1238
|
1053 .arg(m_maxbin));
|
Chris@153
|
1054
|
Chris@1362
|
1055 // New-style colour map attribute, by string id rather than by
|
Chris@1362
|
1056 // number
|
Chris@1362
|
1057
|
Chris@1362
|
1058 s += QString("fillColourMap=\"%1\" ")
|
Chris@1362
|
1059 .arg(ColourMapper::getColourMapId(m_colourMap));
|
Chris@1362
|
1060
|
Chris@1362
|
1061 // Old-style colour map attribute
|
Chris@1362
|
1062
|
Chris@1362
|
1063 s += QString("colourScheme=\"%1\" ")
|
Chris@1362
|
1064 .arg(ColourMapper::getBackwardCompatibilityColourMap(m_colourMap));
|
Chris@1362
|
1065
|
Chris@316
|
1066 SingleColourLayer::toXml(stream, indent, extraAttributes + " " + s);
|
Chris@153
|
1067 }
|
Chris@153
|
1068
|
Chris@153
|
1069 void
|
Chris@193
|
1070 SliceLayer::setProperties(const QXmlAttributes &attributes)
|
Chris@153
|
1071 {
|
Chris@153
|
1072 bool ok = false;
|
Chris@153
|
1073
|
Chris@287
|
1074 SingleColourLayer::setProperties(attributes);
|
Chris@153
|
1075
|
Chris@153
|
1076 EnergyScale scale = (EnergyScale)
|
Chris@1266
|
1077 attributes.value("energyScale").toInt(&ok);
|
Chris@153
|
1078 if (ok) setEnergyScale(scale);
|
Chris@153
|
1079
|
Chris@193
|
1080 SamplingMode mode = (SamplingMode)
|
Chris@1266
|
1081 attributes.value("samplingMode").toInt(&ok);
|
Chris@193
|
1082 if (ok) setSamplingMode(mode);
|
Chris@153
|
1083
|
Chris@1362
|
1084 QString colourMapId = attributes.value("fillColourMap");
|
Chris@1362
|
1085 int colourMap = ColourMapper::getColourMapById(colourMapId);
|
Chris@1362
|
1086 if (colourMap >= 0) {
|
Chris@1362
|
1087 setFillColourMap(colourMap);
|
Chris@1362
|
1088 } else {
|
Chris@1362
|
1089 colourMap = attributes.value("colourScheme").toInt(&ok);
|
Chris@1362
|
1090 if (ok && colourMap < ColourMapper::getColourMapCount()) {
|
Chris@1362
|
1091 setFillColourMap(colourMap);
|
Chris@1362
|
1092 }
|
Chris@1362
|
1093 }
|
Chris@197
|
1094
|
Chris@598
|
1095 PlotStyle s = (PlotStyle)
|
Chris@1266
|
1096 attributes.value("plotStyle").toInt(&ok);
|
Chris@598
|
1097 if (ok) setPlotStyle(s);
|
Chris@598
|
1098
|
Chris@598
|
1099 BinScale b = (BinScale)
|
Chris@1266
|
1100 attributes.value("binScale").toInt(&ok);
|
Chris@598
|
1101 if (ok) setBinScale(b);
|
Chris@598
|
1102
|
Chris@153
|
1103 float gain = attributes.value("gain").toFloat(&ok);
|
Chris@153
|
1104 if (ok) setGain(gain);
|
Chris@153
|
1105
|
Chris@598
|
1106 float threshold = attributes.value("threshold").toFloat(&ok);
|
Chris@598
|
1107 if (ok) setThreshold(threshold);
|
Chris@598
|
1108
|
Chris@153
|
1109 bool normalize = (attributes.value("normalize").trimmed() == "true");
|
Chris@153
|
1110 setNormalize(normalize);
|
Chris@1238
|
1111
|
Chris@1238
|
1112 bool alsoOk = false;
|
Chris@1238
|
1113
|
Chris@1238
|
1114 float min = attributes.value("minbin").toFloat(&ok);
|
Chris@1238
|
1115 float max = attributes.value("maxbin").toFloat(&alsoOk);
|
Chris@1238
|
1116 if (ok && alsoOk) setDisplayExtents(min, max);
|
Chris@133
|
1117 }
|
Chris@133
|
1118
|
Chris@133
|
1119 bool
|
Chris@1238
|
1120 SliceLayer::getValueExtents(double &min, double &max, bool &logarithmic,
|
Chris@1238
|
1121 QString &unit) const
|
Chris@133
|
1122 {
|
Chris@1238
|
1123 if (!m_sliceableModel) return false;
|
Chris@1238
|
1124
|
Chris@1238
|
1125 min = 0;
|
Chris@1238
|
1126 max = double(m_sliceableModel->getHeight());
|
Chris@1238
|
1127
|
Chris@1238
|
1128 logarithmic = (m_binScale == BinScale::LogBins);
|
Chris@1238
|
1129 unit = "";
|
Chris@1238
|
1130
|
Chris@1238
|
1131 return true;
|
Chris@133
|
1132 }
|
Chris@133
|
1133
|
Chris@1238
|
1134 bool
|
Chris@1238
|
1135 SliceLayer::getDisplayExtents(double &min, double &max) const
|
Chris@1238
|
1136 {
|
Chris@1238
|
1137 if (!m_sliceableModel) return false;
|
Chris@1238
|
1138
|
Chris@1238
|
1139 double hmax = double(m_sliceableModel->getHeight());
|
Chris@1238
|
1140
|
Chris@1238
|
1141 min = m_minbin;
|
Chris@1238
|
1142 max = m_maxbin;
|
Chris@1238
|
1143 if (max <= min) {
|
Chris@1238
|
1144 min = 0;
|
Chris@1238
|
1145 max = hmax;
|
Chris@1238
|
1146 }
|
Chris@1238
|
1147 if (min < 0) min = 0;
|
Chris@1238
|
1148 if (max > hmax) max = hmax;
|
Chris@1238
|
1149
|
Chris@1238
|
1150 return true;
|
Chris@1238
|
1151 }
|
Chris@1238
|
1152
|
Chris@1238
|
1153 bool
|
Chris@1238
|
1154 SliceLayer::setDisplayExtents(double min, double max)
|
Chris@1238
|
1155 {
|
Chris@1238
|
1156 if (!m_sliceableModel) return false;
|
Chris@1238
|
1157
|
Chris@1238
|
1158 m_minbin = int(lrint(min));
|
Chris@1238
|
1159 m_maxbin = int(lrint(max));
|
Chris@1238
|
1160
|
Chris@1238
|
1161 emit layerParametersChanged();
|
Chris@1238
|
1162 return true;
|
Chris@1238
|
1163 }
|
Chris@1238
|
1164
|
Chris@1238
|
1165 int
|
Chris@1238
|
1166 SliceLayer::getVerticalZoomSteps(int &defaultStep) const
|
Chris@1238
|
1167 {
|
Chris@1238
|
1168 if (!m_sliceableModel) return 0;
|
Chris@1238
|
1169
|
Chris@1238
|
1170 defaultStep = 0;
|
Chris@1238
|
1171 int h = m_sliceableModel->getHeight();
|
Chris@1238
|
1172 return h;
|
Chris@1238
|
1173 }
|
Chris@1238
|
1174
|
Chris@1238
|
1175 int
|
Chris@1238
|
1176 SliceLayer::getCurrentVerticalZoomStep() const
|
Chris@1238
|
1177 {
|
Chris@1238
|
1178 if (!m_sliceableModel) return 0;
|
Chris@1238
|
1179
|
Chris@1238
|
1180 double min, max;
|
Chris@1238
|
1181 getDisplayExtents(min, max);
|
Chris@1238
|
1182 return m_sliceableModel->getHeight() - int(lrint(max - min));
|
Chris@1238
|
1183 }
|
Chris@1238
|
1184
|
Chris@1238
|
1185 void
|
Chris@1238
|
1186 SliceLayer::setVerticalZoomStep(int step)
|
Chris@1238
|
1187 {
|
Chris@1238
|
1188 if (!m_sliceableModel) return;
|
Chris@1238
|
1189
|
Chris@1238
|
1190 // SVDEBUG << "SliceLayer::setVerticalZoomStep(" <<step <<"): before: minbin = " << m_minbin << ", maxbin = " << m_maxbin << endl;
|
Chris@1238
|
1191
|
Chris@1238
|
1192 int dist = m_sliceableModel->getHeight() - step;
|
Chris@1238
|
1193 if (dist < 1) dist = 1;
|
Chris@1238
|
1194 double centre = m_minbin + (m_maxbin - m_minbin) / 2.0;
|
Chris@1238
|
1195 m_minbin = int(lrint(centre - dist/2.0));
|
Chris@1238
|
1196 if (m_minbin < 0) m_minbin = 0;
|
Chris@1238
|
1197 m_maxbin = m_minbin + dist;
|
Chris@1238
|
1198 if (m_maxbin > m_sliceableModel->getHeight()) m_maxbin = m_sliceableModel->getHeight();
|
Chris@1238
|
1199
|
Chris@1238
|
1200 // SVDEBUG << "SliceLayer::setVerticalZoomStep(" <<step <<"): after: minbin = " << m_minbin << ", maxbin = " << m_maxbin << endl;
|
Chris@1238
|
1201
|
Chris@1238
|
1202 emit layerParametersChanged();
|
Chris@1238
|
1203 }
|
Chris@1238
|
1204
|
Chris@1238
|
1205 RangeMapper *
|
Chris@1238
|
1206 SliceLayer::getNewVerticalZoomRangeMapper() const
|
Chris@1238
|
1207 {
|
Chris@1238
|
1208 if (!m_sliceableModel) return 0;
|
Chris@1238
|
1209
|
Chris@1238
|
1210 return new LinearRangeMapper(0, m_sliceableModel->getHeight(),
|
Chris@1238
|
1211 0, m_sliceableModel->getHeight(), "");
|
Chris@1238
|
1212 }
|