Mercurial > hg > svgui
comparison layer/NoteLayer.cpp @ 1425:f9e3126d223c single-point
Finish updating NoteLayer to single-point API
author | Chris Cannam |
---|---|
date | Thu, 14 Mar 2019 13:12:25 +0000 |
parents | 2ee77c9974d7 |
children | e1a08da75427 |
comparison
equal
deleted
inserted
replaced
1424:2ee77c9974d7 | 1425:f9e3126d223c |
---|---|
731 | 731 |
732 int x0 = rect.left(), x1 = rect.right(); | 732 int x0 = rect.left(), x1 = rect.right(); |
733 sv_frame_t frame0 = v->getFrameForX(x0); | 733 sv_frame_t frame0 = v->getFrameForX(x0); |
734 sv_frame_t frame1 = v->getFrameForX(x1); | 734 sv_frame_t frame1 = v->getFrameForX(x1); |
735 | 735 |
736 NoteModel::PointList points(m_model->getPoints(frame0, frame1)); | 736 EventVector points(m_model->getEventsSpanning(frame0, frame1 - frame0)); |
737 if (points.empty()) return; | 737 if (points.empty()) return; |
738 | 738 |
739 paint.setPen(getBaseQColor()); | 739 paint.setPen(getBaseQColor()); |
740 | 740 |
741 QColor brushColour(getBaseQColor()); | 741 QColor brushColour(getBaseQColor()); |
747 double min = m_model->getValueMinimum(); | 747 double min = m_model->getValueMinimum(); |
748 double max = m_model->getValueMaximum(); | 748 double max = m_model->getValueMaximum(); |
749 if (max == min) max = min + 1.0; | 749 if (max == min) max = min + 1.0; |
750 | 750 |
751 QPoint localPos; | 751 QPoint localPos; |
752 NoteModel::Point illuminatePoint(0); | 752 Event illuminatePoint; |
753 bool shouldIlluminate = false; | 753 bool shouldIlluminate = false; |
754 | 754 |
755 if (v->shouldIlluminateLocalFeatures(this, localPos)) { | 755 if (v->shouldIlluminateLocalFeatures(this, localPos)) { |
756 shouldIlluminate = getPointToDrag(v, localPos.x(), localPos.y(), | 756 shouldIlluminate = getPointToDrag(v, localPos.x(), localPos.y(), |
757 illuminatePoint); | 757 illuminatePoint); |
761 } | 761 } |
762 | 762 |
763 paint.save(); | 763 paint.save(); |
764 paint.setRenderHint(QPainter::Antialiasing, false); | 764 paint.setRenderHint(QPainter::Antialiasing, false); |
765 | 765 |
766 for (NoteModel::PointList::const_iterator i = points.begin(); | 766 for (EventVector::const_iterator i = points.begin(); |
767 i != points.end(); ++i) { | 767 i != points.end(); ++i) { |
768 | 768 |
769 const NoteModel::Point &p(*i); | 769 const Event &p(*i); |
770 | 770 |
771 int x = v->getXForFrame(p.frame); | 771 int x = v->getXForFrame(p.getFrame()); |
772 int y = getYForValue(v, p.value); | 772 int y = getYForValue(v, p.getValue()); |
773 int w = v->getXForFrame(p.frame + p.duration) - x; | 773 int w = v->getXForFrame(p.getFrame() + p.getDuration()) - x; |
774 int h = 3; | 774 int h = 3; |
775 | 775 |
776 if (m_model->getValueQuantization() != 0.0) { | 776 if (m_model->getValueQuantization() != 0.0) { |
777 h = y - getYForValue(v, p.value + m_model->getValueQuantization()); | 777 h = y - getYForValue(v, p.getValue() + m_model->getValueQuantization()); |
778 if (h < 3) h = 3; | 778 if (h < 3) h = 3; |
779 } | 779 } |
780 | 780 |
781 if (w < 1) w = 1; | 781 if (w < 1) w = 1; |
782 paint.setPen(getBaseQColor()); | 782 paint.setPen(getBaseQColor()); |
783 paint.setBrush(brushColour); | 783 paint.setBrush(brushColour); |
784 | 784 |
785 if (shouldIlluminate && | 785 if (shouldIlluminate && illuminatePoint == p) { |
786 // "illuminatePoint == p" | |
787 !NoteModel::Point::Comparator()(illuminatePoint, p) && | |
788 !NoteModel::Point::Comparator()(p, illuminatePoint)) { | |
789 | 786 |
790 paint.setPen(v->getForeground()); | 787 paint.setPen(v->getForeground()); |
791 paint.setBrush(v->getForeground()); | 788 paint.setBrush(v->getForeground()); |
792 | 789 |
793 QString vlabel = QString("%1%2").arg(p.value).arg(getScaleUnits()); | 790 QString vlabel = QString("%1%2").arg(p.getValue()).arg(getScaleUnits()); |
794 PaintAssistant::drawVisibleText(v, paint, | 791 PaintAssistant::drawVisibleText(v, paint, |
795 x - paint.fontMetrics().width(vlabel) - 2, | 792 x - paint.fontMetrics().width(vlabel) - 2, |
796 y + paint.fontMetrics().height()/2 | 793 y + paint.fontMetrics().height()/2 |
797 - paint.fontMetrics().descent(), | 794 - paint.fontMetrics().descent(), |
798 vlabel, PaintAssistant::OutlinedText); | 795 vlabel, PaintAssistant::OutlinedText); |
799 | 796 |
800 QString hlabel = RealTime::frame2RealTime | 797 QString hlabel = RealTime::frame2RealTime |
801 (p.frame, m_model->getSampleRate()).toText(true).c_str(); | 798 (p.getFrame(), m_model->getSampleRate()).toText(true).c_str(); |
802 PaintAssistant::drawVisibleText(v, paint, | 799 PaintAssistant::drawVisibleText(v, paint, |
803 x, | 800 x, |
804 y - h/2 - paint.fontMetrics().descent() - 2, | 801 y - h/2 - paint.fontMetrics().descent() - 2, |
805 hlabel, PaintAssistant::OutlinedText); | 802 hlabel, PaintAssistant::OutlinedText); |
806 } | 803 } |
830 } | 827 } |
831 | 828 |
832 void | 829 void |
833 NoteLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect) const | 830 NoteLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect) const |
834 { | 831 { |
835 if (!m_model || m_model->getPoints().empty()) return; | 832 if (!m_model || m_model->isEmpty()) return; |
836 | 833 |
837 QString unit; | 834 QString unit; |
838 double min, max; | 835 double min, max; |
839 bool logarithmic; | 836 bool logarithmic; |
840 | 837 |
878 if (frame < 0) frame = 0; | 875 if (frame < 0) frame = 0; |
879 frame = frame / m_model->getResolution() * m_model->getResolution(); | 876 frame = frame / m_model->getResolution() * m_model->getResolution(); |
880 | 877 |
881 double value = getValueForY(v, e->y()); | 878 double value = getValueForY(v, e->y()); |
882 | 879 |
883 m_editingPoint = NoteModel::Point(frame, float(value), 0, 0.8f, tr("New Point")); | 880 m_editingPoint = Event(frame, float(value), 0, 0.8f, tr("New Point")); |
884 m_originalPoint = m_editingPoint; | 881 m_originalPoint = m_editingPoint; |
885 | 882 |
886 if (m_editingCommand) finish(m_editingCommand); | 883 if (m_editingCommand) finish(m_editingCommand); |
887 m_editingCommand = new NoteModel::EditCommand(m_model, | 884 m_editingCommand = new NoteModel::EditCommand(m_model, tr("Draw Point")); |
888 tr("Draw Point")); | 885 m_editingCommand->add(m_editingPoint); |
889 m_editingCommand->addPoint(m_editingPoint); | |
890 | 886 |
891 m_editing = true; | 887 m_editing = true; |
892 } | 888 } |
893 | 889 |
894 void | 890 void |
902 if (frame < 0) frame = 0; | 898 if (frame < 0) frame = 0; |
903 frame = frame / m_model->getResolution() * m_model->getResolution(); | 899 frame = frame / m_model->getResolution() * m_model->getResolution(); |
904 | 900 |
905 double newValue = getValueForY(v, e->y()); | 901 double newValue = getValueForY(v, e->y()); |
906 | 902 |
907 sv_frame_t newFrame = m_editingPoint.frame; | 903 sv_frame_t newFrame = m_editingPoint.getFrame(); |
908 sv_frame_t newDuration = frame - newFrame; | 904 sv_frame_t newDuration = frame - newFrame; |
909 if (newDuration < 0) { | 905 if (newDuration < 0) { |
910 newFrame = frame; | 906 newFrame = frame; |
911 newDuration = -newDuration; | 907 newDuration = -newDuration; |
912 } else if (newDuration == 0) { | 908 } else if (newDuration == 0) { |
913 newDuration = 1; | 909 newDuration = 1; |
914 } | 910 } |
915 | 911 |
916 m_editingCommand->deletePoint(m_editingPoint); | 912 m_editingCommand->remove(m_editingPoint); |
917 m_editingPoint.frame = newFrame; | 913 m_editingPoint = m_editingPoint |
918 m_editingPoint.value = float(newValue); | 914 .withFrame(newFrame) |
919 m_editingPoint.duration = newDuration; | 915 .withValue(float(newValue)) |
920 m_editingCommand->addPoint(m_editingPoint); | 916 .withDuration(newDuration); |
917 m_editingCommand->add(m_editingPoint); | |
921 } | 918 } |
922 | 919 |
923 void | 920 void |
924 NoteLayer::drawEnd(LayerGeometryProvider *, QMouseEvent *) | 921 NoteLayer::drawEnd(LayerGeometryProvider *, QMouseEvent *) |
925 { | 922 { |
955 { | 952 { |
956 if (!m_model || !m_editing) return; | 953 if (!m_model || !m_editing) return; |
957 | 954 |
958 m_editing = false; | 955 m_editing = false; |
959 | 956 |
960 NoteModel::Point p(0); | 957 Event p(0); |
961 if (!getPointToDrag(v, e->x(), e->y(), p)) return; | 958 if (!getPointToDrag(v, e->x(), e->y(), p)) return; |
962 if (p.frame != m_editingPoint.frame || p.value != m_editingPoint.value) return; | 959 if (p.getFrame() != m_editingPoint.getFrame() || |
960 p.getValue() != m_editingPoint.getValue()) return; | |
963 | 961 |
964 m_editingCommand = new NoteModel::EditCommand(m_model, tr("Erase Point")); | 962 m_editingCommand = new NoteModel::EditCommand(m_model, tr("Erase Point")); |
965 | 963 |
966 m_editingCommand->deletePoint(m_editingPoint); | 964 m_editingCommand->remove(m_editingPoint); |
967 | 965 |
968 finish(m_editingCommand); | 966 finish(m_editingCommand); |
969 m_editingCommand = nullptr; | 967 m_editingCommand = nullptr; |
970 m_editing = false; | 968 m_editing = false; |
971 } | 969 } |
978 if (!m_model) return; | 976 if (!m_model) return; |
979 | 977 |
980 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; | 978 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; |
981 m_originalPoint = m_editingPoint; | 979 m_originalPoint = m_editingPoint; |
982 | 980 |
983 m_dragPointX = v->getXForFrame(m_editingPoint.frame); | 981 m_dragPointX = v->getXForFrame(m_editingPoint.getFrame()); |
984 m_dragPointY = getYForValue(v, m_editingPoint.value); | 982 m_dragPointY = getYForValue(v, m_editingPoint.getValue()); |
985 | 983 |
986 if (m_editingCommand) { | 984 if (m_editingCommand) { |
987 finish(m_editingCommand); | 985 finish(m_editingCommand); |
988 m_editingCommand = nullptr; | 986 m_editingCommand = nullptr; |
989 } | 987 } |
1014 if (!m_editingCommand) { | 1012 if (!m_editingCommand) { |
1015 m_editingCommand = new NoteModel::EditCommand(m_model, | 1013 m_editingCommand = new NoteModel::EditCommand(m_model, |
1016 tr("Drag Point")); | 1014 tr("Drag Point")); |
1017 } | 1015 } |
1018 | 1016 |
1019 m_editingCommand->deletePoint(m_editingPoint); | 1017 m_editingCommand->remove(m_editingPoint); |
1020 m_editingPoint.frame = frame; | 1018 m_editingPoint = m_editingPoint |
1021 m_editingPoint.value = float(value); | 1019 .withFrame(frame) |
1022 m_editingCommand->addPoint(m_editingPoint); | 1020 .withValue(float(value)); |
1021 m_editingCommand->add(m_editingPoint); | |
1023 } | 1022 } |
1024 | 1023 |
1025 void | 1024 void |
1026 NoteLayer::editEnd(LayerGeometryProvider *, QMouseEvent *) | 1025 NoteLayer::editEnd(LayerGeometryProvider *, QMouseEvent *) |
1027 { | 1026 { |
1030 | 1029 |
1031 if (m_editingCommand) { | 1030 if (m_editingCommand) { |
1032 | 1031 |
1033 QString newName = m_editingCommand->getName(); | 1032 QString newName = m_editingCommand->getName(); |
1034 | 1033 |
1035 if (m_editingPoint.frame != m_originalPoint.frame) { | 1034 if (m_editingPoint.getFrame() != m_originalPoint.getFrame()) { |
1036 if (m_editingPoint.value != m_originalPoint.value) { | 1035 if (m_editingPoint.getValue() != m_originalPoint.getValue()) { |
1037 newName = tr("Edit Point"); | 1036 newName = tr("Edit Point"); |
1038 } else { | 1037 } else { |
1039 newName = tr("Relocate Point"); | 1038 newName = tr("Relocate Point"); |
1040 } | 1039 } |
1041 } else { | 1040 } else { |
1053 bool | 1052 bool |
1054 NoteLayer::editOpen(LayerGeometryProvider *v, QMouseEvent *e) | 1053 NoteLayer::editOpen(LayerGeometryProvider *v, QMouseEvent *e) |
1055 { | 1054 { |
1056 if (!m_model) return false; | 1055 if (!m_model) return false; |
1057 | 1056 |
1058 NoteModel::Point note(0); | 1057 Event note(0); |
1059 if (!getPointToDrag(v, e->x(), e->y(), note)) return false; | 1058 if (!getPointToDrag(v, e->x(), e->y(), note)) return false; |
1060 | 1059 |
1061 // NoteModel::Point note = *points.begin(); | 1060 // Event note = *points.begin(); |
1062 | 1061 |
1063 ItemEditDialog *dialog = new ItemEditDialog | 1062 ItemEditDialog *dialog = new ItemEditDialog |
1064 (m_model->getSampleRate(), | 1063 (m_model->getSampleRate(), |
1065 ItemEditDialog::ShowTime | | 1064 ItemEditDialog::ShowTime | |
1066 ItemEditDialog::ShowDuration | | 1065 ItemEditDialog::ShowDuration | |
1067 ItemEditDialog::ShowValue | | 1066 ItemEditDialog::ShowValue | |
1068 ItemEditDialog::ShowText, | 1067 ItemEditDialog::ShowText, |
1069 getScaleUnits()); | 1068 getScaleUnits()); |
1070 | 1069 |
1071 dialog->setFrameTime(note.frame); | 1070 dialog->setFrameTime(note.getFrame()); |
1072 dialog->setValue(note.value); | 1071 dialog->setValue(note.getValue()); |
1073 dialog->setFrameDuration(note.duration); | 1072 dialog->setFrameDuration(note.getDuration()); |
1074 dialog->setText(note.label); | 1073 dialog->setText(note.getLabel()); |
1075 | 1074 |
1076 m_editingPoint = note; | 1075 m_editingPoint = note; |
1077 m_editIsOpen = true; | 1076 m_editIsOpen = true; |
1078 | 1077 |
1079 if (dialog->exec() == QDialog::Accepted) { | 1078 if (dialog->exec() == QDialog::Accepted) { |
1080 | 1079 |
1081 NoteModel::Point newNote = note; | 1080 Event newNote = note |
1082 newNote.frame = dialog->getFrameTime(); | 1081 .withFrame(dialog->getFrameTime()) |
1083 newNote.value = dialog->getValue(); | 1082 .withValue(dialog->getValue()) |
1084 newNote.duration = dialog->getFrameDuration(); | 1083 .withDuration(dialog->getFrameDuration()) |
1085 newNote.label = dialog->getText(); | 1084 .withLabel(dialog->getText()); |
1086 | 1085 |
1087 NoteModel::EditCommand *command = new NoteModel::EditCommand | 1086 NoteModel::EditCommand *command = new NoteModel::EditCommand |
1088 (m_model, tr("Edit Point")); | 1087 (m_model, tr("Edit Point")); |
1089 command->deletePoint(note); | 1088 command->remove(note); |
1090 command->addPoint(newNote); | 1089 command->add(newNote); |
1091 finish(command); | 1090 finish(command); |
1092 } | 1091 } |
1093 | 1092 |
1094 m_editingPoint = 0; | 1093 m_editingPoint = 0; |
1095 m_editIsOpen = false; | 1094 m_editIsOpen = false; |
1104 if (!m_model) return; | 1103 if (!m_model) return; |
1105 | 1104 |
1106 NoteModel::EditCommand *command = | 1105 NoteModel::EditCommand *command = |
1107 new NoteModel::EditCommand(m_model, tr("Drag Selection")); | 1106 new NoteModel::EditCommand(m_model, tr("Drag Selection")); |
1108 | 1107 |
1109 NoteModel::PointList points = | 1108 EventVector points = |
1110 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); | 1109 m_model->getEventsStartingWithin(s.getStartFrame(), s.getDuration()); |
1111 | 1110 |
1112 for (NoteModel::PointList::iterator i = points.begin(); | 1111 SVCERR << "Have " << points.size() << " points to drag" << endl; |
1113 i != points.end(); ++i) { | 1112 |
1114 | 1113 for (Event p: points) { |
1115 if (s.contains(i->frame)) { | 1114 SVCERR << "asking to remove " << p.toXmlString() << endl; |
1116 NoteModel::Point newPoint(*i); | 1115 command->remove(p); |
1117 newPoint.frame = i->frame + newStartFrame - s.getStartFrame(); | 1116 Event moved = p.withFrame(p.getFrame() + |
1118 command->deletePoint(*i); | 1117 newStartFrame - s.getStartFrame()); |
1119 command->addPoint(newPoint); | 1118 SVCERR << "asking to add " << moved.toXmlString() << endl; |
1120 } | 1119 command->add(moved); |
1121 } | 1120 } |
1122 | 1121 |
1123 finish(command); | 1122 finish(command); |
1124 } | 1123 } |
1125 | 1124 |
1126 void | 1125 void |
1127 NoteLayer::resizeSelection(Selection s, Selection newSize) | 1126 NoteLayer::resizeSelection(Selection s, Selection newSize) |
1128 { | 1127 { |
1129 if (!m_model) return; | 1128 if (!m_model || !s.getDuration()) return; |
1130 | 1129 |
1131 NoteModel::EditCommand *command = | 1130 NoteModel::EditCommand *command = |
1132 new NoteModel::EditCommand(m_model, tr("Resize Selection")); | 1131 new NoteModel::EditCommand(m_model, tr("Resize Selection")); |
1133 | 1132 |
1134 NoteModel::PointList points = | 1133 EventVector points = |
1135 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); | 1134 m_model->getEventsStartingWithin(s.getStartFrame(), s.getDuration()); |
1136 | 1135 |
1137 double ratio = | 1136 double ratio = double(newSize.getDuration()) / double(s.getDuration()); |
1138 double(newSize.getEndFrame() - newSize.getStartFrame()) / | 1137 double oldStart = double(s.getStartFrame()); |
1139 double(s.getEndFrame() - s.getStartFrame()); | 1138 double newStart = double(newSize.getStartFrame()); |
1140 | 1139 |
1141 for (NoteModel::PointList::iterator i = points.begin(); | 1140 for (Event p: points) { |
1142 i != points.end(); ++i) { | 1141 |
1143 | 1142 double newFrame = (double(p.getFrame()) - oldStart) * ratio + newStart; |
1144 if (s.contains(i->frame)) { | 1143 double newDuration = double(p.getDuration()) * ratio; |
1145 | 1144 |
1146 double targetStart = double(i->frame); | 1145 Event newPoint = p |
1147 targetStart = double(newSize.getStartFrame()) + | 1146 .withFrame(lrint(newFrame)) |
1148 targetStart - double(s.getStartFrame()) * ratio; | 1147 .withDuration(lrint(newDuration)); |
1149 | 1148 command->remove(p); |
1150 double targetEnd = double(i->frame + i->duration); | 1149 command->add(newPoint); |
1151 targetEnd = double(newSize.getStartFrame()) + | |
1152 targetEnd - double(s.getStartFrame()) * ratio; | |
1153 | |
1154 NoteModel::Point newPoint(*i); | |
1155 newPoint.frame = lrint(targetStart); | |
1156 newPoint.duration = lrint(targetEnd - targetStart); | |
1157 command->deletePoint(*i); | |
1158 command->addPoint(newPoint); | |
1159 } | |
1160 } | 1150 } |
1161 | 1151 |
1162 finish(command); | 1152 finish(command); |
1163 } | 1153 } |
1164 | 1154 |
1168 if (!m_model) return; | 1158 if (!m_model) return; |
1169 | 1159 |
1170 NoteModel::EditCommand *command = | 1160 NoteModel::EditCommand *command = |
1171 new NoteModel::EditCommand(m_model, tr("Delete Selected Points")); | 1161 new NoteModel::EditCommand(m_model, tr("Delete Selected Points")); |
1172 | 1162 |
1173 NoteModel::PointList points = | 1163 EventVector points = |
1174 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); | 1164 m_model->getEventsStartingWithin(s.getStartFrame(), s.getDuration()); |
1175 | 1165 |
1176 for (NoteModel::PointList::iterator i = points.begin(); | 1166 for (Event p: points) { |
1177 i != points.end(); ++i) { | 1167 command->remove(p); |
1178 | |
1179 if (s.contains(i->frame)) { | |
1180 command->deletePoint(*i); | |
1181 } | |
1182 } | 1168 } |
1183 | 1169 |
1184 finish(command); | 1170 finish(command); |
1185 } | 1171 } |
1186 | 1172 |
1187 void | 1173 void |
1188 NoteLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to) | 1174 NoteLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to) |
1189 { | 1175 { |
1190 if (!m_model) return; | 1176 if (!m_model) return; |
1191 | 1177 |
1192 NoteModel::PointList points = | 1178 EventVector points = |
1193 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); | 1179 m_model->getEventsStartingWithin(s.getStartFrame(), s.getDuration()); |
1194 | 1180 |
1195 for (NoteModel::PointList::iterator i = points.begin(); | 1181 for (Event p: points) { |
1196 i != points.end(); ++i) { | 1182 to.addPoint(p.withReferenceFrame(alignToReference(v, p.getFrame()))); |
1197 if (s.contains(i->frame)) { | |
1198 Event point(i->frame, i->value, i->duration, i->level, i->label); | |
1199 to.addPoint(point.withReferenceFrame(alignToReference(v, i->frame))); | |
1200 } | |
1201 } | 1183 } |
1202 } | 1184 } |
1203 | 1185 |
1204 bool | 1186 bool |
1205 NoteLayer::paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t /* frameOffset */, bool /* interactive */) | 1187 NoteLayer::paste(LayerGeometryProvider *v, const Clipboard &from, |
1188 sv_frame_t /* frameOffset */, bool /* interactive */) | |
1206 { | 1189 { |
1207 if (!m_model) return false; | 1190 if (!m_model) return false; |
1208 | 1191 |
1209 const EventVector &points = from.getPoints(); | 1192 const EventVector &points = from.getPoints(); |
1210 | 1193 |
1230 NoteModel::EditCommand *command = | 1213 NoteModel::EditCommand *command = |
1231 new NoteModel::EditCommand(m_model, tr("Paste")); | 1214 new NoteModel::EditCommand(m_model, tr("Paste")); |
1232 | 1215 |
1233 for (EventVector::const_iterator i = points.begin(); | 1216 for (EventVector::const_iterator i = points.begin(); |
1234 i != points.end(); ++i) { | 1217 i != points.end(); ++i) { |
1218 | |
1219 Event p = *i; | |
1235 | 1220 |
1236 sv_frame_t frame = 0; | 1221 sv_frame_t frame = 0; |
1237 | 1222 |
1238 if (!realign) { | 1223 if (!realign) { |
1239 | 1224 |
1247 } else { | 1232 } else { |
1248 frame = i->getFrame(); | 1233 frame = i->getFrame(); |
1249 } | 1234 } |
1250 } | 1235 } |
1251 | 1236 |
1252 NoteModel::Point newPoint(frame); | 1237 Event newPoint = p; |
1253 | 1238 if (!p.hasValue()) { |
1254 if (i->hasLabel()) newPoint.label = i->getLabel(); | 1239 newPoint = newPoint.withValue((m_model->getValueMinimum() + |
1255 if (i->hasValue()) newPoint.value = i->getValue(); | 1240 m_model->getValueMaximum()) / 2); |
1256 else newPoint.value = (m_model->getValueMinimum() + | 1241 } |
1257 m_model->getValueMaximum()) / 2; | 1242 if (!p.hasDuration()) { |
1258 if (i->hasLevel()) newPoint.level = i->getLevel(); | |
1259 if (i->hasDuration()) newPoint.duration = i->getDuration(); | |
1260 else { | |
1261 sv_frame_t nextFrame = frame; | 1243 sv_frame_t nextFrame = frame; |
1262 EventVector::const_iterator j = i; | 1244 EventVector::const_iterator j = i; |
1263 for (; j != points.end(); ++j) { | 1245 for (; j != points.end(); ++j) { |
1264 if (j != i) break; | 1246 if (j != i) break; |
1265 } | 1247 } |
1266 if (j != points.end()) { | 1248 if (j != points.end()) { |
1267 nextFrame = j->getFrame(); | 1249 nextFrame = j->getFrame(); |
1268 } | 1250 } |
1269 if (nextFrame == frame) { | 1251 if (nextFrame == frame) { |
1270 newPoint.duration = m_model->getResolution(); | 1252 newPoint = newPoint.withDuration(m_model->getResolution()); |
1271 } else { | 1253 } else { |
1272 newPoint.duration = nextFrame - frame; | 1254 newPoint = newPoint.withDuration(nextFrame - frame); |
1273 } | 1255 } |
1274 } | 1256 } |
1275 | 1257 |
1276 command->addPoint(newPoint); | 1258 command->add(newPoint); |
1277 } | 1259 } |
1278 | 1260 |
1279 finish(command); | 1261 finish(command); |
1280 return true; | 1262 return true; |
1281 } | 1263 } |
1282 | 1264 |
1283 void | 1265 void |
1284 NoteLayer::addNoteOn(sv_frame_t frame, int pitch, int velocity) | 1266 NoteLayer::addNoteOn(sv_frame_t frame, int pitch, int velocity) |
1285 { | 1267 { |
1286 m_pendingNoteOns.insert(Note(frame, float(pitch), 0, float(velocity) / 127.f, "")); | 1268 m_pendingNoteOns.insert(Event(frame, float(pitch), 0, |
1269 float(velocity) / 127.f, QString())); | |
1287 } | 1270 } |
1288 | 1271 |
1289 void | 1272 void |
1290 NoteLayer::addNoteOff(sv_frame_t frame, int pitch) | 1273 NoteLayer::addNoteOff(sv_frame_t frame, int pitch) |
1291 { | 1274 { |
1292 for (NoteSet::iterator i = m_pendingNoteOns.begin(); | 1275 for (NoteSet::iterator i = m_pendingNoteOns.begin(); |
1293 i != m_pendingNoteOns.end(); ++i) { | 1276 i != m_pendingNoteOns.end(); ++i) { |
1294 if (lrintf((*i).value) == pitch) { | 1277 |
1295 Note note(*i); | 1278 Event p = *i; |
1279 | |
1280 if (lrintf(p.getValue()) == pitch) { | |
1296 m_pendingNoteOns.erase(i); | 1281 m_pendingNoteOns.erase(i); |
1297 note.duration = frame - note.frame; | 1282 Event note = p.withDuration(frame - p.getFrame()); |
1298 if (m_model) { | 1283 if (m_model) { |
1299 NoteModel::AddPointCommand *c = new NoteModel::AddPointCommand | 1284 NoteModel::EditCommand *c = new NoteModel::EditCommand |
1300 (m_model, note, tr("Record Note")); | 1285 (m_model, tr("Record Note")); |
1286 c->add(note); | |
1301 // execute and bundle: | 1287 // execute and bundle: |
1302 CommandHistory::getInstance()->addCommand(c, true, true); | 1288 CommandHistory::getInstance()->addCommand(c, true, true); |
1303 } | 1289 } |
1304 break; | 1290 break; |
1305 } | 1291 } |