1 /* Faderport 8 Control Surface
2 * This is the button "Controller" of the MVC surface inteface,
3 * see callbacks.cc for the "View".
5 * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
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.
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.
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.
22 #include "ardour/dB.h"
23 #include "ardour/plugin_insert.h"
24 #include "ardour/session.h"
25 #include "ardour/session_configuration.h"
26 #include "ardour/types.h"
28 #include "gtkmm2ext/actions.h"
30 #include "faderport8.h"
34 using namespace ARDOUR;
35 using namespace ArdourSurface;
37 using namespace ArdourSurface::FP8Types;
39 #define BindMethod(ID, CB) \
40 _ctrls.button (FP8Controls::ID).released.connect_same_thread (button_connections, boost::bind (&FaderPort8:: CB, this));
42 #define BindFunction(ID, ACT, CB, ...) \
43 _ctrls.button (FP8Controls::ID). ACT .connect_same_thread (button_connections, boost::bind (&FaderPort8:: CB, this, __VA_ARGS__));
45 #define BindAction(ID, GRP, ITEM) \
46 _ctrls.button (FP8Controls::ID).released.connect_same_thread (button_connections, boost::bind (&FaderPort8::button_action, this, GRP, ITEM));
48 #define BindUserAction(ID) \
49 _ctrls.button (ID).pressed.connect_same_thread (button_connections, boost::bind (&FaderPort8::button_user, this, true, ID)); \
50 _ctrls.button (ID).released.connect_same_thread (button_connections, boost::bind (&FaderPort8::button_user, this, false, ID));
53 /* Bind button signals (press, release) to callback methods
54 * (called once after constructing buttons).
55 * Bound actions are handled the the ctrl-surface thread.
58 FaderPort8::setup_actions ()
60 BindMethod (BtnPlay, button_play);
61 BindMethod (BtnStop, button_stop);
62 BindMethod (BtnLoop, button_loop);
63 BindMethod (BtnRecord, button_record);
64 BindMethod (BtnClick, button_metronom);
65 BindAction (BtnRedo, "Editor", "redo");
67 BindAction (BtnSave, "Common", "Save");
68 BindAction (BtnUndo, "Editor", "undo");
69 BindAction (BtnRedo, "Editor", "redo");
71 #ifdef FP8_MUTESOLO_UNDO
72 BindMethod (BtnSoloClear, button_solo_clear);
74 BindAction (BtnSoloClear, "Main", "cancel-solo");
76 BindMethod (BtnMuteClear, button_mute_clear);
78 BindMethod (FP8Controls::BtnArmAll, button_arm_all);
80 BindFunction (BtnRewind, pressed, button_varispeed, false);
81 BindFunction (BtnFastForward, pressed, button_varispeed, true);
83 BindFunction (BtnPrev, released, button_prev_next, false);
84 BindFunction (BtnNext, released, button_prev_next, true);
86 BindFunction (BtnArm, pressed, button_arm, true);
87 BindFunction (BtnArm, released, button_arm, false);
89 BindFunction (BtnAOff, released, button_automation, ARDOUR::Off);
90 BindFunction (BtnATouch, released, button_automation, ARDOUR::Touch);
91 BindFunction (BtnARead, released, button_automation, ARDOUR::Play);
92 BindFunction (BtnAWrite, released, button_automation, ARDOUR::Write);
94 _ctrls.button (FP8Controls::BtnEncoder).pressed.connect_same_thread (button_connections, boost::bind (&FaderPort8::button_encoder, this));
95 _ctrls.button (FP8Controls::BtnParam).pressed.connect_same_thread (button_connections, boost::bind (&FaderPort8::button_parameter, this));
98 BindMethod (BtnBypass, button_bypass);
99 BindAction (BtnBypassAll, "Mixer", "ab-plugins");
101 BindAction (BtnMacro, "Common", "toggle-editor-and-mixer");
102 BindMethod (BtnOpen, button_open);
104 BindMethod (BtnLink, button_link);
105 BindMethod (BtnLock, button_lock);
108 for (FP8Controls::UserButtonMap::const_iterator i = _ctrls.user_buttons ().begin ();
109 i != _ctrls.user_buttons ().end (); ++i) {
110 BindUserAction ((*i).first);
114 /* ****************************************************************************
115 * Direct control callback Actions
119 FaderPort8::button_play ()
121 if (session->transport_rolling ()) {
122 if (session->transport_speed () != 1.0) {
123 session->request_transport_speed (1.0);
133 FaderPort8::button_stop ()
135 if (session->transport_rolling ()) {
138 AccessAction ("Transport", "GotoStart");
143 FaderPort8::button_record ()
145 set_record_enable (!get_record_enabled ());
149 FaderPort8::button_loop ()
155 FaderPort8::button_metronom ()
157 Config->set_clicking (!Config->get_clicking ());
161 FaderPort8::button_bypass ()
163 boost::shared_ptr<PluginInsert> pi = _plugin_insert.lock();
165 pi->enable (! pi->enabled ());
167 AccessAction ("Mixer", "ab-plugins");
172 FaderPort8::button_open ()
174 boost::shared_ptr<PluginInsert> pi = _plugin_insert.lock();
176 pi->ToggleUI (); /* EMIT SIGNAL */
178 AccessAction ("Common", "addExistingAudioFiles");
182 FaderPort8::button_lock ()
184 if (!_link_enabled) {
185 AccessAction ("Editor", "lock");
190 } else if (!_link_control.expired ()) {
196 FaderPort8::button_link ()
198 switch (_ctrls.fader_mode()) {
208 //AccessAction ("Window", "show-mixer");
214 FaderPort8::button_automation (ARDOUR::AutoState as)
216 FaderMode fadermode = _ctrls.fader_mode ();
219 #if 0 // Plugin Control Automation Mode
220 for ( std::list <ProcessorCtrl>::iterator i = _proc_params.begin(); i != _proc_params.end(); ++i) {
221 ((*i).ac)->set_automation_state (as);
226 if (first_selected_stripable()) {
227 #if 0 // Send Level Automation
228 boost::shared_ptr<Stripable> s = first_selected_stripable();
229 boost::shared_ptr<AutomationControl> send;
231 while (0 != (send = s->send_level_controllable (i))) {
232 send->set_automation_state (as);
242 // TODO link/lock control automation?
244 // apply to all selected tracks
246 session->get_stripables (all);
247 for (StripableList::const_iterator i = all.begin(); i != all.end(); ++i) {
248 if ((*i)->is_master() || (*i)->is_monitor()) {
251 if (!(*i)->is_selected()) {
254 boost::shared_ptr<AutomationControl> ac;
257 ac = (*i)->gain_control ();
260 ac = (*i)->pan_azimuth_control ();
266 ac->set_automation_state (as);
272 FaderPort8::button_varispeed (bool ffw)
274 /* pressing both rew + ffwd -> return to zero */
275 FP8ButtonInterface& b_rew = _ctrls.button (FP8Controls::BtnRewind);
276 FP8ButtonInterface& b_ffw = _ctrls.button (FP8Controls::BtnFastForward);
277 if (b_rew.is_pressed () && b_ffw.is_pressed ()){
279 dynamic_cast<FP8RepeatButton*>(&b_ffw)->stop_repeat();
280 dynamic_cast<FP8RepeatButton*>(&b_rew)->stop_repeat();
281 session->request_locate (0, false);
285 // switch play direction, if needed
287 if (session->transport_speed () <= 0) {
288 session->request_transport_speed (1.0);
292 if (session->transport_speed () >= 0) {
293 session->request_transport_speed (-1.0);
297 // incremetally increase speed. double speed every 10 clicks
298 // (keypress auto-repeat is 100ms)
299 float maxspeed = Config->get_shuttle_max_speed();
300 float speed = exp2f(0.1f) * session->transport_speed ();
301 speed = std::max (-maxspeed, std::min (maxspeed, speed));
302 session->request_transport_speed (speed, false);
305 #ifdef FP8_MUTESOLO_UNDO
307 FaderPort8::button_solo_clear ()
309 bool soloing = session->soloing() || session->listening();
311 soloing |= session->mixbus_soloed();
315 session->get_stripables (all);
316 for (StripableList::const_iterator i = all.begin(); i != all.end(); ++i) {
317 if ((*i)->is_master() || (*i)->is_auditioner() || (*i)->is_monitor()) {
320 boost::shared_ptr<SoloControl> sc = (*i)->solo_control();
321 if (sc && sc->self_soloed ()) {
322 _solo_state.push_back (boost::weak_ptr<AutomationControl>(sc));
325 cancel_all_solo (); // AccessAction ("Main", "cancel-solo");
328 boost::shared_ptr<ControlList> cl (new ControlList);
329 for (std::vector <boost::weak_ptr<AutomationControl> >::const_iterator i = _solo_state.begin(); i != _solo_state.end(); ++i) {
330 boost::shared_ptr<AutomationControl> ac = (*i).lock();
334 ac->start_touch (ac->session().transport_frame());
338 session->set_controls (cl, 1.0, PBD::Controllable::NoGroup);
345 FaderPort8::button_mute_clear ()
347 #ifdef FP8_MUTESOLO_UNDO
348 if (session->muted ()) {
349 _mute_state = session->cancel_all_mute ();
352 boost::shared_ptr<ControlList> cl (new ControlList);
353 for (std::vector <boost::weak_ptr<AutomationControl> >::const_iterator i = _mute_state.begin(); i != _mute_state.end(); ++i) {
354 boost::shared_ptr<AutomationControl> ac = (*i).lock();
359 ac->start_touch (ac->session().transport_frame());
362 session->set_controls (cl, 1.0, PBD::Controllable::NoGroup);
366 session->cancel_all_mute ();
371 FaderPort8::button_arm_all ()
373 BasicUI::all_tracks_rec_in ();
376 /* access generic action */
378 FaderPort8::button_action (const std::string& group, const std::string& item)
380 AccessAction (group, item);
383 /* ****************************************************************************
384 * Control Interaction (encoder)
388 FaderPort8::handle_encoder_pan (int steps)
390 boost::shared_ptr<Stripable> s = first_selected_stripable();
392 boost::shared_ptr<AutomationControl> ac;
393 if (shift_mod () || _ctrls.fader_mode() == ModePan) {
394 ac = s->pan_width_control ();
396 ac = s->pan_azimuth_control ();
399 ac->start_touch (ac->session().transport_frame());
401 ac->set_value (ac->normal(), PBD::Controllable::UseGroup);
403 double v = ac->internal_to_interface (ac->get_value());
404 v = std::max (0.0, std::min (1.0, v + steps * .01));
405 ac->set_value (ac->interface_to_internal(v), PBD::Controllable::UseGroup);
412 FaderPort8::handle_encoder_link (int steps)
414 if (_link_control.expired ()) {
417 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl> (_link_control.lock ());
422 double v = ac->internal_to_interface (ac->get_value());
423 ac->start_touch (ac->session().transport_frame());
426 ac->set_value (ac->normal(), PBD::Controllable::UseGroup);
430 if (ac->desc().toggled) {
432 } else if (ac->desc().integer_step) {
433 v += steps / (1.f + ac->desc().upper - ac->desc().lower);
434 } else if (ac->desc().enumeration) {
435 ac->set_value (ac->desc().step_enum (ac->get_value(), steps < 0), PBD::Controllable::UseGroup);
438 v = std::max (0.0, std::min (1.0, v + steps * .01));
440 ac->set_value (ac->interface_to_internal(v), PBD::Controllable::UseGroup);
444 /* ****************************************************************************
445 * Mode specific and internal callbacks
448 /* handle "ARM" press -- act like shift, change "Select" button mode */
450 FaderPort8::button_arm (bool press)
452 FaderMode fadermode = _ctrls.fader_mode ();
453 if (fadermode == ModeTrack || fadermode == ModePan) {
454 _ctrls.button (FP8Controls::BtnArm).set_active (press);
455 ARMButtonChange (press); /* EMIT SIGNAL */
460 FaderPort8::button_prev_next (bool next)
462 switch (_ctrls.nav_mode()) {
464 select_prev_next (next);
475 VerticalZoomInSelected ();
477 VerticalZoomOutSelected ();
482 AccessAction ("Region", "nudge-forward");
484 AccessAction ("Region", "nudge-backward");
497 /* handle navigation encoder press */
499 FaderPort8::button_encoder ()
501 /* special-case metronome level */
502 if (_ctrls.button (FP8Controls::BtnClick).is_pressed ()) {
503 Config->set_click_gain (1.0);
504 _ctrls.button (FP8Controls::BtnClick).ignore_release();
507 switch (_ctrls.nav_mode()) {
509 ZoomToSession (); // XXX undo zoom
515 AccessAction ("Editor", "select-topmost");
518 move_selected_into_view ();
522 /* master || monitor level -- reset to 0dB */
523 boost::shared_ptr<AutomationControl> ac;
524 if (session->monitor_active() && !_ctrls.button (FP8Controls::BtnMaster).is_pressed ()) {
525 ac = session->monitor_out()->gain_control ();
526 } else if (session->master_out()) {
527 ac = session->master_out()->gain_control ();
530 ac->start_touch (ac->session().transport_frame());
531 ac->set_value (ac->normal(), PBD::Controllable::NoGroup);
541 /* Don't add another mark if one exists within 1/100th of a second of
542 * the current position and we're not rolling.
544 framepos_t where = session->audible_frame();
545 if (session->transport_stopped() && session->locations()->mark_at (where, session->frame_rate() / 100.0)) {
549 session->locations()->next_available_name (markername,"mark");
550 add_marker (markername);
556 /* handle navigation encoder turn */
558 FaderPort8::encoder_navigate (bool neg, int steps)
560 /* special-case metronome level */
561 if (_ctrls.button (FP8Controls::BtnClick).is_pressed ()) {
562 // compare to ARDOUR_UI::click_button_scroll()
563 gain_t gain = Config->get_click_gain();
564 float gain_db = accurate_coefficient_to_dB (gain);
565 gain_db += (neg ? -1.f : 1.f) * steps;
566 gain_db = std::max (-60.f, gain_db);
567 gain = dB_to_coefficient (gain_db);
568 gain = std::min (gain, Config->get_max_gain());
569 Config->set_click_gain (gain);
570 _ctrls.button (FP8Controls::BtnClick).ignore_release();
574 switch (_ctrls.nav_mode()) {
577 AccessAction ("Mixer", "scroll-left");
578 AccessAction ("Editor", "step-tracks-up");
580 AccessAction ("Mixer", "scroll-right");
581 AccessAction ("Editor", "step-tracks-down");
593 ScrollTimeline ((neg ? -1.f : 1.f) * steps / (shift_mod() ? 1024.f : 256.f));
600 /* master || monitor level */
601 boost::shared_ptr<AutomationControl> ac;
602 if (session->monitor_active() && !_ctrls.button (FP8Controls::BtnMaster).is_pressed ()) {
603 ac = session->monitor_out()->gain_control ();
604 } else if (session->master_out()) {
605 ac = session->master_out()->gain_control ();
608 double v = ac->internal_to_interface (ac->get_value());
609 v = std::max (0.0, std::min (1.0, v + steps * (neg ? -.01 : .01)));
610 ac->start_touch (ac->session().transport_frame());
611 ac->set_value (ac->interface_to_internal(v), PBD::Controllable::NoGroup);
617 AccessAction ("Common", "nudge-playhead-backward");
619 AccessAction ("Common", "nudge-playhead-forward");
625 /* handle pan/param encoder press */
627 FaderPort8::button_parameter ()
629 switch (_ctrls.fader_mode()) {
632 if (_link_enabled || _link_locked) {
633 handle_encoder_link (0);
635 handle_encoder_pan (0);
639 toggle_preset_param_mode ();
646 /* handle pan/param encoder turn */
648 FaderPort8::encoder_parameter (bool neg, int steps)
650 switch (_ctrls.fader_mode()) {
654 if (_link_enabled || _link_locked) {
655 handle_encoder_link (neg ? -steps : steps);
657 handle_encoder_pan (neg ? -steps : steps);
664 bank_param (neg, shift_mod());
671 /* handle user-specific actions */
673 FaderPort8::button_user (bool press, FP8Controls::ButtonId btn)
675 _user_action_map[btn].call (*this, press);