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