comparison layer/PianoScale.cpp @ 1266:a34a2a25907c

Untabify
author Chris Cannam
date Thu, 01 Mar 2018 18:02:22 +0000
parents 4d0ca1ab4cd0
children b4cb11ca8233
comparison
equal deleted inserted replaced
1265:6e724c81f18f 1266:a34a2a25907c
26 #include <iostream> 26 #include <iostream>
27 using namespace std; 27 using namespace std;
28 28
29 void 29 void
30 PianoScale::paintPianoVertical(LayerGeometryProvider *v, 30 PianoScale::paintPianoVertical(LayerGeometryProvider *v,
31 QPainter &paint, 31 QPainter &paint,
32 QRect r, 32 QRect r,
33 double minf, 33 double minf,
34 double maxf) 34 double maxf)
35 { 35 {
36 int x0 = r.x(), y0 = r.y(), x1 = r.x() + r.width(), y1 = r.y() + r.height(); 36 int x0 = r.x(), y0 = r.y(), x1 = r.x() + r.width(), y1 = r.y() + r.height();
37 37
38 paint.drawLine(x0, y0, x0, y1); 38 paint.drawLine(x0, y0, x0, y1);
39 39
40 int py = y1, ppy = y1; 40 int py = y1, ppy = y1;
41 paint.setBrush(paint.pen().color()); 41 paint.setBrush(paint.pen().color());
42 42
43 for (int i = 0; i < 128; ++i) { 43 for (int i = 0; i < 128; ++i) {
44 44
45 double f = Pitch::getFrequencyForPitch(i); 45 double f = Pitch::getFrequencyForPitch(i);
46 int y = int(lrint(v->getYForFrequency(f, minf, maxf, true))); 46 int y = int(lrint(v->getYForFrequency(f, minf, maxf, true)));
47 47
48 if (y < y0 - 2) break; 48 if (y < y0 - 2) break;
49 if (y > y1 + 2) { 49 if (y > y1 + 2) {
50 continue; 50 continue;
51 } 51 }
52 52
53 int n = (i % 12); 53 int n = (i % 12);
54 54
55 if (n == 1) { 55 if (n == 1) {
56 // C# -- fill the C from here 56 // C# -- fill the C from here
57 QColor col = Qt::gray; 57 QColor col = Qt::gray;
58 if (i == 61) { // filling middle C 58 if (i == 61) { // filling middle C
59 col = Qt::blue; 59 col = Qt::blue;
60 col = col.light(150); 60 col = col.light(150);
61 } 61 }
62 if (ppy - y > 2) { 62 if (ppy - y > 2) {
63 paint.fillRect(x0 + 1, 63 paint.fillRect(x0 + 1,
64 y, 64 y,
65 x1 - x0, 65 x1 - x0,
66 (py + ppy) / 2 - y, 66 (py + ppy) / 2 - y,
67 col); 67 col);
68 } 68 }
69 } 69 }
70 70
71 if (n == 1 || n == 3 || n == 6 || n == 8 || n == 10) { 71 if (n == 1 || n == 3 || n == 6 || n == 8 || n == 10) {
72 // black notes 72 // black notes
73 paint.drawLine(x0 + 1, y, x1, y); 73 paint.drawLine(x0 + 1, y, x1, y);
74 int rh = ((py - y) / 4) * 2; 74 int rh = ((py - y) / 4) * 2;
75 if (rh < 2) rh = 2; 75 if (rh < 2) rh = 2;
76 paint.drawRect(x0 + 1, y - (py-y)/4, (x1 - x0) / 2, rh); 76 paint.drawRect(x0 + 1, y - (py-y)/4, (x1 - x0) / 2, rh);
77 } else if (n == 0 || n == 5) { 77 } else if (n == 0 || n == 5) {
78 // C, F 78 // C, F
79 if (py < y1) { 79 if (py < y1) {
80 paint.drawLine(x0 + 1, (y + py) / 2, x1, (y + py) / 2); 80 paint.drawLine(x0 + 1, (y + py) / 2, x1, (y + py) / 2);
81 } 81 }
82 } 82 }
83 83
84 ppy = py; 84 ppy = py;
85 py = y; 85 py = y;
86 } 86 }
87 } 87 }
88 88
89 void 89 void
90 PianoScale::paintPianoHorizontal(LayerGeometryProvider *v, 90 PianoScale::paintPianoHorizontal(LayerGeometryProvider *v,