comparison layer/SpectrumLayer.cpp @ 997:296ccd36f626 tony-2.0-integration

Merge through to branch for Tony 2.0
author Chris Cannam
date Thu, 20 Aug 2015 14:54:21 +0100
parents 64c2b3a4435a
children ee01a4062747
comparison
equal deleted inserted replaced
943:788b7623bfca 997:296ccd36f626
110 FFTModel *newFFT = new FFTModel(m_originModel, 110 FFTModel *newFFT = new FFTModel(m_originModel,
111 m_channel, 111 m_channel,
112 m_windowType, 112 m_windowType,
113 m_windowSize, 113 m_windowSize,
114 getWindowIncrement(), 114 getWindowIncrement(),
115 m_windowSize, 115 m_windowSize);
116 false,
117 StorageAdviser::Criteria
118 (StorageAdviser::SpeedCritical |
119 StorageAdviser::FrequentLookupLikely));
120 116
121 setSliceableModel(newFFT); 117 setSliceableModel(newFFT);
122 118
123 m_biasCurve.clear(); 119 m_biasCurve.clear();
124 for (int i = 0; i < m_windowSize; ++i) { 120 for (int i = 0; i < m_windowSize; ++i) {
125 m_biasCurve.push_back(1.f / (float(m_windowSize)/2.f)); 121 m_biasCurve.push_back(1.f / (float(m_windowSize)/2.f));
126 } 122 }
127
128 newFFT->resume();
129 123
130 m_newFFTNeeded = false; 124 m_newFFTNeeded = false;
131 } 125 }
132 126
133 Layer::PropertyList 127 Layer::PropertyList
384 378
385 return x; 379 return x;
386 } 380 }
387 381
388 bool 382 bool
389 SpectrumLayer::getXScaleValue(const View *v, int x, 383 SpectrumLayer::getXScaleValue(const LayerGeometryProvider *v, int x,
390 double &value, QString &unit) const 384 double &value, QString &unit) const
391 { 385 {
392 if (m_xorigins.find(v) == m_xorigins.end()) return false; 386 if (m_xorigins.find(v) == m_xorigins.end()) return false;
393 int xorigin = m_xorigins.find(v)->second; 387 int xorigin = m_xorigins.find(v)->second;
394 value = getFrequencyForX(x - xorigin, v->width() - xorigin - 1); 388 value = getFrequencyForX(x - xorigin, v->getPaintWidth() - xorigin - 1);
395 unit = "Hz"; 389 unit = "Hz";
396 return true; 390 return true;
397 } 391 }
398 392
399 bool 393 bool
400 SpectrumLayer::getYScaleValue(const View *v, int y, 394 SpectrumLayer::getYScaleValue(const LayerGeometryProvider *v, int y,
401 double &value, QString &unit) const 395 double &value, QString &unit) const
402 { 396 {
403 value = getValueForY(y, v); 397 value = getValueForY(y, v);
404 398
405 if (m_energyScale == dBScale || m_energyScale == MeterScale) { 399 if (m_energyScale == dBScale || m_energyScale == MeterScale) {
417 411
418 return true; 412 return true;
419 } 413 }
420 414
421 bool 415 bool
422 SpectrumLayer::getYScaleDifference(const View *v, int y0, int y1, 416 SpectrumLayer::getYScaleDifference(const LayerGeometryProvider *v, int y0, int y1,
423 double &diff, QString &unit) const 417 double &diff, QString &unit) const
424 { 418 {
425 bool rv = SliceLayer::getYScaleDifference(v, y0, y1, diff, unit); 419 bool rv = SliceLayer::getYScaleDifference(v, y0, y1, diff, unit);
426 if (rv && (unit == "dBV")) unit = "dB"; 420 if (rv && (unit == "dBV")) unit = "dB";
427 return rv; 421 return rv;
428 } 422 }
429 423
430 424
431 bool 425 bool
432 SpectrumLayer::getCrosshairExtents(View *v, QPainter &paint, 426 SpectrumLayer::getCrosshairExtents(LayerGeometryProvider *v, QPainter &paint,
433 QPoint cursorPos, 427 QPoint cursorPos,
434 std::vector<QRect> &extents) const 428 std::vector<QRect> &extents) const
435 { 429 {
436 QRect vertical(cursorPos.x(), cursorPos.y(), 1, v->height() - cursorPos.y()); 430 QRect vertical(cursorPos.x(), cursorPos.y(), 1, v->getPaintHeight() - cursorPos.y());
437 extents.push_back(vertical); 431 extents.push_back(vertical);
438 432
439 QRect horizontal(0, cursorPos.y(), v->width(), 12); 433 QRect horizontal(0, cursorPos.y(), v->getPaintWidth(), 12);
440 extents.push_back(horizontal); 434 extents.push_back(horizontal);
441 435
442 int hoffset = 2; 436 int hoffset = 2;
443 if (m_binScale == LogBins) hoffset = 13; 437 if (m_binScale == LogBins) hoffset = 13;
444 438
453 paint.fontMetrics().width("-80.000 dBV") + 2, 447 paint.fontMetrics().width("-80.000 dBV") + 2,
454 paint.fontMetrics().height()); 448 paint.fontMetrics().height());
455 extents.push_back(log); 449 extents.push_back(log);
456 450
457 QRect freq(cursorPos.x(), 451 QRect freq(cursorPos.x(),
458 v->height() - paint.fontMetrics().height() - hoffset, 452 v->getPaintHeight() - paint.fontMetrics().height() - hoffset,
459 paint.fontMetrics().width("123456 Hz") + 2, 453 paint.fontMetrics().width("123456 Hz") + 2,
460 paint.fontMetrics().height()); 454 paint.fontMetrics().height());
461 extents.push_back(freq); 455 extents.push_back(freq);
462 456
463 int w(paint.fontMetrics().width("C#10+50c") + 2); 457 int w(paint.fontMetrics().width("C#10+50c") + 2);
464 QRect pitch(cursorPos.x() - w, 458 QRect pitch(cursorPos.x() - w,
465 v->height() - paint.fontMetrics().height() - hoffset, 459 v->getPaintHeight() - paint.fontMetrics().height() - hoffset,
466 w, 460 w,
467 paint.fontMetrics().height()); 461 paint.fontMetrics().height());
468 extents.push_back(pitch); 462 extents.push_back(pitch);
469 463
470 return true; 464 return true;
471 } 465 }
472 466
473 void 467 void
474 SpectrumLayer::paintCrosshairs(View *v, QPainter &paint, 468 SpectrumLayer::paintCrosshairs(LayerGeometryProvider *v, QPainter &paint,
475 QPoint cursorPos) const 469 QPoint cursorPos) const
476 { 470 {
477 if (!m_sliceableModel) return; 471 if (!m_sliceableModel) return;
478 472
479 paint.save(); 473 paint.save();
485 479
486 ColourMapper mapper(m_colourMap, 0, 1); 480 ColourMapper mapper(m_colourMap, 0, 1);
487 paint.setPen(mapper.getContrastingColour()); 481 paint.setPen(mapper.getContrastingColour());
488 482
489 int xorigin = m_xorigins[v]; 483 int xorigin = m_xorigins[v];
490 int w = v->width() - xorigin - 1; 484 int w = v->getPaintWidth() - xorigin - 1;
491 485
492 paint.drawLine(xorigin, cursorPos.y(), v->width(), cursorPos.y()); 486 paint.drawLine(xorigin, cursorPos.y(), v->getPaintWidth(), cursorPos.y());
493 paint.drawLine(cursorPos.x(), cursorPos.y(), cursorPos.x(), v->height()); 487 paint.drawLine(cursorPos.x(), cursorPos.y(), cursorPos.x(), v->getPaintHeight());
494 488
495 double fundamental = getFrequencyForX(cursorPos.x() - xorigin, w); 489 double fundamental = getFrequencyForX(cursorPos.x() - xorigin, w);
496 490
497 int hoffset = 2; 491 int hoffset = 2;
498 if (m_binScale == LogBins) hoffset = 13; 492 if (m_binScale == LogBins) hoffset = 13;
499 493
500 v->drawVisibleText(paint, 494 v->drawVisibleText(paint,
501 cursorPos.x() + 2, 495 cursorPos.x() + 2,
502 v->height() - 2 - hoffset, 496 v->getPaintHeight() - 2 - hoffset,
503 QString("%1 Hz").arg(fundamental), 497 QString("%1 Hz").arg(fundamental),
504 View::OutlinedText); 498 View::OutlinedText);
505 499
506 if (Pitch::isFrequencyInMidiRange(fundamental)) { 500 if (Pitch::isFrequencyInMidiRange(fundamental)) {
507 QString pitchLabel = Pitch::getPitchLabelForFrequency(fundamental); 501 QString pitchLabel = Pitch::getPitchLabelForFrequency(fundamental);
508 v->drawVisibleText(paint, 502 v->drawVisibleText(paint,
509 cursorPos.x() - paint.fontMetrics().width(pitchLabel) - 2, 503 cursorPos.x() - paint.fontMetrics().width(pitchLabel) - 2,
510 v->height() - 2 - hoffset, 504 v->getPaintHeight() - 2 - hoffset,
511 pitchLabel, 505 pitchLabel,
512 View::OutlinedText); 506 View::OutlinedText);
513 } 507 }
514 508
515 double value = getValueForY(cursorPos.y(), v); 509 double value = getValueForY(cursorPos.y(), v);
535 while (harmonic < 100) { 529 while (harmonic < 100) {
536 530
537 int hx = int(lrint(getXForFrequency(fundamental * harmonic, w))); 531 int hx = int(lrint(getXForFrequency(fundamental * harmonic, w)));
538 hx += xorigin; 532 hx += xorigin;
539 533
540 if (hx < xorigin || hx > v->width()) break; 534 if (hx < xorigin || hx > v->getPaintWidth()) break;
541 535
542 int len = 7; 536 int len = 7;
543 537
544 if (harmonic % 2 == 0) { 538 if (harmonic % 2 == 0) {
545 if (harmonic % 4 == 0) { 539 if (harmonic % 4 == 0) {
559 553
560 paint.restore(); 554 paint.restore();
561 } 555 }
562 556
563 QString 557 QString
564 SpectrumLayer::getFeatureDescription(View *v, QPoint &p) const 558 SpectrumLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &p) const
565 { 559 {
566 if (!m_sliceableModel) return ""; 560 if (!m_sliceableModel) return "";
567 561
568 int minbin = 0, maxbin = 0, range = 0; 562 int minbin = 0, maxbin = 0, range = 0;
569 QString genericDesc = SliceLayer::getFeatureDescriptionAux 563 QString genericDesc = SliceLayer::getFeatureDescriptionAux
648 642
649 return description; 643 return description;
650 } 644 }
651 645
652 void 646 void
653 SpectrumLayer::paint(View *v, QPainter &paint, QRect rect) const 647 SpectrumLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
654 { 648 {
655 if (!m_originModel || !m_originModel->isOK() || 649 if (!m_originModel || !m_originModel->isOK() ||
656 !m_originModel->isReady()) { 650 !m_originModel->isReady()) {
657 SVDEBUG << "SpectrumLayer::paint: no origin model, or origin model not OK or not ready" << endl; 651 SVDEBUG << "SpectrumLayer::paint: no origin model, or origin model not OK or not ready" << endl;
658 return; 652 return;
667 (const_cast<DenseThreeDimensionalModel *>(m_sliceableModel)); 661 (const_cast<DenseThreeDimensionalModel *>(m_sliceableModel));
668 662
669 double thresh = (pow(10, -6) / m_gain) * (m_windowSize / 2.0); // -60dB adj 663 double thresh = (pow(10, -6) / m_gain) * (m_windowSize / 2.0); // -60dB adj
670 664
671 int xorigin = getVerticalScaleWidth(v, false, paint) + 1; 665 int xorigin = getVerticalScaleWidth(v, false, paint) + 1;
672 int w = v->width() - xorigin - 1; 666 int w = v->getPaintWidth() - xorigin - 1;
673 667
674 int pkh = 0; 668 int pkh = 0;
675 //!!! if (m_binScale == LogBins) { 669 //!!! if (m_binScale == LogBins) {
676 pkh = 10; 670 pkh = 10;
677 //!!! } 671 //!!! }
727 721
728 double norm = 0.f; 722 double norm = 0.f;
729 (void)getYForValue(values[bin], v, norm); // don't need return value, need norm 723 (void)getYForValue(values[bin], v, norm); // don't need return value, need norm
730 724
731 paint.setPen(mapper.map(norm)); 725 paint.setPen(mapper.map(norm));
732 paint.drawLine(xorigin + x, 0, xorigin + x, v->height() - pkh - 1); 726 paint.drawLine(xorigin + x, 0, xorigin + x, v->getPaintHeight() - pkh - 1);
733 } 727 }
734 728
735 paint.restore(); 729 paint.restore();
736 } 730 }
737 731
747 //proposition. 741 //proposition.
748 742
749 // if (m_binScale == LogBins) { 743 // if (m_binScale == LogBins) {
750 744
751 // int pkh = 10; 745 // int pkh = 10;
752 int h = v->height(); 746 int h = v->getPaintHeight();
753 747
754 // piano keyboard 748 // piano keyboard
755 //!!! should be in a new paintHorizontalScale()? 749 //!!! should be in a new paintHorizontalScale()?
756 // nice to have a piano keyboard class, of course 750 // nice to have a piano keyboard class, of course
757 751