comparison layer/FlexiNoteLayer.cpp @ 714:797eb48f38c1 tonioni

Indentation
author Chris Cannam
date Fri, 10 Jan 2014 14:07:12 +0000
parents cc6b21976261
children 7169d08e9467
comparison
equal deleted inserted replaced
713:6d79ad93fef0 714:797eb48f38c1
48 48
49 49
50 FlexiNoteLayer::FlexiNoteLayer() : 50 FlexiNoteLayer::FlexiNoteLayer() :
51 SingleColourLayer(), 51 SingleColourLayer(),
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")),
57 // m_editingCommand(0), 57 // m_editingCommand(0),
58 // m_verticalScale(AutoAlignScale), 58 // m_verticalScale(AutoAlignScale),
59 // m_scaleMinimum(0), 59 // m_scaleMinimum(0),
60 // m_scaleMaximum(0) 60 // m_scaleMaximum(0)
61 61
62 m_model(0), 62 m_model(0),
63 m_editing(false), 63 m_editing(false),
64 m_originalPoint(0, 0.0, 0, 1.f, tr("New Point")), 64 m_originalPoint(0, 0.0, 0, 1.f, tr("New Point")),
65 m_editingPoint(0, 0.0, 0, 1.f, tr("New Point")), 65 m_editingPoint(0, 0.0, 0, 1.f, tr("New Point")),
127 else return ""; 127 else return "";
128 } 128 }
129 129
130 int 130 int
131 FlexiNoteLayer::getPropertyRangeAndValue(const PropertyName &name, 131 FlexiNoteLayer::getPropertyRangeAndValue(const PropertyName &name,
132 int *min, int *max, int *deflt) const 132 int *min, int *max, int *deflt) const
133 { 133 {
134 int val = 0; 134 int val = 0;
135 135
136 if (name == "Vertical Scale") { 136 if (name == "Vertical Scale") {
137 137
138 if (min) *min = 0; 138 if (min) *min = 0;
139 if (max) *max = 3; 139 if (max) *max = 3;
140 if (deflt) *deflt = int(AutoAlignScale); 140 if (deflt) *deflt = int(AutoAlignScale);
141 141
142 val = int(m_verticalScale); 142 val = int(m_verticalScale);
143 143
144 } else if (name == "Scale Units") { 144 } else if (name == "Scale Units") {
145 145
146 if (deflt) *deflt = 0; 146 if (deflt) *deflt = 0;
147 if (m_model) { 147 if (m_model) {
149 (getScaleUnits()); 149 (getScaleUnits());
150 } 150 }
151 151
152 } else { 152 } else {
153 153
154 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt); 154 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt);
155 } 155 }
156 156
157 return val; 157 return val;
158 } 158 }
159 159
160 QString 160 QString
161 FlexiNoteLayer::getPropertyValueLabel(const PropertyName &name, 161 FlexiNoteLayer::getPropertyValueLabel(const PropertyName &name,
162 int value) const 162 int value) const
163 { 163 {
164 if (name == "Vertical Scale") { 164 if (name == "Vertical Scale") {
165 switch (value) { 165 switch (value) {
166 default: 166 default:
167 case 0: return tr("Auto-Align"); 167 case 0: return tr("Auto-Align");
168 case 1: return tr("Linear"); 168 case 1: return tr("Linear");
169 case 2: return tr("Log"); 169 case 2: return tr("Log");
170 case 3: return tr("MIDI Notes"); 170 case 3: return tr("MIDI Notes");
171 } 171 }
172 } 172 }
173 return SingleColourLayer::getPropertyValueLabel(name, value); 173 return SingleColourLayer::getPropertyValueLabel(name, value);
174 } 174 }
175 175
176 void 176 void
177 FlexiNoteLayer::setProperty(const PropertyName &name, int value) 177 FlexiNoteLayer::setProperty(const PropertyName &name, int value)
178 { 178 {
179 if (name == "Vertical Scale") { 179 if (name == "Vertical Scale") {
180 setVerticalScale(VerticalScale(value)); 180 setVerticalScale(VerticalScale(value));
181 } else if (name == "Scale Units") { 181 } else if (name == "Scale Units") {
182 if (m_model) { 182 if (m_model) {
183 m_model->setScaleUnits 183 m_model->setScaleUnits
184 (UnitDatabase::getInstance()->getUnitById(value)); 184 (UnitDatabase::getInstance()->getUnitById(value));
185 emit modelChanged(); 185 emit modelChanged();
215 // return false; 215 // return false;
216 } 216 }
217 217
218 bool 218 bool
219 FlexiNoteLayer::getValueExtents(float &min, float &max, 219 FlexiNoteLayer::getValueExtents(float &min, float &max,
220 bool &logarithmic, QString &unit) const 220 bool &logarithmic, QString &unit) const
221 { 221 {
222 if (!m_model) return false; 222 if (!m_model) return false;
223 min = m_model->getValueMinimum(); 223 min = m_model->getValueMinimum();
224 max = m_model->getValueMaximum(); 224 max = m_model->getValueMaximum();
225 225
404 if (!m_model) return FlexiNoteModel::PointList(); 404 if (!m_model) return FlexiNoteModel::PointList();
405 405
406 long frame = v->getFrameForX(x); 406 long frame = v->getFrameForX(x);
407 407
408 FlexiNoteModel::PointList onPoints = 408 FlexiNoteModel::PointList onPoints =
409 m_model->getPoints(frame); 409 m_model->getPoints(frame);
410 410
411 if (!onPoints.empty()) { 411 if (!onPoints.empty()) {
412 return onPoints; 412 return onPoints;
413 } 413 }
414 414
415 FlexiNoteModel::PointList prevPoints = 415 FlexiNoteModel::PointList prevPoints =
416 m_model->getPreviousPoints(frame); 416 m_model->getPreviousPoints(frame);
417 FlexiNoteModel::PointList nextPoints = 417 FlexiNoteModel::PointList nextPoints =
418 m_model->getNextPoints(frame); 418 m_model->getNextPoints(frame);
419 419
420 FlexiNoteModel::PointList usePoints = prevPoints; 420 FlexiNoteModel::PointList usePoints = prevPoints;
421 421
422 if (prevPoints.empty()) { 422 if (prevPoints.empty()) {
423 usePoints = nextPoints; 423 usePoints = nextPoints;
424 } else if (long(prevPoints.begin()->frame) < v->getStartFrame() && 424 } else if (long(prevPoints.begin()->frame) < v->getStartFrame() &&
425 !(nextPoints.begin()->frame > v->getEndFrame())) { 425 !(nextPoints.begin()->frame > v->getEndFrame())) {
426 usePoints = nextPoints; 426 usePoints = nextPoints;
427 } else if (long(nextPoints.begin()->frame) - frame < 427 } else if (long(nextPoints.begin()->frame) - frame <
428 frame - long(prevPoints.begin()->frame)) { 428 frame - long(prevPoints.begin()->frame)) {
429 usePoints = nextPoints; 429 usePoints = nextPoints;
430 } 430 }
431 431
432 if (!usePoints.empty()) { 432 if (!usePoints.empty()) {
433 int fuzz = 2; 433 int fuzz = 2;
434 int px = v->getXForFrame(usePoints.begin()->frame); 434 int px = v->getXForFrame(usePoints.begin()->frame);
435 if ((px > x && px - x > fuzz) || 435 if ((px > x && px - x > fuzz) ||
436 (px < x && x - px > fuzz + 1)) { 436 (px < x && x - px > fuzz + 1)) {
437 usePoints.clear(); 437 usePoints.clear();
438 } 438 }
439 } 439 }
440 440
441 return usePoints; 441 return usePoints;
442 } 442 }
443 443
506 if (!m_model || !m_model->getSampleRate()) return ""; 506 if (!m_model || !m_model->getSampleRate()) return "";
507 507
508 FlexiNoteModel::PointList points = getLocalPoints(v, x); 508 FlexiNoteModel::PointList points = getLocalPoints(v, x);
509 509
510 if (points.empty()) { 510 if (points.empty()) {
511 if (!m_model->isReady()) { 511 if (!m_model->isReady()) {
512 return tr("In progress"); 512 return tr("In progress");
513 } else { 513 } else {
514 return tr("No local points"); 514 return tr("No local points");
515 } 515 }
516 } 516 }
517 517
518 FlexiNote note(0); 518 FlexiNote note(0);
519 FlexiNoteModel::PointList::iterator i; 519 FlexiNoteModel::PointList::iterator i;
520 520
521 for (i = points.begin(); i != points.end(); ++i) { 521 for (i = points.begin(); i != points.end(); ++i) {
522 522
523 int y = getYForValue(v, i->value); 523 int y = getYForValue(v, i->value);
524 int h = NOTE_HEIGHT; // GF: larger notes 524 int h = NOTE_HEIGHT; // GF: larger notes
525 525
526 if (m_model->getValueQuantization() != 0.0) { 526 if (m_model->getValueQuantization() != 0.0) {
527 h = y - getYForValue(v, i->value + m_model->getValueQuantization()); 527 h = y - getYForValue(v, i->value + m_model->getValueQuantization());
528 if (h < NOTE_HEIGHT) h = NOTE_HEIGHT; 528 if (h < NOTE_HEIGHT) h = NOTE_HEIGHT;
529 } 529 }
530 530
531 // GF: this is not quite correct 531 // GF: this is not quite correct
532 if (pos.y() >= y - 4 && pos.y() <= y + h) { 532 if (pos.y() >= y - 4 && pos.y() <= y + h) {
533 note = *i; 533 note = *i;
534 break; 534 break;
535 } 535 }
536 } 536 }
537 537
538 if (i == points.end()) return tr("No local points"); 538 if (i == points.end()) return tr("No local points");
539 539
540 RealTime rt = RealTime::frame2RealTime(note.frame, 540 RealTime rt = RealTime::frame2RealTime(note.frame,
541 m_model->getSampleRate()); 541 m_model->getSampleRate());
542 RealTime rd = RealTime::frame2RealTime(note.duration, 542 RealTime rd = RealTime::frame2RealTime(note.duration,
543 m_model->getSampleRate()); 543 m_model->getSampleRate());
544 544
545 QString pitchText; 545 QString pitchText;
546 546
547 if (shouldConvertMIDIToHz()) { 547 if (shouldConvertMIDIToHz()) {
548 548
567 } 567 }
568 568
569 QString text; 569 QString text;
570 570
571 if (note.label == "") { 571 if (note.label == "") {
572 text = QString(tr("Time:\t%1\nPitch:\t%2\nDuration:\t%3\nNo label")) 572 text = QString(tr("Time:\t%1\nPitch:\t%2\nDuration:\t%3\nNo label"))
573 .arg(rt.toText(true).c_str()) 573 .arg(rt.toText(true).c_str())
574 .arg(pitchText) 574 .arg(pitchText)
575 .arg(rd.toText(true).c_str()); 575 .arg(rd.toText(true).c_str());
576 } else { 576 } else {
577 text = QString(tr("Time:\t%1\nPitch:\t%2\nDuration:\t%3\nLabel:\t%4")) 577 text = QString(tr("Time:\t%1\nPitch:\t%2\nDuration:\t%3\nLabel:\t%4"))
578 .arg(rt.toText(true).c_str()) 578 .arg(rt.toText(true).c_str())
579 .arg(pitchText) 579 .arg(pitchText)
580 .arg(rd.toText(true).c_str()) 580 .arg(rd.toText(true).c_str())
581 .arg(note.label); 581 .arg(note.label);
582 } 582 }
583 583
584 pos = QPoint(v->getXForFrame(note.frame), 584 pos = QPoint(v->getXForFrame(note.frame),
585 getYForValue(v, note.value)); 585 getYForValue(v, note.value));
586 return text; 586 return text;
587 } 587 }
588 588
589 bool 589 bool
590 FlexiNoteLayer::snapToFeatureFrame(View *v, int &frame, 590 FlexiNoteLayer::snapToFeatureFrame(View *v, int &frame,
591 size_t &resolution, 591 size_t &resolution,
592 SnapType snap) const 592 SnapType snap) const
593 { 593 {
594 if (!m_model) { 594 if (!m_model) {
595 return Layer::snapToFeatureFrame(v, frame, resolution, snap); 595 return Layer::snapToFeatureFrame(v, frame, resolution, snap);
596 } 596 }
597 597
598 resolution = m_model->getResolution(); 598 resolution = m_model->getResolution();
599 FlexiNoteModel::PointList points; 599 FlexiNoteModel::PointList points;
600 600
601 if (snap == SnapNeighbouring) { 601 if (snap == SnapNeighbouring) {
602 602
603 points = getLocalPoints(v, v->getXForFrame(frame)); 603 points = getLocalPoints(v, v->getXForFrame(frame));
604 if (points.empty()) return false; 604 if (points.empty()) return false;
605 frame = points.begin()->frame; 605 frame = points.begin()->frame;
606 return true; 606 return true;
607 } 607 }
608 608
609 points = m_model->getPoints(frame, frame); 609 points = m_model->getPoints(frame, frame);
610 int snapped = frame; 610 int snapped = frame;
611 bool found = false; 611 bool found = false;
612 612
613 for (FlexiNoteModel::PointList::const_iterator i = points.begin(); 613 for (FlexiNoteModel::PointList::const_iterator i = points.begin();
614 i != points.end(); ++i) { 614 i != points.end(); ++i) {
615 615
616 if (snap == SnapRight) { 616 if (snap == SnapRight) {
617 617
618 if (i->frame > frame) { 618 if (i->frame > frame) {
619 snapped = i->frame; 619 snapped = i->frame;
620 found = true; 620 found = true;
621 break; 621 break;
622 } 622 }
623 623
624 } else if (snap == SnapLeft) { 624 } else if (snap == SnapLeft) {
625 625
626 if (i->frame <= frame) { 626 if (i->frame <= frame) {
627 snapped = i->frame; 627 snapped = i->frame;
628 found = true; // don't break, as the next may be better 628 found = true; // don't break, as the next may be better
629 } else { 629 } else {
630 break; 630 break;
631 } 631 }
632 632
633 } else { // nearest 633 } else { // nearest
634 634
635 FlexiNoteModel::PointList::const_iterator j = i; 635 FlexiNoteModel::PointList::const_iterator j = i;
636 ++j; 636 ++j;
637 637
638 if (j == points.end()) { 638 if (j == points.end()) {
639 639
640 snapped = i->frame; 640 snapped = i->frame;
641 found = true; 641 found = true;
642 break; 642 break;
643 643
644 } else if (j->frame >= frame) { 644 } else if (j->frame >= frame) {
645 645
646 if (j->frame - frame < frame - i->frame) { 646 if (j->frame - frame < frame - i->frame) {
647 snapped = j->frame; 647 snapped = j->frame;
648 } else { 648 } else {
649 snapped = i->frame; 649 snapped = i->frame;
650 } 650 }
651 found = true; 651 found = true;
652 break; 652 break;
653 } 653 }
654 } 654 }
655 } 655 }
656 656
657 frame = snapped; 657 frame = snapped;
658 return found; 658 return found;
659 } 659 }
819 819
820 paint.save(); 820 paint.save();
821 paint.setRenderHint(QPainter::Antialiasing, false); 821 paint.setRenderHint(QPainter::Antialiasing, false);
822 822
823 for (FlexiNoteModel::PointList::const_iterator i = points.begin(); 823 for (FlexiNoteModel::PointList::const_iterator i = points.begin();
824 i != points.end(); ++i) { 824 i != points.end(); ++i) {
825 825
826 const FlexiNoteModel::Point &p(*i); 826 const FlexiNoteModel::Point &p(*i);
827 827
828 int x = v->getXForFrame(p.frame); 828 int x = v->getXForFrame(p.frame);
829 int y = getYForValue(v, p.value); 829 int y = getYForValue(v, p.value);
830 int w = v->getXForFrame(p.frame + p.duration) - x; 830 int w = v->getXForFrame(p.frame + p.duration) - x;
831 int h = NOTE_HEIGHT; //GF: larger notes 831 int h = NOTE_HEIGHT; //GF: larger notes
832 832
833 if (m_model->getValueQuantization() != 0.0) { 833 if (m_model->getValueQuantization() != 0.0) {
834 h = y - getYForValue(v, p.value + m_model->getValueQuantization()); 834 h = y - getYForValue(v, p.value + m_model->getValueQuantization());
835 if (h < NOTE_HEIGHT) h = NOTE_HEIGHT; //GF: larger notes 835 if (h < NOTE_HEIGHT) h = NOTE_HEIGHT; //GF: larger notes
836 } 836 }
837 837
838 if (w < 1) w = 1; 838 if (w < 1) w = 1;
839 paint.setPen(getBaseQColor()); 839 paint.setPen(getBaseQColor());
840 paint.setBrush(brushColour); 840 paint.setBrush(brushColour);
841 841
842 // if (shouldIlluminate && 842 // if (shouldIlluminate &&
843 // // "illuminatePoint == p" 843 // // "illuminatePoint == p"
844 // !FlexiNoteModel::Point::Comparator()(illuminatePoint, p) && 844 // !FlexiNoteModel::Point::Comparator()(illuminatePoint, p) &&
845 // !FlexiNoteModel::Point::Comparator()(p, illuminatePoint)) { 845 // !FlexiNoteModel::Point::Comparator()(p, illuminatePoint)) {
846 // 846 //
847 // paint.setPen(v->getForeground()); 847 // paint.setPen(v->getForeground());
848 // paint.setBrush(v->getForeground()); 848 // paint.setBrush(v->getForeground());
849 // 849 //
850 // QString vlabel = QString("%1%2").arg(p.value).arg(m_model->getScaleUnits()); 850 // QString vlabel = QString("%1%2").arg(p.value).arg(m_model->getScaleUnits());
851 // v->drawVisibleText(paint, 851 // v->drawVisibleText(paint,
852 // x - paint.fontMetrics().width(vlabel) - 2, 852 // x - paint.fontMetrics().width(vlabel) - 2,
853 // y + paint.fontMetrics().height()/2 853 // y + paint.fontMetrics().height()/2
854 // - paint.fontMetrics().descent(), 854 // - paint.fontMetrics().descent(),
855 // vlabel, View::OutlinedText); 855 // vlabel, View::OutlinedText);
856 // 856 //
857 // QString hlabel = RealTime::frame2RealTime 857 // QString hlabel = RealTime::frame2RealTime
858 // (p.frame, m_model->getSampleRate()).toText(true).c_str(); 858 // (p.frame, m_model->getSampleRate()).toText(true).c_str();
859 // v->drawVisibleText(paint, 859 // v->drawVisibleText(paint,
860 // x, 860 // x,
861 // y - h/2 - paint.fontMetrics().descent() - 2, 861 // y - h/2 - paint.fontMetrics().descent() - 2,
862 // hlabel, View::OutlinedText); 862 // hlabel, View::OutlinedText);
863 // } 863 // }
864 864
865 paint.drawRect(x, y - h/2, w, h); 865 paint.drawRect(x, y - h/2, w, h);
866 } 866 }
867 867
868 paint.restore(); 868 paint.restore();
869 } 869 }
870 870
936 m_editingPoint = FlexiNoteModel::Point(frame, value, 0, 0.8, tr("New Point")); 936 m_editingPoint = FlexiNoteModel::Point(frame, value, 0, 0.8, tr("New Point"));
937 m_originalPoint = m_editingPoint; 937 m_originalPoint = m_editingPoint;
938 938
939 if (m_editingCommand) finish(m_editingCommand); 939 if (m_editingCommand) finish(m_editingCommand);
940 m_editingCommand = new FlexiNoteModel::EditCommand(m_model, 940 m_editingCommand = new FlexiNoteModel::EditCommand(m_model,
941 tr("Draw Point")); 941 tr("Draw Point"));
942 m_editingCommand->addPoint(m_editingPoint); 942 m_editingCommand->addPoint(m_editingPoint);
943 943
944 m_editing = true; 944 m_editing = true;
945 } 945 }
946 946
989 if (!m_model) return; 989 if (!m_model) return;
990 990
991 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; 991 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return;
992 992
993 if (m_editingCommand) { 993 if (m_editingCommand) {
994 finish(m_editingCommand); 994 finish(m_editingCommand);
995 m_editingCommand = 0; 995 m_editingCommand = 0;
996 } 996 }
997 997
998 m_editing = true; 998 m_editing = true;
999 } 999 }
1000 1000
1040 m_dragPointX = v->getXForFrame(m_editingPoint.frame); 1040 m_dragPointX = v->getXForFrame(m_editingPoint.frame);
1041 } 1041 }
1042 m_dragPointY = getYForValue(v, m_editingPoint.value); 1042 m_dragPointY = getYForValue(v, m_editingPoint.value);
1043 1043
1044 if (m_editingCommand) { 1044 if (m_editingCommand) {
1045 finish(m_editingCommand); 1045 finish(m_editingCommand);
1046 m_editingCommand = 0; 1046 m_editingCommand = 0;
1047 } 1047 }
1048 1048
1049 m_editing = true; 1049 m_editing = true;
1050 m_dragStartX = e->x(); 1050 m_dragStartX = e->x();
1051 m_dragStartY = e->y(); 1051 m_dragStartY = e->y();
1092 dragFrame = dragFrame / m_model->getResolution() * m_model->getResolution(); 1092 dragFrame = dragFrame / m_model->getResolution() * m_model->getResolution();
1093 1093
1094 float value = getValueForY(v, newy); 1094 float value = getValueForY(v, newy);
1095 1095
1096 if (!m_editingCommand) { 1096 if (!m_editingCommand) {
1097 m_editingCommand = new FlexiNoteModel::EditCommand(m_model, 1097 m_editingCommand = new FlexiNoteModel::EditCommand(m_model,
1098 tr("Drag Point")); 1098 tr("Drag Point"));
1099 } 1099 }
1100 1100
1101 m_editingCommand->deletePoint(m_editingPoint); 1101 m_editingCommand->deletePoint(m_editingPoint);
1102 1102
1103 std::cerr << "edit mode: " << m_editMode << std::endl; 1103 std::cerr << "edit mode: " << m_editMode << std::endl;
1104 1104
1105 switch (m_editMode) { 1105 switch (m_editMode) {
1106 case LeftBoundary : { 1106 case LeftBoundary : {
1107 // left 1107 // left
1108 if (m_intelligentActions && dragFrame <= m_greatestLeftNeighbourFrame) dragFrame = m_greatestLeftNeighbourFrame + 1; 1108 if (m_intelligentActions && dragFrame <= m_greatestLeftNeighbourFrame) dragFrame = m_greatestLeftNeighbourFrame + 1;
1109 // right 1109 // right
1110 if (m_intelligentActions && dragFrame >= m_originalPoint.frame + m_originalPoint.duration) { 1110 if (m_intelligentActions && dragFrame >= m_originalPoint.frame + m_originalPoint.duration) {
1111 dragFrame = m_originalPoint.frame + m_originalPoint.duration - 1; 1111 dragFrame = m_originalPoint.frame + m_originalPoint.duration - 1;
1112 } 1112 }
1113 m_editingPoint.frame = dragFrame; 1113 m_editingPoint.frame = dragFrame;
1114 m_editingPoint.duration = m_originalPoint.frame - dragFrame + m_originalPoint.duration; 1114 m_editingPoint.duration = m_originalPoint.frame - dragFrame + m_originalPoint.duration;
1115 break; 1115 break;
1116 } 1116 }
1117 case RightBoundary : { 1117 case RightBoundary : {
1118 // left 1118 // left
1119 if (m_intelligentActions && dragFrame <= m_greatestLeftNeighbourFrame) dragFrame = m_greatestLeftNeighbourFrame + 1; 1119 if (m_intelligentActions && dragFrame <= m_greatestLeftNeighbourFrame) dragFrame = m_greatestLeftNeighbourFrame + 1;
1120 if (m_intelligentActions && dragFrame >= m_smallestRightNeighbourFrame) dragFrame = m_smallestRightNeighbourFrame - 1; 1120 if (m_intelligentActions && dragFrame >= m_smallestRightNeighbourFrame) dragFrame = m_smallestRightNeighbourFrame - 1;
1121 m_editingPoint.duration = dragFrame - m_originalPoint.frame + 1; 1121 m_editingPoint.duration = dragFrame - m_originalPoint.frame + 1;
1122 break; 1122 break;
1123 } 1123 }
1124 case DragNote : { 1124 case DragNote : {
1125 // left 1125 // left
1126 if (m_intelligentActions && dragFrame <= m_greatestLeftNeighbourFrame) dragFrame = m_greatestLeftNeighbourFrame + 1; 1126 if (m_intelligentActions && dragFrame <= m_greatestLeftNeighbourFrame) dragFrame = m_greatestLeftNeighbourFrame + 1;
1127 // right 1127 // right
1128 if (m_intelligentActions && dragFrame + m_originalPoint.duration >= m_smallestRightNeighbourFrame) { 1128 if (m_intelligentActions && dragFrame + m_originalPoint.duration >= m_smallestRightNeighbourFrame) {
1129 dragFrame = m_smallestRightNeighbourFrame - m_originalPoint.duration; 1129 dragFrame = m_smallestRightNeighbourFrame - m_originalPoint.duration;
1130 } 1130 }
1131 m_editingPoint.frame = dragFrame; 1131 m_editingPoint.frame = dragFrame;
1132 m_editingPoint.value = value; 1132 m_editingPoint.value = value;
1133 break; 1133 break;
1134 } 1134 }
1135 } 1135 }
1136 m_editingCommand->addPoint(m_editingPoint); 1136 m_editingCommand->addPoint(m_editingPoint);
1137 std::cerr << "added new point(" << m_editingPoint.frame << "," << m_editingPoint.duration << ")" << std::endl; 1137 std::cerr << "added new point(" << m_editingPoint.frame << "," << m_editingPoint.duration << ")" << std::endl;
1138 1138
1139 } 1139 }
1146 1146
1147 if (!m_model || !m_editing) return; 1147 if (!m_model || !m_editing) return;
1148 1148
1149 if (m_editingCommand) { 1149 if (m_editingCommand) {
1150 1150
1151 QString newName = m_editingCommand->getName(); 1151 QString newName = m_editingCommand->getName();
1152 1152
1153 if (m_editingPoint.frame != m_originalPoint.frame) { 1153 if (m_editingPoint.frame != m_originalPoint.frame) {
1154 if (m_editingPoint.value != m_originalPoint.value) { 1154 if (m_editingPoint.value != m_originalPoint.value) {
1155 newName = tr("Edit Point"); 1155 newName = tr("Edit Point");
1156 } else {
1157 newName = tr("Relocate Point");
1158 }
1156 } else { 1159 } else {
1157 newName = tr("Relocate Point"); 1160 newName = tr("Change Point Value");
1158 } 1161 }
1159 } else { 1162
1160 newName = tr("Change Point Value"); 1163 m_editingCommand->setName(newName);
1161 } 1164 finish(m_editingCommand);
1162
1163 m_editingCommand->setName(newName);
1164 finish(m_editingCommand);
1165 } 1165 }
1166 1166
1167 m_editingCommand = 0; 1167 m_editingCommand = 0;
1168 m_editing = false; 1168 m_editing = false;
1169 } 1169 }
1180 // 1180 //
1181 // m_dragPointX = v->getXForFrame(m_editingPoint.frame); 1181 // m_dragPointX = v->getXForFrame(m_editingPoint.frame);
1182 // m_dragPointY = getYForValue(v, m_editingPoint.value); 1182 // m_dragPointY = getYForValue(v, m_editingPoint.value);
1183 1183
1184 if (m_editingCommand) { 1184 if (m_editingCommand) {
1185 finish(m_editingCommand); 1185 finish(m_editingCommand);
1186 m_editingCommand = 0; 1186 m_editingCommand = 0;
1187 } 1187 }
1188 1188
1189 m_editing = true; 1189 m_editing = true;
1190 m_dragStartX = e->x(); 1190 m_dragStartX = e->x();
1191 m_dragStartY = e->y(); 1191 m_dragStartY = e->y();
1270 if (!m_intelligentActions || 1270 if (!m_intelligentActions ||
1271 m_model->getPoints(frame).empty() && duration > 0) 1271 m_model->getPoints(frame).empty() && duration > 0)
1272 { 1272 {
1273 FlexiNote newNote(frame, value, duration, 100, "new note"); 1273 FlexiNote newNote(frame, value, duration, 100, "new note");
1274 FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand 1274 FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand
1275 (m_model, tr("Add Point")); 1275 (m_model, tr("Add Point"));
1276 command->addPoint(newNote); 1276 command->addPoint(newNote);
1277 finish(command); 1277 finish(command);
1278 } 1278 }
1279 } 1279 }
1280 1280
1293 std::cerr << model->getTypeName() << std::endl; 1293 std::cerr << model->getTypeName() << std::endl;
1294 1294
1295 SparseModel<TimeValuePoint>::PointList dataPoints = model->getPoints(note.frame, note.frame + note.duration); 1295 SparseModel<TimeValuePoint>::PointList dataPoints = model->getPoints(note.frame, note.frame + note.duration);
1296 if (dataPoints.empty()) return; 1296 if (dataPoints.empty()) return;
1297 1297
1298 // std::cerr << "frame " << note.frame << ": " << dataPoints.size() << " candidate points" << std::endl; 1298 // std::cerr << "frame " << note.frame << ": " << dataPoints.size() << " candidate points" << std::endl;
1299 1299
1300 std::vector<float> pitchValues; 1300 std::vector<float> pitchValues;
1301 1301
1302 for (SparseModel<TimeValuePoint>::PointList::const_iterator i = dataPoints.begin(); 1302 for (SparseModel<TimeValuePoint>::PointList::const_iterator i = dataPoints.begin();
1303 i != dataPoints.end(); ++i) { 1303 i != dataPoints.end(); ++i) {
1304 pitchValues.push_back((*i).value); 1304 pitchValues.push_back((*i).value);
1305 } 1305 }
1306 sort(pitchValues.begin(), pitchValues.end()); 1306 sort(pitchValues.begin(), pitchValues.end());
1307 size_t size = pitchValues.size(); 1307 size_t size = pitchValues.size();
1308 double median; 1308 double median;
1309 1309
1420 FlexiNoteLayer::moveSelection(Selection s, size_t newStartFrame) 1420 FlexiNoteLayer::moveSelection(Selection s, size_t newStartFrame)
1421 { 1421 {
1422 if (!m_model) return; 1422 if (!m_model) return;
1423 1423
1424 FlexiNoteModel::EditCommand *command = 1424 FlexiNoteModel::EditCommand *command =
1425 new FlexiNoteModel::EditCommand(m_model, tr("Drag Selection")); 1425 new FlexiNoteModel::EditCommand(m_model, tr("Drag Selection"));
1426 1426
1427 FlexiNoteModel::PointList points = 1427 FlexiNoteModel::PointList points =
1428 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 1428 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
1429 1429
1430 for (FlexiNoteModel::PointList::iterator i = points.begin(); 1430 for (FlexiNoteModel::PointList::iterator i = points.begin();
1431 i != points.end(); ++i) { 1431 i != points.end(); ++i) {
1432 1432
1433 if (s.contains(i->frame)) { 1433 if (s.contains(i->frame)) {
1434 FlexiNoteModel::Point newPoint(*i); 1434 FlexiNoteModel::Point newPoint(*i);
1435 newPoint.frame = i->frame + newStartFrame - s.getStartFrame(); 1435 newPoint.frame = i->frame + newStartFrame - s.getStartFrame();
1436 command->deletePoint(*i); 1436 command->deletePoint(*i);
1437 command->addPoint(newPoint); 1437 command->addPoint(newPoint);
1438 } 1438 }
1439 } 1439 }
1440 1440
1441 finish(command); 1441 finish(command);
1442 } 1442 }
1443 1443
1445 FlexiNoteLayer::resizeSelection(Selection s, Selection newSize) 1445 FlexiNoteLayer::resizeSelection(Selection s, Selection newSize)
1446 { 1446 {
1447 if (!m_model) return; 1447 if (!m_model) return;
1448 1448
1449 FlexiNoteModel::EditCommand *command = 1449 FlexiNoteModel::EditCommand *command =
1450 new FlexiNoteModel::EditCommand(m_model, tr("Resize Selection")); 1450 new FlexiNoteModel::EditCommand(m_model, tr("Resize Selection"));
1451 1451
1452 FlexiNoteModel::PointList points = 1452 FlexiNoteModel::PointList points =
1453 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 1453 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
1454 1454
1455 double ratio = 1455 double ratio =
1456 double(newSize.getEndFrame() - newSize.getStartFrame()) / 1456 double(newSize.getEndFrame() - newSize.getStartFrame()) /
1457 double(s.getEndFrame() - s.getStartFrame()); 1457 double(s.getEndFrame() - s.getStartFrame());
1458 1458
1459 for (FlexiNoteModel::PointList::iterator i = points.begin(); 1459 for (FlexiNoteModel::PointList::iterator i = points.begin();
1460 i != points.end(); ++i) { 1460 i != points.end(); ++i) {
1461 1461
1462 if (s.contains(i->frame)) { 1462 if (s.contains(i->frame)) {
1463 1463
1464 double targetStart = i->frame; 1464 double targetStart = i->frame;
1465 targetStart = newSize.getStartFrame() + 1465 targetStart = newSize.getStartFrame() +
1466 double(targetStart - s.getStartFrame()) * ratio; 1466 double(targetStart - s.getStartFrame()) * ratio;
1467 1467
1468 double targetEnd = i->frame + i->duration; 1468 double targetEnd = i->frame + i->duration;
1469 targetEnd = newSize.getStartFrame() + 1469 targetEnd = newSize.getStartFrame() +
1470 double(targetEnd - s.getStartFrame()) * ratio; 1470 double(targetEnd - s.getStartFrame()) * ratio;
1471 1471
1472 FlexiNoteModel::Point newPoint(*i); 1472 FlexiNoteModel::Point newPoint(*i);
1473 newPoint.frame = lrint(targetStart); 1473 newPoint.frame = lrint(targetStart);
1474 newPoint.duration = lrint(targetEnd - targetStart); 1474 newPoint.duration = lrint(targetEnd - targetStart);
1475 command->deletePoint(*i); 1475 command->deletePoint(*i);
1476 command->addPoint(newPoint); 1476 command->addPoint(newPoint);
1477 } 1477 }
1478 } 1478 }
1479 1479
1480 finish(command); 1480 finish(command);
1481 } 1481 }
1482 1482
1484 FlexiNoteLayer::deleteSelection(Selection s) 1484 FlexiNoteLayer::deleteSelection(Selection s)
1485 { 1485 {
1486 if (!m_model) return; 1486 if (!m_model) return;
1487 1487
1488 FlexiNoteModel::EditCommand *command = 1488 FlexiNoteModel::EditCommand *command =
1489 new FlexiNoteModel::EditCommand(m_model, tr("Delete Selected Points")); 1489 new FlexiNoteModel::EditCommand(m_model, tr("Delete Selected Points"));
1490 1490
1491 FlexiNoteModel::PointList points = 1491 FlexiNoteModel::PointList points =
1492 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 1492 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
1493 1493
1494 for (FlexiNoteModel::PointList::iterator i = points.begin(); 1494 for (FlexiNoteModel::PointList::iterator i = points.begin();
1495 i != points.end(); ++i) { 1495 i != points.end(); ++i) {
1496 1496
1497 if (s.contains(i->frame)) { 1497 if (s.contains(i->frame)) {
1498 command->deletePoint(*i); 1498 command->deletePoint(*i);
1499 } 1499 }
1500 } 1500 }
1506 FlexiNoteLayer::copy(View *v, Selection s, Clipboard &to) 1506 FlexiNoteLayer::copy(View *v, Selection s, Clipboard &to)
1507 { 1507 {
1508 if (!m_model) return; 1508 if (!m_model) return;
1509 1509
1510 FlexiNoteModel::PointList points = 1510 FlexiNoteModel::PointList points =
1511 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 1511 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
1512 1512
1513 for (FlexiNoteModel::PointList::iterator i = points.begin(); 1513 for (FlexiNoteModel::PointList::iterator i = points.begin();
1514 i != points.end(); ++i) { 1514 i != points.end(); ++i) {
1515 if (s.contains(i->frame)) { 1515 if (s.contains(i->frame)) {
1516 Clipboard::Point point(i->frame, i->value, i->duration, i->level, i->label); 1516 Clipboard::Point point(i->frame, i->value, i->duration, i->level, i->label);
1517 point.setReferenceFrame(alignToReference(v, i->frame)); 1517 point.setReferenceFrame(alignToReference(v, i->frame));
1518 to.addPoint(point); 1518 to.addPoint(point);
1519 } 1519 }
1520 } 1520 }
1545 realign = true; 1545 realign = true;
1546 } 1546 }
1547 } 1547 }
1548 1548
1549 FlexiNoteModel::EditCommand *command = 1549 FlexiNoteModel::EditCommand *command =
1550 new FlexiNoteModel::EditCommand(m_model, tr("Paste")); 1550 new FlexiNoteModel::EditCommand(m_model, tr("Paste"));
1551 1551
1552 for (Clipboard::PointList::const_iterator i = points.begin(); 1552 for (Clipboard::PointList::const_iterator i = points.begin();
1553 i != points.end(); ++i) { 1553 i != points.end(); ++i) {
1554 1554
1555 if (!i->haveFrame()) continue; 1555 if (!i->haveFrame()) continue;
1641 (QString(darkbg ? "White" : "Black")); 1641 (QString(darkbg ? "White" : "Black"));
1642 } 1642 }
1643 1643
1644 void 1644 void
1645 FlexiNoteLayer::toXml(QTextStream &stream, 1645 FlexiNoteLayer::toXml(QTextStream &stream,
1646 QString indent, QString extraAttributes) const 1646 QString indent, QString extraAttributes) const
1647 { 1647 {
1648 SingleColourLayer::toXml(stream, indent, extraAttributes + 1648 SingleColourLayer::toXml(stream, indent, extraAttributes +
1649 QString(" verticalScale=\"%1\" scaleMinimum=\"%2\" scaleMaximum=\"%3\" ") 1649 QString(" verticalScale=\"%1\" scaleMinimum=\"%2\" scaleMaximum=\"%3\" ")
1650 .arg(m_verticalScale) 1650 .arg(m_verticalScale)
1651 .arg(m_scaleMinimum) 1651 .arg(m_scaleMinimum)
1657 { 1657 {
1658 SingleColourLayer::setProperties(attributes); 1658 SingleColourLayer::setProperties(attributes);
1659 1659
1660 bool ok, alsoOk; 1660 bool ok, alsoOk;
1661 VerticalScale scale = (VerticalScale) 1661 VerticalScale scale = (VerticalScale)
1662 attributes.value("verticalScale").toInt(&ok); 1662 attributes.value("verticalScale").toInt(&ok);
1663 if (ok) setVerticalScale(scale); 1663 if (ok) setVerticalScale(scale);
1664 1664
1665 float min = attributes.value("scaleMinimum").toFloat(&ok); 1665 float min = attributes.value("scaleMinimum").toFloat(&ok);
1666 float max = attributes.value("scaleMaximum").toFloat(&alsoOk); 1666 float max = attributes.value("scaleMaximum").toFloat(&alsoOk);
1667 // if (ok && alsoOk && min != max) setDisplayExtents(min, max); 1667 // if (ok && alsoOk && min != max) setDisplayExtents(min, max);
1673 float minf = std::numeric_limits<float>::max(); 1673 float minf = std::numeric_limits<float>::max();
1674 float maxf = 0; 1674 float maxf = 0;
1675 bool hasNotes = 0; 1675 bool hasNotes = 0;
1676 for (FlexiNoteModel::PointList::const_iterator i = m_model->getPoints().begin(); 1676 for (FlexiNoteModel::PointList::const_iterator i = m_model->getPoints().begin();
1677 i != m_model->getPoints().end(); ++i) { 1677 i != m_model->getPoints().end(); ++i) {
1678 hasNotes = 1; 1678 hasNotes = 1;
1679 FlexiNote note = *i; 1679 FlexiNote note = *i;
1680 if (note.value < minf) minf = note.value; 1680 if (note.value < minf) minf = note.value;
1681 if (note.value > maxf) maxf = note.value; 1681 if (note.value > maxf) maxf = note.value;
1682 } 1682 }
1683 1683
1684 std::cerr << "min frequency:" << minf << ", max frequency: " << maxf << std::endl; 1684 std::cerr << "min frequency:" << minf << ", max frequency: " << maxf << std::endl;
1685 1685
1686 if (hasNotes) { 1686 if (hasNotes) {