Skip to content

Commit

Permalink
refactor zoom focus handling so that all EditingContexts can use the …
Browse files Browse the repository at this point in the history
…same code
  • Loading branch information
pauldavisthefirst committed Dec 29, 2024
1 parent 9b22e16 commit 0a40b50
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 82 deletions.
8 changes: 7 additions & 1 deletion gtk2_ardour/cue_editor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CueEditor::CueEditor (std::string const & name)
{
_history.Changed.connect (history_connection, invalidator (*this), std::bind (&CueEditor::history_changed, this), gui_context());

set_zoom_focus (Editing::ZoomFocusMouse);
set_zoom_focus (Editing::ZoomFocusLeft);
}

CueEditor::~CueEditor ()
Expand Down Expand Up @@ -153,6 +153,12 @@ CueEditor::set_zoom_focus (Editing::ZoomFocus zf)
return;
}

std::string str = zoom_focus_strings[(int)zf];

if (str != zoom_focus_selector.get_text()) {
zoom_focus_selector.set_text (str);
}

if (_zoom_focus != zf) {
_zoom_focus = zf;
ZoomFocusChanged (); /* EMIT SIGNAL */
Expand Down
72 changes: 72 additions & 0 deletions gtk2_ardour/editing_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ static const gchar *_grid_type_strings[] = {
0
};


static const gchar *_zoom_focus_strings[] = {
N_("Left"),
N_("Right"),
N_("Center"),
N_("Playhead"),
N_("Mouse"),
N_("Edit point"),
0
};

Editing::GridType EditingContext::_draw_length (GridTypeNone);
int EditingContext::_draw_velocity (DRAW_VEL_AUTO);
int EditingContext::_draw_channel (DRAW_CHAN_AUTO);
Expand Down Expand Up @@ -174,6 +185,10 @@ EditingContext::EditingContext (std::string const & name)
grid_type_strings = I18N (_grid_type_strings);
}

if (zoom_focus_strings.empty()) {
zoom_focus_strings = I18N (_zoom_focus_strings);
}

snap_mode_button.set_text (_("Snap"));
snap_mode_button.set_name ("mouse mode button");
snap_mode_button.signal_button_press_event().connect (sigc::mem_fun (*this, &EditingContext::snap_mode_button_clicked), false);
Expand Down Expand Up @@ -3157,3 +3172,60 @@ EditingContext::window_event_sample (GdkEvent const * event, double* pcx, double
return pixel_to_sample (canvas_to_timeline (d.x));
}

void
EditingContext::zoom_focus_selection_done (ZoomFocus f)
{
RefPtr<RadioAction> ract = zoom_focus_action (f);
if (ract) {
ract->set_active ();
}
}

RefPtr<RadioAction>
EditingContext::zoom_focus_action (ZoomFocus focus)
{
const char* action = 0;
RefPtr<Action> act;

switch (focus) {
case ZoomFocusLeft:
action = X_("zoom-focus-left");
break;
case ZoomFocusRight:
action = X_("zoom-focus-right");
break;
case ZoomFocusCenter:
action = X_("zoom-focus-center");
break;
case ZoomFocusPlayhead:
action = X_("zoom-focus-playhead");
break;
case ZoomFocusMouse:
action = X_("zoom-focus-mouse");
break;
case ZoomFocusEdit:
action = X_("zoom-focus-edit");
break;
default:
fatal << string_compose (_("programming error: %1: %2"), "Editor: impossible focus type", (int) focus) << endmsg;
abort(); /*NOTREACHED*/
}

return ActionManager::get_radio_action (X_("Zoom"), action);
}

void
EditingContext::zoom_focus_chosen (ZoomFocus focus)
{
/* this is driven by a toggle on a radio group, and so is invoked twice,
once for the item that became inactive and once for the one that became
active.
*/

RefPtr<RadioAction> ract = zoom_focus_action (focus);

if (ract && ract->get_active()) {
set_zoom_focus (focus);
}
}

8 changes: 8 additions & 0 deletions gtk2_ardour/editing_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ class EditingContext : public ARDOUR::SessionHandlePtr, public AxisViewProvider
Editing::ZoomFocus zoom_focus () const { return _zoom_focus; }
sigc::signal<void> ZoomFocusChanged;

void zoom_focus_selection_done (Editing::ZoomFocus);
void zoom_focus_chosen (Editing::ZoomFocus);
Glib::RefPtr<Gtk::RadioAction> zoom_focus_action (Editing::ZoomFocus);

virtual void reposition_and_zoom (samplepos_t, double) = 0;

sigc::signal<void> ZoomChanged;
Expand Down Expand Up @@ -720,6 +724,10 @@ class EditingContext : public ARDOUR::SessionHandlePtr, public AxisViewProvider
virtual void parameter_changed (std::string);
virtual void ui_parameter_changed (std::string);

ArdourWidgets::ArdourDropdown zoom_focus_selector;
std::vector<std::string> zoom_focus_strings;
virtual void build_zoom_focus_menu () = 0;

