From 55c616519bc4cc0ad0095ada7a0fc1909196818b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 28 Nov 2014 18:40:23 -0500 Subject: Use a button as controller for toggled parameters. --- gtk2_ardour/automation_controller.cc | 82 +++++++++++++++++++++++++++++++----- gtk2_ardour/automation_controller.h | 12 +++++- gtk2_ardour/automation_time_axis.cc | 2 +- 3 files changed, 82 insertions(+), 14 deletions(-) (limited to 'gtk2_ardour') diff --git a/gtk2_ardour/automation_controller.cc b/gtk2_ardour/automation_controller.cc index 55670b280a..ff8b1932a2 100644 --- a/gtk2_ardour/automation_controller.cc +++ b/gtk2_ardour/automation_controller.cc @@ -29,6 +29,7 @@ #include "ardour/session.h" #include "ardour/tempo.h" +#include "ardour_button.h" #include "ardour_ui.h" #include "automation_controller.h" #include "gui_thread.h" @@ -42,29 +43,53 @@ using namespace Gtk; AutomationController::AutomationController(boost::shared_ptr printer, boost::shared_ptr ac, Adjustment* adj) - : BarController (*adj, ac) - , _ignore_change(false) + : _widget(NULL) , _printer (printer) , _controllable(ac) , _adjustment(adj) + , _ignore_change(false) { assert (_printer); - set_name (X_("ProcessorControlSlider")); - - StartGesture.connect (sigc::mem_fun(*this, &AutomationController::start_touch)); - StopGesture.connect (sigc::mem_fun(*this, &AutomationController::end_touch)); + if (ac->toggled()) { + ArdourButton* but = manage(new ArdourButton()); - signal_button_release_event().connect( - sigc::mem_fun(*this, &AutomationController::on_button_release)); + // Apply styles for special types + if (ac->parameter().type() == MuteAutomation) { + but->set_name("mute button"); + } else if (ac->parameter().type() == SoloAutomation) { + but->set_name("solo button"); + } else { + but->set_name("generic button"); + } + but->signal_clicked.connect( + sigc::mem_fun(*this, &AutomationController::toggled)); + + _widget = but; + } else { + Gtkmm2ext::BarController* bar = manage(new Gtkmm2ext::BarController(*adj, ac)); + + bar->set_name(X_("ProcessorControlSlider")); + bar->StartGesture.connect( + sigc::mem_fun(*this, &AutomationController::start_touch)); + bar->StopGesture.connect( + sigc::mem_fun(*this, &AutomationController::end_touch)); + bar->signal_button_release_event().connect( + sigc::mem_fun(*this, &AutomationController::on_button_release)); + + _widget = bar; + } - _adjustment->signal_value_changed().connect ( - sigc::mem_fun(*this, &AutomationController::value_adjusted)); + _adjustment->signal_value_changed().connect( + sigc::mem_fun(*this, &AutomationController::value_adjusted)); _screen_update_connection = ARDOUR_UI::RapidScreenUpdate.connect ( sigc::mem_fun (*this, &AutomationController::display_effective_value)); ac->Changed.connect (_changed_connection, invalidator (*this), boost::bind (&AutomationController::value_changed, this), gui_context()); + + add(*_widget); + show_all(); } AutomationController::~AutomationController() @@ -123,6 +148,13 @@ AutomationController::value_adjusted () { if (!_ignore_change) { _controllable->set_value (_controllable->interface_to_internal(_adjustment->get_value())); + } else { + /* A bar controller will automatically follow the adjustment, but for a + button we have to do it manually. */ + ArdourButton* but = dynamic_cast(_widget); + if (but) { + but->set_active(_adjustment->get_value() >= 0.5); + } } } @@ -130,12 +162,12 @@ void AutomationController::start_touch() { _controllable->start_touch (_controllable->session().transport_frame()); + StartGesture.emit(); /* EMIT SIGNAL */ } void AutomationController::end_touch () { - if (!_controllable->alist()) return; if (_controllable->automation_state() == Touch) { bool mark = false; @@ -148,6 +180,23 @@ AutomationController::end_touch () _controllable->stop_touch (mark, when); } + StopGesture.emit(); /* EMIT SIGNAL */ +} + +void +AutomationController::toggled () +{ + ArdourButton* but = dynamic_cast(_widget); + if (but) { + const bool was_active = _controllable->get_value() >= 0.5; + if (was_active) { + _adjustment->set_value(0.0); + but->set_active(false); + } else { + _adjustment->set_value(1.0); + but->set_active(true); + } + } } static double @@ -261,3 +310,14 @@ AutomationController::stop_updating () { _screen_update_connection.disconnect (); } + +void +AutomationController::disable_vertical_scroll () +{ + Gtkmm2ext::BarController* bar = dynamic_cast(_widget); + if (bar) { + bar->set_tweaks ( + Gtkmm2ext::PixFader::Tweaks(bar->tweaks() | + Gtkmm2ext::PixFader::NoVerticalScroll)); + } +} diff --git a/gtk2_ardour/automation_controller.h b/gtk2_ardour/automation_controller.h index 8b00645c80..db79ac249e 100644 --- a/gtk2_ardour/automation_controller.h +++ b/gtk2_ardour/automation_controller.h @@ -43,7 +43,7 @@ namespace ARDOUR { } /** A BarController which displays the value and allows control of an AutomationControl */ -class AutomationController : public Gtkmm2ext::BarController { +class AutomationController : public Gtk::Alignment { public: static boost::shared_ptr create( boost::shared_ptr parent, @@ -55,13 +55,19 @@ public: boost::shared_ptr controllable() { return _controllable; } + void disable_vertical_scroll(); + Gtk::Adjustment* adjustment() { return _adjustment; } + Gtk::Widget* widget() { return _widget; } void display_effective_value(); void value_adjusted(); void stop_updating (); + sigc::signal StartGesture; + sigc::signal StopGesture; + private: AutomationController (boost::shared_ptr printer, boost::shared_ptr ac, @@ -70,6 +76,7 @@ private: void start_touch(); void end_touch(); + void toggled(); void run_note_select_dialog(); void set_ratio(double ratio); @@ -78,12 +85,13 @@ private: void value_changed(); - bool _ignore_change; + Gtk::Widget* _widget; boost::shared_ptr _printer; boost::shared_ptr _controllable; Gtk::Adjustment* _adjustment; sigc::connection _screen_update_connection; PBD::ScopedConnection _changed_connection; + bool _ignore_change; }; diff --git a/gtk2_ardour/automation_time_axis.cc b/gtk2_ardour/automation_time_axis.cc index 5a6bf5dbbe..67e7c06421 100644 --- a/gtk2_ardour/automation_time_axis.cc +++ b/gtk2_ardour/automation_time_axis.cc @@ -219,7 +219,7 @@ AutomationTimeAxisView::AutomationTimeAxisView ( hide_button.show (); if (_controller) { - _controller.get()->set_tweaks (PixFader::Tweaks(_controller.get()->tweaks() | PixFader::NoVerticalScroll)); + _controller->disable_vertical_scroll (); controls_table.attach (*_controller.get(), 2, 4, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0); } -- cgit v1.2.3