1 /*
2  * Copyright (C) 2006-2007 John Anderson
3  * Copyright (C) 2012-2018 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2015-2016 Len Ovens <len@ovenwerks.net>
5  * Copyright (C) 2015-2017 Robin Gareus <robin@gareus.org>
6  * Copyright (C) 2016-2019 Ben Loftis <ben@harrisonconsoles.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #include <algorithm>
24 
25 #include "pbd/memento_command.h"
26 
27 #include "ardour/debug.h"
28 #include "ardour/profile.h"
29 #include "ardour/session.h"
30 #include "ardour/route.h"
31 #include "ardour/location.h"
32 #include "ardour/rc_configuration.h"
33 
34 #include "mackie_control_protocol.h"
35 #include "subview.h"
36 #include "surface.h"
37 #include "fader.h"
38 
39 #include "pbd/i18n.h"
40 
41 /* handlers for all buttons, broken into a separate file to avoid clutter in
42  * mackie_control_protocol.cc
43  */
44 
45 using std::string;
46 using namespace ARDOUR;
47 using namespace PBD;
48 using namespace ArdourSurface;
49 using namespace Mackie;
50 
51 LedState
shift_press(Button &)52 MackieControlProtocol::shift_press (Button &)
53 {
54 	_modifier_state |= MODIFIER_SHIFT;
55 	return on;
56 }
57 LedState
shift_release(Button &)58 MackieControlProtocol::shift_release (Button &)
59 {
60 	_modifier_state &= ~MODIFIER_SHIFT;
61 	return off;
62 }
63 LedState
option_press(Button &)64 MackieControlProtocol::option_press (Button &)
65 {
66 	_modifier_state |= MODIFIER_OPTION;
67 	return on;
68 }
69 LedState
option_release(Button &)70 MackieControlProtocol::option_release (Button &)
71 {
72 	_modifier_state &= ~MODIFIER_OPTION;
73 	return off;
74 }
75 LedState
control_press(Button &)76 MackieControlProtocol::control_press (Button &)
77 {
78 	_modifier_state |= MODIFIER_CONTROL;
79 	DEBUG_TRACE (DEBUG::MackieControl, string_compose ("CONTROL Press: modifier state now set to %1\n", _modifier_state));
80 	return on;
81 }
82 LedState
control_release(Button &)83 MackieControlProtocol::control_release (Button &)
84 {
85 	_modifier_state &= ~MODIFIER_CONTROL;
86 	DEBUG_TRACE (DEBUG::MackieControl, string_compose ("CONTROL Release: modifier state now set to %1\n", _modifier_state));
87 	return off;
88 }
89 LedState
cmd_alt_press(Button &)90 MackieControlProtocol::cmd_alt_press (Button &)
91 {
92 	_modifier_state |= MODIFIER_CMDALT;
93 	return on;
94 }
95 LedState
cmd_alt_release(Button &)96 MackieControlProtocol::cmd_alt_release (Button &)
97 {
98 	_modifier_state &= ~MODIFIER_CMDALT;
99 	return off;
100 }
101 
102 LedState
left_press(Button &)103 MackieControlProtocol::left_press (Button &)
104 {
105 	if (_subview->subview_mode() != Mackie::Subview::None) {
106 		return none;
107 	}
108 
109 	Sorted sorted = get_sorted_stripables();
110 	uint32_t strip_cnt = n_strips ();
111 
112 	DEBUG_TRACE (DEBUG::MackieControl, string_compose ("bank left with current initial = %1 nstrips = %2 tracks/busses = %3\n",
113 							   _current_initial_bank, strip_cnt, sorted.size()));
114 	if (_current_initial_bank > 0) {
115 		(void) switch_banks ((_current_initial_bank - 1) / strip_cnt * strip_cnt);
116 	} else {
117 		(void) switch_banks (0);
118 	}
119 
120 
121 	return on;
122 }
123 
124 LedState
left_release(Button &)125 MackieControlProtocol::left_release (Button &)
126 {
127 	return off;
128 }
129 
130 LedState
right_press(Button &)131 MackieControlProtocol::right_press (Button &)
132 {
133 	if (_subview->subview_mode() != Mackie::Subview::None) {
134 		return none;
135 	}
136 
137 	Sorted sorted = get_sorted_stripables();
138 	uint32_t strip_cnt = n_strips();
139 	uint32_t route_cnt = sorted.size();
140 	uint32_t max_bank = route_cnt / strip_cnt * strip_cnt;
141 
142 
143 	DEBUG_TRACE (DEBUG::MackieControl, string_compose ("bank right with current initial = %1 nstrips = %2 tracks/busses = %3\n",
144 							   _current_initial_bank, strip_cnt, route_cnt));
145 
146 	if (_current_initial_bank < max_bank) {
147 		uint32_t new_initial = (_current_initial_bank / strip_cnt * strip_cnt) + strip_cnt;
148 		(void) switch_banks (new_initial);
149 	}
150 
151 	return on;
152 }
153 
154 LedState
right_release(Button &)155 MackieControlProtocol::right_release (Button &)
156 {
157 	return off;
158 }
159 
160 LedState
cursor_left_press(Button &)161 MackieControlProtocol::cursor_left_press (Button& )
162 {
163 	bool press_handled_by_subview = _subview->handle_cursor_left_press();
164 	if (press_handled_by_subview)
165 	{
166 		return off;
167 	}
168 
169 	if (zoom_mode()) {
170 
171 		if (main_modifier_state() & MODIFIER_OPTION) {
172 			/* reset selected tracks to default vertical zoom */
173 		} else {
174 			ZoomOut (); /* EMIT SIGNAL */
175 		}
176 	} else {
177 		float page_fraction;
178 		if (main_modifier_state() == MODIFIER_CONTROL) {
179 			page_fraction = 1.0;
180 		} else if (main_modifier_state() == MODIFIER_OPTION) {
181 			page_fraction = 0.1;
182 		} else if (main_modifier_state() == MODIFIER_SHIFT) {
183 			page_fraction = 2.0;
184 		} else {
185 			page_fraction = 0.25;
186 		}
187 
188 		ScrollTimeline (-page_fraction);
189 	}
190 
191 	return off;
192 }
193 
194 LedState
cursor_left_release(Button &)195 MackieControlProtocol::cursor_left_release (Button&)
196 {
197 	return off;
198 }
199 
200 LedState
cursor_right_press(Button &)201 MackieControlProtocol::cursor_right_press (Button& )
202 {
203 	bool press_handled_by_subview = _subview->handle_cursor_right_press();
204 	if (press_handled_by_subview)
205 	{
206 		return off;
207 	}
208 
209 	if (zoom_mode()) {
210 
211 		if (main_modifier_state() & MODIFIER_OPTION) {
212 			/* reset selected tracks to default vertical zoom */
213 		} else {
214 			ZoomIn (); /* EMIT SIGNAL */
215 		}
216 	} else {
217 		float page_fraction;
218 		if (main_modifier_state() == MODIFIER_CONTROL) {
219 			page_fraction = 1.0;
220 		} else if (main_modifier_state() == MODIFIER_OPTION) {
221 			page_fraction = 0.1;
222 		} else if (main_modifier_state() == MODIFIER_SHIFT) {
223 			page_fraction = 2.0;
224 		} else {
225 			page_fraction = 0.25;
226 		}
227 
228 		ScrollTimeline (page_fraction);
229 	}
230 
231 	return off;
232 }
233 
234 LedState
cursor_right_release(Button &)235 MackieControlProtocol::cursor_right_release (Button&)
236 {
237 	return off;
238 }
239 
240 LedState
cursor_up_press(Button &)241 MackieControlProtocol::cursor_up_press (Button&)
242 {
243 	if (zoom_mode()) {
244 
245 		if (main_modifier_state() & MODIFIER_CONTROL) {
246 			VerticalZoomInSelected (); /* EMIT SIGNAL */
247 		} else {
248 			VerticalZoomInAll (); /* EMIT SIGNAL */
249 		}
250 	} else {
251 		access_action ("Editor/select-prev-route");
252 	}
253 	return off;
254 }
255 
256 LedState
cursor_up_release(Button &)257 MackieControlProtocol::cursor_up_release (Button&)
258 {
259 	return off;
260 }
261 
262 LedState
cursor_down_press(Button &)263 MackieControlProtocol::cursor_down_press (Button&)
264 {
265 	if (zoom_mode()) {
266 		if (main_modifier_state() & MODIFIER_OPTION) {
267 			VerticalZoomOutSelected (); /* EMIT SIGNAL */
268 		} else {
269 			VerticalZoomOutAll (); /* EMIT SIGNAL */
270 		}
271 	} else {
272 		access_action ("Editor/select-next-route");
273 	}
274 	return off;
275 }
276 
277 LedState
cursor_down_release(Button &)278 MackieControlProtocol::cursor_down_release (Button&)
279 {
280 	return off;
281 }
282 
283 LedState
channel_left_press(Button &)284 MackieControlProtocol::channel_left_press (Button &)
285 {
286 	if (_device_info.single_fader_follows_selection()) {
287 		access_action ("Editor/select-prev-route");
288 		return on;
289 	}
290 
291 	if (_subview->subview_mode() != Mackie::Subview::None) {
292 		return none;
293 	}
294 	Sorted sorted = get_sorted_stripables();
295 	if (sorted.size() > n_strips()) {
296 		prev_track();
297 		return on;
298 	} else {
299 		return flashing;
300 	}
301 }
302 
303 LedState
channel_left_release(Button &)304 MackieControlProtocol::channel_left_release (Button &)
305 {
306 	return off;
307 }
308 
309 LedState
channel_right_press(Button &)310 MackieControlProtocol::channel_right_press (Button &)
311 {
312 	if (_device_info.single_fader_follows_selection()) {
313 		access_action ("Editor/select-next-route");
314 		return on;
315 	}
316 
317 	if (_subview->subview_mode() != Mackie::Subview::None) {
318 		return none;
319 	}
320 	Sorted sorted = get_sorted_stripables();
321 	if (sorted.size() > n_strips()) {
322 		next_track();
323 		return on;
324 	} else {
325 		return flashing;
326 	}
327 }
328 
329 LedState
channel_right_release(Button &)330 MackieControlProtocol::channel_right_release (Button &)
331 {
332 	return off;
333 }
334 
335 Mackie::LedState
zoom_press(Mackie::Button &)336 MackieControlProtocol::zoom_press (Mackie::Button &)
337 {
338 	return none;
339 }
340 
341 Mackie::LedState
zoom_release(Mackie::Button &)342 MackieControlProtocol::zoom_release (Mackie::Button &)
343 {
344 	if (_modifier_state & MODIFIER_ZOOM) {
345 		_modifier_state &= ~MODIFIER_ZOOM;
346 	} else {
347 		_modifier_state |= MODIFIER_ZOOM;
348 	}
349 
350 	return (zoom_mode() ? on : off);
351 }
352 
353 Mackie::LedState
scrub_press(Mackie::Button &)354 MackieControlProtocol::scrub_press (Mackie::Button &)
355 {
356 	if (_master_surface) {
357 		_master_surface->next_jog_mode ();
358 	}
359 
360 	return none;
361 }
362 
363 Mackie::LedState
scrub_release(Mackie::Button &)364 MackieControlProtocol::scrub_release (Mackie::Button &)
365 {
366 	return none;
367 }
368 
369 LedState
undo_press(Button &)370 MackieControlProtocol::undo_press (Button&)
371 {
372 	if (main_modifier_state() == MODIFIER_SHIFT) {
373 		redo();
374 	} else {
375 		undo ();
376 	}
377 	return none;
378 }
379 
380 LedState
undo_release(Button &)381 MackieControlProtocol::undo_release (Button&)
382 {
383 	return none;
384 }
385 
386 LedState
drop_press(Button &)387 MackieControlProtocol::drop_press (Button &)
388 {
389 	if (main_modifier_state() == MODIFIER_SHIFT) {
390 		toggle_punch_in();
391 		return none;
392 	} else {
393 		access_action ("Common/start-range-from-playhead");
394 	}
395 	return none;
396 }
397 
398 LedState
drop_release(Button &)399 MackieControlProtocol::drop_release (Button &)
400 {
401 	return none;
402 }
403 
404 LedState
save_press(Button &)405 MackieControlProtocol::save_press (Button &)
406 {
407 	if (main_modifier_state() == MODIFIER_SHIFT) {
408 		quick_snapshot_switch();
409 	} else {
410 		save_state ();
411 	}
412 
413 	return none;
414 }
415 
416 LedState
save_release(Button &)417 MackieControlProtocol::save_release (Button &)
418 {
419 	return none;
420 }
421 
422 LedState
timecode_beats_press(Button &)423 MackieControlProtocol::timecode_beats_press (Button &)
424 {
425 	switch (_timecode_type) {
426 	case ARDOUR::AnyTime::BBT:
427 		_timecode_type = ARDOUR::AnyTime::Timecode;
428 		break;
429 	case ARDOUR::AnyTime::Timecode:
430 		_timecode_type = ARDOUR::AnyTime::BBT;
431 		break;
432 	default:
433 		return off;
434 	}
435 
436 	update_timecode_beats_led();
437 
438 	return on;
439 }
440 
441 LedState
timecode_beats_release(Button &)442 MackieControlProtocol::timecode_beats_release (Button &)
443 {
444 	return off;
445 }
446 
447 /////////////////////////////////////
448 // Functions
449 /////////////////////////////////////
450 LedState
marker_press(Button &)451 MackieControlProtocol::marker_press (Button &)
452 {
453 	if (main_modifier_state() & MODIFIER_SHIFT) {
454 		access_action ("Common/remove-location-from-playhead");
455 		return off;
456 	} else {
457 		_modifier_state |= MODIFIER_MARKER;
458 		marker_modifier_consumed_by_button = false;
459 		return on;
460 	}
461 }
462 
463 LedState
marker_release(Button &)464 MackieControlProtocol::marker_release (Button &)
465 {
466 	_modifier_state &= ~MODIFIER_MARKER;
467 
468 	if (main_modifier_state() & MODIFIER_SHIFT) {
469 		return off;   //if shift was held, we already did the action
470 	}
471 
472 	if (marker_modifier_consumed_by_button) {
473 		DEBUG_TRACE (DEBUG::MackieControl, "marked modifier consumed by button, ignored\n");
474 		/* marker was used a modifier for some other button(s), so do
475 		   nothing
476 		*/
477 		return off;
478 	}
479 
480 	string markername;
481 
482 	/* Don't add another mark if one exists within 1/100th of a second of
483 	 * the current position and we're not rolling.
484 	 */
485 
486 	samplepos_t where = session->audible_sample();
487 
488 	if (session->transport_stopped_or_stopping() && session->locations()->mark_at (where, session->sample_rate() / 100.0)) {
489 		return off;
490 	}
491 
492 	session->locations()->next_available_name (markername,"mark");
493 	add_marker (markername);
494 
495 	return off;
496 }
497 
498 /////////////////////////////////////
499 // Transport Buttons
500 /////////////////////////////////////
501 
502 LedState
stop_press(Button &)503 MackieControlProtocol::stop_press (Button &)
504 {
505 	transport_stop ();
506 
507 	if (main_modifier_state() == MODIFIER_SHIFT) {
508 		session->midi_panic();
509 	}
510 
511 	return on;
512 }
513 
514 LedState
stop_release(Button &)515 MackieControlProtocol::stop_release (Button &)
516 {
517 	return session->transport_stopped_or_stopping();
518 }
519 
520 LedState
play_press(Button &)521 MackieControlProtocol::play_press (Button &)
522 {
523 	/* if we're already rolling at normal speed, and we're pressed
524 	   again, jump back to where we started last time
525 	*/
526 
527 	transport_play (get_transport_speed() == 1.0);
528 	return none;
529 }
530 
531 LedState
play_release(Button &)532 MackieControlProtocol::play_release (Button &)
533 {
534 	return none;
535 }
536 
537 LedState
record_press(Button &)538 MackieControlProtocol::record_press (Button &)
539 {
540 	rec_enable_toggle ();
541 	return none;
542 }
543 
544 LedState
record_release(Button &)545 MackieControlProtocol::record_release (Button &)
546 {
547 	return none;
548 }
549 
550 LedState
rewind_press(Button &)551 MackieControlProtocol::rewind_press (Button &)
552 {
553 	if (modifier_state() & MODIFIER_MARKER) {
554 		prev_marker ();
555 	} else if (modifier_state() & MODIFIER_NUDGE) {
556 		access_action ("Common/nudge-playhead-backward");
557 	} else if (main_modifier_state() & MODIFIER_SHIFT) {
558 		goto_start ();
559 	} else {
560 		rewind ();
561 	}
562 	return none;
563 }
564 
565 LedState
rewind_release(Button &)566 MackieControlProtocol::rewind_release (Button &)
567 {
568 	return none;
569 }
570 
571 LedState
ffwd_press(Button &)572 MackieControlProtocol::ffwd_press (Button &)
573 {
574 	if (modifier_state() & MODIFIER_MARKER) {
575 		next_marker ();
576 	} else if (modifier_state() & MODIFIER_NUDGE) {
577 		access_action ("Common/nudge-playhead-forward");
578 	} else if (main_modifier_state() & MODIFIER_SHIFT) {
579 		goto_end();
580 	} else {
581 		ffwd ();
582 	}
583 	return none;
584 }
585 
586 LedState
ffwd_release(Button &)587 MackieControlProtocol::ffwd_release (Button &)
588 {
589 	return none;
590 }
591 
592 LedState
loop_press(Button &)593 MackieControlProtocol::loop_press (Button &)
594 {
595 	if (main_modifier_state() & MODIFIER_SHIFT) {
596 		access_action ("Editor/set-loop-from-edit-range");
597 		return off;
598 	} else {
599 		bool was_on = session->get_play_loop();
600 		loop_toggle ();
601 		return was_on ? off : on;
602 	}
603 }
604 
605 LedState
loop_release(Button &)606 MackieControlProtocol::loop_release (Button &)
607 {
608 	return none;
609 }
610 
611 LedState
enter_press(Button &)612 MackieControlProtocol::enter_press (Button &)
613 {
614 	if (main_modifier_state() & MODIFIER_SHIFT) {
615 		access_action ("Transport/ToggleFollowEdits");
616 	} else {
617 		access_action ("Common/select-all-tracks");
618 	}
619 	return none;
620 }
621 
622 LedState
enter_release(Button &)623 MackieControlProtocol::enter_release (Button &)
624 {
625 	return none;
626 }
627 
628 LedState
bank_release(Button & b,uint32_t basic_bank_num)629 MackieControlProtocol::bank_release (Button& b, uint32_t basic_bank_num)
630 {
631 	if (_subview->subview_mode() != Mackie::Subview::None) {
632 		return none;
633 	}
634 
635 	uint32_t bank_num = basic_bank_num;
636 
637 	if (b.long_press_count() > 0) {
638 		bank_num = 8 + basic_bank_num;
639 	}
640 
641 	(void) switch_banks (n_strips() * bank_num);
642 
643 	return on;
644 }
645 
646 /*  F-KEYS are only used for actions that are bound from the control panel; no need to address them here
647 LedState
648 MackieControlProtocol::F1_press (Button &b)
649 {
650 	return on;
651 }
652 LedState
653 MackieControlProtocol::F1_release (Button &b)
654 {
655 	return off;
656 }
657 LedState
658 MackieControlProtocol::F2_press (Button &)
659 {
660 	return on;
661 }
662 LedState
663 MackieControlProtocol::F2_release (Button &b)
664 {
665 	return off;
666 }
667 LedState
668 MackieControlProtocol::F3_press (Button &)
669 {
670 	return on;
671 }
672 LedState
673 MackieControlProtocol::F3_release (Button &b)
674 {
675 	return off;
676 }
677 LedState
678 MackieControlProtocol::F4_press (Button &)
679 {
680 	return on;
681 }
682 LedState
683 MackieControlProtocol::F4_release (Button &b)
684 {
685 	return off;
686 }
687 LedState
688 MackieControlProtocol::F5_press (Button &)
689 {
690 	return on;
691 }
692 LedState
693 MackieControlProtocol::F5_release (Button &)
694 {
695 	return off;
696 }
697 LedState
698 MackieControlProtocol::F6_press (Button &)
699 {
700 	return on;
701 }
702 LedState
703 MackieControlProtocol::F6_release (Button &)
704 {
705 	return off;
706 }
707 LedState
708 MackieControlProtocol::F7_press (Button &)
709 {
710 	return on;
711 }
712 LedState
713 MackieControlProtocol::F7_release (Button &)
714 {
715 	return off;
716 }
717 LedState
718 MackieControlProtocol::F8_press (Button &)
719 {
720 	return on;
721 }
722 LedState
723 MackieControlProtocol::F8_release (Button &)
724 {
725 	return off;
726 }
727 */
728 
729 
730 /* UNIMPLEMENTED */
731 
732 LedState
pan_press(Button &)733 MackieControlProtocol::pan_press (Button &)
734 {
735 	/* XXX eventually pan may have its own subview mode */
736 	set_subview_mode (Mackie::Subview::None, boost::shared_ptr<Stripable>());
737 	return none;
738 }
739 LedState
pan_release(Button &)740 MackieControlProtocol::pan_release (Button &)
741 {
742 	return none;
743 }
744 LedState
plugin_press(Button &)745 MackieControlProtocol::plugin_press (Button &)
746 {
747 	set_subview_mode (Subview::Plugin, first_selected_stripable());
748 	return none;
749 }
750 LedState
plugin_release(Button &)751 MackieControlProtocol::plugin_release (Button &)
752 {
753 	// Do not do this yet, since it does nothing
754 	// set_view_mode (Plugins);
755 	return none; /* LED state set by set_view_mode */
756 }
757 LedState
eq_press(Button &)758 MackieControlProtocol::eq_press (Button &)
759 {
760 	set_subview_mode (Subview::EQ, first_selected_stripable ());
761 	return none; /* led state handled by set_subview_mode() */
762 
763 }
764 LedState
eq_release(Button &)765 MackieControlProtocol::eq_release (Button &)
766 {
767 	return none;
768 }
769 LedState
dyn_press(Button &)770 MackieControlProtocol::dyn_press (Button &)
771 {
772 	set_subview_mode (Subview::Dynamics, first_selected_stripable ());
773 	return none; /* led state handled by set_subview_mode() */
774 }
775 
776 LedState
dyn_release(Button &)777 MackieControlProtocol::dyn_release (Button &)
778 {
779 	return none;
780 }
781 LedState
flip_press(Button &)782 MackieControlProtocol::flip_press (Button &)
783 {
784 	if (_subview->permit_flipping_faders_and_pots()) {
785 		if (_flip_mode != Normal) {
786 			set_flip_mode (Normal);
787 		} else {
788 			set_flip_mode (Mirror);
789 		}
790 		return ((_flip_mode != Normal) ? on : off);
791 	}
792 
793 	return none;
794 }
795 
796 LedState
flip_release(Button &)797 MackieControlProtocol::flip_release (Button &)
798 {
799 	return none;
800 }
801 LedState
name_value_press(Button &)802 MackieControlProtocol::name_value_press (Button &)
803 {
804 	return off;
805 }
806 LedState
name_value_release(Button &)807 MackieControlProtocol::name_value_release (Button &)
808 {
809 	return off;
810 }
811 LedState
touch_press(Button &)812 MackieControlProtocol::touch_press (Button &)
813 {
814 	return none;
815 }
816 LedState
touch_release(Button &)817 MackieControlProtocol::touch_release (Button &)
818 {
819 	set_automation_state (ARDOUR::Touch);
820 	return none;
821 }
822 LedState
cancel_press(Button &)823 MackieControlProtocol::cancel_press (Button &)
824 {
825 	if (main_modifier_state() & MODIFIER_SHIFT) {
826 		access_action ("Transport/ToggleExternalSync");
827 	} else {
828 		access_action ("Main/Escape");
829 	}
830 	return none;
831 }
832 LedState
cancel_release(Button &)833 MackieControlProtocol::cancel_release (Button &)
834 {
835 	return none;
836 }
837 LedState
user_a_press(Button &)838 MackieControlProtocol::user_a_press (Button &)
839 {
840 	transport_play (get_transport_speed() == 1.0);
841 	return off;
842 }
843 LedState
user_a_release(Button &)844 MackieControlProtocol::user_a_release (Button &)
845 {
846 	return off;
847 }
848 LedState
user_b_press(Button &)849 MackieControlProtocol::user_b_press (Button &)
850 {
851 	transport_stop();
852 	return off;
853 }
854 LedState
user_b_release(Button &)855 MackieControlProtocol::user_b_release (Button &)
856 {
857 	return off;
858 }
859 
860 LedState
master_fader_touch_press(Mackie::Button &)861 MackieControlProtocol::master_fader_touch_press (Mackie::Button &)
862 {
863 	if (_master_surface && _master_surface->master_fader() != 0) {
864 		DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::master_fader_touch_press\n");
865 
866 		Fader* master_fader = _master_surface->master_fader();
867 
868 		boost::shared_ptr<AutomationControl> ac = master_fader->control ();
869 
870 		master_fader->set_in_use (true);
871 		master_fader->start_touch (transport_sample());
872 	}
873 	return none;
874 }
875 LedState
master_fader_touch_release(Mackie::Button &)876 MackieControlProtocol::master_fader_touch_release (Mackie::Button &)
877 {
878 	if (_master_surface && _master_surface->master_fader() != 0) {
879 		DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::master_fader_touch_release\n");
880 
881 		Fader* master_fader = _master_surface->master_fader();
882 
883 		master_fader->set_in_use (false);
884 		master_fader->stop_touch (transport_sample());
885 	}
886 	return none;
887 }
888 
889 Mackie::LedState
read_press(Mackie::Button &)890 MackieControlProtocol::read_press (Mackie::Button&)
891 {
892 	return none;
893 }
894 
895 Mackie::LedState
read_release(Mackie::Button &)896 MackieControlProtocol::read_release (Mackie::Button&)
897 {
898 	set_automation_state (ARDOUR::Play);
899 	return none;
900 }
901 Mackie::LedState
write_press(Mackie::Button &)902 MackieControlProtocol::write_press (Mackie::Button&)
903 {
904 	return none;
905 }
906 Mackie::LedState
write_release(Mackie::Button &)907 MackieControlProtocol::write_release (Mackie::Button&)
908 {
909 	set_automation_state (ARDOUR::Write);
910 	return none;
911 }
912 
913 Mackie::LedState
clearsolo_press(Mackie::Button &)914 MackieControlProtocol::clearsolo_press (Mackie::Button&)
915 {
916 	// clears all solos and listens (pfl/afl)
917 
918 	if (main_modifier_state() & MODIFIER_SHIFT) {
919 		access_action ("Editor/set-session-from-edit-range");
920 		return none;
921 	}
922 
923 	cancel_all_solo ();
924 	return none;
925 }
926 
927 Mackie::LedState
clearsolo_release(Mackie::Button &)928 MackieControlProtocol::clearsolo_release (Mackie::Button&)
929 {
930 	//return session->soloing();
931 	return none;
932 }
933 
934 Mackie::LedState
track_press(Mackie::Button &)935 MackieControlProtocol::track_press (Mackie::Button&)
936 {
937 	set_subview_mode (Subview::TrackView, first_selected_stripable());
938 	return none;
939 }
940 Mackie::LedState
track_release(Mackie::Button &)941 MackieControlProtocol::track_release (Mackie::Button&)
942 {
943 	return none;
944 }
945 Mackie::LedState
send_press(Mackie::Button &)946 MackieControlProtocol::send_press (Mackie::Button&)
947 {
948 	set_subview_mode (Subview::Sends, first_selected_stripable());
949 	return none; /* led state handled by set_subview_mode() */
950 }
951 Mackie::LedState
send_release(Mackie::Button &)952 MackieControlProtocol::send_release (Mackie::Button&)
953 {
954 	return none;
955 }
956 Mackie::LedState
miditracks_press(Mackie::Button &)957 MackieControlProtocol::miditracks_press (Mackie::Button&)
958 {
959 	return none;
960 }
961 Mackie::LedState
miditracks_release(Mackie::Button &)962 MackieControlProtocol::miditracks_release (Mackie::Button&)
963 {
964 	set_view_mode (MidiTracks);
965 	return none;
966 }
967 Mackie::LedState
inputs_press(Mackie::Button &)968 MackieControlProtocol::inputs_press (Mackie::Button&)
969 {
970 #ifdef MIXBUS
971 	set_view_mode (Mixer);  //in Mixbus, this is the same as Global View (avoid dead buttons)
972 #endif
973 	return none;
974 }
975 Mackie::LedState
inputs_release(Mackie::Button &)976 MackieControlProtocol::inputs_release (Mackie::Button&)
977 {
978 	return none;
979 }
980 Mackie::LedState
audiotracks_press(Mackie::Button &)981 MackieControlProtocol::audiotracks_press (Mackie::Button&)
982 {
983 	return none;
984 }
985 Mackie::LedState
audiotracks_release(Mackie::Button &)986 MackieControlProtocol::audiotracks_release (Mackie::Button&)
987 {
988 	set_view_mode (AudioTracks);
989 	return none;
990 }
991 Mackie::LedState
audioinstruments_press(Mackie::Button & b)992 MackieControlProtocol::audioinstruments_press (Mackie::Button& b)
993 {
994 #ifdef MIXBUS
995 	set_view_mode (MidiTracks);  //in Mixbus, we do the same thing as MIDI Tracks ( aviod dead buttons )
996 #endif
997 	return none;
998 }
999 
1000 Mackie::LedState
audioinstruments_release(Mackie::Button & b)1001 MackieControlProtocol::audioinstruments_release (Mackie::Button& b)
1002 {
1003 	return none;
1004 
1005 }
1006 Mackie::LedState
aux_press(Mackie::Button &)1007 MackieControlProtocol::aux_press (Mackie::Button&)
1008 {
1009 	return none;
1010 }
1011 Mackie::LedState
aux_release(Mackie::Button &)1012 MackieControlProtocol::aux_release (Mackie::Button&)
1013 {
1014 	set_view_mode (Auxes);
1015 	return none;
1016 }
1017 Mackie::LedState
busses_press(Mackie::Button &)1018 MackieControlProtocol::busses_press (Mackie::Button&)
1019 {
1020 	return none;
1021 }
1022 Mackie::LedState
busses_release(Mackie::Button &)1023 MackieControlProtocol::busses_release (Mackie::Button&)
1024 {
1025 	set_view_mode (Busses);
1026 	return none;
1027 }
1028 Mackie::LedState
outputs_press(Mackie::Button &)1029 MackieControlProtocol::outputs_press (Mackie::Button&)
1030 {
1031 	return none;
1032 }
1033 Mackie::LedState
outputs_release(Mackie::Button &)1034 MackieControlProtocol::outputs_release (Mackie::Button&)
1035 {
1036 	set_view_mode (Hidden);
1037 	return none;
1038 }
1039 Mackie::LedState
user_press(Mackie::Button &)1040 MackieControlProtocol::user_press (Mackie::Button&)
1041 {
1042 	return none;
1043 }
1044 Mackie::LedState
user_release(Mackie::Button &)1045 MackieControlProtocol::user_release (Mackie::Button&)
1046 {
1047 	set_view_mode (Selected);
1048 	return none;
1049 }
1050 Mackie::LedState
trim_press(Mackie::Button &)1051 MackieControlProtocol::trim_press (Mackie::Button&)
1052 {
1053 	return none;
1054 }
1055 Mackie::LedState
trim_release(Mackie::Button &)1056 MackieControlProtocol::trim_release (Mackie::Button&)
1057 {
1058 	return none;
1059 }
1060 Mackie::LedState
latch_press(Mackie::Button &)1061 MackieControlProtocol::latch_press (Mackie::Button&)
1062 {
1063 	return none;
1064 }
1065 Mackie::LedState
latch_release(Mackie::Button &)1066 MackieControlProtocol::latch_release (Mackie::Button&)
1067 {
1068 	return none;
1069 }
1070 Mackie::LedState
grp_press(Mackie::Button &)1071 MackieControlProtocol::grp_press (Mackie::Button&)
1072 {
1073 	return none;
1074 }
1075 Mackie::LedState
grp_release(Mackie::Button &)1076 MackieControlProtocol::grp_release (Mackie::Button&)
1077 {
1078 	/* There is no "Off" button for automation,
1079 	   so we use Group for this purpose.
1080 	*/
1081 	set_automation_state (Off);
1082 	return none;
1083 }
1084 Mackie::LedState
nudge_press(Mackie::Button &)1085 MackieControlProtocol::nudge_press (Mackie::Button&)
1086 {
1087 	_modifier_state |= MODIFIER_NUDGE;
1088 	nudge_modifier_consumed_by_button = false;
1089 	return on;
1090 }
1091 Mackie::LedState
nudge_release(Mackie::Button &)1092 MackieControlProtocol::nudge_release (Mackie::Button&)
1093 {
1094 	_modifier_state &= ~MODIFIER_NUDGE;
1095 
1096 	/* XXX these action names are stupid, because the action can affect
1097 	 * regions, markers or the playhead depending on selection state.
1098 	 */
1099 
1100 	if (main_modifier_state() & MODIFIER_SHIFT) {
1101 		access_action ("Region/nudge-backward");
1102 	} else {
1103 		access_action ("Region/nudge-forward");
1104 	}
1105 
1106 	return off;
1107 }
1108 Mackie::LedState
replace_press(Mackie::Button &)1109 MackieControlProtocol::replace_press (Mackie::Button&)
1110 {
1111 	if (main_modifier_state() == MODIFIER_SHIFT) {
1112 		toggle_punch_out();
1113 		return none;
1114 	} else {
1115 		access_action ("Common/finish-range-from-playhead");
1116 	}
1117 	return none;
1118 }
1119 Mackie::LedState
replace_release(Mackie::Button &)1120 MackieControlProtocol::replace_release (Mackie::Button&)
1121 {
1122 	return none;
1123 }
1124 Mackie::LedState
click_press(Mackie::Button &)1125 MackieControlProtocol::click_press (Mackie::Button&)
1126 {
1127 	if (main_modifier_state() & MODIFIER_SHIFT) {
1128 		access_action ("Editor/set-punch-from-edit-range");
1129 		return off;
1130 	} else {
1131 		bool state = !Config->get_clicking();
1132 		Config->set_clicking (state);
1133 		return state;
1134 	}
1135 }
1136 Mackie::LedState
click_release(Mackie::Button &)1137 MackieControlProtocol::click_release (Mackie::Button&)
1138 {
1139 	return none;
1140 }
1141 Mackie::LedState
view_press(Mackie::Button &)1142 MackieControlProtocol::view_press (Mackie::Button&)
1143 {
1144 	set_view_mode (Mixer);
1145 	return none;
1146 }
1147 Mackie::LedState
view_release(Mackie::Button &)1148 MackieControlProtocol::view_release (Mackie::Button&)
1149 {
1150 	return none;
1151 }
1152