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