comparison layer/SpectrumLayer.cpp @ 1078:ee01a4062747 spectrogram-minor-refactor

Move drawVisibleText to PaintAssistant
author Chris Cannam
date Thu, 30 Jun 2016 12:40:22 +0100
parents 64c2b3a4435a
children 1badacff7ab2
comparison
equal deleted inserted replaced
1077:5144d7185fb5 1078:ee01a4062747
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
24 #include "ColourMapper.h" 25 #include "ColourMapper.h"
26 #include "PaintAssistant.h"
25 27
26 #include <QPainter> 28 #include <QPainter>
27 #include <QTextStream> 29 #include <QTextStream>
28 30
29 31
489 double fundamental = getFrequencyForX(cursorPos.x() - xorigin, w); 491 double fundamental = getFrequencyForX(cursorPos.x() - xorigin, w);
490 492
491 int hoffset = 2; 493 int hoffset = 2;
492 if (m_binScale == LogBins) hoffset = 13; 494 if (m_binScale == LogBins) hoffset = 13;
493 495
494 v->drawVisibleText(paint, 496 PaintAssistant::drawVisibleText(v, paint,
495 cursorPos.x() + 2, 497 cursorPos.x() + 2,
496 v->getPaintHeight() - 2 - hoffset, 498 v->getPaintHeight() - 2 - hoffset,
497 QString("%1 Hz").arg(fundamental), 499 QString("%1 Hz").arg(fundamental),
498 View::OutlinedText); 500 PaintAssistant::OutlinedText);
499 501
500 if (Pitch::isFrequencyInMidiRange(fundamental)) { 502 if (Pitch::isFrequencyInMidiRange(fundamental)) {
501 QString pitchLabel = Pitch::getPitchLabelForFrequency(fundamental); 503 QString pitchLabel = Pitch::getPitchLabelForFrequency(fundamental);
502 v->drawVisibleText(paint, 504 PaintAssistant::drawVisibleText(v, paint,
503 cursorPos.x() - paint.fontMetrics().width(pitchLabel) - 2, 505 cursorPos.x() - paint.fontMetrics().width(pitchLabel) - 2,
504 v->getPaintHeight() - 2 - hoffset, 506 v->getPaintHeight() - 2 - hoffset,
505 pitchLabel, 507 pitchLabel,
506 View::OutlinedText); 508 PaintAssistant::OutlinedText);
507 } 509 }
508 510
509 double value = getValueForY(cursorPos.y(), v); 511 double value = getValueForY(cursorPos.y(), v);
510 double thresh = m_threshold; 512 double thresh = m_threshold;
511 double db = thresh; 513 double db = thresh;
512 if (value > 0.0) db = 10.0 * log10(value); 514 if (value > 0.0) db = 10.0 * log10(value);
513 if (db < thresh) db = thresh; 515 if (db < thresh) db = thresh;
514 516
515 v->drawVisibleText(paint, 517 PaintAssistant::drawVisibleText(v, paint,
516 xorigin + 2, 518 xorigin + 2,
517 cursorPos.y() - 2, 519 cursorPos.y() - 2,
518 QString("%1 V").arg(value), 520 QString("%1 V").arg(value),
519 View::OutlinedText); 521 PaintAssistant::OutlinedText);
520 522
521 v->drawVisibleText(paint, 523 PaintAssistant::drawVisibleText(v, paint,
522 xorigin + 2, 524 xorigin + 2,
523 cursorPos.y() + 2 + paint.fontMetrics().ascent(), 525 cursorPos.y() + 2 + paint.fontMetrics().ascent(),
524 QString("%1 dBV").arg(db), 526 QString("%1 dBV").arg(db),
525 View::OutlinedText); 527 PaintAssistant::OutlinedText);
526 528
527 int harmonic = 2; 529 int harmonic = 2;
528 530
529 while (harmonic < 100) { 531 while (harmonic < 100) {
530 532