Mercurial > hg > svgui
comparison layer/PianoScale.cpp @ 1324:13d9b422f7fe zoom
Merge from default branch
author | Chris Cannam |
---|---|
date | Mon, 17 Sep 2018 13:51:31 +0100 |
parents | b4cb11ca8233 |
children | f2525e6cbdf1 |
comparison
equal
deleted
inserted
replaced
1183:57d192e26331 | 1324:13d9b422f7fe |
---|---|
20 #include <cmath> | 20 #include <cmath> |
21 | 21 |
22 #include "base/Pitch.h" | 22 #include "base/Pitch.h" |
23 | 23 |
24 #include "LayerGeometryProvider.h" | 24 #include "LayerGeometryProvider.h" |
25 #include "HorizontalScaleProvider.h" | |
26 | |
27 #include <iostream> | |
28 using namespace std; | |
25 | 29 |
26 void | 30 void |
27 PianoScale::paintPianoVertical(LayerGeometryProvider *v, | 31 PianoScale::paintPianoVertical(LayerGeometryProvider *v, |
28 QPainter &paint, | 32 QPainter &paint, |
29 QRect r, | 33 QRect r, |
30 double minf, | 34 double minf, |
31 double maxf) | 35 double maxf) |
32 { | 36 { |
33 int x0 = r.x(), y0 = r.y(), x1 = r.x() + r.width(), y1 = r.y() + r.height(); | 37 int x0 = r.x(), y0 = r.y(), x1 = r.x() + r.width(), y1 = r.y() + r.height(); |
34 | 38 |
35 paint.drawLine(x0, y0, x0, y1); | 39 paint.drawLine(x0, y0, x0, y1); |
36 | 40 |
37 int py = y1, ppy = y1; | 41 int py = y1, ppy = y1; |
38 paint.setBrush(paint.pen().color()); | 42 paint.setBrush(paint.pen().color()); |
39 | 43 |
40 for (int i = 0; i < 128; ++i) { | 44 for (int i = 0; i < 128; ++i) { |
41 | 45 |
42 double f = Pitch::getFrequencyForPitch(i); | 46 double f = Pitch::getFrequencyForPitch(i); |
43 int y = int(lrint(v->getYForFrequency(f, minf, maxf, true))); | 47 int y = int(lrint(v->getYForFrequency(f, minf, maxf, true))); |
44 | 48 |
45 if (y < y0 - 2) break; | 49 if (y < y0 - 2) break; |
46 if (y > y1 + 2) { | 50 if (y > y1 + 2) { |
47 continue; | 51 continue; |
48 } | 52 } |
49 | 53 |
50 int n = (i % 12); | 54 int n = (i % 12); |
51 | 55 |
52 if (n == 1) { | 56 if (n == 1) { |
53 // C# -- fill the C from here | 57 // C# -- fill the C from here |
54 QColor col = Qt::gray; | 58 QColor col = Qt::gray; |
55 if (i == 61) { // filling middle C | 59 if (i == 61) { // filling middle C |
56 col = Qt::blue; | 60 col = Qt::blue; |
57 col = col.light(150); | 61 col = col.light(150); |
58 } | 62 } |
59 if (ppy - y > 2) { | 63 if (ppy - y > 2) { |
60 paint.fillRect(x0 + 1, | 64 paint.fillRect(x0 + 1, |
61 y, | 65 y, |
62 x1 - x0, | 66 x1 - x0, |
63 (py + ppy) / 2 - y, | 67 (py + ppy) / 2 - y, |
64 col); | 68 col); |
65 } | 69 } |
66 } | 70 } |
67 | 71 |
68 if (n == 1 || n == 3 || n == 6 || n == 8 || n == 10) { | 72 if (n == 1 || n == 3 || n == 6 || n == 8 || n == 10) { |
69 // black notes | 73 // black notes |
70 paint.drawLine(x0 + 1, y, x1, y); | 74 paint.drawLine(x0 + 1, y, x1, y); |
71 int rh = ((py - y) / 4) * 2; | 75 int rh = ((py - y) / 4) * 2; |
72 if (rh < 2) rh = 2; | 76 if (rh < 2) rh = 2; |
73 paint.drawRect(x0 + 1, y - (py-y)/4, (x1 - x0) / 2, rh); | 77 paint.drawRect(x0 + 1, y - (py-y)/4, (x1 - x0) / 2, rh); |
74 } else if (n == 0 || n == 5) { | 78 } else if (n == 0 || n == 5) { |
75 // C, F | 79 // C, F |
76 if (py < y1) { | 80 if (py < y1) { |
77 paint.drawLine(x0 + 1, (y + py) / 2, x1, (y + py) / 2); | 81 paint.drawLine(x0 + 1, (y + py) / 2, x1, (y + py) / 2); |
78 } | 82 } |
79 } | 83 } |
80 | 84 |
81 ppy = py; | 85 ppy = py; |
82 py = y; | 86 py = y; |
83 } | 87 } |
84 } | 88 } |
85 | 89 |
90 void | |
91 PianoScale::paintPianoHorizontal(LayerGeometryProvider *v, | |
92 const HorizontalScaleProvider *p, | |
93 QPainter &paint, | |
94 QRect r) | |
95 { | |
96 int x0 = r.x(), y0 = r.y(), x1 = r.x() + r.width(), y1 = r.y() + r.height(); | |
97 | |
98 paint.drawLine(x0, y0, x1, y0); | |
99 | |
100 int px = x0, ppx = x0; | |
101 paint.setBrush(paint.pen().color()); | |
102 | |
103 for (int i = 0; i < 128; ++i) { | |
104 | |
105 double f = Pitch::getFrequencyForPitch(i); | |
106 int x = int(lrint(p->getXForFrequency(v, f))); | |
107 | |
108 if (i == 0) { | |
109 px = ppx = x; | |
110 } | |
111 if (i == 1) { | |
112 ppx = px - (x - px); | |
113 } | |
114 | |
115 if (x < x0) { | |
116 ppx = px; | |
117 px = x; | |
118 continue; | |
119 } | |
120 | |
121 if (x > x1) { | |
122 break; | |
123 } | |
124 | |
125 int n = (i % 12); | |
126 | |
127 if (n == 1) { | |
128 // C# -- fill the C from here | |
129 QColor col = Qt::gray; | |
130 if (i == 61) { // filling middle C | |
131 col = Qt::blue; | |
132 col = col.light(150); | |
133 } | |
134 if (x - ppx > 2) { | |
135 paint.fillRect((px + ppx) / 2 + 1, | |
136 y0 + 1, | |
137 x - (px + ppx) / 2 - 1, | |
138 y1 - y0, | |
139 col); | |
140 } | |
141 } | |
142 | |
143 if (n == 1 || n == 3 || n == 6 || n == 8 || n == 10) { | |
144 // black notes | |
145 paint.drawLine(x, y0, x, y1); | |
146 int rw = int(lrint(double(x - px) / 4) * 2); | |
147 if (rw < 2) rw = 2; | |
148 paint.drawRect(x - rw/2, (y0 + y1) / 2, rw, (y1 - y0) / 2); | |
149 } else if (n == 0 || n == 5) { | |
150 // C, F | |
151 if (px < x1) { | |
152 paint.drawLine((x + px) / 2, y0, (x + px) / 2, y1); | |
153 } | |
154 } | |
155 | |
156 ppx = px; | |
157 px = x; | |
158 } | |
159 } | |
160 | |
161 |