]> git.sesse.net Git - vlc/blobdiff - modules/control/hotkeys.c
Add hotkey to cycle through program SIDs.
[vlc] / modules / control / hotkeys.c
index 5a0664946c1b45ca622c83052e7ec82c9afb1dea..25af282ad4e838a8b6473165e2533a09352787f1 100644 (file)
@@ -35,7 +35,7 @@
 #include <vlc_interface.h>
 #include <vlc_input.h>
 #include <vlc_vout.h>
-#include <vlc_aout.h>
+#include <vlc_aout_intf.h>
 #include <vlc_osd.h>
 #include <vlc_playlist.h>
 #include <vlc_keys.h>
@@ -70,13 +70,13 @@ static int  SpecialKeyEvent( vlc_object_t *, char const *,
 static void PlayBookmark( intf_thread_t *, int );
 static void SetBookmark ( intf_thread_t *, int );
 static void DisplayPosition( intf_thread_t *, vout_thread_t *, input_thread_t * );
-static void DisplayVolume  ( intf_thread_t *, vout_thread_t *, audio_volume_t );
+static void DisplayVolume( intf_thread_t *, vout_thread_t *, float );
 static void DisplayRate ( vout_thread_t *, float );
 static float AdjustRateFine( input_thread_t *, const int );
 static void ClearChannels  ( intf_thread_t *, vout_thread_t * );
 
-#define DisplayMessage(vout, fmt, ...) \
-    do { if(vout) vout_OSDMessage(vout, fmt, __VA_ARGS__); } while(0)
+#define DisplayMessage(vout, ch, fmt, ...) \
+    do { if(vout) vout_OSDMessage(vout, ch, fmt, __VA_ARGS__); } while(0)
 #define DisplayIcon(vout, icon) \
     do { if(vout) vout_OSDIcon(vout, SPU_DEFAULT_CHANNEL, icon); } while(0)
 
@@ -104,11 +104,11 @@ vlc_module_begin ()
     set_category( CAT_INTERFACE )
     set_subcategory( SUBCAT_INTERFACE_HOTKEYS )
 
-    add_integer( "hotkeys-mousewheel-mode", MOUSEWHEEL_VOLUME, NULL,
-                 N_("MouseWheel x-axis Control"),
-                 N_("MouseWheel x-axis can control volume, position or "
+    add_integer( "hotkeys-mousewheel-mode", MOUSEWHEEL_VOLUME,
+                 N_("MouseWheel up-down axis Control"),
+                 N_("The MouseWheel up-down (vertical) axis can control volume, position or "
                     "mousewheel event can be ignored"), false )
-            change_integer_list( i_mode_list, psz_mode_list_text, NULL )
+            change_integer_list( i_mode_list, psz_mode_list_text )
 
 vlc_module_end ()
 
@@ -162,7 +162,7 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
     vout_thread_t *p_vout = p_input ? input_GetVout( p_input ) : NULL;
 
     /* Update the aout */
-    aout_instance_t *p_aout = p_input ? input_GetAout( p_input ) : NULL;
+    vlc_object_t *p_aout = p_input ? (vlc_object_t *)input_GetAout( p_input ) : NULL;
 
     /* Register OSD channels */
     /* FIXME: this check can fail if the new vout is reallocated at the same
@@ -186,44 +186,42 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
         /* Volume and audio actions */
         case ACTIONID_VOL_UP:
         {
-            audio_volume_t i_newvol;
-            aout_VolumeUp( p_playlist, 1, &i_newvol );
-            DisplayVolume( p_intf, p_vout, i_newvol );
+            float vol;
+            if( aout_VolumeUp( p_playlist, 1, &vol ) == 0 )
+                DisplayVolume( p_intf, p_vout, vol );
             break;
         }
 
         case ACTIONID_VOL_DOWN:
         {
-            audio_volume_t i_newvol;
-            aout_VolumeDown( p_playlist, 1, &i_newvol );
-            DisplayVolume( p_intf, p_vout, i_newvol );
+            float vol;
+            if( aout_VolumeDown( p_playlist, 1, &vol ) == 0 )
+                DisplayVolume( p_intf, p_vout, vol );
             break;
         }
 
         case ACTIONID_VOL_MUTE:
-        {
-            audio_volume_t i_newvol = -1;
-            aout_ToggleMute( p_playlist, &i_newvol );
-            if( p_vout )
+            if( aout_MuteToggle( p_playlist ) == 0 )
             {
-                if( i_newvol == 0 )
+                float vol = aout_VolumeGet( p_playlist );
+                if( aout_MuteGet( p_playlist ) > 0 || vol == 0.f )
                 {
                     ClearChannels( p_intf, p_vout );
                     DisplayIcon( p_vout, OSD_MUTE_ICON );
                 }
                 else
-                    DisplayVolume( p_intf, p_vout, i_newvol );
+                    DisplayVolume( p_intf, p_vout, vol );
             }
             break;
-        }
 
         /* Interface showing */
-        case ACTIONID_INTF_SHOW:
-            var_SetBool( p_intf->p_libvlc, "intf-show", true );
+        case ACTIONID_INTF_TOGGLE_FSC:
+        case ACTIONID_INTF_HIDE:
+            var_TriggerCallback( p_intf->p_libvlc, "intf-toggle-fscontrol" );
             break;
 
-        case ACTIONID_INTF_HIDE:
-            var_SetBool( p_intf->p_libvlc, "intf-show", false );
+        case ACTIONID_INTF_BOSS:
+            var_TriggerCallback( p_intf->p_libvlc, "intf-boss" );
             break;
 
         /* Video Output actions */
@@ -300,17 +298,8 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
                 ClearChannels( p_intf, p_vout );
 
                 int state = var_GetInteger( p_input, "state" );
-                if( state != PAUSE_S )
-                {
-                    DisplayIcon( p_vout, OSD_PAUSE_ICON );
-                    state = PAUSE_S;
-                }
-                else
-                {
-                    DisplayIcon( p_vout, OSD_PLAY_ICON );
-                    state = PLAYING_S;
-                }
-                var_SetInteger( p_input, "state", state );
+                DisplayIcon( p_vout, state != PAUSE_S ? OSD_PAUSE_ICON : OSD_PLAY_ICON );
+                playlist_Pause( p_playlist );
             }
             else
                 playlist_Play( p_playlist );
@@ -512,6 +501,46 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
                                 list2.p_list->p_values[i].psz_string );
                 var_FreeList( &list, &list2 );
             }
+            else if( i_action == ACTIONID_PROGRAM_SID )
+            {
+                vlc_value_t val, list, list2;
+                int i_count, i;
+                var_Get( p_input, "program", &val );
+
+                var_Change( p_input, "program", VLC_VAR_GETCHOICES,
+                            &list, &list2 );
+                i_count = list.p_list->i_count;
+                if( i_count <= 1 )
+                {
+                    DisplayMessage( p_vout, SPU_DEFAULT_CHANNEL,
+                                    _("Program Service ID: %s"), _("N/A") );
+                    var_FreeList( &list, &list2 );
+                    goto cleanup_and_continue;
+                }
+                for( i = 0; i < i_count; i++ )
+                {
+                    if( val.i_int == list.p_list->p_values[i].i_int )
+                    {
+                        break;
+                    }
+                }
+                /* value of program was not in choices list */
+                if( i == i_count )
+                {
+                    msg_Warn( p_input,
+                              "invalid current program SID, selecting 0" );
+                    i = 0;
+                }
+                else if( i == i_count - 1 )
+                    i = 0;
+                else
+                    i++;
+                var_Set( p_input, "program", list.p_list->p_values[i] );
+                DisplayMessage( p_vout, SPU_DEFAULT_CHANNEL,
+                                _("Program Service ID: %s"),
+                                list2.p_list->p_values[i].psz_string );
+                var_FreeList( &list, &list2 );
+            }
             else if( i_action == ACTIONID_ASPECT_RATIO && p_vout )
             {
                 vlc_value_t val={0}, val_list, text_list;
@@ -713,18 +742,17 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
             }
             else if( i_action == ACTIONID_RATE_NORMAL )
             {
-                var_SetFloat( p_input, "rate", 1. );
-                DisplayMessage( p_vout, SPU_DEFAULT_CHANNEL,
-                                "%s", _("1.00x") );
+                var_SetFloat( p_playlist, "rate", 1. );
+                DisplayRate( p_vout, var_GetFloat( p_input, "rate" ) );
             }
             else if( i_action == ACTIONID_FASTER )
             {
-                var_TriggerCallback( p_input, "rate-faster" );
+                var_TriggerCallback( p_playlist, "rate-faster" );
                 DisplayRate( p_vout, var_GetFloat( p_input, "rate" ) );
             }
             else if( i_action == ACTIONID_SLOWER )
             {
-                var_TriggerCallback( p_input, "rate-slower" );
+                var_TriggerCallback( p_playlist, "rate-slower" );
                 DisplayRate( p_vout, var_GetFloat( p_input, "rate" ) );
             }
             else if( i_action == ACTIONID_RATE_FASTER_FINE ||
@@ -733,7 +761,7 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
                 const int i_dir = i_action == ACTIONID_RATE_FASTER_FINE ? 1 : -1;
                 float f_newrate = AdjustRateFine( p_input, i_dir );
 
-                var_SetFloat( p_input, "rate", f_newrate );
+                var_SetFloat( p_playlist, "rate", f_newrate );
                 DisplayRate( p_vout, f_newrate );
             }
             else if( i_action == ACTIONID_POSITION )
