Skip to content
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

No way to get device callbacks #91

Open
Daniel63656 opened this issue Oct 29, 2024 · 3 comments
Open

No way to get device callbacks #91

Daniel63656 opened this issue Oct 29, 2024 · 3 comments

Comments

@Daniel63656
Copy link

Daniel63656 commented Oct 29, 2024

I am trying to detect when an input device is added on android to update UI. However deviceCallback is private in AndroidMidiAccess. How is one supposed to receive these events? I tried using stateChanges but it always issues 3 changes when I plug/unplug a cable

@Daniel63656 Daniel63656 changed the title No way to get devicecallback No way to get device callbacks Oct 29, 2024
@atsushieno
Copy link
Owner

As you tried, it is implemented to invoke MidiAccess.stateChanged() event handler function (not very cool API, only one handler can be set).

It simply dispatches what Android MIDI API emits. If your Android platform emits 3 changes then you will receive 3 events. But I don't think that's the case. It is more likely that you write app in Jetpack Compose and your app triggers multiple state changes for one event. If you still have doubts in ktmidi MidiAccess implementation, maybe please give me some repro code / project so that I can investigate?

@Daniel63656
Copy link
Author

These events are fired for each port. If I connect my piano for example, 3 ports are opened, 1 input and 2 output ports, thus 3 state changes.
However one (including me) would like to know when a device has been successfully opened for example. Androids midi API provides a callback for that when calling openOutput().
I would suggest making a unified Midi access listener that receives not just on send but also these device connected/disconnected calls or alternatively a separate listener just for these callbacks

@atsushieno
Copy link
Owner

Ah okay I understand what you meant. However it is not what ktmidi MidiAccess is like. It is basically following how Web MIDI API organize ports without the concept of "devices". It is by design. If you need platform specific features like this, you should directly use Android MIDI API.

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

No branches or pull requests

2 participants