comparison layer/LogNumericalScale.cpp @ 1281:fc9d9f1103fa horizontal-scale

Provide linear horizontal scale in spectrum as well as log; fix bin positioning and colour scale property box updating; ensure proper background colour and visibility of peak lines
author Chris Cannam
date Thu, 03 May 2018 15:15:15 +0100
parents b6fc0970cd66
children f2525e6cbdf1
comparison
equal deleted inserted replaced
1280:34394e8c2942 1281:fc9d9f1103fa
2 2
3 /* 3 /*
4 Sonic Visualiser 4 Sonic Visualiser
5 An audio file viewer and annotation editor. 5 An audio file viewer and annotation editor.
6 Centre for Digital Music, Queen Mary, University of London. 6 Centre for Digital Music, Queen Mary, University of London.
7 This file copyright 2006-2013 Chris Cannam and QMUL. 7 This file copyright 2006-2018 Chris Cannam and QMUL.
8 8
9 This program is free software; you can redistribute it and/or 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 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 11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file 12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information. 13 COPYING included with this distribution for more information.
14 */ 14 */
15 15
16 #include "LogNumericalScale.h" 16 #include "LogNumericalScale.h"
17 #include "VerticalScaleLayer.h" 17 #include "VerticalScaleLayer.h"
18 #include "HorizontalScaleProvider.h"
19 #include "LayerGeometryProvider.h" 18 #include "LayerGeometryProvider.h"
20 19
21 #include "base/LogRange.h" 20 #include "base/LogRange.h"
22 #include "base/ScaleTickIntervals.h" 21 #include "base/ScaleTickIntervals.h"
23 22
25 24
26 #include <cmath> 25 #include <cmath>
27 26
28 int 27 int
29 LogNumericalScale::getWidth(LayerGeometryProvider *, 28 LogNumericalScale::getWidth(LayerGeometryProvider *,
30 QPainter &paint, 29 QPainter &paint)
31 bool horizontal)
32 { 30 {
33 if (horizontal) { 31 return paint.fontMetrics().width("-000.00") + 10;
34 return paint.fontMetrics().height() + 10;
35 } else {
36 return paint.fontMetrics().width("-000.00") + 10;
37 }
38 } 32 }
39 33
40 void 34 void
41 LogNumericalScale::paintVertical(LayerGeometryProvider *v, 35 LogNumericalScale::paintVertical(LayerGeometryProvider *v,
42 const VerticalScaleLayer *layer, 36 const VerticalScaleLayer *layer,
83 77
84 prevy = y; 78 prevy = y;
85 } 79 }
86 } 80 }
87 81
88 void
89 LogNumericalScale::paintHorizontal(LayerGeometryProvider *v,
90 const HorizontalScaleProvider *p,
91 QPainter &paint,
92 QRect r)
93 {
94 int x0 = r.x(), y0 = r.y(), x1 = r.x() + r.width(), y1 = r.y() + r.height();
95
96 paint.drawLine(x0, y0, x1, y0);
97
98 double f0 = p->getFrequencyForX(v, x0 ? x0 : 1);
99 double f1 = p->getFrequencyForX(v, x1);
100
101 cerr << "f0 = " << f0 << " at x " << (x0 ? x0 : 1) << endl;
102 cerr << "f1 = " << f1 << " at x " << x1 << endl;
103
104 int n = 20;
105 auto ticks = ScaleTickIntervals::logarithmic({ f0, f1, n });
106 n = int(ticks.size());
107
108 int marginx = -1;
109
110 for (int i = 0; i < n; ++i) {
111
112 double val = ticks[i].value;
113 QString label = QString::fromStdString(ticks[i].label);
114 int tw = paint.fontMetrics().width(label);
115
116 cerr << "i = " << i << ", value = " << val << ", tw = " << tw << endl;
117
118 int x = int(round(p->getXForFrequency(v, val)));
119
120 cerr << "x = " << x << endl;
121
122 if (x < marginx) continue;
123
124 //!!! todo: pixel scaling (here & elsewhere in these classes)
125
126 paint.drawLine(x, y0, x, y1);
127
128 paint.drawText(x + 5, y0 + paint.fontMetrics().ascent() + 5, label);
129
130 marginx = x + tw + 10;
131 }
132 }
133