move from PresentationInfo::global_order() to PresentationInfo::order, and fix up...
[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         update_vca_name ();
156         set_button_names ();
157         update_solo_display ();
158         update_mute_display ();
159         update_track_number_visibility ();
160 }
161
162 void
163 VCATimeAxisView::vca_property_changed (PropertyChange const & what_changed)
164 {
165         if (what_changed.contains (ARDOUR::Properties::name)) {
166                 update_vca_name ();
167         }
168 }
169
170 void
171 VCATimeAxisView::update_vca_name ()
172 {
173         name_label.set_text (_vca->name());
174 }
175
176 void
177 VCATimeAxisView::update_mute_display ()
178 {
179         if (_vca->mute_control()->muted_by_self()) {
180                 mute_button.set_active_state (ExplicitActive);
181         } else if (_vca->mute_control()->muted_by_masters ()) {
182                 mute_button.set_active_state (ImplicitActive);
183         } else {
184                 mute_button.set_active_state (Gtkmm2ext::Off);
185         }
186 }
187
188 void
189 VCATimeAxisView::update_solo_display ()
190 {
191         if (_vca->solo_control()->self_soloed()) {
192                 solo_button.set_active_state (ExplicitActive);
193         } else if (_vca->solo_control()->soloed_by_masters ()) {
194                 solo_button.set_active_state (ImplicitActive);
195         } else {
196                 solo_button.set_active_state (Gtkmm2ext::Off);
197         }
198
199         update_mute_display ();
200 }
201
202 std::string
203 VCATimeAxisView::name() const
204 {
205         return _vca->name();
206 }
207
208 std::string
209 VCATimeAxisView::state_id() const
210 {
211         return string_compose ("vtv %1", _vca->id().to_s());
212 }
213
214 void
215 VCATimeAxisView::set_button_names ()
216 {
217         if (Config->get_solo_control_is_listen_control()) {
218                 switch (Config->get_listen_position()) {
219                 case AfterFaderListen:
220                         solo_button.set_text (S_("AfterFader|A"));
221                         set_tooltip (solo_button, _("After-fade listen (AFL)"));
222                         break;
223                 case PreFaderListen:
224                         solo_button.set_text (S_("PreFader|P"));
225                         set_tooltip (solo_button, _("Pre-fade listen (PFL)"));
226                         break;
227                 }
228         } else {
229                 solo_button.set_text (S_("Solo|S"));
230                 set_tooltip (solo_button, _("Solo"));
231         }
232 }
233
234 void
235 VCATimeAxisView::update_track_number_visibility ()
236 {
237         DisplaySuspender ds;
238         bool show_label = _session->config.get_track_name_number();
239
240         if (number_label.get_parent()) {
241                 controls_table.remove (number_label);
242         }
243
244         if (show_label) {
245                 if (ARDOUR::Profile->get_mixbus()) {
246                         controls_table.attach (number_label, 3, 4, 0, 1, Gtk::SHRINK, Gtk::EXPAND|Gtk::FILL, 1, 0);
247                 } else {
248                         controls_table.attach (number_label, 0, 1, 0, 1, Gtk::SHRINK, Gtk::EXPAND|Gtk::FILL, 1, 0);
249                 }
250
251                 // see ArdourButton::on_size_request(), we should probably use a global size-group here instead.
252                 // except the width of the number label is subtracted from the name-hbox, so we
253                 // need to explictly calculate it anyway until the name-label & entry become ArdourWidgets.
254
255                 int tnw = (2 + std::max(2u, _session->track_number_decimals())) * number_label.char_pixel_width();
256                 if (tnw & 1) --tnw;
257                 number_label.set_size_request(tnw, -1);
258                 number_label.show ();
259         } else {
260                 number_label.hide ();
261         }
262 }
263
264 bool
265 VCATimeAxisView::spill_release (GdkEventButton*)
266 {
267         return true;
268 }
269
270 bool
271 VCATimeAxisView::drop_release (GdkEventButton*)
272 {
273         _vca->Drop (); /* EMIT SIGNAL */
274
275         return true;
276 }
277
278 PresentationInfo const &
279 VCATimeAxisView::presentation_info () const
280 {
281         return _vca->presentation_info();
282 }
283
284 boost::shared_ptr<Stripable>
285 VCATimeAxisView::stripable () const
286 {
287         return _vca;
288 }