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_device_info_h__
20 #define __ardour_us2400_control_protocol_device_info_h__
21 
22 #include <iostream>
23 #include <stdint.h>
24 #include <string>
25 #include <map>
26 
27 #include "button.h"
28 
29 class XMLNode;
30 
31 namespace ArdourSurface {
32 
33 namespace US2400 {
34 
35 struct GlobalButtonInfo {
36 	std::string label; // visible to user
37 	std::string group; // in case we want to present in a GUI
38 	int32_t id;       // value sent by device
39 
GlobalButtonInfoGlobalButtonInfo40 	GlobalButtonInfo () : id (-1) {}
GlobalButtonInfoGlobalButtonInfo41 	GlobalButtonInfo (const std::string& l, const std::string& g, uint32_t i)
42 		: label (l), group (g), id (i) {}
43 };
44 
45 struct StripButtonInfo {
46 	int32_t base_id;
47 	std::string name;
48 
StripButtonInfoStripButtonInfo49 	StripButtonInfo () : base_id (-1) {}
StripButtonInfoStripButtonInfo50 	StripButtonInfo (uint32_t i, const std::string& n)
51 		: base_id (i), name (n) {}
52 };
53 
54 class DeviceInfo
55 {
56                                         public:
57 	enum DeviceType {
58 		MCU = 0x14,
59 		MCXT = 0x15,
60 		LC = 0x10,
61 		LCXT = 0x11,
62 		HUI = 0x5
63 	};
64 
65 	DeviceInfo();
66 	~DeviceInfo();
67 
68 	int set_state (const XMLNode&, int version);
69 
device_type()70 	DeviceType device_type() const { return _device_type; }
71 	uint32_t strip_cnt () const;
72 	uint32_t extenders() const;
73 	uint32_t master_position() const;
74 	bool has_two_character_display() const;
75 	bool has_master_fader () const;
76 	bool has_timecode_display() const;
77 	bool has_global_controls() const;
78 	bool has_jog_wheel () const;
79 	bool has_touch_sense_faders() const;
80 	bool no_handshake() const;
81 	bool has_meters() const;
82 	bool has_separate_meters() const;
us2400()83 	bool us2400() const { return _us2400; }
84 	const std::string& name() const;
85 
86 	static std::map<std::string,DeviceInfo> device_info;
87 	static void reload_device_info();
88 
89 	std::string& get_global_button_name(Button::ID);
90 	GlobalButtonInfo& get_global_button(Button::ID);
91 
92 	typedef std::map<Button::ID,GlobalButtonInfo> GlobalButtonsInfo;
93 	typedef std::map<Button::ID,StripButtonInfo> StripButtonsInfo;
94 
global_buttons()95 	const GlobalButtonsInfo& global_buttons() const { return _global_buttons; }
strip_buttons()96 	const StripButtonsInfo& strip_buttons() const { return _strip_buttons; }
97 
98                                         private:
99 	uint32_t _strip_cnt;
100 	uint32_t _extenders;
101 	uint32_t _master_position;
102 	bool     _has_two_character_display;
103 	bool     _has_master_fader;
104 	bool     _has_timecode_display;
105 	bool     _has_global_controls;
106 	bool     _has_jog_wheel;
107 	bool     _has_touch_sense_faders;
108 	bool     _uses_logic_control_buttons;
109 	bool     _no_handshake;
110 	bool     _has_meters;
111 	bool     _has_separate_meters;
112 	bool     _us2400;
113 	DeviceType _device_type;
114 	std::string _name;
115 	std::string _global_button_name;
116 
117 	GlobalButtonsInfo _global_buttons;
118 	StripButtonsInfo _strip_buttons;
119 
120 	void logic_control_buttons ();
121 	void us2400_control_buttons ();
122 	void shared_buttons ();
123 };
124 
125 
126 } // US2400 namespace
127 } // ArdourSurface namespace
128 
129 std::ostream& operator<< (std::ostream& os, const ArdourSurface::US2400::DeviceInfo& di);
130 
131 #endif /* __ardour_us2400_control_protocol_device_info_h__ */
132