这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@devin-ai-integration
Copy link
Contributor

Implement MIDI I/O Device Opening Functionality

This PR implements actual MIDI device port opening functionality in the C++ MidiDeviceManager to achieve feature parity with the Kotlin implementation. Previously, the C++ version only stored device names without actually opening MIDI ports.

Changes Made

Core Implementation

  • Added libremidi MIDI I/O members: Added std::unique_ptr<libremidi::midi_in> and std::unique_ptr<libremidi::midi_out> to MidiDeviceManager::Impl
  • Implemented actual port opening: Updated set_input_device() and set_output_device() methods to use libremidi API for opening MIDI ports
  • Added callback functionality: Implemented midi_input_opened_ and midi_output_opened_ callback lists matching the Kotlin pattern
  • Added callback registration methods: Added add_input_opened_callback() and add_output_opened_callback() public methods

MIDI Input Handling

  • Input callback setup: Configured libremidi::input_configuration with .on_message callback to process incoming MIDI messages
  • SysEx processing: Connected MIDI input callback to existing process_incoming_sysex() method for message dispatch
  • Proper configuration: Set .ignore_sysex = false to ensure SysEx messages are received

MIDI Output Enhancement

  • Enhanced send_sysex(): Updated to use the opened MIDI output port when available, falling back to custom sender
  • Error handling: Added proper error handling with libremidi's stdx::error system

Resource Management

  • Proper cleanup: Updated shutdown() method to close MIDI ports before shutdown
  • Port lifecycle: Implemented proper opening/closing of ports when devices are changed

Build System

  • Optional Qt5: Made Qt5 tool optional in CMake configuration to avoid build issues when Qt5 is not available

Technical Details

libremidi API Integration

  • Uses libremidi::observer to enumerate available MIDI ports
  • Creates libremidi::midi_in with configuration-based callback setup
  • Creates libremidi::midi_out for sending MIDI messages
  • Proper error handling with stdx::error and stdx::string_ref conversion

Callback Pattern Matching

The implementation follows the exact pattern from the Kotlin version:

  • Kotlin: midiInputOpened and midiOutputOpened callback lists
  • C++: midi_input_opened_ and midi_output_opened_ callback vectors
  • Both invoke registered callbacks when ports are successfully opened

Error Handling

  • Comprehensive error handling for port opening failures
  • Proper conversion of stdx::string_ref to std::string for error messages
  • Graceful fallback when port opening fails

Testing

  • Compilation: Successfully compiles with libremidi integration
  • Build system: CMake configuration works with optional Qt5
  • API compatibility: Maintains existing public API while adding new functionality

Compatibility

This change is backward compatible:

  • Existing API methods unchanged
  • New callback methods are optional additions
  • Fallback behavior maintained for send_sysex when no output port is open

Link to Devin run

https://app.devin.ai/sessions/ad9744cfe3c64558ae6f5adb9fadf986

Requested by: Atsushi Eno (atsushieno@gmail.com)

- Add libremidi::midi_in and libremidi::midi_out members to MidiDeviceManager::Impl
- Implement actual MIDI port opening in set_input_device() and set_output_device()
- Add callback function fields midi_input_opened_ and midi_output_opened_
- Add callback registration methods add_input_opened_callback() and add_output_opened_callback()
- Update send_sysex() to use opened MIDI output port
- Update shutdown() to properly close MIDI ports
- Make Qt5 tool optional in CMake configuration
- Use libremidi input_configuration with callback for MIDI input handling
- Implement proper error handling with stdx::error and string_ref conversion

This achieves feature parity with the Kotlin MidiDeviceManager implementation,
enabling actual MIDI device communication instead of just storing device names.

Co-Authored-By: Atsushi Eno <atsushieno@gmail.com>
@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@atsushieno atsushieno merged commit 518a26b into main Jun 16, 2025
@atsushieno atsushieno deleted the devin/1750042126-implement-midi-io-device-manager branch June 19, 2025 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants