FaderPort8 updates
[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;
34 using namespace ArdourSurface::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_automation_mode_changed (); // XXX (stip specific, see below)
67 }
68
69 // TODO: AutomationState display of plugin & send automation ?!
70 void
71 FaderPort8::notify_automation_mode_changed ()
72 {
73         boost::shared_ptr<Stripable> s = first_selected_stripable();
74         boost::shared_ptr<AutomationControl> ac;
75         if (s) {
76                 switch (_ctrls.fader_mode ()) {
77                         case ModeTrack:
78                                 ac = s->gain_control();
79                                 break;
80                         case ModePan:
81                                 ac = s->pan_azimuth_control();
82                                 break;
83                         default:
84                                 break;
85                 }
86         }
87         if (!s || !ac) {
88                 _ctrls.button (FP8Controls::BtnALatch).set_active (false);
89                 _ctrls.button (FP8Controls::BtnATrim).set_active (false);
90                 _ctrls.button (FP8Controls::BtnAOff).set_active (false);
91                 _ctrls.button (FP8Controls::BtnATouch).set_active (false);
92                 _ctrls.button (FP8Controls::BtnARead).set_active (false);
93                 _ctrls.button (FP8Controls::BtnAWrite).set_active (false);
94                 return;
95         }
96
97         ARDOUR::AutoState as = ac->automation_state();
98         _ctrls.button (FP8Controls::BtnAOff).set_active (as == Off);
99         _ctrls.button (FP8Controls::BtnATouch).set_active (as == Touch);
100         _ctrls.button (FP8Controls::BtnARead).set_active (as == Play);
101         _ctrls.button (FP8Controls::BtnAWrite).set_active (as == Write);
102 }
103
104 void
105 FaderPort8::notify_parameter_changed (std::string param)
106 {
107         if (param == "clicking") {
108                 _ctrls.button (FP8Controls::BtnClick).set_active (Config->get_clicking ());
109         }
110 }
111
112 void
113 FaderPort8::notify_transport_state_changed ()
114 {
115         if (session->transport_rolling ()) {
116                 _ctrls.button (FP8Controls::BtnPlay).set_active (true);
117                 _ctrls.button (FP8Controls::BtnStop).set_active (false);
118         } else {
119                 _ctrls.button (FP8Controls::BtnPlay).set_active (false);
120                 _ctrls.button (FP8Controls::BtnStop).set_active (true);
121         }
122
123         /* set rewind/fastforward lights */
124         const float ts = session->transport_speed ();
125         FP8ButtonInterface& b_rew = _ctrls.button (FP8Controls::BtnRewind);
126         FP8ButtonInterface& b_ffw = _ctrls.button (FP8Controls::BtnFastForward);
127
128         const bool rew = (ts < 0.f);
129         const bool ffw = (ts > 0.f && ts != 1.f);
130         if (b_rew.is_active() != rew) {
131                 b_rew.set_active (rew);
132         }
133         if (b_ffw.is_active() != ffw) {
134                 b_ffw.set_active (ffw);
135         }
136
137         notify_loop_state_changed ();
138 }
139
140 void
141 FaderPort8::notify_record_state_changed ()
142 {
143         switch (session->record_status ()) {
144                 case Session::Disabled:
145                         _ctrls.button (FP8Controls::BtnRecord).set_active (0);
146                         _ctrls.button (FP8Controls::BtnRecord).set_blinking (false);
147                         break;
148                 case Session::Enabled:
149                         _ctrls.button (FP8Controls::BtnRecord).set_active (true);
150                         _ctrls.button (FP8Controls::BtnRecord).set_blinking (true);
151                         break;
152                 case Session::Recording:
153                         _ctrls.button (FP8Controls::BtnRecord).set_active (true);
154                         _ctrls.button (FP8Controls::BtnRecord).set_blinking (false);
155                         break;
156         }
157 }
158
159 void
160 FaderPort8::notify_loop_state_changed ()
161 {
162         bool looping = false;
163         Location* looploc = session->locations ()->auto_loop_location ();
164         if (looploc && session->get_play_loop ()) {
165                 looping = true;
166         }
167         _ctrls.button (FP8Controls::BtnLoop).set_active (looping);
168 }
169
170 void
171 FaderPort8::notify_session_dirty_changed ()
172 {
173         const bool is_dirty = session->dirty ();
174         _ctrls.button (FP8Controls::BtnSave).set_active (is_dirty);
175         _ctrls.button (FP8Controls::BtnSave).set_color (is_dirty ? 0xff0000ff : 0x00ff00ff);
176 }
177
178 void
179 FaderPort8::notify_history_changed ()
180 {
181         _ctrls.button (FP8Controls::BtnRedo).set_active (session->redo_depth() > 0);
182         _ctrls.button (FP8Controls::BtnUndo).set_active (session->undo_depth() > 0);
183 }
184
185 void
186 FaderPort8::notify_solo_changed ()
187 {
188         bool soloing = session->soloing() || session->listening();
189         _ctrls.button (FP8Controls::BtnSoloClear).set_active (soloing);
190 #ifdef FP8_MUTESOLO_UNDO
191         if (soloing) {
192                 _solo_state.clear ();
193         }
194 #endif
195 }
196
197 void
198 FaderPort8::notify_mute_changed ()
199 {
200         bool muted = session->muted ();
201 #ifdef FP8_MUTESOLO_UNDO
202         if (muted) {
203                 _mute_state.clear ();
204         }
205 #endif
206         _ctrls.button (FP8Controls::BtnMuteClear).set_active (muted);
207 }
208
209 void
210 FaderPort8::notify_plugin_active_changed ()
211 {
212         boost::shared_ptr<PluginInsert> pi = _plugin_insert.lock();
213         if (pi) {
214                 _ctrls.button (FP8Controls::BtnBypass).set_active (true);
215                 _ctrls.button (FP8Controls::BtnBypass).set_color (pi->enabled () ? 0x00ff00ff : 0xff0000ff);
216         } else {
217                 _ctrls.button (FP8Controls::BtnBypass).set_active (false);
218                 _ctrls.button (FP8Controls::BtnBypass).set_color (0x888888ff);
219         }
220 }