From 360261f110566f7c6e95cb785706c7dbf03f8c43 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 12 Dec 2018 11:00:43 -0500 Subject: [PATCH] replace ::cast_dynamic() with relevant ActionManager::get_*_action() calls --- libs/surfaces/maschine2/callbacks.cc | 93 +++++++++------------------- 1 file changed, 28 insertions(+), 65 deletions(-) diff --git a/libs/surfaces/maschine2/callbacks.cc b/libs/surfaces/maschine2/callbacks.cc index b95f29032c..9a519740d0 100644 --- a/libs/surfaces/maschine2/callbacks.cc +++ b/libs/surfaces/maschine2/callbacks.cc @@ -49,29 +49,20 @@ Maschine2::connect_signals () session->history().Changed.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&Maschine2::notify_history_changed, this), this); /* Actions */ - Glib::RefPtr act; + Glib::RefPtr tact; + Glib::RefPtr ract; #if 0 - act = ActionManager::find_action (X_("Editor"), X_("ToggleMeasureVisibility")); - if (act) { - Glib::RefPtr tact = Glib::RefPtr::cast_dynamic (act); - tact->signal_toggled ().connect (sigc::mem_fun (*this, &Maschine2::notify_grid_change)); - } + tact = ActionManager::find_toggle_action (X_("Editor"), X_("ToggleMeasureVisibility")); + tact->signal_toggled ().connect (sigc::mem_fun (*this, &Maschine2::notify_grid_change)); #endif - act = ActionManager::find_action (X_("Editor"), X_("snap-off")); - if (act) { - Glib::RefPtr ract = Glib::RefPtr::cast_dynamic (act); - ract->signal_toggled ().connect (sigc::mem_fun (*this, &Maschine2::notify_snap_change)); - } - act = ActionManager::find_action (X_("Editor"), X_("snap-magnetic")); - if (act) { - Glib::RefPtr ract = Glib::RefPtr::cast_dynamic (act); - ract->signal_toggled ().connect (sigc::mem_fun (*this, &Maschine2::notify_snap_change)); - } - act = ActionManager::find_action (X_("Editor"), X_("snap-normal")); - if (act) { - Glib::RefPtr ract = Glib::RefPtr::cast_dynamic (act); - ract->signal_toggled ().connect (sigc::mem_fun (*this, &Maschine2::notify_snap_change)); - } + ract = ActionManager::find_radio_action (X_("Editor"), X_("snap-off")); + ract->signal_toggled ().connect (sigc::mem_fun (*this, &Maschine2::notify_snap_change)); + + ract = ActionManager::find_radio_action (X_("Editor"), X_("snap-magnetic")); + ract->signal_toggled ().connect (sigc::mem_fun (*this, &Maschine2::notify_snap_change)); + + ract = ActionManager::find_radio_action (X_("Editor"), X_("snap-normal")); + ract->signal_toggled ().connect (sigc::mem_fun (*this, &Maschine2::notify_snap_change)); /* Surface events */ _ctrl->button (M2Contols::Play)->released.connect_same_thread (button_connections, boost::bind (&Maschine2::button_play, this)); @@ -167,11 +158,8 @@ Maschine2::notify_parameter_changed (std::string param) void Maschine2::notify_grid_change () { - Glib::RefPtr act = ActionManager::find_action (X_("Editor"), X_("ToggleMeasureVisibility")); - if (act) { - Glib::RefPtr tact = Glib::RefPtr::cast_dynamic (act); - _ctrl->button (M2Contols::Grid)->set_color (tact->get_active () ? COLOR_WHITE : 0); - } + Glib::RefPtr tact = ActionManager::find_toggle_action (X_("Editor"), X_("ToggleMeasureVisibility")); + _ctrl->button (M2Contols::Grid)->set_color (tact->get_active () ? COLOR_WHITE : 0); } #endif @@ -183,16 +171,10 @@ Maschine2::notify_snap_change () return; } - Glib::RefPtr act = ActionManager::find_action (X_("Editor"), X_("snap-magnetic")); - if (act) { - Glib::RefPtr ract = Glib::RefPtr::cast_dynamic (act); - if (ract->get_active ()) { rgba = COLOR_GRAY; } - } - act = ActionManager::find_action (X_("Editor"), X_("snap-normal")); - if (act) { - Glib::RefPtr ract = Glib::RefPtr::cast_dynamic (act); - if (ract->get_active ()) { rgba = COLOR_WHITE; } - } + Glib::RefPtr ract = ActionManager::find_radio_action (X_("Editor"), X_("snap-magnetic")); + if (ract->get_active ()) { rgba = COLOR_GRAY; } + ract = ActionManager::find_radio_action (X_("Editor"), X_("snap-normal")); + if (ract->get_active ()) { rgba = COLOR_WHITE; } _ctrl->button (M2Contols::Grid)->set_color (rgba); } @@ -257,11 +239,8 @@ Maschine2::button_action (const std::string& group, const std::string& item) void Maschine2::button_grid () { - Glib::RefPtr act = ActionManager::find_action (X_("Editor"), X_("ToggleMeasureVisibility")); - if (act) { - Glib::RefPtr tact = Glib::RefPtr::cast_dynamic (act); - tact->set_active (!tact->get_active ()); - } + Glib::RefPtr tact = ActionManager::find_toggle_action (X_("Editor"), X_("ToggleMeasureVisibility")); + tact->set_active (!tact->get_active ()); } #endif @@ -288,34 +267,18 @@ Maschine2::button_snap_released () _ctrl->button (M2Contols::Grid)->set_blinking (false); const char* action = 0; - Glib::RefPtr act = ActionManager::find_action (X_("Editor"), X_("snap-off")); - if (act) { - Glib::RefPtr ract = Glib::RefPtr::cast_dynamic (act); - if (ract->get_active ()) { action = "snap-normal"; } - } - act = ActionManager::find_action (X_("Editor"), X_("snap-normal")); - if (act) { - Glib::RefPtr ract = Glib::RefPtr::cast_dynamic (act); - if (ract->get_active ()) { action = "snap-magnetic"; } - } + Glib::RefPtr ract = ActionManager::find_radio_action (X_("Editor"), X_("snap-off")); + if (ract->get_active ()) { action = "snap-normal"; } - act = ActionManager::find_action (X_("Editor"), X_("snap-magnetic")); - if (act) { - Glib::RefPtr ract = Glib::RefPtr::cast_dynamic (act); - if (ract->get_active ()) { action = "snap-off"; } - } + ract = ActionManager::find_radio_action (X_("Editor"), X_("snap-normal")); + if (ract->get_active ()) { action = "snap-magnetic"; } - if (!action) { - assert (0); - return; - } + ract = ActionManager::find_radio_action (X_("Editor"), X_("snap-magnetic")); + if (ract->get_active ()) { action = "snap-off"; } - act = ActionManager::find_action (X_("Editor"), action); - if (act) { - Glib::RefPtr ract = Glib::RefPtr::cast_dynamic (act); - ract->set_active (true); - } + ract = ActionManager::find_radio_action (X_("Editor"), action); + ract->set_active (true); } /* Master mode + state -- main encoder fn */