Mercurial > hg > svgui
comparison layer/SpectrogramLayer.cpp @ 690:8072264dc61f
Pull out PianoScale into separate class
author | Chris Cannam |
---|---|
date | Tue, 03 Dec 2013 17:32:25 +0000 |
parents | 1a0dfcbffaf1 |
children | 67e6d518ac27 |
comparison
equal
deleted
inserted
replaced
689:d8fc9659a206 | 690:8072264dc61f |
---|---|
25 #include "base/LogRange.h" | 25 #include "base/LogRange.h" |
26 #include "widgets/CommandHistory.h" | 26 #include "widgets/CommandHistory.h" |
27 #include "ColourMapper.h" | 27 #include "ColourMapper.h" |
28 #include "ImageRegionFinder.h" | 28 #include "ImageRegionFinder.h" |
29 #include "data/model/Dense3DModelPeakCache.h" | 29 #include "data/model/Dense3DModelPeakCache.h" |
30 #include "PianoScale.h" | |
30 | 31 |
31 #include <QPainter> | 32 #include <QPainter> |
32 #include <QImage> | 33 #include <QImage> |
33 #include <QPixmap> | 34 #include <QPixmap> |
34 #include <QRect> | 35 #include <QRect> |
3433 | 3434 |
3434 if (m_frequencyScale == LogFrequencyScale) { | 3435 if (m_frequencyScale == LogFrequencyScale) { |
3435 | 3436 |
3436 // piano keyboard | 3437 // piano keyboard |
3437 | 3438 |
3438 paint.drawLine(w - pkw - 1, 0, w - pkw - 1, h); | 3439 PianoScale().paintPianoVertical |
3439 | 3440 (v, paint, QRect(w - pkw - 1, 0, pkw, h), |
3440 float minf = getEffectiveMinFrequency(); | 3441 getEffectiveMinFrequency(), getEffectiveMaxFrequency()); |
3441 float maxf = getEffectiveMaxFrequency(); | |
3442 | |
3443 int py = h, ppy = h; | |
3444 paint.setBrush(paint.pen().color()); | |
3445 | |
3446 for (int i = 0; i < 128; ++i) { | |
3447 | |
3448 float f = Pitch::getFrequencyForPitch(i); | |
3449 int y = lrintf(v->getYForFrequency(f, minf, maxf, true)); | |
3450 | |
3451 if (y < -2) break; | |
3452 if (y > h + 2) { | |
3453 continue; | |
3454 } | |
3455 | |
3456 int n = (i % 12); | |
3457 | |
3458 if (n == 1) { | |
3459 // C# -- fill the C from here | |
3460 QColor col = Qt::gray; | |
3461 if (i == 61) { // filling middle C | |
3462 col = Qt::blue; | |
3463 col = col.light(150); | |
3464 } | |
3465 if (ppy - y > 2) { | |
3466 paint.fillRect(w - pkw, | |
3467 y, | |
3468 pkw, | |
3469 (py + ppy) / 2 - y, | |
3470 col); | |
3471 } | |
3472 } | |
3473 | |
3474 if (n == 1 || n == 3 || n == 6 || n == 8 || n == 10) { | |
3475 // black notes | |
3476 paint.drawLine(w - pkw, y, w, y); | |
3477 int rh = ((py - y) / 4) * 2; | |
3478 if (rh < 2) rh = 2; | |
3479 paint.drawRect(w - pkw, y - (py-y)/4, pkw/2, rh); | |
3480 } else if (n == 0 || n == 5) { | |
3481 // C, F | |
3482 if (py < h) { | |
3483 paint.drawLine(w - pkw, (y + py) / 2, w, (y + py) / 2); | |
3484 } | |
3485 } | |
3486 | |
3487 ppy = py; | |
3488 py = y; | |
3489 } | |
3490 } | 3442 } |
3491 | 3443 |
3492 m_haveDetailedScale = detailed; | 3444 m_haveDetailedScale = detailed; |
3493 } | 3445 } |
3494 | 3446 |