Skip to content

Commit

Permalink
Midi: exists()
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliomoro committed Feb 8, 2024
1 parent e16a346 commit 0befe50
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions libraries/Midi/Midi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions libraries/Midi/Midi.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ class Midi {
const Port& getInputPort() const { return inPortFull; }
const Port& getOutputPort() const { return outPortFull; }
static std::vector<Port> 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()
Expand Down

0 comments on commit 0befe50

Please sign in to comment.