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