DSP-Load Window: subscribe to newly added routes
[ardour.git] / gtk2_ardour / vca_master_strip.cc
1 /*
2     Copyright (C) 2016 Paul Davis
3
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.
8
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.
13
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.
17 */
18
19 #include <gtkmm/stock.h>
20
21 #include "pbd/string_convert.h"
22
23 #include "ardour/rc_configuration.h"
24 #include "ardour/session.h"
25 #include "ardour/vca.h"
26 #include "ardour/vca_manager.h"
27
28 #include "gtkmm2ext/doi.h"
29 #include "gtkmm2ext/keyboard.h"
30 #include "widgets/tooltips.h"
31
32 #include "ardour_dialog.h"
33 #include "floating_text_entry.h"
34 #include "gui_thread.h"
35 #include "mixer_ui.h"
36 #include "ui_config.h"
37 #include "utils.h"
38 #include "vca_master_strip.h"
39
40 #include "pbd/i18n.h"
41
42 using namespace ARDOUR;
43 using namespace ArdourWidgets;
44 using namespace Gtkmm2ext;
45 using namespace Gtk;
46 using namespace PBD;
47 using std::string;
48
49 PBD::Signal1<void,VCAMasterStrip*> VCAMasterStrip::CatchDeletion;
50
51 VCAMasterStrip::VCAMasterStrip (Session* s, boost::shared_ptr<VCA> v)
52         : SessionHandlePtr (s)
53         , _vca (v)
54         , gain_meter (s, 254) /* magic number, don't adjust blindly */
55         , context_menu (0)
56         , delete_dialog (0)
57         , control_slave_ui (s)
58 {
59         /* set color for the VCA, if not already done. */
60
61         if (!_vca->presentation_info().color_set()) {
62                 _vca->presentation_info().set_color (ARDOUR_UI_UTILS::gdk_color_to_rgba (unique_random_color()));
63         }
64
65         control_slave_ui.set_stripable (boost::dynamic_pointer_cast<Stripable> (v));
66
67         gain_meter.set_controls (boost::shared_ptr<Route>(),
68                                  boost::shared_ptr<PeakMeter>(),
69                                  boost::shared_ptr<Amp>(),
70                                  _vca->gain_control());
71
72         solo_button.set_name ("solo button");
73         set_tooltip (solo_button, _("Solo slaves"));
74         solo_button.signal_button_release_event().connect (sigc::mem_fun (*this, &VCAMasterStrip::solo_release), false);
75
76         mute_button.set_name ("mute button");
77         mute_button.set_text (_("M"));
78         set_tooltip (mute_button, _("Mute slaves"));
79         mute_button.signal_button_release_event().connect (sigc::mem_fun (*this, &VCAMasterStrip::mute_release), false);
80
81         hide_button.set_icon (ArdourIcon::CloseCross);
82         set_tooltip (&hide_button, _("Hide this VCA strip"));
83
84         hide_button.signal_clicked.connect (sigc::mem_fun(*this, &VCAMasterStrip::hide_clicked));
85
86         solo_mute_box.set_spacing (2);
87         solo_mute_box.pack_start (mute_button, true, true);
88         solo_mute_box.pack_start (solo_button, true, true);
89
90         mute_button.set_controllable (_vca->mute_control());
91         solo_button.set_controllable (_vca->solo_control());
92
93         number_label.set_text (PBD::to_string (v->number()));
94         number_label.set_elements((ArdourButton::Element)(ArdourButton::Edge|ArdourButton::Body|ArdourButton::Text|ArdourButton::Inactive));
95         number_label.set_no_show_all ();
96         number_label.set_name ("generic button");
97         number_label.set_alignment (.5, .5);
98         number_label.set_fallthrough_to_parent (true);
99         number_label.set_inactive_color (_vca->presentation_info().color ());
100         number_label.signal_button_release_event().connect (sigc::mem_fun (*this, &VCAMasterStrip::number_button_press), false);
101
102         update_bottom_padding ();
103
104         //Glib::RefPtr<Pango::Layout> layout = vertical_button.get_layout ();
105         // layout->set_justify (JUSTIFY_CENTER);
106         /* horizontally centered, with a little space (5%) at the top */
107         vertical_button.set_angle (90);
108         vertical_button.set_layout_font (UIConfiguration::instance().get_NormalBoldFont());
109         vertical_button.signal_button_release_event().connect (sigc::mem_fun (*this, &VCAMasterStrip::vertical_button_press));
110         vertical_button.set_fallthrough_to_parent (true);
111         vertical_button.set_active_color (_vca->presentation_info().color ());
112         set_tooltip (vertical_button, _("Click to show slaves only")); /* tooltip updated dynamically */
113
114         global_vpacker.set_border_width (0);
115         global_vpacker.set_spacing (0);
116         gain_meter.set_spacing(4);
117
118         global_vpacker.pack_start (number_label, false, false, 1);
119         global_vpacker.pack_start (hide_button, false, false, 1);
120         global_vpacker.pack_start (vertical_button, true, true, 1);
121         global_vpacker.pack_start (solo_mute_box, false, false, 1);
122         global_vpacker.pack_start (gain_meter, false, false, 1);
123         global_vpacker.pack_start (control_slave_ui, false, false, 1);
124         global_vpacker.pack_start (gain_meter.gain_automation_state_button, false, false, 1);
125         global_vpacker.pack_start (bottom_padding, false, false, 0);
126
127         global_frame.add (global_vpacker);
128         global_frame.set_shadow_type (Gtk::SHADOW_IN);
129         global_frame.set_name ("BaseFrame");
130
131         add (global_frame);
132
133         global_vpacker.show ();
134         global_frame.show ();
135         vertical_button.show ();
136         hide_button.show ();
137         number_label.show ();
138         gain_meter.show ();
139         solo_mute_box.show_all ();
140         control_slave_ui.show ();
141         gain_meter.gain_automation_state_button.show ();
142
143         /* force setting of visible selected status */
144
145         _selected = true;
146         set_selected (false);
147         set_solo_text ();
148         update_vca_name ();
149         solo_changed ();
150         mute_changed ();
151         spill_change (boost::shared_ptr<VCA>());
152
153         Mixer_UI::instance()->show_spill_change.connect (sigc::mem_fun (*this, &VCAMasterStrip::spill_change));
154
155         _vca->PropertyChanged.connect (vca_connections, invalidator (*this), boost::bind (&VCAMasterStrip::vca_property_changed, this, _1), gui_context());
156         _vca->presentation_info().PropertyChanged.connect (vca_connections, invalidator (*this), boost::bind (&VCAMasterStrip::vca_property_changed, this, _1), gui_context());
157         _vca->DropReferences.connect (vca_connections, invalidator (*this), boost::bind (&VCAMasterStrip::self_delete, this), gui_context());
158
159         _vca->solo_control()->Changed.connect (vca_connections, invalidator (*this), boost::bind (&VCAMasterStrip::solo_changed, this), gui_context());
160         _vca->mute_control()->Changed.connect (vca_connections, invalidator (*this), boost::bind (&VCAMasterStrip::mute_changed, this), gui_context());
161
162
163         s->config.ParameterChanged.connect (*this, invalidator (*this), boost::bind (&VCAMasterStrip::parameter_changed, this, _1), gui_context());
164         Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&VCAMasterStrip::parameter_changed, this, _1), gui_context());
165         UIConfiguration::instance().ParameterChanged.connect (sigc::mem_fun (*this, &VCAMasterStrip::parameter_changed));
166 }
167
168 VCAMasterStrip::~VCAMasterStrip ()
169 {
170         if ((_session && !_session->deletion_in_progress()) && Mixer_UI::instance()->showing_spill_for (_vca)) {
171                 /* cancel spill for this VCA */
172                 Mixer_UI::instance()->show_spill (boost::shared_ptr<Stripable>());
173         }
174
175         delete delete_dialog;
176         delete context_menu;
177
178         CatchDeletion (this); /* EMIT SIGNAL */
179 }
180
181 void
182 VCAMasterStrip::self_delete ()
183 {
184         if ((_session && !_session->deletion_in_progress()) && Mixer_UI::instance()->showing_spill_for (_vca)) {
185                 /* cancel spill for this VCA */
186                 Mixer_UI::instance()->show_spill (boost::shared_ptr<Stripable>());
187         }
188         /* Drop reference immediately, delete self when idle */
189         _vca.reset ();
190         gain_meter.set_controls (boost::shared_ptr<Route>(),
191                                  boost::shared_ptr<PeakMeter>(),
192                                  boost::shared_ptr<Amp>(),
193                                  boost::shared_ptr<GainControl>());
194         delete_when_idle (this);
195 }
196
197 void
198 VCAMasterStrip::parameter_changed (std::string const & p)
199 {
200         if (p == "use-monitor-bus" || p == "solo-control-is-listen-control" || p == "listen-position") {
201                 set_button_names ();
202         } else if (p == "mixer-element-visibility") {
203                 update_bottom_padding ();
204         }
205 }
206
207 void
208 VCAMasterStrip::set_button_names ()
209 {
210         if (Config->get_solo_control_is_listen_control()) {
211                 switch (Config->get_listen_position()) {
212                 case AfterFaderListen:
213                         solo_button.set_text (S_("AfterFader|A"));
214                         set_tooltip (solo_button, _("After-fade listen (AFL)"));
215                         break;
216                 case PreFaderListen:
217                         solo_button.set_text (S_("PreFader|P"));
218                         set_tooltip (solo_button, _("Pre-fade listen (PFL)"));
219                         break;
220                 }
221         } else {
222                 solo_button.set_text (S_("Solo|S"));
223                 set_tooltip (solo_button, _("Solo"));
224         }
225 }
226
227 void
228 VCAMasterStrip::update_bottom_padding ()
229 {
230         std::string viz = UIConfiguration::instance().get_mixer_strip_visibility ();
231
232         ArdourButton output_button (_("Output"));
233         ArdourButton comment_button (_("Comments"));
234
235         output_button.set_name ("mixer strip button");
236         comment_button.set_name ("generic button");
237
238         if (viz.find ("VCA") == std::string::npos) {
239                 control_slave_ui.hide ();
240         } else {
241                 control_slave_ui.show ();
242         }
243
244         int h = 0;
245         if (viz.find ("Output") != std::string::npos) {
246                 Gtk::Window window (WINDOW_TOPLEVEL);
247                 window.add (output_button);
248                 Gtk::Requisition requisition(output_button.size_request ());
249                 h += requisition.height + 2;
250         }
251         if (viz.find ("Comments") != std::string::npos) {
252                 Gtk::Window window (WINDOW_TOPLEVEL);
253                 window.add (comment_button);
254                 Gtk::Requisition requisition(comment_button.size_request ());
255                 h += requisition.height + 2;
256         }
257         if (h <= 0) {
258                 bottom_padding.set_size_request (-1, 1);
259                 bottom_padding.hide ();
260         } else {
261                 bottom_padding.set_size_request (-1, h);
262                 bottom_padding.show ();
263         }
264 }
265
266 string
267 VCAMasterStrip::name() const
268 {
269         return _vca->name();
270 }
271
272 void
273 VCAMasterStrip::hide_clicked ()
274 {
275         _vca->presentation_info().set_hidden (true);
276 }
277
278 void
279 VCAMasterStrip::hide_confirmation (int response)
280 {
281         delete_dialog->hide ();
282
283         switch (response) {
284         case RESPONSE_YES:
285                 /* get everything to deassign. This will also delete ourselves (when
286                  * idle) and that in turn will remove us from the Mixer GUI
287                  */
288                 _session->vca_manager().remove_vca (_vca);
289                 break;
290         default:
291                 break;
292         }
293 }
294
295 bool
296 VCAMasterStrip::width_button_pressed (GdkEventButton* ev)
297 {
298         return false;
299 }
300
301 void
302 VCAMasterStrip::set_selected (bool yn)
303 {
304         AxisView::set_selected (yn);
305
306         if (_selected) {
307                 global_frame.set_shadow_type (Gtk::SHADOW_ETCHED_OUT);
308                 global_frame.set_name ("MixerStripSelectedFrame");
309         } else {
310                 global_frame.set_shadow_type (Gtk::SHADOW_IN);
311                 global_frame.set_name ("MixerStripFrame");
312         }
313
314         global_frame.queue_draw ();
315 }
316
317 bool
318 VCAMasterStrip::solo_release (GdkEventButton*)
319 {
320         /* We use NoGroup because VCA controls are never part of a group. This
321            is redundant, but clear.
322         */
323         _vca->solo_control()->set_value (_vca->solo_control()->self_soloed() ? 0.0 : 1.0, Controllable::NoGroup);
324         return true;
325 }
326
327 bool
328 VCAMasterStrip::mute_release (GdkEventButton*)
329 {
330         /* We use NoGroup because VCA controls are never part of a group. This
331            is redundant, but clear.
332         */
333         _vca->mute_control()->set_value (_vca->mute_control()->muted_by_self() ? 0.0 : 1.0, Controllable::NoGroup);
334         return true;
335 }
336
337 void
338 VCAMasterStrip::set_solo_text ()
339 {
340         if (Config->get_solo_control_is_listen_control ()) {
341                 switch (Config->get_listen_position()) {
342                 case AfterFaderListen:
343                         solo_button.set_text (_("A"));
344                         break;
345                 case PreFaderListen:
346                         solo_button.set_text (_("P"));
347                         break;
348                         }
349         } else {
350                 solo_button.set_text (_("S"));
351         }
352 }
353
354 void
355 VCAMasterStrip::mute_changed ()
356 {
357         if (_vca->mute_control()->muted_by_self()) {
358                 mute_button.set_active_state (ExplicitActive);
359         } else if (_vca->mute_control()->muted_by_masters ()) {
360                 mute_button.set_active_state (ImplicitActive);
361         } else {
362                 mute_button.set_active_state (Gtkmm2ext::Off);
363         }
364 }
365
366 void
367 VCAMasterStrip::solo_changed ()
368 {
369         if (_vca->solo_control()->self_soloed()) {
370                 solo_button.set_active_state (ExplicitActive);
371         } else if (_vca->solo_control()->soloed_by_masters ()) {
372                 solo_button.set_active_state (ImplicitActive);
373         } else {
374                 solo_button.set_active_state (Gtkmm2ext::Off);
375         }
376 }
377
378 bool
379 VCAMasterStrip::vertical_button_press (GdkEventButton* ev)
380 {
381         if (ev->button == 1 && ev->type == GDK_2BUTTON_PRESS) {
382                 start_name_edit ();
383                 return true;
384         }
385
386         if (Keyboard::is_context_menu_event (ev)) {
387                 if (!context_menu) {
388                         build_context_menu ();
389                 }
390                 context_menu->popup (1, ev->time);
391                 return true;
392         }
393
394         if (ev->button == 1) {
395                 spill ();
396         }
397
398         return true;
399 }
400
401 bool
402 VCAMasterStrip::number_button_press (GdkEventButton* ev)
403 {
404         if (Keyboard::is_context_menu_event (ev)) {
405                 if (!context_menu) {
406                         build_context_menu ();
407                 }
408                 context_menu->popup (1, ev->time);
409                 return true;
410         }
411         return false;
412 }
413
414 void
415 VCAMasterStrip::start_name_edit ()
416 {
417         Gtk::Window* win = dynamic_cast<Gtk::Window*>(get_toplevel());
418         FloatingTextEntry* fte = new FloatingTextEntry (win, _vca->name());
419         fte->use_text.connect (sigc::mem_fun (*this, &VCAMasterStrip::finish_name_edit));
420         fte->present ();
421 }
422
423 void
424 VCAMasterStrip::finish_name_edit (std::string str, int)
425 {
426         _vca->set_name (str);
427 }
428
429 void
430 VCAMasterStrip::vca_property_changed (PropertyChange const & what_changed)
431 {
432         if (what_changed.contains (ARDOUR::Properties::name)) {
433                 update_vca_name ();
434         }
435
436         if (what_changed.contains (ARDOUR::Properties::color)) {
437                 vertical_button.set_active_color (_vca->presentation_info().color ());
438                 number_label.set_inactive_color (_vca->presentation_info().color ());
439         }
440
441         if (what_changed.contains (ARDOUR::Properties::hidden)) {
442
443         }
444 }
445
446 void
447 VCAMasterStrip::update_vca_name ()
448 {
449         /* 20 is a rough guess at the number of letters we can fit. */
450         vertical_button.set_text (short_version (_vca->full_name(), 20));
451 }
452
453 void
454 VCAMasterStrip::build_context_menu ()
455 {
456         using namespace Gtk::Menu_Helpers;
457         context_menu = new Menu;
458         MenuList& items = context_menu->items();
459         items.push_back (MenuElem (_("Rename"), sigc::mem_fun (*this, &VCAMasterStrip::start_name_edit)));
460         items.push_back (MenuElem (_("Color..."), sigc::mem_fun (*this, &VCAMasterStrip::start_color_edit)));
461         items.push_back (SeparatorElem());
462         items.push_back (MenuElem (_("Assign Selected Channels"), sigc::mem_fun (*this, &VCAMasterStrip::assign_all_selected)));
463         items.push_back (MenuElem (_("Drop Selected Channels"), sigc::mem_fun (*this, &VCAMasterStrip::unassign_all_selected)));
464         items.push_back (SeparatorElem());
465         items.push_back (MenuElem (_("Drop All Slaves"), sigc::mem_fun (*this, &VCAMasterStrip::drop_all_slaves)));
466         items.push_back (SeparatorElem());
467         items.push_back (MenuElem (_("Remove"), sigc::mem_fun (*this, &VCAMasterStrip::remove)));
468 }
469
470 void
471 VCAMasterStrip::spill ()
472 {
473         if (Mixer_UI::instance()->showing_spill_for (_vca)) {
474                 Mixer_UI::instance()->show_spill (boost::shared_ptr<Stripable>());
475         } else {
476                 Mixer_UI::instance()->show_spill (_vca);
477         }
478 }
479
480 void
481 VCAMasterStrip::spill_change (boost::shared_ptr<Stripable> vca)
482 {
483         if (vca != _vca) {
484                 vertical_button.set_active_state (Gtkmm2ext::Off);
485                 set_tooltip (vertical_button, _("Click to show slaves only"));
486         } else {
487                 vertical_button.set_active_state (Gtkmm2ext::ExplicitActive);
488                 set_tooltip (vertical_button, _("Click to show normal mixer"));
489         }
490 }
491
492 void
493 VCAMasterStrip::remove ()
494 {
495         if (!_session) {
496                 return;
497         }
498
499         _session->vca_manager().remove_vca (_vca);
500 }
501
502 void
503 VCAMasterStrip::assign_all_selected ()
504 {
505         Mixer_UI::instance()->do_vca_assign (_vca);
506 }
507
508 void
509 VCAMasterStrip::unassign_all_selected ()
510 {
511         Mixer_UI::instance()->do_vca_unassign (_vca);
512 }
513
514 void
515 VCAMasterStrip::drop_all_slaves ()
516 {
517         _vca->Drop (); /* EMIT SIGNAL */
518
519         if (Mixer_UI::instance()->showing_spill_for (_vca)) {
520                 Mixer_UI::instance()->show_spill (boost::shared_ptr<Stripable>());
521         }
522 }
523
524 Gdk::Color
525 VCAMasterStrip::color () const
526 {
527         return ARDOUR_UI_UTILS::gdk_color_from_rgba (_vca->presentation_info().color ());
528 }
529
530 string
531 VCAMasterStrip::state_id () const
532 {
533         return string_compose (X_("vms-%1"), _vca->number());
534 }
535
536 void
537 VCAMasterStrip::start_color_edit ()
538 {
539         _color_picker.popup (_vca);
540 }
541
542 bool
543 VCAMasterStrip::marked_for_display () const
544 {
545         return !_vca->presentation_info().hidden();
546 }
547
548 bool
549 VCAMasterStrip::set_marked_for_display (bool yn)
550 {
551         if (yn == _vca->presentation_info().hidden()) {
552                 _vca->presentation_info().set_hidden (!yn);
553                 return true; // things changed
554         }
555         return false;
556 }
557
558 PresentationInfo const &
559 VCAMasterStrip::presentation_info () const
560 {
561         return _vca->presentation_info();
562 }
563
564 boost::shared_ptr<Stripable>
565 VCAMasterStrip::stripable () const
566 {
567         return _vca;
568 }