Skip to content

Commit

Permalink
Checks to see if mid ports are valid
Browse files Browse the repository at this point in the history
  • Loading branch information
fred-dev committed Sep 28, 2023
1 parent b8b73cb commit 0c78690
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,44 @@ void ofApp::setup(){
#endif
if(!useVirtualPort){
if (midiOutDeviceByString) {
//check if the device name is in the list of devices and if not set to the first device
if (std::find(midiOut.getOutPortList().begin(), midiOut.getOutPortList().end(), midiOutDeviceName) != midiOut.getOutPortList().end()) {
midiOut.openPort(midiOutDeviceName);
//let the user know that the device name is not valid
ofLogVerbose() << "Midi Out Device name is not valid, setting to first device" << endl;
}
else {
midiOut.openPort(0);
}
midiIn.openPort(midiInDeviceName);
} else {
//check if the device number is possible (less than the number of devices) and if not set to the first device
if (midiOutDeviceNum > midiOut.getNumOutPorts()) {
midiOutDeviceNum = 0;
//let the user know that the device number is not valid
ofLogVerbose() << "Midi Out Device number is not valid, setting to first device" << endl;
}

midiIn.openPort(midiInDeviceNum);
}
ofLogVerbose() << "Midi In Device initialised and set to port: " << midiIn.getPort() << " With name: "<< midiIn.getName() << endl;
if (midiOutDeviceByString) {
midiOut.openPort(midiOutDeviceName);
//check if the device name is in the list of devices and if not set to the first device
if (std::find(midiOut.getOutPortList().begin(), midiOut.getOutPortList().end(), midiOutDeviceName) != midiOut.getOutPortList().end()) {
midiOut.openPort(0);
//let the user know that the device name is not valid
ofLogVerbose() << "Midi Out Device name is not valid, setting to first device" << endl;
} else {
midiOut.openPort(midiOutDeviceName);

}
} else {
//check if the device number is possible (less than the number of devices) and if not set to the first device
if (midiOutDeviceNum > midiOut.getNumOutPorts()) {
midiOutDeviceNum = 0;
//let the user know that the device number is not valid
ofLogVerbose() << "Midi Out Device number is not valid, setting to first device" << endl;
}
midiOut.openPort(midiOutDeviceNum);
}
ofLogVerbose() << "Midi Out Device initialised and set to port: " << midiOut.getPort() << " With name: " << midiOut.getName() << endl;
Expand All @@ -137,9 +167,12 @@ void ofApp::setup(){

midiIn.listInPorts();
midiOut.listOutPorts();

//save a list of midi in ports to the json file
ofLogVerbose() << "Adding Midi In Ports to json file" << endl;
jsonSettings["midiInPorts"] = midiIn.getInPortList();
//save a list of midi out ports to the json file
ofLogVerbose() << "Adding Midi Out Ports to json file" << endl;
jsonSettings["midiOutPorts"] = midiOut.getOutPortList();
//save the json file
ofSavePrettyJson("MIDI_OSC_SETTINGS.json", jsonSettings);
Expand All @@ -148,7 +181,9 @@ void ofApp::setup(){
midiIn.addListener(this);

oscSend.setup(outgoingIpOSC, outGoingPortOsc);
ofLogVerbose() << "OSC Sender initialised and set to port: " << oscSend.getPort() << " With host: " << oscSend.getHost() << endl;
receiver.setup(incomingPortOsc);
ofLogVerbose() << "OSC Receiver initialised and set to port: " << receiver.getPort() << endl;
message="No messages yet";


Expand Down

0 comments on commit 0c78690

Please sign in to comment.