diff options
author | ChrisK2 <spam@kalania.de> | 2014-05-23 13:24:27 +0200 |
---|---|---|
committer | ChrisK2 <spam@kalania.de> | 2014-05-23 13:24:27 +0200 |
commit | ce69afab440b108972810663255e9211972e964b (patch) | |
tree | 2c6345ba2d0e0523e264bfbe8b313cfc19eaa13a | |
parent | c6915d732510812098e6e6c5f4d3d7e28fe21429 (diff) |
lua/osc: forgot some changed files in previous commit
-rw-r--r-- | DOCS/man/en/lua.rst | 55 | ||||
-rw-r--r-- | DOCS/man/en/osc.rst | 59 | ||||
-rw-r--r-- | player/lua.c | 3 | ||||
-rw-r--r-- | player/lua/options.lua | 2 | ||||
-rw-r--r-- | player/lua/osc.lua | 112 | ||||
-rw-r--r-- | wscript_build.py | 4 |
6 files changed, 118 insertions, 117 deletions
diff --git a/DOCS/man/en/lua.rst b/DOCS/man/en/lua.rst index 0365fd7a02..ab5a70ef57 100644 --- a/DOCS/man/en/lua.rst +++ b/DOCS/man/en/lua.rst @@ -188,8 +188,8 @@ The ``mp`` module is preloaded, although it can be loaded manually with This will print the message ``the key was pressed`` when ``x`` was pressed. - The user can remap these key bindings. Then the user has to put the following - into his input.conf to remap the command to the ``y`` key: + The user can remap these key bindings. Then the user has to put the + following into his input.conf to remap the command to the ``y`` key: :: @@ -411,6 +411,57 @@ with ``require 'mp.msg'``. All of these are shortcuts and equivalent to the corresponding ``msg.log(level, ...)`` call. +mp.option +--------- + +mpv comes with a built-in module to manage options from config-files and the +command-line. All you have to do is to supply a table with default options to +the read_options function. The function will overwrite the default values +with values found in the config-file and the command-line (in that order). + +``read_options(table, identifier)`` + A ``table`` with key-value pairs. The type of the default values is + important for converting the values read from the config file or + command-line back. Do not use ``nil`` as a default value! + + The ``identifier`` is used to identify the config-file and the command-line + options. These needs to unique to avoid collisions with other scripts. + Defaults to ``mp.get_script_name()``. + + +Example implementation:: + + local opt = require 'mp.options' + local options = { + optionA = "defaultvalueA", + optionB = -0.5, + optionC = true, + } + read_options(options, "myscript") + print(option.optionA) + + +The config file will be stored in ``lua-settings/identifier.conf`` in mpv's user +folder. Comment lines can be started with # and stray spaces are not removed. +Boolean values will be represented with yes/no. + +Example config:: + + # comment + optionA=Hello World + optionB=9999 + optionC=no + + +Command-line options are read from the ``--lua-opts`` parameter. To avoid +collisions, all keys have to be prefixed with ``identifier-``. + +Example command-line:: + + --lua-opts=myscript-optionA=TEST:myscript-optionB=0:myscript-optionC=yes + + + Events ------ diff --git a/DOCS/man/en/osc.rst b/DOCS/man/en/osc.rst index dab98bd2fc..2df6ff6feb 100644 --- a/DOCS/man/en/osc.rst +++ b/DOCS/man/en/osc.rst @@ -122,18 +122,24 @@ time remaining left-click toggle between total and remaining time ============= ================================================ -hide - | Hide the OSC permanently until mpv is restarted. +Keybindings +~~~~~~~~~~~ - ============= ================================================ - del hide the OSC - ============= ================================================ +These keybindings are active by default if nothing else is already bound to +these keys. In case of collosision, the function needs to be bound to a +different key. See `Script Commands`_ section. + +============= ================================================ +del Hide the OSC permanently until mpv is restarted. +============= ================================================ Configuration ------------- -The OSC offers limited configuration through a config file ``plugin_osc.conf`` -placed in mpv's user dir. +The OSC offers limited configuration through a config file +``lua-settings/osc.conf`` placed in mpv's user dir and through the +``--lua-opts`` command-line option. Options provided through the command-line +will override those from the config file. Config Syntax ~~~~~~~~~~~~~ @@ -141,14 +147,25 @@ Config Syntax The config file must exactly follow the following syntax:: # this is a comment - parameter1=value1 - parameter2=value2 + optionA=value1 + optionB=value2 ``#`` can only be used at the beginning of a line and there may be no spaces around the ``=`` or anywhere else. -Configurable parameters -~~~~~~~~~~~~~~~~~~~~~~~ +Command-line Syntax +~~~~~~~~~~~~~~~~~~~ + +To avoid collisions with other scripts, all options need to be prefixed with +``osc-``. + +Example:: + + --lua-opts=osc-optionA=value1:osc-optionB=value2 + + +Configurable Options +~~~~~~~~~~~~~~~~~~~~ ``showwindowed`` | Default: yes @@ -199,14 +216,20 @@ Configurable parameters | Default: 0 | Size of the deadzone. The deadzone is an area that makes the mouse act like leaving the window. Movement there won't make the OSC show up and - it will hide immediately if the mouse enters it. + it will hide immediately if the mouse enters it. The deadzone starts + at the window border opposite to the OSC and the size controls how much + of the window it will span. Values between 0 and 1. ``minmousemove`` | Default: 3 | Minimum amount of pixels the mouse has to move between ticks to make the OSC show up -Script commands +``seektooltip`` + | Default: yes + | Display a tooltip over the seekbar indicating time at mouse position. + +Script Commands ~~~~~~~~~~~~~~~ The OSC script listens to certain script commands. These commands can bound @@ -219,11 +242,11 @@ in ``input.conf``, or sent by other scripts. Hide the OSC permanently. This is also what the ``del`` key does. -.. admonition:: Example +Example - You could out this into ``input.conf`` to hide the OSC with the ``a`` key - and to unhide it with ``b``: +You could put this into ``input.conf`` to hide the OSC with the ``a`` key and +to unhide it with ``b``:: - | a script_message disable-osc - | b script_message enable-osc + a script_message disable-osc + b script_message enable-osc diff --git a/player/lua.c b/player/lua.c index 1c8a5c6cb5..4e1f3d04d2 100644 --- a/player/lua.c +++ b/player/lua.c @@ -54,6 +54,9 @@ static const char *builtin_lua_scripts[][2] = { {"mp.assdraw", # include "player/lua/assdraw.inc" }, + {"mp.options", +# include "player/lua/options.inc" + }, {"@osc.lua", # include "player/lua/osc.inc" }, diff --git a/player/lua/options.lua b/player/lua/options.lua index 382a9e4a4b..ca1de400f9 100644 --- a/player/lua/options.lua +++ b/player/lua/options.lua @@ -79,7 +79,7 @@ function read_options(options, identifier) io.close(f) end - --parse commandline options + --parse command-line options for key, val in pairs(mp.get_property_native("options/lua-opts")) do local prefix = identifier.."-" if not (string.find(key, prefix, 1, true) == nil) then diff --git a/player/lua/osc.lua b/player/lua/osc.lua index da07e43456..1ef7e4b455 100644 --- a/player/lua/osc.lua +++ b/player/lua/osc.lua @@ -1,14 +1,13 @@ --- osc.lua - local assdraw = require 'mp.assdraw' local msg = require 'mp.msg' +local opt = require 'mp.options' -- -- Parameters -- -- default user option values --- do not touch, change them in plugin_osc.conf +-- do not touch, change them in osc.conf local user_opts = { showwindowed = true, -- show OSC when windowed? showfullscreen = true, -- show OSC when fullscreen? @@ -23,10 +22,13 @@ local user_opts = { fadeduration = 200, -- duration of fade out in ms, 0 = no fade deadzonesize = 0, -- size of deadzone minmousemove = 3, -- minimum amount of pixels the mouse has to move between ticks to make the OSC show up - seektooltip = false, -- display tooltip over the seekbar indicating time at mouse position + seektooltip = true, -- display tooltip over the seekbar indicating time at mouse position iamaprogrammer = false, -- use native mpv values and disable OSC internal playlist management (and some functions that depend on it) } +-- read options from config and command-line +read_options(user_opts, "osc") + local osc_param = { osc_w = 550, -- width, height, corner-radius, padding of the OSC box osc_h = 138, @@ -72,93 +74,7 @@ local state = { message_timeout, } --- --- User Settings Management --- - -function val2str(val) - local strval = val - if type(val) == "boolean" then - if val then strval = "yes" else strval = "no" end - end - - return strval -end --- converts val to type of desttypeval -function typeconv(desttypeval, val) - if type(desttypeval) == "boolean" then - if val == "yes" then - val = true - elseif val == "no" then - val = false - else - msg.error("Error: Can't convert " .. val .. " to boolean!") - val = nil - end - elseif type(desttypeval) == "number" then - if not (tonumber(val) == nil) then - val = tonumber(val) - else - msg.error("Error: Can't convert " .. val .. " to number!") - val = nil - end - end - return val -end - --- Automagical config handling --- options: A table with options setable via config with assigned default values. The type of the default values is important for --- converting the values read from the config file back. Do not use "nil" as a default value! --- identifier: A simple indentifier string for the config file. Make sure this doesn't collide with other scripts. - --- How does it work: --- Existance of the configfile will be checked, if it doesn't exist, the default values from the options table will be written in a new --- file, commented out. If it exits, the key/value pairs will be read, and values of keys that exist in the options table will overwrite --- their value. Keys that don't exist in the options table will be ignored, keys that don't exits in the config will keep their default --- value. The value's types will automatically be converted to the type used in the options table. -function read_config(options, identifier) - - local conffilename = "plugin_" .. identifier .. ".conf" - local conffile = mp.find_config_file(conffilename) - local f = conffile and io.open(conffile,"r") - if f == nil then - -- config not found - else - -- config exists, read values - local linecounter = 1 - for line in f:lines() do - if string.find(line, "#") == 1 then - - else - local eqpos = string.find(line, "=") - if eqpos == nil then - - else - local key = string.sub(line, 1, eqpos-1) - local val = string.sub(line, eqpos+1) - - -- match found values with defaults - if options[key] == nil then - msg.warn(conffilename..":"..linecounter.." unknown key " .. key .. ", ignoring") - else - local convval = typeconv(options[key], val) - if convval == nil then - msg.error(conffilename..":"..linecounter.." error converting value '" .. val .. "' for key '" .. key .. "'") - else - options[key] = convval - end - end - end - end - linecounter = linecounter + 1 - end - io.close(f) - end -end - --- read configfile -read_config(user_opts, "osc") -- @@ -260,7 +176,7 @@ function update_tracklist() tracks_mpv = {} tracks_mpv.video, tracks_mpv.audio, tracks_mpv.sub = {}, {}, {} for n = 1, #tracktable do - if not (tracktable[n].type == "unkown") then + if not (tracktable[n].type == "unknown") then local type = tracktable[n].type local mpv_id = tonumber(tracktable[n].id) @@ -283,7 +199,7 @@ function get_tracklist(type) else for n = 1, #tracks_osc[type] do local track = tracks_osc[type][n] - local lang, title, selected = "unkown", "", "{\\fscx" .. select_scale .. "\\fscy" .. select_scale .. "}○{\\fscx100\\fscy100}" + local lang, title, selected = "unknown", "", "{\\fscx" .. select_scale .. "\\fscy" .. select_scale .. "}○{\\fscx100\\fscy100}" if not(track.lang == nil) then lang = track.lang end if not(track.title == nil) then title = track.title end if (track.id == tonumber(mp.get_property(type))) then @@ -318,7 +234,7 @@ function set_track(type, next) show_message(nicetypes[type] .. " Track: none") else show_message(nicetypes[type] .. " Track: " .. new_track_osc .. "/" .. #tracks_osc[type] - .. " [" .. (tracks_osc[type][new_track_osc].lang or "unkown") .. "] " .. (tracks_osc[type][new_track_osc].title or "")) + .. " [" .. (tracks_osc[type][new_track_osc].lang or "unknown") .. "] " .. (tracks_osc[type][new_track_osc].title or "")) end end @@ -579,9 +495,9 @@ function render_elements(master_ass) local s_min, s_max = element.metainfo.slider.min, element.metainfo.slider.max local an = 2 - if (sliderpos < (s_min + 10)) then + if (sliderpos < (s_min + 5)) then an = 1 - elseif (sliderpos > (s_max - 10)) then + elseif (sliderpos > (s_max - 5)) then an = 3 end @@ -659,6 +575,8 @@ end -- OSC INIT function osc_init() + msg.debug("osc_init") + -- kill old Elements elements = {} @@ -1045,7 +963,7 @@ end function show_osc() - + msg.debug("show_osc") --remember last time of invocation (mouse move) state.showtime = mp.get_time() @@ -1058,6 +976,7 @@ function show_osc() end function hide_osc() + msg.debug("hide_osc") if (user_opts.fadeduration > 0) then if not(state.osc_visible == false) then state.anitype = "out" @@ -1078,6 +997,7 @@ function request_init() end function render() + msg.debug("rendering") local current_screen_sizeX, current_screen_sizeY = mp.get_screen_size() local mouseX, mouseY = mp.get_mouse_pos() local now = mp.get_time() diff --git a/wscript_build.py b/wscript_build.py index fe711b554f..941887a08b 100644 --- a/wscript_build.py +++ b/wscript_build.py @@ -65,6 +65,10 @@ def build(ctx): target = "player/lua/assdraw.inc") ctx.file2string( + source = "player/lua/options.lua", + target = "player/lua/options.inc") + + ctx.file2string( source = "player/lua/osc.lua", target = "player/lua/osc.inc") |