MayaFlux 0.4.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, 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 void wait_until_running() override;
57
58 [[nodiscard]] SubsystemTokens get_tokens() const override { return m_tokens; }
59 [[nodiscard]] bool is_ready() const override { return m_ready.load(); }
60 [[nodiscard]] bool is_running() const override { return m_running.load(); }
61 [[nodiscard]] SubsystemType get_type() const override { return SubsystemType::CUSTOM; }
63
64 // ─────────────────────────────────────────────────────────────────────
65 // Backend Management
66 // ─────────────────────────────────────────────────────────────────────
67
68 /**
69 * @brief Add a custom input backend
70 * @param backend Backend instance (takes ownership)
71 * @return true if added successfully
72 */
73 bool add_backend(std::unique_ptr<IInputBackend> backend);
74
75 /**
76 * @brief Get a backend by type
77 */
78 [[nodiscard]] IInputBackend* get_backend(InputType type) const;
79
80 /**
81 * @brief Get all active backends
82 */
83 [[nodiscard]] std::vector<IInputBackend*> get_backends() const;
84
85 // ─────────────────────────────────────────────────────────────────────
86 // Device Management
87 // ─────────────────────────────────────────────────────────────────────
88
89 /**
90 * @brief Get all available input devices across all backends
91 */
92 [[nodiscard]] std::vector<InputDeviceInfo> get_all_devices() const;
93
94 /**
95 * @brief Open a device
96 */
97 bool open_device(InputType backend_type, uint32_t device_id);
98
99 /**
100 * @brief Close a device
101 */
102 void close_device(InputType backend_type, uint32_t device_id);
103
104 // ────────────────────────────────────────────────────────────────────────────
105 // Device Discovery (User-Facing API)
106 // ────────────────────────────────────────────────────────────────────────────
107
108 /**
109 * @brief Get all HID devices
110 */
111 [[nodiscard]] std::vector<InputDeviceInfo> get_hid_devices() const;
112
113 /**
114 * @brief Get all MIDI devices
115 */
116 [[nodiscard]] std::vector<InputDeviceInfo> get_midi_devices() const;
117
118 /**
119 * @brief Get device info by backend type and device ID
120 */
121 [[nodiscard]] std::optional<InputDeviceInfo> get_device_info(
122 InputType backend_type,
123 uint32_t device_id) const;
124
125 /**
126 * @brief Find HID device by vendor/product ID
127 */
128 [[nodiscard]] std::optional<InputDeviceInfo> find_hid_device(
129 uint16_t vendor_id,
130 uint16_t product_id) const;
131
132private:
134 SubsystemProcessingHandle* m_handle { nullptr };
136
137 std::atomic<bool> m_ready { false };
138 std::atomic<bool> m_running { false };
139
140 mutable std::shared_mutex m_backends_mutex;
141 std::unordered_map<InputType, std::unique_ptr<IInputBackend>> m_backends;
142 std::shared_ptr<Registry::Service::InputService> m_input_service;
143
144 void initialize_hid_backend();
145 void initialize_midi_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.