comparison layer/FlexiNoteLayer.cpp @ 997:296ccd36f626 tony-2.0-integration

Merge through to branch for Tony 2.0
author Chris Cannam
date Thu, 20 Aug 2015 14:54:21 +0100
parents 8bf05426d950
children 5144d7185fb5
comparison
equal deleted inserted replaced
943:788b7623bfca 997:296ccd36f626
202 m_verticalScale = scale; 202 m_verticalScale = scale;
203 emit layerParametersChanged(); 203 emit layerParametersChanged();
204 } 204 }
205 205
206 bool 206 bool
207 FlexiNoteLayer::isLayerScrollable(const View *v) const 207 FlexiNoteLayer::isLayerScrollable(const LayerGeometryProvider *v) const
208 { 208 {
209 QPoint discard; 209 QPoint discard;
210 return !v->shouldIlluminateLocalFeatures(this, discard); 210 return !v->shouldIlluminateLocalFeatures(this, discard);
211 } 211 }
212 212
403 403
404 return mapper; 404 return mapper;
405 } 405 }
406 406
407 FlexiNoteModel::PointList 407 FlexiNoteModel::PointList
408 FlexiNoteLayer::getLocalPoints(View *v, int x) const 408 FlexiNoteLayer::getLocalPoints(LayerGeometryProvider *v, int x) const
409 { 409 {
410 if (!m_model) return FlexiNoteModel::PointList(); 410 if (!m_model) return FlexiNoteModel::PointList();
411 411
412 sv_frame_t frame = v->getFrameForX(x); 412 sv_frame_t frame = v->getFrameForX(x);
413 413
446 446
447 return usePoints; 447 return usePoints;
448 } 448 }
449 449
450 bool 450 bool
451 FlexiNoteLayer::getPointToDrag(View *v, int x, int y, FlexiNoteModel::Point &p) const 451 FlexiNoteLayer::getPointToDrag(LayerGeometryProvider *v, int x, int y, FlexiNoteModel::Point &p) const
452 { 452 {
453 if (!m_model) return false; 453 if (!m_model) return false;
454 454
455 sv_frame_t frame = v->getFrameForX(x); 455 sv_frame_t frame = v->getFrameForX(x);
456 456
474 474
475 return true; 475 return true;
476 } 476 }
477 477
478 bool 478 bool
479 FlexiNoteLayer::getNoteToEdit(View *v, int x, int y, FlexiNoteModel::Point &p) const 479 FlexiNoteLayer::getNoteToEdit(LayerGeometryProvider *v, int x, int y, FlexiNoteModel::Point &p) const
480 { 480 {
481 // GF: find the note that is closest to the cursor 481 // GF: find the note that is closest to the cursor
482 if (!m_model) return false; 482 if (!m_model) return false;
483 483
484 sv_frame_t frame = v->getFrameForX(x); 484 sv_frame_t frame = v->getFrameForX(x);
503 503
504 return true; 504 return true;
505 } 505 }
506 506
507 QString 507 QString
508 FlexiNoteLayer::getFeatureDescription(View *v, QPoint &pos) const 508 FlexiNoteLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const
509 { 509 {
510 int x = pos.x(); 510 int x = pos.x();
511 511
512 if (!m_model || !m_model->getSampleRate()) return ""; 512 if (!m_model || !m_model->getSampleRate()) return "";
513 513
591 getYForValue(v, note.value)); 591 getYForValue(v, note.value));
592 return text; 592 return text;
593 } 593 }
594 594
595 bool 595 bool
596 FlexiNoteLayer::snapToFeatureFrame(View *v, sv_frame_t &frame, 596 FlexiNoteLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
597 int &resolution, 597 int &resolution,
598 SnapType snap) const 598 SnapType snap) const
599 { 599 {
600 if (!m_model) { 600 if (!m_model) {
601 return Layer::snapToFeatureFrame(v, frame, resolution, snap); 601 return Layer::snapToFeatureFrame(v, frame, resolution, snap);
671 frame = snapped; 671 frame = snapped;
672 return found; 672 return found;
673 } 673 }
674 674
675 void 675 void
676 FlexiNoteLayer::getScaleExtents(View *v, double &min, double &max, bool &log) const 676 FlexiNoteLayer::getScaleExtents(LayerGeometryProvider *v, double &min, double &max, bool &log) const
677 { 677 {
678 min = 0.0; 678 min = 0.0;
679 max = 0.0; 679 max = 0.0;
680 log = false; 680 log = false;
681 681
728 728
729 if (max == min) max = min + 1.0; 729 if (max == min) max = min + 1.0;
730 } 730 }
731 731
732 int 732 int
733 FlexiNoteLayer::getYForValue(View *v, double val) const 733 FlexiNoteLayer::getYForValue(LayerGeometryProvider *v, double val) const
734 { 734 {
735 double min = 0.0, max = 0.0; 735 double min = 0.0, max = 0.0;
736 bool logarithmic = false; 736 bool logarithmic = false;
737 int h = v->height(); 737 int h = v->getPaintHeight();
738 738
739 getScaleExtents(v, min, max, logarithmic); 739 getScaleExtents(v, min, max, logarithmic);
740 740
741 #ifdef DEBUG_NOTE_LAYER 741 #ifdef DEBUG_NOTE_LAYER
742 cerr << "FlexiNoteLayer[" << this << "]::getYForValue(" << val << "): min = " << min << ", max = " << max << ", log = " << logarithmic << endl; 742 cerr << "FlexiNoteLayer[" << this << "]::getYForValue(" << val << "): min = " << min << ", max = " << max << ", log = " << logarithmic << endl;
763 #endif 763 #endif
764 return y; 764 return y;
765 } 765 }
766 766
767 double 767 double
768 FlexiNoteLayer::getValueForY(View *v, int y) const 768 FlexiNoteLayer::getValueForY(LayerGeometryProvider *v, int y) const
769 { 769 {
770 double min = 0.0, max = 0.0; 770 double min = 0.0, max = 0.0;
771 bool logarithmic = false; 771 bool logarithmic = false;
772 int h = v->height(); 772 int h = v->getPaintHeight();
773 773
774 getScaleExtents(v, min, max, logarithmic); 774 getScaleExtents(v, min, max, logarithmic);
775 775
776 double val = min + (double(h - y) * double(max - min)) / h; 776 double val = min + (double(h - y) * double(max - min)) / h;
777 777
792 if (!m_model) return false; 792 if (!m_model) return false;
793 return (m_verticalScale == AutoAlignScale); 793 return (m_verticalScale == AutoAlignScale);
794 } 794 }
795 795
796 void 796 void
797 FlexiNoteLayer::paint(View *v, QPainter &paint, QRect rect) const 797 FlexiNoteLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
798 { 798 {
799 if (!m_model || !m_model->isOK()) return; 799 if (!m_model || !m_model->isOK()) return;
800 800
801 sv_samplerate_t sampleRate = m_model->getSampleRate(); 801 sv_samplerate_t sampleRate = m_model->getSampleRate();
802 if (!sampleRate) return; 802 if (!sampleRate) return;
858 if (shouldIlluminate && 858 if (shouldIlluminate &&
859 // "illuminatePoint == p" 859 // "illuminatePoint == p"
860 !FlexiNoteModel::Point::Comparator()(illuminatePoint, p) && 860 !FlexiNoteModel::Point::Comparator()(illuminatePoint, p) &&
861 !FlexiNoteModel::Point::Comparator()(p, illuminatePoint)) { 861 !FlexiNoteModel::Point::Comparator()(p, illuminatePoint)) {
862 862
863 paint.drawLine(x, -1, x, v->height() + 1); 863 paint.drawLine(x, -1, x, v->getPaintHeight() + 1);
864 paint.drawLine(x+w, -1, x+w, v->height() + 1); 864 paint.drawLine(x+w, -1, x+w, v->getPaintHeight() + 1);
865 865
866 paint.setPen(v->getForeground()); 866 paint.setPen(v->getForeground());
867 // paint.setBrush(v->getForeground()); 867 // paint.setBrush(v->getForeground());
868 868
869 QString vlabel = QString("freq: %1%2").arg(p.value).arg(m_model->getScaleUnits()); 869 QString vlabel = QString("freq: %1%2").arg(p.value).arg(m_model->getScaleUnits());
902 902
903 paint.restore(); 903 paint.restore();
904 } 904 }
905 905
906 int 906 int
907 FlexiNoteLayer::getVerticalScaleWidth(View *v, bool, QPainter &paint) const 907 FlexiNoteLayer::getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &paint) const
908 { 908 {
909 if (!m_model || shouldAutoAlign()) { 909 if (!m_model || shouldAutoAlign()) {
910 return 0; 910 return 0;
911 } else { 911 } else {
912 if (m_verticalScale == LogScale || m_verticalScale == MIDIRangeScale) { 912 if (m_verticalScale == LogScale || m_verticalScale == MIDIRangeScale) {
916 } 916 }
917 } 917 }
918 } 918 }
919 919
920 void 920 void
921 FlexiNoteLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect) const 921 FlexiNoteLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect) const
922 { 922 {
923 if (!m_model || m_model->getPoints().empty()) return; 923 if (!m_model || m_model->getPoints().empty()) return;
924 924
925 QString unit; 925 QString unit;
926 double min, max; 926 double min, max;
927 bool logarithmic; 927 bool logarithmic;
928 928
929 int w = getVerticalScaleWidth(v, false, paint); 929 int w = getVerticalScaleWidth(v, false, paint);
930 int h = v->height(); 930 int h = v->getPaintHeight();
931 931
932 getScaleExtents(v, min, max, logarithmic); 932 getScaleExtents(v, min, max, logarithmic);
933 933
934 if (logarithmic) { 934 if (logarithmic) {
935 LogNumericalScale().paintVertical(v, this, paint, 0, min, max); 935 LogNumericalScale().paintVertical(v, this, paint, 0, min, max);
954 mw)); 954 mw));
955 } 955 }
956 } 956 }
957 957
958 void 958 void
959 FlexiNoteLayer::drawStart(View *v, QMouseEvent *e) 959 FlexiNoteLayer::drawStart(LayerGeometryProvider *v, QMouseEvent *e)
960 { 960 {
961 // SVDEBUG << "FlexiNoteLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl; 961 // SVDEBUG << "FlexiNoteLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl;
962 962
963 if (!m_model) return; 963 if (!m_model) return;
964 964
978 978
979 m_editing = true; 979 m_editing = true;
980 } 980 }
981 981
982 void 982 void
983 FlexiNoteLayer::drawDrag(View *v, QMouseEvent *e) 983 FlexiNoteLayer::drawDrag(LayerGeometryProvider *v, QMouseEvent *e)
984 { 984 {
985 // SVDEBUG << "FlexiNoteLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl; 985 // SVDEBUG << "FlexiNoteLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl;
986 986
987 if (!m_model || !m_editing) return; 987 if (!m_model || !m_editing) return;
988 988
1007 m_editingPoint.duration = newDuration; 1007 m_editingPoint.duration = newDuration;
1008 m_editingCommand->addPoint(m_editingPoint); 1008 m_editingCommand->addPoint(m_editingPoint);
1009 } 1009 }
1010 1010
1011 void 1011 void
1012 FlexiNoteLayer::drawEnd(View *, QMouseEvent *) 1012 FlexiNoteLayer::drawEnd(LayerGeometryProvider *, QMouseEvent *)
1013 { 1013 {
1014 // SVDEBUG << "FlexiNoteLayer::drawEnd(" << e->x() << "," << e->y() << ")" << endl; 1014 // SVDEBUG << "FlexiNoteLayer::drawEnd(" << e->x() << "," << e->y() << ")" << endl;
1015 if (!m_model || !m_editing) return; 1015 if (!m_model || !m_editing) return;
1016 finish(m_editingCommand); 1016 finish(m_editingCommand);
1017 m_editingCommand = 0; 1017 m_editingCommand = 0;
1018 m_editing = false; 1018 m_editing = false;
1019 } 1019 }
1020 1020
1021 void 1021 void
1022 FlexiNoteLayer::eraseStart(View *v, QMouseEvent *e) 1022 FlexiNoteLayer::eraseStart(LayerGeometryProvider *v, QMouseEvent *e)
1023 { 1023 {
1024 if (!m_model) return; 1024 if (!m_model) return;
1025 1025
1026 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; 1026 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return;
1027 1027
1032 1032
1033 m_editing = true; 1033 m_editing = true;
1034 } 1034 }
1035 1035
1036 void 1036 void
1037 FlexiNoteLayer::eraseDrag(View *, QMouseEvent *) 1037 FlexiNoteLayer::eraseDrag(LayerGeometryProvider *, QMouseEvent *)
1038 { 1038 {
1039 } 1039 }
1040 1040
1041 void 1041 void
1042 FlexiNoteLayer::eraseEnd(View *v, QMouseEvent *e) 1042 FlexiNoteLayer::eraseEnd(LayerGeometryProvider *v, QMouseEvent *e)
1043 { 1043 {
1044 if (!m_model || !m_editing) return; 1044 if (!m_model || !m_editing) return;
1045 1045
1046 m_editing = false; 1046 m_editing = false;
1047 1047
1057 m_editingCommand = 0; 1057 m_editingCommand = 0;
1058 m_editing = false; 1058 m_editing = false;
1059 } 1059 }
1060 1060
1061 void 1061 void
1062 FlexiNoteLayer::editStart(View *v, QMouseEvent *e) 1062 FlexiNoteLayer::editStart(LayerGeometryProvider *v, QMouseEvent *e)
1063 { 1063 {
1064 // SVDEBUG << "FlexiNoteLayer::editStart(" << e->x() << "," << e->y() << ")" << endl; 1064 // SVDEBUG << "FlexiNoteLayer::editStart(" << e->x() << "," << e->y() << ")" << endl;
1065 std::cerr << "FlexiNoteLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl; 1065 std::cerr << "FlexiNoteLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl;
1066 1066
1067 if (!m_model) return; 1067 if (!m_model) return;
1108 } 1108 }
1109 std::cerr << "editStart: mode is " << m_editMode << ", note frame: " << onset << ", left boundary: " << m_greatestLeftNeighbourFrame << ", right boundary: " << m_smallestRightNeighbourFrame << std::endl; 1109 std::cerr << "editStart: mode is " << m_editMode << ", note frame: " << onset << ", left boundary: " << m_greatestLeftNeighbourFrame << ", right boundary: " << m_smallestRightNeighbourFrame << std::endl;
1110 } 1110 }
1111 1111
1112 void 1112 void
1113 FlexiNoteLayer::editDrag(View *v, QMouseEvent *e) 1113 FlexiNoteLayer::editDrag(LayerGeometryProvider *v, QMouseEvent *e)
1114 { 1114 {
1115 // SVDEBUG << "FlexiNoteLayer::editDrag(" << e->x() << "," << e->y() << ")" << endl; 1115 // SVDEBUG << "FlexiNoteLayer::editDrag(" << e->x() << "," << e->y() << ")" << endl;
1116 std::cerr << "FlexiNoteLayer::editDrag(" << e->x() << "," << e->y() << ")" << std::endl; 1116 std::cerr << "FlexiNoteLayer::editDrag(" << e->x() << "," << e->y() << ")" << std::endl;
1117 1117
1118 if (!m_model || !m_editing) return; 1118 if (!m_model || !m_editing) return;
1188 1188
1189 std::cerr << "added new point(" << m_editingPoint.frame << "," << m_editingPoint.duration << ")" << std::endl; 1189 std::cerr << "added new point(" << m_editingPoint.frame << "," << m_editingPoint.duration << ")" << std::endl;
1190 } 1190 }
1191 1191
1192 void 1192 void
1193 FlexiNoteLayer::editEnd(View *v, QMouseEvent *e) 1193 FlexiNoteLayer::editEnd(LayerGeometryProvider *v, QMouseEvent *e)
1194 { 1194 {
1195 // SVDEBUG << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl; 1195 // SVDEBUG << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl;
1196 std::cerr << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl; 1196 std::cerr << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl;
1197 1197
1198 if (!m_model || !m_editing) return; 1198 if (!m_model || !m_editing) return;
1227 m_editingCommand = 0; 1227 m_editingCommand = 0;
1228 m_editing = false; 1228 m_editing = false;
1229 } 1229 }
1230 1230
1231 void 1231 void
1232 FlexiNoteLayer::splitStart(View *v, QMouseEvent *e) 1232 FlexiNoteLayer::splitStart(LayerGeometryProvider *v, QMouseEvent *e)
1233 { 1233 {
1234 // GF: note splitting starts (!! remove printing soon) 1234 // 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; 1235 std::cerr << "splitStart (n.b. editStart will be called later, if the user drags the mouse)" << std::endl;
1236 if (!m_model) return; 1236 if (!m_model) return;
1237 1237
1250 m_dragStartX = e->x(); 1250 m_dragStartX = e->x();
1251 m_dragStartY = e->y(); 1251 m_dragStartY = e->y();
1252 } 1252 }
1253 1253
1254 void 1254 void
1255 FlexiNoteLayer::splitEnd(View *v, QMouseEvent *e) 1255 FlexiNoteLayer::splitEnd(LayerGeometryProvider *v, QMouseEvent *e)
1256 { 1256 {
1257 // GF: note splitting ends. (!! remove printing soon) 1257 // GF: note splitting ends. (!! remove printing soon)
1258 std::cerr << "splitEnd" << std::endl; 1258 std::cerr << "splitEnd" << std::endl;
1259 if (!m_model || !m_editing || m_editMode != SplitNote) return; 1259 if (!m_model || !m_editing || m_editMode != SplitNote) return;
1260 1260
1269 1269
1270 splitNotesAt(v, frame, e); 1270 splitNotesAt(v, frame, e);
1271 } 1271 }
1272 1272
1273 void 1273 void
1274 FlexiNoteLayer::splitNotesAt(View *v, sv_frame_t frame) 1274 FlexiNoteLayer::splitNotesAt(LayerGeometryProvider *v, sv_frame_t frame)
1275 { 1275 {
1276 splitNotesAt(v, frame, 0); 1276 splitNotesAt(v, frame, 0);
1277 } 1277 }
1278 1278
1279 void 1279 void
1280 FlexiNoteLayer::splitNotesAt(View *v, sv_frame_t frame, QMouseEvent *e) 1280 FlexiNoteLayer::splitNotesAt(LayerGeometryProvider *v, sv_frame_t frame, QMouseEvent *e)
1281 { 1281 {
1282 FlexiNoteModel::PointList onPoints = m_model->getPoints(frame); 1282 FlexiNoteModel::PointList onPoints = m_model->getPoints(frame);
1283 if (onPoints.empty()) return; 1283 if (onPoints.empty()) return;
1284 1284
1285 FlexiNote note(*onPoints.begin()); 1285 FlexiNote note(*onPoints.begin());
1315 1315
1316 finish(command); 1316 finish(command);
1317 } 1317 }
1318 1318
1319 void 1319 void
1320 FlexiNoteLayer::addNote(View *v, QMouseEvent *e) 1320 FlexiNoteLayer::addNote(LayerGeometryProvider *v, QMouseEvent *e)
1321 { 1321 {
1322 std::cerr << "addNote" << std::endl; 1322 std::cerr << "addNote" << std::endl;
1323 if (!m_model) return; 1323 if (!m_model) return;
1324 1324
1325 sv_frame_t duration = 10000; 1325 sv_frame_t duration = 10000;
1354 finish(command); 1354 finish(command);
1355 } 1355 }
1356 } 1356 }
1357 1357
1358 SparseTimeValueModel * 1358 SparseTimeValueModel *
1359 FlexiNoteLayer::getAssociatedPitchModel(View *v) const 1359 FlexiNoteLayer::getAssociatedPitchModel(LayerGeometryProvider *v) const
1360 { 1360 {
1361 // Better than we used to do, but still not very satisfactory 1361 // Better than we used to do, but still not very satisfactory
1362 1362
1363 // cerr << "FlexiNoteLayer::getAssociatedPitchModel()" << endl; 1363 // cerr << "FlexiNoteLayer::getAssociatedPitchModel()" << endl;
1364 1364
1365 for (int i = 0; i < v->getLayerCount(); ++i) { 1365 for (int i = 0; i < v->getView()->getLayerCount(); ++i) {
1366 Layer *layer = v->getLayer(i); 1366 Layer *layer = v->getView()->getLayer(i);
1367 if (layer && 1367 if (layer &&
1368 layer->getLayerPresentationName() != "candidate") { 1368 layer->getLayerPresentationName() != "candidate") {
1369 // cerr << "FlexiNoteLayer::getAssociatedPitchModel: looks like our layer is " << layer << endl; 1369 // cerr << "FlexiNoteLayer::getAssociatedPitchModel: looks like our layer is " << layer << endl;
1370 SparseTimeValueModel *model = qobject_cast<SparseTimeValueModel *> 1370 SparseTimeValueModel *model = qobject_cast<SparseTimeValueModel *>
1371 (layer->getModel()); 1371 (layer->getModel());
1379 cerr << "FlexiNoteLayer::getAssociatedPitchModel: failed to find a model" << endl; 1379 cerr << "FlexiNoteLayer::getAssociatedPitchModel: failed to find a model" << endl;
1380 return 0; 1380 return 0;
1381 } 1381 }
1382 1382
1383 void 1383 void
1384 FlexiNoteLayer::snapSelectedNotesToPitchTrack(View *v, Selection s) 1384 FlexiNoteLayer::snapSelectedNotesToPitchTrack(LayerGeometryProvider *v, Selection s)
1385 { 1385 {
1386 if (!m_model) return; 1386 if (!m_model) return;
1387 1387
1388 FlexiNoteModel::PointList points = 1388 FlexiNoteModel::PointList points =
1389 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 1389 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
1417 1417
1418 finish(command); 1418 finish(command);
1419 } 1419 }
1420 1420
1421 void 1421 void
1422 FlexiNoteLayer::mergeNotes(View *v, Selection s, bool inclusive) 1422 FlexiNoteLayer::mergeNotes(LayerGeometryProvider *v, Selection s, bool inclusive)
1423 { 1423 {
1424 FlexiNoteModel::PointList points = 1424 FlexiNoteModel::PointList points =
1425 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 1425 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
1426 1426
1427 FlexiNoteModel::PointList::iterator i = points.begin(); 1427 FlexiNoteModel::PointList::iterator i = points.begin();
1460 command->addPoint(newNote); 1460 command->addPoint(newNote);
1461 finish(command); 1461 finish(command);
1462 } 1462 }
1463 1463
1464 bool 1464 bool
1465 FlexiNoteLayer::updateNoteValueFromPitchCurve(View *v, 1465 FlexiNoteLayer::updateNoteValueFromPitchCurve(LayerGeometryProvider *v, FlexiNoteModel::Point &note) const
1466 FlexiNoteModel::Point &note) const
1467 { 1466 {
1468 SparseTimeValueModel *model = getAssociatedPitchModel(v); 1467 SparseTimeValueModel *model = getAssociatedPitchModel(v);
1469 if (!model) return false; 1468 if (!model) return false;
1470 1469
1471 std::cerr << model->getTypeName() << std::endl; 1470 std::cerr << model->getTypeName() << std::endl;
1505 1504
1506 return true; 1505 return true;
1507 } 1506 }
1508 1507
1509 void 1508 void
1510 FlexiNoteLayer::mouseMoveEvent(View *v, QMouseEvent *e) 1509 FlexiNoteLayer::mouseMoveEvent(LayerGeometryProvider *v, QMouseEvent *e)
1511 { 1510 {
1512 // GF: context sensitive cursors 1511 // GF: context sensitive cursors
1513 // v->setCursor(Qt::ArrowCursor); 1512 // v->getView()->setCursor(Qt::ArrowCursor);
1514 FlexiNoteModel::Point note(0); 1513 FlexiNoteModel::Point note(0);
1515 if (!getNoteToEdit(v, e->x(), e->y(), note)) { 1514 if (!getNoteToEdit(v, e->x(), e->y(), note)) {
1516 // v->setCursor(Qt::UpArrowCursor); 1515 // v->getView()->setCursor(Qt::UpArrowCursor);
1517 return; 1516 return;
1518 } 1517 }
1519 1518
1520 bool closeToLeft = false, closeToRight = false, 1519 bool closeToLeft = false, closeToRight = false,
1521 closeToTop = false, closeToBottom = false; 1520 closeToTop = false, closeToBottom = false;
1522 getRelativeMousePosition(v, note, e->x(), e->y(), 1521 getRelativeMousePosition(v, note, e->x(), e->y(),
1523 closeToLeft, closeToRight, 1522 closeToLeft, closeToRight,
1524 closeToTop, closeToBottom); 1523 closeToTop, closeToBottom);
1525 1524
1526 if (closeToLeft) { 1525 if (closeToLeft) {
1527 v->setCursor(Qt::SizeHorCursor); 1526 v->getView()->setCursor(Qt::SizeHorCursor);
1528 m_editMode = LeftBoundary; 1527 m_editMode = LeftBoundary;
1529 cerr << "edit mode -> LeftBoundary" << endl; 1528 cerr << "edit mode -> LeftBoundary" << endl;
1530 } else if (closeToRight) { 1529 } else if (closeToRight) {
1531 v->setCursor(Qt::SizeHorCursor); 1530 v->getView()->setCursor(Qt::SizeHorCursor);
1532 m_editMode = RightBoundary; 1531 m_editMode = RightBoundary;
1533 cerr << "edit mode -> RightBoundary" << endl; 1532 cerr << "edit mode -> RightBoundary" << endl;
1534 } else if (closeToTop) { 1533 } else if (closeToTop) {
1535 v->setCursor(Qt::CrossCursor); 1534 v->getView()->setCursor(Qt::CrossCursor);
1536 m_editMode = DragNote; 1535 m_editMode = DragNote;
1537 cerr << "edit mode -> DragNote" << endl; 1536 cerr << "edit mode -> DragNote" << endl;
1538 } else if (closeToBottom) { 1537 } else if (closeToBottom) {
1539 v->setCursor(Qt::UpArrowCursor); 1538 v->getView()->setCursor(Qt::UpArrowCursor);
1540 m_editMode = SplitNote; 1539 m_editMode = SplitNote;
1541 cerr << "edit mode -> SplitNote" << endl; 1540 cerr << "edit mode -> SplitNote" << endl;
1542 } else { 1541 } else {
1543 v->setCursor(Qt::ArrowCursor); 1542 v->getView()->setCursor(Qt::ArrowCursor);
1544 } 1543 }
1545 } 1544 }
1546 1545
1547 void 1546 void
1548 FlexiNoteLayer::getRelativeMousePosition(View *v, FlexiNoteModel::Point &note, int x, int y, bool &closeToLeft, bool &closeToRight, bool &closeToTop, bool &closeToBottom) const 1547 FlexiNoteLayer::getRelativeMousePosition(LayerGeometryProvider *v, FlexiNoteModel::Point &note, int x, int y, bool &closeToLeft, bool &closeToRight, bool &closeToTop, bool &closeToBottom) const
1549 { 1548 {
1550 // GF: TODO: consoloidate the tolerance values 1549 // GF: TODO: consoloidate the tolerance values
1551 if (!m_model) return; 1550 if (!m_model) return;
1552 1551
1553 int ctol = 0; 1552 int ctol = 0;
1572 // cerr << "FlexiNoteLayer::getRelativeMousePosition: close to: left " << closeToLeft << " right " << closeToRight << " top " << closeToTop << " bottom " << closeToBottom << endl; 1571 // cerr << "FlexiNoteLayer::getRelativeMousePosition: close to: left " << closeToLeft << " right " << closeToRight << " top " << closeToTop << " bottom " << closeToBottom << endl;
1573 } 1572 }
1574 1573
1575 1574
1576 bool 1575 bool
1577 FlexiNoteLayer::editOpen(View *v, QMouseEvent *e) 1576 FlexiNoteLayer::editOpen(LayerGeometryProvider *v, QMouseEvent *e)
1578 { 1577 {
1579 std::cerr << "Opening note editor dialog" << std::endl; 1578 std::cerr << "Opening note editor dialog" << std::endl;
1580 if (!m_model) return false; 1579 if (!m_model) return false;
1581 1580
1582 FlexiNoteModel::Point note(0); 1581 FlexiNoteModel::Point note(0);
1726 1725
1727 finish(command); 1726 finish(command);
1728 } 1727 }
1729 1728
1730 void 1729 void
1731 FlexiNoteLayer::copy(View *v, Selection s, Clipboard &to) 1730 FlexiNoteLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to)
1732 { 1731 {
1733 if (!m_model) return; 1732 if (!m_model) return;
1734 1733
1735 FlexiNoteModel::PointList points = 1734 FlexiNoteModel::PointList points =
1736 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 1735 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
1744 } 1743 }
1745 } 1744 }
1746 } 1745 }
1747 1746
1748 bool 1747 bool
1749 FlexiNoteLayer::paste(View *v, const Clipboard &from, sv_frame_t /*frameOffset */, bool /* interactive */) 1748 FlexiNoteLayer::paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t /*frameOffset */, bool /* interactive */)
1750 { 1749 {
1751 if (!m_model) return false; 1750 if (!m_model) return false;
1752 1751
1753 const Clipboard::PointList &points = from.getPoints(); 1752 const Clipboard::PointList &points = from.getPoints();
1754 1753
1755 bool realign = false; 1754 bool realign = false;
1756 1755
1757 if (clipboardHasDifferentAlignment(v, from)) { 1756 if (clipboardHasDifferentAlignment(v, from)) {
1758 1757
1759 QMessageBox::StandardButton button = 1758 QMessageBox::StandardButton button =
1760 QMessageBox::question(v, tr("Re-align pasted items?"), 1759 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?"), 1760 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, 1761 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
1763 QMessageBox::Yes); 1762 QMessageBox::Yes);
1764 1763
1765 if (button == QMessageBox::Cancel) { 1764 if (button == QMessageBox::Cancel) {
1892 // double max = attributes.value("scaleMaximum").toDouble(&alsoOk); 1891 // double max = attributes.value("scaleMaximum").toDouble(&alsoOk);
1893 // if (ok && alsoOk && min != max) setDisplayExtents(min, max); 1892 // if (ok && alsoOk && min != max) setDisplayExtents(min, max);
1894 } 1893 }
1895 1894
1896 void 1895 void
1897 FlexiNoteLayer::setVerticalRangeToNoteRange(View *v) 1896 FlexiNoteLayer::setVerticalRangeToNoteRange(LayerGeometryProvider *v)
1898 { 1897 {
1899 double minf = std::numeric_limits<double>::max(); 1898 double minf = std::numeric_limits<double>::max();
1900 double maxf = 0; 1899 double maxf = 0;
1901 bool hasNotes = 0; 1900 bool hasNotes = 0;
1902 for (FlexiNoteModel::PointList::const_iterator i = m_model->getPoints().begin(); 1901 for (FlexiNoteModel::PointList::const_iterator i = m_model->getPoints().begin();
1908 } 1907 }
1909 1908
1910 std::cerr << "min frequency:" << minf << ", max frequency: " << maxf << std::endl; 1909 std::cerr << "min frequency:" << minf << ", max frequency: " << maxf << std::endl;
1911 1910
1912 if (hasNotes) { 1911 if (hasNotes) {
1913 v->getLayer(1)->setDisplayExtents(minf*0.66,maxf*1.5); 1912 v->getView()->getLayer(1)->setDisplayExtents(minf*0.66,maxf*1.5);
1914 // MM: this is a hack because we rely on 1913 // MM: this is a hack because we rely on
1915 // * this layer being automatically aligned to layer 1 1914 // * this layer being automatically aligned to layer 1
1916 // * layer one is a log frequency layer. 1915 // * layer one is a log frequency layer.
1917 } 1916 }
1918 } 1917 }