Fix up device preferences
This hopefully fixes #213 (closed). While I was at it, I also grabbed commit 516eba76 from vanilla which adds the missing midiapi setting to the preferences.
The idea is to get rid of zombie audio and MIDI device entries by adding the actual numbers of device entries to the config information. The new keys are optional to retain full backward compatibility (i.e., the case that the new device counts are not in the config is handled gracefully). Tested on Linux, which doesn't actually have this bug, but I checked that all the device counts are recorded properly. Still needs testing on Mac and Windows.