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@906
|
196 double x = 0;
|
Chris@198
|
197
|
Chris@1238
|
198 bin -= m_minbin;
|
Chris@1238
|
199 if (bin < 0) bin = 0;
|
Chris@1238
|
200
|
Chris@1238
|
201 double count = m_maxbin - m_minbin;
|
Chris@1238
|
202 if (count < 0) count = 0;
|
Chris@1238
|
203
|
Chris@1238
|
204 int pw = v->getPaintWidth();
|
Chris@1238
|
205 int origin = m_xorigins[v->getId()];
|
Chris@1238
|
206 int w = pw - origin;
|
Chris@1238
|
207 if (w < 1) w = 1;
|
Chris@1238
|
208
|
Chris@198
|
209 switch (m_binScale) {
|
Chris@198
|
210
|
Chris@198
|
211 case LinearBins:
|
Chris@906
|
212 x = (w * bin) / count;
|
Chris@198
|
213 break;
|
Chris@198
|
214
|
Chris@198
|
215 case LogBins:
|
Chris@1281
|
216 // The 0.8 here is an awkward compromise. Our x-coord is
|
Chris@1281
|
217 // proportional to log of bin number, with the x-coord "of a
|
Chris@1281
|
218 // bin" being that of the left edge of the bin range. We can't
|
Chris@1281
|
219 // start counting bins from 0, as that would give us x = -Inf
|
Chris@1281
|
220 // and hide the first bin entirely. But if we start from 1, we
|
Chris@1281
|
221 // are giving a lot of space to the first bin, which in most
|
Chris@1281
|
222 // display modes won't be used because the "point" location
|
Chris@1281
|
223 // for that bin is in the middle of it. Yet in some modes
|
Chris@1281
|
224 // we'll still want it. A compromise is to count our first bin
|
Chris@1281
|
225 // as "a bit less than 1", so that most of it is visible but a
|
Chris@1281
|
226 // bit is tactfully cropped at the left edge so it doesn't
|
Chris@1281
|
227 // take up so much space.
|
Chris@1281
|
228 x = (w * log10(bin + 0.8)) / log10(count + 0.8);
|
Chris@198
|
229 break;
|
Chris@198
|
230
|
Chris@198
|
231 case InvertedLogBins:
|
Chris@906
|
232 x = w - (w * log10(count - bin - 1)) / log10(count);
|
Chris@198
|
233 break;
|
Chris@198
|
234 }
|
Chris@1238
|
235
|
Chris@1238
|
236 return x + origin;
|
Chris@198
|
237 }
|
Chris@198
|
238
|
Chris@1238
|
239 double
|
Chris@1238
|
240 SliceLayer::getBinForX(const LayerGeometryProvider *v, double x) const
|
Chris@198
|
241 {
|
Chris@1238
|
242 double bin = 0;
|
Chris@198
|
243
|
Chris@1238
|
244 double count = m_maxbin - m_minbin;
|
Chris@1238
|
245 if (count < 0) count = 0;
|
Chris@1238
|
246
|
Chris@1238
|
247 int pw = v->getPaintWidth();
|
Chris@1238
|
248 int origin = m_xorigins[v->getId()];
|
Chris@1238
|
249
|
Chris@1238
|
250 int w = pw - origin;
|
Chris@1238
|
251 if (w < 1) w = 1;
|
Chris@1238
|
252
|
Chris@1238
|
253 x = x - origin;
|
Chris@1238
|
254 if (x < 0) x = 0;
|
Chris@1256
|
255
|
Chris@1256
|
256 double eps = 1e-10;
|
Chris@1238
|
257
|
Chris@198
|
258 switch (m_binScale) {
|
Chris@198
|
259
|
Chris@198
|
260 case LinearBins:
|
Chris@1256
|
261 bin = (x * count) / w + eps;
|
Chris@198
|
262 break;
|
Chris@198
|
263
|
Chris@198
|
264 case LogBins:
|
Chris@1281
|
265 // See comment in getXForBin
|
Chris@1281
|
266 bin = pow(10.0, (x * log10(count + 0.8)) / w) - 0.8 + eps;
|
Chris@198
|
267 break;
|
Chris@198
|
268
|
Chris@198
|
269 case InvertedLogBins:
|
Chris@1256
|
270 bin = count + 1 - pow(10.0, (log10(count) * (w - x)) / double(w)) + eps;
|
Chris@198
|
271 break;
|
Chris@198
|
272 }
|
Chris@198
|
273
|
Chris@1238
|
274 return bin + m_minbin;
|
Chris@198
|
275 }
|
Chris@198
|
276
|
Chris@906
|
277 double
|
Chris@1238
|
278 SliceLayer::getYForValue(const LayerGeometryProvider *v, double value, double &norm) const
|
Chris@274
|
279 {
|
Chris@906
|
280 norm = 0.0;
|
Chris@274
|
281
|
Chris@1238
|
282 if (m_yorigins.find(v->getId()) == m_yorigins.end()) return 0;
|
Chris@274
|
283
|
Chris@274
|
284 value *= m_gain;
|
Chris@274
|
285
|
Chris@1238
|
286 int yorigin = m_yorigins[v->getId()];
|
Chris@1238
|
287 int h = m_heights[v->getId()];
|
Chris@906
|
288 double thresh = getThresholdDb();
|
Chris@274
|
289
|
Chris@906
|
290 double y = 0.0;
|
Chris@274
|
291
|
Chris@274
|
292 if (h <= 0) return y;
|
Chris@274
|
293
|
Chris@274
|
294 switch (m_energyScale) {
|
Chris@274
|
295
|
Chris@274
|
296 case dBScale:
|
Chris@274
|
297 {
|
Chris@906
|
298 double db = thresh;
|
Chris@906
|
299 if (value > 0.0) db = 10.0 * log10(fabs(value));
|
Chris@274
|
300 if (db < thresh) db = thresh;
|
Chris@274
|
301 norm = (db - thresh) / -thresh;
|
Chris@906
|
302 y = yorigin - (double(h) * norm);
|
Chris@274
|
303 break;
|
Chris@274
|
304 }
|
Chris@274
|
305
|
Chris@274
|
306 case MeterScale:
|
Chris@274
|
307 y = AudioLevel::multiplier_to_preview(value, h);
|
Chris@906
|
308 norm = double(y) / double(h);
|
Chris@274
|
309 y = yorigin - y;
|
Chris@274
|
310 break;
|
Chris@274
|
311
|
Chris@538
|
312 case AbsoluteScale:
|
Chris@906
|
313 value = fabs(value);
|
Chris@1264
|
314 #if (__GNUC__ >= 7)
|
Chris@1263
|
315 __attribute__ ((fallthrough));
|
Chris@1263
|
316 #endif
|
Chris@538
|
317
|
Chris@805
|
318 case LinearScale:
|
Chris@274
|
319 default:
|
Chris@538
|
320 norm = (value - m_threshold);
|
Chris@284
|
321 if (norm < 0) norm = 0;
|
Chris@906
|
322 y = yorigin - (double(h) * norm);
|
Chris@274
|
323 break;
|
Chris@274
|
324 }
|
Chris@274
|
325
|
Chris@274
|
326 return y;
|
Chris@274
|
327 }
|
Chris@274
|
328
|
Chris@906
|
329 double
|
Chris@1238
|
330 SliceLayer::getValueForY(const LayerGeometryProvider *v, double y) const
|
Chris@274
|
331 {
|
Chris@906
|
332 double value = 0.0;
|
Chris@274
|
333
|
Chris@1238
|
334 if (m_yorigins.find(v->getId()) == m_yorigins.end()) return value;
|
Chris@274
|
335
|
Chris@1238
|
336 int yorigin = m_yorigins[v->getId()];
|
Chris@1238
|
337 int h = m_heights[v->getId()];
|
Chris@906
|
338 double thresh = getThresholdDb();
|
Chris@274
|
339
|
Chris@274
|
340 if (h <= 0) return value;
|
Chris@274
|
341
|
Chris@274
|
342 y = yorigin - y;
|
Chris@274
|
343
|
Chris@274
|
344 switch (m_energyScale) {
|
Chris@274
|
345
|
Chris@274
|
346 case dBScale:
|
Chris@274
|
347 {
|
Chris@906
|
348 double db = ((y / h) * -thresh) + thresh;
|
Chris@906
|
349 value = pow(10.0, db/10.0);
|
Chris@274
|
350 break;
|
Chris@274
|
351 }
|
Chris@274
|
352
|
Chris@274
|
353 case MeterScale:
|
Chris@906
|
354 value = AudioLevel::preview_to_multiplier(int(lrint(y)), h);
|
Chris@274
|
355 break;
|
Chris@805
|
356
|
Chris@805
|
357 case LinearScale:
|
Chris@805
|
358 case AbsoluteScale:
|
Chris@274
|
359 default:
|
Chris@284
|
360 value = y / h + m_threshold;
|
Chris@274
|
361 }
|
Chris@274
|
362
|
Chris@274
|
363 return value / m_gain;
|
Chris@274
|
364 }
|
Chris@274
|
365
|
Chris@133
|
366 void
|
Chris@916
|
367 SliceLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
|
Chris@133
|
368 {
|
Chris@1383
|
369 if (!m_sliceableModel ||
|
Chris@1383
|
370 !m_sliceableModel->isOK() ||
|
Chris@254
|
371 !m_sliceableModel->isReady()) return;
|
Chris@133
|
372
|
Chris@1383
|
373 Profiler profiler("SliceLayer::paint()");
|
Chris@1383
|
374
|
Chris@195
|
375 paint.save();
|
Chris@1383
|
376 paint.setRenderHint(QPainter::Antialiasing, true);
|
Chris@538
|
377 paint.setBrush(Qt::NoBrush);
|
Chris@195
|
378
|
Chris@195
|
379 if (v->getViewManager() && v->getViewManager()->shouldShowScaleGuides()) {
|
Chris@195
|
380 if (!m_scalePoints.empty()) {
|
Chris@195
|
381 paint.setPen(QColor(240, 240, 240)); //!!! and dark background?
|
Chris@1284
|
382 int ratio = int(round(double(v->getPaintHeight()) /
|
Chris@1284
|
383 m_scalePaintHeight));
|
Chris@805
|
384 for (int i = 0; i < (int)m_scalePoints.size(); ++i) {
|
Chris@1284
|
385 paint.drawLine(0, m_scalePoints[i] * ratio,
|
Chris@1284
|
386 rect.width(), m_scalePoints[i] * ratio);
|
Chris@195
|
387 }
|
Chris@195
|
388 }
|
Chris@195
|
389 }
|
Chris@195
|
390
|
Chris@1233
|
391 if (m_plotStyle == PlotBlocks) {
|
Chris@1233
|
392 // Must use actual zero-width pen, too slow otherwise
|
Chris@1233
|
393 paint.setPen(QPen(getBaseQColor(), 0));
|
Chris@1233
|
394 } else {
|
Chris@1233
|
395 paint.setPen(PaintAssistant::scalePen(getBaseQColor()));
|
Chris@1233
|
396 }
|
Chris@195
|
397
|
Chris@607
|
398 int xorigin = getVerticalScaleWidth(v, true, paint) + 1;
|
Chris@1238
|
399 m_xorigins[v->getId()] = xorigin; // for use in getFeatureDescription
|
Chris@133
|
400
|
Chris@1383
|
401 int yorigin = v->getPaintHeight() - getHorizontalScaleHeight(v, paint) -
|
Chris@1383
|
402 paint.fontMetrics().height();
|
Chris@195
|
403 int h = yorigin - paint.fontMetrics().height() - 8;
|
Chris@133
|
404
|
Chris@1238
|
405 m_yorigins[v->getId()] = yorigin; // for getYForValue etc
|
Chris@1238
|
406 m_heights[v->getId()] = h;
|
Chris@274
|
407
|
Chris@274
|
408 if (h <= 0) return;
|
Chris@274
|
409
|
Chris@133
|
410 QPainterPath path;
|
Chris@133
|
411
|
Chris@805
|
412 int mh = m_sliceableModel->getHeight();
|
Chris@1238
|
413 int bin0 = 0;
|
Chris@133
|
414
|
Chris@1238
|
415 if (m_maxbin > m_minbin) {
|
Chris@1238
|
416 mh = m_maxbin - m_minbin;
|
Chris@1238
|
417 bin0 = m_minbin;
|
Chris@1238
|
418 }
|
Chris@1238
|
419
|
Chris@193
|
420 int divisor = 0;
|
Chris@193
|
421
|
Chris@198
|
422 m_values.clear();
|
Chris@805
|
423 for (int bin = 0; bin < mh; ++bin) {
|
Chris@906
|
424 m_values.push_back(0.0);
|
Chris@193
|
425 }
|
Chris@193
|
426
|
Chris@906
|
427 sv_frame_t f0 = v->getCentreFrame();
|
Chris@193
|
428 int f0x = v->getXForFrame(f0);
|
Chris@195
|
429 f0 = v->getFrameForX(f0x);
|
Chris@906
|
430 sv_frame_t f1 = v->getFrameForX(f0x + 1);
|
Chris@195
|
431 if (f1 > f0) --f1;
|
Chris@193
|
432
|
Chris@682
|
433 // cerr << "centre frame " << v->getCentreFrame() << ", x " << f0x << ", f0 " << f0 << ", f1 " << f1 << endl;
|
Chris@274
|
434
|
Chris@805
|
435 int res = m_sliceableModel->getResolution();
|
Chris@906
|
436 int col0 = int(f0 / res);
|
Chris@805
|
437 int col1 = col0;
|
Chris@906
|
438 if (m_samplingMode != NearestSample) col1 = int(f1 / res);
|
Chris@274
|
439 f0 = col0 * res;
|
Chris@274
|
440 f1 = (col1 + 1) * res - 1;
|
Chris@274
|
441
|
Chris@682
|
442 // cerr << "resolution " << res << ", col0 " << col0 << ", col1 " << col1 << ", f0 " << f0 << ", f1 " << f1 << endl;
|
Chris@1383
|
443 // cerr << "mh = " << mh << endl;
|
Chris@193
|
444
|
Chris@198
|
445 m_currentf0 = f0;
|
Chris@198
|
446 m_currentf1 = f1;
|
Chris@198
|
447
|
Chris@254
|
448 BiasCurve curve;
|
Chris@254
|
449 getBiasCurve(curve);
|
Chris@906
|
450 int cs = int(curve.size());
|
Chris@254
|
451
|
Chris@805
|
452 for (int col = col0; col <= col1; ++col) {
|
Chris@1383
|
453 DenseThreeDimensionalModel::Column column =
|
Chris@1383
|
454 m_sliceableModel->getColumn(col);
|
Chris@805
|
455 for (int bin = 0; bin < mh; ++bin) {
|
Chris@1383
|
456 float value = column[bin0 + bin];
|
Chris@254
|
457 if (bin < cs) value *= curve[bin];
|
Chris@193
|
458 if (m_samplingMode == SamplePeak) {
|
Chris@198
|
459 if (value > m_values[bin]) m_values[bin] = value;
|
Chris@193
|
460 } else {
|
Chris@198
|
461 m_values[bin] += value;
|
Chris@193
|
462 }
|
Chris@153
|
463 }
|
Chris@193
|
464 ++divisor;
|
Chris@193
|
465 }
|
Chris@193
|
466
|
Chris@906
|
467 float max = 0.0;
|
Chris@805
|
468 for (int bin = 0; bin < mh; ++bin) {
|
Chris@847
|
469 if (m_samplingMode == SampleMean && divisor > 0) {
|
Chris@906
|
470 m_values[bin] /= float(divisor);
|
Chris@847
|
471 }
|
Chris@198
|
472 if (m_values[bin] > max) max = m_values[bin];
|
Chris@193
|
473 }
|
Chris@906
|
474 if (max != 0.0 && m_normalize) {
|
Chris@805
|
475 for (int bin = 0; bin < mh; ++bin) {
|
Chris@198
|
476 m_values[bin] /= max;
|
Chris@193
|
477 }
|
Chris@193
|
478 }
|
Chris@193
|
479
|
Chris@1238
|
480 double nx = getXForBin(v, bin0);
|
Chris@193
|
481
|
Chris@1362
|
482 ColourMapper mapper(m_colourMap, m_colourInverted, 0, 1);
|
Chris@197
|
483
|
Chris@1383
|
484 double ytop = 0, ybottom = 0;
|
Chris@1383
|
485 bool firstBinOfPixel = true;
|
Chris@1383
|
486
|
Chris@805
|
487 for (int bin = 0; bin < mh; ++bin) {
|
Chris@193
|
488
|
Chris@906
|
489 double x = nx;
|
Chris@1238
|
490 nx = getXForBin(v, bin + bin0 + 1);
|
Chris@193
|
491
|
Chris@906
|
492 double value = m_values[bin];
|
Chris@906
|
493 double norm = 0.0;
|
Chris@1238
|
494 double y = getYForValue(v, value, norm);
|
Chris@133
|
495
|
Chris@1383
|
496 if (y < ytop || firstBinOfPixel) {
|
Chris@1383
|
497 ytop = y;
|
Chris@1383
|
498 }
|
Chris@1383
|
499 if (y > ybottom || firstBinOfPixel) {
|
Chris@1383
|
500 ybottom = y;
|
Chris@1383
|
501 }
|
Chris@193
|
502
|
Chris@1383
|
503 if (int(nx) != int(x) || bin+1 == mh) {
|
Chris@1383
|
504
|
Chris@1383
|
505 if (m_plotStyle == PlotLines) {
|
Chris@1383
|
506
|
Chris@1383
|
507 auto px = (x + nx) / 2;
|
Chris@1383
|
508
|
Chris@1383
|
509 if (bin == 0) {
|
Chris@1383
|
510 path.moveTo(px, y);
|
Chris@1383
|
511 } else {
|
Chris@1383
|
512 if (ytop != ybottom) {
|
Chris@1383
|
513 path.lineTo(px, ybottom);
|
Chris@1383
|
514 path.lineTo(px, ytop);
|
Chris@1383
|
515 path.moveTo(px, ybottom);
|
Chris@1383
|
516 } else {
|
Chris@1383
|
517 path.lineTo(px, ytop);
|
Chris@1383
|
518 }
|
Chris@1383
|
519 }
|
Chris@1383
|
520
|
Chris@1383
|
521 } else if (m_plotStyle == PlotSteps) {
|
Chris@1383
|
522
|
Chris@1383
|
523 if (bin == 0) {
|
Chris@1383
|
524 path.moveTo(x, y);
|
Chris@1383
|
525 } else {
|
Chris@1383
|
526 path.lineTo(x, ytop);
|
Chris@1383
|
527 }
|
Chris@1383
|
528 path.lineTo(nx, ytop);
|
Chris@1383
|
529
|
Chris@1383
|
530 } else if (m_plotStyle == PlotBlocks) {
|
Chris@1383
|
531
|
Chris@1383
|
532 path.moveTo(x, yorigin);
|
Chris@1383
|
533 path.lineTo(x, ytop);
|
Chris@1383
|
534 path.lineTo(nx, ytop);
|
Chris@1383
|
535 path.lineTo(nx, yorigin);
|
Chris@1383
|
536 path.lineTo(x, yorigin);
|
Chris@1383
|
537
|
Chris@1383
|
538 } else if (m_plotStyle == PlotFilledBlocks) {
|
Chris@1383
|
539
|
Chris@1383
|
540 paint.fillRect(QRectF(x, ytop, nx - x, yorigin - ytop),
|
Chris@1383
|
541 mapper.map(norm));
|
Chris@193
|
542 }
|
Chris@193
|
543
|
Chris@1383
|
544 firstBinOfPixel = true;
|
Chris@193
|
545
|
Chris@1383
|
546 } else {
|
Chris@1383
|
547 firstBinOfPixel = false;
|
Chris@133
|
548 }
|
Chris@133
|
549 }
|
Chris@133
|
550
|
Chris@197
|
551 if (m_plotStyle != PlotFilledBlocks) {
|
Chris@197
|
552 paint.drawPath(path);
|
Chris@197
|
553 }
|
Chris@133
|
554 paint.restore();
|
Chris@195
|
555 }
|
Chris@195
|
556
|
Chris@195
|
557 int
|
Chris@918
|
558 SliceLayer::getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &paint) const
|
Chris@195
|
559 {
|
Chris@1238
|
560 int width;
|
Chris@538
|
561 if (m_energyScale == LinearScale || m_energyScale == AbsoluteScale) {
|
Chris@1266
|
562 width = std::max(paint.fontMetrics().width("0.0") + 13,
|
Chris@1238
|
563 paint.fontMetrics().width("x10-10"));
|
Chris@195
|
564 } else {
|
Chris@1238
|
565 width = std::max(paint.fontMetrics().width(tr("0dB")),
|
Chris@1238
|
566 paint.fontMetrics().width(tr("-Inf"))) + 13;
|
Chris@195
|
567 }
|
Chris@1238
|
568 return width;
|
Chris@195
|
569 }
|
Chris@195
|
570
|
Chris@195
|
571 void
|
Chris@918
|
572 SliceLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const
|
Chris@195
|
573 {
|
Chris@906
|
574 double thresh = m_threshold;
|
Chris@538
|
575 if (m_energyScale != LinearScale && m_energyScale != AbsoluteScale) {
|
Chris@284
|
576 thresh = AudioLevel::dB_to_multiplier(getThresholdDb());
|
Chris@195
|
577 }
|
Chris@195
|
578
|
Chris@195
|
579 // int h = (rect.height() * 3) / 4;
|
Chris@195
|
580 // int y = (rect.height() / 2) - (h / 2);
|
Chris@195
|
581
|
Chris@1383
|
582 int yorigin = v->getPaintHeight() - getHorizontalScaleHeight(v, paint) -
|
Chris@1383
|
583 paint.fontMetrics().height();
|
Chris@195
|
584 int h = yorigin - paint.fontMetrics().height() - 8;
|
Chris@195
|
585 if (h < 0) return;
|
Chris@195
|
586
|
Chris@195
|
587 QRect actual(rect.x(), rect.y() + yorigin - h, rect.width(), h);
|
Chris@195
|
588
|
Chris@220
|
589 int mult = 1;
|
Chris@220
|
590
|
Chris@195
|
591 PaintAssistant::paintVerticalLevelScale
|
Chris@195
|
592 (paint, actual, thresh, 1.0 / m_gain,
|
Chris@195
|
593 PaintAssistant::Scale(m_energyScale),
|
Chris@220
|
594 mult,
|
Chris@195
|
595 const_cast<std::vector<int> *>(&m_scalePoints));
|
Chris@220
|
596
|
Chris@1284
|
597 // Ugly hack (but then everything about this scale drawing is a
|
Chris@1284
|
598 // bit ugly). In pixel-doubling hi-dpi scenarios, the scale is
|
Chris@1284
|
599 // painted at pixel-doubled resolution but we do explicit
|
Chris@1284
|
600 // pixel-doubling ourselves when painting the layer content. We
|
Chris@1284
|
601 // make a note of this here so that we can compare with the
|
Chris@1284
|
602 // equivalent dimension in the paint method when deciding where to
|
Chris@1284
|
603 // place scale continuation lines.
|
Chris@1284
|
604 m_scalePaintHeight = v->getPaintHeight();
|
Chris@1284
|
605
|
Chris@220
|
606 if (mult != 1 && mult != 0) {
|
Chris@906
|
607 int log = int(lrint(log10(mult)));
|
Chris@220
|
608 QString a = tr("x10");
|
Chris@220
|
609 QString b = QString("%1").arg(-log);
|
Chris@220
|
610 paint.drawText(3, 8 + paint.fontMetrics().ascent(), a);
|
Chris@220
|
611 paint.drawText(3 + paint.fontMetrics().width(a),
|
Chris@220
|
612 3 + paint.fontMetrics().ascent(), b);
|
Chris@220
|
613 }
|
Chris@133
|
614 }
|
Chris@133
|
615
|
Chris@1281
|
616 bool
|
Chris@1281
|
617 SliceLayer::hasLightBackground() const
|
Chris@1281
|
618 {
|
Chris@1281
|
619 if (usesSolidColour()) {
|
Chris@1362
|
620 ColourMapper mapper(m_colourMap, m_colourInverted, 0, 1);
|
Chris@1281
|
621 return mapper.hasLightBackground();
|
Chris@1281
|
622 } else {
|
Chris@1281
|
623 return SingleColourLayer::hasLightBackground();
|
Chris@1281
|
624 }
|
Chris@1281
|
625 }
|
Chris@1281
|
626
|
Chris@153
|
627 Layer::PropertyList
|
Chris@193
|
628 SliceLayer::getProperties() const
|
Chris@153
|
629 {
|
Chris@287
|
630 PropertyList list = SingleColourLayer::getProperties();
|
Chris@538
|
631 list.push_back("Bin Scale");
|
Chris@193
|
632 list.push_back("Plot Type");
|
Chris@153
|
633 list.push_back("Scale");
|
Chris@153
|
634 list.push_back("Normalize");
|
Chris@284
|
635 list.push_back("Threshold");
|
Chris@153
|
636 list.push_back("Gain");
|
Chris@153
|
637
|
Chris@153
|
638 return list;
|
Chris@153
|
639 }
|
Chris@153
|
640
|
Chris@153
|
641 QString
|
Chris@193
|
642 SliceLayer::getPropertyLabel(const PropertyName &name) const
|
Chris@153
|
643 {
|
Chris@193
|
644 if (name == "Plot Type") return tr("Plot Type");
|
Chris@290
|
645 if (name == "Scale") return tr("Scale");
|
Chris@153
|
646 if (name == "Normalize") return tr("Normalize");
|
Chris@284
|
647 if (name == "Threshold") return tr("Threshold");
|
Chris@153
|
648 if (name == "Gain") return tr("Gain");
|
Chris@193
|
649 if (name == "Sampling Mode") return tr("Sampling Mode");
|
Chris@538
|
650 if (name == "Bin Scale") return tr("Bin Scale");
|
Chris@287
|
651 return SingleColourLayer::getPropertyLabel(name);
|
Chris@153
|
652 }
|
Chris@153
|
653
|
Chris@335
|
654 QString
|
Chris@335
|
655 SliceLayer::getPropertyIconName(const PropertyName &name) const
|
Chris@335
|
656 {
|
Chris@335
|
657 if (name == "Normalize") return "normalise";
|
Chris@335
|
658 return "";
|
Chris@335
|
659 }
|
Chris@335
|
660
|
Chris@153
|
661 Layer::PropertyType
|
Chris@193
|
662 SliceLayer::getPropertyType(const PropertyName &name) const
|
Chris@153
|
663 {
|
Chris@153
|
664 if (name == "Gain") return RangeProperty;
|
Chris@153
|
665 if (name == "Normalize") return ToggleProperty;
|
Chris@284
|
666 if (name == "Threshold") return RangeProperty;
|
Chris@287
|
667 if (name == "Plot Type") return ValueProperty;
|
Chris@290
|
668 if (name == "Scale") return ValueProperty;
|
Chris@287
|
669 if (name == "Sampling Mode") return ValueProperty;
|
Chris@287
|
670 if (name == "Bin Scale") return ValueProperty;
|
Chris@1281
|
671 if (name == "Colour" && usesSolidColour()) return ColourMapProperty;
|
Chris@287
|
672 return SingleColourLayer::getPropertyType(name);
|
Chris@153
|
673 }
|
Chris@153
|
674
|
Chris@153
|
675 QString
|
Chris@193
|
676 SliceLayer::getPropertyGroupName(const PropertyName &name) const
|
Chris@153
|
677 {
|
Chris@153
|
678 if (name == "Scale" ||
|
Chris@153
|
679 name == "Normalize" ||
|
Chris@193
|
680 name == "Sampling Mode" ||
|
Chris@284
|
681 name == "Threshold" ||
|
Chris@193
|
682 name == "Gain") return tr("Scale");
|
Chris@193
|
683 if (name == "Plot Type" ||
|
Chris@538
|
684 name == "Bin Scale") return tr("Bins");
|
Chris@287
|
685 return SingleColourLayer::getPropertyGroupName(name);
|
Chris@153
|
686 }
|
Chris@153
|
687
|
Chris@153
|
688 int
|
Chris@193
|
689 SliceLayer::getPropertyRangeAndValue(const PropertyName &name,
|
Chris@216
|
690 int *min, int *max, int *deflt) const
|
Chris@153
|
691 {
|
Chris@216
|
692 int val = 0;
|
Chris@153
|
693
|
Chris@216
|
694 int garbage0, garbage1, garbage2;
|
Chris@153
|
695 if (!min) min = &garbage0;
|
Chris@153
|
696 if (!max) max = &garbage1;
|
Chris@248
|
697 if (!deflt) deflt = &garbage2;
|
Chris@153
|
698
|
Chris@153
|
699 if (name == "Gain") {
|
Chris@153
|
700
|
Chris@1266
|
701 *min = -50;
|
Chris@1266
|
702 *max = 50;
|
Chris@216
|
703 *deflt = 0;
|
Chris@153
|
704
|
Chris@1238
|
705 // cerr << "gain is " << m_gain << ", mode is " << m_samplingMode << endl;
|
Chris@193
|
706
|
Chris@1266
|
707 val = int(lrint(log10(m_gain) * 20.0));
|
Chris@1266
|
708 if (val < *min) val = *min;
|
Chris@1266
|
709 if (val > *max) val = *max;
|
Chris@153
|
710
|
Chris@284
|
711 } else if (name == "Threshold") {
|
Chris@284
|
712
|
Chris@1266
|
713 *min = -80;
|
Chris@1266
|
714 *max = 0;
|
Chris@284
|
715
|
Chris@906
|
716 *deflt = int(lrint(AudioLevel::multiplier_to_dB(m_initialThreshold)));
|
Chris@1266
|
717 if (*deflt < *min) *deflt = *min;
|
Chris@1266
|
718 if (*deflt > *max) *deflt = *max;
|
Chris@284
|
719
|
Chris@1266
|
720 val = int(lrint(AudioLevel::multiplier_to_dB(m_threshold)));
|
Chris@1266
|
721 if (val < *min) val = *min;
|
Chris@1266
|
722 if (val > *max) val = *max;
|
Chris@284
|
723
|
Chris@153
|
724 } else if (name == "Normalize") {
|
Chris@1266
|
725
|
Chris@1266
|
726 val = (m_normalize ? 1 : 0);
|
Chris@216
|
727 *deflt = 0;
|
Chris@153
|
728
|
Chris@1281
|
729 } else if (name == "Colour" && usesSolidColour()) {
|
Chris@197
|
730
|
Chris@287
|
731 *min = 0;
|
Chris@287
|
732 *max = ColourMapper::getColourMapCount() - 1;
|
Chris@1281
|
733 *deflt = int(ColourMapper::Ice);
|
Chris@287
|
734
|
Chris@287
|
735 val = m_colourMap;
|
Chris@153
|
736
|
Chris@153
|
737 } else if (name == "Scale") {
|
Chris@153
|
738
|
Chris@1266
|
739 *min = 0;
|
Chris@1266
|
740 *max = 3;
|
Chris@216
|
741 *deflt = (int)dBScale;
|
Chris@153
|
742
|
Chris@1266
|
743 val = (int)m_energyScale;
|
Chris@153
|
744
|
Chris@193
|
745 } else if (name == "Sampling Mode") {
|
Chris@153
|
746
|
Chris@1266
|
747 *min = 0;
|
Chris@1266
|
748 *max = 2;
|
Chris@216
|
749 *deflt = (int)SampleMean;
|
Chris@193
|
750
|
Chris@1266
|
751 val = (int)m_samplingMode;
|
Chris@153
|
752
|
Chris@193
|
753 } else if (name == "Plot Type") {
|
Chris@193
|
754
|
Chris@193
|
755 *min = 0;
|
Chris@197
|
756 *max = 3;
|
Chris@216
|
757 *deflt = (int)PlotSteps;
|
Chris@193
|
758
|
Chris@216
|
759 val = (int)m_plotStyle;
|
Chris@193
|
760
|
Chris@193
|
761 } else if (name == "Bin Scale") {
|
Chris@193
|
762
|
Chris@193
|
763 *min = 0;
|
Chris@198
|
764 *max = 2;
|
Chris@216
|
765 *deflt = (int)LinearBins;
|
Chris@198
|
766 // *max = 1; // I don't think we really do want to offer inverted log
|
Chris@193
|
767
|
Chris@216
|
768 val = (int)m_binScale;
|
Chris@193
|
769
|
Chris@153
|
770 } else {
|
Chris@1266
|
771 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt);
|
Chris@153
|
772 }
|
Chris@153
|
773
|
Chris@216
|
774 return val;
|
Chris@153
|
775 }
|
Chris@153
|
776
|
Chris@153
|
777 QString
|
Chris@193
|
778 SliceLayer::getPropertyValueLabel(const PropertyName &name,
|
Chris@1281
|
779 int value) const
|
Chris@153
|
780 {
|
Chris@1281
|
781 if (name == "Colour" && usesSolidColour()) {
|
Chris@1362
|
782 return ColourMapper::getColourMapLabel(value);
|
Chris@153
|
783 }
|
Chris@153
|
784 if (name == "Scale") {
|
Chris@1266
|
785 switch (value) {
|
Chris@1266
|
786 default:
|
Chris@1266
|
787 case 0: return tr("Linear");
|
Chris@1266
|
788 case 1: return tr("Meter");
|
Chris@1266
|
789 case 2: return tr("Log");
|
Chris@1266
|
790 case 3: return tr("Absolute");
|
Chris@1266
|
791 }
|
Chris@153
|
792 }
|
Chris@193
|
793 if (name == "Sampling Mode") {
|
Chris@1266
|
794 switch (value) {
|
Chris@1266
|
795 default:
|
Chris@1266
|
796 case 0: return tr("Any");
|
Chris@1266
|
797 case 1: return tr("Mean");
|
Chris@1266
|
798 case 2: return tr("Peak");
|
Chris@1266
|
799 }
|
Chris@193
|
800 }
|
Chris@193
|
801 if (name == "Plot Type") {
|
Chris@1266
|
802 switch (value) {
|
Chris@1266
|
803 default:
|
Chris@1266
|
804 case 0: return tr("Lines");
|
Chris@1266
|
805 case 1: return tr("Steps");
|
Chris@1266
|
806 case 2: return tr("Blocks");
|
Chris@1266
|
807 case 3: return tr("Colours");
|
Chris@1266
|
808 }
|
Chris@193
|
809 }
|
Chris@193
|
810 if (name == "Bin Scale") {
|
Chris@1266
|
811 switch (value) {
|
Chris@1266
|
812 default:
|
Chris@1266
|
813 case 0: return tr("Linear");
|
Chris@1266
|
814 case 1: return tr("Log");
|
Chris@1266
|
815 case 2: return tr("Rev Log");
|
Chris@1266
|
816 }
|
Chris@153
|
817 }
|
Chris@287
|
818 return SingleColourLayer::getPropertyValueLabel(name, value);
|
Chris@153
|
819 }
|
Chris@153
|
820
|
Chris@167
|
821 RangeMapper *
|
Chris@193
|
822 SliceLayer::getNewPropertyRangeMapper(const PropertyName &name) const
|
Chris@167
|
823 {
|
Chris@167
|
824 if (name == "Gain") {
|
Chris@167
|
825 return new LinearRangeMapper(-50, 50, -25, 25, tr("dB"));
|
Chris@167
|
826 }
|
Chris@284
|
827 if (name == "Threshold") {
|
Chris@284
|
828 return new LinearRangeMapper(-80, 0, -80, 0, tr("dB"));
|
Chris@284
|
829 }
|
Chris@287
|
830 return SingleColourLayer::getNewPropertyRangeMapper(name);
|
Chris@167
|
831 }
|
Chris@167
|
832
|
Chris@133
|
833 void
|
Chris@193
|
834 SliceLayer::setProperty(const PropertyName &name, int value)
|
Chris@133
|
835 {
|
Chris@153
|
836 if (name == "Gain") {
|
Chris@1266
|
837 setGain(powf(10, float(value)/20.0f));
|
Chris@284
|
838 } else if (name == "Threshold") {
|
Chris@1266
|
839 if (value == -80) setThreshold(0.0f);
|
Chris@1266
|
840 else setThreshold(float(AudioLevel::dB_to_multiplier(value)));
|
Chris@1281
|
841 } else if (name == "Colour" && usesSolidColour()) {
|
Chris@287
|
842 setFillColourMap(value);
|
Chris@153
|
843 } else if (name == "Scale") {
|
Chris@1266
|
844 switch (value) {
|
Chris@1266
|
845 default:
|
Chris@1266
|
846 case 0: setEnergyScale(LinearScale); break;
|
Chris@1266
|
847 case 1: setEnergyScale(MeterScale); break;
|
Chris@1266
|
848 case 2: setEnergyScale(dBScale); break;
|
Chris@1266
|
849 case 3: setEnergyScale(AbsoluteScale); break;
|
Chris@1266
|
850 }
|
Chris@193
|
851 } else if (name == "Plot Type") {
|
Chris@1266
|
852 setPlotStyle(PlotStyle(value));
|
Chris@193
|
853 } else if (name == "Sampling Mode") {
|
Chris@1266
|
854 switch (value) {
|
Chris@1266
|
855 default:
|
Chris@1266
|
856 case 0: setSamplingMode(NearestSample); break;
|
Chris@1266
|
857 case 1: setSamplingMode(SampleMean); break;
|
Chris@1266
|
858 case 2: setSamplingMode(SamplePeak); break;
|
Chris@1266
|
859 }
|
Chris@193
|
860 } else if (name == "Bin Scale") {
|
Chris@1266
|
861 switch (value) {
|
Chris@1266
|
862 default:
|
Chris@1266
|
863 case 0: setBinScale(LinearBins); break;
|
Chris@1266
|
864 case 1: setBinScale(LogBins); break;
|
Chris@1266
|
865 case 2: setBinScale(InvertedLogBins); break;
|
Chris@1266
|
866 }
|
Chris@153
|
867 } else if (name == "Normalize") {
|
Chris@1266
|
868 setNormalize(value ? true : false);
|
Chris@287
|
869 } else {
|
Chris@287
|
870 SingleColourLayer::setProperty(name, value);
|
Chris@153
|
871 }
|
Chris@153
|
872 }
|
Chris@153
|
873
|
Chris@153
|
874 void
|
Chris@197
|
875 SliceLayer::setFillColourMap(int map)
|
Chris@197
|
876 {
|
Chris@197
|
877 if (m_colourMap == map) return;
|
Chris@197
|
878 m_colourMap = map;
|
Chris@197
|
879 emit layerParametersChanged();
|
Chris@197
|
880 }
|
Chris@197
|
881
|
Chris@197
|
882 void
|
Chris@193
|
883 SliceLayer::setEnergyScale(EnergyScale scale)
|
Chris@153
|
884 {
|
Chris@153
|
885 if (m_energyScale == scale) return;
|
Chris@153
|
886 m_energyScale = scale;
|
Chris@153
|
887 emit layerParametersChanged();
|
Chris@153
|
888 }
|
Chris@153
|
889
|
Chris@153
|
890 void
|
Chris@193
|
891 SliceLayer::setSamplingMode(SamplingMode mode)
|
Chris@153
|
892 {
|
Chris@193
|
893 if (m_samplingMode == mode) return;
|
Chris@193
|
894 m_samplingMode = mode;
|
Chris@153
|
895 emit layerParametersChanged();
|
Chris@153
|
896 }
|
Chris@153
|
897
|
Chris@153
|
898 void
|
Chris@193
|
899 SliceLayer::setPlotStyle(PlotStyle style)
|
Chris@153
|
900 {
|
Chris@193
|
901 if (m_plotStyle == style) return;
|
Chris@197
|
902 bool colourTypeChanged = (style == PlotFilledBlocks ||
|
Chris@197
|
903 m_plotStyle == PlotFilledBlocks);
|
Chris@193
|
904 m_plotStyle = style;
|
Chris@197
|
905 if (colourTypeChanged) {
|
Chris@197
|
906 emit layerParameterRangesChanged();
|
Chris@197
|
907 }
|
Chris@153
|
908 emit layerParametersChanged();
|
Chris@153
|
909 }
|
Chris@153
|
910
|
Chris@153
|
911 void
|
Chris@193
|
912 SliceLayer::setBinScale(BinScale scale)
|
Chris@153
|
913 {
|
Chris@193
|
914 if (m_binScale == scale) return;
|
Chris@193
|
915 m_binScale = scale;
|
Chris@153
|
916 emit layerParametersChanged();
|
Chris@153
|
917 }
|
Chris@153
|
918
|
Chris@153
|
919 void
|
Chris@193
|
920 SliceLayer::setNormalize(bool n)
|
Chris@153
|
921 {
|
Chris@153
|
922 if (m_normalize == n) return;
|
Chris@153
|
923 m_normalize = n;
|
Chris@153
|
924 emit layerParametersChanged();
|
Chris@153
|
925 }
|
Chris@153
|
926
|
Chris@153
|
927 void
|
Chris@284
|
928 SliceLayer::setThreshold(float thresh)
|
Chris@284
|
929 {
|
Chris@284
|
930 if (m_threshold == thresh) return;
|
Chris@284
|
931 m_threshold = thresh;
|
Chris@284
|
932 emit layerParametersChanged();
|
Chris@284
|
933 }
|
Chris@284
|
934
|
Chris@284
|
935 void
|
Chris@193
|
936 SliceLayer::setGain(float gain)
|
Chris@153
|
937 {
|
Chris@153
|
938 if (m_gain == gain) return;
|
Chris@153
|
939 m_gain = gain;
|
Chris@153
|
940 emit layerParametersChanged();
|
Chris@153
|
941 }
|
Chris@153
|
942
|
Chris@284
|
943 float
|
Chris@284
|
944 SliceLayer::getThresholdDb() const
|
Chris@284
|
945 {
|
Chris@284
|
946 if (m_threshold == 0.0) return -80.f;
|
Chris@906
|
947 float db = float(AudioLevel::multiplier_to_dB(m_threshold));
|
Chris@284
|
948 return db;
|
Chris@284
|
949 }
|
Chris@284
|
950
|
Chris@287
|
951 int
|
Chris@287
|
952 SliceLayer::getDefaultColourHint(bool darkbg, bool &impose)
|
Chris@287
|
953 {
|
Chris@287
|
954 impose = false;
|
Chris@287
|
955 return ColourDatabase::getInstance()->getColourIndex
|
Chris@287
|
956 (QString(darkbg ? "Bright Blue" : "Blue"));
|
Chris@287
|
957 }
|
Chris@287
|
958
|
Chris@316
|
959 void
|
Chris@316
|
960 SliceLayer::toXml(QTextStream &stream,
|
Chris@316
|
961 QString indent, QString extraAttributes) const
|
Chris@153
|
962 {
|
Chris@153
|
963 QString s;
|
Chris@153
|
964
|
Chris@1362
|
965 s += QString("energyScale=\"%1\" "
|
Chris@1362
|
966 "samplingMode=\"%2\" "
|
Chris@1362
|
967 "plotStyle=\"%3\" "
|
Chris@1362
|
968 "binScale=\"%4\" "
|
Chris@1362
|
969 "gain=\"%5\" "
|
Chris@1362
|
970 "threshold=\"%6\" "
|
Chris@1362
|
971 "normalize=\"%7\" %8 ")
|
Chris@1266
|
972 .arg(m_energyScale)
|
Chris@193
|
973 .arg(m_samplingMode)
|
Chris@598
|
974 .arg(m_plotStyle)
|
Chris@598
|
975 .arg(m_binScale)
|
Chris@153
|
976 .arg(m_gain)
|
Chris@598
|
977 .arg(m_threshold)
|
Chris@1238
|
978 .arg(m_normalize ? "true" : "false")
|
Chris@1238
|
979 .arg(QString("minbin=\"%1\" "
|
Chris@1238
|
980 "maxbin=\"%2\"")
|
Chris@1238
|
981 .arg(m_minbin)
|
Chris@1238
|
982 .arg(m_maxbin));
|
Chris@153
|
983
|
Chris@1362
|
984 // New-style colour map attribute, by string id rather than by
|
Chris@1362
|
985 // number
|
Chris@1362
|
986
|
Chris@1362
|
987 s += QString("fillColourMap=\"%1\" ")
|
Chris@1362
|
988 .arg(ColourMapper::getColourMapId(m_colourMap));
|
Chris@1362
|
989
|
Chris@1362
|
990 // Old-style colour map attribute
|
Chris@1362
|
991
|
Chris@1362
|
992 s += QString("colourScheme=\"%1\" ")
|
Chris@1362
|
993 .arg(ColourMapper::getBackwardCompatibilityColourMap(m_colourMap));
|
Chris@1362
|
994
|
Chris@316
|
995 SingleColourLayer::toXml(stream, indent, extraAttributes + " " + s);
|
Chris@153
|
996 }
|
Chris@153
|
997
|
Chris@153
|
998 void
|
Chris@193
|
999 SliceLayer::setProperties(const QXmlAttributes &attributes)
|
Chris@153
|
1000 {
|
Chris@153
|
1001 bool ok = false;
|
Chris@153
|
1002
|
Chris@287
|
1003 SingleColourLayer::setProperties(attributes);
|
Chris@153
|
1004
|
Chris@153
|
1005 EnergyScale scale = (EnergyScale)
|
Chris@1266
|
1006 attributes.value("energyScale").toInt(&ok);
|
Chris@153
|
1007 if (ok) setEnergyScale(scale);
|
Chris@153
|
1008
|
Chris@193
|
1009 SamplingMode mode = (SamplingMode)
|
Chris@1266
|
1010 attributes.value("samplingMode").toInt(&ok);
|
Chris@193
|
1011 if (ok) setSamplingMode(mode);
|
Chris@153
|
1012
|
Chris@1362
|
1013 QString colourMapId = attributes.value("fillColourMap");
|
Chris@1362
|
1014 int colourMap = ColourMapper::getColourMapById(colourMapId);
|
Chris@1362
|
1015 if (colourMap >= 0) {
|
Chris@1362
|
1016 setFillColourMap(colourMap);
|
Chris@1362
|
1017 } else {
|
Chris@1362
|
1018 colourMap = attributes.value("colourScheme").toInt(&ok);
|
Chris@1362
|
1019 if (ok && colourMap < ColourMapper::getColourMapCount()) {
|
Chris@1362
|
1020 setFillColourMap(colourMap);
|
Chris@1362
|
1021 }
|
Chris@1362
|
1022 }
|
Chris@197
|
1023
|
Chris@598
|
1024 PlotStyle s = (PlotStyle)
|
Chris@1266
|
1025 attributes.value("plotStyle").toInt(&ok);
|
Chris@598
|
1026 if (ok) setPlotStyle(s);
|
Chris@598
|
1027
|
Chris@598
|
1028 BinScale b = (BinScale)
|
Chris@1266
|
1029 attributes.value("binScale").toInt(&ok);
|
Chris@598
|
1030 if (ok) setBinScale(b);
|
Chris@598
|
1031
|
Chris@153
|
1032 float gain = attributes.value("gain").toFloat(&ok);
|
Chris@153
|
1033 if (ok) setGain(gain);
|
Chris@153
|
1034
|
Chris@598
|
1035 float threshold = attributes.value("threshold").toFloat(&ok);
|
Chris@598
|
1036 if (ok) setThreshold(threshold);
|
Chris@598
|
1037
|
Chris@153
|
1038 bool normalize = (attributes.value("normalize").trimmed() == "true");
|
Chris@153
|
1039 setNormalize(normalize);
|
Chris@1238
|
1040
|
Chris@1238
|
1041 bool alsoOk = false;
|
Chris@1238
|
1042
|
Chris@1238
|
1043 float min = attributes.value("minbin").toFloat(&ok);
|
Chris@1238
|
1044 float max = attributes.value("maxbin").toFloat(&alsoOk);
|
Chris@1238
|
1045 if (ok && alsoOk) setDisplayExtents(min, max);
|
Chris@133
|
1046 }
|
Chris@133
|
1047
|
Chris@133
|
1048 bool
|
Chris@1238
|
1049 SliceLayer::getValueExtents(double &min, double &max, bool &logarithmic,
|
Chris@1238
|
1050 QString &unit) const
|
Chris@133
|
1051 {
|
Chris@1238
|
1052 if (!m_sliceableModel) return false;
|
Chris@1238
|
1053
|
Chris@1238
|
1054 min = 0;
|
Chris@1238
|
1055 max = double(m_sliceableModel->getHeight());
|
Chris@1238
|
1056
|
Chris@1238
|
1057 logarithmic = (m_binScale == BinScale::LogBins);
|
Chris@1238
|
1058 unit = "";
|
Chris@1238
|
1059
|
Chris@1238
|
1060 return true;
|
Chris@133
|
1061 }
|
Chris@133
|
1062
|
Chris@1238
|
1063 bool
|
Chris@1238
|
1064 SliceLayer::getDisplayExtents(double &min, double &max) const
|
Chris@1238
|
1065 {
|
Chris@1238
|
1066 if (!m_sliceableModel) return false;
|
Chris@1238
|
1067
|
Chris@1238
|
1068 double hmax = double(m_sliceableModel->getHeight());
|
Chris@1238
|
1069
|
Chris@1238
|
1070 min = m_minbin;
|
Chris@1238
|
1071 max = m_maxbin;
|
Chris@1238
|
1072 if (max <= min) {
|
Chris@1238
|
1073 min = 0;
|
Chris@1238
|
1074 max = hmax;
|
Chris@1238
|
1075 }
|
Chris@1238
|
1076 if (min < 0) min = 0;
|
Chris@1238
|
1077 if (max > hmax) max = hmax;
|
Chris@1238
|
1078
|
Chris@1238
|
1079 return true;
|
Chris@1238
|
1080 }
|
Chris@1238
|
1081
|
Chris@1238
|
1082 bool
|
Chris@1238
|
1083 SliceLayer::setDisplayExtents(double min, double max)
|
Chris@1238
|
1084 {
|
Chris@1238
|
1085 if (!m_sliceableModel) return false;
|
Chris@1238
|
1086
|
Chris@1238
|
1087 m_minbin = int(lrint(min));
|
Chris@1238
|
1088 m_maxbin = int(lrint(max));
|
Chris@1238
|
1089
|
Chris@1238
|
1090 emit layerParametersChanged();
|
Chris@1238
|
1091 return true;
|
Chris@1238
|
1092 }
|
Chris@1238
|
1093
|
Chris@1238
|
1094 int
|
Chris@1238
|
1095 SliceLayer::getVerticalZoomSteps(int &defaultStep) const
|
Chris@1238
|
1096 {
|
Chris@1238
|
1097 if (!m_sliceableModel) return 0;
|
Chris@1238
|
1098
|
Chris@1238
|
1099 defaultStep = 0;
|
Chris@1238
|
1100 int h = m_sliceableModel->getHeight();
|
Chris@1238
|
1101 return h;
|
Chris@1238
|
1102 }
|
Chris@1238
|
1103
|
Chris@1238
|
1104 int
|
Chris@1238
|
1105 SliceLayer::getCurrentVerticalZoomStep() const
|
Chris@1238
|
1106 {
|
Chris@1238
|
1107 if (!m_sliceableModel) return 0;
|
Chris@1238
|
1108
|
Chris@1238
|
1109 double min, max;
|
Chris@1238
|
1110 getDisplayExtents(min, max);
|
Chris@1238
|
1111 return m_sliceableModel->getHeight() - int(lrint(max - min));
|
Chris@1238
|
1112 }
|
Chris@1238
|
1113
|
Chris@1238
|
1114 void
|
Chris@1238
|
1115 SliceLayer::setVerticalZoomStep(int step)
|
Chris@1238
|
1116 {
|
Chris@1238
|
1117 if (!m_sliceableModel) return;
|
Chris@1238
|
1118
|
Chris@1238
|
1119 // SVDEBUG << "SliceLayer::setVerticalZoomStep(" <<step <<"): before: minbin = " << m_minbin << ", maxbin = " << m_maxbin << endl;
|
Chris@1238
|
1120
|
Chris@1238
|
1121 int dist = m_sliceableModel->getHeight() - step;
|
Chris@1238
|
1122 if (dist < 1) dist = 1;
|
Chris@1238
|
1123 double centre = m_minbin + (m_maxbin - m_minbin) / 2.0;
|
Chris@1238
|
1124 m_minbin = int(lrint(centre - dist/2.0));
|
Chris@1238
|
1125 if (m_minbin < 0) m_minbin = 0;
|
Chris@1238
|
1126 m_maxbin = m_minbin + dist;
|
Chris@1238
|
1127 if (m_maxbin > m_sliceableModel->getHeight()) m_maxbin = m_sliceableModel->getHeight();
|
Chris@1238
|
1128
|
Chris@1238
|
1129 // SVDEBUG << "SliceLayer::setVerticalZoomStep(" <<step <<"): after: minbin = " << m_minbin << ", maxbin = " << m_maxbin << endl;
|
Chris@1238
|
1130
|
Chris@1238
|
1131 emit layerParametersChanged();
|
Chris@1238
|
1132 }
|
Chris@1238
|
1133
|
Chris@1238
|
1134 RangeMapper *
|
Chris@1238
|
1135 SliceLayer::getNewVerticalZoomRangeMapper() const
|
Chris@1238
|
1136 {
|
Chris@1238
|
1137 if (!m_sliceableModel) return 0;
|
Chris@1238
|
1138
|
Chris@1238
|
1139 return new LinearRangeMapper(0, m_sliceableModel->getHeight(),
|
Chris@1238
|
1140 0, m_sliceableModel->getHeight(), "");
|
Chris@1238
|
1141 }
|