ghost23 / windows_midi

A quick test to access windows midi data in flutter
MIT License
2 stars 0 forks source link

Receiving midi data results in an error #1

Open ghost23 opened 3 years ago

ghost23 commented 3 years ago

I am having issues retreiving the midi data once I am connected to a MIDI device, as discussed here: https://github.com/timsneath/win32/issues/199#issuecomment-817150226

timsneath commented 3 years ago

If this truly is on a different thread, then this issue is probably the one to investigate: https://github.com/dart-lang/sdk/issues/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 commented 3 years ago

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

ghost23 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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.