1 /*
2  * Copyright (C) 2017 Ben Loftis <ben@harrisonconsoles.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef __ardour_us2400_control_protocol_button_h__
20 #define __ardour_us2400_control_protocol_button_h__
21 
22 #include "ardour/types.h"
23 
24 #include "controls.h"
25 #include "led.h"
26 
27 namespace ArdourSurface {
28 
29 namespace US2400 {
30 
31 class Surface;
32 
33 class Button : public Control
34 {
35 public:
36 /* These values uniquely identify each possible button that an MCP device may
37    send. Each DeviceInfo object contains its own set of button definitions that
38    define what device ID will be sent for each button, and there is no reason
39    for them to be the same.  */
40 
41 	enum ID {
42 		/* Global Buttons */
43 
44 		Scrub,
45 		F1,
46 		F2,
47 		F3,
48 		F4,
49 		F5,
50 		F6,
51 		Rewind,
52 		Ffwd,
53 		Stop,
54 		Play,
55 		Record,
56 		Left,
57 		Right,
58 		Flip,
59 		MstrSelect,
60 
61 		FinalGlobalButton,
62 
63 
64 		/* Global buttons that users should not redefine */
65 
66 		Drop,
67 		Send,
68 		Pan,
69 		ClearSolo,
70 		Shift,
71 		Option,
72 		Ctrl,
73 		CmdAlt,
74 
75 		/* Strip buttons */
76 
77 		Solo,
78 		Mute,
79 		Select,
80 		FaderTouch,
81 
82 		/* Master fader */
83 
84 		MasterFaderTouch,
85 	};
86 
87 
Button(Surface & s,ID bid,int did,std::string name,Group & group)88 	Button (Surface& s, ID bid, int did, std::string name, Group & group)
89 		: Control (did, name, group)
90 		, _surface (s)
91 		, _bid (bid)
92 		, _led  (did, name + "_led", group)
93 		, press_time (0) {}
94 
zero()95 	MidiByteArray zero() { return _led.zero (); }
set_state(LedState ls)96 	MidiByteArray set_state (LedState ls) { return _led.set_state (ls); }
97 
bid()98 	ID bid() const { return _bid; }
99 
100 	static Control* factory (Surface& surface, Button::ID bid, int id, const std::string&, Group& group);
101 	static int name_to_id (const std::string& name);
102 	static std::string id_to_name (Button::ID);
103 
surface()104 	Surface& surface() const { return _surface; }
105 
mark_dirty()106 	void mark_dirty() { _led.mark_dirty(); }
107 
108 	void pressed ();
109 	void released ();
110 
111 	int32_t long_press_count ();
112 
113 private:
114 	Surface& _surface;
115 	ID  _bid; /* device independent button ID */
116 	Led _led;
117 	PBD::microseconds_t press_time;
118 };
119 
120 } // US2400 namespace
121 } // ArdourSurface namespace
122 
123 #endif
124