disconnect method

bool disconnect()

Implementation

bool disconnect() {
  int result;
  if (_ins.length > 0) {
    result = midiInReset(hMidiInDevicePtr.value);
    if (result != 0) {
      print("RESET ERROR($result): ${midiErrorMessage(result)}");
    }

    result = midiInUnprepareHeader(
        hMidiInDevicePtr.value, _midiInHeader, sizeOf<MIDIHDR>());
    if (result != 0) {
      print("UNPREPARE ERROR($result): ${midiErrorMessage(result)}");
    }

    result = midiInStop(hMidiInDevicePtr.value);
    if (result != 0) {
      print("STOP ERROR($result): ${midiErrorMessage(result)}");
    }

    result = midiInClose(hMidiInDevicePtr.value);
    if (result != 0) {
      print("CLOSE ERROR($result): ${midiErrorMessage(result)}");
    }

    free(hMidiInDevicePtr);
  }

  if (_outs.length > 0) {
    result = midiOutClose(hMidiOutDevicePtr.value);
    if (result != 0) {
      print("OUT CLOSE ERROR($result): ${midiErrorMessage(result)}");
    }
    free(hMidiOutDevicePtr);
  }

  free(_midiInBuffer);
  free(_midiInHeader);
  free(_midiOutBuffer);
  free(_midiOutHeader);

  connected = false;
  return true;
}