[vlc-devel] commit: Added hotkeys for fine playback rate control. (Laurent Aimar )

git version control git at videolan.org
Thu Feb 26 00:06:05 CET 2009


vlc | branch: master | Laurent Aimar <fenrir at videolan.org> | Thu Feb 26 00:01:41 2009 +0100| [737137279ab992a32802ec21fac96584caf53820] | committer: Laurent Aimar 

Added hotkeys for fine playback rate control.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=737137279ab992a32802ec21fac96584caf53820
---

 include/vlc_keys.h        |    2 ++
 modules/control/hotkeys.c |   30 +++++++++++++++++++++++++++++-
 src/libvlc-module.c       |   14 ++++++++++++++
 3 files changed, 45 insertions(+), 1 deletions(-)

diff --git a/include/vlc_keys.h b/include/vlc_keys.h
index 60a3075..c39c475 100644
--- a/include/vlc_keys.h
+++ b/include/vlc_keys.h
@@ -345,6 +345,8 @@ typedef enum vlc_key {
     ACTIONID_SCALE_DOWN,
     /* */
     ACTIONID_RATE_NORMAL,
+    ACTIONID_RATE_SLOWER_FINE,
+    ACTIONID_RATE_FASTER_FINE,
 
 } vlc_key_t;
 #endif
diff --git a/modules/control/hotkeys.c b/modules/control/hotkeys.c
index c900435..473536d 100644
--- a/modules/control/hotkeys.c
+++ b/modules/control/hotkeys.c
@@ -39,6 +39,7 @@
 #include <vlc_osd.h>
 #include <vlc_playlist.h>
 #include "vlc_keys.h"
+#include "math.h"
 
 #define BUFFER_SIZE 10
 
