MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ open_device()

bool MayaFlux::Core::MIDIBackend::open_device ( uint32_t  device_id)
overridevirtual

Open a device for input.

Parameters
device_idDevice identifier from get_devices()
Returns
true if device was opened successfully

Implements MayaFlux::Core::IInputBackend.

Definition at line 209 of file MIDIBackend.cpp.

210{
211 std::lock_guard lock(m_devices_mutex);
212
213 if (m_open_devices.find(device_id) != m_open_devices.end()) {
215 "MIDI port {} already open", device_id);
216 return true;
217 }
218
219 auto it = m_enumerated_devices.find(device_id);
220 if (it == m_enumerated_devices.end()) {
222 "MIDI port {} not found", device_id);
223 return false;
224 }
225
226 try {
227 auto state = std::make_shared<MIDIPortState>();
228 state->info = it->second;
229 state->device_id = device_id;
230 state->input_callback = m_input_callback;
231 state->midi_in = std::make_unique<RtMidiIn>();
232
233 state->midi_in->openPort(state->info.rtmidi_port_number, state->info.name);
234 state->midi_in->setCallback(&MIDIBackend::rtmidi_callback, state.get());
235 state->midi_in->ignoreTypes(false, false, false);
236 state->active.store(true);
237
238 m_open_devices.insert_or_assign(device_id, state);
239
241 "Opened MIDI port {}: {}", device_id, state->info.name);
242
243 return true;
244
245 } catch (const RtMidiError& error) {
247 "Failed to open MIDI port {}: {}", it->second.name, error.getMessage());
248 return false;
249 }
250}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
std::unordered_map< uint32_t, MIDIPortInfo > m_enumerated_devices
std::unordered_map< uint32_t, std::shared_ptr< MIDIPortState > > m_open_devices
static void rtmidi_callback(double timestamp, std::vector< unsigned char > *message, void *user_data)
@ InputBackend
Input device backend (HID, MIDI, OSC)
void error(Component component, Context context, std::source_location location, std::string_view message)
Log an error message and optionally throw an exception.
@ Core
Core engine, backend, subsystems.

References MayaFlux::Journal::Core, MayaFlux::Journal::InputBackend, m_devices_mutex, m_enumerated_devices, m_input_callback, m_open_devices, MF_ERROR, MF_INFO, MF_WARN, and rtmidi_callback().

Referenced by MayaFlux::Core::InputSubsystem::initialize_midi_backend(), and start().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: