# HG changeset patch # User giacomo # Date 1141087922 28800 # Node ID 8efa4b799c1973a778438ff01ac6243f10f2a3ec # Parent 113f66421a627cc4f99b3df639940f0fd02314b9 [svn] Added a get_volume plugin function, to ensure that the player volume is properly updated when the player is remotely controlled diff -r 113f66421a62 -r 8efa4b799c19 Plugins/Input/amidi-plug/amidi-plug.c --- a/Plugins/Input/amidi-plug/amidi-plug.c Mon Feb 27 16:51:14 2006 -0800 +++ b/Plugins/Input/amidi-plug/amidi-plug.c Mon Feb 27 16:52:02 2006 -0800 @@ -258,6 +258,17 @@ } +static void amidiplug_get_volume( gint * l , gint * r ) +{ + gchar mixer_card[10]; + snprintf( mixer_card , 8 , "hw:%i" , amidiplug_cfg.mixer_card_id ); + mixer_card[9] = '\0'; + /* get volume */ + i_seq_mixer_get_volume( l , r , mixer_card , amidiplug_cfg.mixer_control_name , + amidiplug_cfg.mixer_control_id ); +} + + static void amidiplug_set_volume( gint l , gint r ) { gchar mixer_card[10]; diff -r 113f66421a62 -r 8efa4b799c19 Plugins/Input/amidi-plug/amidi-plug.h --- a/Plugins/Input/amidi-plug/amidi-plug.h Mon Feb 27 16:51:14 2006 -0800 +++ b/Plugins/Input/amidi-plug/amidi-plug.h Mon Feb 27 16:52:02 2006 -0800 @@ -81,6 +81,7 @@ static void amidiplug_pause( gshort ); static void amidiplug_seek( gint ); static gint amidiplug_get_time( void ); +static void amidiplug_get_volume( gint * , gint * ); static void amidiplug_set_volume( gint , gint ); static void amidiplug_get_song_info( gchar * , gchar ** , gint * ); static void amidiplug_file_info_box( gchar * ); @@ -101,7 +102,7 @@ amidiplug_seek, /* seek */ NULL, /* set_eq */ amidiplug_get_time, /* get_time */ - NULL, /* get_volume */ + amidiplug_get_volume, /* get_volume */ amidiplug_set_volume, /* set_volume */ amidiplug_cleanup, /* cleanup */ NULL, /* get_vis_type */ diff -r 113f66421a62 -r 8efa4b799c19 Plugins/Input/amidi-plug/i_common.h --- a/Plugins/Input/amidi-plug/i_common.h Mon Feb 27 16:51:14 2006 -0800 +++ b/Plugins/Input/amidi-plug/i_common.h Mon Feb 27 16:52:02 2006 -0800 @@ -44,7 +44,7 @@ #endif /* DEBUG */ -#define AMIDIPLUG_VERSION "0.1" +#define AMIDIPLUG_VERSION "0.1a" #define PLAYER_NAME "Audacious" #define G_PATH_GET_BASENAME(x) g_path_get_basename(x) #define G_STRING_PRINTF(...) g_string_printf(__VA_ARGS__) diff -r 113f66421a62 -r 8efa4b799c19 Plugins/Input/amidi-plug/i_seq.c --- a/Plugins/Input/amidi-plug/i_seq.c Mon Feb 27 16:51:14 2006 -0800 +++ b/Plugins/Input/amidi-plug/i_seq.c Mon Feb 27 16:52:02 2006 -0800 @@ -384,6 +384,56 @@ } +gint i_seq_mixer_get_volume( gint * left_volume , gint * right_volume , + gchar * mixer_card , gchar * mixer_control_name , gint mixer_control_id ) +{ + snd_mixer_t * mixer_h; + snd_mixer_selem_id_t * mixer_selem_id; + snd_mixer_elem_t * mixer_elem; + + snd_mixer_selem_id_alloca( &mixer_selem_id ); + snd_mixer_selem_id_set_index( mixer_selem_id , mixer_control_id ); + snd_mixer_selem_id_set_name( mixer_selem_id , mixer_control_name ); + + snd_mixer_open( &mixer_h , 0 ); + snd_mixer_attach( mixer_h , mixer_card ); + snd_mixer_selem_register( mixer_h , NULL , NULL); + snd_mixer_load( mixer_h ); + + mixer_elem = snd_mixer_find_selem( mixer_h , mixer_selem_id ); + + if ( ( mixer_elem ) && ( snd_mixer_selem_has_playback_volume( mixer_elem ) ) ) + { + glong pv_min , pv_max , pv_range; + glong lc, rc; + + snd_mixer_selem_get_playback_volume_range( mixer_elem , &pv_min , &pv_max ); + pv_range = pv_max - pv_min; + if ( pv_range > 0 ) + { + if ( snd_mixer_selem_has_playback_channel( mixer_elem , SND_MIXER_SCHN_FRONT_LEFT ) ) + { + snd_mixer_selem_get_playback_volume( mixer_elem , SND_MIXER_SCHN_FRONT_LEFT , &lc ); + /* convert the range to 0-100 (for the unlucky case that pv_range is not 0-100 already) */ + *left_volume = (gint)(((lc - pv_min) * pv_range) / 100); + DEBUGMSG( "GET VOLUME requested, get left channel (%i)\n" , left_volume ); + } + if ( snd_mixer_selem_has_playback_channel( mixer_elem , SND_MIXER_SCHN_FRONT_RIGHT ) ) + { + snd_mixer_selem_get_playback_volume( mixer_elem , SND_MIXER_SCHN_FRONT_RIGHT , &rc ); + /* convert the range to 0-100 (for the unlucky case that pv_range is not 0-100 already) */ + *right_volume = (gint)(((rc - pv_min) * pv_range) / 100); + DEBUGMSG( "GET VOLUME requested, get right channel (%i)\n" , right_volume ); + } + } + } + + snd_mixer_close( mixer_h ); + /* for now, always return 1 here */ + return 1; +} + + gint i_seq_mixer_set_volume( gint left_volume , gint right_volume , gchar * mixer_card , gchar * mixer_control_name , gint mixer_control_id ) { diff -r 113f66421a62 -r 8efa4b799c19 Plugins/Input/amidi-plug/i_seq.h --- a/Plugins/Input/amidi-plug/i_seq.h Mon Feb 27 16:51:14 2006 -0800 +++ b/Plugins/Input/amidi-plug/i_seq.h Mon Feb 27 16:52:02 2006 -0800 @@ -49,6 +49,7 @@ gint i_seq_queue_create( void ); gint i_seq_queue_free( void ); gint i_seq_queue_set_tempo( gint , gint ); +gint i_seq_mixer_get_volume( gint * , gint * , gchar * , gchar * , gint ); gint i_seq_mixer_set_volume( gint , gint , gchar * , gchar * , gint ); gint i_seq_port_wparse( gchar * ); GSList * i_seq_port_get_list( void );