Multi-note (ie selection) dragging.

git-svn-id: svn://localhost/ardour2/trunk@2267 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
David Robillard 2007-08-08 02:01:14 +00:00
parent 8f6a131e41
commit 7caaa6a0e9
3 changed files with 36 additions and 17 deletions

View File

@ -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;

View File

@ -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();
}
}

View File

@ -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