Mercurial > hg > svgui
comparison layer/WaveformLayer.cpp @ 805:1d526ba11a24 warnfix_no_size_t
Remove size_t's and fix warnings in layer/
author | Chris Cannam |
---|---|
date | Tue, 17 Jun 2014 15:18:06 +0100 |
parents | def489f5ce92 |
children | 4c8ca536b54f |
comparison
equal
deleted
inserted
replaced
782:ddae586bc47b | 805:1d526ba11a24 |
---|---|
359 if (dB < -50.0) return 0; | 359 if (dB < -50.0) return 0; |
360 if (dB > 0.0) return m; | 360 if (dB > 0.0) return m; |
361 return int(((dB + 50.0) * m) / 50.0 + 0.1); | 361 return int(((dB + 50.0) * m) / 50.0 + 0.1); |
362 } | 362 } |
363 | 363 |
364 size_t | 364 int |
365 WaveformLayer::getChannelArrangement(size_t &min, size_t &max, | 365 WaveformLayer::getChannelArrangement(int &min, int &max, |
366 bool &merging, bool &mixing) | 366 bool &merging, bool &mixing) |
367 const | 367 const |
368 { | 368 { |
369 if (!m_model || !m_model->isOK()) return 0; | 369 if (!m_model || !m_model->isOK()) return 0; |
370 | 370 |
371 size_t channels = m_model->getChannelCount(); | 371 int channels = m_model->getChannelCount(); |
372 if (channels == 0) return 0; | 372 if (channels == 0) return 0; |
373 | 373 |
374 size_t rawChannels = channels; | 374 int rawChannels = channels; |
375 | 375 |
376 if (m_channel == -1) { | 376 if (m_channel == -1) { |
377 min = 0; | 377 min = 0; |
378 if (m_channelMode == MergeChannels || | 378 if (m_channelMode == MergeChannels || |
379 m_channelMode == MixChannels) { | 379 m_channelMode == MixChannels) { |
405 | 405 |
406 static float meterdbs[] = { -40, -30, -20, -15, -10, | 406 static float meterdbs[] = { -40, -30, -20, -15, -10, |
407 -5, -3, -2, -1, -0.5, 0 }; | 407 -5, -3, -2, -1, -0.5, 0 }; |
408 | 408 |
409 bool | 409 bool |
410 WaveformLayer::getSourceFramesForX(View *v, int x, size_t modelZoomLevel, | 410 WaveformLayer::getSourceFramesForX(View *v, int x, int modelZoomLevel, |
411 size_t &f0, size_t &f1) const | 411 int &f0, int &f1) const |
412 { | 412 { |
413 long viewFrame = v->getFrameForX(x); | 413 long viewFrame = v->getFrameForX(x); |
414 if (viewFrame < 0) { | 414 if (viewFrame < 0) { |
415 f0 = 0; | 415 f0 = 0; |
416 f1 = 0; | 416 f1 = 0; |
440 // Although a long for purposes of comparison against the view | 440 // Although a long for purposes of comparison against the view |
441 // start and end frames, these are known to be non-negative | 441 // start and end frames, these are known to be non-negative |
442 long modelStart = long(m_model->getStartFrame()); | 442 long modelStart = long(m_model->getStartFrame()); |
443 long modelEnd = long(m_model->getEndFrame()); | 443 long modelEnd = long(m_model->getEndFrame()); |
444 | 444 |
445 size_t rangeStart, rangeEnd; | 445 int rangeStart, rangeEnd; |
446 | 446 |
447 if (startFrame < modelStart) rangeStart = modelStart; | 447 if (startFrame < modelStart) rangeStart = modelStart; |
448 else rangeStart = startFrame; | 448 else rangeStart = startFrame; |
449 | 449 |
450 if (endFrame < 0) rangeEnd = 0; | 450 if (endFrame < 0) rangeEnd = 0; |
454 if (rangeEnd < rangeStart) rangeEnd = rangeStart; | 454 if (rangeEnd < rangeStart) rangeEnd = rangeStart; |
455 | 455 |
456 RangeSummarisableTimeValueModel::Range range = | 456 RangeSummarisableTimeValueModel::Range range = |
457 m_model->getSummary(channel, rangeStart, rangeEnd - rangeStart); | 457 m_model->getSummary(channel, rangeStart, rangeEnd - rangeStart); |
458 | 458 |
459 size_t minChannel = 0, maxChannel = 0; | 459 int minChannel = 0, maxChannel = 0; |
460 bool mergingChannels = false, mixingChannels = false; | 460 bool mergingChannels = false, mixingChannels = false; |
461 | 461 |
462 getChannelArrangement(minChannel, maxChannel, | 462 getChannelArrangement(minChannel, maxChannel, |
463 mergingChannels, mixingChannels); | 463 mergingChannels, mixingChannels); |
464 | 464 |
486 Profiler profiler("WaveformLayer::paint", true); | 486 Profiler profiler("WaveformLayer::paint", true); |
487 cerr << "WaveformLayer::paint (" << rect.x() << "," << rect.y() | 487 cerr << "WaveformLayer::paint (" << rect.x() << "," << rect.y() |
488 << ") [" << rect.width() << "x" << rect.height() << "]: zoom " << zoomLevel << endl; | 488 << ") [" << rect.width() << "x" << rect.height() << "]: zoom " << zoomLevel << endl; |
489 #endif | 489 #endif |
490 | 490 |
491 size_t channels = 0, minChannel = 0, maxChannel = 0; | 491 int channels = 0, minChannel = 0, maxChannel = 0; |
492 bool mergingChannels = false, mixingChannels = false; | 492 bool mergingChannels = false, mixingChannels = false; |
493 | 493 |
494 channels = getChannelArrangement(minChannel, maxChannel, | 494 channels = getChannelArrangement(minChannel, maxChannel, |
495 mergingChannels, mixingChannels); | 495 mergingChannels, mixingChannels); |
496 if (channels == 0) return; | 496 if (channels == 0) return; |
569 // exactly the same set of underlying audio frames, no matter what | 569 // exactly the same set of underlying audio frames, no matter what |
570 // the range being drawn is. And that set of underlying frames | 570 // the range being drawn is. And that set of underlying frames |
571 // must remain the same when we scroll one or more pixels left or | 571 // must remain the same when we scroll one or more pixels left or |
572 // right. | 572 // right. |
573 | 573 |
574 size_t modelZoomLevel = m_model->getSummaryBlockSize(zoomLevel); | 574 int modelZoomLevel = m_model->getSummaryBlockSize(zoomLevel); |
575 | 575 |
576 size_t frame0; | 576 int frame0; |
577 size_t frame1; | 577 int frame1; |
578 size_t spare; | 578 int spare; |
579 | 579 |
580 getSourceFramesForX(v, x0, modelZoomLevel, frame0, spare); | 580 getSourceFramesForX(v, x0, modelZoomLevel, frame0, spare); |
581 getSourceFramesForX(v, x1, modelZoomLevel, spare, frame1); | 581 getSourceFramesForX(v, x1, modelZoomLevel, spare, frame1); |
582 | 582 |
583 #ifdef DEBUG_WAVEFORM_PAINT | 583 #ifdef DEBUG_WAVEFORM_PAINT |
600 midColour = midColour.light(150); | 600 midColour = midColour.light(150); |
601 } else { | 601 } else { |
602 midColour = midColour.light(50); | 602 midColour = midColour.light(50); |
603 } | 603 } |
604 | 604 |
605 while (m_effectiveGains.size() <= maxChannel) { | 605 while ((int)m_effectiveGains.size() <= maxChannel) { |
606 m_effectiveGains.push_back(m_gain); | 606 m_effectiveGains.push_back(m_gain); |
607 } | 607 } |
608 | 608 |
609 for (size_t ch = minChannel; ch <= maxChannel; ++ch) { | 609 for (int ch = minChannel; ch <= maxChannel; ++ch) { |
610 | 610 |
611 int prevRangeBottom = -1, prevRangeTop = -1; | 611 int prevRangeBottom = -1, prevRangeTop = -1; |
612 QColor prevRangeBottomColour = baseColour, prevRangeTopColour = baseColour; | 612 QColor prevRangeBottomColour = baseColour, prevRangeTopColour = baseColour; |
613 | 613 |
614 m_effectiveGains[ch] = m_gain; | 614 m_effectiveGains[ch] = m_gain; |
709 | 709 |
710 for (int x = x0; x <= x1; ++x) { | 710 for (int x = x0; x <= x1; ++x) { |
711 | 711 |
712 range = RangeSummarisableTimeValueModel::Range(); | 712 range = RangeSummarisableTimeValueModel::Range(); |
713 | 713 |
714 size_t f0, f1; | 714 int f0, f1; |
715 if (!getSourceFramesForX(v, x, modelZoomLevel, f0, f1)) continue; | 715 if (!getSourceFramesForX(v, x, modelZoomLevel, f0, f1)) continue; |
716 f1 = f1 - 1; | 716 f1 = f1 - 1; |
717 | 717 |
718 if (f0 < frame0) { | 718 if (f0 < frame0) { |
719 cerr << "ERROR: WaveformLayer::paint: pixel " << x << " has f0 = " << f0 << " which is less than range frame0 " << frame0 << " for x0 = " << x0 << endl; | 719 cerr << "ERROR: WaveformLayer::paint: pixel " << x << " has f0 = " << f0 << " which is less than range frame0 " << frame0 << " for x0 = " << x0 << endl; |
720 continue; | 720 continue; |
721 } | 721 } |
722 | 722 |
723 size_t i0 = (f0 - frame0) / modelZoomLevel; | 723 int i0 = (f0 - frame0) / modelZoomLevel; |
724 size_t i1 = (f1 - frame0) / modelZoomLevel; | 724 int i1 = (f1 - frame0) / modelZoomLevel; |
725 | 725 |
726 #ifdef DEBUG_WAVEFORM_PAINT | 726 #ifdef DEBUG_WAVEFORM_PAINT |
727 cerr << "WaveformLayer::paint: pixel " << x << ": i0 " << i0 << " (f " << f0 << "), i1 " << i1 << " (f " << f1 << ")" << endl; | 727 cerr << "WaveformLayer::paint: pixel " << x << ": i0 " << i0 << " (f " << f0 << "), i1 " << i1 << " (f " << f1 << ")" << endl; |
728 #endif | 728 #endif |
729 | 729 |
730 if (i1 > i0 + 1) { | 730 if (i1 > i0 + 1) { |
731 cerr << "WaveformLayer::paint: ERROR: i1 " << i1 << " > i0 " << i0 << " plus one (zoom = " << zoomLevel << ", model zoom = " << modelZoomLevel << ")" << endl; | 731 cerr << "WaveformLayer::paint: ERROR: i1 " << i1 << " > i0 " << i0 << " plus one (zoom = " << zoomLevel << ", model zoom = " << modelZoomLevel << ")" << endl; |
732 } | 732 } |
733 | 733 |
734 if (ranges && i0 < ranges->size()) { | 734 if (ranges && i0 < (int)ranges->size()) { |
735 | 735 |
736 range = (*ranges)[i0]; | 736 range = (*ranges)[i0]; |
737 | 737 |
738 if (i1 > i0 && i1 < ranges->size()) { | 738 if (i1 > i0 && i1 < (int)ranges->size()) { |
739 range.setMax(std::max(range.max(), (*ranges)[i1].max())); | 739 range.setMax(std::max(range.max(), (*ranges)[i1].max())); |
740 range.setMin(std::min(range.min(), (*ranges)[i1].min())); | 740 range.setMin(std::min(range.min(), (*ranges)[i1].min())); |
741 range.setAbsmean((range.absmean() + (*ranges)[i1].absmean()) / 2); | 741 range.setAbsmean((range.absmean() + (*ranges)[i1].absmean()) / 2); |
742 } | 742 } |
743 | 743 |
750 | 750 |
751 int rangeBottom = 0, rangeTop = 0, meanBottom = 0, meanTop = 0; | 751 int rangeBottom = 0, rangeTop = 0, meanBottom = 0, meanTop = 0; |
752 | 752 |
753 if (mergingChannels) { | 753 if (mergingChannels) { |
754 | 754 |
755 if (otherChannelRanges && i0 < otherChannelRanges->size()) { | 755 if (otherChannelRanges && i0 < (int)otherChannelRanges->size()) { |
756 | 756 |
757 range.setMax(fabsf(range.max())); | 757 range.setMax(fabsf(range.max())); |
758 range.setMin(-fabsf((*otherChannelRanges)[i0].max())); | 758 range.setMin(-fabsf((*otherChannelRanges)[i0].max())); |
759 range.setAbsmean | 759 range.setAbsmean |
760 ((range.absmean() + | 760 ((range.absmean() + |
761 (*otherChannelRanges)[i0].absmean()) / 2); | 761 (*otherChannelRanges)[i0].absmean()) / 2); |
762 | 762 |
763 if (i1 > i0 && i1 < otherChannelRanges->size()) { | 763 if (i1 > i0 && i1 < (int)otherChannelRanges->size()) { |
764 // let's not concern ourselves about the mean | 764 // let's not concern ourselves about the mean |
765 range.setMin | 765 range.setMin |
766 (std::min | 766 (std::min |
767 (range.min(), | 767 (range.min(), |
768 -fabsf((*otherChannelRanges)[i1].max()))); | 768 -fabsf((*otherChannelRanges)[i1].max()))); |
769 } | 769 } |
770 } | 770 } |
771 | 771 |
772 } else if (mixingChannels) { | 772 } else if (mixingChannels) { |
773 | 773 |
774 if (otherChannelRanges && i0 < otherChannelRanges->size()) { | 774 if (otherChannelRanges && i0 < (int)otherChannelRanges->size()) { |
775 | 775 |
776 range.setMax((range.max() + (*otherChannelRanges)[i0].max()) / 2); | 776 range.setMax((range.max() + (*otherChannelRanges)[i0].max()) / 2); |
777 range.setMin((range.min() + (*otherChannelRanges)[i0].min()) / 2); | 777 range.setMin((range.min() + (*otherChannelRanges)[i0].min()) / 2); |
778 range.setAbsmean((range.absmean() + (*otherChannelRanges)[i0].absmean()) / 2); | 778 range.setAbsmean((range.absmean() + (*otherChannelRanges)[i0].absmean()) / 2); |
779 } | 779 } |
960 | 960 |
961 if (!m_model || !m_model->isOK()) return ""; | 961 if (!m_model || !m_model->isOK()) return ""; |
962 | 962 |
963 int zoomLevel = v->getZoomLevel(); | 963 int zoomLevel = v->getZoomLevel(); |
964 | 964 |
965 size_t modelZoomLevel = m_model->getSummaryBlockSize(zoomLevel); | 965 int modelZoomLevel = m_model->getSummaryBlockSize(zoomLevel); |
966 | 966 |
967 size_t f0, f1; | 967 int f0, f1; |
968 if (!getSourceFramesForX(v, x, modelZoomLevel, f0, f1)) return ""; | 968 if (!getSourceFramesForX(v, x, modelZoomLevel, f0, f1)) return ""; |
969 | 969 |
970 QString text; | 970 QString text; |
971 | 971 |
972 RealTime rt0 = RealTime::frame2RealTime(f0, m_model->getSampleRate()); | 972 RealTime rt0 = RealTime::frame2RealTime(f0, m_model->getSampleRate()); |
979 } else { | 979 } else { |
980 text += tr("Time:\t%1") | 980 text += tr("Time:\t%1") |
981 .arg(rt0.toText(true).c_str()); | 981 .arg(rt0.toText(true).c_str()); |
982 } | 982 } |
983 | 983 |
984 size_t channels = 0, minChannel = 0, maxChannel = 0; | 984 int channels = 0, minChannel = 0, maxChannel = 0; |
985 bool mergingChannels = false, mixingChannels = false; | 985 bool mergingChannels = false, mixingChannels = false; |
986 | 986 |
987 channels = getChannelArrangement(minChannel, maxChannel, | 987 channels = getChannelArrangement(minChannel, maxChannel, |
988 mergingChannels, mixingChannels); | 988 mergingChannels, mixingChannels); |
989 if (channels == 0) return ""; | 989 if (channels == 0) return ""; |
990 | 990 |
991 for (size_t ch = minChannel; ch <= maxChannel; ++ch) { | 991 for (int ch = minChannel; ch <= maxChannel; ++ch) { |
992 | 992 |
993 size_t blockSize = v->getZoomLevel(); | 993 int blockSize = v->getZoomLevel(); |
994 RangeSummarisableTimeValueModel::RangeBlock ranges; | 994 RangeSummarisableTimeValueModel::RangeBlock ranges; |
995 m_model->getSummaries(ch, f0, f1 - f0, ranges, blockSize); | 995 m_model->getSummaries(ch, f0, f1 - f0, ranges, blockSize); |
996 | 996 |
997 if (ranges.empty()) continue; | 997 if (ranges.empty()) continue; |
998 | 998 |
1035 | 1035 |
1036 return text; | 1036 return text; |
1037 } | 1037 } |
1038 | 1038 |
1039 int | 1039 int |
1040 WaveformLayer::getYForValue(const View *v, float value, size_t channel) const | 1040 WaveformLayer::getYForValue(const View *v, float value, int channel) const |
1041 { | 1041 { |
1042 size_t channels = 0, minChannel = 0, maxChannel = 0; | 1042 int channels = 0, minChannel = 0, maxChannel = 0; |
1043 bool mergingChannels = false, mixingChannels = false; | 1043 bool mergingChannels = false, mixingChannels = false; |
1044 | 1044 |
1045 channels = getChannelArrangement(minChannel, maxChannel, | 1045 channels = getChannelArrangement(minChannel, maxChannel, |
1046 mergingChannels, mixingChannels); | 1046 mergingChannels, mixingChannels); |
1047 | 1047 |
1078 | 1078 |
1079 return my - vy; | 1079 return my - vy; |
1080 } | 1080 } |
1081 | 1081 |
1082 float | 1082 float |
1083 WaveformLayer::getValueForY(const View *v, int y, size_t &channel) const | 1083 WaveformLayer::getValueForY(const View *v, int y, int &channel) const |
1084 { | 1084 { |
1085 size_t channels = 0, minChannel = 0, maxChannel = 0; | 1085 int channels = 0, minChannel = 0, maxChannel = 0; |
1086 bool mergingChannels = false, mixingChannels = false; | 1086 bool mergingChannels = false, mixingChannels = false; |
1087 | 1087 |
1088 channels = getChannelArrangement(minChannel, maxChannel, | 1088 channels = getChannelArrangement(minChannel, maxChannel, |
1089 mergingChannels, mixingChannels); | 1089 mergingChannels, mixingChannels); |
1090 | 1090 |
1127 | 1127 |
1128 bool | 1128 bool |
1129 WaveformLayer::getYScaleValue(const View *v, int y, | 1129 WaveformLayer::getYScaleValue(const View *v, int y, |
1130 float &value, QString &unit) const | 1130 float &value, QString &unit) const |
1131 { | 1131 { |
1132 size_t channel; | 1132 int channel; |
1133 | 1133 |
1134 value = getValueForY(v, y, channel); | 1134 value = getValueForY(v, y, channel); |
1135 | 1135 |
1136 if (m_scale == dBScale || m_scale == MeterScale) { | 1136 if (m_scale == dBScale || m_scale == MeterScale) { |
1137 | 1137 |
1153 | 1153 |
1154 bool | 1154 bool |
1155 WaveformLayer::getYScaleDifference(const View *v, int y0, int y1, | 1155 WaveformLayer::getYScaleDifference(const View *v, int y0, int y1, |
1156 float &diff, QString &unit) const | 1156 float &diff, QString &unit) const |
1157 { | 1157 { |
1158 size_t c0, c1; | 1158 int c0, c1; |
1159 float v0 = getValueForY(v, y0, c0); | 1159 float v0 = getValueForY(v, y0, c0); |
1160 float v1 = getValueForY(v, y1, c1); | 1160 float v1 = getValueForY(v, y1, c1); |
1161 | 1161 |
1162 if (c0 != c1) { | 1162 if (c0 != c1) { |
1163 // different channels, not comparable | 1163 // different channels, not comparable |
1205 { | 1205 { |
1206 if (!m_model || !m_model->isOK()) { | 1206 if (!m_model || !m_model->isOK()) { |
1207 return; | 1207 return; |
1208 } | 1208 } |
1209 | 1209 |
1210 size_t channels = 0, minChannel = 0, maxChannel = 0; | 1210 int channels = 0, minChannel = 0, maxChannel = 0; |
1211 bool mergingChannels = false, mixingChannels = false; | 1211 bool mergingChannels = false, mixingChannels = false; |
1212 | 1212 |
1213 channels = getChannelArrangement(minChannel, maxChannel, | 1213 channels = getChannelArrangement(minChannel, maxChannel, |
1214 mergingChannels, mixingChannels); | 1214 mergingChannels, mixingChannels); |
1215 if (channels == 0) return; | 1215 if (channels == 0) return; |
1218 int textHeight = paint.fontMetrics().height(); | 1218 int textHeight = paint.fontMetrics().height(); |
1219 int toff = -textHeight/2 + paint.fontMetrics().ascent() + 1; | 1219 int toff = -textHeight/2 + paint.fontMetrics().ascent() + 1; |
1220 | 1220 |
1221 float gain = m_gain; | 1221 float gain = m_gain; |
1222 | 1222 |
1223 for (size_t ch = minChannel; ch <= maxChannel; ++ch) { | 1223 for (int ch = minChannel; ch <= maxChannel; ++ch) { |
1224 | 1224 |
1225 int lastLabelledY = -1; | 1225 int lastLabelledY = -1; |
1226 | 1226 |
1227 if (ch < m_effectiveGains.size()) gain = m_effectiveGains[ch]; | 1227 if (ch < (int)m_effectiveGains.size()) gain = m_effectiveGains[ch]; |
1228 | 1228 |
1229 int n = 10; | 1229 int n = 10; |
1230 | 1230 |
1231 for (int i = 0; i <= n; ++i) { | 1231 for (int i = 0; i <= n; ++i) { |
1232 | 1232 |