From f50d5507c34bb9cc6f071ff35004fdb225cccb9e Mon Sep 17 00:00:00 2001 From: Ben Loftis Date: Mon, 9 May 2022 11:54:18 -0500 Subject: [PATCH] midi_model: rename some midi diff functions, to (try to) avoid confusion syntax for beginning and ending a diff command is: "new_diff_command" -> "apply_diff_command" syntax for applying a diff_command is: "_as_commit" : Begins and Commits a standalone undo Command "_as_subcommand" : adds to undo but does not Begin or Commit a Command "_only" : (new) applies the note_diff but does not have any effect on undo --- libs/ardour/ardour/midi_model.h | 19 +++++++++++++------ libs/ardour/import_pt.cc | 2 +- libs/ardour/luabindings.cc | 3 ++- libs/ardour/midi_model.cc | 17 ++++++++++++----- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/libs/ardour/ardour/midi_model.h b/libs/ardour/ardour/midi_model.h index 3191d00140..6f4966e175 100644 --- a/libs/ardour/ardour/midi_model.h +++ b/libs/ardour/ardour/midi_model.h @@ -256,7 +256,7 @@ public: * * This has no side-effects on the model or Session, the returned command * can be held on to for as long as the caller wishes, or discarded without - * formality, until apply_command is called and ownership is taken. + * formality, until apply_diff_command_* is called and ownership is taken. */ MidiModel::NoteDiffCommand* new_note_diff_command (const std::string& name = "midi edit"); /** Start a new SysExDiff command */ @@ -268,18 +268,25 @@ public: /** Apply a command. * * Ownership of cmd is taken, it must not be deleted by the caller. + * This STARTS and COMMITS an undo command. * The command will constitute one item on the undo stack. */ - void apply_command (Session& session, Command* cmd); + void apply_diff_command_as_commit (Session& session, Command* cmd); - void apply_command (Session* session, Command* cmd) { if (session) { apply_command (*session, cmd); } } + void apply_diff_command_as_commit (Session* session, Command* cmd) { if (session) { apply_diff_command_as_commit (*session, cmd); } } - /** Apply a command as part of a larger reversible transaction + /** Add 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. + * The command will be incorporated into the current command. */ - void apply_command_as_subcommand (Session& session, Command* cmd); + void apply_diff_command_as_subcommand (Session& session, Command* cmd); + + /** Apply the midi diff, but without any effect on undo + * + * Ownership of cmd is not changed. + */ + void apply_diff_command_only (Session& session, Command* cmd); bool sync_to_source (const Source::WriterLock& source_lock); diff --git a/libs/ardour/import_pt.cc b/libs/ardour/import_pt.cc index ac90e16ad7..285a26ebdd 100644 --- a/libs/ardour/import_pt.cc +++ b/libs/ardour/import_pt.cc @@ -461,7 +461,7 @@ no_audio_tracks: /* PT C-2 = 0, Ardour C-1 = 0, subtract twelve to convert ? */ midicmd->add (boost::shared_ptr > (new Evoral::Note ((uint8_t)1, start, len, j->note, j->velocity))); } - mm->apply_command (this, midicmd); + mm->apply_diff_command_only (*this, midicmd); boost::shared_ptr copy (RegionFactory::create (mr, true)); playlist->clear_changes (); playlist->add_region (copy, timepos_t (f)); diff --git a/libs/ardour/luabindings.cc b/libs/ardour/luabindings.cc index 798909a0e0..2b95b1def3 100644 --- a/libs/ardour/luabindings.cc +++ b/libs/ardour/luabindings.cc @@ -1571,7 +1571,8 @@ LuaBindings::common (lua_State* L) .endClass () .deriveWSPtrClass > ("MidiModel") - .addFunction ("apply_command", (void (MidiModel::*)(Session*, Command*))&MidiModel::apply_command) + .addFunction ("apply_command", (void (MidiModel::*)(Session*, Command*))&MidiModel::apply_diff_command_as_commit) /* deprecated: left here in case any extant scripts use apply_command */ + .addFunction ("apply_diff_command_as_commit", (void (MidiModel::*)(Session*, Command*))&MidiModel::apply_diff_command_as_commit) .addFunction ("new_note_diff_command", &MidiModel::new_note_diff_command) .endClass () diff --git a/libs/ardour/midi_model.cc b/libs/ardour/midi_model.cc index 8bc149853c..3ba6f62828 100644 --- a/libs/ardour/midi_model.cc +++ b/libs/ardour/midi_model.cc @@ -92,7 +92,7 @@ MidiModel::new_patch_change_diff_command (const string& name) void -MidiModel::apply_command(Session& session, Command* cmd) +MidiModel::apply_diff_command_as_commit(Session& session, Command* cmd) { session.begin_reversible_command (cmd->name()); (*cmd)(); @@ -101,13 +101,20 @@ MidiModel::apply_command(Session& session, Command* cmd) } void -MidiModel::apply_command_as_subcommand(Session& session, Command* cmd) +MidiModel::apply_diff_command_as_subcommand(Session& session, Command* cmd) { (*cmd)(); session.add_command (cmd); set_edited (true); } +void +MidiModel::apply_diff_command_only(Session& session, Command* cmd) +{ + (*cmd)(); + set_edited (true); +} + /* ************* DIFF COMMAND ********************/ #define NOTE_DIFF_COMMAND_ELEMENT "NoteDiffCommand" @@ -1702,7 +1709,7 @@ MidiModel::insert_silence_at_start (TimeType t) c->change (*i, NoteDiffCommand::StartTime, (*i)->time() + t); } - apply_command_as_subcommand (_midi_source.session(), c); + apply_diff_command_as_subcommand (_midi_source.session(), c); } /* Patch changes */ @@ -1714,7 +1721,7 @@ MidiModel::insert_silence_at_start (TimeType t) c->change_time (*i, (*i)->time() + t); } - apply_command_as_subcommand (_midi_source.session(), c); + apply_diff_command_as_subcommand (_midi_source.session(), c); } /* Controllers */ @@ -1736,7 +1743,7 @@ MidiModel::insert_silence_at_start (TimeType t) c->change (*i, (*i)->time() + t); } - apply_command_as_subcommand (_midi_source.session(), c); + apply_diff_command_as_subcommand (_midi_source.session(), c); } ContentsShifted (timecnt_t (t));