Mercurial > hg > svgui
comparison layer/WaveformLayer.cpp @ 386:590b899b7e45
* Halve space requirements for range (waveform peak) caches
author | Chris Cannam |
---|---|
date | Fri, 16 May 2008 13:27:07 +0000 |
parents | e1a9e478b7f2 |
children | f4960f8ce798 |
comparison
equal
deleted
inserted
replaced
385:c0818f064e66 | 386:590b899b7e45 |
---|---|
453 mergingChannels, mixingChannels); | 453 mergingChannels, mixingChannels); |
454 | 454 |
455 if (mergingChannels || mixingChannels) { | 455 if (mergingChannels || mixingChannels) { |
456 RangeSummarisableTimeValueModel::Range otherRange = | 456 RangeSummarisableTimeValueModel::Range otherRange = |
457 m_model->getSummary(1, rangeStart, rangeEnd - rangeStart); | 457 m_model->getSummary(1, rangeStart, rangeEnd - rangeStart); |
458 range.max = std::max(range.max, otherRange.max); | 458 range.setMax(std::max(range.max(), otherRange.max())); |
459 range.min = std::min(range.min, otherRange.min); | 459 range.setMin(std::min(range.min(), otherRange.min())); |
460 range.absmean = std::min(range.absmean, otherRange.absmean); | 460 range.setAbsmean(std::min(range.absmean(), otherRange.absmean())); |
461 } | 461 } |
462 | 462 |
463 return 1.0 / std::max(fabsf(range.max), fabsf(range.min)); | 463 return 1.0 / std::max(fabsf(range.max()), fabsf(range.min())); |
464 } | 464 } |
465 | 465 |
466 void | 466 void |
467 WaveformLayer::paint(View *v, QPainter &viewPainter, QRect rect) const | 467 WaveformLayer::paint(View *v, QPainter &viewPainter, QRect rect) const |
468 { | 468 { |
713 if (ranges && i0 < ranges->size()) { | 713 if (ranges && i0 < ranges->size()) { |
714 | 714 |
715 range = (*ranges)[i0]; | 715 range = (*ranges)[i0]; |
716 | 716 |
717 if (i1 > i0 && i1 < ranges->size()) { | 717 if (i1 > i0 && i1 < ranges->size()) { |
718 range.max = std::max(range.max, (*ranges)[i1].max); | 718 range.setMax(std::max(range.max(), (*ranges)[i1].max())); |
719 range.min = std::min(range.min, (*ranges)[i1].min); | 719 range.setMin(std::min(range.min(), (*ranges)[i1].min())); |
720 range.absmean = (range.absmean + (*ranges)[i1].absmean) / 2; | 720 range.setAbsmean((range.absmean() + (*ranges)[i1].absmean()) / 2); |
721 } | 721 } |
722 | 722 |
723 } else { | 723 } else { |
724 continue; | 724 continue; |
725 } | 725 } |
728 | 728 |
729 if (mergingChannels) { | 729 if (mergingChannels) { |
730 | 730 |
731 if (otherChannelRanges && i0 < otherChannelRanges->size()) { | 731 if (otherChannelRanges && i0 < otherChannelRanges->size()) { |
732 | 732 |
733 range.max = fabsf(range.max); | 733 range.setMax(fabsf(range.max())); |
734 range.min = -fabsf((*otherChannelRanges)[i0].max); | 734 range.setMin(-fabsf((*otherChannelRanges)[i0].max())); |
735 range.absmean = (range.absmean + | 735 range.setAbsmean |
736 (*otherChannelRanges)[i0].absmean) / 2; | 736 ((range.absmean() + |
737 (*otherChannelRanges)[i0].absmean()) / 2); | |
737 | 738 |
738 if (i1 > i0 && i1 < otherChannelRanges->size()) { | 739 if (i1 > i0 && i1 < otherChannelRanges->size()) { |
739 // let's not concern ourselves about the mean | 740 // let's not concern ourselves about the mean |
740 range.min = std::min | 741 range.setMin |
741 (range.min, | 742 (std::min |
742 -fabsf((*otherChannelRanges)[i1].max)); | 743 (range.min(), |
744 -fabsf((*otherChannelRanges)[i1].max()))); | |
743 } | 745 } |
744 } | 746 } |
745 | 747 |
746 } else if (mixingChannels) { | 748 } else if (mixingChannels) { |
747 | 749 |
748 if (otherChannelRanges && i0 < otherChannelRanges->size()) { | 750 if (otherChannelRanges && i0 < otherChannelRanges->size()) { |
749 | 751 |
750 range.max = (range.max + (*otherChannelRanges)[i0].max) / 2; | 752 range.setMax((range.max() + (*otherChannelRanges)[i0].max()) / 2); |
751 range.min = (range.min + (*otherChannelRanges)[i0].min) / 2; | 753 range.setMin((range.min() + (*otherChannelRanges)[i0].min()) / 2); |
752 range.absmean = (range.absmean + (*otherChannelRanges)[i0].absmean) / 2; | 754 range.setAbsmean((range.absmean() + (*otherChannelRanges)[i0].absmean()) / 2); |
753 } | 755 } |
754 } | 756 } |
755 | 757 |
756 int greyLevels = 1; | 758 int greyLevels = 1; |
757 if (m_greyscale && (m_scale == LinearScale)) greyLevels = 4; | 759 if (m_greyscale && (m_scale == LinearScale)) greyLevels = 4; |
758 | 760 |
759 switch (m_scale) { | 761 switch (m_scale) { |
760 | 762 |
761 case LinearScale: | 763 case LinearScale: |
762 rangeBottom = int( m * greyLevels * range.min * gain); | 764 rangeBottom = int( m * greyLevels * range.min() * gain); |
763 rangeTop = int( m * greyLevels * range.max * gain); | 765 rangeTop = int( m * greyLevels * range.max() * gain); |
764 meanBottom = int(-m * range.absmean * gain); | 766 meanBottom = int(-m * range.absmean() * gain); |
765 meanTop = int( m * range.absmean * gain); | 767 meanTop = int( m * range.absmean() * gain); |
766 break; | 768 break; |
767 | 769 |
768 case dBScale: | 770 case dBScale: |
769 if (!mergingChannels) { | 771 if (!mergingChannels) { |
770 int db0 = dBscale(range.min * gain, m); | 772 int db0 = dBscale(range.min() * gain, m); |
771 int db1 = dBscale(range.max * gain, m); | 773 int db1 = dBscale(range.max() * gain, m); |
772 rangeTop = std::max(db0, db1); | 774 rangeTop = std::max(db0, db1); |
773 meanTop = std::min(db0, db1); | 775 meanTop = std::min(db0, db1); |
774 if (mixingChannels) rangeBottom = meanTop; | 776 if (mixingChannels) rangeBottom = meanTop; |
775 else rangeBottom = dBscale(range.absmean * gain, m); | 777 else rangeBottom = dBscale(range.absmean() * gain, m); |
776 meanBottom = rangeBottom; | 778 meanBottom = rangeBottom; |
777 } else { | 779 } else { |
778 rangeBottom = -dBscale(range.min * gain, m * greyLevels); | 780 rangeBottom = -dBscale(range.min() * gain, m * greyLevels); |
779 rangeTop = dBscale(range.max * gain, m * greyLevels); | 781 rangeTop = dBscale(range.max() * gain, m * greyLevels); |
780 meanBottom = -dBscale(range.absmean * gain, m); | 782 meanBottom = -dBscale(range.absmean() * gain, m); |
781 meanTop = dBscale(range.absmean * gain, m); | 783 meanTop = dBscale(range.absmean() * gain, m); |
782 } | 784 } |
783 break; | 785 break; |
784 | 786 |
785 case MeterScale: | 787 case MeterScale: |
786 if (!mergingChannels) { | 788 if (!mergingChannels) { |
787 int r0 = abs(AudioLevel::multiplier_to_preview(range.min * gain, m)); | 789 int r0 = abs(AudioLevel::multiplier_to_preview(range.min() * gain, m)); |
788 int r1 = abs(AudioLevel::multiplier_to_preview(range.max * gain, m)); | 790 int r1 = abs(AudioLevel::multiplier_to_preview(range.max() * gain, m)); |
789 rangeTop = std::max(r0, r1); | 791 rangeTop = std::max(r0, r1); |
790 meanTop = std::min(r0, r1); | 792 meanTop = std::min(r0, r1); |
791 if (mixingChannels) rangeBottom = meanTop; | 793 if (mixingChannels) rangeBottom = meanTop; |
792 else rangeBottom = AudioLevel::multiplier_to_preview(range.absmean * gain, m); | 794 else rangeBottom = AudioLevel::multiplier_to_preview(range.absmean() * gain, m); |
793 meanBottom = rangeBottom; | 795 meanBottom = rangeBottom; |
794 } else { | 796 } else { |
795 rangeBottom = -AudioLevel::multiplier_to_preview(range.min * gain, m * greyLevels); | 797 rangeBottom = -AudioLevel::multiplier_to_preview(range.min() * gain, m * greyLevels); |
796 rangeTop = AudioLevel::multiplier_to_preview(range.max * gain, m * greyLevels); | 798 rangeTop = AudioLevel::multiplier_to_preview(range.max() * gain, m * greyLevels); |
797 meanBottom = -AudioLevel::multiplier_to_preview(range.absmean * gain, m); | 799 meanBottom = -AudioLevel::multiplier_to_preview(range.absmean() * gain, m); |
798 meanTop = AudioLevel::multiplier_to_preview(range.absmean * gain, m); | 800 meanTop = AudioLevel::multiplier_to_preview(range.absmean() * gain, m); |
799 } | 801 } |
800 break; | 802 break; |
801 } | 803 } |
802 | 804 |
803 rangeBottom = my * greyLevels - rangeBottom; | 805 rangeBottom = my * greyLevels - rangeBottom; |
818 if (rangeTop < my - m) { rangeTop = my - m; } | 820 if (rangeTop < my - m) { rangeTop = my - m; } |
819 if (rangeTop > my + m) { rangeTop = my + m; } | 821 if (rangeTop > my + m) { rangeTop = my + m; } |
820 if (rangeBottom < my - m) { rangeBottom = my - m; } | 822 if (rangeBottom < my - m) { rangeBottom = my - m; } |
821 if (rangeBottom > my + m) { rangeBottom = my + m; } | 823 if (rangeBottom > my + m) { rangeBottom = my + m; } |
822 | 824 |
823 if (range.max <= -1.0 || | 825 if (range.max() <= -1.0 || |
824 range.max >= 1.0) clipped = true; | 826 range.max() >= 1.0) clipped = true; |
825 | 827 |
826 if (meanBottom > rangeBottom) meanBottom = rangeBottom; | 828 if (meanBottom > rangeBottom) meanBottom = rangeBottom; |
827 if (meanTop < rangeTop) meanTop = rangeTop; | 829 if (meanTop < rangeTop) meanTop = rangeTop; |
828 | 830 |
829 bool drawMean = m_showMeans; | 831 bool drawMean = m_showMeans; |
854 } | 856 } |
855 } | 857 } |
856 | 858 |
857 if (ready) { | 859 if (ready) { |
858 if (clipped /*!!! || | 860 if (clipped /*!!! || |
859 range.min * gain <= -1.0 || | 861 range.min() * gain <= -1.0 || |
860 range.max * gain >= 1.0 */) { | 862 range.max() * gain >= 1.0 */) { |
861 paint->setPen(Qt::red); //!!! getContrastingColour | 863 paint->setPen(Qt::red); //!!! getContrastingColour |
862 } else { | 864 } else { |
863 paint->setPen(baseColour); | 865 paint->setPen(baseColour); |
864 } | 866 } |
865 } else { | 867 } else { |
968 } | 970 } |
969 | 971 |
970 bool singleValue = false; | 972 bool singleValue = false; |
971 float min, max; | 973 float min, max; |
972 | 974 |
973 if (fabs(range.min) < 0.01) { | 975 if (fabs(range.min()) < 0.01) { |
974 min = range.min; | 976 min = range.min(); |
975 max = range.max; | 977 max = range.max(); |
976 singleValue = (min == max); | 978 singleValue = (min == max); |
977 } else { | 979 } else { |
978 int imin = int(range.min * 1000); | 980 int imin = int(range.min() * 1000); |
979 int imax = int(range.max * 1000); | 981 int imax = int(range.max() * 1000); |
980 singleValue = (imin == imax); | 982 singleValue = (imin == imax); |
981 min = float(imin)/1000; | 983 min = float(imin)/1000; |
982 max = float(imax)/1000; | 984 max = float(imax)/1000; |
983 } | 985 } |
984 | 986 |
985 int db = int(AudioLevel::multiplier_to_dB(std::max(fabsf(range.min), | 987 int db = int(AudioLevel::multiplier_to_dB(std::max(fabsf(range.min()), |
986 fabsf(range.max))) | 988 fabsf(range.max()))) |
987 * 100); | 989 * 100); |
988 | 990 |
989 if (!singleValue) { | 991 if (!singleValue) { |
990 text += tr("\n%1\t%2 - %3 (%4 dB peak)") | 992 text += tr("\n%1\t%2 - %3 (%4 dB peak)") |
991 .arg(label).arg(min).arg(max).arg(float(db)/100); | 993 .arg(label).arg(min).arg(max).arg(float(db)/100); |