MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
GlobalInputConfig.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Core {
6
7// ─────────────────────────────────────────────────────────────────────────────
8// HID Configuration
9// ─────────────────────────────────────────────────────────────────────────────
10
11/**
12 * @brief Filter for HID device enumeration
13 *
14 * Used to selectively enumerate HID devices by VID/PID or usage page/usage.
15 * All fields are optional - nullopt means "match any".
16 */
17struct MAYAFLUX_API HIDDeviceFilter {
18 std::optional<uint16_t> vendor_id; ///< USB Vendor ID (nullopt = any)
19 std::optional<uint16_t> product_id; ///< USB Product ID (nullopt = any)
20 std::optional<uint16_t> usage_page; ///< HID usage page (nullopt = any)
21 std::optional<uint16_t> usage; ///< HID usage (nullopt = any)
22
23 /**
24 * @brief Check if a device matches this filter
25 */
26 [[nodiscard]] bool matches(uint16_t vid, uint16_t pid,
27 uint16_t upage = 0, uint16_t usg = 0) const
28 {
29 if (vendor_id && *vendor_id != vid)
30 return false;
31 if (product_id && *product_id != pid)
32 return false;
33 if (usage_page && *usage_page != upage)
34 return false;
35
36 return !usage || *usage == usg;
37 }
38
39 // ─────────────────────────────────────────────────────────────────────
40 // Common Preset Filters
41 // ─────────────────────────────────────────────────────────────────────
42
43 /** @brief Match any HID device */
44 static HIDDeviceFilter any() { return {}; }
45
46 /** @brief Match gamepads (Usage Page 0x01, Usage 0x05) */
48 {
49 return {
50 .vendor_id = std::nullopt,
51 .product_id = std::nullopt,
52 .usage_page = 0x01,
53 .usage = 0x05
54 };
55 }
56
57 /** @brief Match joysticks (Usage Page 0x01, Usage 0x04) */
59 {
60 return {
61 .vendor_id = std::nullopt,
62 .product_id = std::nullopt,
63 .usage_page = 0x01,
64 .usage = 0x04
65 };
66 }
67
68 /** @brief Match keyboards (Usage Page 0x01, Usage 0x06) */
70 {
71 return {
72 .vendor_id = std::nullopt,
73 .product_id = std::nullopt,
74 .usage_page = 0x01,
75 .usage = 0x06
76 };
77 }
78
79 /** @brief Match mice (Usage Page 0x01, Usage 0x02) */
81 {
82 return {
83 .vendor_id = std::nullopt,
84 .product_id = std::nullopt,
85 .usage_page = 0x01,
86 .usage = 0x02
87 };
88 }
89
90 /** @brief Match specific device by VID/PID */
91 static HIDDeviceFilter device(uint16_t vid, uint16_t pid)
92 {
93 return {
94 .vendor_id = vid,
95 .product_id = pid,
96 .usage_page = std::nullopt,
97 .usage = std::nullopt
98 };
99 }
100};
101
102/**
103 * @brief HID backend configuration
104 */
105struct MAYAFLUX_API HIDBackendInfo {
106 bool enabled {}; ///< Enable HID backend
107 std::vector<HIDDeviceFilter> filters; ///< Device filters (empty = all devices)
108 bool auto_open {}; ///< Auto-open matching devices on start
109 size_t read_buffer_size { 64 }; ///< Per-device read buffer size
110 int poll_timeout_ms { 10 }; ///< Polling timeout in milliseconds
111 bool auto_reconnect { true }; ///< Auto-reconnect disconnected devices
112 uint32_t reconnect_interval_ms { 1000 }; ///< Reconnection attempt interval
113};
114
115// ─────────────────────────────────────────────────────────────────────────────
116// MIDI Configuration (Future)
117// ─────────────────────────────────────────────────────────────────────────────
118
119/**
120 * @brief MIDI backend configuration
121 */
122struct MAYAFLUX_API MIDIBackendInfo {
123 bool enabled { false }; ///< Enable MIDI backend
124 bool auto_open_inputs { true }; ///< Auto-open all MIDI input ports
125 bool auto_open_outputs { false }; ///< Auto-open all MIDI output ports
126 std::vector<std::string> input_port_filters; ///< Filter input ports by name substring
127 std::vector<std::string> output_port_filters; ///< Filter output ports by name substring
128 bool enable_virtual_port { false }; ///< Create a virtual MIDI port
129 std::string virtual_port_name { "MayaFlux" }; ///< Name for virtual port
130};
131
132// ─────────────────────────────────────────────────────────────────────────────
133// OSC Configuration (Future)
134// ─────────────────────────────────────────────────────────────────────────────
135
136/**
137 * @brief OSC backend configuration
138 */
139struct MAYAFLUX_API OSCBackendInfo {
140 bool enabled { false }; ///< Enable OSC backend
141 uint16_t receive_port { 8000 }; ///< UDP port to listen on
142 uint16_t send_port { 9000 }; ///< Default UDP port to send to
143 std::string send_address { "127.0.0.1" }; ///< Default send address
144 bool enable_multicast { false }; ///< Enable multicast reception
145 std::string multicast_group; ///< Multicast group address
146 size_t receive_buffer_size { 65536 }; ///< UDP receive buffer size
147};
148
149// ─────────────────────────────────────────────────────────────────────────────
150// Serial Configuration (Future)
151// ─────────────────────────────────────────────────────────────────────────────
152
153/**
154 * @brief Serial port configuration
155 */
156struct MAYAFLUX_API SerialPortConfig {
157 std::string port_name; ///< e.g., "/dev/ttyUSB0" or "COM3"
158 uint32_t baud_rate { 9600 }; ///< Baud rate
159 uint8_t data_bits { 8 }; ///< Data bits (5, 6, 7, or 8)
160 uint8_t stop_bits { 1 }; ///< Stop bits (1 or 2)
161 char parity { 'N' }; ///< Parity: 'N'one, 'E'ven, 'O'dd
162 bool flow_control { false }; ///< Hardware flow control
163};
164
165/**
166 * @brief Serial backend configuration
167 */
168struct MAYAFLUX_API SerialBackendInfo {
169 bool enabled { false }; ///< Enable Serial backend
170 std::vector<SerialPortConfig> ports; ///< Ports to open
171 bool auto_detect_arduino { false }; ///< Auto-detect Arduino devices
172 uint32_t default_baud_rate { 115200 }; ///< Default baud for auto-detected devices
173};
174
175// ─────────────────────────────────────────────────────────────────────────────
176// Global Input Configuration
177// ─────────────────────────────────────────────────────────────────────────────
178
179/**
180 * @class GlobalInputConfig
181 * @brief Configuration for the InputSubsystem
182 *
183 * Centralizes configuration for all input backends (HID, MIDI, OSC, Serial).
184 * Passed to InputSubsystem during construction.
185 *
186 * Example usage:
187 * @code
188 * GlobalInputConfig input_config;
189 *
190 * // Enable HID with gamepad filter
191 * input_config.hid.enabled = true;
192 * input_config.hid.filters.push_back(HIDDeviceFilter::controller());
193 *
194 * // Enable OSC on port 8000
195 * input_config.osc.enabled = true;
196 * input_config.osc.receive_port = 8000;
197 *
198 * auto input_subsystem = std::make_unique<InputSubsystem>(input_config);
199 * @endcode
200 */
201struct MAYAFLUX_API GlobalInputConfig {
202 HIDBackendInfo hid; ///< HID backend configuration
203 MIDIBackendInfo midi; ///< MIDI backend configuration
204 OSCBackendInfo osc; ///< OSC backend configuration
205 SerialBackendInfo serial; ///< Serial backend configuration
206
207 // ─────────────────────────────────────────────────────────────────────
208 // Convenience Factory Methods
209 // ─────────────────────────────────────────────────────────────────────
210
211 /**
212 * @brief Create config with HID enabled for gamepads
213 */
215 {
216 GlobalInputConfig config;
217 config.hid.enabled = true;
218 config.hid.filters.push_back(HIDDeviceFilter::controller());
219 config.hid.filters.push_back(HIDDeviceFilter::specialized());
220 return config;
221 }
222
223 /**
224 * @brief Create config with HID enabled for all devices
225 */
227 {
228 GlobalInputConfig config;
229 config.hid.enabled = true;
230 // No filters = all devices
231 return config;
232 }
233
234 /**
235 * @brief Create config with OSC enabled
236 * @param port UDP port to listen on
237 */
238 static GlobalInputConfig with_osc(uint16_t port = 8000)
239 {
240 GlobalInputConfig config;
241 config.osc.enabled = true;
242 config.osc.receive_port = port;
243 return config;
244 }
245
246 /**
247 * @brief Create config with MIDI enabled
248 */
250 {
251 GlobalInputConfig config;
252 config.midi.enabled = true;
253 return config;
254 }
255
256 /**
257 * @brief Check if any backend is enabled
258 */
259 [[nodiscard]] bool any_enabled() const
260 {
261 return hid.enabled || midi.enabled || osc.enabled || serial.enabled;
262 }
263};
264
265} // namespace MayaFlux::Core
static GlobalInputConfig with_midi()
Create config with MIDI enabled.
static GlobalInputConfig with_osc(uint16_t port=8000)
Create config with OSC enabled.
HIDBackendInfo hid
HID backend configuration.
MIDIBackendInfo midi
MIDI backend configuration.
bool any_enabled() const
Check if any backend is enabled.
OSCBackendInfo osc
OSC backend configuration.
static GlobalInputConfig with_gamepads()
Create config with HID enabled for gamepads.
SerialBackendInfo serial
Serial backend configuration.
static GlobalInputConfig with_all_hid()
Create config with HID enabled for all devices.
Configuration for the InputSubsystem.
std::vector< HIDDeviceFilter > filters
Device filters (empty = all devices)
HID backend configuration.
std::optional< uint16_t > usage
HID usage (nullopt = any)
static HIDDeviceFilter controller()
Match gamepads (Usage Page 0x01, Usage 0x05)
static HIDDeviceFilter device(uint16_t vid, uint16_t pid)
Match specific device by VID/PID.
static HIDDeviceFilter mouse()
Match mice (Usage Page 0x01, Usage 0x02)
std::optional< uint16_t > vendor_id
USB Vendor ID (nullopt = any)
std::optional< uint16_t > product_id
USB Product ID (nullopt = any)
std::optional< uint16_t > usage_page
HID usage page (nullopt = any)
static HIDDeviceFilter any()
Match any HID device.
static HIDDeviceFilter specialized()
Match joysticks (Usage Page 0x01, Usage 0x04)
bool matches(uint16_t vid, uint16_t pid, uint16_t upage=0, uint16_t usg=0) const
Check if a device matches this filter.
static HIDDeviceFilter keyboard()
Match keyboards (Usage Page 0x01, Usage 0x06)
Filter for HID device enumeration.
std::vector< std::string > input_port_filters
Filter input ports by name substring.
std::vector< std::string > output_port_filters
Filter output ports by name substring.
MIDI backend configuration.
std::string multicast_group
Multicast group address.
uint16_t receive_port
UDP port to listen on.
OSC backend configuration.
bool enabled
Enable Serial backend.
std::vector< SerialPortConfig > ports
Ports to open.
Serial backend configuration.
std::string port_name
e.g., "/dev/ttyUSB0" or "COM3"