2 * Copyright (C) 2016-2017 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2016-2019 Robin Gareus <robin@gareus.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <gtkmm/menu.h>
24 #include "pbd/string_convert.h"
26 #include "ardour/session.h"
27 #include "ardour/stripable.h"
28 #include "ardour/types.h"
29 #include "ardour/vca.h"
30 #include "ardour/vca_manager.h"
32 #include "gtkmm2ext/gtk_ui.h"
33 #include "gtkmm2ext/utils.h"
35 #include "control_slave_ui.h"
36 #include "gui_thread.h"
40 using namespace ARDOUR;
41 using namespace ArdourWidgets;
45 ControlSlaveUI::ControlSlaveUI (Session* s)
46 : SessionHandlePtr (s)
47 , initial_button (ArdourButton::default_elements)
50 set_no_show_all (true);
52 Gtkmm2ext::UI::instance()->set_tip (*this, _("VCA Assign"));
54 initial_button.set_no_show_all (true);
55 initial_button.set_name (X_("vca assign"));
56 initial_button.set_text (_("-VCAs-"));
57 initial_button.show ();
58 initial_button.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
59 initial_button.signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &ControlSlaveUI::vca_button_release), 0), false);
61 pack_start (initial_button, true, true);
64 ControlSlaveUI::~ControlSlaveUI ()
70 ControlSlaveUI::set_stripable (boost::shared_ptr<Stripable> s)
72 connections.drop_connections ();
77 boost::shared_ptr<GainControl> ac = stripable->gain_control();
80 ac->MasterStatusChange.connect (connections,
82 boost::bind (&ControlSlaveUI::update_vca_display, this),
85 stripable->DropReferences.connect (connections, invalidator (*this), boost::bind (&ControlSlaveUI::set_stripable, this, boost::shared_ptr<Stripable>()), gui_context());
88 update_vca_display ();
92 ControlSlaveUI::update_vca_display ()
94 if (!_session || _session->deletion_in_progress()) {
98 VCAList vcas (_session->vca_manager().vcas());
101 Gtkmm2ext::container_clear (*this);
102 master_connections.drop_connections ();
105 for (VCAList::iterator v = vcas.begin(); v != vcas.end(); ++v) {
106 if (stripable->slaved_to (*v)) {
114 pack_start (initial_button, true, true);
115 initial_button.show ();
122 ControlSlaveUI::vca_menu_toggle (Gtk::CheckMenuItem* menuitem, uint32_t n)
124 boost::shared_ptr<VCA> vca = _session->vca_manager().vca_by_number (n);
130 boost::shared_ptr<Slavable> sl = boost::dynamic_pointer_cast<Slavable> (stripable);
136 if (!menuitem->get_active()) {
144 ControlSlaveUI::unassign_all ()
146 boost::shared_ptr<Slavable> sl = boost::dynamic_pointer_cast<Slavable> (stripable);
152 sl->unassign (boost::shared_ptr<VCA>());
156 ControlSlaveUI::specific_vca_button_release (GdkEventButton* ev, uint32_t n)
158 return vca_button_release (ev, n);
162 ControlSlaveUI::vca_button_release (GdkEventButton* ev, uint32_t n)
164 using namespace Gtk::Menu_Helpers;
170 /* primary click only */
172 if (ev->button != 1) {
177 /* no route - nothing to do */
181 VCAList vcas (_session->vca_manager().vcas());
184 /* the button should not have been visible under these conditions */
189 context_menu = new Menu;
190 MenuList& items = context_menu->items();
193 for (VCAList::iterator v = vcas.begin(); v != vcas.end(); ++v) {
195 if (stripable->assigned_to (_session->vca_manager_ptr (), *v)) {
196 /* master(stripable) is directly or indirectly controlled by slave (v) */
200 items.push_back (CheckMenuElem ((*v)->name()));
201 Gtk::CheckMenuItem* item = dynamic_cast<Gtk::CheckMenuItem*> (&items.back());
203 if (stripable->slaved_to (*v)) {
204 item->set_active (true);
208 item->signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &ControlSlaveUI::vca_menu_toggle), item, (*v)->number()));
212 items.push_back (MenuElem (_("Unassign All"), sigc::mem_fun (*this, &ControlSlaveUI::unassign_all)));
215 if (!items.empty()) {
216 context_menu->popup (1, ev->time);
223 ControlSlaveUI::add_vca_button (boost::shared_ptr<VCA> vca)
225 ArdourButton* vca_button = manage (new ArdourButton (ArdourButton::default_elements));
227 vca_button->set_no_show_all (true);
228 vca_button->set_name (X_("vca assign"));
229 vca_button->add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
230 vca_button->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &ControlSlaveUI::specific_vca_button_release), vca->number()), false);
231 vca_button->set_text (PBD::to_string (vca->number()));
232 vca_button->set_fixed_colors (vca->presentation_info().color(), vca->presentation_info().color ());
234 vca->presentation_info().PropertyChanged.connect (master_connections, invalidator (*this), boost::bind (&ControlSlaveUI::master_property_changed, this, _1), gui_context());
236 pack_start (*vca_button);
241 ControlSlaveUI::master_property_changed (PBD::PropertyChange const& /* what_changed */)
243 update_vca_display ();