comparison layer/FlexiNoteLayer.cpp @ 646:ba76130ed7e5 tonioni

added context sensitive mouse pointers in note edit tool mode
author gyorgyf
date Sat, 15 Jun 2013 17:04:03 +0100
parents 5c9dcec5f3e9
children 87fe9e05e076
comparison
equal deleted inserted replaced
645:c8f45afb83d5 646:ba76130ed7e5
37 #include <iostream> 37 #include <iostream>
38 #include <cmath> 38 #include <cmath>
39 #include <utility> 39 #include <utility>
40 40
41 FlexiNoteLayer::FlexiNoteLayer() : 41 FlexiNoteLayer::FlexiNoteLayer() :
42 SingleColourLayer(), 42 SingleColourLayer(),
43 43
44 // m_model(0), 44 // m_model(0),
45 // m_editing(false), 45 // m_editing(false),
46 // m_originalPoint(0, 0.0, 0, 1.f, tr("New Point")), 46 // m_originalPoint(0, 0.0, 0, 1.f, tr("New Point")),
47 // m_editingPoint(0, 0.0, 0, 1.f, tr("New Point")), 47 // m_editingPoint(0, 0.0, 0, 1.f, tr("New Point")),
48 // m_editingCommand(0), 48 // m_editingCommand(0),
49 // m_verticalScale(AutoAlignScale), 49 // m_verticalScale(AutoAlignScale),
50 // m_scaleMinimum(0), 50 // m_scaleMinimum(0),
51 // m_scaleMaximum(0) 51 // m_scaleMaximum(0)
52 52
53 m_model(0), 53 m_model(0),
54 m_editing(false), 54 m_editing(false),
55 m_originalPoint(0, 0.0, 0, 1.f, tr("New Point")), 55 m_originalPoint(0, 0.0, 0, 1.f, tr("New Point")),
56 m_editingPoint(0, 0.0, 0, 1.f, tr("New Point")), 56 m_editingPoint(0, 0.0, 0, 1.f, tr("New Point")),
114 int *min, int *max, int *deflt) const 114 int *min, int *max, int *deflt) const
115 { 115 {
116 int val = 0; 116 int val = 0;
117 117
118 if (name == "Vertical Scale") { 118 if (name == "Vertical Scale") {
119 119
120 if (min) *min = 0; 120 if (min) *min = 0;
121 if (max) *max = 3; 121 if (max) *max = 3;
122 if (deflt) *deflt = int(AutoAlignScale); 122 if (deflt) *deflt = int(AutoAlignScale);
123 123
124 val = int(m_verticalScale); 124 val = int(m_verticalScale);
125 125
126 } else if (name == "Scale Units") { 126 } else if (name == "Scale Units") {
127 127
128 if (deflt) *deflt = 0; 128 if (deflt) *deflt = 0;
129 if (m_model) { 129 if (m_model) {
131 (m_model->getScaleUnits()); 131 (m_model->getScaleUnits());
132 } 132 }
133 133
134 } else { 134 } else {
135 135
136 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt); 136 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt);
137 } 137 }
138 138
139 return val; 139 return val;
140 } 140 }
141 141
142 QString 142 QString
143 FlexiNoteLayer::getPropertyValueLabel(const PropertyName &name, 143 FlexiNoteLayer::getPropertyValueLabel(const PropertyName &name,
144 int value) const 144 int value) const
145 { 145 {
146 if (name == "Vertical Scale") { 146 if (name == "Vertical Scale") {
147 switch (value) { 147 switch (value) {
148 default: 148 default:
149 case 0: return tr("Auto-Align"); 149 case 0: return tr("Auto-Align");
150 case 1: return tr("Linear"); 150 case 1: return tr("Linear");
151 case 2: return tr("Log"); 151 case 2: return tr("Log");
152 case 3: return tr("MIDI Notes"); 152 case 3: return tr("MIDI Notes");
153 } 153 }
154 } 154 }
155 return SingleColourLayer::getPropertyValueLabel(name, value); 155 return SingleColourLayer::getPropertyValueLabel(name, value);
156 } 156 }
157 157
158 void 158 void
159 FlexiNoteLayer::setProperty(const PropertyName &name, int value) 159 FlexiNoteLayer::setProperty(const PropertyName &name, int value)
160 { 160 {
161 if (name == "Vertical Scale") { 161 if (name == "Vertical Scale") {
162 setVerticalScale(VerticalScale(value)); 162 setVerticalScale(VerticalScale(value));
163 } else if (name == "Scale Units") { 163 } else if (name == "Scale Units") {
164 if (m_model) { 164 if (m_model) {
165 m_model->setScaleUnits 165 m_model->setScaleUnits
166 (UnitDatabase::getInstance()->getUnitById(value)); 166 (UnitDatabase::getInstance()->getUnitById(value));
167 emit modelChanged(); 167 emit modelChanged();
219 219
220 bool 220 bool
221 FlexiNoteLayer::getDisplayExtents(float &min, float &max) const 221 FlexiNoteLayer::getDisplayExtents(float &min, float &max) const
222 { 222 {
223 if (!m_model || shouldAutoAlign()) { 223 if (!m_model || shouldAutoAlign()) {
224 std::cerr << "No model or shouldAutoAlign()" << std::endl; 224 std::cerr << "No model or shouldAutoAlign()" << std::endl;
225 return false; 225 return false;
226 } 226 }
227 227
228 if (m_verticalScale == MIDIRangeScale) { 228 if (m_verticalScale == MIDIRangeScale) {
229 min = Pitch::getFrequencyForPitch(0); 229 min = Pitch::getFrequencyForPitch(0);
230 max = Pitch::getFrequencyForPitch(127); 230 max = Pitch::getFrequencyForPitch(127);
231 return true; 231 return true;
378 if (!m_model) return FlexiNoteModel::PointList(); 378 if (!m_model) return FlexiNoteModel::PointList();
379 379
380 long frame = v->getFrameForX(x); 380 long frame = v->getFrameForX(x);
381 381
382 FlexiNoteModel::PointList onPoints = 382 FlexiNoteModel::PointList onPoints =
383 m_model->getPoints(frame); 383 m_model->getPoints(frame);
384 384
385 if (!onPoints.empty()) { 385 if (!onPoints.empty()) {
386 return onPoints; 386 return onPoints;
387 } 387 }
388 388
389 FlexiNoteModel::PointList prevPoints = 389 FlexiNoteModel::PointList prevPoints =
390 m_model->getPreviousPoints(frame); 390 m_model->getPreviousPoints(frame);
391 FlexiNoteModel::PointList nextPoints = 391 FlexiNoteModel::PointList nextPoints =
392 m_model->getNextPoints(frame); 392 m_model->getNextPoints(frame);
393 393
394 FlexiNoteModel::PointList usePoints = prevPoints; 394 FlexiNoteModel::PointList usePoints = prevPoints;
395 395
396 if (prevPoints.empty()) { 396 if (prevPoints.empty()) {
397 usePoints = nextPoints; 397 usePoints = nextPoints;
398 } else if (long(prevPoints.begin()->frame) < v->getStartFrame() && 398 } else if (long(prevPoints.begin()->frame) < v->getStartFrame() &&
399 !(nextPoints.begin()->frame > v->getEndFrame())) { 399 !(nextPoints.begin()->frame > v->getEndFrame())) {
400 usePoints = nextPoints; 400 usePoints = nextPoints;
401 } else if (long(nextPoints.begin()->frame) - frame < 401 } else if (long(nextPoints.begin()->frame) - frame <
402 frame - long(prevPoints.begin()->frame)) { 402 frame - long(prevPoints.begin()->frame)) {
403 usePoints = nextPoints; 403 usePoints = nextPoints;
404 } 404 }
405 405
406 if (!usePoints.empty()) { 406 if (!usePoints.empty()) {
407 int fuzz = 2; 407 int fuzz = 2;
408 int px = v->getXForFrame(usePoints.begin()->frame); 408 int px = v->getXForFrame(usePoints.begin()->frame);
409 if ((px > x && px - x > fuzz) || 409 if ((px > x && px - x > fuzz) ||
410 (px < x && x - px > fuzz + 1)) { 410 (px < x && x - px > fuzz + 1)) {
411 usePoints.clear(); 411 usePoints.clear();
412 } 412 }
413 } 413 }
414 414
415 return usePoints; 415 return usePoints;
416 } 416 }
417 417
441 } 441 }
442 442
443 return true; 443 return true;
444 } 444 }
445 445
446 bool
447 FlexiNoteLayer::getNoteToEdit(View *v, int x, int y, FlexiNoteModel::Point &p) const
448 {
449 if (!m_model) return false;
450
451 long frame = v->getFrameForX(x);
452
453 FlexiNoteModel::PointList onPoints = m_model->getPoints(frame);
454 if (onPoints.empty()) return false;
455
456 // std::cerr << "frame " << frame << ": " << onPoints.size() << " candidate points" << std::endl;
457
458 int nearestDistance = -1;
459
460 for (FlexiNoteModel::PointList::const_iterator i = onPoints.begin();
461 i != onPoints.end(); ++i) {
462
463 int distance = getYForValue(v, (*i).value) - y;
464 if (distance < 0) distance = -distance;
465 if (nearestDistance == -1 || distance < nearestDistance) {
466 nearestDistance = distance;
467 p = *i;
468 }
469 }
470
471 return true;
472 }
473
446 QString 474 QString
447 FlexiNoteLayer::getFeatureDescription(View *v, QPoint &pos) const 475 FlexiNoteLayer::getFeatureDescription(View *v, QPoint &pos) const
448 { 476 {
449 int x = pos.x(); 477 int x = pos.x();
450 478
451 if (!m_model || !m_model->getSampleRate()) return ""; 479 if (!m_model || !m_model->getSampleRate()) return "";
452 480
453 FlexiNoteModel::PointList points = getLocalPoints(v, x); 481 FlexiNoteModel::PointList points = getLocalPoints(v, x);
454 482
455 if (points.empty()) { 483 if (points.empty()) {
456 if (!m_model->isReady()) { 484 if (!m_model->isReady()) {
457 return tr("In progress"); 485 return tr("In progress");
458 } else { 486 } else {
459 return tr("No local points"); 487 return tr("No local points");
460 } 488 }
461 } 489 }
462 490
463 FlexiNote note(0); 491 FlexiNote note(0);
464 FlexiNoteModel::PointList::iterator i; 492 FlexiNoteModel::PointList::iterator i;
465 493
466 for (i = points.begin(); i != points.end(); ++i) { 494 for (i = points.begin(); i != points.end(); ++i) {
467 495
468 int y = getYForValue(v, i->value); 496 int y = getYForValue(v, i->value);
469 int h = 3; 497 int h = 3;
470 498
471 if (m_model->getValueQuantization() != 0.0) { 499 if (m_model->getValueQuantization() != 0.0) {
472 h = y - getYForValue(v, i->value + m_model->getValueQuantization()); 500 h = y - getYForValue(v, i->value + m_model->getValueQuantization());
473 if (h < 3) h = 3; 501 if (h < 3) h = 3;
474 } 502 }
475 503
476 if (pos.y() >= y - h && pos.y() <= y) { 504 if (pos.y() >= y - h && pos.y() <= y) {
477 note = *i; 505 note = *i;
478 break; 506 break;
479 } 507 }
480 } 508 }
481 509
482 if (i == points.end()) return tr("No local points"); 510 if (i == points.end()) return tr("No local points");
483 511
484 RealTime rt = RealTime::frame2RealTime(note.frame, 512 RealTime rt = RealTime::frame2RealTime(note.frame,
485 m_model->getSampleRate()); 513 m_model->getSampleRate());
486 RealTime rd = RealTime::frame2RealTime(note.duration, 514 RealTime rd = RealTime::frame2RealTime(note.duration,
487 m_model->getSampleRate()); 515 m_model->getSampleRate());
488 516
489 QString pitchText; 517 QString pitchText;
490 518
491 if (shouldConvertMIDIToHz()) { 519 if (shouldConvertMIDIToHz()) {
492 520
511 } 539 }
512 540
513 QString text; 541 QString text;
514 542
515 if (note.label == "") { 543 if (note.label == "") {
516 text = QString(tr("Time:\t%1\nPitch:\t%2\nDuration:\t%3\nNo label")) 544 text = QString(tr("Time:\t%1\nPitch:\t%2\nDuration:\t%3\nNo label"))
517 .arg(rt.toText(true).c_str()) 545 .arg(rt.toText(true).c_str())
518 .arg(pitchText) 546 .arg(pitchText)
519 .arg(rd.toText(true).c_str()); 547 .arg(rd.toText(true).c_str());
520 } else { 548 } else {
521 text = QString(tr("Time:\t%1\nPitch:\t%2\nDuration:\t%3\nLabel:\t%4")) 549 text = QString(tr("Time:\t%1\nPitch:\t%2\nDuration:\t%3\nLabel:\t%4"))
522 .arg(rt.toText(true).c_str()) 550 .arg(rt.toText(true).c_str())
523 .arg(pitchText) 551 .arg(pitchText)
524 .arg(rd.toText(true).c_str()) 552 .arg(rd.toText(true).c_str())
525 .arg(note.label); 553 .arg(note.label);
526 } 554 }
527 555
528 pos = QPoint(v->getXForFrame(note.frame), 556 pos = QPoint(v->getXForFrame(note.frame),
529 getYForValue(v, note.value)); 557 getYForValue(v, note.value));
530 return text; 558 return text;
531 } 559 }
532 560
533 bool 561 bool
534 FlexiNoteLayer::snapToFeatureFrame(View *v, int &frame, 562 FlexiNoteLayer::snapToFeatureFrame(View *v, int &frame,
535 size_t &resolution, 563 size_t &resolution,
536 SnapType snap) const 564 SnapType snap) const
537 { 565 {
538 if (!m_model) { 566 if (!m_model) {
539 return Layer::snapToFeatureFrame(v, frame, resolution, snap); 567 return Layer::snapToFeatureFrame(v, frame, resolution, snap);
540 } 568 }
541 569
542 resolution = m_model->getResolution(); 570 resolution = m_model->getResolution();
543 FlexiNoteModel::PointList points; 571 FlexiNoteModel::PointList points;
544 572
545 if (snap == SnapNeighbouring) { 573 if (snap == SnapNeighbouring) {
546 574
547 points = getLocalPoints(v, v->getXForFrame(frame)); 575 points = getLocalPoints(v, v->getXForFrame(frame));
548 if (points.empty()) return false; 576 if (points.empty()) return false;
549 frame = points.begin()->frame; 577 frame = points.begin()->frame;
550 return true; 578 return true;
551 } 579 }
552 580
553 points = m_model->getPoints(frame, frame); 581 points = m_model->getPoints(frame, frame);
554 int snapped = frame; 582 int snapped = frame;
555 bool found = false; 583 bool found = false;
556 584
557 for (FlexiNoteModel::PointList::const_iterator i = points.begin(); 585 for (FlexiNoteModel::PointList::const_iterator i = points.begin();
558 i != points.end(); ++i) { 586 i != points.end(); ++i) {
559 587
560 if (snap == SnapRight) { 588 if (snap == SnapRight) {
561 589
562 if (i->frame > frame) { 590 if (i->frame > frame) {
563 snapped = i->frame; 591 snapped = i->frame;
564 found = true; 592 found = true;
565 break; 593 break;
566 } 594 }
567 595
568 } else if (snap == SnapLeft) { 596 } else if (snap == SnapLeft) {
569 597
570 if (i->frame <= frame) { 598 if (i->frame <= frame) {
571 snapped = i->frame; 599 snapped = i->frame;
572 found = true; // don't break, as the next may be better 600 found = true; // don't break, as the next may be better
573 } else { 601 } else {
574 break; 602 break;
575 } 603 }
576 604
577 } else { // nearest 605 } else { // nearest
578 606
579 FlexiNoteModel::PointList::const_iterator j = i; 607 FlexiNoteModel::PointList::const_iterator j = i;
580 ++j; 608 ++j;
581 609
582 if (j == points.end()) { 610 if (j == points.end()) {
583 611
584 snapped = i->frame; 612 snapped = i->frame;
585 found = true; 613 found = true;
586 break; 614 break;
587 615
588 } else if (j->frame >= frame) { 616 } else if (j->frame >= frame) {
589 617
590 if (j->frame - frame < frame - i->frame) { 618 if (j->frame - frame < frame - i->frame) {
591 snapped = j->frame; 619 snapped = j->frame;
592 } else { 620 } else {
593 snapped = i->frame; 621 snapped = i->frame;
594 } 622 }
595 found = true; 623 found = true;
596 break; 624 break;
597 } 625 }
598 } 626 }
599 } 627 }
600 628
601 frame = snapped; 629 frame = snapped;
602 return found; 630 return found;
603 } 631 }
733 761
734 QColor brushColour(getBaseQColor()); 762 QColor brushColour(getBaseQColor());
735 brushColour.setAlpha(80); 763 brushColour.setAlpha(80);
736 764
737 // SVDEBUG << "FlexiNoteLayer::paint: resolution is " 765 // SVDEBUG << "FlexiNoteLayer::paint: resolution is "
738 // << m_model->getResolution() << " frames" << endl; 766 // << m_model->getResolution() << " frames" << endl;
739 767
740 float min = m_model->getValueMinimum(); 768 float min = m_model->getValueMinimum();
741 float max = m_model->getValueMaximum(); 769 float max = m_model->getValueMaximum();
742 if (max == min) max = min + 1.0; 770 if (max == min) max = min + 1.0;
743 771
752 780
753 paint.save(); 781 paint.save();
754 paint.setRenderHint(QPainter::Antialiasing, false); 782 paint.setRenderHint(QPainter::Antialiasing, false);
755 783
756 for (FlexiNoteModel::PointList::const_iterator i = points.begin(); 784 for (FlexiNoteModel::PointList::const_iterator i = points.begin();
757 i != points.end(); ++i) { 785 i != points.end(); ++i) {
758 786
759 const FlexiNoteModel::Point &p(*i); 787 const FlexiNoteModel::Point &p(*i);
760 788
761 int x = v->getXForFrame(p.frame); 789 int x = v->getXForFrame(p.frame);
762 int y = getYForValue(v, p.value); 790 int y = getYForValue(v, p.value);
763 int w = v->getXForFrame(p.frame + p.duration) - x; 791 int w = v->getXForFrame(p.frame + p.duration) - x;
764 int h = 8; //GF: larger notes 792 int h = 8; //GF: larger notes
765 793
766 if (m_model->getValueQuantization() != 0.0) { 794 if (m_model->getValueQuantization() != 0.0) {
767 h = y - getYForValue(v, p.value + m_model->getValueQuantization()); 795 h = y - getYForValue(v, p.value + m_model->getValueQuantization());
768 if (h < 3) h = 8; //GF: larger notes 796 if (h < 3) h = 8; //GF: larger notes
769 } 797 }
770 798
771 if (w < 1) w = 1; 799 if (w < 1) w = 1;
772 paint.setPen(getBaseQColor()); 800 paint.setPen(getBaseQColor());
773 paint.setBrush(brushColour); 801 paint.setBrush(brushColour);
774 802
775 if (shouldIlluminate && 803 if (shouldIlluminate &&
776 // "illuminatePoint == p" 804 // "illuminatePoint == p"
777 !FlexiNoteModel::Point::Comparator()(illuminatePoint, p) && 805 !FlexiNoteModel::Point::Comparator()(illuminatePoint, p) &&
778 !FlexiNoteModel::Point::Comparator()(p, illuminatePoint)) { 806 !FlexiNoteModel::Point::Comparator()(p, illuminatePoint)) {
779 807
780 paint.setPen(v->getForeground()); 808 paint.setPen(v->getForeground());
791 (p.frame, m_model->getSampleRate()).toText(true).c_str(); 819 (p.frame, m_model->getSampleRate()).toText(true).c_str();
792 v->drawVisibleText(paint, 820 v->drawVisibleText(paint,
793 x, 821 x,
794 y - h/2 - paint.fontMetrics().descent() - 2, 822 y - h/2 - paint.fontMetrics().descent() - 2,
795 hlabel, View::OutlinedText); 823 hlabel, View::OutlinedText);
796 } 824 }
797 825
798 paint.drawRect(x, y - h/2, w, h); 826 paint.drawRect(x, y - h/2, w, h);
799 } 827 }
800 828
801 paint.restore(); 829 paint.restore();
802 } 830 }
803 831
817 m_editingPoint = FlexiNoteModel::Point(frame, value, 0, 0.8, tr("New Point")); 845 m_editingPoint = FlexiNoteModel::Point(frame, value, 0, 0.8, tr("New Point"));
818 m_originalPoint = m_editingPoint; 846 m_originalPoint = m_editingPoint;
819 847
820 if (m_editingCommand) finish(m_editingCommand); 848 if (m_editingCommand) finish(m_editingCommand);
821 m_editingCommand = new FlexiNoteModel::EditCommand(m_model, 849 m_editingCommand = new FlexiNoteModel::EditCommand(m_model,
822 tr("Draw Point")); 850 tr("Draw Point"));
823 m_editingCommand->addPoint(m_editingPoint); 851 m_editingCommand->addPoint(m_editingPoint);
824 852
825 m_editing = true; 853 m_editing = true;
826 } 854 }
827 855
870 if (!m_model) return; 898 if (!m_model) return;
871 899
872 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; 900 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return;
873 901
874 if (m_editingCommand) { 902 if (m_editingCommand) {
875 finish(m_editingCommand); 903 finish(m_editingCommand);
876 m_editingCommand = 0; 904 m_editingCommand = 0;
877 } 905 }
878 906
879 m_editing = true; 907 m_editing = true;
880 } 908 }
881 909
917 945
918 m_dragPointX = v->getXForFrame(m_editingPoint.frame); 946 m_dragPointX = v->getXForFrame(m_editingPoint.frame);
919 m_dragPointY = getYForValue(v, m_editingPoint.value); 947 m_dragPointY = getYForValue(v, m_editingPoint.value);
920 948
921 if (m_editingCommand) { 949 if (m_editingCommand) {
922 finish(m_editingCommand); 950 finish(m_editingCommand);
923 m_editingCommand = 0; 951 m_editingCommand = 0;
924 } 952 }
925 953
926 m_editing = true; 954 m_editing = true;
927 m_dragStartX = e->x(); 955 m_dragStartX = e->x();
928 m_dragStartY = e->y(); 956 m_dragStartY = e->y();
946 frame = frame / m_model->getResolution() * m_model->getResolution(); 974 frame = frame / m_model->getResolution() * m_model->getResolution();
947 975
948 float value = getValueForY(v, newy); 976 float value = getValueForY(v, newy);
949 977
950 if (!m_editingCommand) { 978 if (!m_editingCommand) {
951 m_editingCommand = new FlexiNoteModel::EditCommand(m_model, 979 m_editingCommand = new FlexiNoteModel::EditCommand(m_model,
952 tr("Drag Point")); 980 tr("Drag Point"));
953 } 981 }
954 982
955 m_editingCommand->deletePoint(m_editingPoint); 983 m_editingCommand->deletePoint(m_editingPoint);
956 m_editingPoint.frame = frame; 984 m_editingPoint.frame = frame;
957 m_editingPoint.value = value; 985 m_editingPoint.value = value;
966 994
967 if (!m_model || !m_editing) return; 995 if (!m_model || !m_editing) return;
968 996
969 if (m_editingCommand) { 997 if (m_editingCommand) {
970 998
971 QString newName = m_editingCommand->getName(); 999 QString newName = m_editingCommand->getName();
972 1000
973 if (m_editingPoint.frame != m_originalPoint.frame) { 1001 if (m_editingPoint.frame != m_originalPoint.frame) {
974 if (m_editingPoint.value != m_originalPoint.value) { 1002 if (m_editingPoint.value != m_originalPoint.value) {
975 newName = tr("Edit Point"); 1003 newName = tr("Edit Point");
976 } else { 1004 } else {
977 newName = tr("Relocate Point"); 1005 newName = tr("Relocate Point");
978 } 1006 }
979 } else { 1007 } else {
980 newName = tr("Change Point Value"); 1008 newName = tr("Change Point Value");
981 } 1009 }
982 1010
983 m_editingCommand->setName(newName); 1011 m_editingCommand->setName(newName);
984 finish(m_editingCommand); 1012 finish(m_editingCommand);
985 } 1013 }
986 1014
987 m_editingCommand = 0; 1015 m_editingCommand = 0;
988 m_editing = false; 1016 m_editing = false;
989 } 1017 }
990 1018
991 void 1019 void
992 FlexiNoteLayer::splitStart(View *v, QMouseEvent *e) 1020 FlexiNoteLayer::splitStart(View *v, QMouseEvent *e)
993 { 1021 {
994 std::cerr << "splitStart" << std::endl; 1022 // GF: note splitting starts (!! remove printing soon)
995 if (!m_model) return; 1023 std::cerr << "splitStart" << std::endl;
1024 if (!m_model) return;
996 1025
997 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; 1026 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return;
998 // m_originalPoint = m_editingPoint; 1027 // m_originalPoint = m_editingPoint;
999 // 1028 //
1000 // m_dragPointX = v->getXForFrame(m_editingPoint.frame); 1029 // m_dragPointX = v->getXForFrame(m_editingPoint.frame);
1001 // m_dragPointY = getYForValue(v, m_editingPoint.value); 1030 // m_dragPointY = getYForValue(v, m_editingPoint.value);
1002 1031
1003 if (m_editingCommand) { 1032 if (m_editingCommand) {
1004 finish(m_editingCommand); 1033 finish(m_editingCommand);
1005 m_editingCommand = 0; 1034 m_editingCommand = 0;
1006 } 1035 }
1007 1036
1008 m_editing = true; 1037 m_editing = true;
1009 m_dragStartX = e->x(); 1038 m_dragStartX = e->x();
1010 m_dragStartY = e->y(); 1039 m_dragStartY = e->y();
1012 } 1041 }
1013 1042
1014 void 1043 void
1015 FlexiNoteLayer::splitEnd(View *v, QMouseEvent *e) 1044 FlexiNoteLayer::splitEnd(View *v, QMouseEvent *e)
1016 { 1045 {
1017 std::cerr << "splitEnd" << std::endl; 1046 // GF: note splitting ends. (!! remove printing soon)
1018 if (!m_model || !m_editing) return; 1047 std::cerr << "splitEnd" << std::endl;
1048 if (!m_model || !m_editing) return;
1019 1049
1020 int xdist = e->x() - m_dragStartX; 1050 int xdist = e->x() - m_dragStartX;
1021 int ydist = e->y() - m_dragStartY; 1051 int ydist = e->y() - m_dragStartY;
1022 if (xdist != 0 || ydist != 0) { 1052 if (xdist != 0 || ydist != 0) {
1023 std::cerr << "mouse moved" << std::endl; 1053 std::cerr << "mouse moved" << std::endl;
1024 return; 1054 return;
1025 } 1055 }
1026 1056
1027 FlexiNoteModel::Point note(0); 1057 FlexiNoteModel::Point note(0);
1028 if (!getPointToDrag(v, e->x(), e->y(), note)) return; 1058 if (!getPointToDrag(v, e->x(), e->y(), note)) return;
1031 1061
1032 FlexiNoteModel::Point newNote1 = note; 1062 FlexiNoteModel::Point newNote1 = note;
1033 newNote1.frame = note.frame; 1063 newNote1.frame = note.frame;
1034 newNote1.value = note.value; 1064 newNote1.value = note.value;
1035 // newNote1.duration = note.duration+10000; 1065 // newNote1.duration = note.duration+10000;
1036 newNote1.duration = frame - note.frame - 100; 1066 newNote1.duration = frame - note.frame - 100;
1037 newNote1.label = note.label; 1067 newNote1.label = note.label;
1038 1068
1039 FlexiNoteModel::Point newNote2 = note; 1069 FlexiNoteModel::Point newNote2 = note;
1040 newNote2.frame = frame + 100; 1070 newNote2.frame = frame + 100;
1041 newNote2.value = note.value; 1071 newNote2.value = note.value;
1042 newNote2.duration = note.duration - (frame - note.frame - 100); 1072 newNote2.duration = note.duration - (frame - note.frame - 100);
1043 newNote2.label = note.label; 1073 newNote2.label = note.label;
1044 1074
1045 1075
1046 FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand 1076 FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand
1047 (m_model, tr("Edit Point")); 1077 (m_model, tr("Edit Point"));
1048 command->deletePoint(note); 1078 command->deletePoint(note);
1049 command->addPoint(newNote1); 1079 command->addPoint(newNote1);
1050 command->addPoint(newNote2); 1080 command->addPoint(newNote2);
1051 finish(command); 1081 finish(command);
1052 1082
1083 }
1084
1085 void
1086 FlexiNoteLayer::mouseMoveEvent(View *v, QMouseEvent *e)
1087 {
1088 // GF: context sensitive cursors
1089 // v->setCursor(Qt::ArrowCursor);
1090 FlexiNoteModel::Point note(0);
1091 if (!getNoteToEdit(v, e->x(), e->y(), note)) {
1092 // v->setCursor(Qt::UpArrowCursor);
1093 return;
1094 }
1095
1096 bool closeToLeft = false, closeToRight = false, closeToTop = false, closeToBottom = false;
1097 getRelativeMousePosition(v, note, e->x(), e->y(), closeToLeft, closeToRight, closeToTop, closeToBottom);
1098 // if (!closeToLeft) return;
1099 if (closeToLeft || closeToRight) { v->setCursor(Qt::SizeHorCursor); return; }
1100 // if (closeToTop) v->setCursor(Qt::SizeVerCursor);
1101 if (closeToTop) { v->setCursor(Qt::CrossCursor); return; }
1102 if (closeToBottom) { v->setCursor(Qt::UpArrowCursor); return; }
1103 v->setCursor(Qt::ArrowCursor);
1104
1105
1106 std::cerr << "Mouse moved in edit mode over FlexiNoteLayer" << std::endl;
1107 // v->setCursor(Qt::SizeHorCursor);
1108
1109 }
1110
1111 void
1112 FlexiNoteLayer::getRelativeMousePosition(View *v, FlexiNoteModel::Point &note, int x, int y, bool &closeToLeft, bool &closeToRight, bool &closeToTop, bool &closeToBottom) const
1113 {
1114 if (!m_model) return;
1115
1116 int ctol = 2;
1117 int noteStartX = v->getXForFrame(note.frame);
1118 int noteEndX = v->getXForFrame(note.frame + note.duration);
1119 int noteValueY = getYForValue(v,note.value);
1120 int noteStartY = noteValueY - (NOTE_HEIGHT / 2);
1121 int noteEndY = noteValueY + (NOTE_HEIGHT / 2);
1122
1123 bool closeToNote = false;
1124
1125 if (y >= noteStartY-ctol && y <= noteEndY+ctol && x >= noteStartX-ctol && x <= noteEndX+ctol) closeToNote = true;
1126 if (!closeToNote) return;
1127
1128 int tol = 4;
1129
1130 if (x >= noteStartX - tol && x <= noteStartX + tol) closeToLeft = true;
1131 if (x >= noteEndX - tol && x <= noteEndX + tol) closeToRight = true;
1132 if (y >= noteStartY - tol && y <= noteStartY + tol) closeToTop = true;
1133 if (y >= noteEndY - tol && y <= noteEndY + tol) closeToBottom = true;
1134
1053 } 1135 }
1054 1136
1055 1137
1056 bool 1138 bool
1057 FlexiNoteLayer::editOpen(View *v, QMouseEvent *e) 1139 FlexiNoteLayer::editOpen(View *v, QMouseEvent *e)
1100 FlexiNoteLayer::moveSelection(Selection s, size_t newStartFrame) 1182 FlexiNoteLayer::moveSelection(Selection s, size_t newStartFrame)
1101 { 1183 {
1102 if (!m_model) return; 1184 if (!m_model) return;
1103 1185
1104 FlexiNoteModel::EditCommand *command = 1186 FlexiNoteModel::EditCommand *command =
1105 new FlexiNoteModel::EditCommand(m_model, tr("Drag Selection")); 1187 new FlexiNoteModel::EditCommand(m_model, tr("Drag Selection"));
1106 1188
1107 FlexiNoteModel::PointList points = 1189 FlexiNoteModel::PointList points =
1108 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 1190 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
1109 1191
1110 for (FlexiNoteModel::PointList::iterator i = points.begin(); 1192 for (FlexiNoteModel::PointList::iterator i = points.begin();
1111 i != points.end(); ++i) { 1193 i != points.end(); ++i) {
1112 1194
1113 if (s.contains(i->frame)) { 1195 if (s.contains(i->frame)) {
1114 FlexiNoteModel::Point newPoint(*i); 1196 FlexiNoteModel::Point newPoint(*i);
1115 newPoint.frame = i->frame + newStartFrame - s.getStartFrame(); 1197 newPoint.frame = i->frame + newStartFrame - s.getStartFrame();
1116 command->deletePoint(*i); 1198 command->deletePoint(*i);
1117 command->addPoint(newPoint); 1199 command->addPoint(newPoint);
1118 } 1200 }
1119 } 1201 }
1120 1202
1121 finish(command); 1203 finish(command);
1122 } 1204 }
1123 1205
1125 FlexiNoteLayer::resizeSelection(Selection s, Selection newSize) 1207 FlexiNoteLayer::resizeSelection(Selection s, Selection newSize)
1126 { 1208 {
1127 if (!m_model) return; 1209 if (!m_model) return;
1128 1210
1129 FlexiNoteModel::EditCommand *command = 1211 FlexiNoteModel::EditCommand *command =
1130 new FlexiNoteModel::EditCommand(m_model, tr("Resize Selection")); 1212 new FlexiNoteModel::EditCommand(m_model, tr("Resize Selection"));
1131 1213
1132 FlexiNoteModel::PointList points = 1214 FlexiNoteModel::PointList points =
1133 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 1215 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
1134 1216
1135 double ratio = 1217 double ratio =
1136 double(newSize.getEndFrame() - newSize.getStartFrame()) / 1218 double(newSize.getEndFrame() - newSize.getStartFrame()) /
1137 double(s.getEndFrame() - s.getStartFrame()); 1219 double(s.getEndFrame() - s.getStartFrame());
1138 1220
1139 for (FlexiNoteModel::PointList::iterator i = points.begin(); 1221 for (FlexiNoteModel::PointList::iterator i = points.begin();
1140 i != points.end(); ++i) { 1222 i != points.end(); ++i) {
1141 1223
1142 if (s.contains(i->frame)) { 1224 if (s.contains(i->frame)) {
1143 1225
1144 double targetStart = i->frame; 1226 double targetStart = i->frame;
1145 targetStart = newSize.getStartFrame() + 1227 targetStart = newSize.getStartFrame() +
1146 double(targetStart - s.getStartFrame()) * ratio; 1228 double(targetStart - s.getStartFrame()) * ratio;
1147 1229
1148 double targetEnd = i->frame + i->duration; 1230 double targetEnd = i->frame + i->duration;
1149 targetEnd = newSize.getStartFrame() + 1231 targetEnd = newSize.getStartFrame() +
1150 double(targetEnd - s.getStartFrame()) * ratio; 1232 double(targetEnd - s.getStartFrame()) * ratio;
1151 1233
1152 FlexiNoteModel::Point newPoint(*i); 1234 FlexiNoteModel::Point newPoint(*i);
1153 newPoint.frame = lrint(targetStart); 1235 newPoint.frame = lrint(targetStart);
1154 newPoint.duration = lrint(targetEnd - targetStart); 1236 newPoint.duration = lrint(targetEnd - targetStart);
1155 command->deletePoint(*i); 1237 command->deletePoint(*i);
1156 command->addPoint(newPoint); 1238 command->addPoint(newPoint);
1157 } 1239 }
1158 } 1240 }
1159 1241
1160 finish(command); 1242 finish(command);
1161 } 1243 }
1162 1244
1164 FlexiNoteLayer::deleteSelection(Selection s) 1246 FlexiNoteLayer::deleteSelection(Selection s)
1165 { 1247 {
1166 if (!m_model) return; 1248 if (!m_model) return;
1167 1249
1168 FlexiNoteModel::EditCommand *command = 1250 FlexiNoteModel::EditCommand *command =
1169 new FlexiNoteModel::EditCommand(m_model, tr("Delete Selected Points")); 1251 new FlexiNoteModel::EditCommand(m_model, tr("Delete Selected Points"));
1170 1252
1171 FlexiNoteModel::PointList points = 1253 FlexiNoteModel::PointList points =
1172 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 1254 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
1173 1255
1174 for (FlexiNoteModel::PointList::iterator i = points.begin(); 1256 for (FlexiNoteModel::PointList::iterator i = points.begin();
1175 i != points.end(); ++i) { 1257 i != points.end(); ++i) {
1176 1258
1177 if (s.contains(i->frame)) { 1259 if (s.contains(i->frame)) {
1178 command->deletePoint(*i); 1260 command->deletePoint(*i);
1179 } 1261 }
1180 } 1262 }
1186 FlexiNoteLayer::copy(View *v, Selection s, Clipboard &to) 1268 FlexiNoteLayer::copy(View *v, Selection s, Clipboard &to)
1187 { 1269 {
1188 if (!m_model) return; 1270 if (!m_model) return;
1189 1271
1190 FlexiNoteModel::PointList points = 1272 FlexiNoteModel::PointList points =
1191 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 1273 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
1192 1274
1193 for (FlexiNoteModel::PointList::iterator i = points.begin(); 1275 for (FlexiNoteModel::PointList::iterator i = points.begin();
1194 i != points.end(); ++i) { 1276 i != points.end(); ++i) {
1195 if (s.contains(i->frame)) { 1277 if (s.contains(i->frame)) {
1196 Clipboard::Point point(i->frame, i->value, i->duration, i->level, i->label); 1278 Clipboard::Point point(i->frame, i->value, i->duration, i->level, i->label);
1197 point.setReferenceFrame(alignToReference(v, i->frame)); 1279 point.setReferenceFrame(alignToReference(v, i->frame));
1198 to.addPoint(point); 1280 to.addPoint(point);
1199 } 1281 }
1200 } 1282 }
1225 realign = true; 1307 realign = true;
1226 } 1308 }
1227 } 1309 }
1228 1310
1229 FlexiNoteModel::EditCommand *command = 1311 FlexiNoteModel::EditCommand *command =
1230 new FlexiNoteModel::EditCommand(m_model, tr("Paste")); 1312 new FlexiNoteModel::EditCommand(m_model, tr("Paste"));
1231 1313
1232 for (Clipboard::PointList::const_iterator i = points.begin(); 1314 for (Clipboard::PointList::const_iterator i = points.begin();
1233 i != points.end(); ++i) { 1315 i != points.end(); ++i) {
1234 1316
1235 if (!i->haveFrame()) continue; 1317 if (!i->haveFrame()) continue;
1337 { 1419 {
1338 SingleColourLayer::setProperties(attributes); 1420 SingleColourLayer::setProperties(attributes);
1339 1421
1340 bool ok, alsoOk; 1422 bool ok, alsoOk;
1341 VerticalScale scale = (VerticalScale) 1423 VerticalScale scale = (VerticalScale)
1342 attributes.value("verticalScale").toInt(&ok); 1424 attributes.value("verticalScale").toInt(&ok);
1343 if (ok) setVerticalScale(scale); 1425 if (ok) setVerticalScale(scale);
1344 1426
1345 float min = attributes.value("scaleMinimum").toFloat(&ok); 1427 float min = attributes.value("scaleMinimum").toFloat(&ok);
1346 float max = attributes.value("scaleMaximum").toFloat(&alsoOk); 1428 float max = attributes.value("scaleMaximum").toFloat(&alsoOk);
1347 if (ok && alsoOk) setDisplayExtents(min, max); 1429 if (ok && alsoOk) setDisplayExtents(min, max);