Mercurial > hg > svgui
comparison layer/WaveformLayer.cpp @ 1045:f535f6e5dbb0 alignment-simple
Merge in from SV 3.0-integration branches
author | Chris Cannam |
---|---|
date | Wed, 02 Mar 2016 17:25:27 +0000 |
parents | 2adca8f05583 |
children | c02c51ae5238 ee01a4062747 |
comparison
equal
deleted
inserted
replaced
976:f2c63ec85901 | 1045:f535f6e5dbb0 |
---|---|
324 m_cacheValid = false; | 324 m_cacheValid = false; |
325 emit layerParametersChanged(); | 325 emit layerParametersChanged(); |
326 } | 326 } |
327 | 327 |
328 int | 328 int |
329 WaveformLayer::getCompletion(View *) const | 329 WaveformLayer::getCompletion(LayerGeometryProvider *) const |
330 { | 330 { |
331 int completion = 100; | 331 int completion = 100; |
332 if (!m_model || !m_model->isOK()) return completion; | 332 if (!m_model || !m_model->isOK()) return completion; |
333 if (m_model->isReady(&completion)) return 100; | 333 if (m_model->isReady(&completion)) return 100; |
334 return completion; | 334 return completion; |
397 | 397 |
398 return channels; | 398 return channels; |
399 } | 399 } |
400 | 400 |
401 bool | 401 bool |
402 WaveformLayer::isLayerScrollable(const View *) const | 402 WaveformLayer::isLayerScrollable(const LayerGeometryProvider *) const |
403 { | 403 { |
404 return !m_autoNormalize; | 404 return !m_autoNormalize; |
405 } | 405 } |
406 | 406 |
407 static float meterdbs[] = { -40, -30, -20, -15, -10, | 407 static float meterdbs[] = { -40, -30, -20, -15, -10, |
408 -5, -3, -2, -1, -0.5, 0 }; | 408 -5, -3, -2, -1, -0.5, 0 }; |
409 | 409 |
410 bool | 410 bool |
411 WaveformLayer::getSourceFramesForX(View *v, int x, int modelZoomLevel, | 411 WaveformLayer::getSourceFramesForX(LayerGeometryProvider *v, int x, int modelZoomLevel, |
412 sv_frame_t &f0, sv_frame_t &f1) const | 412 sv_frame_t &f0, sv_frame_t &f1) const |
413 { | 413 { |
414 sv_frame_t viewFrame = v->getFrameForX(x); | 414 sv_frame_t viewFrame = v->getFrameForX(x); |
415 if (viewFrame < 0) { | 415 if (viewFrame < 0) { |
416 f0 = 0; | 416 f0 = 0; |
431 | 431 |
432 return (f0 < m_model->getEndFrame()); | 432 return (f0 < m_model->getEndFrame()); |
433 } | 433 } |
434 | 434 |
435 float | 435 float |
436 WaveformLayer::getNormalizeGain(View *v, int channel) const | 436 WaveformLayer::getNormalizeGain(LayerGeometryProvider *v, int channel) const |
437 { | 437 { |
438 sv_frame_t startFrame = v->getStartFrame(); | 438 sv_frame_t startFrame = v->getStartFrame(); |
439 sv_frame_t endFrame = v->getEndFrame(); | 439 sv_frame_t endFrame = v->getEndFrame(); |
440 | 440 |
441 sv_frame_t modelStart = m_model->getStartFrame(); | 441 sv_frame_t modelStart = m_model->getStartFrame(); |
471 | 471 |
472 return float(1.0 / std::max(fabs(range.max()), fabs(range.min()))); | 472 return float(1.0 / std::max(fabs(range.max()), fabs(range.min()))); |
473 } | 473 } |
474 | 474 |
475 void | 475 void |
476 WaveformLayer::paint(View *v, QPainter &viewPainter, QRect rect) const | 476 WaveformLayer::paint(LayerGeometryProvider *v, QPainter &viewPainter, QRect rect) const |
477 { | 477 { |
478 if (!m_model || !m_model->isOK()) { | 478 if (!m_model || !m_model->isOK()) { |
479 return; | 479 return; |
480 } | 480 } |
481 | 481 |
492 | 492 |
493 channels = getChannelArrangement(minChannel, maxChannel, | 493 channels = getChannelArrangement(minChannel, maxChannel, |
494 mergingChannels, mixingChannels); | 494 mergingChannels, mixingChannels); |
495 if (channels == 0) return; | 495 if (channels == 0) return; |
496 | 496 |
497 int w = v->width(); | 497 int w = v->getPaintWidth(); |
498 int h = v->height(); | 498 int h = v->getPaintHeight(); |
499 | 499 |
500 bool ready = m_model->isReady(); | 500 bool ready = m_model->isReady(); |
501 QPainter *paint; | 501 QPainter *paint; |
502 | 502 |
503 if (m_aggressive) { | 503 if (m_aggressive) { |
557 x1 = rect.right(); | 557 x1 = rect.right(); |
558 y0 = rect.top(); | 558 y0 = rect.top(); |
559 y1 = rect.bottom(); | 559 y1 = rect.bottom(); |
560 | 560 |
561 if (x0 > 0) --x0; | 561 if (x0 > 0) --x0; |
562 if (x1 < v->width()) ++x1; | 562 if (x1 < w) ++x1; |
563 | 563 |
564 // Our zoom level may differ from that at which the underlying | 564 // Our zoom level may differ from that at which the underlying |
565 // model has its blocks. | 565 // model has its blocks. |
566 | 566 |
567 // Each pixel within our visible range must always draw from | 567 // Each pixel within our visible range must always draw from |
728 | 728 |
729 if (i1 > i0 + 1) { | 729 if (i1 > i0 + 1) { |
730 cerr << "WaveformLayer::paint: ERROR: i1 " << i1 << " > i0 " << i0 << " plus one (zoom = " << zoomLevel << ", model zoom = " << modelZoomLevel << ")" << endl; | 730 cerr << "WaveformLayer::paint: ERROR: i1 " << i1 << " > i0 " << i0 << " plus one (zoom = " << zoomLevel << ", model zoom = " << modelZoomLevel << ")" << endl; |
731 } | 731 } |
732 | 732 |
733 if (ranges && i0 < (int)ranges->size()) { | 733 if (ranges && i0 < (sv_frame_t)ranges->size()) { |
734 | 734 |
735 range = (*ranges)[i0]; | 735 range = (*ranges)[size_t(i0)]; |
736 | 736 |
737 if (i1 > i0 && i1 < (int)ranges->size()) { | 737 if (i1 > i0 && i1 < (int)ranges->size()) { |
738 range.setMax(std::max(range.max(), (*ranges)[i1].max())); | 738 range.setMax(std::max(range.max(), |
739 range.setMin(std::min(range.min(), (*ranges)[i1].min())); | 739 (*ranges)[size_t(i1)].max())); |
740 range.setAbsmean((range.absmean() + (*ranges)[i1].absmean()) / 2); | 740 range.setMin(std::min(range.min(), |
741 (*ranges)[size_t(i1)].min())); | |
742 range.setAbsmean((range.absmean() | |
743 + (*ranges)[size_t(i1)].absmean()) / 2); | |
741 } | 744 } |
742 | 745 |
743 } else { | 746 } else { |
744 #ifdef DEBUG_WAVEFORM_PAINT | 747 #ifdef DEBUG_WAVEFORM_PAINT |
745 cerr << "No (or not enough) ranges for i0 = " << i0 << endl; | 748 cerr << "No (or not enough) ranges for i0 = " << i0 << endl; |
749 | 752 |
750 int rangeBottom = 0, rangeTop = 0, meanBottom = 0, meanTop = 0; | 753 int rangeBottom = 0, rangeTop = 0, meanBottom = 0, meanTop = 0; |
751 | 754 |
752 if (mergingChannels) { | 755 if (mergingChannels) { |
753 | 756 |
754 if (otherChannelRanges && i0 < (int)otherChannelRanges->size()) { | 757 if (otherChannelRanges && i0 < (sv_frame_t)otherChannelRanges->size()) { |
755 | 758 |
756 range.setMax(fabsf(range.max())); | 759 range.setMax(fabsf(range.max())); |
757 range.setMin(-fabsf((*otherChannelRanges)[i0].max())); | 760 range.setMin(-fabsf((*otherChannelRanges)[size_t(i0)].max())); |
758 range.setAbsmean | 761 range.setAbsmean |
759 ((range.absmean() + | 762 ((range.absmean() + |
760 (*otherChannelRanges)[i0].absmean()) / 2); | 763 (*otherChannelRanges)[size_t(i0)].absmean()) / 2); |
761 | 764 |
762 if (i1 > i0 && i1 < (int)otherChannelRanges->size()) { | 765 if (i1 > i0 && i1 < (sv_frame_t)otherChannelRanges->size()) { |
763 // let's not concern ourselves about the mean | 766 // let's not concern ourselves about the mean |
764 range.setMin | 767 range.setMin |
765 (std::min | 768 (std::min |
766 (range.min(), | 769 (range.min(), |
767 -fabsf((*otherChannelRanges)[i1].max()))); | 770 -fabsf((*otherChannelRanges)[size_t(i1)].max()))); |
768 } | 771 } |
769 } | 772 } |
770 | 773 |
771 } else if (mixingChannels) { | 774 } else if (mixingChannels) { |
772 | 775 |
773 if (otherChannelRanges && i0 < (int)otherChannelRanges->size()) { | 776 if (otherChannelRanges && i0 < (sv_frame_t)otherChannelRanges->size()) { |
774 | 777 |
775 range.setMax((range.max() + (*otherChannelRanges)[i0].max()) / 2); | 778 range.setMax((range.max() |
776 range.setMin((range.min() + (*otherChannelRanges)[i0].min()) / 2); | 779 + (*otherChannelRanges)[size_t(i0)].max()) / 2); |
777 range.setAbsmean((range.absmean() + (*otherChannelRanges)[i0].absmean()) / 2); | 780 range.setMin((range.min() |
781 + (*otherChannelRanges)[size_t(i0)].min()) / 2); | |
782 range.setAbsmean((range.absmean() | |
783 + (*otherChannelRanges)[size_t(i0)].absmean()) / 2); | |
778 } | 784 } |
779 } | 785 } |
780 | 786 |
781 int greyLevels = 1; | 787 int greyLevels = 1; |
782 if (m_greyscale && (m_scale == LinearScale)) greyLevels = 4; | 788 if (m_greyscale && (m_scale == LinearScale)) greyLevels = 4; |
937 paint->restore(); | 943 paint->restore(); |
938 } | 944 } |
939 | 945 |
940 if (m_aggressive) { | 946 if (m_aggressive) { |
941 | 947 |
942 if (ready && rect == v->rect()) { | 948 if (ready && rect == v->getPaintRect()) { |
943 m_cacheValid = true; | 949 m_cacheValid = true; |
944 m_cacheZoomLevel = zoomLevel; | 950 m_cacheZoomLevel = zoomLevel; |
945 } | 951 } |
946 paint->end(); | 952 paint->end(); |
947 delete paint; | 953 delete paint; |
951 if (otherChannelRanges != ranges) delete otherChannelRanges; | 957 if (otherChannelRanges != ranges) delete otherChannelRanges; |
952 delete ranges; | 958 delete ranges; |
953 } | 959 } |
954 | 960 |
955 QString | 961 QString |
956 WaveformLayer::getFeatureDescription(View *v, QPoint &pos) const | 962 WaveformLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const |
957 { | 963 { |
958 int x = pos.x(); | 964 int x = pos.x(); |
959 | 965 |
960 if (!m_model || !m_model->isOK()) return ""; | 966 if (!m_model || !m_model->isOK()) return ""; |
961 | 967 |
1034 | 1040 |
1035 return text; | 1041 return text; |
1036 } | 1042 } |
1037 | 1043 |
1038 int | 1044 int |
1039 WaveformLayer::getYForValue(const View *v, double value, int channel) const | 1045 WaveformLayer::getYForValue(const LayerGeometryProvider *v, double value, int channel) const |
1040 { | 1046 { |
1041 int channels = 0, minChannel = 0, maxChannel = 0; | 1047 int channels = 0, minChannel = 0, maxChannel = 0; |
1042 bool mergingChannels = false, mixingChannels = false; | 1048 bool mergingChannels = false, mixingChannels = false; |
1043 | 1049 |
1044 channels = getChannelArrangement(minChannel, maxChannel, | 1050 channels = getChannelArrangement(minChannel, maxChannel, |
1045 mergingChannels, mixingChannels); | 1051 mergingChannels, mixingChannels); |
1046 if (channels == 0) return 0; | 1052 if (channels == 0) return 0; |
1047 if (maxChannel < minChannel || channel < minChannel) return 0; | 1053 if (maxChannel < minChannel || channel < minChannel) return 0; |
1048 | 1054 |
1049 int h = v->height(); | 1055 int h = v->getPaintHeight(); |
1050 int m = (h / channels) / 2; | 1056 int m = (h / channels) / 2; |
1051 | 1057 |
1052 if ((m_scale == dBScale || m_scale == MeterScale) && | 1058 if ((m_scale == dBScale || m_scale == MeterScale) && |
1053 m_channelMode != MergeChannels) { | 1059 m_channelMode != MergeChannels) { |
1054 m = (h / channels); | 1060 m = (h / channels); |
1077 | 1083 |
1078 return my - vy; | 1084 return my - vy; |
1079 } | 1085 } |
1080 | 1086 |
1081 double | 1087 double |
1082 WaveformLayer::getValueForY(const View *v, int y, int &channel) const | 1088 WaveformLayer::getValueForY(const LayerGeometryProvider *v, int y, int &channel) const |
1083 { | 1089 { |
1084 int channels = 0, minChannel = 0, maxChannel = 0; | 1090 int channels = 0, minChannel = 0, maxChannel = 0; |
1085 bool mergingChannels = false, mixingChannels = false; | 1091 bool mergingChannels = false, mixingChannels = false; |
1086 | 1092 |
1087 channels = getChannelArrangement(minChannel, maxChannel, | 1093 channels = getChannelArrangement(minChannel, maxChannel, |
1088 mergingChannels, mixingChannels); | 1094 mergingChannels, mixingChannels); |
1089 if (channels == 0) return 0; | 1095 if (channels == 0) return 0; |
1090 if (maxChannel < minChannel) return 0; | 1096 if (maxChannel < minChannel) return 0; |
1091 | 1097 |
1092 int h = v->height(); | 1098 int h = v->getPaintHeight(); |
1093 int m = (h / channels) / 2; | 1099 int m = (h / channels) / 2; |
1094 | 1100 |
1095 if ((m_scale == dBScale || m_scale == MeterScale) && | 1101 if ((m_scale == dBScale || m_scale == MeterScale) && |
1096 m_channelMode != MergeChannels) { | 1102 m_channelMode != MergeChannels) { |
1097 m = (h / channels); | 1103 m = (h / channels); |
1123 | 1129 |
1124 return value / m_gain; | 1130 return value / m_gain; |
1125 } | 1131 } |
1126 | 1132 |
1127 bool | 1133 bool |
1128 WaveformLayer::getYScaleValue(const View *v, int y, | 1134 WaveformLayer::getYScaleValue(const LayerGeometryProvider *v, int y, |
1129 double &value, QString &unit) const | 1135 double &value, QString &unit) const |
1130 { | 1136 { |
1131 int channel; | 1137 int channel; |
1132 | 1138 |
1133 value = getValueForY(v, y, channel); | 1139 value = getValueForY(v, y, channel); |
1149 | 1155 |
1150 return true; | 1156 return true; |
1151 } | 1157 } |
1152 | 1158 |
1153 bool | 1159 bool |
1154 WaveformLayer::getYScaleDifference(const View *v, int y0, int y1, | 1160 WaveformLayer::getYScaleDifference(const LayerGeometryProvider *v, int y0, int y1, |
1155 double &diff, QString &unit) const | 1161 double &diff, QString &unit) const |
1156 { | 1162 { |
1157 int c0, c1; | 1163 int c0, c1; |
1158 double v0 = getValueForY(v, y0, c0); | 1164 double v0 = getValueForY(v, y0, c0); |
1159 double v1 = getValueForY(v, y1, c1); | 1165 double v1 = getValueForY(v, y1, c1); |
1187 | 1193 |
1188 return true; | 1194 return true; |
1189 } | 1195 } |
1190 | 1196 |
1191 int | 1197 int |
1192 WaveformLayer::getVerticalScaleWidth(View *, bool, QPainter &paint) const | 1198 WaveformLayer::getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &paint) const |
1193 { | 1199 { |
1194 if (m_scale == LinearScale) { | 1200 if (m_scale == LinearScale) { |
1195 return paint.fontMetrics().width("0.0") + 13; | 1201 return paint.fontMetrics().width("0.0") + 13; |
1196 } else { | 1202 } else { |
1197 return std::max(paint.fontMetrics().width(tr("0dB")), | 1203 return std::max(paint.fontMetrics().width(tr("0dB")), |
1198 paint.fontMetrics().width(tr("-Inf"))) + 13; | 1204 paint.fontMetrics().width(tr("-Inf"))) + 13; |
1199 } | 1205 } |
1200 } | 1206 } |
1201 | 1207 |
1202 void | 1208 void |
1203 WaveformLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const | 1209 WaveformLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const |
1204 { | 1210 { |
1205 if (!m_model || !m_model->isOK()) { | 1211 if (!m_model || !m_model->isOK()) { |
1206 return; | 1212 return; |
1207 } | 1213 } |
1208 | 1214 |