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
This commit is contained in:
Ben Loftis 2022-05-09 11:54:18 -05:00
parent c44d692390
commit f50d5507c3
4 changed files with 28 additions and 13 deletions

View file

@ -256,7 +256,7 @@ public:
* *
* This has no side-effects on the model or Session, the returned command * 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 * 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"); MidiModel::NoteDiffCommand* new_note_diff_command (const std::string& name = "midi edit");
/** Start a new SysExDiff command */ /** Start a new SysExDiff command */
@ -268,18 +268,25 @@ public:
/** Apply a command. /** Apply a command.
* *
* Ownership of cmd is taken, it must not be deleted by the caller. * 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. * 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. * 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); bool sync_to_source (const Source::WriterLock& source_lock);

View file

@ -461,7 +461,7 @@ no_audio_tracks:
/* PT C-2 = 0, Ardour C-1 = 0, subtract twelve to convert ? */ /* PT C-2 = 0, Ardour C-1 = 0, subtract twelve to convert ? */
midicmd->add (boost::shared_ptr<Evoral::Note<Temporal::Beats> > (new Evoral::Note<Temporal::Beats> ((uint8_t)1, start, len, j->note, j->velocity))); midicmd->add (boost::shared_ptr<Evoral::Note<Temporal::Beats> > (new Evoral::Note<Temporal::Beats> ((uint8_t)1, start, len, j->note, j->velocity)));
} }
mm->apply_command (this, midicmd); mm->apply_diff_command_only (*this, midicmd);
boost::shared_ptr<Region> copy (RegionFactory::create (mr, true)); boost::shared_ptr<Region> copy (RegionFactory::create (mr, true));
playlist->clear_changes (); playlist->clear_changes ();
playlist->add_region (copy, timepos_t (f)); playlist->add_region (copy, timepos_t (f));

View file

@ -1571,7 +1571,8 @@ LuaBindings::common (lua_State* L)
.endClass () .endClass ()
.deriveWSPtrClass <MidiModel, AutomatableSequence<Temporal::Beats> > ("MidiModel") .deriveWSPtrClass <MidiModel, AutomatableSequence<Temporal::Beats> > ("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) .addFunction ("new_note_diff_command", &MidiModel::new_note_diff_command)
.endClass () .endClass ()

View file

@ -92,7 +92,7 @@ MidiModel::new_patch_change_diff_command (const string& name)
void void
MidiModel::apply_command(Session& session, Command* cmd) MidiModel::apply_diff_command_as_commit(Session& session, Command* cmd)
{ {
session.begin_reversible_command (cmd->name()); session.begin_reversible_command (cmd->name());
(*cmd)(); (*cmd)();
@ -101,13 +101,20 @@ MidiModel::apply_command(Session& session, Command* cmd)
} }
void void
MidiModel::apply_command_as_subcommand(Session& session, Command* cmd) MidiModel::apply_diff_command_as_subcommand(Session& session, Command* cmd)
{ {
(*cmd)(); (*cmd)();
session.add_command (cmd); session.add_command (cmd);
set_edited (true); set_edited (true);
} }
void
MidiModel::apply_diff_command_only(Session& session, Command* cmd)
{
(*cmd)();
set_edited (true);
}
/* ************* DIFF COMMAND ********************/ /* ************* DIFF COMMAND ********************/
#define NOTE_DIFF_COMMAND_ELEMENT "NoteDiffCommand" #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); 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 */ /* Patch changes */
@ -1714,7 +1721,7 @@ MidiModel::insert_silence_at_start (TimeType t)
c->change_time (*i, (*i)->time() + 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 */ /* Controllers */
@ -1736,7 +1743,7 @@ MidiModel::insert_silence_at_start (TimeType t)
c->change (*i, (*i)->time() + 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)); ContentsShifted (timecnt_t (t));