1 /*
2  * Copyright (C) 2006-2007 John Anderson
3  * Copyright (C) 2012-2015 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2015 Len Ovens <len@ovenwerks.net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
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.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #ifndef __ardour_mackie_control_protocol_button_h__
22 #define __ardour_mackie_control_protocol_button_h__
23 
24 #include "ardour/types.h"
25 
26 #include "controls.h"
27 #include "led.h"
28 
29 namespace ArdourSurface {
30 
31 namespace Mackie {
32 
33 class Surface;
34 
35 class Button : public Control
36 {
37 public:
38 /* These values uniquely identify each possible button that an MCP device may
39    send. Each DeviceInfo object contains its own set of button definitions that
40    define what device ID will be sent for each button, and there is no reason
41    for them to be the same.  */
42 
43 	enum ID {
44 		/* Global Buttons */
45 
46 		Track,
47 		Send,
48 		Pan,
49 		Plugin,
50 		Eq,
51 		Dyn,
52 		Left,
53 		Right,
54 		ChannelLeft,
55 		ChannelRight,
56 		Flip,
57 		View,
58 		NameValue,
59 		TimecodeBeats,
60 		F1,
61 		F2,
62 		F3,
63 		F4,
64 		F5,
65 		F6,
66 		F7,
67 		F8,
68 		MidiTracks,
69 		Inputs,
70 		AudioTracks,
71 		AudioInstruments,
72 		Aux,
73 		Busses,
74 		Outputs,
75 		User,
76 		Read,
77 		Write,
78 		Trim,
79 		Touch,
80 		Latch,
81 		Grp,
82 		Save,
83 		Undo,
84 		Cancel,
85 		Enter,
86 		Marker,
87 		Nudge,
88 		Loop,
89 		Drop,
90 		Replace,
91 		Click,
92 		ClearSolo,
93 		Rewind,
94 		Ffwd,
95 		Stop,
96 		Play,
97 		Record,
98 		CursorUp,
99 		CursorDown,
100 		CursorLeft,
101 		CursorRight,
102 		Zoom,
103 		Scrub,
104 		UserA,
105 		UserB,
106 
107 		FinalGlobalButton,
108 
109 		/* Global buttons that users should not redefine */
110 
111 		Shift,
112 		Option,
113 		Ctrl,
114 		CmdAlt,
115 
116 		/* Strip buttons */
117 
118 		RecEnable,
119 		Solo,
120 		Mute,
121 		Select,
122 		VSelect,
123 		FaderTouch,
124 
125 		/* Master fader */
126 
127 		MasterFaderTouch,
128 	};
129 
130 
Button(Surface & s,ID bid,int did,std::string name,Group & group)131 	Button (Surface& s, ID bid, int did, std::string name, Group & group)
132 		: Control (did, name, group)
133 		, _surface (s)
134 		, _bid (bid)
135 		, _led  (did, name + "_led", group)
136 		, press_time (0) {}
137 
zero()138 	MidiByteArray zero() { return _led.zero (); }
set_state(LedState ls)139 	MidiByteArray set_state (LedState ls) { return _led.set_state (ls); }
140 
bid()141 	ID bid() const { return _bid; }
142 
143 	static Control* factory (Surface& surface, Button::ID bid, int id, const std::string&, Group& group);
144 	static int name_to_id (const std::string& name);
145 	static std::string id_to_name (Button::ID);
146 
surface()147 	Surface& surface() const { return _surface; }
148 
149 	void pressed ();
150 	void released ();
151 
152 	int32_t long_press_count ();
153 
154 private:
155 	Surface& _surface;
156 	ID  _bid; /* device independent button ID */
157 	Led _led;
158 	PBD::microseconds_t press_time;
159 };
160 
161 } // Mackie namespace
162 } // ArdourSurface namespace
163 
164 #endif
165