@@ -963,22 +991,26 @@ static void PlayBookmark( intf_thread_t *p_intf, int i_num )
 static void SetBookmark( intf_thread_t *p_intf, int i_num )
 {
     char *psz_bookmark_name;
+    char *psz_uri = NULL;
     if( asprintf( &psz_bookmark_name, "bookmark%i", i_num ) == -1 )
         return;
 
     playlist_t *p_playlist = pl_Get( p_intf );
     var_Create( p_intf, psz_bookmark_name,
                 VLC_VAR_STRING|VLC_VAR_DOINHERIT );
+
+    PL_LOCK;
     playlist_item_t * p_item = playlist_CurrentPlayingItem( p_playlist );
+    if( p_item ) psz_uri = input_item_GetURI( p_item->p_input );
+    PL_UNLOCK;
+
     if( p_item )
     {
-        char *psz_uri = input_item_GetURI( p_item->p_input );
         config_PutPsz( p_intf, psz_bookmark_name, psz_uri);
         msg_Info( p_intf, "setting playlist bookmark %i to %s", i_num, psz_uri);
-        free( psz_uri );
-        config_SaveConfigFile( p_intf, "hotkeys" );
     }
 
+    free( psz_uri );
     free( psz_bookmark_name );
 }
 
@@ -1019,24 +1051,17 @@ static void DisplayPosition( intf_thread_t *p_intf, vout_thread_t *p_vout,
 }
 
 static void DisplayVolume( intf_thread_t *p_intf, vout_thread_t *p_vout,
-                           audio_volume_t i_vol )
+                           float vol )
 {
     if( p_vout == NULL )
-    {
         return;
-    }
     ClearChannels( p_intf, p_vout );
 
     if( var_GetBool( p_vout, "fullscreen" ) )
-    {
-        vout_OSDSlider( p_vout, VOLUME_WIDGET_CHAN,
-            i_vol*100/AOUT_VOLUME_MAX, OSD_VERT_SLIDER );
-    }
-    else
-    {
-        DisplayMessage( p_vout, VOLUME_TEXT_CHAN, _( "Volume %d%%" ),
-                        i_vol*400/AOUT_VOLUME_MAX );
-    }
+        vout_OSDSlider( p_vout, VOLUME_WIDGET_CHAN, lround(vol * 100.),
+                        OSD_VERT_SLIDER );
+    DisplayMessage( p_vout, VOLUME_TEXT_CHAN, _( "Volume %ld%%" ),
+                    lround(vol * 100.) );
 }
 
 static void DisplayRate( vout_thread_t *p_vout, float f_rate )