diff options
-rw-r--r-- | gtk2_ardour/canvas-midi-event.cc | 25 | ||||
-rw-r--r-- | gtk2_ardour/midi_region_view.cc | 27 | ||||
-rw-r--r-- | gtk2_ardour/midi_region_view.h | 3 |
3 files changed, 37 insertions, 18 deletions
diff --git a/gtk2_ardour/canvas-midi-event.cc b/gtk2_ardour/canvas-midi-event.cc index f9ee2f9ffb..1e8e313684 100644 --- a/gtk2_ardour/canvas-midi-event.cc +++ b/gtk2_ardour/canvas-midi-event.cc @@ -162,7 +162,7 @@ CanvasMidiEvent::on_event(GdkEvent* ev) last_y = last_y + dy; } - _item->move(dx, dy); + _region.move_selection(dx, dy); return true; default: @@ -191,23 +191,12 @@ CanvasMidiEvent::on_event(GdkEvent* ev) case Dragging: // Dropped _item->ungrab(ev->button.time); _state = None; - if (_note) { - // This would be nicer with a MoveCommand that doesn't need to copy... - _region.start_delta_command(); - _region.command_remove_note(this); - MidiModel::Note copy(*_note); - - double delta_t = _region.midi_view()->editor.pixel_to_frame( - abs(drag_delta_x)); - if (drag_delta_x < 0) - delta_t *= -1; - - copy.set_time(_note->time() + delta_t); - copy.set_note(_note->note() + drag_delta_note); - - _region.command_add_note(copy); - _region.apply_command(); - } + + if (_note) + _region.note_dropped(this, + _region.midi_view()->editor.pixel_to_frame(abs(drag_delta_x)) + * ((drag_delta_x < 0.0) ? -1 : 1), + drag_delta_note); return true; default: break; diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index 49817a35a0..88e7a98e7b 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -659,4 +659,31 @@ MidiRegionView::update_drag_selection(double last_x, double x, double last_y, do } } + +void +MidiRegionView::move_selection(double dx, double dy) +{ + for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i) + (*i)->item()->move(dx, dy); +} + +void +MidiRegionView::note_dropped(CanvasMidiEvent* ev, double dt, uint8_t dnote) +{ + // TODO: This would be faster/nicer with a MoveCommand that doesn't need to copy... + if (_selection.find(ev) != _selection.end()) { + start_delta_command(); + + for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i) { + command_remove_note(*i); + MidiModel::Note copy(*(*i)->note()); + + copy.set_time((*i)->note()->time() + dt); + copy.set_note((*i)->note()->note() + dnote); + + command_add_note(copy); + } + apply_command(); + } +} diff --git a/gtk2_ardour/midi_region_view.h b/gtk2_ardour/midi_region_view.h index d85b3ca91e..38d61703fa 100644 --- a/gtk2_ardour/midi_region_view.h +++ b/gtk2_ardour/midi_region_view.h @@ -142,6 +142,9 @@ class MidiRegionView : public RegionView void delete_selection(); size_t selection_size() { return _selection.size(); } + void move_selection(double dx, double dy); + void note_dropped(ArdourCanvas::CanvasMidiEvent* ev, double dt, uint8_t dnote); + protected: /* this constructor allows derived types |