use session stripable selection API
[ardour.git] / libs / surfaces / mackie / button.cc
1 /*
2         Copyright (C) 2006,2007 John Anderson
3         Copyright (C) 2012 Paul Davis
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 #include <glib.h>
21
22 #include "ardour/ardour.h"
23
24 #include "button.h"
25 #include "surface.h"
26 #include "control_group.h"
27
28 using namespace ArdourSurface;
29 using namespace Mackie;
30
31 Control*
32 Button::factory (Surface& surface, Button::ID bid, int id, const std::string& name, Group& group)
33 {
34         Button* b = new Button (surface, bid, id, name, group);
35         /* store button with the device-specific ID */
36         surface.buttons[id] = b;
37         surface.controls.push_back (b);
38         group.add (*b);
39         return b;
40 }
41
42 void
43 Button::pressed ()
44 {
45         press_time = ARDOUR::get_microseconds ();
46 }
47
48 void
49 Button::released ()
50 {
51         press_time = 0;
52 }
53
54 int32_t
55 Button::long_press_count ()
56 {
57         if (press_time == 0) {
58                 return -1; /* button is not pressed */
59         }
60
61         const ARDOUR::microseconds_t delta = ARDOUR::get_microseconds () - press_time;
62
63         if (delta < 500000) {
64                 return 0;
65         } else if (delta < 1000000) {
66                 return 1;
67         }
68
69         return 2;
70 }
71 int
72 Button::name_to_id (const std::string& name)
73 {
74         if (!g_ascii_strcasecmp (name.c_str(), "Track")) { return Track; }
75         if (!g_ascii_strcasecmp (name.c_str(), "Send")) { return Send; }
76         if (!g_ascii_strcasecmp (name.c_str(), "Pan")) { return Pan; }
77         if (!g_ascii_strcasecmp (name.c_str(), "Plugin")) { return Plugin; }
78         if (!g_ascii_strcasecmp (name.c_str(), "Eq")) { return Eq; }
79         if (!g_ascii_strcasecmp (name.c_str(), "Dyn")) { return Dyn; }
80         if (!g_ascii_strcasecmp (name.c_str(), "Bank Left")) { return Left; }
81         if (!g_ascii_strcasecmp (name.c_str(), "Bank Right")) { return Right; }
82         if (!g_ascii_strcasecmp (name.c_str(), "Channel Left")) { return ChannelLeft; }
83         if (!g_ascii_strcasecmp (name.c_str(), "Channel Right")) { return ChannelRight; }
84         if (!g_ascii_strcasecmp (name.c_str(), "Flip")) { return Flip; }
85         if (!g_ascii_strcasecmp (name.c_str(), "View")) { return View; }
86         if (!g_ascii_strcasecmp (name.c_str(), "Name/Value")) { return NameValue; }
87         if (!g_ascii_strcasecmp (name.c_str(), "Timecode/Beats")) { return TimecodeBeats; }
88         if (!g_ascii_strcasecmp (name.c_str(), "F1")) { return F1; }
89         if (!g_ascii_strcasecmp (name.c_str(), "F2")) { return F2; }
90         if (!g_ascii_strcasecmp (name.c_str(), "F3")) { return F3; }
91         if (!g_ascii_strcasecmp (name.c_str(), "F4")) { return F4; }
92         if (!g_ascii_strcasecmp (name.c_str(), "F5")) { return F5; }
93         if (!g_ascii_strcasecmp (name.c_str(), "F6")) { return F6; }
94         if (!g_ascii_strcasecmp (name.c_str(), "F7")) { return F7; }
95         if (!g_ascii_strcasecmp (name.c_str(), "F8")) { return F8; }
96         if (!g_ascii_strcasecmp (name.c_str(), "Midi Tracks")) { return MidiTracks; }
97         if (!g_ascii_strcasecmp (name.c_str(), "Inputs")) { return Inputs; }
98         if (!g_ascii_strcasecmp (name.c_str(), "Audio Tracks")) { return AudioTracks; }
99         if (!g_ascii_strcasecmp (name.c_str(), "Audio Instruments")) { return AudioInstruments; }
100         if (!g_ascii_strcasecmp (name.c_str(), "Aux")) { return Aux; }
101         if (!g_ascii_strcasecmp (name.c_str(), "Busses")) { return Busses; }
102         if (!g_ascii_strcasecmp (name.c_str(), "Outputs")) { return Outputs; }
103         if (!g_ascii_strcasecmp (name.c_str(), "User")) { return User; }
104         if (!g_ascii_strcasecmp (name.c_str(), "UserA")) { return UserA; }
105         if (!g_ascii_strcasecmp (name.c_str(), "UserB")) { return UserB; }
106         if (!g_ascii_strcasecmp (name.c_str(), "Shift")) { return Shift; }
107         if (!g_ascii_strcasecmp (name.c_str(), "Option")) { return Option; }
108         if (!g_ascii_strcasecmp (name.c_str(), "Ctrl")) { return Ctrl; }
109         if (!g_ascii_strcasecmp (name.c_str(), "CmdAlt")) { return CmdAlt; }
110         if (!g_ascii_strcasecmp (name.c_str(), "Read")) { return Read; }
111         if (!g_ascii_strcasecmp (name.c_str(), "Write")) { return Write; }
112         if (!g_ascii_strcasecmp (name.c_str(), "Trim")) { return Trim; }
113         if (!g_ascii_strcasecmp (name.c_str(), "Touch")) { return Touch; }
114         if (!g_ascii_strcasecmp (name.c_str(), "Latch")) { return Latch; }
115         if (!g_ascii_strcasecmp (name.c_str(), "Group")) { return Grp; }
116         if (!g_ascii_strcasecmp (name.c_str(), "Save")) { return Save; }
117         if (!g_ascii_strcasecmp (name.c_str(), "Undo")) { return Undo; }
118         if (!g_ascii_strcasecmp (name.c_str(), "Cancel")) { return Cancel; }
119         if (!g_ascii_strcasecmp (name.c_str(), "Enter")) { return Enter; }
120         if (!g_ascii_strcasecmp (name.c_str(), "Marker")) { return Marker; }
121         if (!g_ascii_strcasecmp (name.c_str(), "Nudge")) { return Nudge; }
122         if (!g_ascii_strcasecmp (name.c_str(), "Loop")) { return Loop; }
123         if (!g_ascii_strcasecmp (name.c_str(), "Drop")) { return Drop; }
124         if (!g_ascii_strcasecmp (name.c_str(), "Replace")) { return Replace; }
125         if (!g_ascii_strcasecmp (name.c_str(), "Click")) { return Click; }
126         if (!g_ascii_strcasecmp (name.c_str(), "Clear Solo")) { return ClearSolo; }
127         if (!g_ascii_strcasecmp (name.c_str(), "Rewind")) { return Rewind; }
128         if (!g_ascii_strcasecmp (name.c_str(), "Ffwd")) { return Ffwd; }
129         if (!g_ascii_strcasecmp (name.c_str(), "Stop")) { return Stop; }
130         if (!g_ascii_strcasecmp (name.c_str(), "Play")) { return Play; }
131         if (!g_ascii_strcasecmp (name.c_str(), "Record")) { return Record; }
132         if (!g_ascii_strcasecmp (name.c_str(), "Cursor Up")) { return CursorUp; }
133         if (!g_ascii_strcasecmp (name.c_str(), "Cursor Down")) { return CursorDown; }
134         if (!g_ascii_strcasecmp (name.c_str(), "Cursor Left")) { return CursorLeft; }
135         if (!g_ascii_strcasecmp (name.c_str(), "Cursor Right")) { return CursorRight; }
136         if (!g_ascii_strcasecmp (name.c_str(), "Zoom")) { return Zoom; }
137         if (!g_ascii_strcasecmp (name.c_str(), "Scrub")) { return Scrub; }
138         if (!g_ascii_strcasecmp (name.c_str(), "User A")) { return UserA; }
139         if (!g_ascii_strcasecmp (name.c_str(), "User B")) { return UserB; }
140
141                 /* Strip buttons */
142
143         if (!g_ascii_strcasecmp (name.c_str(), "Record Enable")) { return RecEnable; }
144         if (!g_ascii_strcasecmp (name.c_str(), "Solo")) { return Solo; }
145         if (!g_ascii_strcasecmp (name.c_str(), "Mute")) { return Mute; }
146         if (!g_ascii_strcasecmp (name.c_str(), "Select")) { return Select; }
147         if (!g_ascii_strcasecmp (name.c_str(), "V-Pot")) { return VSelect; }
148         if (!g_ascii_strcasecmp (name.c_str(), "Fader Touch")) { return FaderTouch; }
149
150         /* Master Fader button */
151
152         if (!g_ascii_strcasecmp (name.c_str(), "Master Fader Touch")) { return MasterFaderTouch; }
153
154         return -1;
155 }
156
157 std::string
158 Button::id_to_name (Button::ID id)
159 {
160         if (id == Track) { return "Track"; }
161         if (id == Send) { return "Send"; }
162         if (id == Pan) { return "Pan"; }
163         if (id == Plugin) { return "Plugin"; }
164         if (id == Eq) { return "Eq"; }
165         if (id == Dyn) { return "Dyn"; }
166         if (id == Left) { return "Bank Left"; }
167         if (id == Right) { return "Bank Right"; }
168         if (id == ChannelLeft) { return "Channel Left"; }
169         if (id == ChannelRight) { return "Channel Right"; }
170         if (id == Flip) { return "Flip"; }
171         if (id == View) { return "View"; }
172         if (id == NameValue) { return "Name/Value"; }
173         if (id == TimecodeBeats) { return "Timecode/Beats"; }
174         if (id == F1) { return "F1"; }
175         if (id == F2) { return "F2"; }
176         if (id == F3) { return "F3"; }
177         if (id == F4) { return "F4"; }
178         if (id == F5) { return "F5"; }
179         if (id == F6) { return "F6"; }
180         if (id == F7) { return "F7"; }
181         if (id == F8) { return "F8"; }
182         if (id == MidiTracks) { return "Midi Tracks"; }
183         if (id == Inputs) { return "Inputs"; }
184         if (id == AudioTracks) { return "Audio Tracks"; }
185         if (id == AudioInstruments) { return "Audio Instruments"; }
186         if (id == Aux) { return "Aux"; }
187         if (id == Busses) { return "Busses"; }
188         if (id == Outputs) { return "Outputs"; }
189         if (id == User) { return "User"; }
190         if (id == Shift) { return "Shift"; }
191         if (id == Option) { return "Option"; }
192         if (id == Ctrl) { return "Ctrl"; }
193         if (id == CmdAlt) { return "CmdAlt"; }
194         if (id == Read) { return "Read"; }
195         if (id == Write) { return "Write"; }
196         if (id == Trim) { return "Trim"; }
197         if (id == Touch) { return "Touch"; }
198         if (id == Latch) { return "Latch"; }
199         if (id == Grp) { return "Group"; }
200         if (id == Save) { return "Save"; }
201         if (id == Undo) { return "Undo"; }
202         if (id == Cancel) { return "Cancel"; }
203         if (id == Enter) { return "Enter"; }
204         if (id == Marker) { return "Marker"; }
205         if (id == Nudge) { return "Nudge"; }
206         if (id == Loop) { return "Loop"; }
207         if (id == Drop) { return "Drop"; }
208         if (id == Replace) { return "Replace"; }
209         if (id == Click) { return "Click"; }
210         if (id == ClearSolo) { return "Clear Solo"; }
211         if (id == Rewind) { return "Rewind"; }
212         if (id == Ffwd) { return "FFwd"; }
213         if (id == Stop) { return "Stop"; }
214         if (id == Play) { return "Play"; }
215         if (id == Record) { return "Record"; }
216         if (id == CursorUp) { return "Cursor Up"; }
217         if (id == CursorDown) { return "Cursor Down"; }
218         if (id == CursorLeft) { return "Cursor Left"; }
219         if (id == CursorRight) { return "Cursor Right"; }
220         if (id == Zoom) { return "Zoom"; }
221         if (id == Scrub) { return "Scrub"; }
222         if (id == UserA) { return "User A"; }
223         if (id == UserB) { return "User B"; }
224
225         if (id == RecEnable) { return "Record Enable"; }
226         if (id == Solo) { return "Solo"; }
227         if (id == Mute) { return "Mute"; }
228         if (id == Select) { return "Select"; }
229         if (id == VSelect) { return "V-Pot"; }
230         if (id == FaderTouch) { return "Fader Touch"; }
231
232         if (id == MasterFaderTouch) { return "Master Fader Touch"; }
233
234         return "???";
235 }