comparison widgets/WindowShapePreview.cpp @ 1159:8a5f0c8d5608 3.0-integration

Merge from branch piper
author Chris Cannam
date Fri, 28 Oct 2016 15:20:58 +0100
parents e6c798c9bc91
children 6796afa25c88
comparison
equal deleted inserted replaced
1152:fc00a06feecd 1159:8a5f0c8d5608
45 } 45 }
46 46
47 void 47 void
48 WindowShapePreview::updateLabels() 48 WindowShapePreview::updateLabels()
49 { 49 {
50 int step = 24; 50 float scaleRatio = float(QFontMetrics(font()).height()) / 14.f;
51 float peak = 48; 51 if (scaleRatio < 1.f) scaleRatio = 1.f;
52 int w = step * 4, h = 64; 52
53 int step = int(24 * scaleRatio);
54 float peak = float(48 * scaleRatio);
55
56 int w = step * 4, h = int((peak * 4) / 3);
57
53 WindowType type = m_windowType; 58 WindowType type = m_windowType;
54 Window<float> windower = Window<float>(type, step * 2); 59 Window<float> windower = Window<float>(type, step * 2);
55 60
56 QPixmap timeLabel(w, h + 1); 61 QPixmap timeLabel(w, h + 1);
57 timeLabel.fill(Qt::white); 62 timeLabel.fill(Qt::white);
58 QPainter timePainter(&timeLabel); 63 QPainter timePainter(&timeLabel);
59 64
60 QPainterPath path; 65 QPainterPath path;
66 timePainter.setRenderHint(QPainter::Antialiasing, true); 71 timePainter.setRenderHint(QPainter::Antialiasing, true);
67 timePainter.drawPath(path); 72 timePainter.drawPath(path);
68 73
69 path = QPainterPath(); 74 path = QPainterPath();
70 75
71 float *acc = new float(w); 76 float *acc = new float[w];
72 for (int i = 0; i < w; ++i) acc[i] = 0.f; 77 for (int i = 0; i < w; ++i) acc[i] = 0.f;
73 for (int j = 0; j < 3; ++j) { 78 for (int j = 0; j < 3; ++j) {
74 for (int i = 0; i < step * 2; ++i) { 79 for (int i = 0; i < step * 2; ++i) {
75 acc[j * step + i] += windower.getValue(i); 80 acc[j * step + i] += windower.getValue(i);
76 } 81 }
103 timePainter.setRenderHint(QPainter::Antialiasing, true); 108 timePainter.setRenderHint(QPainter::Antialiasing, true);
104 path.addRect(0, 0, w, h + 1); 109 path.addRect(0, 0, w, h + 1);
105 timePainter.drawPath(path); 110 timePainter.drawPath(path);
106 111
107 QFont font; 112 QFont font;
108 font.setPixelSize(10); 113 font.setPixelSize(int(10 * scaleRatio));
109 font.setItalic(true); 114 font.setItalic(true);
110 timePainter.setFont(font); 115 timePainter.setFont(font);
111 QString label = tr("V / time"); 116 QString label = tr("V / time");
112 timePainter.drawText(w - timePainter.fontMetrics().width(label) - 4, 117 timePainter.drawText(w - timePainter.fontMetrics().width(label) - 4,
113 timePainter.fontMetrics().ascent() + 1, label); 118 timePainter.fontMetrics().ascent() + 1, label);
114 119
115 m_windowTimeExampleLabel->setPixmap(timeLabel); 120 m_windowTimeExampleLabel->setPixmap(timeLabel);
116 121
117 int fw = 100; 122 QPixmap freqLabel(w, h + 1);
118
119 QPixmap freqLabel(fw, h + 1);
120 freqLabel.fill(Qt::white); 123 freqLabel.fill(Qt::white);
121 QPainter freqPainter(&freqLabel); 124 QPainter freqPainter(&freqLabel);
122 path = QPainterPath(); 125 path = QPainterPath();
123 126
124 int fftsize = 512; 127 int fftsize = 512;
159 float maxval = maxdb + -mindb; 162 float maxval = maxdb + -mindb;
160 163
161 // float ly = h - ((-80.f + -mindb) / maxval) * peak + 1; 164 // float ly = h - ((-80.f + -mindb) / maxval) * peak + 1;
162 165
163 path.moveTo(0, float(h) - peak + 1); 166 path.moveTo(0, float(h) - peak + 1);
164 path.lineTo(fw, float(h) - peak + 1); 167 path.lineTo(w, float(h) - peak + 1);
165 168
166 freqPainter.setPen(Qt::gray); 169 freqPainter.setPen(Qt::gray);
167 freqPainter.setRenderHint(QPainter::Antialiasing, true); 170 freqPainter.setRenderHint(QPainter::Antialiasing, true);
168 freqPainter.drawPath(path); 171 freqPainter.drawPath(path);
169 172
176 float power = output[i][0] * output[i][0] + output[i][1] * output[i][1]; 179 float power = output[i][0] * output[i][0] + output[i][1] * output[i][1];
177 float db = 20.f * log10f(power); 180 float db = 20.f * log10f(power);
178 float val = db + -mindb; 181 float val = db + -mindb;
179 if (val < 0) val = 0; 182 if (val < 0) val = 0;
180 float norm = val / maxval; 183 float norm = val / maxval;
181 float x = (float(fw) / float(fftsize/2)) * float(i); 184 float x = (float(w) / float(fftsize/2)) * float(i);
182 float y = float(h) - norm * peak + 1; 185 float y = float(h) - norm * peak + 1;
183 if (i == 0) path.moveTo(x, y); 186 if (i == 0) path.moveTo(x, y);
184 else path.lineTo(x, y); 187 else path.lineTo(x, y);
185 } 188 }
186 189
187 freqPainter.setRenderHint(QPainter::Antialiasing, true); 190 freqPainter.setRenderHint(QPainter::Antialiasing, true);
188 path.addRect(0, 0, fw, h + 1); 191 path.addRect(0, 0, w, h + 1);
189 freqPainter.drawPath(path); 192 freqPainter.drawPath(path);
190 193
191 fftf_free(input); 194 fftf_free(input);
192 fftf_free(output); 195 fftf_free(output);
193 196
194 freqPainter.setFont(font); 197 freqPainter.setFont(font);
195 label = tr("dB / freq"); 198 label = tr("dB / freq");
196 freqPainter.drawText(fw - freqPainter.fontMetrics().width(label) - 4, 199 freqPainter.drawText(w - freqPainter.fontMetrics().width(label) - 4,
197 freqPainter.fontMetrics().ascent() + 1, label); 200 freqPainter.fontMetrics().ascent() + 1, label);
198 201
199 m_windowFreqExampleLabel->setPixmap(freqLabel); 202 m_windowFreqExampleLabel->setPixmap(freqLabel);
200 } 203 }
201 204