sanitize MIDI port names on Windows/Linux
This commit is contained in:
parent
04bbffac13
commit
eac4f50d92
|
|
@ -21,6 +21,26 @@
|
||||||
#include "../ta-log.h"
|
#include "../ta-log.h"
|
||||||
#include "taAudio.h"
|
#include "taAudio.h"
|
||||||
|
|
||||||
|
String sanitizePortName(const String& name) {
|
||||||
|
#if defined(_WIN32)
|
||||||
|
// remove port number
|
||||||
|
size_t namePos=name.rfind(' ');
|
||||||
|
if (namePos!=String::npos) {
|
||||||
|
return name.substr(0,namePos);
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
#elif defined(__linux__)
|
||||||
|
// remove port location
|
||||||
|
size_t namePos=name.rfind(' ');
|
||||||
|
if (namePos!=String::npos) {
|
||||||
|
return name.substr(0,namePos);
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
#else
|
||||||
|
return name;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// --- IN ---
|
// --- IN ---
|
||||||
|
|
||||||
bool TAMidiInRtMidi::gather() {
|
bool TAMidiInRtMidi::gather() {
|
||||||
|
|
@ -56,7 +76,7 @@ std::vector<String> TAMidiInRtMidi::listDevices() {
|
||||||
unsigned int count=port->getPortCount();
|
unsigned int count=port->getPortCount();
|
||||||
logD("got port count.");
|
logD("got port count.");
|
||||||
for (unsigned int i=0; i<count; i++) {
|
for (unsigned int i=0; i<count; i++) {
|
||||||
String name=port->getPortName(i);
|
String name=sanitizePortName(port->getPortName(i));
|
||||||
if (name!="") ret.push_back(name);
|
if (name!="") ret.push_back(name);
|
||||||
}
|
}
|
||||||
} catch (RtMidiError& e) {
|
} catch (RtMidiError& e) {
|
||||||
|
|
@ -77,7 +97,7 @@ bool TAMidiInRtMidi::openDevice(String name) {
|
||||||
unsigned int count=port->getPortCount();
|
unsigned int count=port->getPortCount();
|
||||||
logD("finding port %s...",name);
|
logD("finding port %s...",name);
|
||||||
for (unsigned int i=0; i<count; i++) {
|
for (unsigned int i=0; i<count; i++) {
|
||||||
String portName=port->getPortName(i);
|
String portName=sanitizePortName(port->getPortName(i));
|
||||||
logV("- %d: %s",i,portName);
|
logV("- %d: %s",i,portName);
|
||||||
if (portName==name) {
|
if (portName==name) {
|
||||||
logD("opening port %d...",i);
|
logD("opening port %d...",i);
|
||||||
|
|
@ -190,7 +210,7 @@ bool TAMidiOutRtMidi::openDevice(String name) {
|
||||||
unsigned int count=port->getPortCount();
|
unsigned int count=port->getPortCount();
|
||||||
logD("finding port %s...",name);
|
logD("finding port %s...",name);
|
||||||
for (unsigned int i=0; i<count; i++) {
|
for (unsigned int i=0; i<count; i++) {
|
||||||
String portName=port->getPortName(i);
|
String portName=sanitizePortName(port->getPortName(i));
|
||||||
logV("- %d: %s",i,portName);
|
logV("- %d: %s",i,portName);
|
||||||
if (portName==name) {
|
if (portName==name) {
|
||||||
logD("opening port %d...",i);
|
logD("opening port %d...",i);
|
||||||
|
|
@ -230,7 +250,7 @@ std::vector<String> TAMidiOutRtMidi::listDevices() {
|
||||||
try {
|
try {
|
||||||
unsigned int count=port->getPortCount();
|
unsigned int count=port->getPortCount();
|
||||||
for (unsigned int i=0; i<count; i++) {
|
for (unsigned int i=0; i<count; i++) {
|
||||||
String name=port->getPortName(i);
|
String name=sanitizePortName(port->getPortName(i));
|
||||||
if (name!="") ret.push_back(name);
|
if (name!="") ret.push_back(name);
|
||||||
}
|
}
|
||||||
} catch (RtMidiError& e) {
|
} catch (RtMidiError& e) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue