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