remove unused member
[ardour.git] / libs / surfaces / faderport8 / callbacks.cc
1 /*
2  * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
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 along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18
19 /* Faderport 8 Control Surface
20  * This is the button "View" of the MVC surface inteface,
21  * see actions.cc for the "Controller"
22  */
23
24 #include "ardour/plugin_insert.h"
25 #include "ardour/session.h"
26 #include "ardour/session_configuration.h"
27
28 #include "gtkmm2ext/actions.h"
29
30 #include "faderport8.h"
31
32 #include "pbd/i18n.h"
33
34 using namespace ARDOUR;
35 using namespace ArdourSurface::FP_NAMESPACE;
36 using namespace ArdourSurface::FP_NAMESPACE::FP8Types;
37
38 void
39 FaderPort8::connect_session_signals ()
40 {
41          session->RouteAdded.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_stripable_added_or_removed, this), this);
42          PresentationInfo::Change.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_pi_property_changed, this, _1), this);
43
44         Config->ParameterChanged.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_parameter_changed, this, _1), this);
45         session->config.ParameterChanged.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_parameter_changed, this, _1), this);
46
47         session->TransportStateChange.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_transport_state_changed, this), this);
48         session->TransportLooped.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_loop_state_changed, this), this);
49         session->RecordStateChanged.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_record_state_changed, this), this);
50
51         session->DirtyChanged.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_session_dirty_changed, this), this);
52         session->SoloChanged.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_solo_changed, this), this);
53         session->MuteChanged.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_mute_changed, this), this);
54         session->history().Changed.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&FaderPort8::notify_history_changed, this), this);
55 }
56
57 void
58 FaderPort8::send_session_state ()
59 {
60         notify_transport_state_changed ();
61         notify_record_state_changed ();
62         notify_session_dirty_changed ();
63         notify_history_changed ();
64         notify_solo_changed ();
65         notify_mute_changed ();
66         notify_parameter_changed ("clicking");
67
68         notify_route_state_changed (); // XXX (stip specific, see below)
69 }
70
71 // TODO: AutomationState display of plugin & send automation
72 // TODO: link/lock control AS.
73 void
74 FaderPort8::notify_route_state_changed ()
75 {
76         boost::shared_ptr<Stripable> s = first_selected_stripable();
77         boost::shared_ptr<AutomationControl> ac;
78         if (s) {
79                 switch (_ctrls.fader_mode ()) {
80                         case ModeTrack:
81                                 ac = s->gain_control();
82                                 break;
83                         case ModePan:
84                                 ac = s->pan_azimuth_control();
85                                 break;
86                         default:
87                                 break;
88                 }
89         }
90         if (!s || !ac) {
91                 _ctrls.button (FP8Controls::BtnALatch).set_active (false);
92                 _ctrls.button (FP8Controls::BtnATrim).set_active (false);
93                 _ctrls.button (FP8Controls::BtnAOff).set_active (false);
94                 _ctrls.button (FP8Controls::BtnATouch).set_active (false);
95                 _ctrls.button (FP8Controls::BtnARead).set_active (false);
96                 _ctrls.button (FP8Controls::BtnAWrite).set_active (false);
97 #ifdef FADERPORT2
98                 _ctrls.button (FP8Controls::BtnArm).set_active (false);
99 #endif
100                 return;
101         }
102
103         ARDOUR::AutoState as = ac->automation_state();
104         _ctrls.button (FP8Controls::BtnAOff).set_active (as == Off);
105         _ctrls.button (FP8Controls::BtnATouch).set_active (as == Touch);
106         _ctrls.button (FP8Controls::BtnARead).set_active (as == Play);
107         _ctrls.button (FP8Controls::BtnAWrite).set_active (as == Write);
108         _ctrls.button (FP8Controls::BtnALatch).set_active (as == Latch);
109
110 #ifdef FADERPORT2
111         /* handle the Faderport's track-arm button */
112         ac = s->rec_enable_control ();
113         _ctrls.button (FP8Controls::BtnArm).set_active (ac ? ac->get_value() : false);
114 #endif
115 }
116
117 void
118 FaderPort8::notify_parameter_changed (std::string param)
119 {
120         if (param == "clicking") {
121                 _ctrls.button (FP8Controls::BtnClick).set_active (Config->get_clicking ());
122         }
123 }
124
125 void
126 FaderPort8::notify_transport_state_changed ()
127 {
128         if (session->transport_rolling ()) {
129                 _ctrls.button (FP8Controls::BtnPlay).set_active (true);
130                 _ctrls.button (FP8Controls::BtnStop).set_active (false);
131         } else {
132                 _ctrls.button (FP8Controls::BtnPlay).set_active (false);
133                 _ctrls.button (FP8Controls::BtnStop).set_active (true);
134         }
135
136         /* set rewind/fastforward lights */
137         const float ts = session->transport_speed ();
138         FP8ButtonInterface& b_rew = _ctrls.button (FP8Controls::BtnRewind);
139         FP8ButtonInterface& b_ffw = _ctrls.button (FP8Controls::BtnFastForward);
140
141         const bool rew = (ts < 0.f);
142         const bool ffw = (ts > 0.f && ts != 1.f);
143         if (b_rew.is_active() != rew) {
144                 b_rew.set_active (rew);
145         }
146         if (b_ffw.is_active() != ffw) {
147                 b_ffw.set_active (ffw);
148         }
149
150         notify_loop_state_changed ();
151 }
152
153 void
154 FaderPort8::notify_record_state_changed ()
155 {
156         switch (session->record_status ()) {
157                 case Session::Disabled:
158                         _ctrls.button (FP8Controls::BtnRecord).set_active (0);
159                         _ctrls.button (FP8Controls::BtnRecord).set_blinking (false);
160                         break;
161                 case Session::Enabled:
162                         _ctrls.button (FP8Controls::BtnRecord).set_active (true);
163                         _ctrls.button (FP8Controls::BtnRecord).set_blinking (true);
164                         break;
165                 case Session::Recording:
166                         _ctrls.button (FP8Controls::BtnRecord).set_active (true);
167                         _ctrls.button (FP8Controls::BtnRecord).set_blinking (false);
168                         break;
169         }
170 }
171
172 void
173 FaderPort8::notify_loop_state_changed ()
174 {
175         bool looping = false;
176         Location* looploc = session->locations ()->auto_loop_location ();
177         if (looploc && session->get_play_loop ()) {
178                 looping = true;
179         }
180         _ctrls.button (FP8Controls::BtnLoop).set_active (looping);
181 }
182
183 void
184 FaderPort8::notify_session_dirty_changed ()
185 {
186         const bool is_dirty = session->dirty ();
187         _ctrls.button (FP8Controls::BtnSave).set_active (is_dirty);
188         _ctrls.button (FP8Controls::BtnSave).set_color (is_dirty ? 0xff0000ff : 0x00ff00ff);
189 }
190
191 void
192 FaderPort8::notify_history_changed ()
193 {
194         _ctrls.button (FP8Controls::BtnRedo).set_active (session->redo_depth() > 0);
195         _ctrls.button (FP8Controls::BtnUndo).set_active (session->undo_depth() > 0);
196 }
197
198 void
199 FaderPort8::notify_solo_changed ()
200 {
201         bool soloing = session->soloing() || session->listening();
202 #ifdef MIXBUS
203         soloing |= session->mixbus_soloed();
204 #endif
205         _ctrls.button (FP8Controls::BtnSoloClear).set_active (soloing);
206 #ifdef FP8_MUTESOLO_UNDO
207         if (soloing) {
208                 _solo_state.clear ();
209         }
210 #endif
211 }
212
213 void
214 FaderPort8::notify_mute_changed ()
215 {
216         bool muted = session->muted ();
217 #ifdef FP8_MUTESOLO_UNDO
218         if (muted) {
219                 _mute_state.clear ();
220         }
221 #endif
222         _ctrls.button (FP8Controls::BtnMuteClear).set_active (muted);
223 }
224
225 void
226 FaderPort8::notify_plugin_active_changed ()
227 {
228         boost::shared_ptr<PluginInsert> pi = _plugin_insert.lock();
229         if (pi) {
230                 _ctrls.button (FP8Controls::BtnBypass).set_active (true);
231                 _ctrls.button (FP8Controls::BtnBypass).set_color (pi->enabled () ? 0x00ff00ff : 0xff0000ff);
232         } else {
233                 _ctrls.button (FP8Controls::BtnBypass).set_active (false);
234                 _ctrls.button (FP8Controls::BtnBypass).set_color (0x888888ff);
235         }
236 }
237
238 void
239 FaderPort8::nofity_focus_control (boost::weak_ptr<PBD::Controllable> c)
240 {
241         assert (_link_enabled && !_link_locked);
242         // TODO consider subscribing to c's DropReferences
243         // (in case the control goes away while it has focus, update the BtnColor)
244         _link_control = c;
245         if (c.expired () || 0 == boost::dynamic_pointer_cast<AutomationControl> (_link_control.lock ())) {
246                 _ctrls.button (FP8Controls::BtnLink).set_color (0xff8800ff);
247                 _ctrls.button (FP8Controls::BtnLock).set_color (0xff0000ff);
248         } else {
249                 _ctrls.button (FP8Controls::BtnLink).set_color (0x88ff00ff);
250                 _ctrls.button (FP8Controls::BtnLock).set_color (0x00ff88ff);
251         }
252 }