Mercurial > hg > svgui
comparison layer/PianoScale.cpp @ 1238:4d0ca1ab4cd0
Some work to make spectrum layers (and slice layers generally) zoomable in the frequency axis. Also fixes a number of view id mixups in SliceLayer which broke offset calculations for the x axis scale.
author | Chris Cannam |
---|---|
date | Tue, 07 Feb 2017 14:55:19 +0000 |
parents | 5144d7185fb5 |
children | a34a2a25907c |
comparison
equal
deleted
inserted
replaced
1237:2cc9e0e5df51 | 1238:4d0ca1ab4cd0 |
---|---|
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 | |
26 #include <iostream> | |
27 using namespace std; | |
25 | 28 |
26 void | 29 void |
27 PianoScale::paintPianoVertical(LayerGeometryProvider *v, | 30 PianoScale::paintPianoVertical(LayerGeometryProvider *v, |
28 QPainter &paint, | 31 QPainter &paint, |
29 QRect r, | 32 QRect r, |
81 ppy = py; | 84 ppy = py; |
82 py = y; | 85 py = y; |
83 } | 86 } |
84 } | 87 } |
85 | 88 |
89 void | |
90 PianoScale::paintPianoHorizontal(LayerGeometryProvider *v, | |
91 const HorizontalScaleProvider *p, | |
92 QPainter &paint, | |
93 QRect r) | |
94 { | |
95 int x0 = r.x(), y0 = r.y(), x1 = r.x() + r.width(), y1 = r.y() + r.height(); | |
96 | |
97 paint.drawLine(x0, y0, x1, y0); | |
98 | |
99 int px = x0, ppx = x0; | |
100 paint.setBrush(paint.pen().color()); | |
101 | |
102 for (int i = 0; i < 128; ++i) { | |
103 | |
104 double f = Pitch::getFrequencyForPitch(i); | |
105 int x = int(lrint(p->getXForFrequency(v, f))); | |
106 | |
107 if (i == 0) { | |
108 px = ppx = x; | |
109 } | |
110 if (i == 1) { | |
111 ppx = px - (x - px); | |
112 } | |
113 | |
114 if (x < x0) { | |
115 ppx = px; | |
116 px = x; | |
117 continue; | |
118 } | |
119 | |
120 if (x > x1) { | |
121 break; | |
122 } | |
123 | |
124 int n = (i % 12); | |
125 | |
126 if (n == 1) { | |
127 // C# -- fill the C from here | |
128 QColor col = Qt::gray; | |
129 if (i == 61) { // filling middle C | |
130 col = Qt::blue; | |
131 col = col.light(150); | |
132 } | |
133 if (x - ppx > 2) { | |
134 paint.fillRect((px + ppx) / 2 + 1, | |
135 y0 + 1, | |
136 x - (px + ppx) / 2 - 1, | |
137 y1 - y0, | |
138 col); | |
139 } | |
140 } | |
141 | |
142 if (n == 1 || n == 3 || n == 6 || n == 8 || n == 10) { | |
143 // black notes | |
144 paint.drawLine(x, y0, x, y1); | |
145 int rw = int(lrint(double(x - px) / 4) * 2); | |
146 if (rw < 2) rw = 2; | |
147 paint.drawRect(x - rw/2, (y0 + y1) / 2, rw, (y1 - y0) / 2); | |
148 } else if (n == 0 || n == 5) { | |
149 // C, F | |
150 if (px < x1) { | |
151 paint.drawLine((x + px) / 2, y0, (x + px) / 2, y1); | |
152 } | |
153 } | |
154 | |
155 ppx = px; | |
156 px = x; | |
157 } | |
158 } | |
159 | |
160 |