Skip to content

Commit

Permalink
osc.lua: cycle tracks when there's only one
Browse files Browse the repository at this point in the history
When there is 1 audio or sub track, if the command wasn't configured,
make left click select or unselect it directly without opening the
selector. Unfortunately this is awkward to implement with the command
script-opts.

Requested by sfan5.
  • Loading branch information
guidocella committed Oct 26, 2024
1 parent 9af491f commit a576f7a
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions player/lua/osc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ local assdraw = require 'mp.assdraw'
local msg = require 'mp.msg'
local opt = require 'mp.options'

local default_audio_command = "script-binding select/select-aid; script-message-to osc osc-hide"
local default_sub_command = "script-binding select/select-sid; script-message-to osc osc-hide"

--
-- Parameters
--
Expand Down Expand Up @@ -94,13 +97,13 @@ local user_opts = {
chapter_next_mbtn_mid_command = "show-text ${chapter-list} 3000",
chapter_next_mbtn_right_command = "script-binding select/select-chapter; script-message-to osc osc-hide",

audio_track_mbtn_left_command = "script-binding select/select-aid; script-message-to osc osc-hide",
audio_track_mbtn_left_command = default_audio_command,
audio_track_mbtn_mid_command = "show-text ${track-list/audio} 3000",
audio_track_mbtn_right_command = "show-text ${track-list/audio} 3000",
audio_track_wheel_down_command = "cycle audio",
audio_track_wheel_up_command = "cycle audio down",

sub_track_mbtn_left_command = "script-binding select/select-sid; script-message-to osc osc-hide",
sub_track_mbtn_left_command = default_sub_command,
sub_track_mbtn_mid_command = "show-text ${track-list/sub} 3000",
sub_track_mbtn_right_command = "show-text ${track-list/sub} 3000",
sub_track_wheel_down_command = "cycle sub",
Expand Down Expand Up @@ -1866,7 +1869,12 @@ local function osc_init()
return ("\238\132\134" .. osc_styles.smallButtonsLlabel .. " " ..
(mp.get_property_native("aid") or "-") .. "/" .. audio_track_count)
end
ne.eventresponder["mbtn_left_up"] = command_callback(user_opts.audio_track_mbtn_left_command)
if audio_track_count == 1 and
user_opts.audio_track_mbtn_left_command == default_audio_command then
ne.eventresponder["mbtn_left_up"] = command_callback("cycle audio")
else
ne.eventresponder["mbtn_left_up"] = command_callback(user_opts.audio_track_mbtn_left_command)
end
ne.eventresponder["shift+mbtn_left_up"] = command_callback(
user_opts.audio_track_mbtn_mid_command)
ne.eventresponder["mbtn_right_up"] = command_callback(user_opts.audio_track_mbtn_right_command)
Expand All @@ -1886,7 +1894,11 @@ local function osc_init()
return ("\238\132\135" .. osc_styles.smallButtonsLlabel .. " " ..
(mp.get_property_native("sid") or "-") .. "/" .. sub_track_count)
end
ne.eventresponder["mbtn_left_up"] = command_callback(user_opts.sub_track_mbtn_left_command)
if sub_track_count == 1 and user_opts.sub_track_mbtn_left_command == default_sub_command then
ne.eventresponder["mbtn_left_up"] = command_callback("cycle sub")
else
ne.eventresponder["mbtn_left_up"] = command_callback(user_opts.sub_track_mbtn_left_command)
end
ne.eventresponder["shift+mbtn_left_up"] = command_callback(user_opts.sub_track_mbtn_mid_command)
ne.eventresponder["mbtn_right_up"] = command_callback(user_opts.sub_track_mbtn_right_command)

Expand Down

0 comments on commit a576f7a

Please sign in to comment.