move cut/copy/delete/paste operations into EditingContext

derived classes (Editor and Pianoroll) provide ::cut_copy() to wrap the
context-specific logic, and then both defer to MidiView for MIDI-specific
operations.

Note that this also changes several action names in ardour.keys.in
This commit is contained in:
Paul Davis 2025-01-14 15:31:53 -07:00
parent 13161a3975
commit 4e8591da99
8 changed files with 136 additions and 37 deletions

View file

@ -231,10 +231,10 @@ This mode provides many different operations on both regions and control points,
@editing|Editing/alternate-alternate-redo| <@PRIMARY@><@TERTIARY@>z|redo
@vis|Editor/toggle-zoom| <@TERTIARY@>z|toggle last 2 zoom states
@aep|Region/align-regions-sync-relative| x|align sync points (relative)
@edit|Editor/editor-cut| <@PRIMARY@>x|cut
@editing|Editing/editor-cut| <@PRIMARY@>x|cut
@edit|Editor/cut-paste-section| <@PRIMARY@><@TERTIARY@>x|cut \& paste section
@mmode|Editor/set-mouse-mode-cut| c|cut mode
@edit|Editor/editor-copy| <@PRIMARY@>c|copy
@editing|Editing/editor-copy| <@PRIMARY@>c|copy
@wvis|Common/show-trigger| <@SECONDARY@>c|show cues page
@edit|Editor/editor-crop| <@PRIMARY@><@SECONDARY@>c|crop range
@edit|Editor/copy-paste-section| <@PRIMARY@><@TERTIARY@>c|copy \& paste section
@ -242,7 +242,7 @@ This mode provides many different operations on both regions and control points,
@edit|Editor/alternate-delete-section| <@PRIMARY@><@TERTIARY@>BackSpace|delete section
@edit|Editor/editor-consolidate| <@SECONDARY@><@TERTIARY@>c|consolidate range
@rop|Region/set-region-sync-position| v|set region sync point
@edit|Editor/editor-paste| <@PRIMARY@>v|paste
@editing|Editing/editor-paste| <@PRIMARY@>v|paste
@edit|Editor/ToggleJadeo| <@SECONDARY@>v|video window
@wvis|Common/toggle-meterbridge| <@SECONDARY@>b|show meter bridge
@edtrk|Editor/track-record-enable-toggle| <@TERTIARY@>b|toggle track rec-enable
@ -294,8 +294,8 @@ This mode provides many different operations on both regions and control points,
@vis|Editor/scroll-tracks-up| Page_Up|scroll up (page)
@movp|Transport/GotoStart| Home|to start marker
@movp|Transport/GotoEnd| End|to end marker
@edit|Editor/editor-delete| Delete|delete
@edit|Editor/alternate-editor-delete| BackSpace|backspace (delete)
@editing|Editing/editor-delete| Delete|delete
@editing|Editing/alternate-editor-delete| BackSpace|backspace (delete)
;; this one is super-global, so we put it in the session group but don't show
;; it on cheat sheets etc.

View file

@ -306,6 +306,13 @@ EditingContext::register_common_actions (Bindings* common_bindings)
redo_action = reg_sens (_common_actions, "redo", _("Redo"), []() { current_editing_context()->redo(1U) ; });
alternate_redo_action = reg_sens (_common_actions, "alternate-redo", _("Redo"), []() { current_editing_context()->redo(1U) ; });
alternate_alternate_redo_action = reg_sens (_common_actions, "alternate-alternate-redo", _("Redo"), []() { current_editing_context()->redo(1U) ; });
reg_sens (_common_actions, "editor-delete", _("Delete"), []() { current_editing_context()->delete_() ; });
reg_sens (_common_actions, "alternate-editor-delete", _("Delete"), []() { current_editing_context()->delete_() ; });
reg_sens (_common_actions, "editor-cut", _("Cut"), []() { current_editing_context()->cut() ; });
reg_sens (_common_actions, "editor-copy", _("Copy"), []() { current_editing_context()->copy() ; });
reg_sens (_common_actions, "editor-paste", _("Paste"), []() { current_editing_context()->keyboard_paste() ; });
}
void
@ -3248,3 +3255,24 @@ EditingContext::zoom_focus_chosen (ZoomFocus focus)
}
}
void
EditingContext::alt_delete_ ()
{
delete_ ();
}
/** Cut selected regions, automation points or a time range */
void
EditingContext::cut ()
{
cut_copy (Cut);
}
/** Copy selected regions, automation points or a time range */
void
EditingContext::copy ()
{
cut_copy (Copy);
}

View file

@ -463,6 +463,17 @@ class EditingContext : public ARDOUR::SessionHandlePtr, public AxisViewProvider
*/
bool mouse_sample (samplepos_t&, bool& in_track_canvas) const;
/* editing actions */
virtual void delete_ () = 0;
virtual void paste (float times, bool from_context_menu) = 0;
virtual void keyboard_paste () = 0;
virtual void cut_copy (Editing::CutCopyOp) = 0;
void cut ();
void copy ();
void alt_delete_ ();
protected:
std::string _name;
bool within_track_canvas;

