[vlc-devel] Added hotkey to cycle through audio devices

Jean-Baptiste Kempf jb at videolan.org
Mon Mar 24 07:13:01 CET 2008


On Mon, Mar 24, 2008, Dylan Yudaken wrote :
> I wrote a small patch to add a hotkey to VLC to cycle through the audio 
> devices.
> It could be useful if you run VLC on a tv and need to remotely switch
> between them.
OK.

> @@ -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

Why 103 and not 96 ?

> @@ -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 */

Could you keep some correct code alignment please ?


> +#   define KEY_AUDIODEVICE_CYCLE  KEY_MODIFIER_SHIFT|'s'
What is the rationnal of using shift+s for that ?


> +	//Dylan test
Remove this

Else, it should be ok.

-- 
Jean-Baptiste Kempf
http://www.jbkempf.com/



More information about the vlc-devel mailing list