Skip to content

Issues with MidiCommand().connectToDevice() on Linux #141

@M0JXD

Description

@M0JXD

Hi FlutterMidiCommand Maintainers!

I'm having a couple issues with connectToDevice() on Linux. I've tried using the latest code for this and the flutter_midi_command_linux dependency instead of the pub packages and it's still the same.

My first issue is that when even when awaiting MidiCommand().connectToDevice(), the onMidiDataReceived stream is not ready to be used. Adding an awaited delay helps but does not feel like a reliable solution, e.g. if the user has a slow computer that takes longer to setup.

Here's an example of what I'm trying to do:

  void doMidiThing(MidiDevice userSelectedDevice) async {
    await MidiCommand().connectToDevice(userSelectedDevice);

    // Without this delay, the await for loop below never gets events
    // because awaiting connectToDevice() does not ensure the stream is ready to be subscribed to
    await Future.delayed(const Duration(milliseconds: 200));

    Uint8List reqCommand = getReqCommand();
    MidiCommand().sendData(reqCommand);

    // A delay here has no effect

    await for (final value in MidiCommand().onMidiDataReceived!) {
        print("Without the delay, this is never excecuted");
        // Process MIDI packets...
        condition = doThingWithPacket(value.data);
        if (condition) {
            break;
        }
    }
    MidiCommand().disconnectDevice(userSelectedDevice);
  }

I also have an issue where trying to connect a second time causes a freeze, but only in release mode.
The passed device is the same one in both calls.

When running with flutter run --release

  void doMidiThingThatIsCalledTwice(MidiDevice userSelectedDevice) async {
    print("This always prints");
    await MidiCommand().connectToDevice(userSelectedDevice);
    // connectToDevice() always causes a print of "connect to Instance of 'LinuxMidiDevice'" in both calls
    print("On the second call in release Mode, this print will not be reached and the app freezes.");
    print("In debug mode multiple calls are always fine.");
    await Future.delayed(const Duration(milliseconds: 200));  // As before

    // Do MIDI things...

    MidiCommand().disconnectDevice(userSelectedDevice);
  }

Thanks for reading and your work on this package :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions