1 /* Faderport 8 Control Surface
2 * Abstraction of Surface Control Elements.
4 * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "fp8_controls.h"
23 using namespace ArdourSurface::FP_NAMESPACE;
24 using namespace ArdourSurface::FP_NAMESPACE::FP8Types;
26 bool FP8ButtonInterface::force_change = false;
28 #define NEWBUTTON(midi_id, button_id, color) \
30 assert (_midimap.end() == _midimap.find (midi_id)); \
31 assert (_ctrlmap.end() == _ctrlmap.find (button_id)); \
32 FP8Button *t = new FP8Button (b, midi_id); \
33 _midimap[midi_id] = t; \
34 _ctrlmap[button_id] = t; \
38 #define NEWTYPEBUTTON(TYPE, midi_id, button_id, color) \
40 assert (_midimap.end() == _midimap.find (midi_id)); \
41 assert (_ctrlmap.end() == _ctrlmap.find (button_id)); \
42 TYPE *t = new TYPE (b, midi_id); \
43 _midimap[midi_id] = t; \
44 _ctrlmap[button_id] = t; \
49 #define NEWSHIFTBUTTON(midi_id, id1, id2, color) \
51 assert (_midimap.end() == _midimap.find (midi_id)); \
52 assert (_ctrlmap.end() == _ctrlmap.find (id1)); \
53 assert (_ctrlmap.end() == _ctrlmap.find (id2)); \
54 FP8ShiftSensitiveButton *t = \
55 new FP8ShiftSensitiveButton (b, midi_id, color); \
56 _midimap[midi_id] = t; \
57 _ctrlmap[id1] = t->button (); \
58 _ctrlmap[id2] = t->button_shift (); \
62 FP8Controls::FP8Controls (FP8Base& b)
63 : _fadermode (ModeTrack)
65 , _navmode (NavScroll)
67 , _navmode (NavMaster)
70 , _display_timecode (false)
72 NEWBUTTON (0x56, BtnLoop, false);
73 NEWTYPEBUTTON (FP8RepeatButton, 0x5b, BtnRewind, false);
74 NEWTYPEBUTTON (FP8RepeatButton, 0x5c, BtnFastForward, false);
75 NEWBUTTON (0x5d, BtnStop, false);
76 NEWBUTTON (0x5e, BtnPlay, false);
77 NEWBUTTON (0x5f, BtnRecord, false);
81 NEWSHIFTBUTTON (0x4a, BtnARead, BtnAOff, true);
82 NEWSHIFTBUTTON (0x4b, BtnAWrite, BtnATrim, true);
83 NEWSHIFTBUTTON (0x4d, BtnATouch, BtnALatch, true);
85 NEWSHIFTBUTTON (0x2e, BtnPrev, BtnUndo, false);
86 NEWSHIFTBUTTON (0x2f, BtnNext, BtnRedo, false);
88 NEWSHIFTBUTTON (0x2a, BtnPan, BtnFlip, true); //TODO: Flip Pan knob to fader ...?
90 NEWSHIFTBUTTON (0x36, BtnChannel, BtnChanLock, true);
92 NEWSHIFTBUTTON (0x38, BtnScroll, BtnZoom, true);
94 NEWSHIFTBUTTON (0x3a, BtnMaster, BtnF1, false);
95 NEWSHIFTBUTTON (0x3b, BtnClick, BtnF2, false);
96 NEWSHIFTBUTTON (0x3c, BtnSection, BtnF3, false);
97 NEWSHIFTBUTTON (0x3d, BtnMarker, BtnF4, false);
99 //these buttons do not exist in FP2, but they need to exist in the ctrlmap:
100 NEWBUTTON (0x71, BtnBank, false);
101 NEWBUTTON (0x72, BtnF5, false);
102 NEWBUTTON (0x73, BtnF6, false);
103 NEWBUTTON (0x74, BtnF7, false);
104 NEWBUTTON (0x75, BtnF8, false);
105 NEWBUTTON (0x76, BtnUser1, false);
106 NEWBUTTON (0x77, BtnUser2, false);
107 NEWBUTTON (0x78, BtnUser3, false);
108 NEWBUTTON (0x79, BtnSave, false);
111 NEWSHIFTBUTTON (0x4a, BtnARead, BtnUser3, true);
112 NEWSHIFTBUTTON (0x4b, BtnAWrite, BtnUser2, true);
113 NEWSHIFTBUTTON (0x4c, BtnATrim, BtnRedo, true);
114 NEWSHIFTBUTTON (0x4d, BtnATouch, BtnUser1, true);
115 NEWSHIFTBUTTON (0x4e, BtnALatch, BtnSave, true);
116 NEWSHIFTBUTTON (0x4f, BtnAOff, BtnUndo, true);
118 NEWBUTTON (0x2e, BtnPrev, false);
119 NEWBUTTON (0x2f, BtnNext, false);
121 NEWSHIFTBUTTON (0x36, BtnChannel, BtnF1, false);
122 NEWSHIFTBUTTON (0x37, BtnZoom, BtnF2, false);
123 NEWSHIFTBUTTON (0x38, BtnScroll, BtnF3, false);
124 NEWSHIFTBUTTON (0x39, BtnBank, BtnF4, false);
125 NEWSHIFTBUTTON (0x3a, BtnMaster, BtnF5, false);
126 NEWSHIFTBUTTON (0x3b, BtnClick, BtnF6, false);
127 NEWSHIFTBUTTON (0x3c, BtnSection, BtnF7, false);
128 NEWSHIFTBUTTON (0x3d, BtnMarker, BtnF8, false);
130 NEWBUTTON (0x2a, BtnPan, false);
133 NEWSHIFTBUTTON (0x28, BtnTrack, BtnTimecode, false);
134 NEWBUTTON (0x2b, BtnPlugins, false);
135 NEWBUTTON (0x29, BtnSend, false);
137 NEWSHIFTBUTTON (0x00, BtnArm, BtnArmAll, false);
138 NEWBUTTON (0x01, BtnSoloClear, false);
139 NEWBUTTON (0x02, BtnMuteClear, false);
141 NEWSHIFTBUTTON (0x03, BtnBypass, BtnBypassAll, true);
142 NEWSHIFTBUTTON (0x04, BtnMacro, BtnOpen, true);
143 NEWSHIFTBUTTON (0x05, BtnLink, BtnLock, true);
145 NEWSHIFTBUTTON (0x3e, BtnMAudio, BtnMInputs, true);
146 NEWSHIFTBUTTON (0x3f, BtnMVI, BtnMMIDI, true);
147 NEWSHIFTBUTTON (0x40, BtnMBus, BtnMOutputs, true);
148 NEWSHIFTBUTTON (0x41, BtnMVCA, BtnMFX, true);
149 NEWSHIFTBUTTON (0x42, BtnMAll, BtnMUser, true);
151 NEWTYPEBUTTON (FP8ReadOnlyButton, 0x53, BtnEncoder, false);
152 NEWTYPEBUTTON (FP8ReadOnlyButton, 0x20, BtnParam, false);
153 NEWTYPEBUTTON (FP8ReadOnlyButton, 0x66, BtnFootswitch, false);
155 /* internal bindings */
157 #define BindMethod(ID, CB) \
158 button (ID).released.connect_same_thread (button_connections, boost::bind (&FP8Controls:: CB, this));
160 BindMethod (FP8Controls::BtnTimecode, toggle_timecode);
162 #define BindNav(BTN, MODE)\
163 button (BTN).released.connect_same_thread (button_connections, boost::bind (&FP8Controls::set_nav_mode, this, MODE))
165 BindNav (BtnChannel, NavChannel);
166 BindNav (BtnZoom, NavZoom);
167 BindNav (BtnScroll, NavScroll);
168 BindNav (BtnBank, NavBank);
169 BindNav (BtnMaster, NavMaster);
170 BindNav (BtnSection, NavSection);
171 BindNav (BtnMarker, NavMarker);
173 BindNav (BtnPan, NavPan);
176 #define BindFader(BTN, MODE)\
177 button (BTN).released.connect_same_thread (button_connections, boost::bind (&FP8Controls::set_fader_mode, this, MODE))
179 BindFader (BtnTrack, ModeTrack);
180 BindFader (BtnPlugins, ModePlugins);
181 BindFader (BtnSend, ModeSend);
183 BindFader (BtnPan, ModePan);
187 #define BindMix(BTN, MODE)\
188 button (BTN).released.connect_same_thread (button_connections, boost::bind (&FP8Controls::set_mix_mode, this, MODE))
190 BindMix (BtnMAudio, MixAudio);
191 BindMix (BtnMVI, MixInstrument);
192 BindMix (BtnMBus, MixBus);
193 BindMix (BtnMVCA, MixVCA);
194 BindMix (BtnMAll, MixAll);
195 BindMix (BtnMInputs, MixInputs);
196 BindMix (BtnMMIDI, MixMIDI);
197 BindMix (BtnMOutputs, MixOutputs);
198 BindMix (BtnMFX, MixFX);
199 BindMix (BtnMUser, MixUser);
201 /* create channelstrips */
202 for (uint8_t id = 0; id < N_STRIPS; ++id) {
203 chanstrip[id] = new FP8Strip (b, id);
204 _midimap_strip[FP8Strip::midi_ctrl_id (FP8Strip::BtnSolo, id)] = &(chanstrip[id]->solo_button());
205 _midimap_strip[FP8Strip::midi_ctrl_id (FP8Strip::BtnMute, id)] = &(chanstrip[id]->mute_button());
206 _midimap_strip[FP8Strip::midi_ctrl_id (FP8Strip::BtnSelect, id)] = &(chanstrip[id]->selrec_button());
209 /* set User button names */
211 #define REGISTER_ENUM(ID, NAME) \
212 _user_str_to_enum[#ID] = ID; \
213 _user_enum_to_str[ID] = #ID; \
214 _user_buttons[ID] = NAME;
216 REGISTER_ENUM (BtnFootswitch, "Footswitch");
217 REGISTER_ENUM (BtnUser1 , "User 1");
218 REGISTER_ENUM (BtnUser2 , "User 2");
219 REGISTER_ENUM (BtnUser3 , "User 3");
220 REGISTER_ENUM (BtnF1 , "F1");
221 REGISTER_ENUM (BtnF2 , "F2");
222 REGISTER_ENUM (BtnF3 , "F3");
223 REGISTER_ENUM (BtnF4 , "F4");
224 REGISTER_ENUM (BtnF5 , "F5");
225 REGISTER_ENUM (BtnF6 , "F6");
226 REGISTER_ENUM (BtnF7 , "F7");
227 REGISTER_ENUM (BtnF8 , "F8");
231 FP8Controls::~FP8Controls ()
233 for (MidiButtonMap::const_iterator i = _midimap.begin (); i != _midimap.end (); ++i) {
236 for (uint8_t id = 0; id < N_STRIPS; ++id) {
237 delete chanstrip[id];
239 _midimap_strip.clear ();
245 FP8Controls::button_name_to_enum (std::string const& n, ButtonId& id) const
247 std::map<std::string, ButtonId>::const_iterator i = _user_str_to_enum.find (n);
248 if (i == _user_str_to_enum.end()) {
256 FP8Controls::button_enum_to_name (ButtonId id, std::string& n) const
258 std::map<ButtonId, std::string>::const_iterator i = _user_enum_to_str.find (id);
259 if (i == _user_enum_to_str.end()) {
267 FP8Controls::initialize ()
269 FP8ButtonInterface::force_change = true;
271 button (BtnUndo).set_color (0x00ff00ff);
272 button (BtnRedo).set_color (0x00ff00ff);
274 button (BtnAOff).set_color (0xffffffff);
275 button (BtnATrim).set_color (0x000030ff);
276 button (BtnARead).set_color (0x00ff00ff);
277 button (BtnAWrite).set_color (0xff0000ff);
278 button (BtnATouch).set_color (0xff8800ff);
279 button (BtnALatch).set_color (0xffff00ff);
281 button (BtnUser1).set_color (0x0000ffff);
282 button (BtnUser2).set_color (0x0000ffff);
283 button (BtnUser3).set_color (0x0000ffff);
285 button (BtnBypass).set_color (0x888888ff);
286 button (BtnBypassAll).set_color (0xffffffff);
288 button (BtnMacro).set_color (0x888888ff);
289 button (BtnOpen).set_color (0xffffffff);
291 button (BtnLink).set_color (0x888888ff);
292 button (BtnLock).set_color (0xffffffff);
294 button (BtnMAudio).set_color (0x0000ffff);
295 button (BtnMVI).set_color (0x0000ffff);
296 button (BtnMBus).set_color (0x0000ffff);
297 button (BtnMVCA).set_color (0x0000ffff);
298 button (BtnMAll).set_color (0x0000ffff);
300 button (BtnMInputs).set_color (0x0000ffff);
301 button (BtnMMIDI).set_color (0x0000ffff);
302 button (BtnMOutputs).set_color (0x0000ffff);
303 button (BtnMFX).set_color (0x0000ffff);
304 button (BtnMUser).set_color (0x0000ffff);
307 /* encoder mode-switches are orange, to match the Master switch physical color */
308 button (BtnLink).set_color (0x000000ff);
309 button (BtnChannel).set_color (0x0000ffff);
310 button (BtnScroll).set_color (0x0000ffff);
311 button (BtnPan).set_color (0xffffffff);
314 for (uint8_t id = 0; id < N_STRIPS; ++id) {
315 chanstrip[id]->initialize ();
318 /* initally turn all lights off */
323 button (BtnScroll).set_active (true);
325 button (BtnMaster).set_active (true);
327 button (BtnTrack).set_active (true);
328 button (BtnMAll).set_active (true);
329 button (BtnTimecode).set_active (_display_timecode);
331 FP8ButtonInterface::force_change = false;
335 FP8Controls::all_lights_off () const
337 for (CtrlButtonMap::const_iterator i = _ctrlmap.begin (); i != _ctrlmap.end (); ++i) {
338 i->second->set_active (false);
343 FP8Controls::button (ButtonId id)
345 CtrlButtonMap::const_iterator i = _ctrlmap.find (id);
346 if (i == _ctrlmap.end()) {
348 return _dummy_button;
354 FP8Controls::strip (uint8_t id)
356 assert (id < N_STRIPS);
357 return *chanstrip[id];
360 /* *****************************************************************************
361 * Delegate MIDI events
365 FP8Controls::midi_event (uint8_t id, uint8_t val)
367 MidiButtonMap::const_iterator i;
369 i = _midimap_strip.find (id);
370 if (i != _midimap_strip.end()) {
371 return i->second->midi_event (val > 0x40);
374 i = _midimap.find (id);
375 if (i != _midimap.end()) {
376 return i->second->midi_event (val > 0x40);
382 FP8Controls::midi_touch (uint8_t id, uint8_t val)
384 assert (id < N_STRIPS);
385 return chanstrip[id]->midi_touch (val > 0x40);
389 FP8Controls::midi_fader (uint8_t id, unsigned short val)
391 assert (id < N_STRIPS);
392 return chanstrip[id]->midi_fader ((val >> 4) / 1023.f);
395 /* *****************************************************************************
396 * Internal Model + View for Modes
400 FP8Controls::set_nav_mode (NavigationMode m)
405 // TODO add special-cases:
406 // - master/monitor (blink when button is held + monitor section present)
407 // - "click" hold -> encoder sets click volume, encoder-press toggle rec-only-metro
408 button (BtnChannel).set_active (m == NavChannel);
409 button (BtnZoom).set_active (m == NavZoom);
410 button (BtnScroll).set_active (m == NavScroll);
411 button (BtnBank).set_active (m == NavBank);
412 button (BtnMaster).set_active (m == NavMaster);
413 button (BtnSection).set_active (m == NavSection);
414 button (BtnMarker).set_active (m == NavMarker);
416 button (BtnPan).set_active (m == NavPan);
422 FP8Controls::set_fader_mode (FaderMode m)
424 if (_fadermode == m) {
425 if (m == ModePlugins || m == ModeSend) {
426 /* "Edit Plugins" while editing Plugin-params, returns back
427 * to plugin selection.
428 * "Sends" button banks through sends.
435 button (BtnTrack).set_active (m == ModeTrack);
436 button (BtnPlugins).set_active (m == ModePlugins);
437 button (BtnSend).set_active (m == ModeSend);
438 button (BtnPan).set_active (m == ModePan);
444 FP8Controls::set_mix_mode (MixMode m)
447 if (m == MixUser || m == MixInputs) {
449 * - MixUser: depends on selection
450 * - MixInputs: depends on rec-arm
456 button (BtnMAudio).set_active (m == MixAudio);
457 button (BtnMVI).set_active (m == MixInstrument);
458 button (BtnMBus).set_active (m == MixBus);
459 button (BtnMVCA).set_active (m == MixVCA);
460 button (BtnMAll).set_active (m == MixAll);
461 button (BtnMInputs).set_active (m == MixInputs);
462 button (BtnMMIDI).set_active (m == MixMIDI);
463 button (BtnMOutputs).set_active (m == MixOutputs);
464 button (BtnMFX).set_active (m == MixFX);
465 button (BtnMUser).set_active (m == MixUser);
472 FP8Controls::toggle_timecode ()
474 _display_timecode = !_display_timecode;
475 button (BtnTimecode).set_active (_display_timecode);