2 Copyright (C) 2016 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <gtkmm/menu.h>
23 #include "pbd/convert.h"
25 #include "ardour/session.h"
26 #include "ardour/stripable.h"
27 #include "ardour/types.h"
28 #include "ardour/vca.h"
29 #include "ardour/vca_manager.h"
31 #include "gtkmm2ext/gtk_ui.h"
32 #include "gtkmm2ext/utils.h"
34 #include "ardour_button.h"
35 #include "control_slave_ui.h"
36 #include "gui_thread.h"
40 using namespace ARDOUR;
44 ControlSlaveUI::ControlSlaveUI (Session* s)
45 : SessionHandlePtr (s)
46 , initial_button (ArdourButton::default_elements)
48 set_no_show_all (true);
50 Gtkmm2ext::UI::instance()->set_tip (*this, _("Control Masters"));
52 initial_button.set_no_show_all (true);
53 initial_button.set_name (X_("vca assign"));
54 initial_button.set_text (_("-VCAs-"));
55 initial_button.show ();
56 initial_button.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
57 initial_button.signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &ControlSlaveUI::vca_button_release), 0), false);
59 pack_start (initial_button, true, true);
63 ControlSlaveUI::set_stripable (boost::shared_ptr<Stripable> s)
65 connections.drop_connections ();
70 boost::shared_ptr<GainControl> ac = stripable->gain_control();
73 ac->MasterStatusChange.connect (connections,
75 boost::bind (&ControlSlaveUI::update_vca_display, this),
78 stripable->DropReferences.connect (connections, invalidator (*this), boost::bind (&ControlSlaveUI::set_stripable, this, boost::shared_ptr<Stripable>()), gui_context());
81 update_vca_display ();
85 ControlSlaveUI::update_vca_display ()
87 if (!_session || _session->deletion_in_progress()) {
91 VCAList vcas (_session->vca_manager().vcas());
94 Gtkmm2ext::container_clear (*this);
95 master_connections.drop_connections ();
98 for (VCAList::iterator v = vcas.begin(); v != vcas.end(); ++v) {
99 if (stripable->gain_control()->slaved_to ((*v)->gain_control())) {
107 pack_start (initial_button, true, true);
114 ControlSlaveUI::vca_menu_toggle (Gtk::CheckMenuItem* menuitem, uint32_t n)
116 boost::shared_ptr<VCA> vca = _session->vca_manager().vca_by_number (n);
122 boost::shared_ptr<Slavable> sl = boost::dynamic_pointer_cast<Slavable> (stripable);
128 if (!menuitem->get_active()) {
136 ControlSlaveUI::unassign_all ()
138 boost::shared_ptr<Slavable> sl = boost::dynamic_pointer_cast<Slavable> (stripable);
144 sl->unassign (boost::shared_ptr<VCA>());
148 ControlSlaveUI::specific_vca_button_release (GdkEventButton* ev, uint32_t n)
150 return vca_button_release (ev, n);
154 ControlSlaveUI::vca_button_release (GdkEventButton* ev, uint32_t n)
156 using namespace Gtk::Menu_Helpers;
162 /* primary click only */
164 if (ev->button != 1) {
169 /* no route - nothing to do */
173 VCAList vcas (_session->vca_manager().vcas());
176 /* the button should not have been visible under these conditions */
180 Menu* menu = new Menu;
181 MenuList& items = menu->items();
184 for (VCAList::iterator v = vcas.begin(); v != vcas.end(); ++v) {
186 boost::shared_ptr<GainControl> gcs = stripable->gain_control();
187 boost::shared_ptr<GainControl> gcm = (*v)->gain_control();
190 /* asked to slave to self. not ok */
194 if (gcm->slaved_to (gcs)) {
195 /* master is already slaved to slave */
199 items.push_back (CheckMenuElem ((*v)->name()));
200 Gtk::CheckMenuItem* item = dynamic_cast<Gtk::CheckMenuItem*> (&items.back());
202 if (gcs->slaved_to (gcm)) {
203 item->set_active (true);
207 item->signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &ControlSlaveUI::vca_menu_toggle), item, (*v)->number()));
211 items.push_back (MenuElem (_("Unassign All"), sigc::mem_fun (*this, &ControlSlaveUI::unassign_all)));
214 if (!items.empty()) {
215 menu->popup (1, ev->time);
222 ControlSlaveUI::add_vca_button (boost::shared_ptr<VCA> vca)
224 ArdourButton* vca_button = manage (new ArdourButton (ArdourButton::default_elements));
226 vca_button->set_no_show_all (true);
227 vca_button->set_name (X_("vca assign"));
228 vca_button->add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
229 vca_button->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &ControlSlaveUI::specific_vca_button_release), vca->number()), false);
230 vca_button->set_text (PBD::to_string (vca->number(), std::dec));
231 vca_button->set_fixed_colors (vca->presentation_info().color(), vca->presentation_info().color ());
233 vca->presentation_info().PropertyChanged.connect (master_connections, invalidator (*this), boost::bind (&ControlSlaveUI::master_property_changed, this, _1), gui_context());
235 pack_start (*vca_button);
240 ControlSlaveUI::master_property_changed (PBD::PropertyChange const& /* what_changed */)
242 update_vca_display ();