Mercurial > hg > svgui
comparison layer/PianoScale.cpp @ 694:ad12e428785b tonioni
Merge from default branch
author | Chris Cannam |
---|---|
date | Tue, 03 Dec 2013 17:58:40 +0000 |
parents | 8072264dc61f |
children | e0f08e108064 |
comparison
equal
deleted
inserted
replaced
688:212644efa523 | 694:ad12e428785b |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2006-2013 Chris Cannam and QMUL. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #include "PianoScale.h" | |
17 | |
18 #include <QPainter> | |
19 | |
20 #include <cmath> | |
21 | |
22 #include "base/Pitch.h" | |
23 | |
24 #include "view/View.h" | |
25 | |
26 void | |
27 PianoScale::paintPianoVertical(View *v, | |
28 QPainter &paint, | |
29 QRect r, | |
30 float minf, | |
31 float maxf) | |
32 { | |
33 int x0 = r.x(), y0 = r.y(), x1 = r.x() + r.width(), y1 = r.y() + r.height(); | |
34 | |
35 paint.drawLine(x0, y0, x0, y1); | |
36 | |
37 int py = y1, ppy = y1; | |
38 paint.setBrush(paint.pen().color()); | |
39 | |
40 for (int i = 0; i < 128; ++i) { | |
41 | |
42 float f = Pitch::getFrequencyForPitch(i); | |
43 int y = lrintf(v->getYForFrequency(f, minf, maxf, true)); | |
44 | |
45 if (y < y0 - 2) break; | |
46 if (y > y1 + 2) { | |
47 continue; | |
48 } | |
49 | |
50 int n = (i % 12); | |
51 | |
52 if (n == 1) { | |
53 // C# -- fill the C from here | |
54 QColor col = Qt::gray; | |
55 if (i == 61) { // filling middle C | |
56 col = Qt::blue; | |
57 col = col.light(150); | |
58 } | |
59 if (ppy - y > 2) { | |
60 paint.fillRect(x0 + 1, | |
61 y, | |
62 x1 - x0, | |
63 (py + ppy) / 2 - y, | |
64 col); | |
65 } | |
66 } | |
67 | |
68 if (n == 1 || n == 3 || n == 6 || n == 8 || n == 10) { | |
69 // black notes | |
70 paint.drawLine(x0 + 1, y, x1, y); | |
71 int rh = ((py - y) / 4) * 2; | |
72 if (rh < 2) rh = 2; | |
73 paint.drawRect(x0 + 1, y - (py-y)/4, (x1 - x0) / 2, rh); | |
74 } else if (n == 0 || n == 5) { | |
75 // C, F | |
76 if (py < y1) { | |
77 paint.drawLine(x0 + 1, (y + py) / 2, x1, (y + py) / 2); | |
78 } | |
79 } | |
80 | |
81 ppy = py; | |
82 py = y; | |
83 } | |
84 } | |
85 |