2 * Copyright (C) 2016-2017 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2016-2019 Robin Gareus <robin@gareus.org>
4 * Copyright (C) 2017-2018 Ben Loftis <ben@harrisonconsoles.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <gtkmm/stock.h>
23 #include "pbd/string_convert.h"
25 #include "ardour/rc_configuration.h"
26 #include "ardour/session.h"
27 #include "ardour/vca.h"
28 #include "ardour/vca_manager.h"
30 #include "gtkmm2ext/doi.h"
31 #include "gtkmm2ext/keyboard.h"
32 #include "widgets/tooltips.h"
34 #include "ardour_dialog.h"
35 #include "floating_text_entry.h"
36 #include "gui_thread.h"
38 #include "ui_config.h"
40 #include "vca_master_strip.h"
44 using namespace ARDOUR;
45 using namespace ArdourWidgets;
46 using namespace Gtkmm2ext;
51 PBD::Signal1<void,VCAMasterStrip*> VCAMasterStrip::CatchDeletion;
53 VCAMasterStrip::VCAMasterStrip (Session* s, boost::shared_ptr<VCA> v)
54 : SessionHandlePtr (s)
56 , gain_meter (s, 254) /* magic number, don't adjust blindly */
59 , control_slave_ui (s)
61 /* set color for the VCA, if not already done. */
63 if (!_vca->presentation_info().color_set()) {
64 _vca->presentation_info().set_color (ARDOUR_UI_UTILS::gdk_color_to_rgba (unique_random_color()));
67 control_slave_ui.set_stripable (boost::dynamic_pointer_cast<Stripable> (v));
69 gain_meter.set_controls (boost::shared_ptr<Route>(),
70 boost::shared_ptr<PeakMeter>(),
71 boost::shared_ptr<Amp>(),
72 _vca->gain_control());
74 solo_button.set_name ("solo button");
75 set_tooltip (solo_button, _("Solo slaves"));
76 solo_button.signal_button_release_event().connect (sigc::mem_fun (*this, &VCAMasterStrip::solo_release), false);
78 mute_button.set_name ("mute button");
79 mute_button.set_text (_("M"));
80 set_tooltip (mute_button, _("Mute slaves"));
81 mute_button.signal_button_release_event().connect (sigc::mem_fun (*this, &VCAMasterStrip::mute_release), false);
83 hide_button.set_icon (ArdourIcon::HideEye);
84 set_tooltip (&hide_button, _("Hide this VCA strip"));
86 hide_button.signal_clicked.connect (sigc::mem_fun(*this, &VCAMasterStrip::hide_clicked));
88 solo_mute_box.set_spacing (2);
89 solo_mute_box.pack_start (mute_button, true, true);
90 solo_mute_box.pack_start (solo_button, true, true);
92 mute_button.set_controllable (_vca->mute_control());
93 solo_button.set_controllable (_vca->solo_control());
95 number_label.set_text (PBD::to_string (v->number()));
96 number_label.set_elements((ArdourButton::Element)(ArdourButton::Edge|ArdourButton::Body|ArdourButton::Text|ArdourButton::Inactive));
97 number_label.set_no_show_all ();
98 number_label.set_name ("generic button");
99 number_label.set_alignment (.5, .5);
100 number_label.set_fallthrough_to_parent (true);
101 number_label.set_inactive_color (_vca->presentation_info().color ());
102 number_label.signal_button_release_event().connect (sigc::mem_fun (*this, &VCAMasterStrip::number_button_press), false);
104 update_bottom_padding ();
106 //Glib::RefPtr<Pango::Layout> layout = vertical_button.get_layout ();
107 // layout->set_justify (JUSTIFY_CENTER);
108 /* horizontally centered, with a little space (5%) at the top */
109 vertical_button.set_angle (90);
110 vertical_button.set_layout_font (UIConfiguration::instance().get_NormalBoldFont());
111 vertical_button.signal_button_release_event().connect (sigc::mem_fun (*this, &VCAMasterStrip::vertical_button_press));
112 vertical_button.set_fallthrough_to_parent (true);
113 vertical_button.set_active_color (_vca->presentation_info().color ());
114 set_tooltip (vertical_button, _("Click to show slaves only")); /* tooltip updated dynamically */
116 global_vpacker.set_border_width (0);
117 global_vpacker.set_spacing (0);
118 gain_meter.set_spacing(4);
120 global_vpacker.pack_start (number_label, false, false, 1);
121 global_vpacker.pack_start (hide_button, false, false, 1);
122 global_vpacker.pack_start (vertical_button, true, true, 1);
123 global_vpacker.pack_start (solo_mute_box, false, false, 1);
124 global_vpacker.pack_start (gain_meter, false, false, 1);
125 global_vpacker.pack_start (control_slave_ui, false, false, 1);
126 global_vpacker.pack_start (gain_meter.gain_automation_state_button, false, false, 1);
127 global_vpacker.pack_start (bottom_padding, false, false, 0);
129 global_frame.add (global_vpacker);
130 global_frame.set_shadow_type (Gtk::SHADOW_IN);
131 global_frame.set_name ("BaseFrame");
135 global_vpacker.show ();
136 global_frame.show ();
137 vertical_button.show ();
139 number_label.show ();
141 solo_mute_box.show_all ();
142 control_slave_ui.show ();
143 gain_meter.gain_automation_state_button.show ();
145 /* force setting of visible selected status */
148 set_selected (false);
153 spill_change (boost::shared_ptr<VCA>());
155 Mixer_UI::instance()->show_spill_change.connect (sigc::mem_fun (*this, &VCAMasterStrip::spill_change));
157 _vca->PropertyChanged.connect (vca_connections, invalidator (*this), boost::bind (&VCAMasterStrip::vca_property_changed, this, _1), gui_context());
158 _vca->presentation_info().PropertyChanged.connect (vca_connections, invalidator (*this), boost::bind (&VCAMasterStrip::vca_property_changed, this, _1), gui_context());
159 _vca->DropReferences.connect (vca_connections, invalidator (*this), boost::bind (&VCAMasterStrip::self_delete, this), gui_context());
161 _vca->solo_control()->Changed.connect (vca_connections, invalidator (*this), boost::bind (&VCAMasterStrip::solo_changed, this), gui_context());
162 _vca->mute_control()->Changed.connect (vca_connections, invalidator (*this), boost::bind (&VCAMasterStrip::mute_changed, this), gui_context());
164 _session->MonitorBusAddedOrRemoved.connect (*this, invalidator (*this), boost::bind (&VCAMasterStrip::set_button_names, this), gui_context());
166 s->config.ParameterChanged.connect (*this, invalidator (*this), boost::bind (&VCAMasterStrip::parameter_changed, this, _1), gui_context());
167 Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&VCAMasterStrip::parameter_changed, this, _1), gui_context());
168 UIConfiguration::instance().ParameterChanged.connect (sigc::mem_fun (*this, &VCAMasterStrip::parameter_changed));
171 VCAMasterStrip::~VCAMasterStrip ()
173 if ((_session && !_session->deletion_in_progress()) && Mixer_UI::instance()->showing_spill_for (_vca)) {
174 /* cancel spill for this VCA */
175 Mixer_UI::instance()->show_spill (boost::shared_ptr<Stripable>());
178 delete delete_dialog;
181 CatchDeletion (this); /* EMIT SIGNAL */
185 VCAMasterStrip::self_delete ()
187 if ((_session && !_session->deletion_in_progress()) && Mixer_UI::instance()->showing_spill_for (_vca)) {
188 /* cancel spill for this VCA */
189 Mixer_UI::instance()->show_spill (boost::shared_ptr<Stripable>());
191 /* Drop reference immediately, delete self when idle */
193 gain_meter.set_controls (boost::shared_ptr<Route>(),
194 boost::shared_ptr<PeakMeter>(),
195 boost::shared_ptr<Amp>(),
196 boost::shared_ptr<GainControl>());
197 delete_when_idle (this);
201 VCAMasterStrip::parameter_changed (std::string const & p)
203 if (p == "solo-control-is-listen-control" || p == "listen-position") {
205 } else if (p == "mixer-element-visibility") {
206 update_bottom_padding ();
211 VCAMasterStrip::set_button_names ()
213 if (Config->get_solo_control_is_listen_control()) {
214 switch (Config->get_listen_position()) {
215 case AfterFaderListen:
216 solo_button.set_text (S_("AfterFader|A"));
217 set_tooltip (solo_button, _("After-fade listen (AFL)"));
220 solo_button.set_text (S_("PreFader|P"));
221 set_tooltip (solo_button, _("Pre-fade listen (PFL)"));
225 solo_button.set_text (S_("Solo|S"));
226 set_tooltip (solo_button, _("Solo"));
231 VCAMasterStrip::update_bottom_padding ()
233 std::string viz = UIConfiguration::instance().get_mixer_strip_visibility ();
235 ArdourButton output_button (_("Output"));
236 ArdourButton comment_button (_("Comments"));
238 output_button.set_name ("mixer strip button");
239 comment_button.set_name ("generic button");
241 if (viz.find ("VCA") == std::string::npos) {
242 control_slave_ui.hide ();
244 control_slave_ui.show ();
248 if (viz.find ("Output") != std::string::npos) {
249 Gtk::Window window (WINDOW_TOPLEVEL);
250 window.add (output_button);
251 Gtk::Requisition requisition(output_button.size_request ());
252 h += requisition.height + 2;
254 if (viz.find ("Comments") != std::string::npos) {
255 Gtk::Window window (WINDOW_TOPLEVEL);
256 window.add (comment_button);
257 Gtk::Requisition requisition(comment_button.size_request ());
258 h += requisition.height + 2;
261 bottom_padding.set_size_request (-1, 1);
262 bottom_padding.hide ();
264 bottom_padding.set_size_request (-1, h);
265 bottom_padding.show ();
270 VCAMasterStrip::name() const
276 VCAMasterStrip::hide_clicked ()
278 _vca->presentation_info().set_hidden (true);
282 VCAMasterStrip::hide_confirmation (int response)
284 delete_dialog->hide ();
288 /* get everything to deassign. This will also delete ourselves (when
289 * idle) and that in turn will remove us from the Mixer GUI
291 _session->vca_manager().remove_vca (_vca);
299 VCAMasterStrip::width_button_pressed (GdkEventButton* ev)
305 VCAMasterStrip::set_selected (bool yn)
307 AxisView::set_selected (yn);
310 global_frame.set_shadow_type (Gtk::SHADOW_ETCHED_OUT);
311 global_frame.set_name ("MixerStripSelectedFrame");
313 global_frame.set_shadow_type (Gtk::SHADOW_IN);
314 global_frame.set_name ("MixerStripFrame");
317 global_frame.queue_draw ();
321 VCAMasterStrip::solo_release (GdkEventButton*)
323 /* We use NoGroup because VCA controls are never part of a group. This
324 is redundant, but clear.
326 _vca->solo_control()->set_value (_vca->solo_control()->self_soloed() ? 0.0 : 1.0, Controllable::NoGroup);
331 VCAMasterStrip::mute_release (GdkEventButton*)
333 /* We use NoGroup because VCA controls are never part of a group. This
334 is redundant, but clear.
336 _vca->mute_control()->set_value (_vca->mute_control()->muted_by_self() ? 0.0 : 1.0, Controllable::NoGroup);
341 VCAMasterStrip::set_solo_text ()
343 if (Config->get_solo_control_is_listen_control ()) {
344 switch (Config->get_listen_position()) {
345 case AfterFaderListen:
346 solo_button.set_text (_("A"));
349 solo_button.set_text (_("P"));
353 solo_button.set_text (_("S"));
358 VCAMasterStrip::mute_changed ()
360 if (_vca->mute_control()->muted_by_self()) {
361 mute_button.set_active_state (ExplicitActive);
362 } else if (_vca->mute_control()->muted_by_masters ()) {
363 mute_button.set_active_state (ImplicitActive);
365 mute_button.set_active_state (Gtkmm2ext::Off);
370 VCAMasterStrip::solo_changed ()
372 if (_vca->solo_control()->self_soloed()) {
373 solo_button.set_active_state (ExplicitActive);
374 } else if (_vca->solo_control()->soloed_by_masters ()) {
375 solo_button.set_active_state (ImplicitActive);
377 solo_button.set_active_state (Gtkmm2ext::Off);
382 VCAMasterStrip::vertical_button_press (GdkEventButton* ev)
384 if (ev->button == 1 && ev->type == GDK_2BUTTON_PRESS) {
389 if (Keyboard::is_context_menu_event (ev)) {
391 build_context_menu ();
393 context_menu->popup (1, ev->time);
397 if (ev->button == 1) {
405 VCAMasterStrip::number_button_press (GdkEventButton* ev)
407 if (Keyboard::is_context_menu_event (ev)) {
409 build_context_menu ();
411 context_menu->popup (1, ev->time);
418 VCAMasterStrip::start_name_edit ()
420 Gtk::Window* win = dynamic_cast<Gtk::Window*>(get_toplevel());
421 FloatingTextEntry* fte = new FloatingTextEntry (win, _vca->name());
422 fte->use_text.connect (sigc::mem_fun (*this, &VCAMasterStrip::finish_name_edit));
427 VCAMasterStrip::finish_name_edit (std::string str, int)
429 _vca->set_name (str);
433 VCAMasterStrip::vca_property_changed (PropertyChange const & what_changed)
435 if (what_changed.contains (ARDOUR::Properties::name)) {
439 if (what_changed.contains (ARDOUR::Properties::color)) {
440 vertical_button.set_active_color (_vca->presentation_info().color ());
441 number_label.set_inactive_color (_vca->presentation_info().color ());
444 if (what_changed.contains (ARDOUR::Properties::hidden)) {
450 VCAMasterStrip::update_vca_name ()
452 /* 20 is a rough guess at the number of letters we can fit. */
453 vertical_button.set_text (short_version (_vca->full_name(), 20));
457 VCAMasterStrip::build_context_menu ()
459 using namespace Gtk::Menu_Helpers;
460 context_menu = new Menu;
461 MenuList& items = context_menu->items();
462 items.push_back (MenuElem (_("Rename"), sigc::mem_fun (*this, &VCAMasterStrip::start_name_edit)));
463 items.push_back (MenuElem (_("Color..."), sigc::mem_fun (*this, &VCAMasterStrip::start_color_edit)));
464 items.push_back (SeparatorElem());
465 items.push_back (MenuElem (_("Assign Selected Channels"), sigc::mem_fun (*this, &VCAMasterStrip::assign_all_selected)));
466 items.push_back (MenuElem (_("Drop Selected Channels"), sigc::mem_fun (*this, &VCAMasterStrip::unassign_all_selected)));
467 items.push_back (SeparatorElem());
468 items.push_back (MenuElem (_("Drop All Slaves"), sigc::mem_fun (*this, &VCAMasterStrip::drop_all_slaves)));
469 items.push_back (SeparatorElem());
470 items.push_back (MenuElem (_("Remove"), sigc::mem_fun (*this, &VCAMasterStrip::remove)));
474 VCAMasterStrip::spill ()
476 if (Mixer_UI::instance()->showing_spill_for (_vca)) {
477 Mixer_UI::instance()->show_spill (boost::shared_ptr<Stripable>());
479 Mixer_UI::instance()->show_spill (_vca);
484 VCAMasterStrip::spill_change (boost::shared_ptr<Stripable> vca)
487 vertical_button.set_active_state (Gtkmm2ext::Off);
488 set_tooltip (vertical_button, _("Click to show slaves only"));
490 vertical_button.set_active_state (Gtkmm2ext::ExplicitActive);
491 set_tooltip (vertical_button, _("Click to show normal mixer"));
496 VCAMasterStrip::remove ()
502 _session->vca_manager().remove_vca (_vca);
506 VCAMasterStrip::assign_all_selected ()
508 Mixer_UI::instance()->do_vca_assign (_vca);
512 VCAMasterStrip::unassign_all_selected ()
514 Mixer_UI::instance()->do_vca_unassign (_vca);
518 VCAMasterStrip::drop_all_slaves ()
520 _vca->Drop (); /* EMIT SIGNAL */
522 if (Mixer_UI::instance()->showing_spill_for (_vca)) {
523 Mixer_UI::instance()->show_spill (boost::shared_ptr<Stripable>());
528 VCAMasterStrip::color () const
530 return ARDOUR_UI_UTILS::gdk_color_from_rgba (_vca->presentation_info().color ());
534 VCAMasterStrip::state_id () const
536 return string_compose (X_("vms-%1"), _vca->number());
540 VCAMasterStrip::start_color_edit ()
542 _color_picker.popup (_vca);
546 VCAMasterStrip::marked_for_display () const
548 return !_vca->presentation_info().hidden();
552 VCAMasterStrip::set_marked_for_display (bool yn)
554 if (yn == _vca->presentation_info().hidden()) {
555 _vca->presentation_info().set_hidden (!yn);
556 return true; // things changed
561 PresentationInfo const &
562 VCAMasterStrip::presentation_info () const
564 return _vca->presentation_info();
567 boost::shared_ptr<Stripable>
568 VCAMasterStrip::stripable () const