From 0befe5037f773200dcab4d7a576aa35c8a19f170 Mon Sep 17 00:00:00 2001 From: Giulio Moro Date: Thu, 8 Feb 2024 22:06:05 +0000 Subject: [PATCH] Midi: exists() --- libraries/Midi/Midi.cpp | 10 ++++++++++ libraries/Midi/Midi.h | 1 + 2 files changed, 11 insertions(+) diff --git a/libraries/Midi/Midi.cpp b/libraries/Midi/Midi.cpp index bdaa64fdd..22d7c5063 100644 --- a/libraries/Midi/Midi.cpp +++ b/libraries/Midi/Midi.cpp @@ -304,6 +304,16 @@ static int getPort(snd_rawmidi_t* rmidi, Midi::Port& port) { return 0; } +bool Midi::exists(const char* port) +{ + snd_rawmidi_t* d; + if(snd_rawmidi_open(&d, NULL, port, 0)) // open in + if(snd_rawmidi_open(NULL, &d, port, 0)) // open out + return false; + snd_rawmidi_close(d); + return true; +} + int Midi::readFrom(const char* port){ if(port == NULL){ port = defaultPort.c_str(); diff --git a/libraries/Midi/Midi.h b/libraries/Midi/Midi.h index d4ae89def..c5868373a 100644 --- a/libraries/Midi/Midi.h +++ b/libraries/Midi/Midi.h @@ -396,6 +396,7 @@ class Midi { const Port& getInputPort() const { return inPortFull; } const Port& getOutputPort() const { return outPortFull; } static std::vector listAllPorts(); + static bool exists(const char* port); /** * Opens all the existing MIDI ports, in the same order returned by the filesystem or Alsa. * Ports open with this method should be closed with destroyPorts()