View file

@ -1124,7 +1124,6 @@ private:
Temporal::timepos_t last_paste_pos;
unsigned paste_count;
void cut_copy (Editing::CutCopyOp);
bool can_cut_copy () const;
void cut_copy_points (Editing::CutCopyOp, Temporal::timepos_t const & earliest);
void cut_copy_regions (Editing::CutCopyOp, RegionSelection&);
@ -1224,17 +1223,15 @@ private:
void split_region ();
void delete_ ();
void alt_delete_ ();
void cut ();
void copy ();
void paste (float times, bool from_context_menu);
void keyboard_paste ();
void cut_copy (Editing::CutCopyOp);
void place_transient ();
void remove_transient (ArdourCanvas::Item* item);
void snap_regions_to_grid ();
void close_region_gaps ();
void keyboard_paste ();
void region_from_selection ();
void create_region_from_selection (std::vector<std::shared_ptr<ARDOUR::Region> >&);

View file

@ -421,15 +421,9 @@ Editor::register_actions ()
act = reg_sens (editor_actions, "editor-loudness-assistant", _("Loudness Assistant"), sigc::bind (sigc::mem_fun(*this, &Editor::loudness_assistant), true));
ActionManager::time_selection_sensitive_actions.push_back (act);
reg_sens (editor_actions, "editor-cut", _("Cut"), sigc::mem_fun(*this, &Editor::cut));
reg_sens (editor_actions, "editor-delete", _("Delete"), sigc::mem_fun(*this, &Editor::delete_));
reg_sens (editor_actions, "alternate-editor-delete", _("Delete"), sigc::mem_fun(*this, &Editor::delete_));
reg_sens (editor_actions, "split-region", _("Split/Separate"), sigc::mem_fun (*this, &Editor::split_region));
reg_sens (editor_actions, "editor-copy", _("Copy"), sigc::mem_fun(*this, &Editor::copy));
reg_sens (editor_actions, "editor-paste", _("Paste"), sigc::mem_fun(*this, &Editor::keyboard_paste));
reg_sens (editor_actions, "editor-fade-range", _("Fade Range Selection"), sigc::mem_fun(*this, &Editor::fade_range));
act = ActionManager::register_action (editor_actions, "set-tempo-from-edit-range", _("Set Tempo from Edit Range = Bar"), sigc::mem_fun(*this, &Editor::use_range_as_bar));

View file

@ -4266,27 +4266,6 @@ Editor::delete_ ()
}
}
void
Editor::alt_delete_ ()
{
delete_ ();
}
/** Cut selected regions, automation points or a time range */
void
Editor::cut ()
{
cut_copy (Cut);
}
/** Copy selected regions, automation points or a time range */
void
Editor::copy ()
{
cut_copy (Copy);
}
/** @return true if a Cut, Copy or Clear is possible */
bool
Editor::can_cut_copy () const

View file

@ -2103,3 +2103,88 @@ Pianoroll::point_selection_changed ()
view->point_selection_changed ();
}
}
void
Pianoroll::delete_ ()
{
/* Editor has a lot to do here, potentially. But we don't */
cut_copy (Editing::Delete);
}
void
Pianoroll::paste (float times, bool from_context_menu)
{
if (view) {
// view->paste (Editing::Cut);
}
}
void
Pianoroll::keyboard_paste ()
{
}
/** Cut, copy or clear selected regions, automation points or a time range.
* @param op Operation (Delete, Cut, Copy or Clear)
*/
void
Pianoroll::cut_copy (Editing::CutCopyOp op)
{
using namespace Editing;
/* only cancel selection if cut/copy is successful.*/
std::string opname;
switch (op) {
case Delete:
opname = _("delete");
break;
case Cut:
opname = _("cut");
break;
case Copy:
opname = _("copy");
break;
case Clear:
opname = _("clear");
break;
}
/* if we're deleting something, and the mouse is still pressed,
the thing we started a drag for will be gone when we release
the mouse button(s). avoid this. see part 2 at the end of
this function.
*/
if (op == Delete || op == Cut || op == Clear) {
if (_drags->active ()) {
_drags->abort ();
}
}
if (op != Delete) { //"Delete" doesn't change copy/paste buf
cut_buffer->clear ();
}
switch (mouse_mode) {
case MouseDraw:
case MouseContent:
if (view) {
begin_reversible_command (opname + ' ' + X_("MIDI"));
view->cut_copy_clear (op);
commit_reversible_command ();
}
return;
default:
break;
}
bool did_edit = false;
if (op == Delete || op == Cut || op == Clear) {
_drags->abort ();
}
}

View file

@ -126,6 +126,11 @@ class Pianoroll : public CueEditor
void full_zoom_clicked();
void delete_ ();
void paste (float times, bool from_context_menu);
void keyboard_paste ();
void cut_copy (Editing::CutCopyOp);
protected:
void register_actions ();