Skip to content

Instantly share code, notes, and snippets.

@johnty
Last active August 29, 2015 14:12
Show Gist options
  • Save johnty/fe7948c8c92a3f78cf98 to your computer and use it in GitHub Desktop.
Save johnty/fe7948c8c92a3f78cf98 to your computer and use it in GitHub Desktop.
midi port name search/connect
int portInIndex = -1;
int portOutIndex = -1;
// print input ports to console
midiIn.listPorts(); // via instance
//ofxMidiIn::listPorts(); // via static as well
if (midiIn.getNumPorts()) {
for (int i=0; i<midiIn.getNumPorts(); i++) {
string pname = midiIn.getPortName(i);
if (ofStringTimesInString(pname, "ICubeX")) {
printf("port exists!\n");
portInIndex = i;
}
}
}
if (ofxMidiOut::getNumPorts()) {
for (int i=0; i<ofxMidiOut::getNumPorts(); i++) {
string pname = ofxMidiOut::getPortName(i);
if (ofStringTimesInString(pName, "ICubeX")) {
portOutIndex = i; //note: there is a very small chance that when using multiple digitizers
// we can have two virtual devices but the in/out port indicies are mixed up?
// this is highly unlikely due to use case scenario, but this note is left here
// just in case...
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment