Mercurial > hg > svgui
comparison layer/SliceLayer.cpp @ 538:3bf74851d93e
* A few minor fixes to SliceLayer based on using it for slices of key plots
author | Chris Cannam |
---|---|
date | Fri, 05 Jun 2009 16:08:18 +0000 |
parents | e1a9e478b7f2 |
children | f4960f8ce798 |
comparison
equal
deleted
inserted
replaced
537:0cc658fe1423 | 538:3bf74851d93e |
---|---|
1 | |
2 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ |
3 | 2 |
4 /* | 3 /* |
5 Sonic Visualiser | 4 Sonic Visualiser |
6 An audio file viewer and annotation editor. | 5 An audio file viewer and annotation editor. |
246 switch (m_energyScale) { | 245 switch (m_energyScale) { |
247 | 246 |
248 case dBScale: | 247 case dBScale: |
249 { | 248 { |
250 float db = thresh; | 249 float db = thresh; |
251 if (value > 0.f) db = 10.f * log10f(value); | 250 if (value > 0.f) db = 10.f * log10f(fabsf(value)); |
252 if (db < thresh) db = thresh; | 251 if (db < thresh) db = thresh; |
253 norm = (db - thresh) / -thresh; | 252 norm = (db - thresh) / -thresh; |
254 y = yorigin - (float(h) * norm); | 253 y = yorigin - (float(h) * norm); |
255 break; | 254 break; |
256 } | 255 } |
259 y = AudioLevel::multiplier_to_preview(value, h); | 258 y = AudioLevel::multiplier_to_preview(value, h); |
260 norm = float(y) / float(h); | 259 norm = float(y) / float(h); |
261 y = yorigin - y; | 260 y = yorigin - y; |
262 break; | 261 break; |
263 | 262 |
263 case AbsoluteScale: | |
264 value = fabsf(value); | |
265 // and fall through | |
266 | |
264 default: | 267 default: |
265 // std::cerr << "thresh = " << m_threshold << std::endl; | 268 norm = (value - m_threshold); |
266 norm = (fabsf(value) - m_threshold); | |
267 if (norm < 0) norm = 0; | 269 if (norm < 0) norm = 0; |
268 y = yorigin - (float(h) * norm); | 270 y = yorigin - (float(h) * norm); |
269 break; | 271 break; |
270 } | 272 } |
271 | 273 |
297 } | 299 } |
298 | 300 |
299 case MeterScale: | 301 case MeterScale: |
300 value = AudioLevel::preview_to_multiplier(lrintf(y), h); | 302 value = AudioLevel::preview_to_multiplier(lrintf(y), h); |
301 break; | 303 break; |
302 | 304 |
303 default: | 305 default: |
304 value = y / h + m_threshold; | 306 value = y / h + m_threshold; |
305 } | 307 } |
306 | 308 |
307 return value / m_gain; | 309 return value / m_gain; |
313 if (!m_sliceableModel || !m_sliceableModel->isOK() || | 315 if (!m_sliceableModel || !m_sliceableModel->isOK() || |
314 !m_sliceableModel->isReady()) return; | 316 !m_sliceableModel->isReady()) return; |
315 | 317 |
316 paint.save(); | 318 paint.save(); |
317 paint.setRenderHint(QPainter::Antialiasing, false); | 319 paint.setRenderHint(QPainter::Antialiasing, false); |
320 paint.setBrush(Qt::NoBrush); | |
318 | 321 |
319 if (v->getViewManager() && v->getViewManager()->shouldShowScaleGuides()) { | 322 if (v->getViewManager() && v->getViewManager()->shouldShowScaleGuides()) { |
320 if (!m_scalePoints.empty()) { | 323 if (!m_scalePoints.empty()) { |
321 paint.setPen(QColor(240, 240, 240)); //!!! and dark background? | 324 paint.setPen(QColor(240, 240, 240)); //!!! and dark background? |
322 for (size_t i = 0; i < m_scalePoints.size(); ++i) { | 325 for (size_t i = 0; i < m_scalePoints.size(); ++i) { |
495 } | 498 } |
496 | 499 |
497 int | 500 int |
498 SliceLayer::getVerticalScaleWidth(View *, QPainter &paint) const | 501 SliceLayer::getVerticalScaleWidth(View *, QPainter &paint) const |
499 { | 502 { |
500 if (m_energyScale == LinearScale) { | 503 if (m_energyScale == LinearScale || m_energyScale == AbsoluteScale) { |
501 return std::max(paint.fontMetrics().width("0.0") + 13, | 504 return std::max(paint.fontMetrics().width("0.0") + 13, |
502 paint.fontMetrics().width("x10-10")); | 505 paint.fontMetrics().width("x10-10")); |
503 } else { | 506 } else { |
504 return std::max(paint.fontMetrics().width(tr("0dB")), | 507 return std::max(paint.fontMetrics().width(tr("0dB")), |
505 paint.fontMetrics().width(tr("-Inf"))) + 13; | 508 paint.fontMetrics().width(tr("-Inf"))) + 13; |
508 | 511 |
509 void | 512 void |
510 SliceLayer::paintVerticalScale(View *v, QPainter &paint, QRect rect) const | 513 SliceLayer::paintVerticalScale(View *v, QPainter &paint, QRect rect) const |
511 { | 514 { |
512 float thresh = m_threshold; | 515 float thresh = m_threshold; |
513 if (m_energyScale != LinearScale) { | 516 if (m_energyScale != LinearScale && m_energyScale != AbsoluteScale) { |
514 thresh = AudioLevel::dB_to_multiplier(getThresholdDb()); | 517 thresh = AudioLevel::dB_to_multiplier(getThresholdDb()); |
515 } | 518 } |
516 | 519 |
517 // int h = (rect.height() * 3) / 4; | 520 // int h = (rect.height() * 3) / 4; |
518 // int y = (rect.height() / 2) - (h / 2); | 521 // int y = (rect.height() / 2) - (h / 2); |
543 | 546 |
544 Layer::PropertyList | 547 Layer::PropertyList |
545 SliceLayer::getProperties() const | 548 SliceLayer::getProperties() const |
546 { | 549 { |
547 PropertyList list = SingleColourLayer::getProperties(); | 550 PropertyList list = SingleColourLayer::getProperties(); |
551 list.push_back("Bin Scale"); | |
548 list.push_back("Plot Type"); | 552 list.push_back("Plot Type"); |
549 // list.push_back("Sampling Mode"); | |
550 list.push_back("Scale"); | 553 list.push_back("Scale"); |
551 list.push_back("Normalize"); | 554 list.push_back("Normalize"); |
552 list.push_back("Threshold"); | 555 list.push_back("Threshold"); |
553 list.push_back("Gain"); | 556 list.push_back("Gain"); |
554 list.push_back("Bin Scale"); | |
555 | 557 |
556 return list; | 558 return list; |
557 } | 559 } |
558 | 560 |
559 QString | 561 QString |
563 if (name == "Scale") return tr("Scale"); | 565 if (name == "Scale") return tr("Scale"); |
564 if (name == "Normalize") return tr("Normalize"); | 566 if (name == "Normalize") return tr("Normalize"); |
565 if (name == "Threshold") return tr("Threshold"); | 567 if (name == "Threshold") return tr("Threshold"); |
566 if (name == "Gain") return tr("Gain"); | 568 if (name == "Gain") return tr("Gain"); |
567 if (name == "Sampling Mode") return tr("Sampling Mode"); | 569 if (name == "Sampling Mode") return tr("Sampling Mode"); |
568 if (name == "Bin Scale") return tr("Plot X Scale"); | 570 if (name == "Bin Scale") return tr("Bin Scale"); |
569 return SingleColourLayer::getPropertyLabel(name); | 571 return SingleColourLayer::getPropertyLabel(name); |
570 } | 572 } |
571 | 573 |
572 QString | 574 QString |
573 SliceLayer::getPropertyIconName(const PropertyName &name) const | 575 SliceLayer::getPropertyIconName(const PropertyName &name) const |
597 name == "Normalize" || | 599 name == "Normalize" || |
598 name == "Sampling Mode" || | 600 name == "Sampling Mode" || |
599 name == "Threshold" || | 601 name == "Threshold" || |
600 name == "Gain") return tr("Scale"); | 602 name == "Gain") return tr("Scale"); |
601 if (name == "Plot Type" || | 603 if (name == "Plot Type" || |
602 name == "Bin Scale") return tr("Plot Type"); | 604 name == "Bin Scale") return tr("Bins"); |
603 return SingleColourLayer::getPropertyGroupName(name); | 605 return SingleColourLayer::getPropertyGroupName(name); |
604 } | 606 } |
605 | 607 |
606 int | 608 int |
607 SliceLayer::getPropertyRangeAndValue(const PropertyName &name, | 609 SliceLayer::getPropertyRangeAndValue(const PropertyName &name, |
653 val = m_colourMap; | 655 val = m_colourMap; |
654 | 656 |
655 } else if (name == "Scale") { | 657 } else if (name == "Scale") { |
656 | 658 |
657 *min = 0; | 659 *min = 0; |
658 *max = 2; | 660 *max = 3; |
659 *deflt = (int)dBScale; | 661 *deflt = (int)dBScale; |
660 | 662 |
661 val = (int)m_energyScale; | 663 val = (int)m_energyScale; |
662 | 664 |
663 } else if (name == "Sampling Mode") { | 665 } else if (name == "Sampling Mode") { |
702 if (name == "Scale") { | 704 if (name == "Scale") { |
703 switch (value) { | 705 switch (value) { |
704 default: | 706 default: |
705 case 0: return tr("Linear"); | 707 case 0: return tr("Linear"); |
706 case 1: return tr("Meter"); | 708 case 1: return tr("Meter"); |
707 case 2: return tr("dB"); | 709 case 2: return tr("Log"); |
710 case 3: return tr("Absolute"); | |
708 } | 711 } |
709 } | 712 } |
710 if (name == "Sampling Mode") { | 713 if (name == "Sampling Mode") { |
711 switch (value) { | 714 switch (value) { |
712 default: | 715 default: |
725 } | 728 } |
726 } | 729 } |
727 if (name == "Bin Scale") { | 730 if (name == "Bin Scale") { |
728 switch (value) { | 731 switch (value) { |
729 default: | 732 default: |
730 case 0: return tr("Linear Bins"); | 733 case 0: return tr("Linear"); |
731 case 1: return tr("Log Bins"); | 734 case 1: return tr("Log"); |
732 case 2: return tr("Rev Log Bins"); | 735 case 2: return tr("Rev Log"); |
733 } | 736 } |
734 } | 737 } |
735 return SingleColourLayer::getPropertyValueLabel(name, value); | 738 return SingleColourLayer::getPropertyValueLabel(name, value); |
736 } | 739 } |
737 | 740 |
761 switch (value) { | 764 switch (value) { |
762 default: | 765 default: |
763 case 0: setEnergyScale(LinearScale); break; | 766 case 0: setEnergyScale(LinearScale); break; |
764 case 1: setEnergyScale(MeterScale); break; | 767 case 1: setEnergyScale(MeterScale); break; |
765 case 2: setEnergyScale(dBScale); break; | 768 case 2: setEnergyScale(dBScale); break; |
769 case 3: setEnergyScale(AbsoluteScale); break; | |
766 } | 770 } |
767 } else if (name == "Plot Type") { | 771 } else if (name == "Plot Type") { |
768 setPlotStyle(PlotStyle(value)); | 772 setPlotStyle(PlotStyle(value)); |
769 } else if (name == "Sampling Mode") { | 773 } else if (name == "Sampling Mode") { |
770 switch (value) { | 774 switch (value) { |