comparison layer/SliceLayer.cpp @ 811:c4ef666721bf

Merge from branch warnfix_no_size_t
author Chris Cannam
date Wed, 18 Jun 2014 13:51:27 +0100
parents 1d526ba11a24
children 312b92ffb04e
comparison
equal deleted inserted replaced
782:ddae586bc47b 811:c4ef666721bf
93 93
94 QString 94 QString
95 SliceLayer::getFeatureDescription(View *v, QPoint &p) const 95 SliceLayer::getFeatureDescription(View *v, QPoint &p) const
96 { 96 {
97 int minbin, maxbin, range; 97 int minbin, maxbin, range;
98 return getFeatureDescription(v, p, true, minbin, maxbin, range); 98 return getFeatureDescriptionAux(v, p, true, minbin, maxbin, range);
99 } 99 }
100 100
101 QString 101 QString
102 SliceLayer::getFeatureDescription(View *v, QPoint &p, 102 SliceLayer::getFeatureDescriptionAux(View *v, QPoint &p,
103 bool includeBinDescription, 103 bool includeBinDescription,
104 int &minbin, int &maxbin, int &range) const 104 int &minbin, int &maxbin, int &range) const
105 { 105 {
106 minbin = 0; 106 minbin = 0;
107 maxbin = 0; 107 maxbin = 0;
108 if (!m_sliceableModel) return ""; 108 if (!m_sliceableModel) return "";
109 109
119 if (minbin < 0) minbin = 0; 119 if (minbin < 0) minbin = 0;
120 if (maxbin < 0) maxbin = 0; 120 if (maxbin < 0) maxbin = 0;
121 121
122 int sampleRate = m_sliceableModel->getSampleRate(); 122 int sampleRate = m_sliceableModel->getSampleRate();
123 123
124 size_t f0 = m_currentf0; 124 int f0 = m_currentf0;
125 size_t f1 = m_currentf1; 125 int f1 = m_currentf1;
126 126
127 RealTime rt0 = RealTime::frame2RealTime(f0, sampleRate); 127 RealTime rt0 = RealTime::frame2RealTime(f0, sampleRate);
128 RealTime rt1 = RealTime::frame2RealTime(f1, sampleRate); 128 RealTime rt1 = RealTime::frame2RealTime(f1, sampleRate);
129 129
130 range = f1 - f0 + 1; 130 range = f1 - f0 + 1;
262 262
263 case AbsoluteScale: 263 case AbsoluteScale:
264 value = fabsf(value); 264 value = fabsf(value);
265 // and fall through 265 // and fall through
266 266
267 case LinearScale:
267 default: 268 default:
268 norm = (value - m_threshold); 269 norm = (value - m_threshold);
269 if (norm < 0) norm = 0; 270 if (norm < 0) norm = 0;
270 y = yorigin - (float(h) * norm); 271 y = yorigin - (float(h) * norm);
271 break; 272 break;
299 } 300 }
300 301
301 case MeterScale: 302 case MeterScale:
302 value = AudioLevel::preview_to_multiplier(lrintf(y), h); 303 value = AudioLevel::preview_to_multiplier(lrintf(y), h);
303 break; 304 break;
304 305
306 case LinearScale:
307 case AbsoluteScale:
305 default: 308 default:
306 value = y / h + m_threshold; 309 value = y / h + m_threshold;
307 } 310 }
308 311
309 return value / m_gain; 312 return value / m_gain;
320 paint.setBrush(Qt::NoBrush); 323 paint.setBrush(Qt::NoBrush);
321 324
322 if (v->getViewManager() && v->getViewManager()->shouldShowScaleGuides()) { 325 if (v->getViewManager() && v->getViewManager()->shouldShowScaleGuides()) {
323 if (!m_scalePoints.empty()) { 326 if (!m_scalePoints.empty()) {
324 paint.setPen(QColor(240, 240, 240)); //!!! and dark background? 327 paint.setPen(QColor(240, 240, 240)); //!!! and dark background?
325 for (size_t i = 0; i < m_scalePoints.size(); ++i) { 328 for (int i = 0; i < (int)m_scalePoints.size(); ++i) {
326 paint.drawLine(0, m_scalePoints[i], rect.width(), m_scalePoints[i]); 329 paint.drawLine(0, m_scalePoints[i], rect.width(), m_scalePoints[i]);
327 } 330 }
328 } 331 }
329 } 332 }
330 333
343 346
344 if (h <= 0) return; 347 if (h <= 0) return;
345 348
346 QPainterPath path; 349 QPainterPath path;
347 350
348 size_t mh = m_sliceableModel->getHeight(); 351 int mh = m_sliceableModel->getHeight();
349 352
350 int divisor = 0; 353 int divisor = 0;
351 354
352 m_values.clear(); 355 m_values.clear();
353 for (size_t bin = 0; bin < mh; ++bin) { 356 for (int bin = 0; bin < mh; ++bin) {
354 m_values.push_back(0.f); 357 m_values.push_back(0.f);
355 } 358 }
356 359
357 size_t f0 = v->getCentreFrame(); 360 int f0 = v->getCentreFrame();
358 int f0x = v->getXForFrame(f0); 361 int f0x = v->getXForFrame(f0);
359 f0 = v->getFrameForX(f0x); 362 f0 = v->getFrameForX(f0x);
360 size_t f1 = v->getFrameForX(f0x + 1); 363 int f1 = v->getFrameForX(f0x + 1);
361 if (f1 > f0) --f1; 364 if (f1 > f0) --f1;
362 365
363 // cerr << "centre frame " << v->getCentreFrame() << ", x " << f0x << ", f0 " << f0 << ", f1 " << f1 << endl; 366 // cerr << "centre frame " << v->getCentreFrame() << ", x " << f0x << ", f0 " << f0 << ", f1 " << f1 << endl;
364 367
365 size_t res = m_sliceableModel->getResolution(); 368 int res = m_sliceableModel->getResolution();
366 size_t col0 = f0 / res; 369 int col0 = f0 / res;
367 size_t col1 = col0; 370 int col1 = col0;
368 if (m_samplingMode != NearestSample) col1 = f1 / res; 371 if (m_samplingMode != NearestSample) col1 = f1 / res;
369 f0 = col0 * res; 372 f0 = col0 * res;
370 f1 = (col1 + 1) * res - 1; 373 f1 = (col1 + 1) * res - 1;
371 374
372 // cerr << "resolution " << res << ", col0 " << col0 << ", col1 " << col1 << ", f0 " << f0 << ", f1 " << f1 << endl; 375 // cerr << "resolution " << res << ", col0 " << col0 << ", col1 " << col1 << ", f0 " << f0 << ", f1 " << f1 << endl;
374 m_currentf0 = f0; 377 m_currentf0 = f0;
375 m_currentf1 = f1; 378 m_currentf1 = f1;
376 379
377 BiasCurve curve; 380 BiasCurve curve;
378 getBiasCurve(curve); 381 getBiasCurve(curve);
379 size_t cs = curve.size(); 382 int cs = curve.size();
380 383
381 for (size_t col = col0; col <= col1; ++col) { 384 for (int col = col0; col <= col1; ++col) {
382 for (size_t bin = 0; bin < mh; ++bin) { 385 for (int bin = 0; bin < mh; ++bin) {
383 float value = m_sliceableModel->getValueAt(col, bin); 386 float value = m_sliceableModel->getValueAt(col, bin);
384 if (bin < cs) value *= curve[bin]; 387 if (bin < cs) value *= curve[bin];
385 if (m_samplingMode == SamplePeak) { 388 if (m_samplingMode == SamplePeak) {
386 if (value > m_values[bin]) m_values[bin] = value; 389 if (value > m_values[bin]) m_values[bin] = value;
387 } else { 390 } else {
390 } 393 }
391 ++divisor; 394 ++divisor;
392 } 395 }
393 396
394 float max = 0.f; 397 float max = 0.f;
395 for (size_t bin = 0; bin < mh; ++bin) { 398 for (int bin = 0; bin < mh; ++bin) {
396 if (m_samplingMode == SampleMean) m_values[bin] /= divisor; 399 if (m_samplingMode == SampleMean) m_values[bin] /= divisor;
397 if (m_values[bin] > max) max = m_values[bin]; 400 if (m_values[bin] > max) max = m_values[bin];
398 } 401 }
399 if (max != 0.f && m_normalize) { 402 if (max != 0.f && m_normalize) {
400 for (size_t bin = 0; bin < mh; ++bin) { 403 for (int bin = 0; bin < mh; ++bin) {
401 m_values[bin] /= max; 404 m_values[bin] /= max;
402 } 405 }
403 } 406 }
404 407
405 float py = 0;
406 float nx = xorigin; 408 float nx = xorigin;
407 409
408 ColourMapper mapper(m_colourMap, 0, 1); 410 ColourMapper mapper(m_colourMap, 0, 1);
409 411
410 for (size_t bin = 0; bin < mh; ++bin) { 412 for (int bin = 0; bin < mh; ++bin) {
411 413
412 float x = nx; 414 float x = nx;
413 nx = xorigin + getXForBin(bin + 1, mh, w); 415 nx = xorigin + getXForBin(bin + 1, mh, w);
414 416
415 float value = m_values[bin]; 417 float value = m_values[bin];
444 } else if (m_plotStyle == PlotFilledBlocks) { 446 } else if (m_plotStyle == PlotFilledBlocks) {
445 447
446 paint.fillRect(QRectF(x, y, nx - x, yorigin - y), mapper.map(norm)); 448 paint.fillRect(QRectF(x, y, nx - x, yorigin - y), mapper.map(norm));
447 } 449 }
448 450
449 py = y;
450 } 451 }
451 452
452 if (m_plotStyle != PlotFilledBlocks) { 453 if (m_plotStyle != PlotFilledBlocks) {
453 paint.drawPath(path); 454 paint.drawPath(path);
454 } 455 }