>From ffa42e0d73825a26ce523f4923867396126114f4 Mon Sep 17 00:00:00 2001
From: dylan <dylan@toast.(none)>
Date: Wed, 19 Mar 2008 19:15:05 +0200
Subject: [PATCH] Change to include hotkey to cycle through audio devices

---
 include/vlc_keys.h        |    1 +
 modules/control/hotkeys.c |   69 ++++++++++++++++++++++++++++++++++++++------
 src/libvlc-module.c       |    8 +++++
 3 files changed, 68 insertions(+), 10 deletions(-)

diff --git a/include/vlc_keys.h b/include/vlc_keys.h
index cce28fc..3ddf481 100644
--- a/include/vlc_keys.h
+++ b/include/vlc_keys.h
@@ -335,4 +335,5 @@ static inline int StringToKey( char *psz_key )
 #define ACTIONID_ZOOM_ORIGINAL         94
 #define ACTIONID_ZOOM_DOUBLE           95
 
+#define ACTIONID_AUDIODEVICE_CYCLE     103
 #endif
diff --git a/modules/control/hotkeys.c b/modules/control/hotkeys.c
index 23242a4..2df2d1e 100644
--- a/modules/control/hotkeys.c
+++ b/modules/control/hotkeys.c
@@ -626,19 +626,67 @@ static void Run( intf_thread_t *p_intf )
                 }
                 free( val.psz_string );
             }
-            else if( ( i_action == ACTIONID_ZOOM || i_action == ACTIONID_UNZOOM ) && p_vout )
-            {
-                vlc_value_t val={0}, val_list, text_list;
-                var_Get( p_vout, "zoom", &val );
-                if( var_Change( p_vout, "zoom", VLC_VAR_GETLIST,
-                                &val_list, &text_list ) >= 0 )
+            else if( i_action == ACTIONID_AUDIODEVICE_CYCLE && p_vout)
+	      {
+		vlc_value_t val, list, list2;
+		int i_count, i;
+		aout_instance_t *p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE );
+                var_Get( p_aout, "audio-device", &val );
+                var_Change( p_aout, "audio-device", VLC_VAR_GETCHOICES,
+		          &list, &list2 );
+                i_count = list.p_list->i_count;
+                if( i_count <= 1 )
                 {
-                    int i;
-                    for( i = 0; i < val_list.p_list->i_count; i++ )
+                    continue;
+                }
+                for( i = 1; i < i_count; i++ )
+                {
+                    if( val.i_int == list.p_list->p_values[i].i_int )
                     {
-                        if( val_list.p_list->p_values[i].f_float
+                        break;
+                    }
+                }
+                if( i == i_count )
+                {
+                    msg_Warn( p_aout,
+                              "invalid current audio device, selecting 0" );
+		      var_Set( p_aout, "audio-device",
+                             list.p_list->p_values[1] );
+                    i = 1;
+		    
+                }
+                else if( i == i_count -1 )
+                {
+		  var_Set( p_aout, "audio-device",
+		          list.p_list->p_values[0] );
+                    i = 0;
+		    
+                }
+                else
+                {
+		  var_Set( p_aout, "audio-device",
+		           list.p_list->p_values[i+1] );
+                    i++;
+	     
+                }
+                vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
+		                _("Audio Device: %s"),
+				 list2.p_list->p_values[i].psz_string );
+	    
+	}
+	else if( ( i_action == ACTIONID_ZOOM || i_action == ACTIONID_UNZOOM ) && p_vout )
+	  {
+	    vlc_value_t val={0}, val_list, text_list;
+	    var_Get( p_vout, "zoom", &val );
+	    if( var_Change( p_vout, "zoom", VLC_VAR_GETLIST,
+                                &val_list, &text_list ) >= 0 )
+	      {
+		int i;
+		for( i = 0; i < val_list.p_list->i_count; i++ )
+		  {
+		    if( val_list.p_list->p_values[i].f_float
                            == val.f_float )
-                        {
+		      {
                             if( i_action == ACTIONID_ZOOM )
                                 i++;
                             else /* ACTIONID_UNZOOM */
@@ -809,6 +857,7 @@ static void Run( intf_thread_t *p_intf )
             {
                 osd_MenuActivate( VLC_OBJECT(p_intf) );
             }
+			
         }
         if( p_vout )
             vlc_object_release( p_vout );
diff --git a/src/libvlc-module.c b/src/libvlc-module.c
index e01b822..7784702 100644
--- a/src/libvlc-module.c
+++ b/src/libvlc-module.c
@@ -1350,6 +1350,8 @@ static const char *ppsz_pltree_descriptions[] = { N_("Default"), N_("Always"), N
 #define MENU_SELECT_KEY_LONGTEXT N_( \
         "Selecting current widget performs the associated action.")
 
+#define AUDI_DEVICE_CYCLE_KEY_TEXT N_("Cycle through audio devices")
+#define AUDI_DEVICE_CYCLE_KEY_LONGTEXT N_("Cycle through audio devices")
 const char vlc_usage[] = N_(
     "Usage: %s [options] [stream] ..."
     "\nYou can specify multiple streams on the commandline. They will be enqueued in the playlist."
@@ -2175,6 +2177,7 @@ vlc_module_begin();
 #   define KEY_MENU_UP            KEY_MODIFIER_ALT|KEY_MODIFIER_SHIFT|KEY_UP
 #   define KEY_MENU_DOWN          KEY_MODIFIER_ALT|KEY_MODIFIER_SHIFT|KEY_DOWN
 #   define KEY_MENU_SELECT        KEY_MODIFIER_ALT|KEY_MODIFIER_SHIFT|KEY_ENTER
+#   define KEY_AUDIODEVICE_CYCLE  KEY_MODIFIER_SHIFT|'s'
 #endif
 
     add_key( "key-toggle-fullscreen", KEY_TOGGLE_FULLSCREEN, NULL, TOGGLE_FULLSCREEN_KEY_TEXT,
@@ -2384,6 +2387,10 @@ vlc_module_begin();
     add_key( "key-play-bookmark10", KEY_PLAY_BOOKMARK10, NULL,
              PLAY_BOOKMARK10_KEY_TEXT, PLAY_BOOKMARK_KEY_LONGTEXT, VLC_TRUE );
 
+	//Dylan test
+	add_key( "key-audiodevice-cycle", KEY_STOP, NULL, AUDI_DEVICE_CYCLE_KEY_TEXT,
+             AUDI_DEVICE_CYCLE_KEY_LONGTEXT, VLC_FALSE );
+
 
     add_string( "bookmark1", NULL, NULL,
              BOOKMARK1_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
@@ -2588,6 +2595,7 @@ const struct hotkey libvlc_hotkeys[] =
     { "key-menu-up", ACTIONID_MENU_UP, 0, 0, 0, 0 },
     { "key-menu-down", ACTIONID_MENU_DOWN, 0, 0, 0, 0 },
     { "key-menu-select", ACTIONID_MENU_SELECT, 0, 0, 0, 0 },
+	{ "key-audiodevice-cycle", ACTIONID_AUDIODEVICE_CYCLE, 0, 0, 0, 0 },
     { NULL, 0, 0, 0, 0, 0 }
 };
 
-- 
1.5.2.5


