Mercurial > hg > svgui
comparison layer/NoteLayer.cpp @ 1266:a34a2a25907c
Untabify
author | Chris Cannam |
---|---|
date | Thu, 01 Mar 2018 18:02:22 +0000 |
parents | ee01a4062747 |
children | 1d7921b1852f |
comparison
equal
deleted
inserted
replaced
1265:6e724c81f18f | 1266:a34a2a25907c |
---|---|
59 m_editingCommand(0), | 59 m_editingCommand(0), |
60 m_verticalScale(AutoAlignScale), | 60 m_verticalScale(AutoAlignScale), |
61 m_scaleMinimum(0), | 61 m_scaleMinimum(0), |
62 m_scaleMaximum(0) | 62 m_scaleMaximum(0) |
63 { | 63 { |
64 SVDEBUG << "constructed NoteLayer" << endl; | 64 SVDEBUG << "constructed NoteLayer" << endl; |
65 } | 65 } |
66 | 66 |
67 void | 67 void |
68 NoteLayer::setModel(NoteModel *model) | 68 NoteLayer::setModel(NoteModel *model) |
69 { | 69 { |
70 if (m_model == model) return; | 70 if (m_model == model) return; |
71 m_model = model; | 71 m_model = model; |
72 | 72 |
73 connectSignals(m_model); | 73 connectSignals(m_model); |
74 | 74 |
126 int *min, int *max, int *deflt) const | 126 int *min, int *max, int *deflt) const |
127 { | 127 { |
128 int val = 0; | 128 int val = 0; |
129 | 129 |
130 if (name == "Vertical Scale") { | 130 if (name == "Vertical Scale") { |
131 | 131 |
132 if (min) *min = 0; | 132 if (min) *min = 0; |
133 if (max) *max = 3; | 133 if (max) *max = 3; |
134 if (deflt) *deflt = int(AutoAlignScale); | 134 if (deflt) *deflt = int(AutoAlignScale); |
135 | 135 |
136 val = int(m_verticalScale); | 136 val = int(m_verticalScale); |
137 | 137 |
138 } else if (name == "Scale Units") { | 138 } else if (name == "Scale Units") { |
139 | 139 |
140 if (deflt) *deflt = 0; | 140 if (deflt) *deflt = 0; |
141 if (m_model) { | 141 if (m_model) { |
143 (getScaleUnits()); | 143 (getScaleUnits()); |
144 } | 144 } |
145 | 145 |
146 } else { | 146 } else { |
147 | 147 |
148 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt); | 148 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt); |
149 } | 149 } |
150 | 150 |
151 return val; | 151 return val; |
152 } | 152 } |
153 | 153 |
154 QString | 154 QString |
155 NoteLayer::getPropertyValueLabel(const PropertyName &name, | 155 NoteLayer::getPropertyValueLabel(const PropertyName &name, |
156 int value) const | 156 int value) const |
157 { | 157 { |
158 if (name == "Vertical Scale") { | 158 if (name == "Vertical Scale") { |
159 switch (value) { | 159 switch (value) { |
160 default: | 160 default: |
161 case 0: return tr("Auto-Align"); | 161 case 0: return tr("Auto-Align"); |
162 case 1: return tr("Linear"); | 162 case 1: return tr("Linear"); |
163 case 2: return tr("Log"); | 163 case 2: return tr("Log"); |
164 case 3: return tr("MIDI Notes"); | 164 case 3: return tr("MIDI Notes"); |
165 } | 165 } |
166 } | 166 } |
167 return SingleColourLayer::getPropertyValueLabel(name, value); | 167 return SingleColourLayer::getPropertyValueLabel(name, value); |
168 } | 168 } |
169 | 169 |
170 void | 170 void |
171 NoteLayer::setProperty(const PropertyName &name, int value) | 171 NoteLayer::setProperty(const PropertyName &name, int value) |
172 { | 172 { |
173 if (name == "Vertical Scale") { | 173 if (name == "Vertical Scale") { |
174 setVerticalScale(VerticalScale(value)); | 174 setVerticalScale(VerticalScale(value)); |
175 } else if (name == "Scale Units") { | 175 } else if (name == "Scale Units") { |
176 if (m_model) { | 176 if (m_model) { |
177 m_model->setScaleUnits | 177 m_model->setScaleUnits |
178 (UnitDatabase::getInstance()->getUnitById(value)); | 178 (UnitDatabase::getInstance()->getUnitById(value)); |
179 emit modelChanged(); | 179 emit modelChanged(); |
395 if (!m_model) return NoteModel::PointList(); | 395 if (!m_model) return NoteModel::PointList(); |
396 | 396 |
397 sv_frame_t frame = v->getFrameForX(x); | 397 sv_frame_t frame = v->getFrameForX(x); |
398 | 398 |
399 NoteModel::PointList onPoints = | 399 NoteModel::PointList onPoints = |
400 m_model->getPoints(frame); | 400 m_model->getPoints(frame); |
401 | 401 |
402 if (!onPoints.empty()) { | 402 if (!onPoints.empty()) { |
403 return onPoints; | 403 return onPoints; |
404 } | 404 } |
405 | 405 |
406 NoteModel::PointList prevPoints = | 406 NoteModel::PointList prevPoints = |
407 m_model->getPreviousPoints(frame); | 407 m_model->getPreviousPoints(frame); |
408 NoteModel::PointList nextPoints = | 408 NoteModel::PointList nextPoints = |
409 m_model->getNextPoints(frame); | 409 m_model->getNextPoints(frame); |
410 | 410 |
411 NoteModel::PointList usePoints = prevPoints; | 411 NoteModel::PointList usePoints = prevPoints; |
412 | 412 |
413 if (prevPoints.empty()) { | 413 if (prevPoints.empty()) { |
414 usePoints = nextPoints; | 414 usePoints = nextPoints; |
415 } else if (int(prevPoints.begin()->frame) < v->getStartFrame() && | 415 } else if (int(prevPoints.begin()->frame) < v->getStartFrame() && |
416 !(nextPoints.begin()->frame > v->getEndFrame())) { | 416 !(nextPoints.begin()->frame > v->getEndFrame())) { |
417 usePoints = nextPoints; | 417 usePoints = nextPoints; |
418 } else if (int(nextPoints.begin()->frame) - frame < | 418 } else if (int(nextPoints.begin()->frame) - frame < |
419 frame - int(prevPoints.begin()->frame)) { | 419 frame - int(prevPoints.begin()->frame)) { |
420 usePoints = nextPoints; | 420 usePoints = nextPoints; |
421 } | 421 } |
422 | 422 |
423 if (!usePoints.empty()) { | 423 if (!usePoints.empty()) { |
424 int fuzz = 2; | 424 int fuzz = 2; |
425 int px = v->getXForFrame(usePoints.begin()->frame); | 425 int px = v->getXForFrame(usePoints.begin()->frame); |
426 if ((px > x && px - x > fuzz) || | 426 if ((px > x && px - x > fuzz) || |
427 (px < x && x - px > fuzz + 1)) { | 427 (px < x && x - px > fuzz + 1)) { |
428 usePoints.clear(); | 428 usePoints.clear(); |
429 } | 429 } |
430 } | 430 } |
431 | 431 |
432 return usePoints; | 432 return usePoints; |
433 } | 433 } |
434 | 434 |
468 if (!m_model || !m_model->getSampleRate()) return ""; | 468 if (!m_model || !m_model->getSampleRate()) return ""; |
469 | 469 |
470 NoteModel::PointList points = getLocalPoints(v, x); | 470 NoteModel::PointList points = getLocalPoints(v, x); |
471 | 471 |
472 if (points.empty()) { | 472 if (points.empty()) { |
473 if (!m_model->isReady()) { | 473 if (!m_model->isReady()) { |
474 return tr("In progress"); | 474 return tr("In progress"); |
475 } else { | 475 } else { |
476 return tr("No local points"); | 476 return tr("No local points"); |
477 } | 477 } |
478 } | 478 } |
479 | 479 |
480 Note note(0); | 480 Note note(0); |
481 NoteModel::PointList::iterator i; | 481 NoteModel::PointList::iterator i; |
482 | 482 |
483 for (i = points.begin(); i != points.end(); ++i) { | 483 for (i = points.begin(); i != points.end(); ++i) { |
484 | 484 |
485 int y = getYForValue(v, i->value); | 485 int y = getYForValue(v, i->value); |
486 int h = 3; | 486 int h = 3; |
487 | 487 |
488 if (m_model->getValueQuantization() != 0.0) { | 488 if (m_model->getValueQuantization() != 0.0) { |
489 h = y - getYForValue(v, i->value + m_model->getValueQuantization()); | 489 h = y - getYForValue(v, i->value + m_model->getValueQuantization()); |
490 if (h < 3) h = 3; | 490 if (h < 3) h = 3; |
491 } | 491 } |
492 | 492 |
493 if (pos.y() >= y - h && pos.y() <= y) { | 493 if (pos.y() >= y - h && pos.y() <= y) { |
494 note = *i; | 494 note = *i; |
495 break; | 495 break; |
496 } | 496 } |
497 } | 497 } |
498 | 498 |
499 if (i == points.end()) return tr("No local points"); | 499 if (i == points.end()) return tr("No local points"); |
500 | 500 |
501 RealTime rt = RealTime::frame2RealTime(note.frame, | 501 RealTime rt = RealTime::frame2RealTime(note.frame, |
502 m_model->getSampleRate()); | 502 m_model->getSampleRate()); |
503 RealTime rd = RealTime::frame2RealTime(note.duration, | 503 RealTime rd = RealTime::frame2RealTime(note.duration, |
504 m_model->getSampleRate()); | 504 m_model->getSampleRate()); |
505 | 505 |
506 QString pitchText; | 506 QString pitchText; |
507 | 507 |
508 if (shouldConvertMIDIToHz()) { | 508 if (shouldConvertMIDIToHz()) { |
509 | 509 |
528 } | 528 } |
529 | 529 |
530 QString text; | 530 QString text; |
531 | 531 |
532 if (note.label == "") { | 532 if (note.label == "") { |
533 text = QString(tr("Time:\t%1\nPitch:\t%2\nDuration:\t%3\nNo label")) | 533 text = QString(tr("Time:\t%1\nPitch:\t%2\nDuration:\t%3\nNo label")) |
534 .arg(rt.toText(true).c_str()) | 534 .arg(rt.toText(true).c_str()) |
535 .arg(pitchText) | 535 .arg(pitchText) |
536 .arg(rd.toText(true).c_str()); | 536 .arg(rd.toText(true).c_str()); |
537 } else { | 537 } else { |
538 text = QString(tr("Time:\t%1\nPitch:\t%2\nDuration:\t%3\nLabel:\t%4")) | 538 text = QString(tr("Time:\t%1\nPitch:\t%2\nDuration:\t%3\nLabel:\t%4")) |
539 .arg(rt.toText(true).c_str()) | 539 .arg(rt.toText(true).c_str()) |
540 .arg(pitchText) | 540 .arg(pitchText) |
541 .arg(rd.toText(true).c_str()) | 541 .arg(rd.toText(true).c_str()) |
542 .arg(note.label); | 542 .arg(note.label); |
543 } | 543 } |
544 | 544 |
545 pos = QPoint(v->getXForFrame(note.frame), | 545 pos = QPoint(v->getXForFrame(note.frame), |
546 getYForValue(v, note.value)); | 546 getYForValue(v, note.value)); |
547 return text; | 547 return text; |
548 } | 548 } |
549 | 549 |
550 bool | 550 bool |
551 NoteLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, | 551 NoteLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, |
552 int &resolution, | 552 int &resolution, |
553 SnapType snap) const | 553 SnapType snap) const |
554 { | 554 { |
555 if (!m_model) { | 555 if (!m_model) { |
556 return Layer::snapToFeatureFrame(v, frame, resolution, snap); | 556 return Layer::snapToFeatureFrame(v, frame, resolution, snap); |
557 } | 557 } |
558 | 558 |
559 resolution = m_model->getResolution(); | 559 resolution = m_model->getResolution(); |
560 NoteModel::PointList points; | 560 NoteModel::PointList points; |
561 | 561 |
562 if (snap == SnapNeighbouring) { | 562 if (snap == SnapNeighbouring) { |
563 | 563 |
564 points = getLocalPoints(v, v->getXForFrame(frame)); | 564 points = getLocalPoints(v, v->getXForFrame(frame)); |
565 if (points.empty()) return false; | 565 if (points.empty()) return false; |
566 frame = points.begin()->frame; | 566 frame = points.begin()->frame; |
567 return true; | 567 return true; |
568 } | 568 } |
569 | 569 |
570 points = m_model->getPoints(frame, frame); | 570 points = m_model->getPoints(frame, frame); |
571 sv_frame_t snapped = frame; | 571 sv_frame_t snapped = frame; |
572 bool found = false; | 572 bool found = false; |
573 | 573 |
574 for (NoteModel::PointList::const_iterator i = points.begin(); | 574 for (NoteModel::PointList::const_iterator i = points.begin(); |
575 i != points.end(); ++i) { | 575 i != points.end(); ++i) { |
576 | 576 |
577 if (snap == SnapRight) { | 577 if (snap == SnapRight) { |
578 | 578 |
579 if (i->frame > frame) { | 579 if (i->frame > frame) { |
580 snapped = i->frame; | 580 snapped = i->frame; |
581 found = true; | 581 found = true; |
582 break; | 582 break; |
583 } | 583 } |
584 | 584 |
585 } else if (snap == SnapLeft) { | 585 } else if (snap == SnapLeft) { |
586 | 586 |
587 if (i->frame <= frame) { | 587 if (i->frame <= frame) { |
588 snapped = i->frame; | 588 snapped = i->frame; |
589 found = true; // don't break, as the next may be better | 589 found = true; // don't break, as the next may be better |
590 } else { | 590 } else { |
591 break; | 591 break; |
592 } | 592 } |
593 | 593 |
594 } else { // nearest | 594 } else { // nearest |
595 | 595 |
596 NoteModel::PointList::const_iterator j = i; | 596 NoteModel::PointList::const_iterator j = i; |
597 ++j; | 597 ++j; |
598 | 598 |
599 if (j == points.end()) { | 599 if (j == points.end()) { |
600 | 600 |
601 snapped = i->frame; | 601 snapped = i->frame; |
602 found = true; | 602 found = true; |
603 break; | 603 break; |
604 | 604 |
605 } else if (j->frame >= frame) { | 605 } else if (j->frame >= frame) { |
606 | 606 |
607 if (j->frame - frame < frame - i->frame) { | 607 if (j->frame - frame < frame - i->frame) { |
608 snapped = j->frame; | 608 snapped = j->frame; |
609 } else { | 609 } else { |
610 snapped = i->frame; | 610 snapped = i->frame; |
611 } | 611 } |
612 found = true; | 612 found = true; |
613 break; | 613 break; |
614 } | 614 } |
615 } | 615 } |
616 } | 616 } |
617 | 617 |
618 frame = snapped; | 618 frame = snapped; |
619 return found; | 619 return found; |
620 } | 620 } |
762 | 762 |
763 QColor brushColour(getBaseQColor()); | 763 QColor brushColour(getBaseQColor()); |
764 brushColour.setAlpha(80); | 764 brushColour.setAlpha(80); |
765 | 765 |
766 // SVDEBUG << "NoteLayer::paint: resolution is " | 766 // SVDEBUG << "NoteLayer::paint: resolution is " |
767 // << m_model->getResolution() << " frames" << endl; | 767 // << m_model->getResolution() << " frames" << endl; |
768 | 768 |
769 double min = m_model->getValueMinimum(); | 769 double min = m_model->getValueMinimum(); |
770 double max = m_model->getValueMaximum(); | 770 double max = m_model->getValueMaximum(); |
771 if (max == min) max = min + 1.0; | 771 if (max == min) max = min + 1.0; |
772 | 772 |
781 | 781 |
782 paint.save(); | 782 paint.save(); |
783 paint.setRenderHint(QPainter::Antialiasing, false); | 783 paint.setRenderHint(QPainter::Antialiasing, false); |
784 | 784 |
785 for (NoteModel::PointList::const_iterator i = points.begin(); | 785 for (NoteModel::PointList::const_iterator i = points.begin(); |
786 i != points.end(); ++i) { | 786 i != points.end(); ++i) { |
787 | 787 |
788 const NoteModel::Point &p(*i); | 788 const NoteModel::Point &p(*i); |
789 | 789 |
790 int x = v->getXForFrame(p.frame); | 790 int x = v->getXForFrame(p.frame); |
791 int y = getYForValue(v, p.value); | 791 int y = getYForValue(v, p.value); |
792 int w = v->getXForFrame(p.frame + p.duration) - x; | 792 int w = v->getXForFrame(p.frame + p.duration) - x; |
793 int h = 3; | 793 int h = 3; |
794 | 794 |
795 if (m_model->getValueQuantization() != 0.0) { | 795 if (m_model->getValueQuantization() != 0.0) { |
796 h = y - getYForValue(v, p.value + m_model->getValueQuantization()); | 796 h = y - getYForValue(v, p.value + m_model->getValueQuantization()); |
797 if (h < 3) h = 3; | 797 if (h < 3) h = 3; |
798 } | 798 } |
799 | 799 |
800 if (w < 1) w = 1; | 800 if (w < 1) w = 1; |
801 paint.setPen(getBaseQColor()); | 801 paint.setPen(getBaseQColor()); |
802 paint.setBrush(brushColour); | 802 paint.setBrush(brushColour); |
803 | 803 |
804 if (shouldIlluminate && | 804 if (shouldIlluminate && |
805 // "illuminatePoint == p" | 805 // "illuminatePoint == p" |
806 !NoteModel::Point::Comparator()(illuminatePoint, p) && | 806 !NoteModel::Point::Comparator()(illuminatePoint, p) && |
807 !NoteModel::Point::Comparator()(p, illuminatePoint)) { | 807 !NoteModel::Point::Comparator()(p, illuminatePoint)) { |
808 | 808 |
809 paint.setPen(v->getForeground()); | 809 paint.setPen(v->getForeground()); |
820 (p.frame, m_model->getSampleRate()).toText(true).c_str(); | 820 (p.frame, m_model->getSampleRate()).toText(true).c_str(); |
821 PaintAssistant::drawVisibleText(v, paint, | 821 PaintAssistant::drawVisibleText(v, paint, |
822 x, | 822 x, |
823 y - h/2 - paint.fontMetrics().descent() - 2, | 823 y - h/2 - paint.fontMetrics().descent() - 2, |
824 hlabel, PaintAssistant::OutlinedText); | 824 hlabel, PaintAssistant::OutlinedText); |
825 } | 825 } |
826 | 826 |
827 paint.drawRect(x, y - h/2, w, h); | 827 paint.drawRect(x, y - h/2, w, h); |
828 } | 828 } |
829 | 829 |
830 paint.restore(); | 830 paint.restore(); |
831 } | 831 } |
832 | 832 |
898 m_editingPoint = NoteModel::Point(frame, float(value), 0, 0.8f, tr("New Point")); | 898 m_editingPoint = NoteModel::Point(frame, float(value), 0, 0.8f, tr("New Point")); |
899 m_originalPoint = m_editingPoint; | 899 m_originalPoint = m_editingPoint; |
900 | 900 |
901 if (m_editingCommand) finish(m_editingCommand); | 901 if (m_editingCommand) finish(m_editingCommand); |
902 m_editingCommand = new NoteModel::EditCommand(m_model, | 902 m_editingCommand = new NoteModel::EditCommand(m_model, |
903 tr("Draw Point")); | 903 tr("Draw Point")); |
904 m_editingCommand->addPoint(m_editingPoint); | 904 m_editingCommand->addPoint(m_editingPoint); |
905 | 905 |
906 m_editing = true; | 906 m_editing = true; |
907 } | 907 } |
908 | 908 |
951 if (!m_model) return; | 951 if (!m_model) return; |
952 | 952 |
953 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; | 953 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; |
954 | 954 |
955 if (m_editingCommand) { | 955 if (m_editingCommand) { |
956 finish(m_editingCommand); | 956 finish(m_editingCommand); |
957 m_editingCommand = 0; | 957 m_editingCommand = 0; |
958 } | 958 } |
959 | 959 |
960 m_editing = true; | 960 m_editing = true; |
961 } | 961 } |
962 | 962 |
997 | 997 |
998 m_dragPointX = v->getXForFrame(m_editingPoint.frame); | 998 m_dragPointX = v->getXForFrame(m_editingPoint.frame); |
999 m_dragPointY = getYForValue(v, m_editingPoint.value); | 999 m_dragPointY = getYForValue(v, m_editingPoint.value); |
1000 | 1000 |
1001 if (m_editingCommand) { | 1001 if (m_editingCommand) { |
1002 finish(m_editingCommand); | 1002 finish(m_editingCommand); |
1003 m_editingCommand = 0; | 1003 m_editingCommand = 0; |
1004 } | 1004 } |
1005 | 1005 |
1006 m_editing = true; | 1006 m_editing = true; |
1007 m_dragStartX = e->x(); | 1007 m_dragStartX = e->x(); |
1008 m_dragStartY = e->y(); | 1008 m_dragStartY = e->y(); |
1025 frame = frame / m_model->getResolution() * m_model->getResolution(); | 1025 frame = frame / m_model->getResolution() * m_model->getResolution(); |
1026 | 1026 |
1027 double value = getValueForY(v, newy); | 1027 double value = getValueForY(v, newy); |
1028 | 1028 |
1029 if (!m_editingCommand) { | 1029 if (!m_editingCommand) { |
1030 m_editingCommand = new NoteModel::EditCommand(m_model, | 1030 m_editingCommand = new NoteModel::EditCommand(m_model, |
1031 tr("Drag Point")); | 1031 tr("Drag Point")); |
1032 } | 1032 } |
1033 | 1033 |
1034 m_editingCommand->deletePoint(m_editingPoint); | 1034 m_editingCommand->deletePoint(m_editingPoint); |
1035 m_editingPoint.frame = frame; | 1035 m_editingPoint.frame = frame; |
1036 m_editingPoint.value = float(value); | 1036 m_editingPoint.value = float(value); |
1043 // SVDEBUG << "NoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl; | 1043 // SVDEBUG << "NoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl; |
1044 if (!m_model || !m_editing) return; | 1044 if (!m_model || !m_editing) return; |
1045 | 1045 |
1046 if (m_editingCommand) { | 1046 if (m_editingCommand) { |
1047 | 1047 |
1048 QString newName = m_editingCommand->getName(); | 1048 QString newName = m_editingCommand->getName(); |
1049 | 1049 |
1050 if (m_editingPoint.frame != m_originalPoint.frame) { | 1050 if (m_editingPoint.frame != m_originalPoint.frame) { |
1051 if (m_editingPoint.value != m_originalPoint.value) { | 1051 if (m_editingPoint.value != m_originalPoint.value) { |
1052 newName = tr("Edit Point"); | 1052 newName = tr("Edit Point"); |
1053 } else { | 1053 } else { |
1054 newName = tr("Relocate Point"); | 1054 newName = tr("Relocate Point"); |
1055 } | 1055 } |
1056 } else { | 1056 } else { |
1057 newName = tr("Change Point Value"); | 1057 newName = tr("Change Point Value"); |
1058 } | 1058 } |
1059 | 1059 |
1060 m_editingCommand->setName(newName); | 1060 m_editingCommand->setName(newName); |
1061 finish(m_editingCommand); | 1061 finish(m_editingCommand); |
1062 } | 1062 } |
1063 | 1063 |
1064 m_editingCommand = 0; | 1064 m_editingCommand = 0; |
1065 m_editing = false; | 1065 m_editing = false; |
1066 } | 1066 } |
1111 NoteLayer::moveSelection(Selection s, sv_frame_t newStartFrame) | 1111 NoteLayer::moveSelection(Selection s, sv_frame_t newStartFrame) |
1112 { | 1112 { |
1113 if (!m_model) return; | 1113 if (!m_model) return; |
1114 | 1114 |
1115 NoteModel::EditCommand *command = | 1115 NoteModel::EditCommand *command = |
1116 new NoteModel::EditCommand(m_model, tr("Drag Selection")); | 1116 new NoteModel::EditCommand(m_model, tr("Drag Selection")); |
1117 | 1117 |
1118 NoteModel::PointList points = | 1118 NoteModel::PointList points = |
1119 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); | 1119 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); |
1120 | 1120 |
1121 for (NoteModel::PointList::iterator i = points.begin(); | 1121 for (NoteModel::PointList::iterator i = points.begin(); |
1122 i != points.end(); ++i) { | 1122 i != points.end(); ++i) { |
1123 | 1123 |
1124 if (s.contains(i->frame)) { | 1124 if (s.contains(i->frame)) { |
1125 NoteModel::Point newPoint(*i); | 1125 NoteModel::Point newPoint(*i); |
1126 newPoint.frame = i->frame + newStartFrame - s.getStartFrame(); | 1126 newPoint.frame = i->frame + newStartFrame - s.getStartFrame(); |
1127 command->deletePoint(*i); | 1127 command->deletePoint(*i); |
1128 command->addPoint(newPoint); | 1128 command->addPoint(newPoint); |
1129 } | 1129 } |
1130 } | 1130 } |
1131 | 1131 |
1132 finish(command); | 1132 finish(command); |
1133 } | 1133 } |
1134 | 1134 |
1136 NoteLayer::resizeSelection(Selection s, Selection newSize) | 1136 NoteLayer::resizeSelection(Selection s, Selection newSize) |
1137 { | 1137 { |
1138 if (!m_model) return; | 1138 if (!m_model) return; |
1139 | 1139 |
1140 NoteModel::EditCommand *command = | 1140 NoteModel::EditCommand *command = |
1141 new NoteModel::EditCommand(m_model, tr("Resize Selection")); | 1141 new NoteModel::EditCommand(m_model, tr("Resize Selection")); |
1142 | 1142 |
1143 NoteModel::PointList points = | 1143 NoteModel::PointList points = |
1144 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); | 1144 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); |
1145 | 1145 |
1146 double ratio = | 1146 double ratio = |
1147 double(newSize.getEndFrame() - newSize.getStartFrame()) / | 1147 double(newSize.getEndFrame() - newSize.getStartFrame()) / |
1148 double(s.getEndFrame() - s.getStartFrame()); | 1148 double(s.getEndFrame() - s.getStartFrame()); |
1149 | 1149 |
1150 for (NoteModel::PointList::iterator i = points.begin(); | 1150 for (NoteModel::PointList::iterator i = points.begin(); |
1151 i != points.end(); ++i) { | 1151 i != points.end(); ++i) { |
1152 | 1152 |
1153 if (s.contains(i->frame)) { | 1153 if (s.contains(i->frame)) { |
1154 | 1154 |
1155 double targetStart = double(i->frame); | 1155 double targetStart = double(i->frame); |
1156 targetStart = double(newSize.getStartFrame()) + | 1156 targetStart = double(newSize.getStartFrame()) + |
1157 targetStart - double(s.getStartFrame()) * ratio; | 1157 targetStart - double(s.getStartFrame()) * ratio; |
1158 | 1158 |
1159 double targetEnd = double(i->frame + i->duration); | 1159 double targetEnd = double(i->frame + i->duration); |
1160 targetEnd = double(newSize.getStartFrame()) + | 1160 targetEnd = double(newSize.getStartFrame()) + |
1161 targetEnd - double(s.getStartFrame()) * ratio; | 1161 targetEnd - double(s.getStartFrame()) * ratio; |
1162 | 1162 |
1163 NoteModel::Point newPoint(*i); | 1163 NoteModel::Point newPoint(*i); |
1164 newPoint.frame = lrint(targetStart); | 1164 newPoint.frame = lrint(targetStart); |
1165 newPoint.duration = lrint(targetEnd - targetStart); | 1165 newPoint.duration = lrint(targetEnd - targetStart); |
1166 command->deletePoint(*i); | 1166 command->deletePoint(*i); |
1167 command->addPoint(newPoint); | 1167 command->addPoint(newPoint); |
1168 } | 1168 } |
1169 } | 1169 } |
1170 | 1170 |
1171 finish(command); | 1171 finish(command); |
1172 } | 1172 } |
1173 | 1173 |
1175 NoteLayer::deleteSelection(Selection s) | 1175 NoteLayer::deleteSelection(Selection s) |
1176 { | 1176 { |
1177 if (!m_model) return; | 1177 if (!m_model) return; |
1178 | 1178 |
1179 NoteModel::EditCommand *command = | 1179 NoteModel::EditCommand *command = |
1180 new NoteModel::EditCommand(m_model, tr("Delete Selected Points")); | 1180 new NoteModel::EditCommand(m_model, tr("Delete Selected Points")); |
1181 | 1181 |
1182 NoteModel::PointList points = | 1182 NoteModel::PointList points = |
1183 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); | 1183 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); |
1184 | 1184 |
1185 for (NoteModel::PointList::iterator i = points.begin(); | 1185 for (NoteModel::PointList::iterator i = points.begin(); |
1186 i != points.end(); ++i) { | 1186 i != points.end(); ++i) { |
1187 | 1187 |
1188 if (s.contains(i->frame)) { | 1188 if (s.contains(i->frame)) { |
1189 command->deletePoint(*i); | 1189 command->deletePoint(*i); |
1190 } | 1190 } |
1191 } | 1191 } |
1197 NoteLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to) | 1197 NoteLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to) |
1198 { | 1198 { |
1199 if (!m_model) return; | 1199 if (!m_model) return; |
1200 | 1200 |
1201 NoteModel::PointList points = | 1201 NoteModel::PointList points = |
1202 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); | 1202 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); |
1203 | 1203 |
1204 for (NoteModel::PointList::iterator i = points.begin(); | 1204 for (NoteModel::PointList::iterator i = points.begin(); |
1205 i != points.end(); ++i) { | 1205 i != points.end(); ++i) { |
1206 if (s.contains(i->frame)) { | 1206 if (s.contains(i->frame)) { |
1207 Clipboard::Point point(i->frame, i->value, i->duration, i->level, i->label); | 1207 Clipboard::Point point(i->frame, i->value, i->duration, i->level, i->label); |
1208 point.setReferenceFrame(alignToReference(v, i->frame)); | 1208 point.setReferenceFrame(alignToReference(v, i->frame)); |
1209 to.addPoint(point); | 1209 to.addPoint(point); |
1210 } | 1210 } |
1211 } | 1211 } |
1236 realign = true; | 1236 realign = true; |
1237 } | 1237 } |
1238 } | 1238 } |
1239 | 1239 |
1240 NoteModel::EditCommand *command = | 1240 NoteModel::EditCommand *command = |
1241 new NoteModel::EditCommand(m_model, tr("Paste")); | 1241 new NoteModel::EditCommand(m_model, tr("Paste")); |
1242 | 1242 |
1243 for (Clipboard::PointList::const_iterator i = points.begin(); | 1243 for (Clipboard::PointList::const_iterator i = points.begin(); |
1244 i != points.end(); ++i) { | 1244 i != points.end(); ++i) { |
1245 | 1245 |
1246 if (!i->haveFrame()) continue; | 1246 if (!i->haveFrame()) continue; |
1348 { | 1348 { |
1349 SingleColourLayer::setProperties(attributes); | 1349 SingleColourLayer::setProperties(attributes); |
1350 | 1350 |
1351 bool ok, alsoOk; | 1351 bool ok, alsoOk; |
1352 VerticalScale scale = (VerticalScale) | 1352 VerticalScale scale = (VerticalScale) |
1353 attributes.value("verticalScale").toInt(&ok); | 1353 attributes.value("verticalScale").toInt(&ok); |
1354 if (ok) setVerticalScale(scale); | 1354 if (ok) setVerticalScale(scale); |
1355 | 1355 |
1356 float min = attributes.value("scaleMinimum").toFloat(&ok); | 1356 float min = attributes.value("scaleMinimum").toFloat(&ok); |
1357 float max = attributes.value("scaleMaximum").toFloat(&alsoOk); | 1357 float max = attributes.value("scaleMaximum").toFloat(&alsoOk); |
1358 if (ok && alsoOk && min != max) setDisplayExtents(min, max); | 1358 if (ok && alsoOk && min != max) setDisplayExtents(min, max); |