bool _mouse_changed_selection;
ArdourMarker* entered_marker;
TimeAxisView* entered_track;
Expand Down
32 changes: 6 additions & 26 deletions gtk2_ardour/editor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,6 @@ static const gchar *_ripple_mode_strings[] = {
0
};

static const gchar *_zoom_focus_strings[] = {
N_("Left"),
N_("Right"),
N_("Center"),
N_("Playhead"),
N_("Mouse"),
N_("Edit point"),
0
};

#ifdef USE_RUBBERBAND
static const gchar *_rb_opt_strings[] = {
N_("Mushy"),
Expand Down Expand Up @@ -407,7 +397,6 @@ Editor::Editor ()
selection_op_history.clear();
before.clear();

zoom_focus_strings = I18N (_zoom_focus_strings);
edit_mode_strings = I18N (_edit_mode_strings);
ripple_mode_strings = I18N (_ripple_mode_strings);
edit_point_strings = I18N (_edit_point_strings);
Expand Down Expand Up @@ -3182,24 +3171,15 @@ Editor::build_zoom_focus_menu ()
{
using namespace Menu_Helpers;

zoom_focus_selector.AddMenuElem (MenuElem (zoom_focus_strings[(int)ZoomFocusLeft], sigc::bind (sigc::mem_fun(*this, &Editor::zoom_focus_selection_done), (ZoomFocus) ZoomFocusLeft)));
zoom_focus_selector.AddMenuElem (MenuElem (zoom_focus_strings[(int)ZoomFocusRight], sigc::bind (sigc::mem_fun(*this, &Editor::zoom_focus_selection_done), (ZoomFocus) ZoomFocusRight)));
zoom_focus_selector.AddMenuElem (MenuElem (zoom_focus_strings[(int)ZoomFocusCenter], sigc::bind (sigc::mem_fun(*this, &Editor::zoom_focus_selection_done), (ZoomFocus) ZoomFocusCenter)));
zoom_focus_selector.AddMenuElem (MenuElem (zoom_focus_strings[(int)ZoomFocusPlayhead], sigc::bind (sigc::mem_fun(*this, &Editor::zoom_focus_selection_done), (ZoomFocus) ZoomFocusPlayhead)));
zoom_focus_selector.AddMenuElem (MenuElem (zoom_focus_strings[(int)ZoomFocusMouse], sigc::bind (sigc::mem_fun(*this, &Editor::zoom_focus_selection_done), (ZoomFocus) ZoomFocusMouse)));
zoom_focus_selector.AddMenuElem (MenuElem (zoom_focus_strings[(int)ZoomFocusEdit], sigc::bind (sigc::mem_fun(*this, &Editor::zoom_focus_selection_done), (ZoomFocus) ZoomFocusEdit)));
zoom_focus_selector.AddMenuElem (MenuElem (zoom_focus_strings[(int)ZoomFocusLeft], sigc::bind (sigc::mem_fun(*this, &EditingContext::zoom_focus_selection_done), (ZoomFocus) ZoomFocusLeft)));
zoom_focus_selector.AddMenuElem (MenuElem (zoom_focus_strings[(int)ZoomFocusRight], sigc::bind (sigc::mem_fun(*this, &EditingContext::zoom_focus_selection_done), (ZoomFocus) ZoomFocusRight)));
zoom_focus_selector.AddMenuElem (MenuElem (zoom_focus_strings[(int)ZoomFocusCenter], sigc::bind (sigc::mem_fun(*this, &EditingContext::zoom_focus_selection_done), (ZoomFocus) ZoomFocusCenter)));
zoom_focus_selector.AddMenuElem (MenuElem (zoom_focus_strings[(int)ZoomFocusPlayhead], sigc::bind (sigc::mem_fun(*this, &EditingContext::zoom_focus_selection_done), (ZoomFocus) ZoomFocusPlayhead)));
zoom_focus_selector.AddMenuElem (MenuElem (zoom_focus_strings[(int)ZoomFocusMouse], sigc::bind (sigc::mem_fun(*this, &EditingContext::zoom_focus_selection_done), (ZoomFocus) ZoomFocusMouse)));
zoom_focus_selector.AddMenuElem (MenuElem (zoom_focus_strings[(int)ZoomFocusEdit], sigc::bind (sigc::mem_fun(*this, &EditingContext::zoom_focus_selection_done), (ZoomFocus) ZoomFocusEdit)));
zoom_focus_selector.set_sizing_texts (zoom_focus_strings);
}

void
Editor::zoom_focus_selection_done (ZoomFocus f)
{
RefPtr<RadioAction> ract = zoom_focus_action (f);
if (ract) {
ract->set_active ();
}
}

void
Editor::marker_click_behavior_selection_done (MarkerClickBehavior m)
{
Expand Down
7 changes: 0 additions & 7 deletions gtk2_ardour/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1786,14 +1786,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList
//zoom focus menu stuff
Editing::ZoomFocus effective_zoom_focus() const;

ArdourWidgets::ArdourDropdown zoom_focus_selector;
void zoom_focus_selection_done (Editing::ZoomFocus);
void build_zoom_focus_menu ();
std::vector<std::string> zoom_focus_strings;

void zoom_focus_chosen (Editing::ZoomFocus);

Glib::RefPtr<Gtk::RadioAction> zoom_focus_action (Editing::ZoomFocus);

/* Marker Click Radio */
Glib::RefPtr<Gtk::RadioAction> marker_click_behavior_action (Editing::MarkerClickBehavior);
Expand Down
48 changes: 0 additions & 48 deletions gtk2_ardour/editor_actions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1022,39 +1022,6 @@ Editor::marker_click_behavior_action (MarkerClickBehavior m)
return ActionManager::get_radio_action (X_("MarkerClickBehavior"), action);
}

RefPtr<RadioAction>
Editor::zoom_focus_action (ZoomFocus focus)
{
const char* action = 0;
RefPtr<Action> act;

switch (focus) {
case ZoomFocusLeft:
action = X_("zoom-focus-left");
break;
case ZoomFocusRight:
action = X_("zoom-focus-right");
break;
case ZoomFocusCenter:
action = X_("zoom-focus-center");
break;
case ZoomFocusPlayhead:
action = X_("zoom-focus-playhead");
break;
case ZoomFocusMouse:
action = X_("zoom-focus-mouse");
break;
case ZoomFocusEdit:
action = X_("zoom-focus-edit");
break;
default:
fatal << string_compose (_("programming error: %1: %2"), "Editor: impossible focus type", (int) focus) << endmsg;
abort(); /*NOTREACHED*/
}

return ActionManager::get_radio_action (X_("Zoom"), action);
}

void
Editor::toggle_sound_midi_notes ()
{
Expand All @@ -1065,21 +1032,6 @@ Editor::toggle_sound_midi_notes ()
}
}

