Mercurial > hg > svgui
comparison layer/SliceLayer.cpp @ 906:12ab113ca2b1 cxx11
A few more fixes
author | Chris Cannam |
---|---|
date | Mon, 09 Mar 2015 15:59:04 +0000 |
parents | 312b92ffb04e |
children | 94e4952a6774 |
comparison
equal
deleted
inserted
replaced
905:b66fb15de477 | 906:12ab113ca2b1 |
---|---|
117 if (minbin >= mh) minbin = mh - 1; | 117 if (minbin >= mh) minbin = mh - 1; |
118 if (maxbin >= mh) maxbin = mh - 1; | 118 if (maxbin >= mh) maxbin = mh - 1; |
119 if (minbin < 0) minbin = 0; | 119 if (minbin < 0) minbin = 0; |
120 if (maxbin < 0) maxbin = 0; | 120 if (maxbin < 0) maxbin = 0; |
121 | 121 |
122 int sampleRate = m_sliceableModel->getSampleRate(); | 122 sv_samplerate_t sampleRate = m_sliceableModel->getSampleRate(); |
123 | 123 |
124 int f0 = m_currentf0; | 124 sv_frame_t f0 = m_currentf0; |
125 int f1 = m_currentf1; | 125 sv_frame_t f1 = m_currentf1; |
126 | 126 |
127 RealTime rt0 = RealTime::frame2RealTime(f0, sampleRate); | 127 RealTime rt0 = RealTime::frame2RealTime(f0, sampleRate); |
128 RealTime rt1 = RealTime::frame2RealTime(f1, sampleRate); | 128 RealTime rt1 = RealTime::frame2RealTime(f1, sampleRate); |
129 | 129 |
130 range = f1 - f0 + 1; | 130 range = int(f1 - f0 + 1); |
131 | 131 |
132 QString rtrangestr = QString("%1 s").arg((rt1 - rt0).toText().c_str()); | 132 QString rtrangestr = QString("%1 s").arg((rt1 - rt0).toText().c_str()); |
133 | 133 |
134 if (includeBinDescription) { | 134 if (includeBinDescription) { |
135 | 135 |
136 float minvalue = 0.f; | 136 float minvalue = 0.0; |
137 if (minbin < int(m_values.size())) minvalue = m_values[minbin]; | 137 if (minbin < int(m_values.size())) minvalue = m_values[minbin]; |
138 | 138 |
139 float maxvalue = minvalue; | 139 float maxvalue = minvalue; |
140 if (maxbin < int(m_values.size())) maxvalue = m_values[maxbin]; | 140 if (maxbin < int(m_values.size())) maxvalue = m_values[maxbin]; |
141 | 141 |
177 | 177 |
178 return description; | 178 return description; |
179 } | 179 } |
180 } | 180 } |
181 | 181 |
182 float | 182 double |
183 SliceLayer::getXForBin(int bin, int count, float w) const | 183 SliceLayer::getXForBin(int bin, int count, double w) const |
184 { | 184 { |
185 float x = 0; | 185 double x = 0; |
186 | 186 |
187 switch (m_binScale) { | 187 switch (m_binScale) { |
188 | 188 |
189 case LinearBins: | 189 case LinearBins: |
190 x = (float(w) * bin) / count; | 190 x = (w * bin) / count; |
191 break; | 191 break; |
192 | 192 |
193 case LogBins: | 193 case LogBins: |
194 x = (float(w) * log10f(bin + 1)) / log10f(count + 1); | 194 x = (w * log10(bin + 1)) / log10(count + 1); |
195 break; | 195 break; |
196 | 196 |
197 case InvertedLogBins: | 197 case InvertedLogBins: |
198 x = w - (float(w) * log10f(count - bin - 1)) / log10f(count); | 198 x = w - (w * log10(count - bin - 1)) / log10(count); |
199 break; | 199 break; |
200 } | 200 } |
201 | 201 |
202 return x; | 202 return x; |
203 } | 203 } |
204 | 204 |
205 int | 205 int |
206 SliceLayer::getBinForX(float x, int count, float w) const | 206 SliceLayer::getBinForX(double x, int count, double w) const |
207 { | 207 { |
208 int bin = 0; | 208 int bin = 0; |
209 | 209 |
210 switch (m_binScale) { | 210 switch (m_binScale) { |
211 | 211 |
212 case LinearBins: | 212 case LinearBins: |
213 bin = int((x * count) / w + 0.0001); | 213 bin = int((x * count) / w + 0.0001); |
214 break; | 214 break; |
215 | 215 |
216 case LogBins: | 216 case LogBins: |
217 bin = int(powf(10.f, (x * log10f(count + 1)) / w) - 1 + 0.0001); | 217 bin = int(pow(10.0, (x * log10(count + 1)) / w) - 1 + 0.0001); |
218 break; | 218 break; |
219 | 219 |
220 case InvertedLogBins: | 220 case InvertedLogBins: |
221 bin = count + 1 - int(powf(10.f, (log10f(count) * (w - x)) / float(w)) + 0.0001); | 221 bin = count + 1 - int(pow(10.0, (log10(count) * (w - x)) / double(w)) + 0.0001); |
222 break; | 222 break; |
223 } | 223 } |
224 | 224 |
225 return bin; | 225 return bin; |
226 } | 226 } |
227 | 227 |
228 float | 228 double |
229 SliceLayer::getYForValue(float value, const View *v, float &norm) const | 229 SliceLayer::getYForValue(double value, const View *v, double &norm) const |
230 { | 230 { |
231 norm = 0.f; | 231 norm = 0.0; |
232 | 232 |
233 if (m_yorigins.find(v) == m_yorigins.end()) return 0; | 233 if (m_yorigins.find(v) == m_yorigins.end()) return 0; |
234 | 234 |
235 value *= m_gain; | 235 value *= m_gain; |
236 | 236 |
237 int yorigin = m_yorigins[v]; | 237 int yorigin = m_yorigins[v]; |
238 int h = m_heights[v]; | 238 int h = m_heights[v]; |
239 float thresh = getThresholdDb(); | 239 double thresh = getThresholdDb(); |
240 | 240 |
241 float y = 0.f; | 241 double y = 0.0; |
242 | 242 |
243 if (h <= 0) return y; | 243 if (h <= 0) return y; |
244 | 244 |
245 switch (m_energyScale) { | 245 switch (m_energyScale) { |
246 | 246 |
247 case dBScale: | 247 case dBScale: |
248 { | 248 { |
249 float db = thresh; | 249 double db = thresh; |
250 if (value > 0.f) db = 10.f * log10f(fabsf(value)); | 250 if (value > 0.0) db = 10.0 * log10(fabs(value)); |
251 if (db < thresh) db = thresh; | 251 if (db < thresh) db = thresh; |
252 norm = (db - thresh) / -thresh; | 252 norm = (db - thresh) / -thresh; |
253 y = yorigin - (float(h) * norm); | 253 y = yorigin - (double(h) * norm); |
254 break; | 254 break; |
255 } | 255 } |
256 | 256 |
257 case MeterScale: | 257 case MeterScale: |
258 y = AudioLevel::multiplier_to_preview(value, h); | 258 y = AudioLevel::multiplier_to_preview(value, h); |
259 norm = float(y) / float(h); | 259 norm = double(y) / double(h); |
260 y = yorigin - y; | 260 y = yorigin - y; |
261 break; | 261 break; |
262 | 262 |
263 case AbsoluteScale: | 263 case AbsoluteScale: |
264 value = fabsf(value); | 264 value = fabs(value); |
265 // and fall through | 265 // and fall through |
266 | 266 |
267 case LinearScale: | 267 case LinearScale: |
268 default: | 268 default: |
269 norm = (value - m_threshold); | 269 norm = (value - m_threshold); |
270 if (norm < 0) norm = 0; | 270 if (norm < 0) norm = 0; |
271 y = yorigin - (float(h) * norm); | 271 y = yorigin - (double(h) * norm); |
272 break; | 272 break; |
273 } | 273 } |
274 | 274 |
275 return y; | 275 return y; |
276 } | 276 } |
277 | 277 |
278 float | 278 double |
279 SliceLayer::getValueForY(float y, const View *v) const | 279 SliceLayer::getValueForY(double y, const View *v) const |
280 { | 280 { |
281 float value = 0.f; | 281 double value = 0.0; |
282 | 282 |
283 if (m_yorigins.find(v) == m_yorigins.end()) return value; | 283 if (m_yorigins.find(v) == m_yorigins.end()) return value; |
284 | 284 |
285 int yorigin = m_yorigins[v]; | 285 int yorigin = m_yorigins[v]; |
286 int h = m_heights[v]; | 286 int h = m_heights[v]; |
287 float thresh = getThresholdDb(); | 287 double thresh = getThresholdDb(); |
288 | 288 |
289 if (h <= 0) return value; | 289 if (h <= 0) return value; |
290 | 290 |
291 y = yorigin - y; | 291 y = yorigin - y; |
292 | 292 |
293 switch (m_energyScale) { | 293 switch (m_energyScale) { |
294 | 294 |
295 case dBScale: | 295 case dBScale: |
296 { | 296 { |
297 float db = ((y / h) * -thresh) + thresh; | 297 double db = ((y / h) * -thresh) + thresh; |
298 value = powf(10.f, db/10.f); | 298 value = pow(10.0, db/10.0); |
299 break; | 299 break; |
300 } | 300 } |
301 | 301 |
302 case MeterScale: | 302 case MeterScale: |
303 value = AudioLevel::preview_to_multiplier(lrintf(y), h); | 303 value = AudioLevel::preview_to_multiplier(int(lrint(y)), h); |
304 break; | 304 break; |
305 | 305 |
306 case LinearScale: | 306 case LinearScale: |
307 case AbsoluteScale: | 307 case AbsoluteScale: |
308 default: | 308 default: |
352 | 352 |
353 int divisor = 0; | 353 int divisor = 0; |
354 | 354 |
355 m_values.clear(); | 355 m_values.clear(); |
356 for (int bin = 0; bin < mh; ++bin) { | 356 for (int bin = 0; bin < mh; ++bin) { |
357 m_values.push_back(0.f); | 357 m_values.push_back(0.0); |
358 } | 358 } |
359 | 359 |
360 int f0 = v->getCentreFrame(); | 360 sv_frame_t f0 = v->getCentreFrame(); |
361 int f0x = v->getXForFrame(f0); | 361 int f0x = v->getXForFrame(f0); |
362 f0 = v->getFrameForX(f0x); | 362 f0 = v->getFrameForX(f0x); |
363 int f1 = v->getFrameForX(f0x + 1); | 363 sv_frame_t f1 = v->getFrameForX(f0x + 1); |
364 if (f1 > f0) --f1; | 364 if (f1 > f0) --f1; |
365 | 365 |
366 // cerr << "centre frame " << v->getCentreFrame() << ", x " << f0x << ", f0 " << f0 << ", f1 " << f1 << endl; | 366 // cerr << "centre frame " << v->getCentreFrame() << ", x " << f0x << ", f0 " << f0 << ", f1 " << f1 << endl; |
367 | 367 |
368 int res = m_sliceableModel->getResolution(); | 368 int res = m_sliceableModel->getResolution(); |
369 int col0 = f0 / res; | 369 int col0 = int(f0 / res); |
370 int col1 = col0; | 370 int col1 = col0; |
371 if (m_samplingMode != NearestSample) col1 = f1 / res; | 371 if (m_samplingMode != NearestSample) col1 = int(f1 / res); |
372 f0 = col0 * res; | 372 f0 = col0 * res; |
373 f1 = (col1 + 1) * res - 1; | 373 f1 = (col1 + 1) * res - 1; |
374 | 374 |
375 // cerr << "resolution " << res << ", col0 " << col0 << ", col1 " << col1 << ", f0 " << f0 << ", f1 " << f1 << endl; | 375 // cerr << "resolution " << res << ", col0 " << col0 << ", col1 " << col1 << ", f0 " << f0 << ", f1 " << f1 << endl; |
376 | 376 |
377 m_currentf0 = f0; | 377 m_currentf0 = f0; |
378 m_currentf1 = f1; | 378 m_currentf1 = f1; |
379 | 379 |
380 BiasCurve curve; | 380 BiasCurve curve; |
381 getBiasCurve(curve); | 381 getBiasCurve(curve); |
382 int cs = curve.size(); | 382 int cs = int(curve.size()); |
383 | 383 |
384 for (int col = col0; col <= col1; ++col) { | 384 for (int col = col0; col <= col1; ++col) { |
385 for (int bin = 0; bin < mh; ++bin) { | 385 for (int bin = 0; bin < mh; ++bin) { |
386 float value = m_sliceableModel->getValueAt(col, bin); | 386 float value = m_sliceableModel->getValueAt(col, bin); |
387 if (bin < cs) value *= curve[bin]; | 387 if (bin < cs) value *= curve[bin]; |
392 } | 392 } |
393 } | 393 } |
394 ++divisor; | 394 ++divisor; |
395 } | 395 } |
396 | 396 |
397 float max = 0.f; | 397 float max = 0.0; |
398 for (int bin = 0; bin < mh; ++bin) { | 398 for (int bin = 0; bin < mh; ++bin) { |
399 if (m_samplingMode == SampleMean && divisor > 0) { | 399 if (m_samplingMode == SampleMean && divisor > 0) { |
400 m_values[bin] /= divisor; | 400 m_values[bin] /= float(divisor); |
401 } | 401 } |
402 if (m_values[bin] > max) max = m_values[bin]; | 402 if (m_values[bin] > max) max = m_values[bin]; |
403 } | 403 } |
404 if (max != 0.f && m_normalize) { | 404 if (max != 0.0 && m_normalize) { |
405 for (int bin = 0; bin < mh; ++bin) { | 405 for (int bin = 0; bin < mh; ++bin) { |
406 m_values[bin] /= max; | 406 m_values[bin] /= max; |
407 } | 407 } |
408 } | 408 } |
409 | 409 |
410 float nx = xorigin; | 410 double nx = xorigin; |
411 | 411 |
412 ColourMapper mapper(m_colourMap, 0, 1); | 412 ColourMapper mapper(m_colourMap, 0, 1); |
413 | 413 |
414 for (int bin = 0; bin < mh; ++bin) { | 414 for (int bin = 0; bin < mh; ++bin) { |
415 | 415 |
416 float x = nx; | 416 double x = nx; |
417 nx = xorigin + getXForBin(bin + 1, mh, w); | 417 nx = xorigin + getXForBin(bin + 1, mh, w); |
418 | 418 |
419 float value = m_values[bin]; | 419 double value = m_values[bin]; |
420 float norm = 0.f; | 420 double norm = 0.0; |
421 float y = getYForValue(value, v, norm); | 421 double y = getYForValue(value, v, norm); |
422 | 422 |
423 if (m_plotStyle == PlotLines) { | 423 if (m_plotStyle == PlotLines) { |
424 | 424 |
425 if (bin == 0) { | 425 if (bin == 0) { |
426 path.moveTo(x, y); | 426 path.moveTo(x, y); |
513 } | 513 } |
514 | 514 |
515 void | 515 void |
516 SliceLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const | 516 SliceLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const |
517 { | 517 { |
518 float thresh = m_threshold; | 518 double thresh = m_threshold; |
519 if (m_energyScale != LinearScale && m_energyScale != AbsoluteScale) { | 519 if (m_energyScale != LinearScale && m_energyScale != AbsoluteScale) { |
520 thresh = AudioLevel::dB_to_multiplier(getThresholdDb()); | 520 thresh = AudioLevel::dB_to_multiplier(getThresholdDb()); |
521 } | 521 } |
522 | 522 |
523 // int h = (rect.height() * 3) / 4; | 523 // int h = (rect.height() * 3) / 4; |
536 PaintAssistant::Scale(m_energyScale), | 536 PaintAssistant::Scale(m_energyScale), |
537 mult, | 537 mult, |
538 const_cast<std::vector<int> *>(&m_scalePoints)); | 538 const_cast<std::vector<int> *>(&m_scalePoints)); |
539 | 539 |
540 if (mult != 1 && mult != 0) { | 540 if (mult != 1 && mult != 0) { |
541 int log = lrintf(log10f(mult)); | 541 int log = int(lrint(log10(mult))); |
542 QString a = tr("x10"); | 542 QString a = tr("x10"); |
543 QString b = QString("%1").arg(-log); | 543 QString b = QString("%1").arg(-log); |
544 paint.drawText(3, 8 + paint.fontMetrics().ascent(), a); | 544 paint.drawText(3, 8 + paint.fontMetrics().ascent(), a); |
545 paint.drawText(3 + paint.fontMetrics().width(a), | 545 paint.drawText(3 + paint.fontMetrics().width(a), |
546 3 + paint.fontMetrics().ascent(), b); | 546 3 + paint.fontMetrics().ascent(), b); |
625 *max = 50; | 625 *max = 50; |
626 *deflt = 0; | 626 *deflt = 0; |
627 | 627 |
628 cerr << "gain is " << m_gain << ", mode is " << m_samplingMode << endl; | 628 cerr << "gain is " << m_gain << ", mode is " << m_samplingMode << endl; |
629 | 629 |
630 val = lrint(log10(m_gain) * 20.0); | 630 val = int(lrint(log10(m_gain) * 20.0)); |
631 if (val < *min) val = *min; | 631 if (val < *min) val = *min; |
632 if (val > *max) val = *max; | 632 if (val > *max) val = *max; |
633 | 633 |
634 } else if (name == "Threshold") { | 634 } else if (name == "Threshold") { |
635 | 635 |
636 *min = -80; | 636 *min = -80; |
637 *max = 0; | 637 *max = 0; |
638 | 638 |
639 *deflt = lrintf(AudioLevel::multiplier_to_dB(m_initialThreshold)); | 639 *deflt = int(lrint(AudioLevel::multiplier_to_dB(m_initialThreshold))); |
640 if (*deflt < *min) *deflt = *min; | 640 if (*deflt < *min) *deflt = *min; |
641 if (*deflt > *max) *deflt = *max; | 641 if (*deflt > *max) *deflt = *max; |
642 | 642 |
643 val = lrintf(AudioLevel::multiplier_to_dB(m_threshold)); | 643 val = int(lrint(AudioLevel::multiplier_to_dB(m_threshold))); |
644 if (val < *min) val = *min; | 644 if (val < *min) val = *min; |
645 if (val > *max) val = *max; | 645 if (val > *max) val = *max; |
646 | 646 |
647 } else if (name == "Normalize") { | 647 } else if (name == "Normalize") { |
648 | 648 |
755 | 755 |
756 void | 756 void |
757 SliceLayer::setProperty(const PropertyName &name, int value) | 757 SliceLayer::setProperty(const PropertyName &name, int value) |
758 { | 758 { |
759 if (name == "Gain") { | 759 if (name == "Gain") { |
760 setGain(pow(10, float(value)/20.0)); | 760 setGain(powf(10, float(value)/20.0f)); |
761 } else if (name == "Threshold") { | 761 } else if (name == "Threshold") { |
762 if (value == -80) setThreshold(0.0); | 762 if (value == -80) setThreshold(0.0f); |
763 else setThreshold(AudioLevel::dB_to_multiplier(value)); | 763 else setThreshold(float(AudioLevel::dB_to_multiplier(value))); |
764 } else if (name == "Colour" && m_plotStyle == PlotFilledBlocks) { | 764 } else if (name == "Colour" && m_plotStyle == PlotFilledBlocks) { |
765 setFillColourMap(value); | 765 setFillColourMap(value); |
766 } else if (name == "Scale") { | 766 } else if (name == "Scale") { |
767 switch (value) { | 767 switch (value) { |
768 default: | 768 default: |
865 | 865 |
866 float | 866 float |
867 SliceLayer::getThresholdDb() const | 867 SliceLayer::getThresholdDb() const |
868 { | 868 { |
869 if (m_threshold == 0.0) return -80.f; | 869 if (m_threshold == 0.0) return -80.f; |
870 float db = AudioLevel::multiplier_to_dB(m_threshold); | 870 float db = float(AudioLevel::multiplier_to_dB(m_threshold)); |
871 return db; | 871 return db; |
872 } | 872 } |
873 | 873 |
874 int | 874 int |
875 SliceLayer::getDefaultColourHint(bool darkbg, bool &impose) | 875 SliceLayer::getDefaultColourHint(bool darkbg, bool &impose) |
940 bool normalize = (attributes.value("normalize").trimmed() == "true"); | 940 bool normalize = (attributes.value("normalize").trimmed() == "true"); |
941 setNormalize(normalize); | 941 setNormalize(normalize); |
942 } | 942 } |
943 | 943 |
944 bool | 944 bool |
945 SliceLayer::getValueExtents(float &, float &, bool &, QString &) const | 945 SliceLayer::getValueExtents(double &, double &, bool &, QString &) const |
946 { | 946 { |
947 return false; | 947 return false; |
948 } | 948 } |
949 | 949 |