Mercurial > hg > svgui
comparison layer/TimeValueLayer.cpp @ 706:97ea68f62c1f imaf_enc
Merge from default branch
author | Chris Cannam |
---|---|
date | Thu, 05 Dec 2013 09:47:02 +0000 |
parents | 084f65094203 |
children | ceb9a2992d96 88a16eed3338 |
comparison
equal
deleted
inserted
replaced
678:26c5f7fd4807 | 706:97ea68f62c1f |
---|---|
26 #include "data/model/SparseTimeValueModel.h" | 26 #include "data/model/SparseTimeValueModel.h" |
27 #include "data/model/Labeller.h" | 27 #include "data/model/Labeller.h" |
28 | 28 |
29 #include "widgets/ItemEditDialog.h" | 29 #include "widgets/ItemEditDialog.h" |
30 #include "widgets/ListInputDialog.h" | 30 #include "widgets/ListInputDialog.h" |
31 #include "widgets/TextAbbrev.h" | |
31 | 32 |
32 #include "ColourMapper.h" | 33 #include "ColourMapper.h" |
34 #include "PianoScale.h" | |
35 #include "LinearNumericalScale.h" | |
36 #include "LogNumericalScale.h" | |
37 #include "LinearColourScale.h" | |
38 #include "LogColourScale.h" | |
33 | 39 |
34 #include <QPainter> | 40 #include <QPainter> |
35 #include <QPainterPath> | 41 #include <QPainterPath> |
36 #include <QMouseEvent> | 42 #include <QMouseEvent> |
37 #include <QRegExp> | 43 #include <QRegExp> |
79 if (m_model && m_model->getRDFTypeURI().endsWith("Change")) { | 85 if (m_model && m_model->getRDFTypeURI().endsWith("Change")) { |
80 setPlotStyle(PlotSegmentation); | 86 setPlotStyle(PlotSegmentation); |
81 } | 87 } |
82 | 88 |
83 #ifdef DEBUG_TIME_VALUE_LAYER | 89 #ifdef DEBUG_TIME_VALUE_LAYER |
84 std::cerr << "TimeValueLayer::setModel(" << model << ")" << std::endl; | 90 cerr << "TimeValueLayer::setModel(" << model << ")" << endl; |
85 #endif | 91 #endif |
86 | 92 |
87 emit modelReplaced(); | 93 emit modelReplaced(); |
88 } | 94 } |
89 | 95 |
141 return tr("Plot Type"); | 147 return tr("Plot Type"); |
142 } | 148 } |
143 return SingleColourLayer::getPropertyGroupName(name); | 149 return SingleColourLayer::getPropertyGroupName(name); |
144 } | 150 } |
145 | 151 |
152 QString | |
153 TimeValueLayer::getScaleUnits() const | |
154 { | |
155 if (m_model) return m_model->getScaleUnits(); | |
156 else return ""; | |
157 } | |
158 | |
146 int | 159 int |
147 TimeValueLayer::getPropertyRangeAndValue(const PropertyName &name, | 160 TimeValueLayer::getPropertyRangeAndValue(const PropertyName &name, |
148 int *min, int *max, int *deflt) const | 161 int *min, int *max, int *deflt) const |
149 { | 162 { |
150 int val = 0; | 163 int val = 0; |
176 } else if (name == "Scale Units") { | 189 } else if (name == "Scale Units") { |
177 | 190 |
178 if (deflt) *deflt = 0; | 191 if (deflt) *deflt = 0; |
179 if (m_model) { | 192 if (m_model) { |
180 val = UnitDatabase::getInstance()->getUnitId | 193 val = UnitDatabase::getInstance()->getUnitId |
181 (m_model->getScaleUnits()); | 194 (getScaleUnits()); |
182 } | 195 } |
183 | 196 |
184 } else if (name == "Draw Segment Division Lines") { | 197 } else if (name == "Draw Segment Division Lines") { |
185 | 198 |
186 if (min) *min = 0; | 199 if (min) *min = 0; |
324 min = m_model->getValueMinimum(); | 337 min = m_model->getValueMinimum(); |
325 max = m_model->getValueMaximum(); | 338 max = m_model->getValueMaximum(); |
326 | 339 |
327 logarithmic = (m_verticalScale == LogScale); | 340 logarithmic = (m_verticalScale == LogScale); |
328 | 341 |
329 unit = m_model->getScaleUnits(); | 342 unit = getScaleUnits(); |
330 | 343 |
331 if (m_derivative) { | 344 if (m_derivative) { |
332 max = std::max(fabsf(min), fabsf(max)); | 345 max = std::max(fabsf(min), fabsf(max)); |
333 min = -max; | 346 min = -max; |
334 } | 347 } |
335 | 348 |
336 #ifdef DEBUG_TIME_VALUE_LAYER | 349 #ifdef DEBUG_TIME_VALUE_LAYER |
337 std::cerr << "TimeValueLayer::getValueExtents: min = " << min << ", max = " << max << std::endl; | 350 cerr << "TimeValueLayer::getValueExtents: min = " << min << ", max = " << max << endl; |
338 #endif | 351 #endif |
339 | 352 |
340 if (!shouldAutoAlign() && !logarithmic && !m_derivative) { | 353 if (!shouldAutoAlign() && !logarithmic && !m_derivative) { |
341 | 354 |
342 if (max == min) { | 355 if (max == min) { |
347 max = max + margin; | 360 max = max + margin; |
348 min = min - margin; | 361 min = min - margin; |
349 } | 362 } |
350 | 363 |
351 #ifdef DEBUG_TIME_VALUE_LAYER | 364 #ifdef DEBUG_TIME_VALUE_LAYER |
352 std::cerr << "TimeValueLayer::getValueExtents: min = " << min << ", max = " << max << " (after adjustment)" << std::endl; | 365 cerr << "TimeValueLayer::getValueExtents: min = " << min << ", max = " << max << " (after adjustment)" << endl; |
353 #endif | 366 #endif |
354 } | 367 } |
355 | 368 |
356 return true; | 369 return true; |
357 } | 370 } |
374 max = std::max(fabsf(min), fabsf(max)); | 387 max = std::max(fabsf(min), fabsf(max)); |
375 min = -max; | 388 min = -max; |
376 } | 389 } |
377 | 390 |
378 #ifdef DEBUG_TIME_VALUE_LAYER | 391 #ifdef DEBUG_TIME_VALUE_LAYER |
379 std::cerr << "TimeValueLayer::getDisplayExtents: min = " << min << ", max = " << max << std::endl; | 392 cerr << "TimeValueLayer::getDisplayExtents: min = " << min << ", max = " << max << endl; |
380 #endif | 393 #endif |
381 | 394 |
382 return true; | 395 return true; |
383 } | 396 } |
384 | 397 |
397 | 410 |
398 m_scaleMinimum = min; | 411 m_scaleMinimum = min; |
399 m_scaleMaximum = max; | 412 m_scaleMaximum = max; |
400 | 413 |
401 #ifdef DEBUG_TIME_VALUE_LAYER | 414 #ifdef DEBUG_TIME_VALUE_LAYER |
402 std::cerr << "TimeValueLayer::setDisplayExtents: min = " << min << ", max = " << max << std::endl; | 415 cerr << "TimeValueLayer::setDisplayExtents: min = " << min << ", max = " << max << endl; |
403 #endif | 416 #endif |
404 | 417 |
405 emit layerParametersChanged(); | 418 emit layerParametersChanged(); |
406 return true; | 419 return true; |
407 } | 420 } |
429 getDisplayExtents(dmin, dmax); | 442 getDisplayExtents(dmin, dmax); |
430 | 443 |
431 int nr = mapper->getPositionForValue(dmax - dmin); | 444 int nr = mapper->getPositionForValue(dmax - dmin); |
432 | 445 |
433 #ifdef DEBUG_TIME_VALUE_LAYER | 446 #ifdef DEBUG_TIME_VALUE_LAYER |
434 std::cerr << "TimeValueLayer::getCurrentVerticalZoomStep: dmin = " << dmin << ", dmax = " << dmax << ", nr = " << nr << std::endl; | 447 cerr << "TimeValueLayer::getCurrentVerticalZoomStep: dmin = " << dmin << ", dmax = " << dmax << ", nr = " << nr << endl; |
435 #endif | 448 #endif |
436 | 449 |
437 delete mapper; | 450 delete mapper; |
438 | 451 |
439 return 100 - nr; | 452 return 100 - nr; |
466 | 479 |
467 newmax = (newdist + sqrtf(newdist*newdist + 4*dmin*dmax)) / 2; | 480 newmax = (newdist + sqrtf(newdist*newdist + 4*dmin*dmax)) / 2; |
468 newmin = newmax - newdist; | 481 newmin = newmax - newdist; |
469 | 482 |
470 #ifdef DEBUG_TIME_VALUE_LAYER | 483 #ifdef DEBUG_TIME_VALUE_LAYER |
471 std::cerr << "newmin = " << newmin << ", newmax = " << newmax << std::endl; | 484 cerr << "newmin = " << newmin << ", newmax = " << newmax << endl; |
472 #endif | 485 #endif |
473 | 486 |
474 } else { | 487 } else { |
475 float dmid = (dmax + dmin) / 2; | 488 float dmid = (dmax + dmin) / 2; |
476 newmin = dmid - newdist / 2; | 489 newmin = dmid - newdist / 2; |
484 if (newmax > max) { | 497 if (newmax > max) { |
485 newmax = max; | 498 newmax = max; |
486 } | 499 } |
487 | 500 |
488 #ifdef DEBUG_TIME_VALUE_LAYER | 501 #ifdef DEBUG_TIME_VALUE_LAYER |
489 std::cerr << "TimeValueLayer::setVerticalZoomStep: " << step << ": " << newmin << " -> " << newmax << " (range " << newdist << ")" << std::endl; | 502 cerr << "TimeValueLayer::setVerticalZoomStep: " << step << ": " << newmin << " -> " << newmax << " (range " << newdist << ")" << endl; |
490 #endif | 503 #endif |
491 | 504 |
492 setDisplayExtents(newmin, newmax); | 505 setDisplayExtents(newmin, newmax); |
493 } | 506 } |
494 | 507 |
592 long useFrame = points.begin()->frame; | 605 long useFrame = points.begin()->frame; |
593 | 606 |
594 RealTime rt = RealTime::frame2RealTime(useFrame, m_model->getSampleRate()); | 607 RealTime rt = RealTime::frame2RealTime(useFrame, m_model->getSampleRate()); |
595 | 608 |
596 QString text; | 609 QString text; |
597 QString unit = m_model->getScaleUnits(); | 610 QString unit = getScaleUnits(); |
598 if (unit != "") unit = " " + unit; | 611 if (unit != "") unit = " " + unit; |
599 | 612 |
600 if (points.begin()->label == "") { | 613 if (points.begin()->label == "") { |
601 text = QString(tr("Time:\t%1\nValue:\t%2%3\nNo label")) | 614 text = QString(tr("Time:\t%1\nValue:\t%2%3\nNo label")) |
602 .arg(rt.toText(true).c_str()) | 615 .arg(rt.toText(true).c_str()) |
767 max = 0.0; | 780 max = 0.0; |
768 log = false; | 781 log = false; |
769 | 782 |
770 if (shouldAutoAlign()) { | 783 if (shouldAutoAlign()) { |
771 | 784 |
772 if (!v->getValueExtents(m_model->getScaleUnits(), min, max, log)) { | 785 if (!v->getValueExtents(getScaleUnits(), min, max, log)) { |
773 min = m_model->getValueMinimum(); | 786 min = m_model->getValueMinimum(); |
774 max = m_model->getValueMaximum(); | 787 max = m_model->getValueMaximum(); |
775 } else if (log) { | 788 } else if (log) { |
776 LogRange::mapRange(min, max); | 789 LogRange::mapRange(min, max); |
777 } | 790 } |
790 log = true; | 803 log = true; |
791 } | 804 } |
792 } | 805 } |
793 | 806 |
794 #ifdef DEBUG_TIME_VALUE_LAYER | 807 #ifdef DEBUG_TIME_VALUE_LAYER |
795 std::cerr << "TimeValueLayer::getScaleExtents: min = " << min << ", max = " << max << std::endl; | 808 cerr << "TimeValueLayer::getScaleExtents: min = " << min << ", max = " << max << endl; |
796 #endif | 809 #endif |
797 } | 810 } |
798 | 811 |
799 int | 812 int |
800 TimeValueLayer::getYForValue(View *v, float val) const | 813 TimeValueLayer::getYForValue(View *v, float val) const |
804 int h = v->height(); | 817 int h = v->height(); |
805 | 818 |
806 getScaleExtents(v, min, max, logarithmic); | 819 getScaleExtents(v, min, max, logarithmic); |
807 | 820 |
808 #ifdef DEBUG_TIME_VALUE_LAYER | 821 #ifdef DEBUG_TIME_VALUE_LAYER |
809 std::cerr << "getYForValue(" << val << "): min " << min << ", max " | 822 cerr << "getYForValue(" << val << "): min " << min << ", max " |
810 << max << ", log " << logarithmic << std::endl; | 823 << max << ", log " << logarithmic << endl; |
811 #endif | 824 #endif |
812 | 825 |
813 if (logarithmic) { | 826 if (logarithmic) { |
814 val = LogRange::map(val); | 827 val = LogRange::map(val); |
815 } | 828 } |
837 | 850 |
838 bool | 851 bool |
839 TimeValueLayer::shouldAutoAlign() const | 852 TimeValueLayer::shouldAutoAlign() const |
840 { | 853 { |
841 if (!m_model) return false; | 854 if (!m_model) return false; |
842 QString unit = m_model->getScaleUnits(); | 855 QString unit = getScaleUnits(); |
843 return (m_verticalScale == AutoAlignScale && unit != ""); | 856 return (m_verticalScale == AutoAlignScale && unit != ""); |
844 } | 857 } |
845 | 858 |
846 QColor | 859 QColor |
847 TimeValueLayer::getColourForValue(View *v, float val) const | 860 TimeValueLayer::getColourForValue(View *v, float val) const |
856 if (log) { | 869 if (log) { |
857 val = LogRange::map(val); | 870 val = LogRange::map(val); |
858 } | 871 } |
859 | 872 |
860 #ifdef DEBUG_TIME_VALUE_LAYER | 873 #ifdef DEBUG_TIME_VALUE_LAYER |
861 std::cerr << "TimeValueLayer::getColourForValue: min " << min << ", max " | 874 cerr << "TimeValueLayer::getColourForValue: min " << min << ", max " |
862 << max << ", log " << log << ", value " << val << std::endl; | 875 << max << ", log " << log << ", value " << val << endl; |
863 #endif | 876 #endif |
864 | 877 |
865 QColor solid = ColourMapper(m_colourMap, min, max).map(val); | 878 QColor solid = ColourMapper(m_colourMap, min, max).map(val); |
866 return QColor(solid.red(), solid.green(), solid.blue(), 120); | 879 return QColor(solid.red(), solid.green(), solid.blue(), 120); |
867 } | 880 } |
900 QColor brushColour(getBaseQColor()); | 913 QColor brushColour(getBaseQColor()); |
901 brushColour.setAlpha(80); | 914 brushColour.setAlpha(80); |
902 paint.setBrush(brushColour); | 915 paint.setBrush(brushColour); |
903 | 916 |
904 #ifdef DEBUG_TIME_VALUE_LAYER | 917 #ifdef DEBUG_TIME_VALUE_LAYER |
905 std::cerr << "TimeValueLayer::paint: resolution is " | 918 cerr << "TimeValueLayer::paint: resolution is " |
906 << m_model->getResolution() << " frames" << std::endl; | 919 << m_model->getResolution() << " frames" << endl; |
907 #endif | 920 #endif |
908 | 921 |
909 float min = m_model->getValueMinimum(); | 922 float min = m_model->getValueMinimum(); |
910 float max = m_model->getValueMaximum(); | 923 float max = m_model->getValueMaximum(); |
911 if (max == min) max = min + 1.0; | 924 if (max == min) max = min + 1.0; |
918 | 931 |
919 if (v->shouldIlluminateLocalFeatures(this, localPos)) { | 932 if (v->shouldIlluminateLocalFeatures(this, localPos)) { |
920 SparseTimeValueModel::PointList localPoints = | 933 SparseTimeValueModel::PointList localPoints = |
921 getLocalPoints(v, localPos.x()); | 934 getLocalPoints(v, localPos.x()); |
922 #ifdef DEBUG_TIME_VALUE_LAYER | 935 #ifdef DEBUG_TIME_VALUE_LAYER |
923 std::cerr << "TimeValueLayer: " << localPoints.size() << " local points" << std::endl; | 936 cerr << "TimeValueLayer: " << localPoints.size() << " local points" << endl; |
924 #endif | 937 #endif |
925 if (!localPoints.empty()) illuminateFrame = localPoints.begin()->frame; | 938 if (!localPoints.empty()) illuminateFrame = localPoints.begin()->frame; |
926 } | 939 } |
927 | 940 |
928 int w = | 941 int w = |
1002 nx = v->getXForFrame(nf); | 1015 nx = v->getXForFrame(nf); |
1003 ny = getYForValue(v, nvalue); | 1016 ny = getYForValue(v, nvalue); |
1004 haveNext = true; | 1017 haveNext = true; |
1005 } | 1018 } |
1006 | 1019 |
1007 // std::cout << "frame = " << p.frame << ", x = " << x << ", haveNext = " << haveNext | 1020 // cout << "frame = " << p.frame << ", x = " << x << ", haveNext = " << haveNext |
1008 // << ", nx = " << nx << std::endl; | 1021 // << ", nx = " << nx << endl; |
1009 | 1022 |
1010 if (m_plotStyle == PlotDiscreteCurves) { | 1023 if (m_plotStyle == PlotDiscreteCurves) { |
1011 paint.setPen(QPen(getBaseQColor(), 3)); | 1024 paint.setPen(QPen(getBaseQColor(), 3)); |
1012 paint.setBrush(Qt::NoBrush); | 1025 paint.setBrush(Qt::NoBrush); |
1013 } else if (m_plotStyle == PlotSegmentation) { | 1026 } else if (m_plotStyle == PlotSegmentation) { |
1130 } | 1143 } |
1131 | 1144 |
1132 if (m_plotStyle == PlotSegmentation) { | 1145 if (m_plotStyle == PlotSegmentation) { |
1133 | 1146 |
1134 #ifdef DEBUG_TIME_VALUE_LAYER | 1147 #ifdef DEBUG_TIME_VALUE_LAYER |
1135 std::cerr << "drawing rect" << std::endl; | 1148 cerr << "drawing rect" << endl; |
1136 #endif | 1149 #endif |
1137 | 1150 |
1138 if (nx <= x) continue; | 1151 if (nx <= x) continue; |
1139 | 1152 |
1140 paint.setPen(QPen(getForegroundQColor(v), 2)); | 1153 paint.setPen(QPen(getForegroundQColor(v), 2)); |
1177 | 1190 |
1178 prevFrame = p.frame; | 1191 prevFrame = p.frame; |
1179 ++pointCount; | 1192 ++pointCount; |
1180 } | 1193 } |
1181 | 1194 |
1182 if ((m_plotStyle == PlotCurve || m_plotStyle == PlotDiscreteCurves || | 1195 if (m_plotStyle == PlotDiscreteCurves) { |
1183 m_plotStyle == PlotLines) | 1196 paint.setRenderHint(QPainter::Antialiasing, true); |
1184 && !path.isEmpty()) { | 1197 paint.drawPath(path); |
1198 } else if ((m_plotStyle == PlotCurve || m_plotStyle == PlotLines) | |
1199 && !path.isEmpty()) { | |
1185 paint.setRenderHint(QPainter::Antialiasing, pointCount <= v->width()); | 1200 paint.setRenderHint(QPainter::Antialiasing, pointCount <= v->width()); |
1186 paint.drawPath(path); | 1201 paint.drawPath(path); |
1187 } | 1202 } |
1188 | 1203 |
1189 paint.restore(); | 1204 paint.restore(); |
1191 // looks like save/restore doesn't deal with this: | 1206 // looks like save/restore doesn't deal with this: |
1192 paint.setRenderHint(QPainter::Antialiasing, false); | 1207 paint.setRenderHint(QPainter::Antialiasing, false); |
1193 } | 1208 } |
1194 | 1209 |
1195 int | 1210 int |
1196 TimeValueLayer::getVerticalScaleWidth(View *, bool, QPainter &paint) const | 1211 TimeValueLayer::getVerticalScaleWidth(View *v, bool, QPainter &paint) const |
1197 { | 1212 { |
1198 int w = paint.fontMetrics().width("-000.000"); | 1213 if (!m_model || shouldAutoAlign()) { |
1199 if (m_plotStyle == PlotSegmentation) return w + 20; | 1214 return 0; |
1200 else return w + 10; | 1215 } else if (m_plotStyle == PlotSegmentation) { |
1216 if (m_verticalScale == LogScale) { | |
1217 return LogColourScale().getWidth(v, paint); | |
1218 } else { | |
1219 return LinearColourScale().getWidth(v, paint); | |
1220 } | |
1221 } else { | |
1222 if (m_verticalScale == LogScale) { | |
1223 return LogNumericalScale().getWidth(v, paint) + 10; // for piano | |
1224 } else { | |
1225 return LinearNumericalScale().getWidth(v, paint); | |
1226 } | |
1227 } | |
1201 } | 1228 } |
1202 | 1229 |
1203 void | 1230 void |
1204 TimeValueLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect) const | 1231 TimeValueLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect) const |
1205 { | 1232 { |
1206 if (!m_model) return; | 1233 if (!m_model) return; |
1207 | 1234 |
1208 int h = v->height(); | 1235 QString unit; |
1209 | |
1210 int n = 10; | |
1211 | |
1212 float min, max; | 1236 float min, max; |
1213 bool logarithmic; | 1237 bool logarithmic; |
1214 getScaleExtents(v, min, max, logarithmic); | 1238 |
1239 int w = getVerticalScaleWidth(v, false, paint); | |
1240 int h = v->height(); | |
1215 | 1241 |
1216 if (m_plotStyle == PlotSegmentation) { | 1242 if (m_plotStyle == PlotSegmentation) { |
1217 QString unit; | 1243 |
1218 getValueExtents(min, max, logarithmic, unit); | 1244 getValueExtents(min, max, logarithmic, unit); |
1245 | |
1219 if (logarithmic) { | 1246 if (logarithmic) { |
1220 LogRange::mapRange(min, max); | 1247 LogRange::mapRange(min, max); |
1221 } | 1248 LogColourScale().paintVertical(v, this, paint, 0, min, max); |
1222 } | |
1223 | |
1224 float val = min; | |
1225 float inc = (max - val) / n; | |
1226 | |
1227 char buffer[40]; | |
1228 | |
1229 int w = getVerticalScaleWidth(v, false, paint); | |
1230 | |
1231 int tx = 5; | |
1232 | |
1233 int boxx = 5, boxy = 5; | |
1234 if (m_model->getScaleUnits() != "") { | |
1235 boxy += paint.fontMetrics().height(); | |
1236 } | |
1237 int boxw = 10, boxh = h - boxy - 5; | |
1238 | |
1239 if (m_plotStyle == PlotSegmentation) { | |
1240 tx += boxx + boxw; | |
1241 paint.drawRect(boxx, boxy, boxw, boxh); | |
1242 } | |
1243 | |
1244 if (m_plotStyle == PlotSegmentation) { | |
1245 paint.save(); | |
1246 for (int y = 0; y < boxh; ++y) { | |
1247 float val = ((boxh - y) * (max - min)) / boxh + min; | |
1248 if (logarithmic) { | |
1249 paint.setPen(getColourForValue(v, LogRange::unmap(val))); | |
1250 } else { | |
1251 paint.setPen(getColourForValue(v, val)); | |
1252 } | |
1253 paint.drawLine(boxx + 1, y + boxy + 1, boxx + boxw, y + boxy + 1); | |
1254 } | |
1255 paint.restore(); | |
1256 } | |
1257 | |
1258 float round = 1.f; | |
1259 int dp = 0; | |
1260 if (inc > 0) { | |
1261 int prec = trunc(log10f(inc)); | |
1262 prec -= 1; | |
1263 if (prec < 0) dp = -prec; | |
1264 round = powf(10.f, prec); | |
1265 #ifdef DEBUG_TIME_VALUE_LAYER | |
1266 std::cerr << "inc = " << inc << ", round = " << round << ", dp = " << dp << std::endl; | |
1267 #endif | |
1268 } | |
1269 | |
1270 int prevy = -1; | |
1271 | |
1272 for (int i = 0; i < n; ++i) { | |
1273 | |
1274 int y, ty; | |
1275 bool drawText = true; | |
1276 | |
1277 float dispval = val; | |
1278 | |
1279 if (m_plotStyle == PlotSegmentation) { | |
1280 y = boxy + int(boxh - ((val - min) * boxh) / (max - min)); | |
1281 ty = y; | |
1282 } else { | 1249 } else { |
1283 if (i == n-1 && | 1250 LinearColourScale().paintVertical(v, this, paint, 0, min, max); |
1284 v->height() < paint.fontMetrics().height() * (n*2)) { | 1251 } |
1285 if (m_model->getScaleUnits() != "") drawText = false; | 1252 |
1286 } | 1253 } else { |
1287 dispval = lrintf(val / round) * round; | 1254 |
1288 #ifdef DEBUG_TIME_VALUE_LAYER | 1255 getScaleExtents(v, min, max, logarithmic); |
1289 std::cerr << "val = " << val << ", dispval = " << dispval << std::endl; | |
1290 #endif | |
1291 if (logarithmic) { | |
1292 y = getYForValue(v, LogRange::unmap(dispval)); | |
1293 } else { | |
1294 y = getYForValue(v, dispval); | |
1295 } | |
1296 ty = y - paint.fontMetrics().height() + | |
1297 paint.fontMetrics().ascent() + 2; | |
1298 | |
1299 if (prevy >= 0 && (prevy - y) < paint.fontMetrics().height()) { | |
1300 val += inc; | |
1301 continue; | |
1302 } | |
1303 } | |
1304 | 1256 |
1305 if (logarithmic) { | 1257 if (logarithmic) { |
1306 double dv = LogRange::unmap(dispval); | 1258 LogNumericalScale().paintVertical(v, this, paint, 0, min, max); |
1307 int digits = trunc(log10f(dv)); | |
1308 int sf = dp + (digits > 0 ? digits : 0); | |
1309 if (sf < 2) sf = 2; | |
1310 sprintf(buffer, "%.*g", sf, dv); | |
1311 } else { | 1259 } else { |
1312 sprintf(buffer, "%.*f", dp, dispval); | 1260 LinearNumericalScale().paintVertical(v, this, paint, 0, min, max); |
1313 } | 1261 } |
1314 QString label = QString(buffer); | 1262 |
1315 | 1263 if (logarithmic && (getScaleUnits() == "Hz")) { |
1316 if (m_plotStyle != PlotSegmentation) { | 1264 PianoScale().paintPianoVertical |
1317 paint.drawLine(w - 5, y, w, y); | 1265 (v, paint, QRect(w - 10, 0, 10, h), |
1318 } else { | 1266 LogRange::unmap(min), |
1319 paint.drawLine(boxx + boxw - boxw/3, y, boxx + boxw, y); | 1267 LogRange::unmap(max)); |
1320 } | 1268 paint.drawLine(w, 0, w, h); |
1321 | 1269 } |
1322 if (drawText) { | 1270 } |
1323 if (m_plotStyle != PlotSegmentation) { | 1271 |
1324 paint.drawText(tx + w - paint.fontMetrics().width(label) - 8, | 1272 if (getScaleUnits() != "") { |
1325 ty, label); | 1273 int mw = w - 5; |
1326 } else { | 1274 paint.drawText(5, |
1327 paint.drawText(tx, ty, label); | 1275 5 + paint.fontMetrics().ascent(), |
1328 } | 1276 TextAbbrev::abbreviate(getScaleUnits(), |
1329 } | 1277 paint.fontMetrics(), |
1330 | 1278 mw)); |
1331 prevy = y; | |
1332 val += inc; | |
1333 } | |
1334 | |
1335 if (m_model->getScaleUnits() != "") { | |
1336 paint.drawText(5, 5 + paint.fontMetrics().ascent(), | |
1337 m_model->getScaleUnits()); | |
1338 } | 1279 } |
1339 } | 1280 } |
1340 | 1281 |
1341 void | 1282 void |
1342 TimeValueLayer::drawStart(View *v, QMouseEvent *e) | 1283 TimeValueLayer::drawStart(View *v, QMouseEvent *e) |
1343 { | 1284 { |
1344 #ifdef DEBUG_TIME_VALUE_LAYER | 1285 #ifdef DEBUG_TIME_VALUE_LAYER |
1345 std::cerr << "TimeValueLayer::drawStart(" << e->x() << "," << e->y() << ")" << std::endl; | 1286 cerr << "TimeValueLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl; |
1346 #endif | 1287 #endif |
1347 | 1288 |
1348 if (!m_model) return; | 1289 if (!m_model) return; |
1349 | 1290 |
1350 long frame = v->getFrameForX(e->x()); | 1291 long frame = v->getFrameForX(e->x()); |
1360 if (!points.empty()) { | 1301 if (!points.empty()) { |
1361 for (SparseTimeValueModel::PointList::iterator i = points.begin(); | 1302 for (SparseTimeValueModel::PointList::iterator i = points.begin(); |
1362 i != points.end(); ++i) { | 1303 i != points.end(); ++i) { |
1363 if (((i->frame / resolution) * resolution) != frame) { | 1304 if (((i->frame / resolution) * resolution) != frame) { |
1364 #ifdef DEBUG_TIME_VALUE_LAYER | 1305 #ifdef DEBUG_TIME_VALUE_LAYER |
1365 std::cerr << "ignoring out-of-range frame at " << i->frame << std::endl; | 1306 cerr << "ignoring out-of-range frame at " << i->frame << endl; |
1366 #endif | 1307 #endif |
1367 continue; | 1308 continue; |
1368 } | 1309 } |
1369 m_editingPoint = *i; | 1310 m_editingPoint = *i; |
1370 havePoint = true; | 1311 havePoint = true; |
1390 | 1331 |
1391 void | 1332 void |
1392 TimeValueLayer::drawDrag(View *v, QMouseEvent *e) | 1333 TimeValueLayer::drawDrag(View *v, QMouseEvent *e) |
1393 { | 1334 { |
1394 #ifdef DEBUG_TIME_VALUE_LAYER | 1335 #ifdef DEBUG_TIME_VALUE_LAYER |
1395 std::cerr << "TimeValueLayer::drawDrag(" << e->x() << "," << e->y() << ")" << std::endl; | 1336 cerr << "TimeValueLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl; |
1396 #endif | 1337 #endif |
1397 | 1338 |
1398 if (!m_model || !m_editing) return; | 1339 if (!m_model || !m_editing) return; |
1399 | 1340 |
1400 long frame = v->getFrameForX(e->x()); | 1341 long frame = v->getFrameForX(e->x()); |
1405 float value = getValueForY(v, e->y()); | 1346 float value = getValueForY(v, e->y()); |
1406 | 1347 |
1407 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x()); | 1348 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x()); |
1408 | 1349 |
1409 #ifdef DEBUG_TIME_VALUE_LAYER | 1350 #ifdef DEBUG_TIME_VALUE_LAYER |
1410 std::cerr << points.size() << " points" << std::endl; | 1351 cerr << points.size() << " points" << endl; |
1411 #endif | 1352 #endif |
1412 | 1353 |
1413 bool havePoint = false; | 1354 bool havePoint = false; |
1414 | 1355 |
1415 if (!points.empty()) { | 1356 if (!points.empty()) { |
1416 for (SparseTimeValueModel::PointList::iterator i = points.begin(); | 1357 for (SparseTimeValueModel::PointList::iterator i = points.begin(); |
1417 i != points.end(); ++i) { | 1358 i != points.end(); ++i) { |
1418 if (i->frame == m_editingPoint.frame && | 1359 if (i->frame == m_editingPoint.frame && |
1419 i->value == m_editingPoint.value) { | 1360 i->value == m_editingPoint.value) { |
1420 #ifdef DEBUG_TIME_VALUE_LAYER | 1361 #ifdef DEBUG_TIME_VALUE_LAYER |
1421 std::cerr << "ignoring current editing point at " << i->frame << ", " << i->value << std::endl; | 1362 cerr << "ignoring current editing point at " << i->frame << ", " << i->value << endl; |
1422 #endif | 1363 #endif |
1423 continue; | 1364 continue; |
1424 } | 1365 } |
1425 if (((i->frame / resolution) * resolution) != frame) { | 1366 if (((i->frame / resolution) * resolution) != frame) { |
1426 #ifdef DEBUG_TIME_VALUE_LAYER | 1367 #ifdef DEBUG_TIME_VALUE_LAYER |
1427 std::cerr << "ignoring out-of-range frame at " << i->frame << std::endl; | 1368 cerr << "ignoring out-of-range frame at " << i->frame << endl; |
1428 #endif | 1369 #endif |
1429 continue; | 1370 continue; |
1430 } | 1371 } |
1431 #ifdef DEBUG_TIME_VALUE_LAYER | 1372 #ifdef DEBUG_TIME_VALUE_LAYER |
1432 std::cerr << "adjusting to new point at " << i->frame << ", " << i->value << std::endl; | 1373 cerr << "adjusting to new point at " << i->frame << ", " << i->value << endl; |
1433 #endif | 1374 #endif |
1434 m_editingPoint = *i; | 1375 m_editingPoint = *i; |
1435 m_originalPoint = m_editingPoint; | 1376 m_originalPoint = m_editingPoint; |
1436 m_editingCommand->deletePoint(m_editingPoint); | 1377 m_editingCommand->deletePoint(m_editingPoint); |
1437 havePoint = true; | 1378 havePoint = true; |
1452 | 1393 |
1453 void | 1394 void |
1454 TimeValueLayer::drawEnd(View *, QMouseEvent *) | 1395 TimeValueLayer::drawEnd(View *, QMouseEvent *) |
1455 { | 1396 { |
1456 #ifdef DEBUG_TIME_VALUE_LAYER | 1397 #ifdef DEBUG_TIME_VALUE_LAYER |
1457 std::cerr << "TimeValueLayer::drawEnd" << std::endl; | 1398 cerr << "TimeValueLayer::drawEnd" << endl; |
1458 #endif | 1399 #endif |
1459 if (!m_model || !m_editing) return; | 1400 if (!m_model || !m_editing) return; |
1460 finish(m_editingCommand); | 1401 finish(m_editingCommand); |
1461 m_editingCommand = 0; | 1402 m_editingCommand = 0; |
1462 m_editing = false; | 1403 m_editing = false; |
1509 | 1450 |
1510 void | 1451 void |
1511 TimeValueLayer::editStart(View *v, QMouseEvent *e) | 1452 TimeValueLayer::editStart(View *v, QMouseEvent *e) |
1512 { | 1453 { |
1513 #ifdef DEBUG_TIME_VALUE_LAYER | 1454 #ifdef DEBUG_TIME_VALUE_LAYER |
1514 std::cerr << "TimeValueLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl; | 1455 cerr << "TimeValueLayer::editStart(" << e->x() << "," << e->y() << ")" << endl; |
1515 #endif | 1456 #endif |
1516 | 1457 |
1517 if (!m_model) return; | 1458 if (!m_model) return; |
1518 | 1459 |
1519 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x()); | 1460 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x()); |
1532 | 1473 |
1533 void | 1474 void |
1534 TimeValueLayer::editDrag(View *v, QMouseEvent *e) | 1475 TimeValueLayer::editDrag(View *v, QMouseEvent *e) |
1535 { | 1476 { |
1536 #ifdef DEBUG_TIME_VALUE_LAYER | 1477 #ifdef DEBUG_TIME_VALUE_LAYER |
1537 std::cerr << "TimeValueLayer::editDrag(" << e->x() << "," << e->y() << ")" << std::endl; | 1478 cerr << "TimeValueLayer::editDrag(" << e->x() << "," << e->y() << ")" << endl; |
1538 #endif | 1479 #endif |
1539 | 1480 |
1540 if (!m_model || !m_editing) return; | 1481 if (!m_model || !m_editing) return; |
1541 | 1482 |
1542 long frame = v->getFrameForX(e->x()); | 1483 long frame = v->getFrameForX(e->x()); |
1558 | 1499 |
1559 void | 1500 void |
1560 TimeValueLayer::editEnd(View *, QMouseEvent *) | 1501 TimeValueLayer::editEnd(View *, QMouseEvent *) |
1561 { | 1502 { |
1562 #ifdef DEBUG_TIME_VALUE_LAYER | 1503 #ifdef DEBUG_TIME_VALUE_LAYER |
1563 std::cerr << "TimeValueLayer::editEnd" << std::endl; | 1504 cerr << "TimeValueLayer::editEnd" << endl; |
1564 #endif | 1505 #endif |
1565 if (!m_model || !m_editing) return; | 1506 if (!m_model || !m_editing) return; |
1566 | 1507 |
1567 if (m_editingCommand) { | 1508 if (m_editingCommand) { |
1568 | 1509 |
1599 ItemEditDialog *dialog = new ItemEditDialog | 1540 ItemEditDialog *dialog = new ItemEditDialog |
1600 (m_model->getSampleRate(), | 1541 (m_model->getSampleRate(), |
1601 ItemEditDialog::ShowTime | | 1542 ItemEditDialog::ShowTime | |
1602 ItemEditDialog::ShowValue | | 1543 ItemEditDialog::ShowValue | |
1603 ItemEditDialog::ShowText, | 1544 ItemEditDialog::ShowText, |
1604 m_model->getScaleUnits()); | 1545 getScaleUnits()); |
1605 | 1546 |
1606 dialog->setFrameTime(point.frame); | 1547 dialog->setFrameTime(point.frame); |
1607 dialog->setValue(point.value); | 1548 dialog->setValue(point.value); |
1608 dialog->setText(point.label); | 1549 dialog->setText(point.label); |
1609 | 1550 |
1898 | 1839 |
1899 if (i->haveValue()) { | 1840 if (i->haveValue()) { |
1900 newPoint.value = i->getValue(); | 1841 newPoint.value = i->getValue(); |
1901 } else { | 1842 } else { |
1902 #ifdef DEBUG_TIME_VALUE_LAYER | 1843 #ifdef DEBUG_TIME_VALUE_LAYER |
1903 std::cerr << "Setting value on point at " << newPoint.frame << " from labeller"; | 1844 cerr << "Setting value on point at " << newPoint.frame << " from labeller"; |
1904 if (i == points.begin()) { | 1845 if (i == points.begin()) { |
1905 std::cerr << ", no prev point" << std::endl; | 1846 cerr << ", no prev point" << endl; |
1906 } else { | 1847 } else { |
1907 std::cerr << ", prev point is at " << prevPoint.frame << std::endl; | 1848 cerr << ", prev point is at " << prevPoint.frame << endl; |
1908 } | 1849 } |
1909 #endif | 1850 #endif |
1910 labeller.setValue<SparseTimeValueModel::Point> | 1851 labeller.setValue<SparseTimeValueModel::Point> |
1911 (newPoint, (i == points.begin()) ? 0 : &prevPoint); | 1852 (newPoint, (i == points.begin()) ? 0 : &prevPoint); |
1912 #ifdef DEBUG_TIME_VALUE_LAYER | 1853 #ifdef DEBUG_TIME_VALUE_LAYER |
1913 std::cerr << "New point value = " << newPoint.value << std::endl; | 1854 cerr << "New point value = " << newPoint.value << endl; |
1914 #endif | 1855 #endif |
1915 if (labeller.actingOnPrevPoint() && i != points.begin()) { | 1856 if (labeller.actingOnPrevPoint() && i != points.begin()) { |
1916 usePrev = true; | 1857 usePrev = true; |
1917 } | 1858 } |
1918 } | 1859 } |
1971 setShowDerivative(derivative); | 1912 setShowDerivative(derivative); |
1972 | 1913 |
1973 float min = attributes.value("scaleMinimum").toFloat(&ok); | 1914 float min = attributes.value("scaleMinimum").toFloat(&ok); |
1974 float max = attributes.value("scaleMaximum").toFloat(&alsoOk); | 1915 float max = attributes.value("scaleMaximum").toFloat(&alsoOk); |
1975 #ifdef DEBUG_TIME_VALUE_LAYER | 1916 #ifdef DEBUG_TIME_VALUE_LAYER |
1976 std::cerr << "from properties: min = " << min << ", max = " << max << std::endl; | 1917 cerr << "from properties: min = " << min << ", max = " << max << endl; |
1977 #endif | 1918 #endif |
1978 if (ok && alsoOk && min != max) setDisplayExtents(min, max); | 1919 if (ok && alsoOk && min != max) setDisplayExtents(min, max); |
1979 } | 1920 } |
1980 | 1921 |