mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-06 14:54:56 +01:00
coremidi separate ID and Name, use fixed IDs.
This commit is contained in:
parent
0cf11acc27
commit
8fd67c5a88
3 changed files with 45 additions and 20 deletions
|
|
@ -968,7 +968,7 @@ CoreAudioBackend::coremidi_rediscover()
|
|||
for (std::vector<CoreBackendPort*>::iterator it = _system_midi_out.begin (); it != _system_midi_out.end ();) {
|
||||
bool found = false;
|
||||
for (size_t i = 0; i < _midiio->n_midi_outputs(); ++i) {
|
||||
if ((*it)->name() == _midiio->port_name(i, false)) {
|
||||
if ((*it)->name() == _midiio->port_id(i, false)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
|
@ -988,7 +988,7 @@ CoreAudioBackend::coremidi_rediscover()
|
|||
for (std::vector<CoreBackendPort*>::iterator it = _system_midi_in.begin (); it != _system_midi_in.end ();) {
|
||||
bool found = false;
|
||||
for (size_t i = 0; i < _midiio->n_midi_inputs(); ++i) {
|
||||
if ((*it)->name() == _midiio->port_name(i, true)) {
|
||||
if ((*it)->name() == _midiio->port_id(i, true)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
|
@ -1006,7 +1006,7 @@ CoreAudioBackend::coremidi_rediscover()
|
|||
}
|
||||
|
||||
for (size_t i = 0; i < _midiio->n_midi_inputs(); ++i) {
|
||||
std::string name = _midiio->port_name(i, true);
|
||||
std::string name = _midiio->port_id(i, true);
|
||||
if (find_port_in(_system_midi_in, name)) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -1022,12 +1022,14 @@ CoreAudioBackend::coremidi_rediscover()
|
|||
LatencyRange lr;
|
||||
lr.min = lr.max = _samples_per_period; // TODO add per-port midi-systemic latency
|
||||
set_latency_range (p, false, lr);
|
||||
_system_midi_in.push_back(static_cast<CoreBackendPort*>(p));
|
||||
CoreBackendPort *pp = static_cast<CoreBackendPort*>(p);
|
||||
pp->set_pretty_name(_midiio->port_name(i, true));
|
||||
_system_midi_in.push_back(pp);
|
||||
_port_change_flag = true;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < _midiio->n_midi_outputs(); ++i) {
|
||||
std::string name = _midiio->port_name(i, false);
|
||||
std::string name = _midiio->port_id(i, false);
|
||||
if (find_port_in(_system_midi_out, name)) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -1043,7 +1045,9 @@ CoreAudioBackend::coremidi_rediscover()
|
|||
LatencyRange lr;
|
||||
lr.min = lr.max = _samples_per_period; // TODO add per-port midi-systemic latency
|
||||
set_latency_range (p, false, lr);
|
||||
_system_midi_out.push_back(static_cast<CoreBackendPort*>(p));
|
||||
CoreBackendPort *pp = static_cast<CoreBackendPort*>(p);
|
||||
pp->set_pretty_name(_midiio->port_name(i, false));
|
||||
_system_midi_out.push_back(pp);
|
||||
_port_change_flag = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,11 +43,11 @@ static void midiInputCallback(const MIDIPacketList *list, void *procRef, void *s
|
|||
}
|
||||
}
|
||||
|
||||
static std::string getDisplayName(MIDIObjectRef object)
|
||||
static std::string getPropertyString (MIDIObjectRef object, CFStringRef key)
|
||||
{
|
||||
CFStringRef name = nil;
|
||||
std::string rv = "";
|
||||
if (noErr == MIDIObjectGetStringProperty(object, kMIDIPropertyDisplayName, &name)) {
|
||||
if (noErr == MIDIObjectGetStringProperty(object, key, &name)) {
|
||||
const CFIndex size = CFStringGetMaximumSizeForEncoding(CFStringGetLength(name), kCFStringEncodingUTF8);
|
||||
char *tmp = (char*) malloc(size);
|
||||
if (CFStringGetCString(name, tmp, size, kCFStringEncodingUTF8)) {
|
||||
|
|
@ -59,6 +59,10 @@ static std::string getDisplayName(MIDIObjectRef object)
|
|||
return rv;
|
||||
}
|
||||
|
||||
static std::string getDisplayName (MIDIObjectRef object) {
|
||||
return getPropertyString(object, kMIDIPropertyDisplayName);
|
||||
}
|
||||
|
||||
CoreMidiIo::CoreMidiIo()
|
||||
: _midi_client (0)
|
||||
, _input_endpoints (0)
|
||||
|
|
@ -231,28 +235,44 @@ CoreMidiIo::send_event (uint32_t port, double reltime_us, const uint8_t *d, cons
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
std::string
|
||||
CoreMidiIo::port_id (uint32_t port, bool input)
|
||||
{
|
||||
std::stringstream ss;
|
||||
if (input) {
|
||||
ss << "system:midi_capture_";
|
||||
SInt32 id;
|
||||
if (noErr == MIDIObjectGetIntegerProperty(_input_endpoints[port], kMIDIPropertyUniqueID, &id)) {
|
||||
ss << (int)id;
|
||||
} else {
|
||||
ss << port;
|
||||
}
|
||||
} else {
|
||||
ss << "system:midi_playback_";
|
||||
SInt32 id;
|
||||
if (noErr == MIDIObjectGetIntegerProperty(_output_endpoints[port], kMIDIPropertyUniqueID, &id)) {
|
||||
ss << (int)id;
|
||||
} else {
|
||||
ss << port;
|
||||
}
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string
|
||||
CoreMidiIo::port_name (uint32_t port, bool input)
|
||||
{
|
||||
std::stringstream ss;
|
||||
std::string pn;
|
||||
// XXX including the number will not yield persistent port-names
|
||||
// when disconnecting devices in the middle.
|
||||
if (input) {
|
||||
ss << "system:midi_capture_" << port;
|
||||
if (port < _n_midi_in) {
|
||||
pn = getDisplayName(_input_endpoints[port]);
|
||||
return getDisplayName(_input_endpoints[port]);
|
||||
}
|
||||
} else {
|
||||
ss << "system:midi_playback_" << port;
|
||||
if (port < _n_midi_out) {
|
||||
pn = getDisplayName(_output_endpoints[port]);
|
||||
return getDisplayName(_output_endpoints[port]);
|
||||
}
|
||||
}
|
||||
if (!pn.empty()) {
|
||||
ss << " - " << pn;
|
||||
}
|
||||
return ss.str();
|
||||
return "";
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ public:
|
|||
|
||||
uint32_t n_midi_inputs (void) const { return _n_midi_in; }
|
||||
uint32_t n_midi_outputs (void) const { return _n_midi_out; }
|
||||
std::string port_id (uint32_t, bool input);
|
||||
std::string port_name (uint32_t, bool input);
|
||||
|
||||
void notify_proc (const MIDINotification *message);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue