Skip to content
This repository has been archived by the owner on Nov 12, 2023. It is now read-only.

Receiving midi data results in an error #1

Open
ghost23 opened this issue Apr 10, 2021 · 5 comments
Open

Receiving midi data results in an error #1

ghost23 opened this issue Apr 10, 2021 · 5 comments

Comments

@ghost23
Copy link
Owner

ghost23 commented Apr 10, 2021

I am having issues retreiving the midi data once I am connected to a MIDI device, as discussed here: halildurmus/win32#199 (comment)

@timsneath
Copy link
Contributor

If this truly is on a different thread, then this issue is probably the one to investigate: dart-lang/sdk#37022

A solution proposed here is to write a very small stub in C++ that uses Dart's native ports functionality. In theory, this small stub could be written in the Windows runner (i.e. windows_midi\windows\runner\main.cpp).

@timsneath
Copy link
Contributor

Here's a Go example of receiving async data from another thread: https://github.com/mraleph/go_dart_ffi_example

@ghost23
Copy link
Owner Author

ghost23 commented Apr 11, 2021

I also found this example for C++: https://github.com/mikeperri/flutter-native-callbacks-example

I must admit, I do not completely understand everything in there. But wouldn't this be something that would need to be implemented on your Win32 side? It seems to me that the async part is quite strongly connected with the actual calling of the native c++ functionality. Or am I getting this wrong?

@ghost23
Copy link
Owner Author

ghost23 commented Apr 11, 2021

For example, if we consider the method startWork in the Go example: https://github.com/mraleph/go_dart_ffi_example/blob/master/godart.dart#L22

to be midiInOpen in my example, then startWork is accepting a nativePort.

Similarly in the C++ example, the method method_a, which I would deem to be an equivalent of our midiInOpen is also accepting a port, in this case a Dart_Port: https://github.com/mikeperri/flutter-native-callbacks-example/blob/master/android/src/main/cpp/native_callbacks_example.cpp#L14

Yet, midiInOpen on the Dart side currently is directly expecting a pointer to a function on the Dart side instead of some sort of port.

So I am not sure, if I actually can solve this on my side.

@ghost23
Copy link
Owner Author

ghost23 commented May 8, 2021

Hi @timsneath . I finally got around in making a proof of concept to see, whether I was right about the async callback. I made a new repo for that: https://github.com/ghost23/win32_midi

If you're interested, the method in question there is Win32Midi.openMidiInput(...) in ./lib/win32_midi.dart
and its counterpart openMidiInput(...) in ./windows/win32_midi_plugin.cpp, which is taking
an async callback.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants