comparison layer/NoteLayer.cpp @ 1427:f792a5001d80 single-point

Update to use external set of commands
author Chris Cannam
date Fri, 15 Mar 2019 11:09:17 +0000
parents e1a08da75427
children c9fa16e41664
comparison
equal deleted inserted replaced
1426:e1a08da75427 1427:f792a5001d80
879 879
880 m_editingPoint = Event(frame, float(value), 0, 0.8f, tr("New Point")); 880 m_editingPoint = Event(frame, float(value), 0, 0.8f, tr("New Point"));
881 m_originalPoint = m_editingPoint; 881 m_originalPoint = m_editingPoint;
882 882
883 if (m_editingCommand) finish(m_editingCommand); 883 if (m_editingCommand) finish(m_editingCommand);
884 m_editingCommand = new NoteModel::EditCommand(m_model, tr("Draw Point")); 884 m_editingCommand = new ChangeEventsCommand(m_model, tr("Draw Point"));
885 m_editingCommand->add(m_editingPoint); 885 m_editingCommand->add(m_editingPoint);
886 886
887 m_editing = true; 887 m_editing = true;
888 } 888 }
889 889
957 Event p(0); 957 Event p(0);
958 if (!getPointToDrag(v, e->x(), e->y(), p)) return; 958 if (!getPointToDrag(v, e->x(), e->y(), p)) return;
959 if (p.getFrame() != m_editingPoint.getFrame() || 959 if (p.getFrame() != m_editingPoint.getFrame() ||
960 p.getValue() != m_editingPoint.getValue()) return; 960 p.getValue() != m_editingPoint.getValue()) return;
961 961
962 m_editingCommand = new NoteModel::EditCommand(m_model, tr("Erase Point")); 962 m_editingCommand = new ChangeEventsCommand(m_model, tr("Erase Point"));
963 963
964 m_editingCommand->remove(m_editingPoint); 964 m_editingCommand->remove(m_editingPoint);
965 965
966 finish(m_editingCommand); 966 finish(m_editingCommand);
967 m_editingCommand = nullptr; 967 m_editingCommand = nullptr;
1008 frame = frame / m_model->getResolution() * m_model->getResolution(); 1008 frame = frame / m_model->getResolution() * m_model->getResolution();
1009 1009
1010 double value = getValueForY(v, newy); 1010 double value = getValueForY(v, newy);
1011 1011
1012 if (!m_editingCommand) { 1012 if (!m_editingCommand) {
1013 m_editingCommand = new NoteModel::EditCommand(m_model, 1013 m_editingCommand = new ChangeEventsCommand(m_model,
1014 tr("Drag Point")); 1014 tr("Drag Point"));
1015 } 1015 }
1016 1016
1017 m_editingCommand->remove(m_editingPoint); 1017 m_editingCommand->remove(m_editingPoint);
1018 m_editingPoint = m_editingPoint 1018 m_editingPoint = m_editingPoint
1081 .withFrame(dialog->getFrameTime()) 1081 .withFrame(dialog->getFrameTime())
1082 .withValue(dialog->getValue()) 1082 .withValue(dialog->getValue())
1083 .withDuration(dialog->getFrameDuration()) 1083 .withDuration(dialog->getFrameDuration())
1084 .withLabel(dialog->getText()); 1084 .withLabel(dialog->getText());
1085 1085
1086 NoteModel::EditCommand *command = new NoteModel::EditCommand 1086 ChangeEventsCommand *command = new ChangeEventsCommand
1087 (m_model, tr("Edit Point")); 1087 (m_model, tr("Edit Point"));
1088 command->remove(note); 1088 command->remove(note);
1089 command->add(newNote); 1089 command->add(newNote);
1090 finish(command); 1090 finish(command);
1091 } 1091 }
1100 void 1100 void
1101 NoteLayer::moveSelection(Selection s, sv_frame_t newStartFrame) 1101 NoteLayer::moveSelection(Selection s, sv_frame_t newStartFrame)
1102 { 1102 {
1103 if (!m_model) return; 1103 if (!m_model) return;
1104 1104
1105 NoteModel::EditCommand *command = 1105 ChangeEventsCommand *command =
1106 new NoteModel::EditCommand(m_model, tr("Drag Selection")); 1106 new ChangeEventsCommand(m_model, tr("Drag Selection"));
1107 1107
1108 EventVector points = 1108 EventVector points =
1109 m_model->getEventsStartingWithin(s.getStartFrame(), s.getDuration()); 1109 m_model->getEventsStartingWithin(s.getStartFrame(), s.getDuration());
1110 1110
1111 for (Event p: points) { 1111 for (Event p: points) {
1121 void 1121 void
1122 NoteLayer::resizeSelection(Selection s, Selection newSize) 1122 NoteLayer::resizeSelection(Selection s, Selection newSize)
1123 { 1123 {
1124 if (!m_model || !s.getDuration()) return; 1124 if (!m_model || !s.getDuration()) return;
1125 1125
1126 NoteModel::EditCommand *command = 1126 ChangeEventsCommand *command =
1127 new NoteModel::EditCommand(m_model, tr("Resize Selection")); 1127 new ChangeEventsCommand(m_model, tr("Resize Selection"));
1128 1128
1129 EventVector points = 1129 EventVector points =
1130 m_model->getEventsStartingWithin(s.getStartFrame(), s.getDuration()); 1130 m_model->getEventsStartingWithin(s.getStartFrame(), s.getDuration());
1131 1131
1132 double ratio = double(newSize.getDuration()) / double(s.getDuration()); 1132 double ratio = double(newSize.getDuration()) / double(s.getDuration());
1151 void 1151 void
1152 NoteLayer::deleteSelection(Selection s) 1152 NoteLayer::deleteSelection(Selection s)
1153 { 1153 {
1154 if (!m_model) return; 1154 if (!m_model) return;
1155 1155
1156 NoteModel::EditCommand *command = 1156 ChangeEventsCommand *command =
1157 new NoteModel::EditCommand(m_model, tr("Delete Selected Points")); 1157 new ChangeEventsCommand(m_model, tr("Delete Selected Points"));
1158 1158
1159 EventVector points = 1159 EventVector points =
1160 m_model->getEventsStartingWithin(s.getStartFrame(), s.getDuration()); 1160 m_model->getEventsStartingWithin(s.getStartFrame(), s.getDuration());
1161 1161
1162 for (Event p: points) { 1162 for (Event p: points) {
1204 if (button == QMessageBox::Yes) { 1204 if (button == QMessageBox::Yes) {
1205 realign = true; 1205 realign = true;
1206 } 1206 }
1207 } 1207 }
1208 1208
1209 NoteModel::EditCommand *command = 1209 ChangeEventsCommand *command =
1210 new NoteModel::EditCommand(m_model, tr("Paste")); 1210 new ChangeEventsCommand(m_model, tr("Paste"));
1211 1211
1212 for (EventVector::const_iterator i = points.begin(); 1212 for (EventVector::const_iterator i = points.begin();
1213 i != points.end(); ++i) { 1213 i != points.end(); ++i) {
1214 1214
1215 Event p = *i; 1215 Event p = *i;
1275 1275
1276 if (lrintf(p.getValue()) == pitch) { 1276 if (lrintf(p.getValue()) == pitch) {
1277 m_pendingNoteOns.erase(i); 1277 m_pendingNoteOns.erase(i);
1278 Event note = p.withDuration(frame - p.getFrame()); 1278 Event note = p.withDuration(frame - p.getFrame());
1279 if (m_model) { 1279 if (m_model) {
1280 NoteModel::EditCommand *c = new NoteModel::EditCommand 1280 ChangeEventsCommand *c = new ChangeEventsCommand
1281 (m_model, tr("Record Note")); 1281 (m_model, tr("Record Note"));
1282 c->add(note); 1282 c->add(note);
1283 // execute and bundle: 1283 // execute and bundle:
1284 CommandHistory::getInstance()->addCommand(c, true, true); 1284 CommandHistory::getInstance()->addCommand(c, true, true);
1285 } 1285 }