-
Notifications
You must be signed in to change notification settings - Fork 419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement MIDI input support #2804
Conversation
Point raised in private discussion: Should MidiKey be part of InputKey? Right now it's a separate enum which makes conversion to and from integers easy, but it probably isn't usable as an input in projects like lazer. |
It should be available as normal input, yes. |
That CodeFactor failure complains about |
PR should be ready for review and testing on Android, iOS and MacOS. I've tried testing on Android but my device doesn't seem to support MIDI input. |
Unfortunately this library seems to crash on macOS (atsushieno/managed-midi#50), and the developer seems to be "unable to continue development" (atsushieno/managed-midi#42). May be best to wait for ManagedBass to be fixed... Code-wide it looks great. |
True, but this applies to primary development (on Linux) and not for MacOS-specific issues. I will try fixing this on weekend. |
Have made a few fixes for other hard crashes in managed-midi, but at this point I'm not completely sold on the stability of the framework. Gonna delay merging this one for a few weeks while the managedbass guy responds (they're generally pretty responsive). |
@smoogipoo ManagedBass got updated to v3 and I got a response in ManagedBass/ManagedBass#54, and it seems Bass does not support MIDI input on Android. Managed-midi has received a few bugfixes since your last message so could you give it another look when you have a spare moment? |
I'm able to trigger the sequence:
By refreshing devices on macOS. Based on how MIDI input is implemented on macOS it's probably doing something really silly, but this should probably be guarded against otherwise it crashes the app. Causes:
|
osu.Framework/Input/InputManager.cs
Outdated
@@ -539,6 +560,10 @@ protected virtual void HandleMouseButtonStateChange(ButtonStateChangeEvent<Mouse | |||
|
|||
private bool handleScroll(InputState state, Vector2 lastScroll, bool isPrecise) => PropagateBlockableEvent(PositionalInputQueue, new ScrollEvent(state, state.Mouse.Scroll - lastScroll, isPrecise)); | |||
|
|||
private bool handleMidiKeyDown(InputState state, MidiKey key, byte velocity) => PropagateBlockableEvent(NonPositionalInputQueue, new MidiDownEvent(state, key, velocity)); | |||
|
|||
private bool handleMidiKeyUp(InputState state, MidiKey key) => PropagateBlockableEvent(NonPositionalInputQueue, new MidiUpEvent(state, key)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be updated to use the new ButtonEventManager
stuff. See how it's implemented for joysticks / mouse buttons / keys for reference.
osu.Framework/Graphics/Drawable.cs
Outdated
@@ -2192,6 +2198,10 @@ public bool TriggerEvent(UIEvent e) | |||
/// <param name="e">The <see cref="JoystickReleaseEvent"/> containing information about the input event.</param> | |||
protected virtual void OnJoystickRelease(JoystickReleaseEvent e) => Handle(e); | |||
|
|||
protected virtual bool OnMidiDown(MidiDownEvent e) => Handle(e); | |||
|
|||
protected virtual bool OnMidiUp(MidiUpEvent e) => Handle(e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should return void
(and false
in TriggerEvent()
).
Also I assume this isn't supposed to support channels at this point? It's coded in such a way that it seems like it should support them, but it isn't for some reason. |
In case you are trying to use managed-midi's own Core MIDI support, note that its quality is super low and not quite ready for general consumption yet. I cannot provide solid implementation for Xamarin.Mac alternatives up to CoreFoundation level. On Mac managed-midi via Xamarin.Mac is the only viable approach (managed-midi has particular build for the profile). Or you might want to try RtMidiSharp which might work better. |
Ah... We're avoiding using Xamarin on desktop platforms in favour of netcore, so that isn't really an option for us at this point. Maybe NET5 will change that. I'm not super concerned about macOS support for the time being though, just as long as it doesn't crash the app. If the reason for channels not working is a result of being on macOS then I'm fine with that. |
Sorry but I'm not really tracking this project issue and have no idea what kind of issue the "channels" stuff is. If there is something reproducible at my side let me know and I might be able to help. |
Updated according to feedback, there's a few things I want to mention:
|
The way you've implemented it is fine :) Made one minor change to make the velocities public - may come in useful if someone's handling input manually via Thanks! |
Closes #2723.
Still WIP, uses managed-midi for cross-platform MIDI input.
Remaining issues:
Running status is not handled yet, which is used by Linux when multiple keys are pressed at once.Linux midi input stops when too many keys are pressed at onceDisconnecting a device on Windows throws an unhandled exception (Exception on device disconnect on Windows atsushieno/managed-midi#49)Does not yet take velocity into accountTested on: