Mercurial > hg > svgui
comparison layer/PaintAssistant.cpp @ 946:36cddc3de023 alignment_view
Merge from default branch
author | Chris Cannam |
---|---|
date | Mon, 20 Apr 2015 09:19:52 +0100 |
parents | b66fb15de477 |
children | ee01a4062747 |
comparison
equal
deleted
inserted
replaced
897:499b637f2a26 | 946:36cddc3de023 |
---|---|
23 #include <iostream> | 23 #include <iostream> |
24 #include <cmath> | 24 #include <cmath> |
25 | 25 |
26 void | 26 void |
27 PaintAssistant::paintVerticalLevelScale(QPainter &paint, QRect rect, | 27 PaintAssistant::paintVerticalLevelScale(QPainter &paint, QRect rect, |
28 float minVal, float maxVal, | 28 double minVal, double maxVal, |
29 Scale scale, int &mult, | 29 Scale scale, int &mult, |
30 std::vector<int> *vy) | 30 std::vector<int> *vy) |
31 { | 31 { |
32 static float meterdbs[] = { -40, -30, -20, -15, -10, | 32 static double meterdbs[] = { -40, -30, -20, -15, -10, |
33 -5, -3, -2, -1, -0.5, 0 }; | 33 -5, -3, -2, -1, -0.5, 0 }; |
34 | 34 |
35 int h = rect.height(), w = rect.width(); | 35 int h = rect.height(), w = rect.width(); |
36 int textHeight = paint.fontMetrics().height(); | 36 int textHeight = paint.fontMetrics().height(); |
37 int toff = -textHeight/2 + paint.fontMetrics().ascent() + 1; | 37 int toff = -textHeight/2 + paint.fontMetrics().ascent() + 1; |
39 int lastLabelledY = -1; | 39 int lastLabelledY = -1; |
40 | 40 |
41 int n = 10; | 41 int n = 10; |
42 if (vy) vy->clear(); | 42 if (vy) vy->clear(); |
43 | 43 |
44 float step = 0; | 44 double step = 0; |
45 mult = 1; | 45 mult = 1; |
46 if (scale == LinearScale) { | 46 if (scale == LinearScale) { |
47 step = (maxVal - minVal) / n; | 47 step = (maxVal - minVal) / n; |
48 int round = 0, limit = 10000000; | 48 int round = 0, limit = 10000000; |
49 do { | 49 do { |
51 mult *= 10; | 51 mult *= 10; |
52 } while (!round && mult < limit); | 52 } while (!round && mult < limit); |
53 if (round) { | 53 if (round) { |
54 mult /= 10; | 54 mult /= 10; |
55 // cerr << "\n\nstep goes from " << step; | 55 // cerr << "\n\nstep goes from " << step; |
56 step = float(round) / mult; | 56 step = double(round) / mult; |
57 n = lrintf((maxVal - minVal) / step); | 57 n = int(lrint((maxVal - minVal) / step)); |
58 if (mult > 1) { | 58 if (mult > 1) { |
59 mult /= 10; | 59 mult /= 10; |
60 } | 60 } |
61 // cerr << " to " << step << " (n = " << n << ")" << endl; | 61 // cerr << " to " << step << " (n = " << n << ")" << endl; |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
65 for (int i = 0; i <= n; ++i) { | 65 for (int i = 0; i <= n; ++i) { |
66 | 66 |
67 float val = 0.0, nval = 0.0; | 67 double val = 0.0, nval = 0.0; |
68 QString text = ""; | 68 QString text = ""; |
69 | 69 |
70 switch (scale) { | 70 switch (scale) { |
71 | 71 |
72 case LinearScale: | 72 case LinearScale: |
164 } | 164 } |
165 } | 165 } |
166 } | 166 } |
167 | 167 |
168 static int | 168 static int |
169 dBscale(float sample, int m, float maxVal, float minVal) | 169 dBscale(double sample, int m, double maxVal, double minVal) |
170 { | 170 { |
171 if (sample < 0.0) return dBscale(-sample, m, maxVal, minVal); | 171 if (sample < 0.0) return dBscale(-sample, m, maxVal, minVal); |
172 float dB = AudioLevel::multiplier_to_dB(sample); | 172 double dB = AudioLevel::multiplier_to_dB(sample); |
173 float mindB = AudioLevel::multiplier_to_dB(minVal); | 173 double mindB = AudioLevel::multiplier_to_dB(minVal); |
174 float maxdB = AudioLevel::multiplier_to_dB(maxVal); | 174 double maxdB = AudioLevel::multiplier_to_dB(maxVal); |
175 if (dB < mindB) return 0; | 175 if (dB < mindB) return 0; |
176 if (dB > 0.0) return m; | 176 if (dB > 0.0) return m; |
177 return int(((dB - mindB) * m) / (maxdB - mindB) + 0.1); | 177 return int(((dB - mindB) * m) / (maxdB - mindB) + 0.1); |
178 } | 178 } |
179 | 179 |
180 int | 180 int |
181 PaintAssistant::getYForValue(Scale scale, float value, | 181 PaintAssistant::getYForValue(Scale scale, double value, |
182 float minVal, float maxVal, | 182 double minVal, double maxVal, |
183 int minY, int height) | 183 int minY, int height) |
184 { | 184 { |
185 int vy = 0; | 185 int vy = 0; |
186 | 186 |
187 // int m = height/2; | 187 // int m = height/2; |