comparison layer/SpectrumLayer.cpp @ 1148:c0d841cb8ab9 tony-2.0-integration

Merge latest SV 3.0 branch code
author Chris Cannam
date Fri, 19 Aug 2016 15:58:57 +0100
parents 1badacff7ab2
children ff97318e993c
comparison
equal deleted inserted replaced
1009:96cf499fad62 1148:c0d841cb8ab9
19 #include "view/View.h" 19 #include "view/View.h"
20 #include "base/AudioLevel.h" 20 #include "base/AudioLevel.h"
21 #include "base/Preferences.h" 21 #include "base/Preferences.h"
22 #include "base/RangeMapper.h" 22 #include "base/RangeMapper.h"
23 #include "base/Pitch.h" 23 #include "base/Pitch.h"
24 #include "base/Strings.h"
25
24 #include "ColourMapper.h" 26 #include "ColourMapper.h"
27 #include "PaintAssistant.h"
25 28
26 #include <QPainter> 29 #include <QPainter>
27 #include <QTextStream> 30 #include <QTextStream>
28 31
29 32
489 double fundamental = getFrequencyForX(cursorPos.x() - xorigin, w); 492 double fundamental = getFrequencyForX(cursorPos.x() - xorigin, w);
490 493
491 int hoffset = 2; 494 int hoffset = 2;
492 if (m_binScale == LogBins) hoffset = 13; 495 if (m_binScale == LogBins) hoffset = 13;
493 496
494 v->drawVisibleText(paint, 497 PaintAssistant::drawVisibleText(v, paint,
495 cursorPos.x() + 2, 498 cursorPos.x() + 2,
496 v->getPaintHeight() - 2 - hoffset, 499 v->getPaintHeight() - 2 - hoffset,
497 QString("%1 Hz").arg(fundamental), 500 QString("%1 Hz").arg(fundamental),
498 View::OutlinedText); 501 PaintAssistant::OutlinedText);
499 502
500 if (Pitch::isFrequencyInMidiRange(fundamental)) { 503 if (Pitch::isFrequencyInMidiRange(fundamental)) {
501 QString pitchLabel = Pitch::getPitchLabelForFrequency(fundamental); 504 QString pitchLabel = Pitch::getPitchLabelForFrequency(fundamental);
502 v->drawVisibleText(paint, 505 PaintAssistant::drawVisibleText(v, paint,
503 cursorPos.x() - paint.fontMetrics().width(pitchLabel) - 2, 506 cursorPos.x() - paint.fontMetrics().width(pitchLabel) - 2,
504 v->getPaintHeight() - 2 - hoffset, 507 v->getPaintHeight() - 2 - hoffset,
505 pitchLabel, 508 pitchLabel,
506 View::OutlinedText); 509 PaintAssistant::OutlinedText);
507 } 510 }
508 511
509 double value = getValueForY(cursorPos.y(), v); 512 double value = getValueForY(cursorPos.y(), v);
510 double thresh = m_threshold; 513 double thresh = m_threshold;
511 double db = thresh; 514 double db = thresh;
512 if (value > 0.0) db = 10.0 * log10(value); 515 if (value > 0.0) db = 10.0 * log10(value);
513 if (db < thresh) db = thresh; 516 if (db < thresh) db = thresh;
514 517
515 v->drawVisibleText(paint, 518 PaintAssistant::drawVisibleText(v, paint,
516 xorigin + 2, 519 xorigin + 2,
517 cursorPos.y() - 2, 520 cursorPos.y() - 2,
518 QString("%1 V").arg(value), 521 QString("%1 V").arg(value),
519 View::OutlinedText); 522 PaintAssistant::OutlinedText);
520 523
521 v->drawVisibleText(paint, 524 PaintAssistant::drawVisibleText(v, paint,
522 xorigin + 2, 525 xorigin + 2,
523 cursorPos.y() + 2 + paint.fontMetrics().ascent(), 526 cursorPos.y() + 2 + paint.fontMetrics().ascent(),
524 QString("%1 dBV").arg(db), 527 QString("%1 dBV").arg(db),
525 View::OutlinedText); 528 PaintAssistant::OutlinedText);
526 529
527 int harmonic = 2; 530 int harmonic = 2;
528 531
529 while (harmonic < 100) { 532 while (harmonic < 100) {
530 533
603 double mindb = AudioLevel::multiplier_to_dB(minvalue); 606 double mindb = AudioLevel::multiplier_to_dB(minvalue);
604 double maxdb = AudioLevel::multiplier_to_dB(maxvalue); 607 double maxdb = AudioLevel::multiplier_to_dB(maxvalue);
605 QString mindbstr; 608 QString mindbstr;
606 QString maxdbstr; 609 QString maxdbstr;
607 if (mindb == AudioLevel::DB_FLOOR) { 610 if (mindb == AudioLevel::DB_FLOOR) {
608 mindbstr = tr("-Inf"); 611 mindbstr = Strings::minus_infinity;
609 } else { 612 } else {
610 mindbstr = QString("%1").arg(lrint(mindb)); 613 mindbstr = QString("%1").arg(lrint(mindb));
611 } 614 }
612 if (maxdb == AudioLevel::DB_FLOOR) { 615 if (maxdb == AudioLevel::DB_FLOOR) {
613 maxdbstr = tr("-Inf"); 616 maxdbstr = Strings::minus_infinity;
614 } else { 617 } else {
615 maxdbstr = QString("%1").arg(lrint(maxdb)); 618 maxdbstr = QString("%1").arg(lrint(maxdb));
616 } 619 }
617 if (lrint(mindb) != lrint(maxdb)) { 620 if (lrint(mindb) != lrint(maxdb)) {
618 dbstr = tr("%1 - %2").arg(mindbstr).arg(maxdbstr); 621 dbstr = tr("%1 - %2").arg(mindbstr).arg(maxdbstr);