@@ -773,7 +774,34 @@ static void Run( intf_thread_t *p_intf )
             {
                 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
-                                 _("1x") );
+                                 _("1.00x") );
+            }
+            else if( i_action == ACTIONID_RATE_FASTER_FINE ||
+                     i_action == ACTIONID_RATE_SLOWER_FINE )
+            {
+                /* The playback rate is defined by INPUT_RATE_DEFAULT / "rate"
+                 * and we want to increase/decrease it by 0.1 while making sure
+                 * that the resulting playback rate is a multiple of 0.1
+                 */
+                int i_rate = var_GetInteger( p_input, "rate" );
+                if( i_rate == 0 )
+                    i_rate = INPUT_RATE_MIN;
+                int i_sign = i_rate < 0 ? -1 : 1;
+                const int i_dir = i_action == ACTIONID_RATE_FASTER_FINE ? 1 : -1;
+
+                const double f_speed = floor( ( (double)INPUT_RATE_DEFAULT / abs(i_rate) + 0.05 ) / 0.1 + i_dir ) * 0.1;
+                if( f_speed <= (double)INPUT_RATE_DEFAULT / INPUT_RATE_MAX ) /* Needed to avoid infinity */
+                    i_rate = INPUT_RATE_MAX;
+                else
+                    i_rate = INPUT_RATE_DEFAULT / f_speed + 0.5;
+
+                i_rate = i_sign * __MIN( __MAX( i_rate, INPUT_RATE_MIN ), INPUT_RATE_MAX );
+
+                var_SetInteger( p_input, "rate", i_rate );
+
+                char psz_msg[7+1];
+                snprintf( psz_msg, sizeof(psz_msg), _("%.2fx"), (double)INPUT_RATE_DEFAULT / i_rate );
+                vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN, psz_msg );
             }
             else if( i_action == ACTIONID_POSITION && b_seekable )
             {
diff --git a/src/libvlc-module.c b/src/libvlc-module.c
index 4ee70fc..116e577 100644
--- a/src/libvlc-module.c
+++ b/src/libvlc-module.c
@@ -1217,6 +1217,10 @@ static const char *const ppsz_albumart_descriptions[] =
 #define SLOWER_KEY_LONGTEXT N_("Select the hotkey to use for slow motion playback.")
 #define RATE_NORMAL_KEY_TEXT N_("Normal rate")
 #define RATE_NORMAL_KEY_LONGTEXT N_("Select the hotkey to set the playback rate back to normal.")
+#define RATE_FASTER_FINE_KEY_TEXT N_("Faster (fine)")
+#define RATE_FASTER_FINE_KEY_LONGTEXT N_("Select the hotkey to use for fast forward playback.")
+#define RATE_SLOWER_FINE_KEY_TEXT N_("Slower (fine)")
+#define RATE_SLOWER_FINE_KEY_LONGTEXT N_("Select the hotkey to use for slow motion playback.")
 #define NEXT_KEY_TEXT N_("Next")
 #define NEXT_KEY_LONGTEXT N_("Select the hotkey to use to skip to the next item in the playlist.")
 #define PREV_KEY_TEXT N_("Previous")
@@ -2117,6 +2121,8 @@ vlc_module_begin ()
 #   define KEY_FASTER             KEY_MODIFIER_COMMAND|'='
 #   define KEY_SLOWER             KEY_MODIFIER_COMMAND|'-'
 #   define KEY_RATE_NORMAL        KEY_UNSET
+#   define KEY_RATE_FASTER_FINE   KEY_UNSET
+#   define KEY_RATE_SLOWER_FINE   KEY_UNSET
 #   define KEY_NEXT               KEY_MODIFIER_COMMAND|KEY_RIGHT
 #   define KEY_PREV               KEY_MODIFIER_COMMAND|KEY_LEFT
 #   define KEY_STOP               KEY_MODIFIER_COMMAND|'.'
@@ -2229,6 +2235,8 @@ vlc_module_begin ()
 #   define KEY_FASTER             '+'
 #   define KEY_SLOWER             '-'
 #   define KEY_RATE_NORMAL        KEY_UNSET
+#   define KEY_RATE_FASTER_FINE   KEY_UNSET
+#   define KEY_RATE_SLOWER_FINE   KEY_UNSET
 #   define KEY_NEXT               'n'
 #   define KEY_PREV               'p'
 #   define KEY_STOP               's'
@@ -2351,6 +2359,10 @@ vlc_module_begin ()
              SLOWER_KEY_LONGTEXT, false )
     add_key( "key-rate-normal", KEY_RATE_NORMAL, NULL, RATE_NORMAL_KEY_TEXT,
              RATE_NORMAL_KEY_LONGTEXT, false )
+    add_key( "key-rate-faster-fine", KEY_RATE_FASTER_FINE, NULL, RATE_FASTER_FINE_KEY_TEXT,
+             RATE_FASTER_FINE_KEY_LONGTEXT, false )
+    add_key( "key-rate-slower-fine", KEY_RATE_SLOWER_FINE, NULL, RATE_SLOWER_FINE_KEY_TEXT,
+             RATE_SLOWER_FINE_KEY_LONGTEXT, false )
     add_key( "key-next", KEY_NEXT, NULL, NEXT_KEY_TEXT,
              NEXT_KEY_LONGTEXT, false )
     add_key( "key-prev", KEY_PREV, NULL, PREV_KEY_TEXT,
@@ -2694,6 +2706,8 @@ const struct hotkey libvlc_hotkeys[] =
     { "key-faster", ACTIONID_FASTER, 0, },
     { "key-slower", ACTIONID_SLOWER, 0, },
     { "key-rate-normal", ACTIONID_RATE_NORMAL, 0, },
+    { "key-rate-faster-fine", ACTIONID_RATE_FASTER_FINE, 0, },
+    { "key-rate-slower-fine", ACTIONID_RATE_SLOWER_FINE, 0, },
     { "key-toggle-fullscreen", ACTIONID_TOGGLE_FULLSCREEN, 0, },
     { "key-leave-fullscreen", ACTIONID_LEAVE_FULLSCREEN, 0, },
     { "key-vol-up", ACTIONID_VOL_UP, 0, },




More information about the vlc-devel mailing list