Skip to content
Snippets Groups Projects
Commit ba3c76f9 authored by Albert Gräf's avatar Albert Gräf
Browse files

Keep track of the actual device names in the MIDI prefs.

This adds new midiindevname and midioutdevname keys to the preferences,
which enables us to remap device indices on the fly at startup in case
the device list has changed during invocations. (Which happens a lot, in
particular, with the portmidi backend, due to MIDI devices being plugged
and unplugged, change of virtual MIDI devices, etc.)

Note that this doesn't provide hotplugging support, which is really what
we'd like to have, but is currently impossible due to backend
limitations. But at least Purr Data will not connect to the wrong
devices on relaunch any more, which previously was a major annoyance.
parent 786f9618
No related branches found
No related tags found
1 merge request!843Keep track of the actual device names in the audio and MIDI prefs
...@@ -609,6 +609,14 @@ void sys_loadpreferences( void) ...@@ -609,6 +609,14 @@ void sys_loadpreferences( void)
break; break;
if (sscanf(prefbuf, "%d", &midiindev[i]) < 1) if (sscanf(prefbuf, "%d", &midiindev[i]) < 1)
break; break;
/* AG: If we have a name for the device, find the proper device
index in case that there was a change to the device list
between invocations. */
sprintf(keybuf, "midiindevname%d", i+1);
if (sys_getpreference(keybuf, prefbuf, MAXPDSTRING)) {
int d = sys_mididevnametonumber(0, prefbuf);
if (d >= 0) midiindev[i] = d;
}
nmidiindev++; nmidiindev++;
} }
} }
...@@ -630,6 +638,14 @@ void sys_loadpreferences( void) ...@@ -630,6 +638,14 @@ void sys_loadpreferences( void)
break; break;
if (sscanf(prefbuf, "%d", &midioutdev[i]) < 1) if (sscanf(prefbuf, "%d", &midioutdev[i]) < 1)
break; break;
/* AG: If we have a name for the device, find the proper device
index in case that there was a change to the device list
between invocations. */
sprintf(keybuf, "midioutdevname%d", i+1);
if (sys_getpreference(keybuf, prefbuf, MAXPDSTRING)) {
int d = sys_mididevnametonumber(1, prefbuf);
if (d >= 0) midioutdev[i] = d;
}
nmidioutdev++; nmidioutdev++;
} }
} }
...@@ -788,6 +804,14 @@ void glob_savepreferences(t_pd *dummy) ...@@ -788,6 +804,14 @@ void glob_savepreferences(t_pd *dummy)
sprintf(buf1, "midiindev%d", i+1); sprintf(buf1, "midiindev%d", i+1);
sprintf(buf2, "%d", midiindev[i]); sprintf(buf2, "%d", midiindev[i]);
sys_putpreference(buf1, buf2); sys_putpreference(buf1, buf2);
/* AG: If we have a name for the device, store it with the device
index, so that we can find the proper device index after a change
to the device list between invocations. */
sys_mididevnumbertoname(0, midiindev[i], buf2, MAXPDSTRING);
if (*buf2) {
sprintf(buf1, "midiindevname%d", i+1);
sys_putpreference(buf1, buf2);
}
} }
sys_putpreference("nomidiout", (nmidioutdev <= 0 ? "True" : "False")); sys_putpreference("nomidiout", (nmidioutdev <= 0 ? "True" : "False"));
/* AG: nmidiout */ /* AG: nmidiout */
...@@ -798,6 +822,14 @@ void glob_savepreferences(t_pd *dummy) ...@@ -798,6 +822,14 @@ void glob_savepreferences(t_pd *dummy)
sprintf(buf1, "midioutdev%d", i+1); sprintf(buf1, "midioutdev%d", i+1);
sprintf(buf2, "%d", midioutdev[i]); sprintf(buf2, "%d", midioutdev[i]);
sys_putpreference(buf1, buf2); sys_putpreference(buf1, buf2);
/* AG: If we have a name for the device, store it with the device
index, so that we can find the proper device index after a change
to the device list between invocations. */
sys_mididevnumbertoname(1, midioutdev[i], buf2, MAXPDSTRING);
if (*buf2) {
sprintf(buf1, "midioutdevname%d", i+1);
sys_putpreference(buf1, buf2);
}
} }
/* file search path */ /* file search path */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment