MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
InputSubsystem.hpp
Go to the documentation of this file.
1#pragma once
2
5
7class InputNode;
8}
9
11struct InputService;
12}
13
14namespace MayaFlux::Core {
15
16class InputManager;
17struct InputBinding;
18
19/**
20 * @class InputSubsystem
21 * @brief Input processing subsystem for external devices
22 *
23 * Coordinates input backends (HID, MIDI, OSC, Serial) and InputManager.
24 * Follows the same lifecycle patterns as AudioSubsystem and GraphicsSubsystem.
25 *
26 * Responsibilities:
27 * - Owns and manages input backends based on GlobalInputConfig
28 * - Owns InputManager which handles processing thread and node dispatch
29 * - Routes backend callbacks to InputManager's queue
30 * - Provides node registration API (delegates to InputManager)
31 *
32 * Does NOT directly call process_sample on nodes - that's InputManager's job.
33 */
34class MAYAFLUX_API InputSubsystem : public ISubsystem {
35public:
36 explicit InputSubsystem(GlobalInputConfig& config);
37 ~InputSubsystem() override;
38
39 // Non-copyable, non-movable
44
45 // ─────────────────────────────────────────────────────────────────────
46 // ISubsystem Implementation
47 // ─────────────────────────────────────────────────────────────────────
48
49 void register_callbacks() override;
50 void initialize(SubsystemProcessingHandle& handle) override;
51 void start() override;
52 void pause() override;
53 void resume() override;
54 void stop() override;
55 void shutdown() override;
56
57 [[nodiscard]] SubsystemTokens get_tokens() const override { return m_tokens; }
58 [[nodiscard]] bool is_ready() const override { return m_ready.load(); }
59 [[nodiscard]] bool is_running() const override { return m_running.load(); }
60 [[nodiscard]] SubsystemType get_type() const override { return SubsystemType::CUSTOM; }
62
63 // ─────────────────────────────────────────────────────────────────────
64 // Backend Management
65 // ─────────────────────────────────────────────────────────────────────
66
67 /**
68 * @brief Add a custom input backend
69 * @param backend Backend instance (takes ownership)
70 * @return true if added successfully
71 */
72 bool add_backend(std::unique_ptr<IInputBackend> backend);
73
74 /**
75 * @brief Get a backend by type
76 */
77 [[nodiscard]] IInputBackend* get_backend(InputType type) const;
78
79 /**
80 * @brief Get all active backends
81 */
82 [[nodiscard]] std::vector<IInputBackend*> get_backends() const;
83
84 // ─────────────────────────────────────────────────────────────────────
85 // Device Management
86 // ─────────────────────────────────────────────────────────────────────
87
88 /**
89 * @brief Get all available input devices across all backends
90 */
91 [[nodiscard]] std::vector<InputDeviceInfo> get_all_devices() const;
92
93 /**
94 * @brief Open a device
95 */
96 bool open_device(InputType backend_type, uint32_t device_id);
97
98 /**
99 * @brief Close a device
100 */
101 void close_device(InputType backend_type, uint32_t device_id);
102
103 // ────────────────────────────────────────────────────────────────────────────
104 // Device Discovery (User-Facing API)
105 // ────────────────────────────────────────────────────────────────────────────
106
107 /**
108 * @brief Get all HID devices
109 */
110 [[nodiscard]] std::vector<InputDeviceInfo> get_hid_devices() const;
111
112 /**
113 * @brief Get all MIDI devices
114 */
115 [[nodiscard]] std::vector<InputDeviceInfo> get_midi_devices() const;
116
117 /**
118 * @brief Get device info by backend type and device ID
119 */
120 [[nodiscard]] std::optional<InputDeviceInfo> get_device_info(
121 InputType backend_type,
122 uint32_t device_id) const;
123
124 /**
125 * @brief Find HID device by vendor/product ID
126 */
127 [[nodiscard]] std::optional<InputDeviceInfo> find_hid_device(
128 uint16_t vendor_id,
129 uint16_t product_id) const;
130
131private:
133 SubsystemProcessingHandle* m_handle { nullptr };
135
136 std::atomic<bool> m_ready { false };
137 std::atomic<bool> m_running { false };
138
139 mutable std::shared_mutex m_backends_mutex;
140 std::unordered_map<InputType, std::unique_ptr<IInputBackend>> m_backends;
141 std::shared_ptr<Registry::Service::InputService> m_input_service;
142
143 void initialize_hid_backend();
144 void initialize_midi_backend();
145 void initialize_osc_backend();
146 void initialize_serial_backend();
147
148 void wire_backend_to_manager(IInputBackend* backend);
149
150 void register_backend_service();
151};
152
153} // namespace MayaFlux::Core
Abstract interface for input device backends.
Base interface for all subsystems in the MayaFlux processing architecture.
Definition Subsystem.hpp:26
SubsystemProcessingHandle * get_processing_context_handle() override
Get the processing context handle for this subsystem.
InputSubsystem(const InputSubsystem &)=delete
SubsystemType get_type() const override
Get the type of this subsystem.
std::shared_ptr< Registry::Service::InputService > m_input_service
InputSubsystem & operator=(InputSubsystem &&)=delete
std::unordered_map< InputType, std::unique_ptr< IInputBackend > > m_backends
bool is_running() const override
Check if subsystem is currently processing.
bool is_ready() const override
Check if subsystem is ready for operation.
SubsystemTokens get_tokens() const override
Get the processing token configuration this subsystem manages.
InputSubsystem(InputSubsystem &&)=delete
InputSubsystem & operator=(const InputSubsystem &)=delete
Input processing subsystem for external devices.
Unified interface combining buffer and node processing for subsystems.
void initialize()
Definition main.cpp:11
InputType
Input backend type enumeration.
std::vector< Core::InputDeviceInfo > get_midi_devices()
Get a list of connected MIDI devices.
Definition Input.cpp:36
std::optional< Core::InputDeviceInfo > find_hid_device(uint16_t vendor_id, uint16_t product_id)
Find a HID device by vendor and product ID.
Definition Input.cpp:46
std::vector< Core::InputDeviceInfo > get_hid_devices()
Get a list of connected HID devices.
Definition Input.cpp:31
Configuration for the InputSubsystem.
Processing token configuration for subsystem operation.