globally remove all trailing whitespace from ardour code base.
[ardour.git] / libs / surfaces / tranzport / buttons.cc
1 /*
2  *   Copyright (C) 2006 Paul Davis
3  *   Copyright (C) 2007 Michael Taht
4  *
5  *   This program is free software; you can redistribute it and/or modify
6  *   it under the terms of the GNU General Public License as published by
7  *   the Free Software Foundation; either version 2 of the License, or
8  *   (at your option) any later version.
9  *
10  *   This program is distributed in the hope that it will be useful,
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *   GNU General Public License for more details.
14  *
15  *   You should have received a copy of the GNU General Public License
16  *   along with this program; if not, write to the Free Software
17  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  *   */
20
21 #include "tranzport_control_protocol.h"
22
23 #define TRANZPORT_BUTTON_HANDLER(callback, button_arg) if (button_changes & button_arg) { \
24                 if (buttonmask & button_arg) {                          \
25                         callback##_press (buttonmask&ButtonShift); } else { callback##_release (buttonmask&ButtonShift); } }
26
27 int
28 TranzportControlProtocol::process (uint8_t* buf)
29 {
30
31         uint32_t this_button_mask;
32         uint32_t button_changes;
33
34         _device_status = buf[1];
35
36 #if DEBUG_TRANZPORT > 10
37         // Perhaps the device can go offline due to flow control, print command bits to see if we have anything interesting
38         if(_device_status == STATUS_ONLINE) {
39                 printf("ONLINE   : %02x %02x %02x %02x %02x %02x %02x %02x\n",
40                        buf[0],buf[1],buf[2], buf[3], buf[4], buf[5],buf[6],buf[7]);
41         }
42         if(_device_status == STATUS_OFFLINE) {
43                 printf("OFFLINE  : %02x %02x %02x %02x %02x %02x %02x %02x\n",
44                        buf[0],buf[1],buf[2], buf[3], buf[4], buf[5],buf[6],buf[7]);
45         }
46
47         if(_device_status != STATUS_OK) { return 1; }
48
49 #endif
50
51
52         this_button_mask = 0;
53         this_button_mask |= buf[2] << 24;
54         this_button_mask |= buf[3] << 16;
55         this_button_mask |= buf[4] << 8;
56         this_button_mask |= buf[5];
57         _datawheel = buf[6];
58         
59 #if DEBUG_TRANZPORT_STATE > 1
60         // Is the state machine incomplete?
61         const unsigned int knownstates = 0x00004000|0x00008000|
62                 0x04000000|    0x40000000|    0x00040000|    0x00400000|
63                 0x00000400|    0x80000000|    0x02000000|    0x20000000|
64                 0x00800000|    0x00080000|    0x00020000|    0x00200000|
65                 0x00000200|    0x01000000|    0x10000000|    0x00010000|
66                 0x00100000|    0x00000100|    0x08000000|    0x00001000;
67
68         std::bitset<32> bi(knownstates);
69         std::bitset<32> vi(this_button_mask);
70
71         //  if an bi & vi == vi the same - it's a valid set
72
73         if(vi != (bi & vi)) {
74                 printf("UNKNOWN STATE: %s also, datawheel= %d\n", vi.to_string().c_str(), _datawheel);
75         }
76 #endif
77
78         button_changes = (this_button_mask ^ buttonmask);
79         buttonmask = this_button_mask;
80
81         if (_datawheel) {
82                 datawheel ();
83         }
84
85         // SHIFT + STOP + PLAY for bling mode?
86         // if (button_changes & ButtonPlay & ButtonStop) {
87         // bling_mode_toggle();
88         // } or something like that
89
90         TRANZPORT_BUTTON_HANDLER(button_event_battery,ButtonBattery);
91         TRANZPORT_BUTTON_HANDLER(button_event_backlight,ButtonBacklight);
92         TRANZPORT_BUTTON_HANDLER(button_event_trackleft,ButtonTrackLeft);
93         TRANZPORT_BUTTON_HANDLER(button_event_trackright,ButtonTrackRight);
94         TRANZPORT_BUTTON_HANDLER(button_event_trackrec,ButtonTrackRec);
95         TRANZPORT_BUTTON_HANDLER(button_event_trackmute,ButtonTrackMute);
96         TRANZPORT_BUTTON_HANDLER(button_event_tracksolo,ButtonTrackSolo);
97         TRANZPORT_BUTTON_HANDLER(button_event_undo,ButtonUndo);
98         TRANZPORT_BUTTON_HANDLER(button_event_in,ButtonIn);
99         TRANZPORT_BUTTON_HANDLER(button_event_out,ButtonOut);
100         TRANZPORT_BUTTON_HANDLER(button_event_punch,ButtonPunch);
101         TRANZPORT_BUTTON_HANDLER(button_event_loop,ButtonLoop);
102         TRANZPORT_BUTTON_HANDLER(button_event_prev,ButtonPrev);
103         TRANZPORT_BUTTON_HANDLER(button_event_add,ButtonAdd);
104         TRANZPORT_BUTTON_HANDLER(button_event_next,ButtonNext);
105         TRANZPORT_BUTTON_HANDLER(button_event_rewind,ButtonRewind);
106         TRANZPORT_BUTTON_HANDLER(button_event_fastforward,ButtonFastForward);
107         TRANZPORT_BUTTON_HANDLER(button_event_stop,ButtonStop);
108         TRANZPORT_BUTTON_HANDLER(button_event_play,ButtonPlay);
109         TRANZPORT_BUTTON_HANDLER(button_event_record,ButtonRecord);
110         TRANZPORT_BUTTON_HANDLER(button_event_footswitch,ButtonFootswitch);
111         return 0;
112 }
113