--- sound_alsa.cxx.orig	2007-02-01 18:26:22.000000000 +0100
+++ sound_alsa.cxx	2007-02-01 18:26:26.000000000 +0100
@@ -130,13 +130,22 @@
 #pragma implementation "sound_alsa.h"
 
 #include "sound_alsa.h"
-
+#include "/home/jpuydt/Projets/pwlib_PNoCollisionDictionary/no_collision_dict.h"
 
 PCREATE_SOUND_PLUGIN(ALSA, PSoundChannelALSA)
 
-
-static PStringToOrdinal playback_devices;
-static PStringToOrdinal capture_devices;
+class AlsaDevice : public PObject
+{
+public:
+  AlsaDevice (PString _device)
+    : device(_device) {}
+ 
+  PString device;
+  
+};
+ 
+static PNoCollisionDictionary<AlsaDevice> playback_devices;
+static PNoCollisionDictionary<AlsaDevice> capture_devices;
 PMutex dictionaryMutex;
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -164,7 +173,6 @@
   storedPeriods = 3;
   storedSize = storedPeriods * frameBytes;
 
-  card_nr = 0;
   os_handle = NULL;
 }
 
@@ -192,12 +200,12 @@
   if (dir == Recorder) {
 
     stream = SND_PCM_STREAM_CAPTURE;
-    capture_devices = PStringToOrdinal ();
+    capture_devices.RemoveAll ();
   }
   else {
 
     stream = SND_PCM_STREAM_PLAYBACK;
-    playback_devices = PStringToOrdinal ();
+    playback_devices.RemoveAll ();
   }
 
   snd_ctl_card_info_alloca (&info);
@@ -232,9 +240,9 @@
 
           snd_card_get_name (card, &name);
           if (dir == Recorder) 
-            capture_devices.SetAt (name, card);
+            capture_devices.AddNoClash (name, new AlsaDevice ("plughw:" + PString (card)));
           else 
-            playback_devices.SetAt (name, card);
+            playback_devices.AddNoClash (name, new AlsaDevice ("plughw:" + PString (card)));
           free (name);
         }
       }
@@ -243,6 +251,16 @@
 
     snd_card_next (&card);
   }
+
+  if (dir == Recorder) {
+
+    if (capture_devices.GetSize () > 0)
+      capture_devices.AddNoClash ("Default", new AlsaDevice ("default"));
+  } else {
+
+    if (playback_devices.GetSize () > 0)
+      playback_devices.AddNoClash ("Default", new AlsaDevice ("default"));
+  }
 }
 
 
@@ -252,20 +270,10 @@
  
   UpdateDictionary (dir);
   
-  if (dir == Recorder) {
-    
-    for (PINDEX j = 0 ; j < capture_devices.GetSize () ; j++) 
-      devices += capture_devices.GetKeyAt (j);
-  }
-  else {
-
-    for (PINDEX j = 0 ; j < playback_devices.GetSize () ; j++) 
-      devices += playback_devices.GetKeyAt (j);
-  }
-
-
-  if (devices.GetSize () > 0)
-    devices += "Default";
+  if (dir == Recorder)
+    devices = capture_devices.GetKeys ();
+  else
+    devices = playback_devices.GetKeys ();
   
   return devices;
 }
@@ -287,7 +295,6 @@
                               unsigned _bitsPerSample)
 {
   PString real_device_name;
-  POrdinalKey *i = NULL;
   snd_pcm_stream_t stream;
 
   Close();
@@ -308,30 +315,14 @@
     stream = SND_PCM_STREAM_PLAYBACK;
 
   /* Open in NONBLOCK mode */
-  if (_device == "Default") {
-
-    real_device_name = "default";
-    card_nr = -2;
-  }
-  else {
-
   if ((_dir == Recorder && capture_devices.IsEmpty ())
       || (_dir == Player && playback_devices.IsEmpty ()))
     UpdateDictionary (_dir);
 
-    i = (_dir == Recorder) ? capture_devices.GetAt (_device) : playback_devices.GetAt (_device);
-
-    if (i) {
-
-      real_device_name = "plughw:" + PString (*i);
-      card_nr = *i;
-    }
-    else {
-
-      PTRACE (1, "ALSA\tDevice not found");
-      return FALSE;
-    }
-  }
+  if (_dir == Recorder)
+    real_device_name = capture_devices [_device].device;
+  else
+    real_device_name = playback_devices [_device].device;
     
   if (snd_pcm_open (&os_handle, real_device_name, stream, SND_PCM_NONBLOCK) < 0) {
 
@@ -804,7 +795,6 @@
 
   const char *play_mix_name [] = { "PCM", "Master", "Speaker", NULL };
   const char *rec_mix_name [] = { "Capture", "Mic", NULL };
-  PString card_name;
 
   long pmin = 0, pmax = 0;
   long int vol = 0;
@@ -813,11 +803,6 @@
   if (!os_handle)
     return FALSE;
 
-  if (card_nr == -2)
-    card_name = "default";
-  else
-    card_name = "hw:" + PString (card_nr);
-
   //allocate simple id
   snd_mixer_selem_id_alloca (&sid);
 
@@ -829,7 +814,7 @@
     return FALSE;
   }
 
-  if ((err = snd_mixer_attach (handle, card_name)) < 0) {
+  if ((err = snd_mixer_attach (handle, device)) < 0) {
     PTRACE (1, "alsa-control: mixer attach " << card_name << " error: " << snd_strerror(err));
     snd_mixer_close(handle);
     return FALSE;
