From 4933586ef7d5faceebe4666a8ec4c90a5bb35943 Mon Sep 17 00:00:00 2001
From: kevin <kpl@larke.org>
Date: Tue, 26 Mar 2013 12:37:17 -0700
Subject: [PATCH] cmAudioPort.h/c: Added cmApDeviceLabelToIndex().

---
 cmAudioPort.c | 16 +++++++++++++++-
 cmAudioPort.h |  3 +++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/cmAudioPort.c b/cmAudioPort.c
index 57080cf..672ba0d 100644
--- a/cmAudioPort.c
+++ b/cmAudioPort.c
@@ -202,7 +202,7 @@ cmApRC_t      cmApFinalize()
 unsigned cmApDeviceCount()
 { return _ap->devCnt; }
 
-const char*   cmApDeviceLabel(          unsigned devIdx )
+const char*   cmApDeviceLabel( unsigned devIdx )
 {
   cmApDriver_t* dp;
   unsigned      di;
@@ -217,6 +217,20 @@ const char*   cmApDeviceLabel(          unsigned devIdx )
   return dp->deviceLabel(di);
 }
 
+unsigned      cmApDeviceLabelToIndex( const cmChar_t* label )
+{
+  unsigned n = cmApDeviceCount();
+  unsigned i;
+  for(i=0; i<n; ++i)
+  {
+    const cmChar_t* s = cmApDeviceLabel(i);
+    if( s!=NULL && strcmp(s,label)==0)
+      return i;
+  }
+  return cmInvalidIdx;
+}
+
+
 unsigned      cmApDeviceChannelCount(   unsigned devIdx, bool inputFl )
 {
   cmApDriver_t* dp;
diff --git a/cmAudioPort.h b/cmAudioPort.h
index 187d283..d146ea1 100644
--- a/cmAudioPort.h
+++ b/cmAudioPort.h
@@ -95,6 +95,9 @@ extern "C" {
   /// Get a textual description of the device at index 'devIdx'.
   const char*   cmApDeviceLabel(          unsigned devIdx );
 
+  /// Given an audio device label return the associated device index.
+  unsigned      cmApDeviceLabelToIndex( const cmChar_t* label );
+
   /// Get the count of audio input or output channesl on device at index 'devIdx'.
   unsigned      cmApDeviceChannelCount(   unsigned devIdx, bool inputFl );