disconnect method

void disconnect()

Implementation

void disconnect() {
  receivePort?.close();
  errorPort?.close();
  _isolate?.kill(priority: Isolate.immediate);
  _isolate = null;

  _connectedDevices.remove(hardwareId(cardId, deviceId));
  _disconnectStreamCtrl.add(this);

  var status = 0;
  if (outPort != null) {
    if ((status = alsa.snd_rawmidi_drain(outPort!.value)) < 0) {
      print('error: cannot drain out port $this ${stringFromNative(alsa.snd_strerror(status))}');
    }
    if ((status = alsa.snd_rawmidi_close(outPort!.value)) < 0) {
      print('error: cannot close out port $this ${stringFromNative(alsa.snd_strerror(status))}');
    }
    outPort = null;
  }

  if (inPort != null) {
    if ((status = alsa.snd_rawmidi_drain(inPort!.value)) < 0) {
      print('error: cannot drain in port $this ${stringFromNative(alsa.snd_strerror(status))}');
    }
    if ((status = alsa.snd_rawmidi_close(inPort!.value)) < 0) {
      print('error: cannot close in port $this ${stringFromNative(alsa.snd_strerror(status))}');
    }
    inPort = null;
  }
  connected = false;
}