diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2009-08-27 03:09:30 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2009-08-27 03:09:30 +0000 |
commit | 3845af6ce92ef15637ffb09410f442e7b4a104c3 (patch) | |
tree | 218a29f23c83c3ac57c857d3b1f599f1e6d97a14 /libs/ardour/midi_model.cc | |
parent | c6be9b688802198e04a07dc902c49d1d6b66340e (diff) |
lots of MIDI editing stuff. to be explained on the website when its done
git-svn-id: svn://localhost/ardour2/branches/3.0@5596 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/midi_model.cc')
-rw-r--r-- | libs/ardour/midi_model.cc | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/libs/ardour/midi_model.cc b/libs/ardour/midi_model.cc index 0c0c0ead5b..da524307f6 100644 --- a/libs/ardour/midi_model.cc +++ b/libs/ardour/midi_model.cc @@ -70,6 +70,19 @@ MidiModel::apply_command(Session& session, Command* cmd) set_edited(true); } +/** Apply a command as part of a larger reversible transaction + * + * Ownership of cmd is taken, it must not be deleted by the caller. + * The command will constitute one item on the undo stack. + */ +void +MidiModel::apply_command_as_subcommand(Session& session, Command* cmd) +{ + (*cmd)(); + session.add_command(cmd); + set_edited(true); +} + // DeltaCommand @@ -107,17 +120,19 @@ MidiModel::DeltaCommand::operator()() { // This could be made much faster by using a priority_queue for added and // removed notes (or sort here), and doing a single iteration over _model - + Glib::Mutex::Lock lm (_model->_midi_source->mutex()); _model->_midi_source->invalidate(); // release model read lock _model->write_lock(); - for (NoteList::iterator i = _added_notes.begin(); i != _added_notes.end(); ++i) + for (NoteList::iterator i = _added_notes.begin(); i != _added_notes.end(); ++i) { _model->add_note_unlocked(*i); + } - for (NoteList::iterator i = _removed_notes.begin(); i != _removed_notes.end(); ++i) + for (NoteList::iterator i = _removed_notes.begin(); i != _removed_notes.end(); ++i) { _model->remove_note_unlocked(*i); - + } + _model->write_unlock(); _model->ContentsChanged(); /* EMIT SIGNAL */ } @@ -132,11 +147,13 @@ MidiModel::DeltaCommand::undo() _model->_midi_source->invalidate(); // release model read lock _model->write_lock(); - for (NoteList::iterator i = _added_notes.begin(); i != _added_notes.end(); ++i) + for (NoteList::iterator i = _added_notes.begin(); i != _added_notes.end(); ++i) { _model->remove_note_unlocked(*i); + } - for (NoteList::iterator i = _removed_notes.begin(); i != _removed_notes.end(); ++i) + for (NoteList::iterator i = _removed_notes.begin(); i != _removed_notes.end(); ++i) { _model->add_note_unlocked(*i); + } _model->write_unlock(); _model->ContentsChanged(); /* EMIT SIGNAL */ |