Mercurial > hg > svgui
comparison layer/FlexiNoteLayer.cpp @ 1216:dc2af6616c83
Merge from branch 3.0-integration
author | Chris Cannam |
---|---|
date | Fri, 13 Jan 2017 10:29:50 +0000 |
parents | ee01a4062747 |
children | c39f2d439d59 |
comparison
equal
deleted
inserted
replaced
1048:e8102ff5573b | 1216:dc2af6616c83 |
---|---|
20 #include "base/RealTime.h" | 20 #include "base/RealTime.h" |
21 #include "base/Profiler.h" | 21 #include "base/Profiler.h" |
22 #include "base/Pitch.h" | 22 #include "base/Pitch.h" |
23 #include "base/LogRange.h" | 23 #include "base/LogRange.h" |
24 #include "base/RangeMapper.h" | 24 #include "base/RangeMapper.h" |
25 | |
25 #include "ColourDatabase.h" | 26 #include "ColourDatabase.h" |
26 #include "view/View.h" | 27 #include "LayerGeometryProvider.h" |
27 | |
28 #include "PianoScale.h" | 28 #include "PianoScale.h" |
29 #include "LinearNumericalScale.h" | 29 #include "LinearNumericalScale.h" |
30 #include "LogNumericalScale.h" | 30 #include "LogNumericalScale.h" |
31 #include "PaintAssistant.h" | |
31 | 32 |
32 #include "data/model/FlexiNoteModel.h" | 33 #include "data/model/FlexiNoteModel.h" |
34 | |
35 #include "view/View.h" | |
33 | 36 |
34 #include "widgets/ItemEditDialog.h" | 37 #include "widgets/ItemEditDialog.h" |
35 #include "widgets/TextAbbrev.h" | 38 #include "widgets/TextAbbrev.h" |
36 | 39 |
37 #include <QPainter> | 40 #include <QPainter> |
202 m_verticalScale = scale; | 205 m_verticalScale = scale; |
203 emit layerParametersChanged(); | 206 emit layerParametersChanged(); |
204 } | 207 } |
205 | 208 |
206 bool | 209 bool |
207 FlexiNoteLayer::isLayerScrollable(const View *v) const | 210 FlexiNoteLayer::isLayerScrollable(const LayerGeometryProvider *v) const |
208 { | 211 { |
209 QPoint discard; | 212 QPoint discard; |
210 return !v->shouldIlluminateLocalFeatures(this, discard); | 213 return !v->shouldIlluminateLocalFeatures(this, discard); |
211 } | 214 } |
212 | 215 |
403 | 406 |
404 return mapper; | 407 return mapper; |
405 } | 408 } |
406 | 409 |
407 FlexiNoteModel::PointList | 410 FlexiNoteModel::PointList |
408 FlexiNoteLayer::getLocalPoints(View *v, int x) const | 411 FlexiNoteLayer::getLocalPoints(LayerGeometryProvider *v, int x) const |
409 { | 412 { |
410 if (!m_model) return FlexiNoteModel::PointList(); | 413 if (!m_model) return FlexiNoteModel::PointList(); |
411 | 414 |
412 sv_frame_t frame = v->getFrameForX(x); | 415 sv_frame_t frame = v->getFrameForX(x); |
413 | 416 |
446 | 449 |
447 return usePoints; | 450 return usePoints; |
448 } | 451 } |
449 | 452 |
450 bool | 453 bool |
451 FlexiNoteLayer::getPointToDrag(View *v, int x, int y, FlexiNoteModel::Point &p) const | 454 FlexiNoteLayer::getPointToDrag(LayerGeometryProvider *v, int x, int y, FlexiNoteModel::Point &p) const |
452 { | 455 { |
453 if (!m_model) return false; | 456 if (!m_model) return false; |
454 | 457 |
455 sv_frame_t frame = v->getFrameForX(x); | 458 sv_frame_t frame = v->getFrameForX(x); |
456 | 459 |
474 | 477 |
475 return true; | 478 return true; |
476 } | 479 } |
477 | 480 |
478 bool | 481 bool |
479 FlexiNoteLayer::getNoteToEdit(View *v, int x, int y, FlexiNoteModel::Point &p) const | 482 FlexiNoteLayer::getNoteToEdit(LayerGeometryProvider *v, int x, int y, FlexiNoteModel::Point &p) const |
480 { | 483 { |
481 // GF: find the note that is closest to the cursor | 484 // GF: find the note that is closest to the cursor |
482 if (!m_model) return false; | 485 if (!m_model) return false; |
483 | 486 |
484 sv_frame_t frame = v->getFrameForX(x); | 487 sv_frame_t frame = v->getFrameForX(x); |
503 | 506 |
504 return true; | 507 return true; |
505 } | 508 } |
506 | 509 |
507 QString | 510 QString |
508 FlexiNoteLayer::getFeatureDescription(View *v, QPoint &pos) const | 511 FlexiNoteLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const |
509 { | 512 { |
510 int x = pos.x(); | 513 int x = pos.x(); |
511 | 514 |
512 if (!m_model || !m_model->getSampleRate()) return ""; | 515 if (!m_model || !m_model->getSampleRate()) return ""; |
513 | 516 |
591 getYForValue(v, note.value)); | 594 getYForValue(v, note.value)); |
592 return text; | 595 return text; |
593 } | 596 } |
594 | 597 |
595 bool | 598 bool |
596 FlexiNoteLayer::snapToFeatureFrame(View *v, sv_frame_t &frame, | 599 FlexiNoteLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, |
597 int &resolution, | 600 int &resolution, |
598 SnapType snap) const | 601 SnapType snap) const |
599 { | 602 { |
600 if (!m_model) { | 603 if (!m_model) { |
601 return Layer::snapToFeatureFrame(v, frame, resolution, snap); | 604 return Layer::snapToFeatureFrame(v, frame, resolution, snap); |
671 frame = snapped; | 674 frame = snapped; |
672 return found; | 675 return found; |
673 } | 676 } |
674 | 677 |
675 void | 678 void |
676 FlexiNoteLayer::getScaleExtents(View *v, double &min, double &max, bool &log) const | 679 FlexiNoteLayer::getScaleExtents(LayerGeometryProvider *v, double &min, double &max, bool &log) const |
677 { | 680 { |
678 min = 0.0; | 681 min = 0.0; |
679 max = 0.0; | 682 max = 0.0; |
680 log = false; | 683 log = false; |
681 | 684 |
728 | 731 |
729 if (max == min) max = min + 1.0; | 732 if (max == min) max = min + 1.0; |
730 } | 733 } |
731 | 734 |
732 int | 735 int |
733 FlexiNoteLayer::getYForValue(View *v, double val) const | 736 FlexiNoteLayer::getYForValue(LayerGeometryProvider *v, double val) const |
734 { | 737 { |
735 double min = 0.0, max = 0.0; | 738 double min = 0.0, max = 0.0; |
736 bool logarithmic = false; | 739 bool logarithmic = false; |
737 int h = v->height(); | 740 int h = v->getPaintHeight(); |
738 | 741 |
739 getScaleExtents(v, min, max, logarithmic); | 742 getScaleExtents(v, min, max, logarithmic); |
740 | 743 |
741 #ifdef DEBUG_NOTE_LAYER | 744 #ifdef DEBUG_NOTE_LAYER |
742 cerr << "FlexiNoteLayer[" << this << "]::getYForValue(" << val << "): min = " << min << ", max = " << max << ", log = " << logarithmic << endl; | 745 cerr << "FlexiNoteLayer[" << this << "]::getYForValue(" << val << "): min = " << min << ", max = " << max << ", log = " << logarithmic << endl; |
763 #endif | 766 #endif |
764 return y; | 767 return y; |
765 } | 768 } |
766 | 769 |
767 double | 770 double |
768 FlexiNoteLayer::getValueForY(View *v, int y) const | 771 FlexiNoteLayer::getValueForY(LayerGeometryProvider *v, int y) const |
769 { | 772 { |
770 double min = 0.0, max = 0.0; | 773 double min = 0.0, max = 0.0; |
771 bool logarithmic = false; | 774 bool logarithmic = false; |
772 int h = v->height(); | 775 int h = v->getPaintHeight(); |
773 | 776 |
774 getScaleExtents(v, min, max, logarithmic); | 777 getScaleExtents(v, min, max, logarithmic); |
775 | 778 |
776 double val = min + (double(h - y) * double(max - min)) / h; | 779 double val = min + (double(h - y) * double(max - min)) / h; |
777 | 780 |
792 if (!m_model) return false; | 795 if (!m_model) return false; |
793 return (m_verticalScale == AutoAlignScale); | 796 return (m_verticalScale == AutoAlignScale); |
794 } | 797 } |
795 | 798 |
796 void | 799 void |
797 FlexiNoteLayer::paint(View *v, QPainter &paint, QRect rect) const | 800 FlexiNoteLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const |
798 { | 801 { |
799 if (!m_model || !m_model->isOK()) return; | 802 if (!m_model || !m_model->isOK()) return; |
800 | 803 |
801 sv_samplerate_t sampleRate = m_model->getSampleRate(); | 804 sv_samplerate_t sampleRate = m_model->getSampleRate(); |
802 if (!sampleRate) return; | 805 if (!sampleRate) return; |
858 if (shouldIlluminate && | 861 if (shouldIlluminate && |
859 // "illuminatePoint == p" | 862 // "illuminatePoint == p" |
860 !FlexiNoteModel::Point::Comparator()(illuminatePoint, p) && | 863 !FlexiNoteModel::Point::Comparator()(illuminatePoint, p) && |
861 !FlexiNoteModel::Point::Comparator()(p, illuminatePoint)) { | 864 !FlexiNoteModel::Point::Comparator()(p, illuminatePoint)) { |
862 | 865 |
863 paint.drawLine(x, -1, x, v->height() + 1); | 866 paint.drawLine(x, -1, x, v->getPaintHeight() + 1); |
864 paint.drawLine(x+w, -1, x+w, v->height() + 1); | 867 paint.drawLine(x+w, -1, x+w, v->getPaintHeight() + 1); |
865 | 868 |
866 paint.setPen(v->getForeground()); | 869 paint.setPen(v->getForeground()); |
867 // paint.setBrush(v->getForeground()); | 870 // paint.setBrush(v->getForeground()); |
868 | 871 |
869 QString vlabel = QString("freq: %1%2").arg(p.value).arg(m_model->getScaleUnits()); | 872 QString vlabel = QString("freq: %1%2").arg(p.value).arg(m_model->getScaleUnits()); |
870 // v->drawVisibleText(paint, | 873 // PaintAssistant::drawVisibleText(v, paint, |
871 // x - paint.fontMetrics().width(vlabel) - 2, | 874 // x - paint.fontMetrics().width(vlabel) - 2, |
872 // y + paint.fontMetrics().height()/2 | 875 // y + paint.fontMetrics().height()/2 |
873 // - paint.fontMetrics().descent(), | 876 // - paint.fontMetrics().descent(), |
874 // vlabel, View::OutlinedText); | 877 // vlabel, PaintAssistant::OutlinedText); |
875 v->drawVisibleText(paint, | 878 PaintAssistant::drawVisibleText(v, paint, |
876 x, | 879 x, |
877 y - h/2 - 2 - paint.fontMetrics().height() | 880 y - h/2 - 2 - paint.fontMetrics().height() |
878 - paint.fontMetrics().descent(), | 881 - paint.fontMetrics().descent(), |
879 vlabel, View::OutlinedText); | 882 vlabel, PaintAssistant::OutlinedText); |
880 | 883 |
881 QString hlabel = "dur: " + QString(RealTime::frame2RealTime | 884 QString hlabel = "dur: " + QString(RealTime::frame2RealTime |
882 (p.duration, m_model->getSampleRate()).toText(true).c_str()); | 885 (p.duration, m_model->getSampleRate()).toText(true).c_str()); |
883 v->drawVisibleText(paint, | 886 PaintAssistant::drawVisibleText(v, paint, |
884 x, | 887 x, |
885 y - h/2 - paint.fontMetrics().descent() - 2, | 888 y - h/2 - paint.fontMetrics().descent() - 2, |
886 hlabel, View::OutlinedText); | 889 hlabel, PaintAssistant::OutlinedText); |
887 | 890 |
888 QString llabel = QString("%1").arg(p.label); | 891 QString llabel = QString("%1").arg(p.label); |
889 v->drawVisibleText(paint, | 892 PaintAssistant::drawVisibleText(v, paint, |
890 x, | 893 x, |
891 y + h + 2 + paint.fontMetrics().descent(), | 894 y + h + 2 + paint.fontMetrics().descent(), |
892 llabel, View::OutlinedText); | 895 llabel, PaintAssistant::OutlinedText); |
893 QString nlabel = QString("%1").arg(noteNumber); | 896 QString nlabel = QString("%1").arg(noteNumber); |
894 v->drawVisibleText(paint, | 897 PaintAssistant::drawVisibleText(v, paint, |
895 x + paint.fontMetrics().averageCharWidth() / 2, | 898 x + paint.fontMetrics().averageCharWidth() / 2, |
896 y + h/2 - paint.fontMetrics().descent(), | 899 y + h/2 - paint.fontMetrics().descent(), |
897 nlabel, View::OutlinedText); | 900 nlabel, PaintAssistant::OutlinedText); |
898 } | 901 } |
899 | 902 |
900 paint.drawRect(x, y - h/2, w, h); | 903 paint.drawRect(x, y - h/2, w, h); |
901 } | 904 } |
902 | 905 |
903 paint.restore(); | 906 paint.restore(); |
904 } | 907 } |
905 | 908 |
906 int | 909 int |
907 FlexiNoteLayer::getVerticalScaleWidth(View *v, bool, QPainter &paint) const | 910 FlexiNoteLayer::getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &paint) const |
908 { | 911 { |
909 if (!m_model || shouldAutoAlign()) { | 912 if (!m_model || shouldAutoAlign()) { |
910 return 0; | 913 return 0; |
911 } else { | 914 } else { |
912 if (m_verticalScale == LogScale || m_verticalScale == MIDIRangeScale) { | 915 if (m_verticalScale == LogScale || m_verticalScale == MIDIRangeScale) { |
916 } | 919 } |
917 } | 920 } |
918 } | 921 } |
919 | 922 |
920 void | 923 void |
921 FlexiNoteLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect) const | 924 FlexiNoteLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect) const |
922 { | 925 { |
923 if (!m_model || m_model->getPoints().empty()) return; | 926 if (!m_model || m_model->getPoints().empty()) return; |
924 | 927 |
925 QString unit; | 928 QString unit; |
926 double min, max; | 929 double min, max; |
927 bool logarithmic; | 930 bool logarithmic; |
928 | 931 |
929 int w = getVerticalScaleWidth(v, false, paint); | 932 int w = getVerticalScaleWidth(v, false, paint); |
930 int h = v->height(); | 933 int h = v->getPaintHeight(); |
931 | 934 |
932 getScaleExtents(v, min, max, logarithmic); | 935 getScaleExtents(v, min, max, logarithmic); |
933 | 936 |
934 if (logarithmic) { | 937 if (logarithmic) { |
935 LogNumericalScale().paintVertical(v, this, paint, 0, min, max); | 938 LogNumericalScale().paintVertical(v, this, paint, 0, min, max); |
954 mw)); | 957 mw)); |
955 } | 958 } |
956 } | 959 } |
957 | 960 |
958 void | 961 void |
959 FlexiNoteLayer::drawStart(View *v, QMouseEvent *e) | 962 FlexiNoteLayer::drawStart(LayerGeometryProvider *v, QMouseEvent *e) |
960 { | 963 { |
961 // SVDEBUG << "FlexiNoteLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl; | 964 // SVDEBUG << "FlexiNoteLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl; |
962 | 965 |
963 if (!m_model) return; | 966 if (!m_model) return; |
964 | 967 |
978 | 981 |
979 m_editing = true; | 982 m_editing = true; |
980 } | 983 } |
981 | 984 |
982 void | 985 void |
983 FlexiNoteLayer::drawDrag(View *v, QMouseEvent *e) | 986 FlexiNoteLayer::drawDrag(LayerGeometryProvider *v, QMouseEvent *e) |
984 { | 987 { |
985 // SVDEBUG << "FlexiNoteLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl; | 988 // SVDEBUG << "FlexiNoteLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl; |
986 | 989 |
987 if (!m_model || !m_editing) return; | 990 if (!m_model || !m_editing) return; |
988 | 991 |
1007 m_editingPoint.duration = newDuration; | 1010 m_editingPoint.duration = newDuration; |
1008 m_editingCommand->addPoint(m_editingPoint); | 1011 m_editingCommand->addPoint(m_editingPoint); |
1009 } | 1012 } |
1010 | 1013 |
1011 void | 1014 void |
1012 FlexiNoteLayer::drawEnd(View *, QMouseEvent *) | 1015 FlexiNoteLayer::drawEnd(LayerGeometryProvider *, QMouseEvent *) |
1013 { | 1016 { |
1014 // SVDEBUG << "FlexiNoteLayer::drawEnd(" << e->x() << "," << e->y() << ")" << endl; | 1017 // SVDEBUG << "FlexiNoteLayer::drawEnd(" << e->x() << "," << e->y() << ")" << endl; |
1015 if (!m_model || !m_editing) return; | 1018 if (!m_model || !m_editing) return; |
1016 finish(m_editingCommand); | 1019 finish(m_editingCommand); |
1017 m_editingCommand = 0; | 1020 m_editingCommand = 0; |
1018 m_editing = false; | 1021 m_editing = false; |
1019 } | 1022 } |
1020 | 1023 |
1021 void | 1024 void |
1022 FlexiNoteLayer::eraseStart(View *v, QMouseEvent *e) | 1025 FlexiNoteLayer::eraseStart(LayerGeometryProvider *v, QMouseEvent *e) |
1023 { | 1026 { |
1024 if (!m_model) return; | 1027 if (!m_model) return; |
1025 | 1028 |
1026 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; | 1029 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; |
1027 | 1030 |
1032 | 1035 |
1033 m_editing = true; | 1036 m_editing = true; |
1034 } | 1037 } |
1035 | 1038 |
1036 void | 1039 void |
1037 FlexiNoteLayer::eraseDrag(View *, QMouseEvent *) | 1040 FlexiNoteLayer::eraseDrag(LayerGeometryProvider *, QMouseEvent *) |
1038 { | 1041 { |
1039 } | 1042 } |
1040 | 1043 |
1041 void | 1044 void |
1042 FlexiNoteLayer::eraseEnd(View *v, QMouseEvent *e) | 1045 FlexiNoteLayer::eraseEnd(LayerGeometryProvider *v, QMouseEvent *e) |
1043 { | 1046 { |
1044 if (!m_model || !m_editing) return; | 1047 if (!m_model || !m_editing) return; |
1045 | 1048 |
1046 m_editing = false; | 1049 m_editing = false; |
1047 | 1050 |
1057 m_editingCommand = 0; | 1060 m_editingCommand = 0; |
1058 m_editing = false; | 1061 m_editing = false; |
1059 } | 1062 } |
1060 | 1063 |
1061 void | 1064 void |
1062 FlexiNoteLayer::editStart(View *v, QMouseEvent *e) | 1065 FlexiNoteLayer::editStart(LayerGeometryProvider *v, QMouseEvent *e) |
1063 { | 1066 { |
1064 // SVDEBUG << "FlexiNoteLayer::editStart(" << e->x() << "," << e->y() << ")" << endl; | 1067 // SVDEBUG << "FlexiNoteLayer::editStart(" << e->x() << "," << e->y() << ")" << endl; |
1065 std::cerr << "FlexiNoteLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl; | 1068 std::cerr << "FlexiNoteLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl; |
1066 | 1069 |
1067 if (!m_model) return; | 1070 if (!m_model) return; |
1108 } | 1111 } |
1109 std::cerr << "editStart: mode is " << m_editMode << ", note frame: " << onset << ", left boundary: " << m_greatestLeftNeighbourFrame << ", right boundary: " << m_smallestRightNeighbourFrame << std::endl; | 1112 std::cerr << "editStart: mode is " << m_editMode << ", note frame: " << onset << ", left boundary: " << m_greatestLeftNeighbourFrame << ", right boundary: " << m_smallestRightNeighbourFrame << std::endl; |
1110 } | 1113 } |
1111 | 1114 |
1112 void | 1115 void |
1113 FlexiNoteLayer::editDrag(View *v, QMouseEvent *e) | 1116 FlexiNoteLayer::editDrag(LayerGeometryProvider *v, QMouseEvent *e) |
1114 { | 1117 { |
1115 // SVDEBUG << "FlexiNoteLayer::editDrag(" << e->x() << "," << e->y() << ")" << endl; | 1118 // SVDEBUG << "FlexiNoteLayer::editDrag(" << e->x() << "," << e->y() << ")" << endl; |
1116 std::cerr << "FlexiNoteLayer::editDrag(" << e->x() << "," << e->y() << ")" << std::endl; | 1119 std::cerr << "FlexiNoteLayer::editDrag(" << e->x() << "," << e->y() << ")" << std::endl; |
1117 | 1120 |
1118 if (!m_model || !m_editing) return; | 1121 if (!m_model || !m_editing) return; |
1188 | 1191 |
1189 std::cerr << "added new point(" << m_editingPoint.frame << "," << m_editingPoint.duration << ")" << std::endl; | 1192 std::cerr << "added new point(" << m_editingPoint.frame << "," << m_editingPoint.duration << ")" << std::endl; |
1190 } | 1193 } |
1191 | 1194 |
1192 void | 1195 void |
1193 FlexiNoteLayer::editEnd(View *v, QMouseEvent *e) | 1196 FlexiNoteLayer::editEnd(LayerGeometryProvider *v, QMouseEvent *e) |
1194 { | 1197 { |
1195 // SVDEBUG << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl; | 1198 // SVDEBUG << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl; |
1196 std::cerr << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl; | 1199 std::cerr << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl; |
1197 | 1200 |
1198 if (!m_model || !m_editing) return; | 1201 if (!m_model || !m_editing) return; |
1227 m_editingCommand = 0; | 1230 m_editingCommand = 0; |
1228 m_editing = false; | 1231 m_editing = false; |
1229 } | 1232 } |
1230 | 1233 |
1231 void | 1234 void |
1232 FlexiNoteLayer::splitStart(View *v, QMouseEvent *e) | 1235 FlexiNoteLayer::splitStart(LayerGeometryProvider *v, QMouseEvent *e) |
1233 { | 1236 { |
1234 // GF: note splitting starts (!! remove printing soon) | 1237 // GF: note splitting starts (!! remove printing soon) |
1235 std::cerr << "splitStart (n.b. editStart will be called later, if the user drags the mouse)" << std::endl; | 1238 std::cerr << "splitStart (n.b. editStart will be called later, if the user drags the mouse)" << std::endl; |
1236 if (!m_model) return; | 1239 if (!m_model) return; |
1237 | 1240 |
1250 m_dragStartX = e->x(); | 1253 m_dragStartX = e->x(); |
1251 m_dragStartY = e->y(); | 1254 m_dragStartY = e->y(); |
1252 } | 1255 } |
1253 | 1256 |
1254 void | 1257 void |
1255 FlexiNoteLayer::splitEnd(View *v, QMouseEvent *e) | 1258 FlexiNoteLayer::splitEnd(LayerGeometryProvider *v, QMouseEvent *e) |
1256 { | 1259 { |
1257 // GF: note splitting ends. (!! remove printing soon) | 1260 // GF: note splitting ends. (!! remove printing soon) |
1258 std::cerr << "splitEnd" << std::endl; | 1261 std::cerr << "splitEnd" << std::endl; |
1259 if (!m_model || !m_editing || m_editMode != SplitNote) return; | 1262 if (!m_model || !m_editing || m_editMode != SplitNote) return; |
1260 | 1263 |
1269 | 1272 |
1270 splitNotesAt(v, frame, e); | 1273 splitNotesAt(v, frame, e); |
1271 } | 1274 } |
1272 | 1275 |
1273 void | 1276 void |
1274 FlexiNoteLayer::splitNotesAt(View *v, sv_frame_t frame) | 1277 FlexiNoteLayer::splitNotesAt(LayerGeometryProvider *v, sv_frame_t frame) |
1275 { | 1278 { |
1276 splitNotesAt(v, frame, 0); | 1279 splitNotesAt(v, frame, 0); |
1277 } | 1280 } |
1278 | 1281 |
1279 void | 1282 void |
1280 FlexiNoteLayer::splitNotesAt(View *v, sv_frame_t frame, QMouseEvent *e) | 1283 FlexiNoteLayer::splitNotesAt(LayerGeometryProvider *v, sv_frame_t frame, QMouseEvent *e) |
1281 { | 1284 { |
1282 FlexiNoteModel::PointList onPoints = m_model->getPoints(frame); | 1285 FlexiNoteModel::PointList onPoints = m_model->getPoints(frame); |
1283 if (onPoints.empty()) return; | 1286 if (onPoints.empty()) return; |
1284 | 1287 |
1285 FlexiNote note(*onPoints.begin()); | 1288 FlexiNote note(*onPoints.begin()); |
1315 | 1318 |
1316 finish(command); | 1319 finish(command); |
1317 } | 1320 } |
1318 | 1321 |
1319 void | 1322 void |
1320 FlexiNoteLayer::addNote(View *v, QMouseEvent *e) | 1323 FlexiNoteLayer::addNote(LayerGeometryProvider *v, QMouseEvent *e) |
1321 { | 1324 { |
1322 std::cerr << "addNote" << std::endl; | 1325 std::cerr << "addNote" << std::endl; |
1323 if (!m_model) return; | 1326 if (!m_model) return; |
1324 | 1327 |
1325 sv_frame_t duration = 10000; | 1328 sv_frame_t duration = 10000; |
1354 finish(command); | 1357 finish(command); |
1355 } | 1358 } |
1356 } | 1359 } |
1357 | 1360 |
1358 SparseTimeValueModel * | 1361 SparseTimeValueModel * |
1359 FlexiNoteLayer::getAssociatedPitchModel(View *v) const | 1362 FlexiNoteLayer::getAssociatedPitchModel(LayerGeometryProvider *v) const |
1360 { | 1363 { |
1361 // Better than we used to do, but still not very satisfactory | 1364 // Better than we used to do, but still not very satisfactory |
1362 | 1365 |
1363 // cerr << "FlexiNoteLayer::getAssociatedPitchModel()" << endl; | 1366 // cerr << "FlexiNoteLayer::getAssociatedPitchModel()" << endl; |
1364 | 1367 |
1365 for (int i = 0; i < v->getLayerCount(); ++i) { | 1368 for (int i = 0; i < v->getView()->getLayerCount(); ++i) { |
1366 Layer *layer = v->getLayer(i); | 1369 Layer *layer = v->getView()->getLayer(i); |
1367 if (layer && | 1370 if (layer && |
1368 layer->getLayerPresentationName() != "candidate") { | 1371 layer->getLayerPresentationName() != "candidate") { |
1369 // cerr << "FlexiNoteLayer::getAssociatedPitchModel: looks like our layer is " << layer << endl; | 1372 // cerr << "FlexiNoteLayer::getAssociatedPitchModel: looks like our layer is " << layer << endl; |
1370 SparseTimeValueModel *model = qobject_cast<SparseTimeValueModel *> | 1373 SparseTimeValueModel *model = qobject_cast<SparseTimeValueModel *> |
1371 (layer->getModel()); | 1374 (layer->getModel()); |
1379 cerr << "FlexiNoteLayer::getAssociatedPitchModel: failed to find a model" << endl; | 1382 cerr << "FlexiNoteLayer::getAssociatedPitchModel: failed to find a model" << endl; |
1380 return 0; | 1383 return 0; |
1381 } | 1384 } |
1382 | 1385 |
1383 void | 1386 void |
1384 FlexiNoteLayer::snapSelectedNotesToPitchTrack(View *v, Selection s) | 1387 FlexiNoteLayer::snapSelectedNotesToPitchTrack(LayerGeometryProvider *v, Selection s) |
1385 { | 1388 { |
1386 if (!m_model) return; | 1389 if (!m_model) return; |
1387 | 1390 |
1388 FlexiNoteModel::PointList points = | 1391 FlexiNoteModel::PointList points = |
1389 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); | 1392 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); |
1417 | 1420 |
1418 finish(command); | 1421 finish(command); |
1419 } | 1422 } |
1420 | 1423 |
1421 void | 1424 void |
1422 FlexiNoteLayer::mergeNotes(View *v, Selection s, bool inclusive) | 1425 FlexiNoteLayer::mergeNotes(LayerGeometryProvider *v, Selection s, bool inclusive) |
1423 { | 1426 { |
1424 FlexiNoteModel::PointList points = | 1427 FlexiNoteModel::PointList points = |
1425 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); | 1428 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); |
1426 | 1429 |
1427 FlexiNoteModel::PointList::iterator i = points.begin(); | 1430 FlexiNoteModel::PointList::iterator i = points.begin(); |
1460 command->addPoint(newNote); | 1463 command->addPoint(newNote); |
1461 finish(command); | 1464 finish(command); |
1462 } | 1465 } |
1463 | 1466 |
1464 bool | 1467 bool |
1465 FlexiNoteLayer::updateNoteValueFromPitchCurve(View *v, | 1468 FlexiNoteLayer::updateNoteValueFromPitchCurve(LayerGeometryProvider *v, FlexiNoteModel::Point ¬e) const |
1466 FlexiNoteModel::Point ¬e) const | |
1467 { | 1469 { |
1468 SparseTimeValueModel *model = getAssociatedPitchModel(v); | 1470 SparseTimeValueModel *model = getAssociatedPitchModel(v); |
1469 if (!model) return false; | 1471 if (!model) return false; |
1470 | 1472 |
1471 std::cerr << model->getTypeName() << std::endl; | 1473 std::cerr << model->getTypeName() << std::endl; |
1505 | 1507 |
1506 return true; | 1508 return true; |
1507 } | 1509 } |
1508 | 1510 |
1509 void | 1511 void |
1510 FlexiNoteLayer::mouseMoveEvent(View *v, QMouseEvent *e) | 1512 FlexiNoteLayer::mouseMoveEvent(LayerGeometryProvider *v, QMouseEvent *e) |
1511 { | 1513 { |
1512 // GF: context sensitive cursors | 1514 // GF: context sensitive cursors |
1513 // v->setCursor(Qt::ArrowCursor); | 1515 // v->getView()->setCursor(Qt::ArrowCursor); |
1514 FlexiNoteModel::Point note(0); | 1516 FlexiNoteModel::Point note(0); |
1515 if (!getNoteToEdit(v, e->x(), e->y(), note)) { | 1517 if (!getNoteToEdit(v, e->x(), e->y(), note)) { |
1516 // v->setCursor(Qt::UpArrowCursor); | 1518 // v->getView()->setCursor(Qt::UpArrowCursor); |
1517 return; | 1519 return; |
1518 } | 1520 } |
1519 | 1521 |
1520 bool closeToLeft = false, closeToRight = false, | 1522 bool closeToLeft = false, closeToRight = false, |
1521 closeToTop = false, closeToBottom = false; | 1523 closeToTop = false, closeToBottom = false; |
1522 getRelativeMousePosition(v, note, e->x(), e->y(), | 1524 getRelativeMousePosition(v, note, e->x(), e->y(), |
1523 closeToLeft, closeToRight, | 1525 closeToLeft, closeToRight, |
1524 closeToTop, closeToBottom); | 1526 closeToTop, closeToBottom); |
1525 | 1527 |
1526 if (closeToLeft) { | 1528 if (closeToLeft) { |
1527 v->setCursor(Qt::SizeHorCursor); | 1529 v->getView()->setCursor(Qt::SizeHorCursor); |
1528 m_editMode = LeftBoundary; | 1530 m_editMode = LeftBoundary; |
1529 cerr << "edit mode -> LeftBoundary" << endl; | 1531 cerr << "edit mode -> LeftBoundary" << endl; |
1530 } else if (closeToRight) { | 1532 } else if (closeToRight) { |
1531 v->setCursor(Qt::SizeHorCursor); | 1533 v->getView()->setCursor(Qt::SizeHorCursor); |
1532 m_editMode = RightBoundary; | 1534 m_editMode = RightBoundary; |
1533 cerr << "edit mode -> RightBoundary" << endl; | 1535 cerr << "edit mode -> RightBoundary" << endl; |
1534 } else if (closeToTop) { | 1536 } else if (closeToTop) { |
1535 v->setCursor(Qt::CrossCursor); | 1537 v->getView()->setCursor(Qt::CrossCursor); |
1536 m_editMode = DragNote; | 1538 m_editMode = DragNote; |
1537 cerr << "edit mode -> DragNote" << endl; | 1539 cerr << "edit mode -> DragNote" << endl; |
1538 } else if (closeToBottom) { | 1540 } else if (closeToBottom) { |
1539 v->setCursor(Qt::UpArrowCursor); | 1541 v->getView()->setCursor(Qt::UpArrowCursor); |
1540 m_editMode = SplitNote; | 1542 m_editMode = SplitNote; |
1541 cerr << "edit mode -> SplitNote" << endl; | 1543 cerr << "edit mode -> SplitNote" << endl; |
1542 } else { | 1544 } else { |
1543 v->setCursor(Qt::ArrowCursor); | 1545 v->getView()->setCursor(Qt::ArrowCursor); |
1544 } | 1546 } |
1545 } | 1547 } |
1546 | 1548 |
1547 void | 1549 void |
1548 FlexiNoteLayer::getRelativeMousePosition(View *v, FlexiNoteModel::Point ¬e, int x, int y, bool &closeToLeft, bool &closeToRight, bool &closeToTop, bool &closeToBottom) const | 1550 FlexiNoteLayer::getRelativeMousePosition(LayerGeometryProvider *v, FlexiNoteModel::Point ¬e, int x, int y, bool &closeToLeft, bool &closeToRight, bool &closeToTop, bool &closeToBottom) const |
1549 { | 1551 { |
1550 // GF: TODO: consoloidate the tolerance values | 1552 // GF: TODO: consoloidate the tolerance values |
1551 if (!m_model) return; | 1553 if (!m_model) return; |
1552 | 1554 |
1553 int ctol = 0; | 1555 int ctol = 0; |
1572 // cerr << "FlexiNoteLayer::getRelativeMousePosition: close to: left " << closeToLeft << " right " << closeToRight << " top " << closeToTop << " bottom " << closeToBottom << endl; | 1574 // cerr << "FlexiNoteLayer::getRelativeMousePosition: close to: left " << closeToLeft << " right " << closeToRight << " top " << closeToTop << " bottom " << closeToBottom << endl; |
1573 } | 1575 } |
1574 | 1576 |
1575 | 1577 |
1576 bool | 1578 bool |
1577 FlexiNoteLayer::editOpen(View *v, QMouseEvent *e) | 1579 FlexiNoteLayer::editOpen(LayerGeometryProvider *v, QMouseEvent *e) |
1578 { | 1580 { |
1579 std::cerr << "Opening note editor dialog" << std::endl; | 1581 std::cerr << "Opening note editor dialog" << std::endl; |
1580 if (!m_model) return false; | 1582 if (!m_model) return false; |
1581 | 1583 |
1582 FlexiNoteModel::Point note(0); | 1584 FlexiNoteModel::Point note(0); |
1726 | 1728 |
1727 finish(command); | 1729 finish(command); |
1728 } | 1730 } |
1729 | 1731 |
1730 void | 1732 void |
1731 FlexiNoteLayer::copy(View *v, Selection s, Clipboard &to) | 1733 FlexiNoteLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to) |
1732 { | 1734 { |
1733 if (!m_model) return; | 1735 if (!m_model) return; |
1734 | 1736 |
1735 FlexiNoteModel::PointList points = | 1737 FlexiNoteModel::PointList points = |
1736 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); | 1738 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); |
1744 } | 1746 } |
1745 } | 1747 } |
1746 } | 1748 } |
1747 | 1749 |
1748 bool | 1750 bool |
1749 FlexiNoteLayer::paste(View *v, const Clipboard &from, sv_frame_t /*frameOffset */, bool /* interactive */) | 1751 FlexiNoteLayer::paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t /*frameOffset */, bool /* interactive */) |
1750 { | 1752 { |
1751 if (!m_model) return false; | 1753 if (!m_model) return false; |
1752 | 1754 |
1753 const Clipboard::PointList &points = from.getPoints(); | 1755 const Clipboard::PointList &points = from.getPoints(); |
1754 | 1756 |
1755 bool realign = false; | 1757 bool realign = false; |
1756 | 1758 |
1757 if (clipboardHasDifferentAlignment(v, from)) { | 1759 if (clipboardHasDifferentAlignment(v, from)) { |
1758 | 1760 |
1759 QMessageBox::StandardButton button = | 1761 QMessageBox::StandardButton button = |
1760 QMessageBox::question(v, tr("Re-align pasted items?"), | 1762 QMessageBox::question(v->getView(), tr("Re-align pasted items?"), |
1761 tr("The items you are pasting came from a layer with different source material from this one. Do you want to re-align them in time, to match the source material for this layer?"), | 1763 tr("The items you are pasting came from a layer with different source material from this one. Do you want to re-align them in time, to match the source material for this layer?"), |
1762 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, | 1764 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, |
1763 QMessageBox::Yes); | 1765 QMessageBox::Yes); |
1764 | 1766 |
1765 if (button == QMessageBox::Cancel) { | 1767 if (button == QMessageBox::Cancel) { |
1892 // double max = attributes.value("scaleMaximum").toDouble(&alsoOk); | 1894 // double max = attributes.value("scaleMaximum").toDouble(&alsoOk); |
1893 // if (ok && alsoOk && min != max) setDisplayExtents(min, max); | 1895 // if (ok && alsoOk && min != max) setDisplayExtents(min, max); |
1894 } | 1896 } |
1895 | 1897 |
1896 void | 1898 void |
1897 FlexiNoteLayer::setVerticalRangeToNoteRange(View *v) | 1899 FlexiNoteLayer::setVerticalRangeToNoteRange(LayerGeometryProvider *v) |
1898 { | 1900 { |
1899 double minf = std::numeric_limits<double>::max(); | 1901 double minf = std::numeric_limits<double>::max(); |
1900 double maxf = 0; | 1902 double maxf = 0; |
1901 bool hasNotes = 0; | 1903 bool hasNotes = 0; |
1902 for (FlexiNoteModel::PointList::const_iterator i = m_model->getPoints().begin(); | 1904 for (FlexiNoteModel::PointList::const_iterator i = m_model->getPoints().begin(); |
1908 } | 1910 } |
1909 | 1911 |
1910 std::cerr << "min frequency:" << minf << ", max frequency: " << maxf << std::endl; | 1912 std::cerr << "min frequency:" << minf << ", max frequency: " << maxf << std::endl; |
1911 | 1913 |
1912 if (hasNotes) { | 1914 if (hasNotes) { |
1913 v->getLayer(1)->setDisplayExtents(minf*0.66,maxf*1.5); | 1915 v->getView()->getLayer(1)->setDisplayExtents(minf*0.66,maxf*1.5); |
1914 // MM: this is a hack because we rely on | 1916 // MM: this is a hack because we rely on |
1915 // * this layer being automatically aligned to layer 1 | 1917 // * this layer being automatically aligned to layer 1 |
1916 // * layer one is a log frequency layer. | 1918 // * layer one is a log frequency layer. |
1917 } | 1919 } |
1918 } | 1920 } |