enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / gtk2_ardour / vca_time_axis.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
20 #include "pbd/convert.h"
21
22 #include "ardour/mute_control.h"
23 #include "ardour/profile.h"
24 #include "ardour/session.h"
25 #include "ardour/solo_control.h"
26 #include "ardour/vca.h"
27
28 #include "gtkmm2ext/doi.h"
29
30 #include "gui_thread.h"
31 #include "public_editor.h"
32 #include "tooltips.h"
33 #include "ui_config.h"
34 #include "vca_time_axis.h"
35
36 #include "pbd/i18n.h"
37
38 using namespace ARDOUR;
39 using namespace ARDOUR_UI_UTILS;
40 using namespace Gtkmm2ext;
41 using namespace PBD;
42
43 VCATimeAxisView::VCATimeAxisView (PublicEditor& ed, Session* s, ArdourCanvas::Canvas& canvas)
44         : SessionHandlePtr (s)
45         , TimeAxisView (s, ed, (TimeAxisView*) 0, canvas)
46         , gain_meter (s, true, 75, 14) // XXX stupid magic numbers, match sizes in RouteTimeAxisView
47 {
48         solo_button.set_name ("solo button");
49         set_tooltip (solo_button, _("Solo slaves"));
50         solo_button.signal_button_release_event().connect (sigc::mem_fun (*this, &VCATimeAxisView::solo_release), false);
51         mute_button.unset_flags (Gtk::CAN_FOCUS);
52
53         mute_button.set_name ("mute button");
54         mute_button.set_text (_("M"));
55         set_tooltip (mute_button, _("Mute slaves"));
56         mute_button.signal_button_release_event().connect (sigc::mem_fun (*this, &VCATimeAxisView::mute_release), false);
57         solo_button.unset_flags (Gtk::CAN_FOCUS);
58
59         drop_button.set_name ("mute button");
60         drop_button.set_text (_("D"));
61         set_tooltip (drop_button, _("Unassign all slaves"));
62         drop_button.signal_button_release_event().connect (sigc::mem_fun (*this, &VCATimeAxisView::drop_release), false);
63
64         spill_button.set_name ("mute button");
65         spill_button.set_text (_("V"));
66         set_tooltip (spill_button, _("Show only slaves"));
67         spill_button.signal_button_release_event().connect (sigc::mem_fun (*this, &VCATimeAxisView::spill_release), false);
68
69         mute_button.set_tweaks(ArdourButton::TrackHeader);
70         solo_button.set_tweaks(ArdourButton::TrackHeader);
71         drop_button.set_tweaks(ArdourButton::TrackHeader);
72         spill_button.set_tweaks(ArdourButton::TrackHeader);
73
74         controls_table.attach (mute_button, 2, 3, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
75         controls_table.attach (solo_button, 3, 4, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
76         controls_table.attach (drop_button, 2, 3, 1, 2, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
77         controls_table.attach (spill_button, 3, 4, 1, 2, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
78         controls_table.attach (gain_meter.get_gain_slider(), 0, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 1, 0);
79
80         mute_button.show ();
81         solo_button.show ();
82         drop_button.show ();
83         spill_button.show ();
84         gain_meter.get_gain_slider().show ();
85
86         controls_ebox.set_name ("ControlMasterBaseUnselected");
87         time_axis_frame.set_name ("ControlMasterBaseUnselected");
88
89         s->config.ParameterChanged.connect (*this, invalidator (*this), boost::bind (&VCATimeAxisView::parameter_changed, this, _1), gui_context());
90         Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&VCATimeAxisView::parameter_changed, this, _1), gui_context());
91         UIConfiguration::instance().ParameterChanged.connect (sigc::mem_fun (*this, &VCATimeAxisView::parameter_changed));
92 }
93
94 VCATimeAxisView::~VCATimeAxisView ()
95 {
96 }
97
98 void
99 VCATimeAxisView::self_delete ()
100 {
101         /* reset reference immediately rather than deferring to idle */
102         _vca.reset ();
103         delete_when_idle (this);
104 }
105
106 void
107 VCATimeAxisView::parameter_changed (std::string const & p)
108 {
109         if (p == "track-name-number") {
110                 update_track_number_visibility();
111         } else if (p == "use-monitor-bus" || p == "solo-control-is-listen-control" || p == "listen-position") {
112                 set_button_names ();
113         }
114 }
115
116 bool
117 VCATimeAxisView::solo_release (GdkEventButton*)
118 {
119         /* We use NoGroup because VCA controls are never part of a group. This
120            is redundant, but clear.
121         */
122         _vca->solo_control()->set_value (_vca->solo_control()->self_soloed() ? 0.0 : 1.0, Controllable::NoGroup);
123         return true;
124 }
125
126 bool
127 VCATimeAxisView::mute_release (GdkEventButton*)
128 {
129         /* We use NoGroup because VCA controls are never part of a group. This
130            is redundant, but clear.
131         */
132         _vca->mute_control()->set_value (_vca->mute_control()->muted_by_self() ? 0.0 : 1.0, Controllable::NoGroup);
133         return true;
134 }
135
136 void
137 VCATimeAxisView::set_vca (boost::shared_ptr<VCA> v)
138 {
139         _vca = v;
140
141         gain_meter.set_controls (boost::shared_ptr<Route>(),
142                                  boost::shared_ptr<PeakMeter>(),
143                                  boost::shared_ptr<Amp>(),
144                                  _vca->gain_control());
145
146         // Mixer_UI::instance()->show_vca_change.connect (sigc::mem_fun (*this, &VCAMasterStrip::spill_change));
147
148         _vca->PropertyChanged.connect (vca_connections, invalidator (*this), boost::bind (&VCATimeAxisView::vca_property_changed, this, _1), gui_context());
149
150         _vca->solo_control()->Changed.connect (vca_connections, invalidator (*this), boost::bind (&VCATimeAxisView::update_solo_display, this), gui_context());
151         _vca->mute_control()->Changed.connect (vca_connections, invalidator (*this), boost::bind (&VCATimeAxisView::update_mute_display, this), gui_context());
152         _vca->DropReferences.connect (vca_connections, invalidator (*this), boost::bind (&VCATimeAxisView::self_delete, this), gui_context());
153
154         solo_button.set_controllable (_vca->solo_control());
155         mute_button.set_controllable (_vca->mute_control());
156
157         /* VCA number never changes */
158         number_label.set_text (to_string (_vca->number(), std::dec));
159
160         set_height (preset_height (HeightNormal));
161
162         update_vca_name ();
163         set_button_names ();
164         update_solo_display ();
165         update_mute_display ();
166         update_track_number_visibility ();
167 }
168
169 void
170 VCATimeAxisView::vca_property_changed (PropertyChange const & what_changed)
171 {
172         if (what_changed.contains (ARDOUR::Properties::name)) {
173                 update_vca_name ();
174         }
175 }
176
177 void
178 VCATimeAxisView::update_vca_name ()
179 {
180         name_label.set_text (_vca->name());
181 }
182
183 void
184 VCATimeAxisView::update_mute_display ()
185 {
186         if (_vca->mute_control()->muted_by_self()) {
187                 mute_button.set_active_state (ExplicitActive);
188         } else if (_vca->mute_control()->muted_by_masters ()) {
189                 mute_button.set_active_state (ImplicitActive);
190         } else {
191                 mute_button.set_active_state (Gtkmm2ext::Off);
192         }
193 }
194
195 void
196 VCATimeAxisView::update_solo_display ()
197 {
198         if (_vca->solo_control()->self_soloed()) {
199                 solo_button.set_active_state (ExplicitActive);
200         } else if (_vca->solo_control()->soloed_by_masters ()) {
201                 solo_button.set_active_state (ImplicitActive);
202         } else {
203                 solo_button.set_active_state (Gtkmm2ext::Off);
204         }
205
206         update_mute_display ();
207 }
208
209 std::string
210 VCATimeAxisView::name() const
211 {
212         return _vca->name();
213 }
214
215 std::string
216 VCATimeAxisView::state_id() const
217 {
218         return string_compose ("vtv %1", _vca->id().to_s());
219 }
220
221 void
222 VCATimeAxisView::set_button_names ()
223 {
224         if (Config->get_solo_control_is_listen_control()) {
225                 switch (Config->get_listen_position()) {
226                 case AfterFaderListen:
227                         solo_button.set_text (S_("AfterFader|A"));
228                         set_tooltip (solo_button, _("After-fade listen (AFL)"));
229                         break;
230                 case PreFaderListen:
231                         solo_button.set_text (S_("PreFader|P"));
232                         set_tooltip (solo_button, _("Pre-fade listen (PFL)"));
233                         break;
234                 }
235         } else {
236                 solo_button.set_text (S_("Solo|S"));
237                 set_tooltip (solo_button, _("Solo"));
238         }
239 }
240
241 void
242 VCATimeAxisView::update_track_number_visibility ()
243 {
244         DisplaySuspender ds;
245         bool show_label = _session->config.get_track_name_number();
246
247         if (number_label.get_parent()) {
248                 controls_table.remove (number_label);
249         }
250
251         if (show_label) {
252                 if (ARDOUR::Profile->get_mixbus()) {
253                         controls_table.attach (number_label, 3, 4, 0, 1, Gtk::SHRINK, Gtk::EXPAND|Gtk::FILL, 1, 0);
254                 } else {
255                         controls_table.attach (number_label, 0, 1, 0, 1, Gtk::SHRINK, Gtk::EXPAND|Gtk::FILL, 1, 0);
256                 }
257
258                 // see ArdourButton::on_size_request(), we should probably use a global size-group here instead.
259                 // except the width of the number label is subtracted from the name-hbox, so we
260                 // need to explictly calculate it anyway until the name-label & entry become ArdourWidgets.
261
262                 int tnw = (2 + std::max(2u, _session->track_number_decimals())) * number_label.char_pixel_width();
263                 if (tnw & 1) --tnw;
264                 number_label.set_size_request(tnw, -1);
265                 number_label.show ();
266         } else {
267                 number_label.hide ();
268         }
269 }
270
271 bool
272 VCATimeAxisView::spill_release (GdkEventButton*)
273 {
274         return true;
275 }
276
277 bool
278 VCATimeAxisView::drop_release (GdkEventButton*)
279 {
280         _vca->Drop (); /* EMIT SIGNAL */
281
282         return true;
283 }
284
285 PresentationInfo const &
286 VCATimeAxisView::presentation_info () const
287 {
288         return _vca->presentation_info();
289 }
290
291 boost::shared_ptr<Stripable>
292 VCATimeAxisView::stripable () const
293 {
294         return _vca;
295 }
296
297 Gdk::Color
298 VCATimeAxisView::color () const
299 {
300         return gdk_color_from_rgb (_vca->presentation_info().color ());
301 }
302
303 void
304 VCATimeAxisView::set_height (uint32_t h, TrackHeightMode m)
305 {
306         TimeAxisView::set_height (h, m);
307         set_gui_property ("height", h);
308         _vca->gui_changed ("track_height", (void*) 0); /* EMIT SIGNAL */
309 }
310
311 bool
312 VCATimeAxisView::marked_for_display () const
313 {
314         return _vca && !_vca->presentation_info().hidden();
315 }
316
317 bool
318 VCATimeAxisView::set_marked_for_display (bool yn)
319 {
320         if (_vca && (yn == _vca->presentation_info().hidden())) {
321                 _vca->presentation_info().set_hidden (!yn);
322                 return true; // things changed
323         }
324         return false;
325 }