comparison layer/SliceLayer.cpp @ 1266:a34a2a25907c

Untabify
author Chris Cannam
date Thu, 01 Mar 2018 18:02:22 +0000
parents 5f68f5c74904
children fc9d9f1103fa
comparison
equal deleted inserted replaced
1265:6e724c81f18f 1266:a34a2a25907c
505 int 505 int
506 SliceLayer::getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &paint) const 506 SliceLayer::getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &paint) const
507 { 507 {
508 int width; 508 int width;
509 if (m_energyScale == LinearScale || m_energyScale == AbsoluteScale) { 509 if (m_energyScale == LinearScale || m_energyScale == AbsoluteScale) {
510 width = std::max(paint.fontMetrics().width("0.0") + 13, 510 width = std::max(paint.fontMetrics().width("0.0") + 13,
511 paint.fontMetrics().width("x10-10")); 511 paint.fontMetrics().width("x10-10"));
512 } else { 512 } else {
513 width = std::max(paint.fontMetrics().width(tr("0dB")), 513 width = std::max(paint.fontMetrics().width(tr("0dB")),
514 paint.fontMetrics().width(tr("-Inf"))) + 13; 514 paint.fontMetrics().width(tr("-Inf"))) + 13;
515 } 515 }
623 if (!max) max = &garbage1; 623 if (!max) max = &garbage1;
624 if (!deflt) deflt = &garbage2; 624 if (!deflt) deflt = &garbage2;
625 625
626 if (name == "Gain") { 626 if (name == "Gain") {
627 627
628 *min = -50; 628 *min = -50;
629 *max = 50; 629 *max = 50;
630 *deflt = 0; 630 *deflt = 0;
631 631
632 // cerr << "gain is " << m_gain << ", mode is " << m_samplingMode << endl; 632 // cerr << "gain is " << m_gain << ", mode is " << m_samplingMode << endl;
633 633
634 val = int(lrint(log10(m_gain) * 20.0)); 634 val = int(lrint(log10(m_gain) * 20.0));
635 if (val < *min) val = *min; 635 if (val < *min) val = *min;
636 if (val > *max) val = *max; 636 if (val > *max) val = *max;
637 637
638 } else if (name == "Threshold") { 638 } else if (name == "Threshold") {
639 639
640 *min = -80; 640 *min = -80;
641 *max = 0; 641 *max = 0;
642 642
643 *deflt = int(lrint(AudioLevel::multiplier_to_dB(m_initialThreshold))); 643 *deflt = int(lrint(AudioLevel::multiplier_to_dB(m_initialThreshold)));
644 if (*deflt < *min) *deflt = *min; 644 if (*deflt < *min) *deflt = *min;
645 if (*deflt > *max) *deflt = *max; 645 if (*deflt > *max) *deflt = *max;
646 646
647 val = int(lrint(AudioLevel::multiplier_to_dB(m_threshold))); 647 val = int(lrint(AudioLevel::multiplier_to_dB(m_threshold)));
648 if (val < *min) val = *min; 648 if (val < *min) val = *min;
649 if (val > *max) val = *max; 649 if (val > *max) val = *max;
650 650
651 } else if (name == "Normalize") { 651 } else if (name == "Normalize") {
652 652
653 val = (m_normalize ? 1 : 0); 653 val = (m_normalize ? 1 : 0);
654 *deflt = 0; 654 *deflt = 0;
655 655
656 } else if (name == "Colour" && m_plotStyle == PlotFilledBlocks) { 656 } else if (name == "Colour" && m_plotStyle == PlotFilledBlocks) {
657 657
658 *min = 0; 658 *min = 0;
661 661
662 val = m_colourMap; 662 val = m_colourMap;
663 663
664 } else if (name == "Scale") { 664 } else if (name == "Scale") {
665 665
666 *min = 0; 666 *min = 0;
667 *max = 3; 667 *max = 3;
668 *deflt = (int)dBScale; 668 *deflt = (int)dBScale;
669 669
670 val = (int)m_energyScale; 670 val = (int)m_energyScale;
671 671
672 } else if (name == "Sampling Mode") { 672 } else if (name == "Sampling Mode") {
673 673
674 *min = 0; 674 *min = 0;
675 *max = 2; 675 *max = 2;
676 *deflt = (int)SampleMean; 676 *deflt = (int)SampleMean;
677 677
678 val = (int)m_samplingMode; 678 val = (int)m_samplingMode;
679 679
680 } else if (name == "Plot Type") { 680 } else if (name == "Plot Type") {
681 681
682 *min = 0; 682 *min = 0;
683 *max = 3; 683 *max = 3;
693 // *max = 1; // I don't think we really do want to offer inverted log 693 // *max = 1; // I don't think we really do want to offer inverted log
694 694
695 val = (int)m_binScale; 695 val = (int)m_binScale;
696 696
697 } else { 697 } else {
698 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt); 698 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt);
699 } 699 }
700 700
701 return val; 701 return val;
702 } 702 }
703 703
704 QString 704 QString
705 SliceLayer::getPropertyValueLabel(const PropertyName &name, 705 SliceLayer::getPropertyValueLabel(const PropertyName &name,
706 int value) const 706 int value) const
707 { 707 {
708 if (name == "Colour" && m_plotStyle == PlotFilledBlocks) { 708 if (name == "Colour" && m_plotStyle == PlotFilledBlocks) {
709 return ColourMapper::getColourMapName(value); 709 return ColourMapper::getColourMapName(value);
710 } 710 }
711 if (name == "Scale") { 711 if (name == "Scale") {
712 switch (value) { 712 switch (value) {
713 default: 713 default:
714 case 0: return tr("Linear"); 714 case 0: return tr("Linear");
715 case 1: return tr("Meter"); 715 case 1: return tr("Meter");
716 case 2: return tr("Log"); 716 case 2: return tr("Log");
717 case 3: return tr("Absolute"); 717 case 3: return tr("Absolute");
718 } 718 }
719 } 719 }
720 if (name == "Sampling Mode") { 720 if (name == "Sampling Mode") {
721 switch (value) { 721 switch (value) {
722 default: 722 default:
723 case 0: return tr("Any"); 723 case 0: return tr("Any");
724 case 1: return tr("Mean"); 724 case 1: return tr("Mean");
725 case 2: return tr("Peak"); 725 case 2: return tr("Peak");
726 } 726 }
727 } 727 }
728 if (name == "Plot Type") { 728 if (name == "Plot Type") {
729 switch (value) { 729 switch (value) {
730 default: 730 default:
731 case 0: return tr("Lines"); 731 case 0: return tr("Lines");
732 case 1: return tr("Steps"); 732 case 1: return tr("Steps");
733 case 2: return tr("Blocks"); 733 case 2: return tr("Blocks");
734 case 3: return tr("Colours"); 734 case 3: return tr("Colours");
735 } 735 }
736 } 736 }
737 if (name == "Bin Scale") { 737 if (name == "Bin Scale") {
738 switch (value) { 738 switch (value) {
739 default: 739 default:
740 case 0: return tr("Linear"); 740 case 0: return tr("Linear");
741 case 1: return tr("Log"); 741 case 1: return tr("Log");
742 case 2: return tr("Rev Log"); 742 case 2: return tr("Rev Log");
743 } 743 }
744 } 744 }
745 return SingleColourLayer::getPropertyValueLabel(name, value); 745 return SingleColourLayer::getPropertyValueLabel(name, value);
746 } 746 }
747 747
748 RangeMapper * 748 RangeMapper *
759 759
760 void 760 void
761 SliceLayer::setProperty(const PropertyName &name, int value) 761 SliceLayer::setProperty(const PropertyName &name, int value)
762 { 762 {
763 if (name == "Gain") { 763 if (name == "Gain") {
764 setGain(powf(10, float(value)/20.0f)); 764 setGain(powf(10, float(value)/20.0f));
765 } else if (name == "Threshold") { 765 } else if (name == "Threshold") {
766 if (value == -80) setThreshold(0.0f); 766 if (value == -80) setThreshold(0.0f);
767 else setThreshold(float(AudioLevel::dB_to_multiplier(value))); 767 else setThreshold(float(AudioLevel::dB_to_multiplier(value)));
768 } else if (name == "Colour" && m_plotStyle == PlotFilledBlocks) { 768 } else if (name == "Colour" && m_plotStyle == PlotFilledBlocks) {
769 setFillColourMap(value); 769 setFillColourMap(value);
770 } else if (name == "Scale") { 770 } else if (name == "Scale") {
771 switch (value) { 771 switch (value) {
772 default: 772 default:
773 case 0: setEnergyScale(LinearScale); break; 773 case 0: setEnergyScale(LinearScale); break;
774 case 1: setEnergyScale(MeterScale); break; 774 case 1: setEnergyScale(MeterScale); break;
775 case 2: setEnergyScale(dBScale); break; 775 case 2: setEnergyScale(dBScale); break;
776 case 3: setEnergyScale(AbsoluteScale); break; 776 case 3: setEnergyScale(AbsoluteScale); break;
777 } 777 }
778 } else if (name == "Plot Type") { 778 } else if (name == "Plot Type") {
779 setPlotStyle(PlotStyle(value)); 779 setPlotStyle(PlotStyle(value));
780 } else if (name == "Sampling Mode") { 780 } else if (name == "Sampling Mode") {
781 switch (value) { 781 switch (value) {
782 default: 782 default:
783 case 0: setSamplingMode(NearestSample); break; 783 case 0: setSamplingMode(NearestSample); break;
784 case 1: setSamplingMode(SampleMean); break; 784 case 1: setSamplingMode(SampleMean); break;
785 case 2: setSamplingMode(SamplePeak); break; 785 case 2: setSamplingMode(SamplePeak); break;
786 } 786 }
787 } else if (name == "Bin Scale") { 787 } else if (name == "Bin Scale") {
788 switch (value) { 788 switch (value) {
789 default: 789 default:
790 case 0: setBinScale(LinearBins); break; 790 case 0: setBinScale(LinearBins); break;
791 case 1: setBinScale(LogBins); break; 791 case 1: setBinScale(LogBins); break;
792 case 2: setBinScale(InvertedLogBins); break; 792 case 2: setBinScale(InvertedLogBins); break;
793 } 793 }
794 } else if (name == "Normalize") { 794 } else if (name == "Normalize") {
795 setNormalize(value ? true : false); 795 setNormalize(value ? true : false);
796 } else { 796 } else {
797 SingleColourLayer::setProperty(name, value); 797 SingleColourLayer::setProperty(name, value);
798 } 798 }
799 } 799 }
800 800
888 QString indent, QString extraAttributes) const 888 QString indent, QString extraAttributes) const
889 { 889 {
890 QString s; 890 QString s;
891 891
892 s += QString("colourScheme=\"%1\" " 892 s += QString("colourScheme=\"%1\" "
893 "energyScale=\"%2\" " 893 "energyScale=\"%2\" "
894 "samplingMode=\"%3\" " 894 "samplingMode=\"%3\" "
895 "plotStyle=\"%4\" " 895 "plotStyle=\"%4\" "
896 "binScale=\"%5\" " 896 "binScale=\"%5\" "
897 "gain=\"%6\" " 897 "gain=\"%6\" "
898 "threshold=\"%7\" " 898 "threshold=\"%7\" "
899 "normalize=\"%8\" %9") 899 "normalize=\"%8\" %9")
900 .arg(m_colourMap) 900 .arg(m_colourMap)
901 .arg(m_energyScale) 901 .arg(m_energyScale)
902 .arg(m_samplingMode) 902 .arg(m_samplingMode)
903 .arg(m_plotStyle) 903 .arg(m_plotStyle)
904 .arg(m_binScale) 904 .arg(m_binScale)
905 .arg(m_gain) 905 .arg(m_gain)
906 .arg(m_threshold) 906 .arg(m_threshold)
919 bool ok = false; 919 bool ok = false;
920 920
921 SingleColourLayer::setProperties(attributes); 921 SingleColourLayer::setProperties(attributes);
922 922
923 EnergyScale scale = (EnergyScale) 923 EnergyScale scale = (EnergyScale)
924 attributes.value("energyScale").toInt(&ok); 924 attributes.value("energyScale").toInt(&ok);
925 if (ok) setEnergyScale(scale); 925 if (ok) setEnergyScale(scale);
926 926
927 SamplingMode mode = (SamplingMode) 927 SamplingMode mode = (SamplingMode)
928 attributes.value("samplingMode").toInt(&ok); 928 attributes.value("samplingMode").toInt(&ok);
929 if (ok) setSamplingMode(mode); 929 if (ok) setSamplingMode(mode);
930 930
931 int colourMap = attributes.value("colourScheme").toInt(&ok); 931 int colourMap = attributes.value("colourScheme").toInt(&ok);
932 if (ok) setFillColourMap(colourMap); 932 if (ok) setFillColourMap(colourMap);
933 933
934 PlotStyle s = (PlotStyle) 934 PlotStyle s = (PlotStyle)
935 attributes.value("plotStyle").toInt(&ok); 935 attributes.value("plotStyle").toInt(&ok);
936 if (ok) setPlotStyle(s); 936 if (ok) setPlotStyle(s);
937 937
938 BinScale b = (BinScale) 938 BinScale b = (BinScale)
939 attributes.value("binScale").toInt(&ok); 939 attributes.value("binScale").toInt(&ok);
940 if (ok) setBinScale(b); 940 if (ok) setBinScale(b);
941 941
942 float gain = attributes.value("gain").toFloat(&ok); 942 float gain = attributes.value("gain").toFloat(&ok);
943 if (ok) setGain(gain); 943 if (ok) setGain(gain);
944 944