MidiView: adjust API to use when brushing multiple notes

This commit is contained in:
Paul Davis 2025-10-31 13:23:37 -06:00
parent deafaa904f
commit dcb482e74d
2 changed files with 24 additions and 8 deletions

View file

@ -841,7 +841,7 @@ MidiView::show_list_editor ()
* \param snap_t true to snap t to the grid, otherwise false. * \param snap_t true to snap t to the grid, otherwise false.
*/ */
void void
MidiView::create_note_at (timepos_t const & source_relative_start, double y, Temporal::Beats length, uint32_t state, bool shift_snap) MidiView::create_note_at (timepos_t const & source_relative_start, double y, Temporal::Beats length, uint32_t state, bool shift_snap, bool control_reversible_command)
{ {
if (!_model) { if (!_model) {
return; return;
@ -865,16 +865,18 @@ MidiView::create_note_at (timepos_t const & source_relative_start, double y, Tem
return; return;
} }
start_note_diff_command(_("add note")); start_note_diff_command(_("add note"), control_reversible_command);
note_diff_add_note (new_note, true, false); note_diff_add_note (new_note, true, false);
apply_note_diff(); apply_note_diff (!control_reversible_command);
// XXX _editing_context.set_selected_midi_region_view (*this); // XXX _editing_context.set_selected_midi_region_view (*this);
list<Evoral::event_id_t> to_be_selected; list<Evoral::event_id_t> to_be_selected;
to_be_selected.push_back (new_note->id()); to_be_selected.push_back (new_note->id());
select_notes (to_be_selected, true); select_notes (to_be_selected, true);
play_midi_note (new_note); if (do_commit) {
play_midi_note (new_note);
}
} }
void void
@ -906,20 +908,33 @@ MidiView::display_model (std::shared_ptr<MidiModel> model)
} }
void void
MidiView::start_note_diff_command (string name) MidiView::start_note_diff_command (string name, bool with_reversible_command)
{ {
if (!_model) { if (!_model) {
return; return;
} }
if (!_note_diff_command) { if (!_note_diff_command) {
_editing_context.begin_reversible_command (name); if (with_reversible_command) {
_editing_context.begin_reversible_command (name);
}
_note_diff_command = _model->new_note_diff_command (name); _note_diff_command = _model->new_note_diff_command (name);
} else { } else {
std::cerr << "ERROR: start_note_diff_command command called, but a note_diff_command was already underway" << std::endl; std::cerr << "ERROR: start_note_diff_command command called, but a note_diff_command was already underway" << std::endl;
} }
} }
void
MidiView::end_note_diff_command ()
{
if (!_model) {
return;
}
_editing_context.commit_reversible_command ();
_note_diff_command = nullptr;
}
void void
MidiView::note_diff_add_note (const std::shared_ptr<NoteType> note, bool selected, bool show_velocity) MidiView::note_diff_add_note (const std::shared_ptr<NoteType> note, bool selected, bool show_velocity)
{ {

View file

@ -193,7 +193,8 @@ class MidiView : public virtual sigc::trackable, public LineMerger
std::shared_ptr<ARDOUR::MidiModel> model() const { return _model; } std::shared_ptr<ARDOUR::MidiModel> model() const { return _model; }
/* note_diff commands should start here; this initiates an undo record */ /* note_diff commands should start here; this initiates an undo record */
void start_note_diff_command (std::string name = "midi edit"); void start_note_diff_command (std::string name = "midi edit", bool with_reversible_command = true);
void end_note_diff_command ();
void note_diff_add_change (NoteBase* ev, ARDOUR::MidiModel::NoteDiffCommand::Property, uint8_t val); void note_diff_add_change (NoteBase* ev, ARDOUR::MidiModel::NoteDiffCommand::Property, uint8_t val);
void note_diff_add_change (NoteBase* ev, ARDOUR::MidiModel::NoteDiffCommand::Property, Temporal::Beats val); void note_diff_add_change (NoteBase* ev, ARDOUR::MidiModel::NoteDiffCommand::Property, Temporal::Beats val);
@ -328,7 +329,7 @@ class MidiView : public virtual sigc::trackable, public LineMerger
* \param state the keyboard modifier mask for the canvas event (click). * \param state the keyboard modifier mask for the canvas event (click).
* \param shift_snap true alters snap behavior to round down always (false if the gui has already done that). * \param shift_snap true alters snap behavior to round down always (false if the gui has already done that).
*/ */
void create_note_at (Temporal::timepos_t const & t, double y, Temporal::Beats length, uint32_t state, bool shift_snap); void create_note_at (Temporal::timepos_t const & t, double y, Temporal::Beats length, uint32_t state, bool shift_snap, bool control_reversible_command = true);
/** An external request to clear the note selection, remove MRV from editor /** An external request to clear the note selection, remove MRV from editor
* selection. * selection.