[vlc-devel] [PATCH 1/5] add a new hotkey
Aaron Wang
hughwung at gmail.com
Wed Sep 23 10:18:00 CEST 2015
---
include/vlc_keys.h | 2 +
modules/control/hotkeys.c | 196 +++++++++++++++++++++++++---------------------
src/config/keys.c | 2 +
src/libvlc-module.c | 13 +++
4 files changed, 125 insertions(+), 88 deletions(-)
diff --git a/include/vlc_keys.h b/include/vlc_keys.h
index ea54950..8c058fa 100644
--- a/include/vlc_keys.h
+++ b/include/vlc_keys.h
@@ -176,6 +176,8 @@ typedef enum vlc_action {
ACTIONID_SUBTITLE_TEXT_SCALE_NORMAL,
ACTIONID_SUBTITLE_TEXT_SCALE_UP,
ACTIONID_SUBTITLE_TEXT_SCALE_DOWN,
+ ACTIONID_SUBTITLE_TRACK2,
+ ACTIONID_SUBTITLE_TOGGLE2,
ACTIONID_INTF_TOGGLE_FSC,
ACTIONID_INTF_HIDE,
ACTIONID_INTF_BOSS,
diff --git a/modules/control/hotkeys.c b/modules/control/hotkeys.c
index 7c4ee7f..2ffef6e 100644
--- a/modules/control/hotkeys.c
+++ b/modules/control/hotkeys.c
@@ -73,6 +73,8 @@ static void DisplayRate ( vout_thread_t *, float );
static float AdjustRateFine( vlc_object_t *, const int );
static void ClearChannels ( intf_thread_t *, vout_thread_t * );
+static void SubtitleTrack(input_thread_t* , vout_thread_t* , const char*, const char*,const char*);
+static void SubtitleToggle(input_thread_t*, vout_thread_t*, const char*, const char*, const char*);
#define DisplayMessage(vout, ...) \
do { \
if (vout) \
@@ -556,97 +558,17 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
var_FreeList( &list, &list2 );
}
break;
+ case ACTIONID_SUBTITLE_TRACK2:
+ SubtitleTrack(p_input, p_vout, "spu-es2", "spu-choice2","2nd ");
+ break;
case ACTIONID_SUBTITLE_TRACK:
- if( p_input )
- {
- vlc_value_t val, list, list2;
- int i_count, i;
- var_Get( p_input, "spu-es", &val );
-
- var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
- &list, &list2 );
- i_count = list.p_list->i_count;
- if( i_count <= 1 )
- {
- DisplayMessage( p_vout, _("Subtitle track: %s"),
- _("N/A") );
- var_FreeList( &list, &list2 );
- break;
- }
- for( i = 0; i < i_count; i++ )
- {
- if( val.i_int == list.p_list->p_values[i].i_int )
- {
- break;
- }
- }
- /* value of spu-es was not in choices list */
- if( i == i_count )
- {
- msg_Warn( p_input,
- "invalid current subtitle track, selecting 0" );
- i = 0;
- }
- else if( i == i_count - 1 )
- i = 0;
- else
- i++;
- var_SetInteger( p_input, "spu-es", list.p_list->p_values[i].i_int );
- var_SetInteger( p_input, "spu-choice", list.p_list->p_values[i].i_int );
- DisplayMessage( p_vout, _("Subtitle track: %s"),
- list2.p_list->p_values[i].psz_string );
- var_FreeList( &list, &list2 );
- }
+ SubtitleTrack(p_input, p_vout, "spu-es", "spu-choice","");
+ break;
+ case ACTIONID_SUBTITLE_TOGGLE2:
+ SubtitleToggle(p_input, p_vout, "spu-es2", "spu-choice2","");
break;
case ACTIONID_SUBTITLE_TOGGLE:
- if( p_input )
- {
- vlc_value_t list, list2;
- int i_count, i_sel_index, i_sel_id, i_old_id, i_new_index;
- i_old_id = var_GetInteger( p_input, "spu-es" );
- i_sel_id = var_GetInteger( p_input, "spu-choice" );
-
- var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
- &list, &list2 );
- i_count = list.p_list->i_count;
- if( i_count <= 1 )
- {
- DisplayMessage( p_vout, _("Subtitle track: %s"),
- _("N/A") );
- var_FreeList( &list, &list2 );
- break;
- }
- for( i_sel_index = 0; i_sel_index < i_count; i_sel_index++ )
- {
- if( i_sel_id == list.p_list->p_values[i_sel_index].i_int )
- {
- break;
- }
- }
- /* if there is nothing to toggle choose the first track */
- if( !i_sel_index ) {
- i_sel_index = 1;
- i_sel_id = list.p_list->p_values[1].i_int;
- var_SetInteger( p_input, "spu-choice", i_sel_id );
- }
-
- i_new_index = 0;
- if( i_old_id != i_sel_id )
- {
- if( i_sel_index >= i_count )
- {
- var_SetInteger( p_input, "spu-choice", list.p_list->p_values[0].i_int );
- }
- else
- {
- i_new_index = i_sel_index;
- }
- }
- var_SetInteger( p_input, "spu-es", list.p_list->p_values[i_new_index].i_int );
- DisplayMessage( p_vout, _("Subtitle track: %s"),
- list2.p_list->p_values[i_new_index].psz_string );
- var_FreeList( &list, &list2 );
- }
+ SubtitleToggle(p_input, p_vout, "spu-es", "spu-choice","");
break;
case ACTIONID_PROGRAM_SID_NEXT:
case ACTIONID_PROGRAM_SID_PREV:
@@ -1276,3 +1198,101 @@ static void ClearChannels( intf_thread_t *p_intf, vout_thread_t *p_vout )
vout_FlushSubpictureChannel( p_vout, p_intf->p_sys->slider_chan );
}
}
+
+static void SubtitleTrack(input_thread_t* p_input, vout_thread_t * p_vout,
+ const char* spu, const char* spuchoice, const char* prompt )
+{
+ if( p_input == NULL )
+ return;
+ vlc_value_t val, list, list2;
+ int i_count, i;
+ var_Get( p_input, spu, &val );
+
+ var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
+ &list, &list2 );
+ i_count = list.p_list->i_count;
+ if( i_count <= 1 )
+ {
+ DisplayMessage( p_vout, _("%sSubtitle track: %s"),prompt,
+ _("N/A") );
+ var_FreeList( &list, &list2 );
+ return;
+ }
+ for( i = 0; i < i_count; i++ )
+ {
+ if( val.i_int == list.p_list->p_values[i].i_int )
+ {
+ break;
+ }
+ }
+ /* value of spu-es was not in choices list */
+ if( i == i_count )
+ {
+ msg_Warn( p_input,
+ "invalid current subtitle track, selecting 0" );
+ i = 0;
+ }
+ else if( i == i_count - 1 )
+ i = 0;
+ else
+ i++;
+ var_SetInteger( p_input, spu, list.p_list->p_values[i].i_int );
+ var_SetInteger( p_input, spuchoice, list.p_list->p_values[i].i_int );
+ DisplayMessage( p_vout, _("%sSubtitle track: %s"),prompt,
+ list2.p_list->p_values[i].psz_string );
+ var_FreeList( &list, &list2 );
+}
+
+static void SubtitleToggle(input_thread_t* p_input, vout_thread_t * p_vout,
+ const char* spues, const char* spuchoice, const char* prompt )
+{
+ if( p_input == NULL )
+ return;
+ vlc_value_t list, list2;
+ int i_count, i_sel_index, i_sel_id, i_old_id, i_new_index;
+ i_old_id = var_GetInteger( p_input, spues );//id is always changing
+ i_sel_id = var_GetInteger( p_input, spuchoice );
+
+ var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
+ &list, &list2 );
+ i_count = list.p_list->i_count;
+
+ if( i_count <= 1 )// o is disable, >=1 are real tracks
+ {
+ DisplayMessage( p_vout, _("%sSubtitle track: %s"),prompt,
+ _("N/A") );
+ var_FreeList( &list, &list2 );
+ return;
+ }
+ for( i_sel_index = 0; i_sel_index < i_count; i_sel_index++ )
+ {
+ if( i_sel_id == list.p_list->p_values[i_sel_index].i_int )
+ {
+ break;
+ }
+ }
+ /* if there is nothing to toggle choose the first track */
+ if( !i_sel_index )
+ {
+ i_sel_index = 1;
+ i_sel_id = list.p_list->p_values[1].i_int;
+ var_SetInteger(p_input, spuchoice, i_sel_id);
+ }
+
+ i_new_index = 0;
+ if( i_old_id != i_sel_id )
+ {
+ if( i_sel_index >= i_count )
+ {
+ var_SetInteger( p_input, spuchoice, list.p_list->p_values[0].i_int );
+ }
+ else
+ {
+ i_new_index = i_sel_index;
+ }
+ }
+ var_SetInteger( p_input, spues, list.p_list->p_values[i_new_index].i_int );
+ DisplayMessage( p_vout, _("%sSubtitle track: %s"), prompt,
+ list2.p_list->p_values[i_new_index].psz_string );
+ var_FreeList( &list, &list2 );
+}
diff --git a/src/config/keys.c b/src/config/keys.c
index 94e5cf5..dfd300f 100644
--- a/src/config/keys.c
+++ b/src/config/keys.c
@@ -358,6 +358,8 @@ static const struct action actions[] =
{ "subtitle-text-scale-up", ACTIONID_SUBTITLE_TEXT_SCALE_UP, },
{ "subtitle-toggle", ACTIONID_SUBTITLE_TOGGLE, },
{ "subtitle-track", ACTIONID_SUBTITLE_TRACK, },
+ { "subtitle-track2", ACTIONID_SUBTITLE_TRACK2, },
+ { "subtitle2-toggle", ACTIONID_SUBTITLE_TOGGLE2, },//2 is larger
{ "title-next", ACTIONID_TITLE_NEXT, },
{ "title-prev", ACTIONID_TITLE_PREV, },
{ "toggle-autoscale", ACTIONID_TOGGLE_AUTOSCALE, },
diff --git a/src/libvlc-module.c b/src/libvlc-module.c
index a13093d..0d6f5af 100644
--- a/src/libvlc-module.c
+++ b/src/libvlc-module.c
@@ -574,6 +574,7 @@ static const char *const ppsz_clock_descriptions[] =
"(from 0 to n).")
#define INPUT_SUBTRACK_TEXT N_("Subtitle track")
+#define INPUT_SUBTRACK2_TEXT N_("2nd Subtitle track")
#define INPUT_SUBTRACK_LONGTEXT N_( \
"Stream number of the subtitle track to use " \
"(from 0 to n).")
@@ -1336,8 +1337,10 @@ static const char *const mouse_wheel_texts[] = {
#define AUDIO_TRACK_KEY_TEXT N_("Cycle audio track")
#define AUDIO_TRACK_KEY_LONGTEXT N_("Cycle through the available audio tracks(languages).")
#define SUBTITLE_TRACK_KEY_TEXT N_("Cycle subtitle track")
+#define SUBTITLE_TRACK2_KEY_TEXT N_("Cycle 2nd subtitle track")
#define SUBTITLE_TRACK_KEY_LONGTEXT N_("Cycle through the available subtitle tracks.")
#define SUBTITLE_TOGGLE_KEY_TEXT N_("Toggle subtitles")
+#define SUBTITLE2_TOGGLE_KEY_TEXT N_("Toggle 2nd subtitles")
#define SUBTITLE_TOGGLE_KEY_LONGTEXT N_("Toggle subtitle track visibility.")
#define PROGRAM_SID_NEXT_KEY_TEXT N_("Cycle next program Service ID")
#define PROGRAM_SID_NEXT_KEY_LONGTEXT N_("Cycle through the available next program Service IDs (SIDs).")
@@ -1658,6 +1661,9 @@ vlc_module_begin ()
add_integer( "sub-track", -1,
INPUT_SUBTRACK_TEXT, INPUT_SUBTRACK_LONGTEXT, true )
change_safe ()
+ add_integer( "sub-track2", -1,
+ INPUT_SUBTRACK2_TEXT, INPUT_SUBTRACK_LONGTEXT, true )
+ change_safe ()
add_string( "audio-language", "",
INPUT_AUDIOTRACK_LANG_TEXT, INPUT_AUDIOTRACK_LANG_LONGTEXT,
false )
@@ -2298,6 +2304,8 @@ vlc_module_begin ()
# define KEY_AUDIO_TRACK "b"
# define KEY_SUBTITLE_TRACK "v"
# define KEY_SUBTITLE_TOGGLE "Shift+v"
+# define KEY_SUBTITLE_TRACK2 "Ctrl+v"
+# define KEY_SUBTITLE_TOGGLE2 NULL
# define KEY_PROGRAM_SID_NEXT "x"
# define KEY_PROGRAM_SID_PREV "Shift+x"
# define KEY_ASPECT_RATIO "a"
@@ -2470,6 +2478,11 @@ vlc_module_begin ()
SUBTITLE_TRACK_KEY_TEXT, SUBTITLE_TRACK_KEY_LONGTEXT, false )
add_key( "key-subtitle-toggle", KEY_SUBTITLE_TOGGLE,
SUBTITLE_TOGGLE_KEY_TEXT, SUBTITLE_TOGGLE_KEY_LONGTEXT, false )
+ add_key( "key-subtitle-track2", KEY_SUBTITLE_TRACK2,
+ SUBTITLE_TRACK2_KEY_TEXT, SUBTITLE_TRACK_KEY_LONGTEXT, false )
+ add_key( "key-subtitle2-toggle", KEY_SUBTITLE_TOGGLE2,
+ SUBTITLE2_TOGGLE_KEY_TEXT, SUBTITLE_TOGGLE_KEY_LONGTEXT, false )
+
add_key( "key-program-sid-next", KEY_PROGRAM_SID_NEXT,
PROGRAM_SID_NEXT_KEY_TEXT, PROGRAM_SID_NEXT_KEY_LONGTEXT, false )
add_key( "key-program-sid-prev", KEY_PROGRAM_SID_PREV,
--
1.9.1
More information about the vlc-devel
mailing list