From 2db4e71b6693f47f2fc48c78e8cff5e570c1f8d1 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Tue, 27 Jul 2010 13:01:10 +0000 Subject: ALSA: Simplify device querying code. Thanks to eriktorbjorn for some quick testing. svn-id: r51366 --- backends/midi/alsa.cpp | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'backends') diff --git a/backends/midi/alsa.cpp b/backends/midi/alsa.cpp index a895ef8b80..1f7f7d2ba3 100644 --- a/backends/midi/alsa.cpp +++ b/backends/midi/alsa.cpp @@ -314,46 +314,41 @@ AlsaDevices AlsaMusicPlugin::getAlsaDevices() const { MusicDevices AlsaMusicPlugin::getDevices() const { MusicDevices devices; - Common::Array used; AlsaDevices::iterator d; - int i; AlsaDevices alsaDevices = getAlsaDevices(); - for (i = 0, d = alsaDevices.begin(); d != alsaDevices.end(); ++i, ++d) { - used.push_back(false); - } - // Since the default behaviour is to use the first device in the list, // try to put something sensible there. We used to have 17:0 and 65:0 // as defaults. - for (i = 0, d = alsaDevices.begin(); d != alsaDevices.end(); ++i, ++d) { - int client = d->getClient(); + for (d = alsaDevices.begin(); d != alsaDevices.end();) { + const int client = d->getClient(); + if (client == 17 || client == 65) { devices.push_back(MusicDevice(this, d->getName(), d->getType())); - used[i] = true; + d = alsaDevices.erase(d); + } else { + ++d; } } // 128:0 is probably TiMidity, or something like that, so that's // probably a good second choice. - for (i = 0, d = alsaDevices.begin(); d != alsaDevices.end(); ++i, ++d) { + for (d = alsaDevices.begin(); d != alsaDevices.end();) { if (d->getClient() == 128) { devices.push_back(MusicDevice(this, d->getName(), d->getType())); - used[i] = true; + d = alsaDevices.erase(d); + } else { + ++d; } } // Add the remaining devices in the order they were found. - for (i = 0, d = alsaDevices.begin(); d != alsaDevices.end(); ++i, ++d) { - - if (!used[i]) { - devices.push_back(MusicDevice(this, d->getName(), d->getType())); - } - } + for (d = alsaDevices.begin(); d != alsaDevices.end(); ++d) + devices.push_back(MusicDevice(this, d->getName(), d->getType())); return devices; } -- cgit v1.2.3