void
Editor::zoom_focus_chosen (ZoomFocus focus)
{
/* this is driven by a toggle on a radio group, and so is invoked twice,
once for the item that became inactive and once for the one that became
active.
*/

RefPtr<RadioAction> ract = zoom_focus_action (focus);

if (ract && ract->get_active()) {
set_zoom_focus (focus);
}
}

void
Editor::marker_click_behavior_chosen (Editing::MarkerClickBehavior m)
{
Expand Down
21 changes: 21 additions & 0 deletions gtk2_ardour/midi_cue_editor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,13 @@ MidiCueEditor::build_upper_toolbar ()
_toolbar_outer->pack_start (full_zoom_button, false, false);
_toolbar_outer->pack_start (*_toolbar_inner, true, false);

build_zoom_focus_menu ();
std::string str = zoom_focus_strings[(int)_zoom_focus];
if (str != zoom_focus_selector.get_text()) {
zoom_focus_selector.set_text (str);
}
_toolbar_outer->pack_start (zoom_focus_selector, true, false);

_toolbox.pack_start (*_toolbar_outer, false, false);

Bindings* pr_bindings = Bindings::get_bindings (X_("Pianoroll"));
Expand Down Expand Up @@ -2026,3 +2033,17 @@ MidiCueEditor::set_note_mode (NoteMode nm)
}
}
}

void
MidiCueEditor::build_zoom_focus_menu ()
{
using namespace Gtk::Menu_Helpers;
using namespace Editing;

zoom_focus_selector.AddMenuElem (MenuElem (zoom_focus_strings[(int)ZoomFocusLeft], sigc::bind (sigc::mem_fun(*this, &EditingContext::zoom_focus_selection_done), (ZoomFocus) ZoomFocusLeft)));
zoom_focus_selector.AddMenuElem (MenuElem (zoom_focus_strings[(int)ZoomFocusRight], sigc::bind (sigc::mem_fun(*this, &EditingContext::zoom_focus_selection_done), (ZoomFocus) ZoomFocusRight)));
zoom_focus_selector.AddMenuElem (MenuElem (zoom_focus_strings[(int)ZoomFocusCenter], sigc::bind (sigc::mem_fun(*this, &EditingContext::zoom_focus_selection_done), (ZoomFocus) ZoomFocusCenter)));
zoom_focus_selector.AddMenuElem (MenuElem (zoom_focus_strings[(int)ZoomFocusMouse], sigc::bind (sigc::mem_fun(*this, &EditingContext::zoom_focus_selection_done), (ZoomFocus) ZoomFocusMouse)));
zoom_focus_selector.set_sizing_texts (zoom_focus_strings);
}

1 change: 1 addition & 0 deletions gtk2_ardour/midi_cue_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ class MidiCueEditor : public CueEditor

void automation_state_changed ();

void build_zoom_focus_menu ();
};


0 comments on commit 0a40b50

Please sign in to comment.