From bba9ac20d9ec68f8caab52d792d25a5b923ca326 Mon Sep 17 00:00:00 2001 From: Ben Loftis Date: Thu, 6 Dec 2018 20:57:33 -0600 Subject: [PATCH] Monitor Section actions: Allow use-monitor-section to be controlled by both menu and session-options dialog. --- gtk2_ardour/ardour_ui2.cc | 6 ++- gtk2_ardour/mixer_ui.cc | 57 ++++++++++++++-------------- gtk2_ardour/mixer_ui.h | 2 + gtk2_ardour/option_editor.cc | 49 ++++++++++++++++++++++++ gtk2_ardour/option_editor.h | 29 ++++++++++++++ gtk2_ardour/session_option_editor.cc | 34 ++--------------- gtk2_ardour/session_option_editor.h | 3 -- 7 files changed, 116 insertions(+), 64 deletions(-) diff --git a/gtk2_ardour/ardour_ui2.cc b/gtk2_ardour/ardour_ui2.cc index 55cb0850ca..97d639fc1b 100644 --- a/gtk2_ardour/ardour_ui2.cc +++ b/gtk2_ardour/ardour_ui2.cc @@ -821,7 +821,11 @@ ARDOUR_UI::update_title () void ARDOUR_UI::toggle_use_monitor_section () { - bool yn = !(_session->monitor_out() != 0); + RefPtr act = ActionManager::get_action (X_("Monitor"), "UseMonitorSection"); + assert (act); RefPtr tact = Glib::RefPtr::cast_dynamic (act); + assert (tact); + + bool yn = tact->get_active (); if (yn) { _session->add_monitor_section (); diff --git a/gtk2_ardour/mixer_ui.cc b/gtk2_ardour/mixer_ui.cc index 5ec3203654..39ddb6b08e 100644 --- a/gtk2_ardour/mixer_ui.cc +++ b/gtk2_ardour/mixer_ui.cc @@ -571,6 +571,8 @@ Mixer_UI::add_stripables (StripableList& slist) if (mnode) { _monitor_section->tearoff().set_state (*mnode); } + + set_monitor_action_sensitivity(true); } out_packer.pack_end (_monitor_section->tearoff(), false, false); @@ -2631,26 +2633,36 @@ Mixer_UI::set_axis_targets_for_operation () } +void +Mixer_UI::set_monitor_action_sensitivity (bool yn) +{ + Glib::RefPtr act; + Glib::RefPtr tact; + + act = ActionManager::get_action (X_("Monitor"), "UseMonitorSection"); + assert (act); tact = Glib::RefPtr::cast_dynamic (act); + assert (tact); tact->set_active ( yn ); + + act = ActionManager::get_action (X_("Monitor"), "monitor-cut-all"); + assert (act); tact = Glib::RefPtr::cast_dynamic (act); + assert (tact); tact->set_sensitive ( yn ); + + act = ActionManager::get_action (X_("Monitor"), "monitor-dim-all"); + assert (act); tact = Glib::RefPtr::cast_dynamic (act); + assert (tact); tact->set_sensitive ( yn ); + + act = ActionManager::get_action (X_("Monitor"), "monitor-mono"); + assert (act); tact = Glib::RefPtr::cast_dynamic (act); + assert (tact); tact->set_sensitive ( yn ); +} + void Mixer_UI::monitor_section_going_away () { /* Set sensitivity based on existence of the monitor bus */ - Glib::RefPtr act; - Glib::RefPtr tact; - - act = ActionManager::get_action (X_("Monitor"), "monitor-cut-all"); - assert (act); tact = Glib::RefPtr::cast_dynamic (act); - assert (tact); tact->set_sensitive ( false ); - - act = ActionManager::get_action (X_("Monitor"), "monitor-dim-all"); - assert (act); tact = Glib::RefPtr::cast_dynamic (act); - assert (tact); tact->set_sensitive ( false ); - - act = ActionManager::get_action (X_("Monitor"), "monitor-mono"); - assert (act); tact = Glib::RefPtr::cast_dynamic (act); - assert (tact); tact->set_sensitive ( false ); - + set_monitor_action_sensitivity(false); + if (_monitor_section) { XMLNode* ui_node = Config->extra_xml(X_("UI")); @@ -2730,20 +2742,7 @@ Mixer_UI::restore_mixer_space () void Mixer_UI::monitor_section_attached () { - /* Set sensitivity based on existence of the monitor bus */ - - Glib::RefPtr act; - - act = ActionManager::get_action (X_("Monitor"), "monitor-cut-all"); - assert (act); act->set_sensitive ( true ); - - act = ActionManager::get_action (X_("Monitor"), "monitor-dim-all"); - assert (act); act->set_sensitive ( true ); - - act = ActionManager::get_action (X_("Monitor"), "monitor-mono"); - assert (act); act->set_sensitive ( true ); - - act = myactions.find_action ("Mixer", "ToggleMonitorSection"); + Glib::RefPtr act = myactions.find_action ("Mixer", "ToggleMonitorSection"); assert (act); act->set_sensitive (true); Glib::RefPtr tact = Glib::RefPtr::cast_dynamic(act); diff --git a/gtk2_ardour/mixer_ui.h b/gtk2_ardour/mixer_ui.h index 5429fa2bb4..aab4480d30 100644 --- a/gtk2_ardour/mixer_ui.h +++ b/gtk2_ardour/mixer_ui.h @@ -378,6 +378,8 @@ private: friend class MixerGroupTabs; + void set_monitor_action_sensitivity (bool); + void monitor_section_going_away (); void monitor_section_attached (); diff --git a/gtk2_ardour/option_editor.cc b/gtk2_ardour/option_editor.cc index b685e78947..4d51bbce10 100644 --- a/gtk2_ardour/option_editor.cc +++ b/gtk2_ardour/option_editor.cc @@ -202,6 +202,55 @@ RcActionButton::add_to_page (OptionEditorPage *p) } } +/*--------------------------*/ + +CheckOption::CheckOption (string const & i, string const & n, Glib::RefPtr act) +{ + _button = manage (new CheckButton); + _label = manage (new Label); + _label->set_markup (n); + _button->add (*_label); + _button->signal_toggled().connect (sigc::mem_fun (*this, &CheckOption::toggled)); + + Gtkmm2ext::Activatable::set_related_action (act); + if (_action) { + + action_sensitivity_changed (); + + Glib::RefPtr tact = Glib::RefPtr::cast_dynamic (_action); + if (tact) { + action_toggled (); + tact->signal_toggled().connect (sigc::mem_fun (*this, &CheckOption::action_toggled)); + } + + _action->connect_property_changed ("sensitive", sigc::mem_fun (*this, &CheckOption::action_sensitivity_changed)); + } +} + +void +CheckOption::action_toggled () +{ + Glib::RefPtr tact = Glib::RefPtr::cast_dynamic (_action); + if (tact) { + _button->set_active(tact->get_active()); + } +} + +void +CheckOption::add_to_page (OptionEditorPage* p) +{ + add_widget_to_page (p, _button); +} + +void +CheckOption::toggled () +{ + Glib::RefPtr tact = Glib::RefPtr::cast_dynamic (_action); + + tact->set_active( _button->get_active() ); +} + + /*--------------------------*/ BoolOption::BoolOption (string const & i, string const & n, sigc::slot g, sigc::slot s) diff --git a/gtk2_ardour/option_editor.h b/gtk2_ardour/option_editor.h index 132d260c05..d6738889f3 100644 --- a/gtk2_ardour/option_editor.h +++ b/gtk2_ardour/option_editor.h @@ -33,6 +33,7 @@ #include "widgets/slider_controller.h" +#include "actions.h" #include "ardour_window.h" #include "audio_clock.h" #include "ardour/types.h" @@ -187,6 +188,34 @@ protected: std::string _name; }; +/** Just a Gtk Checkbutton, masquerading as an option component */ +class CheckOption : public OptionEditorComponent , public Gtkmm2ext::Activatable +{ +public: + CheckOption (std::string const &, std::string const &, Glib::RefPtr act ); + void set_state_from_config () {} + void parameter_changed (std::string const &) {} + void add_to_page (OptionEditorPage*); + + void set_sensitive (bool yn) { + _button->set_sensitive (yn); + } + + Gtk::Widget& tip_widget() { return *_button; } + + void action_toggled (); + void action_sensitivity_changed () {} + void action_visibility_changed () {} + +protected: + virtual void toggled (); + + sigc::slot _get; ///< slot to get the configuration variable's value + sigc::slot _set; ///< slot to set the configuration variable's value + Gtk::CheckButton* _button; ///< UI button + Gtk::Label* _label; ///< label for button, so we can use markup +}; + /** Component which provides the UI to handle a boolean option using a GTK CheckButton */ class BoolOption : public Option { diff --git a/gtk2_ardour/session_option_editor.cc b/gtk2_ardour/session_option_editor.cc index 362d28cce4..a2f0227d3f 100644 --- a/gtk2_ardour/session_option_editor.cc +++ b/gtk2_ardour/session_option_editor.cc @@ -20,6 +20,7 @@ #include "ardour/session.h" #include "ardour/transport_master_manager.h" +#include "actions.h" #include "gui_thread.h" #include "session_option_editor.h" #include "search_path_option.h" @@ -273,11 +274,10 @@ SessionOptionEditor::SessionOptionEditor (Session* s) sigc::mem_fun (*_session_config, &SessionConfiguration::set_auto_input) )); - add_option (_("Monitoring"), new BoolOption ( + add_option (_("Monitoring"), new CheckOption ( "have-monitor-section", _("Use monitor section in this session"), - sigc::mem_fun (*this, &SessionOptionEditor::get_use_monitor_section), - sigc::mem_fun (*this, &SessionOptionEditor::set_use_monitor_section) + ActionManager::get_action(X_("Monitor"), "UseMonitorSection") )); add_option (_("Monitoring"), new OptionEditorBlank ()); @@ -448,34 +448,6 @@ SessionOptionEditor::parameter_changed (std::string const & p) } } -/* the presence of absence of a monitor section is not really a regular session - * property so we provide these two functions to act as setter/getter slots - */ - -bool -SessionOptionEditor::set_use_monitor_section (bool yn) -{ - bool had_monitor_section = _session->monitor_out() != 0; - - if (yn) { - _session->add_monitor_section (); - } else { - _session->remove_monitor_section (); - } - - /* store this choice for any new sessions */ - - Config->set_use_monitor_bus (yn); - - return had_monitor_section != (_session->monitor_out() != 0); -} - -bool -SessionOptionEditor::get_use_monitor_section () -{ - return _session->monitor_out() != 0; -} - void SessionOptionEditor::save_defaults () { diff --git a/gtk2_ardour/session_option_editor.h b/gtk2_ardour/session_option_editor.h index 81d72df731..a27ae88ad1 100644 --- a/gtk2_ardour/session_option_editor.h +++ b/gtk2_ardour/session_option_editor.h @@ -37,9 +37,6 @@ private: ARDOUR::SessionConfiguration* _session_config; - bool set_use_monitor_section (bool); - bool get_use_monitor_section (); - ComboOption* _vpu; ComboOption* _sf; EntryOption* _take_name;