comparison layer/SpectrumLayer.cpp @ 978:64c2b3a4435a 3.0-integration

Merge from branch osx-retina
author Chris Cannam
date Fri, 26 Jun 2015 14:10:40 +0100
parents b8187c83b93a 4fe7a09be0fe
children ee01a4062747
comparison
equal deleted inserted replaced
977:f40ccbf228c2 978:64c2b3a4435a
378 378
379 return x; 379 return x;
380 } 380 }
381 381
382 bool 382 bool
383 SpectrumLayer::getXScaleValue(const View *v, int x, 383 SpectrumLayer::getXScaleValue(const LayerGeometryProvider *v, int x,
384 double &value, QString &unit) const 384 double &value, QString &unit) const
385 { 385 {
386 if (m_xorigins.find(v) == m_xorigins.end()) return false; 386 if (m_xorigins.find(v) == m_xorigins.end()) return false;
387 int xorigin = m_xorigins.find(v)->second; 387 int xorigin = m_xorigins.find(v)->second;
388 value = getFrequencyForX(x - xorigin, v->width() - xorigin - 1); 388 value = getFrequencyForX(x - xorigin, v->getPaintWidth() - xorigin - 1);
389 unit = "Hz"; 389 unit = "Hz";
390 return true; 390 return true;
391 } 391 }
392 392
393 bool 393 bool
394 SpectrumLayer::getYScaleValue(const View *v, int y, 394 SpectrumLayer::getYScaleValue(const LayerGeometryProvider *v, int y,
395 double &value, QString &unit) const 395 double &value, QString &unit) const
396 { 396 {
397 value = getValueForY(y, v); 397 value = getValueForY(y, v);
398 398
399 if (m_energyScale == dBScale || m_energyScale == MeterScale) { 399 if (m_energyScale == dBScale || m_energyScale == MeterScale) {
411 411
412 return true; 412 return true;
413 } 413 }
414 414
415 bool 415 bool
416 SpectrumLayer::getYScaleDifference(const View *v, int y0, int y1, 416 SpectrumLayer::getYScaleDifference(const LayerGeometryProvider *v, int y0, int y1,
417 double &diff, QString &unit) const 417 double &diff, QString &unit) const
418 { 418 {
419 bool rv = SliceLayer::getYScaleDifference(v, y0, y1, diff, unit); 419 bool rv = SliceLayer::getYScaleDifference(v, y0, y1, diff, unit);
420 if (rv && (unit == "dBV")) unit = "dB"; 420 if (rv && (unit == "dBV")) unit = "dB";
421 return rv; 421 return rv;
422 } 422 }
423 423
424 424
425 bool 425 bool
426 SpectrumLayer::getCrosshairExtents(View *v, QPainter &paint, 426 SpectrumLayer::getCrosshairExtents(LayerGeometryProvider *v, QPainter &paint,
427 QPoint cursorPos, 427 QPoint cursorPos,
428 std::vector<QRect> &extents) const 428 std::vector<QRect> &extents) const
429 { 429 {
430 QRect vertical(cursorPos.x(), cursorPos.y(), 1, v->height() - cursorPos.y()); 430 QRect vertical(cursorPos.x(), cursorPos.y(), 1, v->getPaintHeight() - cursorPos.y());
431 extents.push_back(vertical); 431 extents.push_back(vertical);
432 432
433 QRect horizontal(0, cursorPos.y(), v->width(), 12); 433 QRect horizontal(0, cursorPos.y(), v->getPaintWidth(), 12);
434 extents.push_back(horizontal); 434 extents.push_back(horizontal);
435 435
436 int hoffset = 2; 436 int hoffset = 2;
437 if (m_binScale == LogBins) hoffset = 13; 437 if (m_binScale == LogBins) hoffset = 13;
438 438
447 paint.fontMetrics().width("-80.000 dBV") + 2, 447 paint.fontMetrics().width("-80.000 dBV") + 2,
448 paint.fontMetrics().height()); 448 paint.fontMetrics().height());
449 extents.push_back(log); 449 extents.push_back(log);
450 450
451 QRect freq(cursorPos.x(), 451 QRect freq(cursorPos.x(),
452 v->height() - paint.fontMetrics().height() - hoffset, 452 v->getPaintHeight() - paint.fontMetrics().height() - hoffset,
453 paint.fontMetrics().width("123456 Hz") + 2, 453 paint.fontMetrics().width("123456 Hz") + 2,
454 paint.fontMetrics().height()); 454 paint.fontMetrics().height());
455 extents.push_back(freq); 455 extents.push_back(freq);
456 456
457 int w(paint.fontMetrics().width("C#10+50c") + 2); 457 int w(paint.fontMetrics().width("C#10+50c") + 2);
458 QRect pitch(cursorPos.x() - w, 458 QRect pitch(cursorPos.x() - w,
459 v->height() - paint.fontMetrics().height() - hoffset, 459 v->getPaintHeight() - paint.fontMetrics().height() - hoffset,
460 w, 460 w,
461 paint.fontMetrics().height()); 461 paint.fontMetrics().height());
462 extents.push_back(pitch); 462 extents.push_back(pitch);
463 463
464 return true; 464 return true;
465 } 465 }
466 466
467 void 467 void
468 SpectrumLayer::paintCrosshairs(View *v, QPainter &paint, 468 SpectrumLayer::paintCrosshairs(LayerGeometryProvider *v, QPainter &paint,
469 QPoint cursorPos) const 469 QPoint cursorPos) const
470 { 470 {
471 if (!m_sliceableModel) return; 471 if (!m_sliceableModel) return;
472 472
473 paint.save(); 473 paint.save();
479 479
480 ColourMapper mapper(m_colourMap, 0, 1); 480 ColourMapper mapper(m_colourMap, 0, 1);
481 paint.setPen(mapper.getContrastingColour()); 481 paint.setPen(mapper.getContrastingColour());
482 482
483 int xorigin = m_xorigins[v]; 483 int xorigin = m_xorigins[v];
484 int w = v->width() - xorigin - 1; 484 int w = v->getPaintWidth() - xorigin - 1;
485 485
486 paint.drawLine(xorigin, cursorPos.y(), v->width(), cursorPos.y()); 486 paint.drawLine(xorigin, cursorPos.y(), v->getPaintWidth(), cursorPos.y());
487 paint.drawLine(cursorPos.x(), cursorPos.y(), cursorPos.x(), v->height()); 487 paint.drawLine(cursorPos.x(), cursorPos.y(), cursorPos.x(), v->getPaintHeight());
488 488
489 double fundamental = getFrequencyForX(cursorPos.x() - xorigin, w); 489 double fundamental = getFrequencyForX(cursorPos.x() - xorigin, w);
490 490
491 int hoffset = 2; 491 int hoffset = 2;
492 if (m_binScale == LogBins) hoffset = 13; 492 if (m_binScale == LogBins) hoffset = 13;
493 493
494 v->drawVisibleText(paint, 494 v->drawVisibleText(paint,
495 cursorPos.x() + 2, 495 cursorPos.x() + 2,
496 v->height() - 2 - hoffset, 496 v->getPaintHeight() - 2 - hoffset,
497 QString("%1 Hz").arg(fundamental), 497 QString("%1 Hz").arg(fundamental),
498 View::OutlinedText); 498 View::OutlinedText);
499 499
500 if (Pitch::isFrequencyInMidiRange(fundamental)) { 500 if (Pitch::isFrequencyInMidiRange(fundamental)) {
501 QString pitchLabel = Pitch::getPitchLabelForFrequency(fundamental); 501 QString pitchLabel = Pitch::getPitchLabelForFrequency(fundamental);
502 v->drawVisibleText(paint, 502 v->drawVisibleText(paint,
503 cursorPos.x() - paint.fontMetrics().width(pitchLabel) - 2, 503 cursorPos.x() - paint.fontMetrics().width(pitchLabel) - 2,
504 v->height() - 2 - hoffset, 504 v->getPaintHeight() - 2 - hoffset,
505 pitchLabel, 505 pitchLabel,
506 View::OutlinedText); 506 View::OutlinedText);
507 } 507 }
508 508
509 double value = getValueForY(cursorPos.y(), v); 509 double value = getValueForY(cursorPos.y(), v);
529 while (harmonic < 100) { 529 while (harmonic < 100) {
530 530
531 int hx = int(lrint(getXForFrequency(fundamental * harmonic, w))); 531 int hx = int(lrint(getXForFrequency(fundamental * harmonic, w)));
532 hx += xorigin; 532 hx += xorigin;
533 533
534 if (hx < xorigin || hx > v->width()) break; 534 if (hx < xorigin || hx > v->getPaintWidth()) break;
535 535
536 int len = 7; 536 int len = 7;
537 537
538 if (harmonic % 2 == 0) { 538 if (harmonic % 2 == 0) {
539 if (harmonic % 4 == 0) { 539 if (harmonic % 4 == 0) {
553 553
554 paint.restore(); 554 paint.restore();
555 } 555 }
556 556
557 QString 557 QString
558 SpectrumLayer::getFeatureDescription(View *v, QPoint &p) const 558 SpectrumLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &p) const
559 { 559 {
560 if (!m_sliceableModel) return ""; 560 if (!m_sliceableModel) return "";
561 561
562 int minbin = 0, maxbin = 0, range = 0; 562 int minbin = 0, maxbin = 0, range = 0;
563 QString genericDesc = SliceLayer::getFeatureDescriptionAux 563 QString genericDesc = SliceLayer::getFeatureDescriptionAux
642 642
643 return description; 643 return description;
644 } 644 }
645 645
646 void 646 void
647 SpectrumLayer::paint(View *v, QPainter &paint, QRect rect) const 647 SpectrumLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
648 { 648 {
649 if (!m_originModel || !m_originModel->isOK() || 649 if (!m_originModel || !m_originModel->isOK() ||
650 !m_originModel->isReady()) { 650 !m_originModel->isReady()) {
651 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;
652 return; 652 return;
661 (const_cast<DenseThreeDimensionalModel *>(m_sliceableModel)); 661 (const_cast<DenseThreeDimensionalModel *>(m_sliceableModel));
662 662
663 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
664 664
665 int xorigin = getVerticalScaleWidth(v, false, paint) + 1; 665 int xorigin = getVerticalScaleWidth(v, false, paint) + 1;
666 int w = v->width() - xorigin - 1; 666 int w = v->getPaintWidth() - xorigin - 1;
667 667
668 int pkh = 0; 668 int pkh = 0;
669 //!!! if (m_binScale == LogBins) { 669 //!!! if (m_binScale == LogBins) {
670 pkh = 10; 670 pkh = 10;
671 //!!! } 671 //!!! }
721 721
722 double norm = 0.f; 722 double norm = 0.f;
723 (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
724 724
725 paint.setPen(mapper.map(norm)); 725 paint.setPen(mapper.map(norm));
726 paint.drawLine(xorigin + x, 0, xorigin + x, v->height() - pkh - 1); 726 paint.drawLine(xorigin + x, 0, xorigin + x, v->getPaintHeight() - pkh - 1);
727 } 727 }
728 728
729 paint.restore(); 729 paint.restore();
730 } 730 }
731 731
741 //proposition. 741 //proposition.
742 742
743 // if (m_binScale == LogBins) { 743 // if (m_binScale == LogBins) {
744 744
745 // int pkh = 10; 745 // int pkh = 10;
746 int h = v->height(); 746 int h = v->getPaintHeight();
747 747
748 // piano keyboard 748 // piano keyboard
749 //!!! should be in a new paintHorizontalScale()? 749 //!!! should be in a new paintHorizontalScale()?
750 // nice to have a piano keyboard class, of course 750 // nice to have a piano keyboard class, of course
751 751