Skip to content

Commit

Permalink
Virtual port switch
Browse files Browse the repository at this point in the history
  • Loading branch information
fred-dev committed Sep 28, 2023
1 parent 47c0c21 commit b8b73cb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 26 deletions.
Binary file not shown.
9 changes: 4 additions & 5 deletions bin/data/MIDI_OSC_SETTINGS.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"Euphonix MIDI Euphonix Port 1",
"Euphonix MIDI Euphonix Port 2",
"Euphonix MIDI Euphonix Port 3",
"Euphonix MIDI Euphonix Port 4",
"OSC_MIDI_OSC_OUT"
"Euphonix MIDI Euphonix Port 4"
],
"midiOutChannel": 1,
"midiOutDevice": 9,
Expand All @@ -19,9 +18,9 @@
"Euphonix MIDI Euphonix Port 1",
"Euphonix MIDI Euphonix Port 2",
"Euphonix MIDI Euphonix Port 3",
"Euphonix MIDI Euphonix Port 4",
"OSC_MIDI_OSC_IN"
"Euphonix MIDI Euphonix Port 4"
],
"outGoingPortOsc": 1234,
"outgoingIpOSC": "127.0.0.1"
"outgoingIpOSC": "127.0.0.1",
"useVirtualPort": false
}
51 changes: 31 additions & 20 deletions src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ void ofApp::setup(){
ofSetLogLevel(OF_LOG_VERBOSE);
ofLogVerbose() << "Log level set to OF_LOG_VERBOSE" << endl;
}
#ifdef TARGET_OSX
if (!jsonSettings["useVirtualPort"].is_null()) {
useVirtualPort = jsonSettings["useVirtualPort"];
ofLogVerbose()<<"useVirtualPort set to "<<useVirtualPort<<endl;
} else {
useVirtualPort = true;
}
#else
useVirtualPort = false;
#endif
//set the incomingPortOsc from the jsonSettings
if (!jsonSettings["incomingPortOsc"].is_null()) {
incomingPortOsc = jsonSettings["incomingPortOsc"];
Expand Down Expand Up @@ -100,29 +110,30 @@ void ofApp::setup(){

//if we are on OSX we need to set the midi port to virtual
#ifdef TARGET_OSX
midiOut.openVirtualPort("OSC_MIDI_OSC_OUT");
midiIn.openVirtualPort("OSC_MIDI_OSC_IN");
ofLogVerbose() << "Midi In Device set to OSC_MIDI_OSC_IN" << endl;
ofLogVerbose() << "Midi Out Device set to OSC_MIDI_OSC_OUT" << endl;


//if we are on windows we need to set the midi port to the selected port
#else

if (midiOutDeviceByString) {
midiIn.openPort(midiInDeviceName);
} else {
midiIn.openPort(midiInDeviceNum);
if(useVirtualPort){
midiOut.openVirtualPort("OSC_MIDI_OSC_OUT");
midiIn.openVirtualPort("OSC_MIDI_OSC_IN");
ofLogVerbose() << "Midi In Device set to OSC_MIDI_OSC_IN - Virtual port" << endl;
ofLogVerbose() << "Midi Out Device set to OSC_MIDI_OSC_OUT - Virtual port" << endl;
}
ofLogVerbose() << "Midi In Device initialised and set to port: " << midiIn.getPort() << " With name: "<< midiIn.getName() << endl;
if (midiOutDeviceByString) {
midiOut.openPort(midiOutDeviceName);
} else {
midiOut.openPort(midiOutDeviceNum);
//if we are on windows we need to set the midi port to the selected port
#endif
if(!useVirtualPort){
if (midiOutDeviceByString) {
midiIn.openPort(midiInDeviceName);
} else {
midiIn.openPort(midiInDeviceNum);
}
ofLogVerbose() << "Midi In Device initialised and set to port: " << midiIn.getPort() << " With name: "<< midiIn.getName() << endl;
if (midiOutDeviceByString) {
midiOut.openPort(midiOutDeviceName);
} else {
midiOut.openPort(midiOutDeviceNum);
}
ofLogVerbose() << "Midi Out Device initialised and set to port: " << midiOut.getPort() << " With name: " << midiOut.getName() << endl;
}
ofLogVerbose() << "Midi Out Device initialised and set to port: " << midiOut.getPort() << " With name: " << midiOut.getName() << endl;

#endif

midiIn.listInPorts();
midiOut.listOutPorts();
Expand Down
2 changes: 1 addition & 1 deletion src/ofApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ofApp : public ofBaseApp, public ofxMidiListener {
int frameRate;
int incomingPortOsc, outGoingPortOsc, midiInChannel, midiOutChannel, midiInDeviceNum, midiOutDeviceNum;
string outgoingIpOSC, midiInDeviceName, midiOutDeviceName;
bool midiInDeviceByString, midiOutDeviceByString;
bool midiInDeviceByString, midiOutDeviceByString, useVirtualPort;


};

0 comments on commit b8b73cb

Please sign in to comment.