add ::set_height() for VCATimeAxisView
[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 "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         s->config.ParameterChanged.connect (*this, invalidator (*this), boost::bind (&VCATimeAxisView::parameter_changed, this, _1), gui_context());
87         Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&VCATimeAxisView::parameter_changed, this, _1), gui_context());
88         UIConfiguration::instance().ParameterChanged.connect (sigc::mem_fun (*this, &VCATimeAxisView::parameter_changed));
89 }
90
91 VCATimeAxisView::~VCATimeAxisView ()
92 {
93 }
94
95 void
96 VCATimeAxisView::self_delete ()
97 {
98         /* reset reference immediately rather than deferring to idle */
99         _vca.reset ();
100         delete_when_idle (this);
101 }
102
103 void
104 VCATimeAxisView::parameter_changed (std::string const & p)
105 {
106         if (p == "track-name-number") {
107                 update_track_number_visibility();
108         } else if (p == "use-monitor-bus" || p == "solo-control-is-listen-control" || p == "listen-position") {
109                 set_button_names ();
110         }
111 }
112
113 bool
114 VCATimeAxisView::solo_release (GdkEventButton*)
115 {
116         /* We use NoGroup because VCA controls are never part of a group. This
117            is redundant, but clear.
118         */
119         _vca->solo_control()->set_value (_vca->solo_control()->self_soloed() ? 0.0 : 1.0, Controllable::NoGroup);
120         return true;
121 }
122
123 bool
124 VCATimeAxisView::mute_release (GdkEventButton*)
125 {
126         /* We use NoGroup because VCA controls are never part of a group. This
127            is redundant, but clear.
128         */
129         _vca->mute_control()->set_value (_vca->mute_control()->muted_by_self() ? 0.0 : 1.0, Controllable::NoGroup);
130         return true;
131 }
132
133 void
134 VCATimeAxisView::set_vca (boost::shared_ptr<VCA> v)
135 {
136         _vca = v;
137
138         gain_meter.set_controls (boost::shared_ptr<Route>(),
139                                  boost::shared_ptr<PeakMeter>(),
140                                  boost::shared_ptr<Amp>(),
141                                  _vca->gain_control());
142
143         // Mixer_UI::instance()->show_vca_change.connect (sigc::mem_fun (*this, &VCAMasterStrip::spill_change));
144
145         _vca->PropertyChanged.connect (vca_connections, invalidator (*this), boost::bind (&VCATimeAxisView::vca_property_changed, this, _1), gui_context());
146
147         _vca->solo_control()->Changed.connect (vca_connections, invalidator (*this), boost::bind (&VCATimeAxisView::update_solo_display, this), gui_context());
148         _vca->mute_control()->Changed.connect (vca_connections, invalidator (*this), boost::bind (&VCATimeAxisView::update_mute_display, this), gui_context());
149         _vca->DropReferences.connect (vca_connections, invalidator (*this), boost::bind (&VCATimeAxisView::self_delete, this), gui_context());
150
151         solo_button.set_controllable (_vca->solo_control());
152         mute_button.set_controllable (_vca->mute_control());
153
154         /* VCA number never changes */
155         number_label.set_text (to_string (_vca->number(), std::dec));
156
157         set_height (preset_height (HeightNormal));
158
159         update_vca_name ();
160         set_button_names ();
161         update_solo_display ();
162         update_mute_display ();
163         update_track_number_visibility ();
164 }
165
166 void
167 VCATimeAxisView::vca_property_changed (PropertyChange const & what_changed)
168 {
169         if (what_changed.contains (ARDOUR::Properties::name)) {
170                 update_vca_name ();
171         }
172 }
173
174 void
175 VCATimeAxisView::update_vca_name ()
176 {
177         name_label.set_text (_vca->name());
178 }
179
180 void
181 VCATimeAxisView::update_mute_display ()
182 {
183         if (_vca->mute_control()->muted_by_self()) {
184                 mute_button.set_active_state (ExplicitActive);
185         } else if (_vca->mute_control()->muted_by_masters ()) {
186                 mute_button.set_active_state (ImplicitActive);
187         } else {
188                 mute_button.set_active_state (Gtkmm2ext::Off);
189         }
190 }
191
192 void
193 VCATimeAxisView::update_solo_display ()
194 {
195         if (_vca->solo_control()->self_soloed()) {
196                 solo_button.set_active_state (ExplicitActive);
197         } else if (_vca->solo_control()->soloed_by_masters ()) {
198                 solo_button.set_active_state (ImplicitActive);
199         } else {
200                 solo_button.set_active_state (Gtkmm2ext::Off);
201         }
202
203         update_mute_display ();
204 }
205
206 std::string
207 VCATimeAxisView::name() const
208 {
209         return _vca->name();
210 }
211
212 std::string
213 VCATimeAxisView::state_id() const
214 {
215         return string_compose ("vtv %1", _vca->id().to_s());
216 }
217
218 void
219 VCATimeAxisView::set_button_names ()
220 {
221         if (Config->get_solo_control_is_listen_control()) {
222                 switch (Config->get_listen_position()) {
223                 case AfterFaderListen:
224                         solo_button.set_text (S_("AfterFader|A"));
225                         set_tooltip (solo_button, _("After-fade listen (AFL)"));
226                         break;
227                 case PreFaderListen:
228                         solo_button.set_text (S_("PreFader|P"));
229                         set_tooltip (solo_button, _("Pre-fade listen (PFL)"));
230                         break;
231                 }
232         } else {
233                 solo_button.set_text (S_("Solo|S"));
234                 set_tooltip (solo_button, _("Solo"));
235         }
236 }
237
238 void
239 VCATimeAxisView::update_track_number_visibility ()
240 {
241         DisplaySuspender ds;
242         bool show_label = _session->config.get_track_name_number();
243
244         if (number_label.get_parent()) {
245                 controls_table.remove (number_label);
246         }
247
248         if (show_label) {
249                 if (ARDOUR::Profile->get_mixbus()) {
250                         controls_table.attach (number_label, 3, 4, 0, 1, Gtk::SHRINK, Gtk::EXPAND|Gtk::FILL, 1, 0);
251                 } else {
252                         controls_table.attach (number_label, 0, 1, 0, 1, Gtk::SHRINK, Gtk::EXPAND|Gtk::FILL, 1, 0);
253                 }
254
255                 // see ArdourButton::on_size_request(), we should probably use a global size-group here instead.
256                 // except the width of the number label is subtracted from the name-hbox, so we
257                 // need to explictly calculate it anyway until the name-label & entry become ArdourWidgets.
258
259                 int tnw = (2 + std::max(2u, _session->track_number_decimals())) * number_label.char_pixel_width();
260                 if (tnw & 1) --tnw;
261                 number_label.set_size_request(tnw, -1);
262                 number_label.show ();
263         } else {
264                 number_label.hide ();
265         }
266 }
267
268 bool
269 VCATimeAxisView::spill_release (GdkEventButton*)
270 {
271         return true;
272 }
273
274 bool
275 VCATimeAxisView::drop_release (GdkEventButton*)
276 {
277         _vca->Drop (); /* EMIT SIGNAL */
278
279         return true;
280 }
281
282 PresentationInfo const &
283 VCATimeAxisView::presentation_info () const
284 {
285         return _vca->presentation_info();
286 }
287
288 boost::shared_ptr<Stripable>
289 VCATimeAxisView::stripable () const
290 {
291         return _vca;
292 }
293
294 Gdk::Color
295 VCATimeAxisView::color () const
296 {
297         return gdk_color_from_rgb (_vca->presentation_info().color ());
298 }
299
300 void
301 VCATimeAxisView::set_height (uint32_t h, TrackHeightMode m)
302 {
303         TimeAxisView::set_height (h, m);
304         set_gui_property ("height", h);
305         _vca->gui_changed ("track_height", (void*) 0); /* EMIT SIGNAL */
306 }