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.
19 #include <gtkmm/stock.h>
21 #include "pbd/convert.h"
23 #include "ardour/rc_configuration.h"
24 #include "ardour/session.h"
25 #include "ardour/vca.h"
26 #include "ardour/vca_manager.h"
28 #include "gtkmm2ext/doi.h"
29 #include "gtkmm2ext/keyboard.h"
31 #include "ardour_dialog.h"
32 #include "floating_text_entry.h"
33 #include "gui_thread.h"
35 #include "vca_master_strip.h"
39 using namespace ARDOUR;
40 using namespace ARDOUR_UI_UTILS;
41 using namespace Gtkmm2ext;
46 PBD::Signal1<void,VCAMasterStrip*> VCAMasterStrip::CatchDeletion;
49 verticalize (string const & str)
54 string::const_iterator s = str.begin();
59 while (s != str.end()) {
65 /* remove terminal newline */
67 ret.erase (ret.length() - 1, string::npos);
72 VCAMasterStrip::VCAMasterStrip (Session* s, boost::shared_ptr<VCA> v)
79 gain_meter.set_controls (boost::shared_ptr<Route>(),
80 boost::shared_ptr<PeakMeter>(),
81 boost::shared_ptr<Amp>(),
82 _vca->gain_control());
84 solo_button.set_name ("solo button");
85 set_tooltip (solo_button, _("Solo slaves"));
86 solo_button.signal_button_release_event().connect (sigc::mem_fun (*this, &VCAMasterStrip::solo_release), false);
88 mute_button.set_name ("mute button");
89 mute_button.set_text (_("M"));
90 set_tooltip (mute_button, _("Mute slaves"));
91 mute_button.signal_button_release_event().connect (sigc::mem_fun (*this, &VCAMasterStrip::mute_release), false);
93 hide_button.set_icon (ArdourIcon::CloseCross);
94 set_tooltip (&hide_button, _("Hide this VCA strip"));
96 assign_button.set_name (X_("vca assign"));
97 set_tooltip (assign_button, _("Click to assign a VCA Master to this VCA"));
98 assign_button.signal_button_release_event().connect (sigc::mem_fun (*this, &VCAMasterStrip::vca_button_release), false);
100 hide_button.signal_clicked.connect (sigc::mem_fun(*this, &VCAMasterStrip::hide_clicked));
102 width_hide_box.pack_start (number_label, true, true);
103 width_hide_box.pack_end (hide_button, false, true);
105 solo_mute_box.set_spacing (2);
106 solo_mute_box.pack_start (mute_button, true, true);
107 solo_mute_box.pack_start (solo_button, true, true);
109 number_label.set_text (to_string (v->number(), std::dec));
110 number_label.set_elements((ArdourButton::Element)(ArdourButton::Edge|ArdourButton::Body|ArdourButton::Text|ArdourButton::Inactive));
111 number_label.set_no_show_all ();
112 number_label.set_name ("generic button");
113 number_label.set_alignment (.5, .5);
114 number_label.set_fallthrough_to_parent (true);
116 name_button.signal_button_press_event().connect (sigc::mem_fun (*this, &VCAMasterStrip::name_button_press), false);
118 top_padding.set_size_request (-1, 16); /* must match height in GroupTabs::set_size_request() */
119 bottom_padding.set_size_request (-1, 50); /* this one is a hack. there's no trivial way to compute it */
121 vertical_label.set_justify (JUSTIFY_CENTER);
122 /* horizontally centered, with a little space (5%) at the top */
123 vertical_label.set_alignment (0.5, 0.05);
124 vertical_label.set_name (X_("vca_vertical_box"));
125 vertical_label.set_angle (270); /* top to bottom */
127 vertical_box.add (vertical_label);
128 vertical_box.set_name (X_("vca_vertical_box"));
129 vertical_box.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
130 vertical_box.signal_button_press_event().connect (sigc::mem_fun (*this, &VCAMasterStrip::vertical_box_press), false);
132 global_vpacker.set_border_width (1);
133 global_vpacker.set_spacing (0);
135 global_vpacker.pack_start (top_padding, false, false);
136 global_vpacker.pack_start (width_hide_box, false, false);
137 global_vpacker.pack_start (name_button, false, false);
138 global_vpacker.pack_start (vertical_box, true, true);
139 global_vpacker.pack_start (solo_mute_box, false, false);
140 global_vpacker.pack_start (gain_meter, false, false);
141 global_vpacker.pack_start (assign_button, false, false);
142 global_vpacker.pack_start (bottom_padding, false, false);
144 global_frame.add (global_vpacker);
145 global_frame.set_shadow_type (Gtk::SHADOW_IN);
146 global_frame.set_name ("BaseFrame");
150 global_vpacker.show ();
151 global_frame.show ();
153 bottom_padding.show ();
154 vertical_label.show ();
155 vertical_box.show ();
157 number_label.show ();
158 width_hide_box.show ();
161 solo_mute_box.show_all ();
162 assign_button.show ();
164 /* force setting of visible selected status */
167 set_selected (false);
169 update_vca_display ();
174 /* this remains unchanged as the name changes */
175 name_button.set_text (string_compose (X_("VCA %1"), _vca->number()));
177 _vca->PropertyChanged.connect (vca_connections, invalidator (*this), boost::bind (&VCAMasterStrip::vca_property_changed, this, _1), gui_context());
179 _vca->solo_control()->Changed.connect (vca_connections, invalidator (*this), boost::bind (&VCAMasterStrip::solo_changed, this), gui_context());
180 _vca->mute_control()->Changed.connect (vca_connections, invalidator (*this), boost::bind (&VCAMasterStrip::mute_changed, this), gui_context());
182 /* only need to connect to one of these to update VCA status */
184 _vca->gain_control()->MasterStatusChange.connect (vca_connections,
186 boost::bind (&VCAMasterStrip::update_vca_display, this),
190 _vca->DropReferences.connect (vca_connections, invalidator (*this), boost::bind (&VCAMasterStrip::self_delete, this), gui_context());
194 VCAMasterStrip::~VCAMasterStrip ()
196 delete delete_dialog;
199 CatchDeletion (this); /* EMIT SIGNAL */
203 VCAMasterStrip::self_delete ()
205 delete_when_idle (this);
209 VCAMasterStrip::update_vca_display ()
211 VCAList vcas (_session->vca_manager().vcas());
214 for (VCAList::iterator v = vcas.begin(); v != vcas.end(); ++v) {
215 if (_vca->gain_control()->slaved_to ((*v)->gain_control())) {
216 if (!label.empty()) {
219 label += to_string ((*v)->number(), std::dec);
225 assign_button.set_active_state (Gtkmm2ext::Off);
227 assign_button.set_active_state (Gtkmm2ext::ExplicitActive);
230 assign_button.set_text (label);
234 VCAMasterStrip::name() const
240 VCAMasterStrip::hide_clicked ()
242 if (!delete_dialog) {
243 delete_dialog = new MessageDialog (_("Removing a Master will deassign all slaves. Remove it anyway?"),
244 true, MESSAGE_WARNING, BUTTONS_YES_NO, true);
245 delete_dialog->signal_response().connect (sigc::mem_fun (*this, &VCAMasterStrip::hide_confirmation));
248 delete_dialog->set_position (Gtk::WIN_POS_MOUSE);
249 delete_dialog->present ();
253 VCAMasterStrip::hide_confirmation (int response)
255 delete_dialog->hide ();
259 /* get everything to deassign. This will also delete ourselves (when
260 * idle) and that in turn will remove us from the Mixer GUI
262 _session->vca_manager().remove_vca (_vca);
270 VCAMasterStrip::width_button_pressed (GdkEventButton* ev)
276 VCAMasterStrip::set_selected (bool yn)
278 AxisView::set_selected (yn);
281 global_frame.set_shadow_type (Gtk::SHADOW_ETCHED_OUT);
282 global_frame.set_name ("MixerStripSelectedFrame");
284 global_frame.set_shadow_type (Gtk::SHADOW_IN);
285 global_frame.set_name ("MixerStripFrame");
288 global_frame.queue_draw ();
292 VCAMasterStrip::solo_release (GdkEventButton*)
294 /* We use NoGroup because VCA controls are never part of a group. This
295 is redundant, but clear.
297 _vca->solo_control()->set_value (_vca->solo_control()->self_soloed() ? 0.0 : 1.0, Controllable::NoGroup);
302 VCAMasterStrip::mute_release (GdkEventButton*)
304 /* We use NoGroup because VCA controls are never part of a group. This
305 is redundant, but clear.
307 _vca->mute_control()->set_value (_vca->mute_control()->muted_by_self() ? 0.0 : 1.0, Controllable::NoGroup);
312 VCAMasterStrip::set_solo_text ()
314 if (Config->get_solo_control_is_listen_control ()) {
315 switch (Config->get_listen_position()) {
316 case AfterFaderListen:
317 solo_button.set_text (_("A"));
320 solo_button.set_text (_("P"));
324 solo_button.set_text (_("S"));
329 VCAMasterStrip::mute_changed ()
331 if (_vca->mute_control()->muted_by_self()) {
332 mute_button.set_active_state (ExplicitActive);
333 } else if (_vca->mute_control()->muted_by_masters ()) {
334 mute_button.set_active_state (ImplicitActive);
336 mute_button.set_active_state (Gtkmm2ext::Off);
341 VCAMasterStrip::solo_changed ()
343 if (_vca->solo_control()->self_soloed()) {
344 solo_button.set_active_state (ExplicitActive);
345 } else if (_vca->solo_control()->soloed_by_masters ()) {
346 solo_button.set_active_state (ImplicitActive);
348 solo_button.set_active_state (Gtkmm2ext::Off);
353 VCAMasterStrip::vca_menu_toggle (CheckMenuItem* menuitem, uint32_t n)
355 boost::shared_ptr<VCA> vca = _session->vca_manager().vca_by_number (n);
357 if (!menuitem->get_active()) {
359 /* null VCA means drop all VCA assignments */
360 _vca->unassign (boost::shared_ptr<VCA>());
363 _vca->unassign (vca);
373 VCAMasterStrip::unassign ()
375 _vca->unassign (boost::shared_ptr<VCA>());
379 VCAMasterStrip::vca_button_release (GdkEventButton* ev)
381 using namespace Gtk::Menu_Helpers;
387 /* primary click only */
389 if (ev->button != 1) {
393 VCAList vcas (_session->vca_manager().vcas());
396 /* XXX should probably show a message saying "No VCA masters" */
400 Menu* menu = new Menu;
401 MenuList& items = menu->items();
403 items.push_back (MenuElem (_("Unassign"), sigc::mem_fun (*this, &VCAMasterStrip::unassign)));
405 for (VCAList::iterator v = vcas.begin(); v != vcas.end(); ++v) {
408 /* no self-mastering */
412 items.push_back (CheckMenuElem ((*v)->name()));
413 CheckMenuItem* item = dynamic_cast<CheckMenuItem*> (&items.back());
414 if (_vca->gain_control()->slaved_to ((*v)->gain_control())) {
415 item->set_active (true);
417 item->signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &VCAMasterStrip::vca_menu_toggle), item, (*v)->number()));
420 menu->popup (1, ev->time);
426 VCAMasterStrip::vertical_box_press (GdkEventButton* ev)
428 if (ev->button == 1 && ev->type == GDK_2BUTTON_PRESS) {
433 if (Keyboard::is_context_menu_event (ev)) {
435 build_context_menu ();
437 context_menu->popup (1, ev->time);
441 if (ev->button == 1) {
449 VCAMasterStrip::name_button_press (GdkEventButton* ev)
451 if (ev->button == 1 && ev->type == GDK_2BUTTON_PRESS) {
456 if (Keyboard::is_context_menu_event (ev)) {
458 build_context_menu ();
460 context_menu->popup (1, ev->time);
468 VCAMasterStrip::start_name_edit ()
470 Gtk::Window* win = dynamic_cast<Gtk::Window*>(get_toplevel());
471 FloatingTextEntry* fte = new FloatingTextEntry (win, _vca->name());
472 fte->use_text.connect (sigc::mem_fun (*this, &VCAMasterStrip::finish_name_edit));
477 VCAMasterStrip::finish_name_edit (std::string str)
479 _vca->set_name (str);
483 VCAMasterStrip::vca_property_changed (PropertyChange const & what_changed)
485 if (what_changed.contains (ARDOUR::Properties::name)) {
491 VCAMasterStrip::update_vca_name ()
493 vertical_label.set_text (verticalize (short_version (_vca->name(), 15)));
497 VCAMasterStrip::build_context_menu ()
499 using namespace Gtk::Menu_Helpers;
500 context_menu = new Menu;
501 MenuList& items = context_menu->items();
502 items.push_back (MenuElem (_("Rename"), sigc::mem_fun (*this, &VCAMasterStrip::start_name_edit)));
503 items.push_back (MenuElem (_("Remove")));