[Scummvm-cvs-logs] SF.net SVN: scummvm:[51366] scummvm/trunk/backends/midi/alsa.cpp

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Tue Jul 27 15:01:11 CEST 2010


Revision: 51366
          http://scummvm.svn.sourceforge.net/scummvm/?rev=51366&view=rev
Author:   lordhoto
Date:     2010-07-27 13:01:10 +0000 (Tue, 27 Jul 2010)

Log Message:
-----------
ALSA: Simplify device querying code.

Thanks to eriktorbjorn for some quick testing.

Modified Paths:
--------------
    scummvm/trunk/backends/midi/alsa.cpp

Modified: scummvm/trunk/backends/midi/alsa.cpp
===================================================================
--- scummvm/trunk/backends/midi/alsa.cpp	2010-07-27 12:56:30 UTC (rev 51365)
+++ scummvm/trunk/backends/midi/alsa.cpp	2010-07-27 13:01:10 UTC (rev 51366)
@@ -314,47 +314,42 @@
 
 MusicDevices AlsaMusicPlugin::getDevices() const {
 	MusicDevices devices;
-	Common::Array<bool> 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) {
+	for (d = alsaDevices.begin(); d != alsaDevices.end(); ++d)
+		devices.push_back(MusicDevice(this, d->getName(), d->getType()));
 
-		if (!used[i]) {
-			devices.push_back(MusicDevice(this, d->getName(), d->getType()));
-		}
-	}
-
 	return devices;
 }
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list