GUI tweaks for VCAMasterStrip, including renaming
[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 "pbd/convert.h"
20
21 #include "ardour/rc_configuration.h"
22 #include "ardour/session.h"
23 #include "ardour/vca.h"
24 #include "ardour/vca_manager.h"
25
26 #include "gui_thread.h"
27 #include "floating_text_entry.h"
28 #include "tooltips.h"
29 #include "vca_master_strip.h"
30
31 #include "i18n.h"
32
33 using namespace ARDOUR;
34 using namespace ARDOUR_UI_UTILS;
35 using namespace Gtkmm2ext;
36 using namespace Gtk;
37 using namespace PBD;
38 using std::string;
39
40 VCAMasterStrip::VCAMasterStrip (Session* s, boost::shared_ptr<VCA> v)
41         : AxisView (s)
42         , _vca (v)
43         , gain_meter (s, 250)
44 {
45         gain_meter.set_controls (boost::shared_ptr<Route>(),
46                                  boost::shared_ptr<PeakMeter>(),
47                                  boost::shared_ptr<Amp>(),
48                                  _vca->gain_control());
49
50         solo_button.set_name ("solo button");
51         set_tooltip (solo_button, _("Solo slaves"));
52         solo_button.signal_button_release_event().connect (sigc::mem_fun (*this, &VCAMasterStrip::solo_release), false);
53
54         mute_button.set_name ("mute button");
55         mute_button.set_text (_("M"));
56         set_tooltip (mute_button, _("Mute slaves"));
57         mute_button.signal_button_release_event().connect (sigc::mem_fun (*this, &VCAMasterStrip::mute_release), false);
58
59         hide_button.set_icon (ArdourIcon::CloseCross);
60         set_tooltip (&hide_button, _("Hide this VCA strip"));
61
62         assign_button.set_name (X_("vca assign"));
63         set_tooltip (assign_button, _("Click to assign a VCA Master to this VCA"));
64         assign_button.signal_button_release_event().connect (sigc::mem_fun (*this, &VCAMasterStrip::vca_button_release), false);
65
66         hide_button.signal_clicked.connect (sigc::mem_fun(*this, &VCAMasterStrip::hide_clicked));
67
68         width_hide_box.pack_start (number_label, true, true);
69         width_hide_box.pack_end (hide_button, false, true);
70
71         solo_mute_box.set_spacing (2);
72         solo_mute_box.pack_start (mute_button, true, true);
73         solo_mute_box.pack_start (solo_button, true, true);
74
75         number_label.set_text (to_string (v->number(), std::dec));
76         number_label.set_elements((ArdourButton::Element)(ArdourButton::Edge|ArdourButton::Body|ArdourButton::Text|ArdourButton::Inactive));
77         number_label.set_no_show_all ();
78         number_label.set_name ("generic button");
79         number_label.set_alignment (.5, .5);
80         number_label.set_fallthrough_to_parent (true);
81
82         name_button.signal_button_press_event().connect (sigc::mem_fun (*this, &VCAMasterStrip::name_button_press), false);
83
84         top_padding.set_size_request (-1, 16); /* must match height in GroupTabs::set_size_request() */
85         bottom_padding.set_size_request (-1, 50); /* this one is a hack. there's no trivial way to compute it */
86
87         global_vpacker.set_border_width (1);
88         global_vpacker.set_spacing (0);
89
90         global_vpacker.pack_start (top_padding, false, false);
91         global_vpacker.pack_start (width_hide_box, false, false);
92         global_vpacker.pack_start (name_button, false, false);
93         global_vpacker.pack_start (vertical_padding, true, true);
94         global_vpacker.pack_start (solo_mute_box, false, false);
95         global_vpacker.pack_start (gain_meter, false, false);
96         global_vpacker.pack_start (assign_button, false, false);
97         global_vpacker.pack_start (bottom_padding, false, false);
98
99         global_frame.add (global_vpacker);
100         global_frame.set_shadow_type (Gtk::SHADOW_IN);
101         global_frame.set_name ("BaseFrame");
102
103         add (global_frame);
104
105         global_vpacker.show ();
106         global_frame.show ();
107         top_padding.show ();
108         bottom_padding.show ();
109         vertical_padding.show ();
110         hide_button.show ();
111         number_label.show ();
112         width_hide_box.show ();
113         name_button.show ();
114         gain_meter.show ();
115         solo_mute_box.show_all ();
116         assign_button.show ();
117
118         /* force setting of visible selected status */
119
120         _selected = true;
121         set_selected (false);
122         set_solo_text ();
123         update_vca_display ();
124         update_vca_name ();
125
126         _vca->PropertyChanged.connect (vca_connections, invalidator (*this), boost::bind (&VCAMasterStrip::vca_property_changed, this, _1), gui_context());
127
128         _vca->solo_control()->Changed.connect (vca_connections, invalidator (*this), boost::bind (&VCAMasterStrip::solo_changed, this), gui_context());
129         _vca->mute_control()->Changed.connect (vca_connections, invalidator (*this), boost::bind (&VCAMasterStrip::mute_changed, this), gui_context());
130
131         _vca->gain_control()->VCAStatusChange.connect (vca_connections,
132                                                   invalidator (*this),
133                                                   boost::bind (&VCAMasterStrip::update_vca_display, this),
134                                                   gui_context());
135 }
136
137 void
138 VCAMasterStrip::update_vca_display ()
139 {
140         VCAList vcas (_session->vca_manager().vcas());
141         string label;
142
143         for (VCAList::iterator v = vcas.begin(); v != vcas.end(); ++v) {
144                 if (_vca->gain_control()->slaved_to (*v)) {
145                         if (!label.empty()) {
146                                 label += ' ';
147                         }
148                         label += to_string ((*v)->number(), std::dec);
149                 }
150         }
151
152         if (label.empty()) {
153                 label = _("-vca-");
154                 assign_button.set_active_state (Gtkmm2ext::Off);
155         } else {
156                 assign_button.set_active_state (Gtkmm2ext::ExplicitActive);
157         }
158
159         assign_button.set_text (label);
160 }
161
162 string
163 VCAMasterStrip::name() const
164 {
165         return _vca->name();
166 }
167
168 void
169 VCAMasterStrip::hide_clicked ()
170 {
171 }
172
173 bool
174 VCAMasterStrip::width_button_pressed (GdkEventButton* ev)
175 {
176         return false;
177 }
178
179 void
180 VCAMasterStrip::set_selected (bool yn)
181 {
182         AxisView::set_selected (yn);
183
184         if (_selected) {
185                 global_frame.set_shadow_type (Gtk::SHADOW_ETCHED_OUT);
186                 global_frame.set_name ("MixerStripSelectedFrame");
187         } else {
188                 global_frame.set_shadow_type (Gtk::SHADOW_IN);
189                 global_frame.set_name ("MixerStripFrame");
190         }
191
192         global_frame.queue_draw ();
193 }
194
195 bool
196 VCAMasterStrip::solo_release (GdkEventButton*)
197 {
198         _vca->solo_control()->set_value (_vca->soloed() ? 0.0 : 1.0, Controllable::NoGroup);
199         return true;
200 }
201
202 bool
203 VCAMasterStrip::mute_release (GdkEventButton*)
204 {
205         _vca->mute_control()->set_value (_vca->muted() ? 0.0 : 1.0, Controllable::NoGroup);
206         return true;
207 }
208
209 void
210 VCAMasterStrip::set_solo_text ()
211 {
212         if (Config->get_solo_control_is_listen_control ()) {
213                 switch (Config->get_listen_position()) {
214                 case AfterFaderListen:
215                         solo_button.set_text (_("A"));
216                         break;
217                 case PreFaderListen:
218                         solo_button.set_text (_("P"));
219                         break;
220                         }
221         } else {
222                 solo_button.set_text (_("S"));
223         }
224 }
225
226 void
227 VCAMasterStrip::mute_changed ()
228 {
229         if (_vca->muted()) {
230                 mute_button.set_active_state (ExplicitActive);
231         } else {
232                 mute_button.set_active_state (Gtkmm2ext::Off);
233         }
234 }
235
236 void
237 VCAMasterStrip::solo_changed ()
238 {
239         if (_vca->soloed()) {
240                 solo_button.set_active_state (ExplicitActive);
241         } else {
242                 solo_button.set_active_state (Gtkmm2ext::Off);
243         }
244 }
245
246 void
247 VCAMasterStrip::vca_menu_toggle (CheckMenuItem* menuitem, uint32_t n)
248 {
249         boost::shared_ptr<VCA> vca = _session->vca_manager().vca_by_number (n);
250
251         if (!menuitem->get_active()) {
252                 if (!vca) {
253                         /* null VCA means drop all VCA assignments */
254                         vca_unassign ();
255                 } else {
256                         _vca->gain_control()->remove_master (vca);
257                 }
258         } else {
259                 if (vca) {
260                         _vca->gain_control()->add_master (vca);
261                 }
262         }
263 }
264
265 void
266 VCAMasterStrip::vca_unassign ()
267 {
268         _vca->gain_control()->clear_masters ();
269 }
270
271 bool
272 VCAMasterStrip::vca_button_release (GdkEventButton* ev)
273 {
274         using namespace Gtk::Menu_Helpers;
275
276         if (!_session) {
277                 return false;
278         }
279
280         /* primary click only */
281
282         if (ev->button != 1) {
283                 return false;
284         }
285
286         VCAList vcas (_session->vca_manager().vcas());
287
288         if (vcas.empty()) {
289                 /* XXX should probably show a message saying "No VCA masters" */
290                 return true;
291         }
292
293         Menu* menu = new Menu;
294         MenuList& items = menu->items();
295
296         items.push_back (MenuElem (_("Unassign"), sigc::mem_fun (*this, &VCAMasterStrip::vca_unassign)));
297
298         for (VCAList::iterator v = vcas.begin(); v != vcas.end(); ++v) {
299
300                 if (*v == _vca) {
301                         /* no self-mastering */
302                         continue;
303                 }
304
305                 items.push_back (CheckMenuElem ((*v)->name()));
306                 CheckMenuItem* item = dynamic_cast<CheckMenuItem*> (&items.back());
307                 if (_vca->gain_control()->slaved_to (*v)) {
308                         item->set_active (true);
309                 }
310                 item->signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &VCAMasterStrip::vca_menu_toggle), item, (*v)->number()));
311         }
312
313         menu->popup (1, ev->time);
314
315         return true;
316 }
317
318 bool
319 VCAMasterStrip::name_button_press (GdkEventButton* ev)
320 {
321         if (ev->type == GDK_2BUTTON_PRESS) {
322                 Gtk::Window* win = dynamic_cast<Gtk::Window*>(get_toplevel());
323                 FloatingTextEntry* fte = new FloatingTextEntry (win, _vca->name());
324                 fte->use_text.connect (sigc::mem_fun (*this, &VCAMasterStrip::finish_name_edit));
325                 fte->present ();
326                 return true;
327         }
328
329         return false;
330 }
331
332 void
333 VCAMasterStrip::finish_name_edit (std::string str)
334 {
335         _vca->set_name (str);
336 }
337
338 void
339 VCAMasterStrip::vca_property_changed (PropertyChange const & what_changed)
340 {
341         if (what_changed.contains (ARDOUR::Properties::name)) {
342                 update_vca_name ();
343         }
344 }
345
346 void
347 VCAMasterStrip::update_vca_name ()
348 {
349         name_button.set_text (short_version (_vca->name(), 8));
350 }