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 osc.conflocal user_opts = { showwindowed = true, -- show OSC when windowed? showfullscreen = true, -- show OSC when fullscreen? idlescreen = true, -- show mpv logo on idle scalewindowed = 1, -- scaling of the controller when windowed scalefullscreen = 1, -- scaling of the controller when fullscreen vidscale = "auto", -- scale the controller with the video? valign = 0.8, -- vertical alignment, -1 (top) to 1 (bottom) halign = 0, -- horizontal alignment, -1 (left) to 1 (right) barmargin = 0, -- vertical margin of top/bottombar boxalpha = 80, -- alpha of the background box, -- 0 (opaque) to 255 (fully transparent) hidetimeout = 500, -- duration in ms until the OSC hides if no -- mouse movement. enforced non-negative for the -- user, but internally negative is "always-on". fadeduration = 200, -- duration of fade out in ms, 0 = no fade deadzonesize = 0.5, -- size of deadzone minmousemove = 0, -- minimum amount of pixels the mouse has to -- move between ticks to make the OSC show up layout = "bottombar", seekbarstyle = "bar", -- bar, diamond or knob seekbarhandlesize = 0.6, -- size ratio of the diamond and knob handle seekrangestyle = "inverted",-- bar, line, slider, inverted or none seekrangeseparate = true, -- whether the seekranges overlay on the bar-style seekbar seekrangealpha = 200, -- transparency of seekranges seekbarkeyframes = true, -- use keyframes when dragging the seekbar scrollcontrols = true, -- allow scrolling when hovering certain OSC elements title = "${!playlist-count==1:[${playlist-pos-1}/${playlist-count}] }${media-title}", -- to be shown as OSC title tooltipborder = 1, -- border of tooltip in bottom/topbar timetotal = false, -- display total time instead of remaining time? remaining_playtime = true, -- display the remaining time in playtime or video-time mode -- playtime takes speed into account, whereas video-time doesn't timems = false, -- display timecodes with milliseconds? tcspace = 100, -- timecode spacing (compensate font size estimation) visibility = "auto", -- only used at init to set visibility_mode(...) boxmaxchars = 80, -- title crop threshold for box layout boxvideo = false, -- apply osc_param.video_margins to video windowcontrols = "auto", -- whether to show window controls windowcontrols_alignment = "right", -- which side to show window controls on windowcontrols_title = "${media-title}", -- same as title but for windowcontrols greenandgrumpy = false, -- disable santa hat livemarkers = true, -- update seekbar chapter markers on duration change chapter_fmt = "Chapter: %s", -- chapter print format for seekbar-hover. "no" to disable unicodeminus = false, -- whether to use the Unicode minus sign character background_color = "#000000", -- background color of the osc timecode_color = "#FFFFFF", -- color of the progress bar and time color title_color = "#FFFFFF", -- color of the title time_pos_color = "#FFFFFF", -- color of the timecode at hovered position buttons_color = "#FFFFFF", -- color of big buttons, wc buttons, and bar small buttons small_buttonsL_color = "#FFFFFF", -- color of left small buttons small_buttonsR_color = "#FFFFFF", -- color of right small buttons top_buttons_color = "#FFFFFF", -- color of top buttons held_element_color = "#999999", -- color of an element while held down time_pos_outline_color = "#000000", -- color of the border timecodes in slimbox and TimePosBar tick_delay = 1 / 60, -- minimum interval between OSC redraws in seconds tick_delay_follow_display_fps = false, -- use display fps as the minimum interval -- luacheck: push ignore -- luacheck: max line length title_mbtn_left_command = "script-binding select/select-playlist; script-message-to osc osc-hide", title_mbtn_mid_command = "show-text ${filename}", title_mbtn_right_command = "script-binding stats/display-page-5", playlist_prev_mbtn_left_command = "playlist-prev", playlist_prev_mbtn_mid_command = "show-text ${playlist} 3000", playlist_prev_mbtn_right_command = "show-text ${playlist} 3000", playlist_next_mbtn_left_command = "playlist-next", playlist_next_mbtn_mid_command = "show-text ${playlist} 3000", playlist_next_mbtn_right_command = "show-text ${playlist} 3000", play_pause_mbtn_left_command = "cycle pause", play_pause_mbtn_mid_command = "", play_pause_mbtn_right_command = "cycle-values loop-file inf no", chapter_prev_mbtn_left_command = "osd-msg add chapter -1", chapter_prev_mbtn_mid_command = "show-text ${chapter-list} 3000", chapter_prev_mbtn_right_command = "script-binding select/select-chapter; script-message-to osc osc-hide", chapter_next_mbtn_left_command = "osd-msg add chapter 1", 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_mid_command = "show-text ${track-list/audio} 3000", audio_track_mbtn_right_command = "cycle audio", 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_mid_command = "show-text ${track-list/sub} 3000", sub_track_mbtn_right_command = "cycle sub", sub_track_wheel_down_command = "cycle sub", sub_track_wheel_up_command = "cycle sub down", volume_mbtn_left_command = "no-osd cycle mute", volume_mbtn_mid_command = "", volume_mbtn_right_command = "script-binding select/select-audio-device; script-message-to osc osc-hide", volume_wheel_down_command = "add volume -5", volume_wheel_up_command = "add volume 5", fullscreen_mbtn_left_command = "cycle fullscreen", fullscreen_mbtn_mid_command = "", fullscreen_mbtn_right_command = "cycle window-maximized", -- luacheck: pop} local osc_param = { -- calculated by osc_init() playresy = 0, -- canvas size Y playresx = 0, -- canvas size X display_aspect = 1, unscaled_y = 0, areas = {}, video_margins = { l = 0, r = 0, t = 0, b = 0, -- left/right/top/bottom },} local margins_opts = { {"l", "video-margin-ratio-left"}, {"r", "video-margin-ratio-right"}, {"t", "video-margin-ratio-top"}, {"b", "video-margin-ratio-bottom"},} local tick_delay = 1 / 60local audio_track_count = 0local sub_track_count = 0local window_control_box_width = 80local layouts = {}local is_december = os.date("*t").month == 12local UNICODE_MINUS = string.char(0xe2, 0x88, 0x92) -- UTF-8 for U+2212 MINUS SIGN local function osc_color_convert(color) return color:sub(6,7) .. color:sub(4,5) .. color:sub(2,3)end -- luacheck: push ignore-- luacheck: max line lengthlocal osc_styles local function set_osc_styles() osc_styles = { bigButtons = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.buttons_color) .. "\\3c&HFFFFFF\\fs50\\fnmpv-osd-symbols}", smallButtonsL = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.small_buttonsL_color) .. "\\3c&HFFFFFF\\fs19\\fnmpv-osd-symbols}", smallButtonsLlabel = "{\\fscx105\\fscy105\\fn" .. mp.get_property("options/osd-font") .. "}", smallButtonsR = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.small_buttonsR_color) .. "\\3c&HFFFFFF\\fs30\\fnmpv-osd-symbols}", topButtons = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.top_buttons_color) .. "\\3c&HFFFFFF\\fs12\\fnmpv-osd-symbols}", elementDown = "{\\1c&H" .. osc_color_convert(user_opts.held_element_color) .."}", timecodes = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.timecode_color) .. "\\3c&HFFFFFF\\fs20}", vidtitle = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.title_color) .. "\\3c&HFFFFFF\\fs14\\q2}", box = "{\\rDefault\\blur0\\bord1\\1c&H" .. osc_color_convert(user_opts.background_color) .. "\\3c&HFFFFFF}", topButtonsBar = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.top_buttons_color) .. "\\3c&HFFFFFF\\fs18\\fnmpv-osd-symbols}", smallButtonsBar = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.buttons_color) .. "\\3c&HFFFFFF\\fs28\\fnmpv-osd-symbols}", timecodesBar = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.timecode_color) .."\\3c&HFFFFFF\\fs27}", timePosBar = "{\\blur0\\bord".. user_opts.tooltipborder .."\\1c&H" .. osc_color_convert(user_opts.time_pos_color) .. "\\3c&H" .. osc_color_convert(user_opts.time_pos_outline_color) .. "\\fs30}", vidtitleBar = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.title_color) .. "\\3c&HFFFFFF\\fs18\\q2}", wcButtons = "{\\1c&H" .. osc_color_convert(user_opts.buttons_color) .. "\\fs24\\fnmpv-osd-symbols}", wcTitle = "{\\1c&H" .. osc_color_convert(user_opts.title_color) .. "\\fs24\\q2}", wcBar = "{\\1c&H" .. osc_color_convert(user_opts.background_color) .. "}", }end -- internal states, do not touchlocal state = { showtime = nil, -- time of last invocation (last mouse move) touchtime = nil, -- time of last invocation (last touch event) osc_visible = false, anistart = nil, -- time when the animation started anitype = nil, -- current type of animation animation = nil, -- current animation alpha mouse_down_counter = 0, -- used for softrepeat active_element = nil, -- nil = none, 0 = background, 1+ = see elements[] active_event_source = nil, -- the "button" that issued the current event rightTC_trem = not user_opts.timetotal, -- if the right timecode should display total or remaining time tc_ms = user_opts.timems, -- Should the timecodes display their time with milliseconds screen_sizeX = nil, screen_sizeY = nil, -- last screen-resolution, to detect resolution changes to issue reINITs initREQ = false, -- is a re-init request pending? marginsREQ = false, -- is a margins update pending? last_mouseX = nil, last_mouseY = nil, -- last mouse position, to detect significant mouse movement mouse_in_window = false, fullscreen = false, tick_timer = nil, tick_last_time = 0, -- when the last tick() was run hide_timer = nil, cache_state = nil, idle = false, enabled = true, input_enabled = true, showhide_enabled = false, windowcontrols_buttons = false, windowcontrols_title = false, dmx_cache = 0, using_video_margins = false, border = true, maximized = false, osd = mp.create_osd_overlay("ass-events"), chapter_list = {}, -- sorted by time} local logo_lines = { -- White border "{\\c&HE5E5E5&\\p6}m 895 10 b 401 10 0 410 0 905 0 1399 401 1800 895 1800 1390 1800 1790 1399 1790 905 1790 410 1390 10 895 10 {\\p0}", -- Purple fill "{\\c&H682167&\\p6}m 925 42 b 463 42 87 418 87 880 87 1343 463 1718 925 1718 1388 1718 1763 1343 1763 880 1763 418 1388 42 925 42{\\p0}", -- Darker fill "{\\c&H430142&\\p6}m 1605 828 b 1605 1175 1324 1456 977 1456 631 1456 349 1175 349 828 349 482 631 200 977 200 1324 200 1605 482 1605 828{\\p0}", -- White fill "{\\c&HDDDBDD&\\p6}m 1296 910 b 1296 1131 1117 1310 897 1310 676 1310 497 1131 497 910 497 689 676 511 897 511 1117 511 1296 689 1296 910{\\p0}", -- Triangle "{\\c&H691F69&\\p6}m 762 1113 l 762 708 b 881 776 1000 843 1119 911 1000 978 881 1046 762 1113{\\p0}",} local santa_hat_lines = { -- Pompoms "{\\c&HC0C0C0&\\p6}m 500 -323 b 491 -322 481 -318 475 -311 465 -312 456 -319 446 -318 434 -314 427 -304 417 -297 410 -290 404 -282 395 -278 390 -274 387 -267 381 -265 377 -261 379 -254 384 -253 397 -244 409 -232 425 -228 437 -228 446 -218 457 -217 462 -216 466 -213 468 -209 471 -205 477 -203 482 -206 491 -211 499 -217 508 -222 532 -235 556 -249 576 -267 584 -272 584 -284 578 -290 569 -305 550 -312 533 -309 523 -310 515 -316 507 -321 505 -323 503 -323 500 -323{\\p0}", "{\\c&HE0E0E0&\\p6}m 315 -260 b 286 -258 259 -240 246 -215 235 -210 222 -215 211 -211 204 -188 177 -176 172 -151 170 -139 163 -128 154 -121 143 -103 141 -81 143 -60 139 -46 125 -34 129 -17 132 -1 134 16 142 30 145 56 161 80 181 96 196 114 210 133 231 144 266 153 303 138 328 115 373 79 401 28 423 -24 446 -73 465 -123 483 -174 487 -199 467 -225 442 -227 421 -232 402 -242 384 -254 364 -259 342 -250 322 -260 320 -260 317 -261 315 -260{\\p0}", -- Main cap "{\\c&H0000F0&\\p6}m 1151 -523 b 1016 -516 891 -458 769 -406 693 -369 624 -319 561 -262 526 -252 465 -235 479 -187 502 -147 551 -135 588 -111 1115 165 1379 232 1909 761 1926 800 1952 834 1987 858 2020 883 2053 912 2065 952 2088 1000 2146 962 2139 919 2162 836 2156 747 2143 662 2131 615 2116 567 2122 517 2120 410 2090 306 2089 199 2092 147 2071 99 2034 64 1987 5 1928 -41 1869 -86 1777 -157 1712 -256 1629 -337 1578 -389 1521 -436 1461 -476 1407 -509 1343 -507 1284 -515 1240 -519 1195 -521 1151 -523{\\p0}", -- Cap shadow "{\\c&H0000AA&\\p6}m 1657 248 b 1658 254 1659 261 1660 267 1669 276 1680 284 1689 293 1695 302 1700 311 1707 320 1716 325 1726 330 1735 335 1744 347 1752 360 1761 371 1753 352 1754 331 1753 311 1751 237 1751 163 1751 90 1752 64 1752 37 1767 14 1778 -3 1785 -24 1786 -45 1786 -60 1786 -77 1774 -87 1760 -96 1750 -78 1751 -65 1748 -37 1750 -8 1750 20 1734 78 1715 134 1699 192 1694 211 1689 231 1676 246 1671 251 1661 255 1657 248 m 1909 541 b 1914 542 1922 549 1917 539 1919 520 1921 502 1919 483 1918 458 1917 433 1915 407 1930 373 1942 338 1947 301 1952 270 1954 238 1951 207 1946 214 1947 229 1945 239 1939 278 1936 318 1924 356 1923 362 1913 382 1912 364 1906 301 1904 237 1891 175 1887 150 1892 126 1892 101 1892 68 1893 35 1888 2 1884 -9 1871 -20 1859 -14 1851 -6 1854 9 1854 20 1855 58 1864 95 1873 132 1883 179 1894 225 1899 273 1908 362 1910 451 1909 541{\\p0}", -- Brim and tip pompom "{\\c&HF8F8F8&\\p6}m 626 -191 b 565 -155 486 -196 428 -151 387 -115 327 -101 304 -47 273 2 267 59 249 113 219 157 217 213 215 265 217 309 260 302 285 283 373 264 465 264 555 257 608 252 655 292 709 287 759 294 816 276 863 298 903 340 972 324 1012 367 1061 394 1125 382 1167 424 1213 462 1268 482 1322 506 1385 546 1427 610 1479 662 1510 690 1534 725 1566 752 1611 796 1664 830 1703 880 1740 918 1747 986 1805 1005 1863 991 1897 932 1916 880 1914 823 1945 777 1961 725 1979 673 1957 622 1938 575 1912 534 1862 515 1836 473 1790 417 1755 351 1697 305 1658 266 1633 216 1593 176 1574 138 1539 116 1497 110 1448 101 1402 77 1371 37 1346 -16 1295 15 1254 6 1211 -27 1170 -62 1121 -86 1072 -104 1027 -128 976 -133 914 -130 851 -137 794 -162 740 -181 679 -168 626 -191 m 2051 917 b 1971 932 1929 1017 1919 1091 1912 1149 1923 1214 1970 1254 2000 1279 2027 1314 2066 1325 2139 1338 2212 1295 2254 1238 2281 1203 2287 1158 2282 1116 2292 1061 2273 1006 2229 970 2206 941 2167 938 2138 918{\\p0}",}-- luacheck: pop ---- Helper functions-- local function kill_animation() state.anistart = nil state.animation = nil state.anitype = nilend local function set_osd(res_x, res_y, text, z) if state.osd.res_x == res_x and state.osd.res_y == res_y and state.osd.data == text then return end state.osd.res_x = res_x state.osd.res_y = res_y state.osd.data = text state.osd.z = z state.osd:update()end local function set_time_styles(timetotal_changed, timems_changed) if timetotal_changed then state.rightTC_trem = not user_opts.timetotal end if timems_changed then state.tc_ms = user_opts.timems endend -- scale factor for translating between real and virtual ASS coordinateslocal function get_virt_scale_factor() local w, h = mp.get_osd_size() if w <= 0 or h <= 0 then return 0, 0 end return osc_param.playresx / w, osc_param.playresy / hend -- return mouse position in virtual ASS coordinates (playresx/y)local function get_virt_mouse_pos() if state.mouse_in_window then local sx, sy = get_virt_scale_factor() local x, y = mp.get_mouse_pos() return x * sx, y * sy else return -1, -1 endend local function set_virt_mouse_area(x0, y0, x1, y1, name) local sx, sy = get_virt_scale_factor() mp.set_mouse_area(x0 / sx, y0 / sy, x1 / sx, y1 / sy, name)end local function scale_value(x0, x1, y0, y1, val) local m = (y1 - y0) / (x1 - x0) local b = y0 - (m * x0) return (m * val) + bend -- returns hitbox spanning coordinates (top left, bottom right corner)-- according to alignmentlocal function get_hitbox_coords(x, y, an, w, h) local alignments = { [1] = function () return x, y-h, x+w, y end, [2] = function () return x-(w/2), y-h, x+(w/2), y end, [3] = function () return x-w, y-h, x, y end, [4] = function () return x, y-(h/2), x+w, y+(h/2) end, [5] = function () return x-(w/2), y-(h/2), x+(w/2), y+(h/2) end, [6] = function () return x-w, y-(h/2), x, y+(h/2) end, [7] = function () return x, y, x+w, y+h end, [8] = function () return x-(w/2), y, x+(w/2), y+h end, [9] = function () return x-w, y, x, y+h end, } return alignments[an]()end local function get_hitbox_coords_geo(geometry) return get_hitbox_coords(geometry.x, geometry.y, geometry.an, geometry.w, geometry.h)end local function get_element_hitbox(element) return element.hitbox.x1, element.hitbox.y1, element.hitbox.x2, element.hitbox.y2end local function mouse_hit_coords(bX1, bY1, bX2, bY2) local mX, mY = get_virt_mouse_pos() return (mX >= bX1 and mX <= bX2 and mY >= bY1 and mY <= bY2)end local function mouse_hit(element) return mouse_hit_coords(get_element_hitbox(element))end local function limit_range(min, max, val) if val > max then val = max elseif val < min then val = min end return valend -- translate value into element coordinateslocal function get_slider_ele_pos_for(element, val) local ele_pos = scale_value( element.slider.min.value, element.slider.max.value, element.slider.min.ele_pos, element.slider.max.ele_pos, val) return limit_range( element.slider.min.ele_pos, element.slider.max.ele_pos, ele_pos)end -- translates global (mouse) coordinates to valuelocal function get_slider_value_at(element, glob_pos) local val = scale_value( element.slider.min.glob_pos, element.slider.max.glob_pos, element.slider.min.value, element.slider.max.value, glob_pos) return limit_range( element.slider.min.value, element.slider.max.value, val)end -- get value at current mouse positionlocal function get_slider_value(element) return get_slider_value_at(element, get_virt_mouse_pos())end -- align: -1 .. +1-- frame: size of the containing area-- obj: size of the object that should be positioned inside the area-- margin: min. distance from object to frame (as long as -1 <= align <= +1)local function get_align(align, frame, obj, margin) return (frame / 2) + (((frame / 2) - margin - (obj / 2)) * align)end -- multiplies two alpha values, formular can probably be improvedlocal function mult_alpha(alphaA, alphaB) return 255 - (((1-(alphaA/255)) * (1-(alphaB/255))) * 255)end local function add_area(name, x1, y1, x2, y2) -- create area if needed if osc_param.areas[name] == nil then osc_param.areas[name] = {} end table.insert(osc_param.areas[name], {x1=x1, y1=y1, x2=x2, y2=y2})end local function ass_append_alpha(ass, alpha, modifier) local ar = {} for ai, av in pairs(alpha) do av = mult_alpha(av, modifier) if state.animation then av = mult_alpha(av, state.animation) end ar[ai] = av end ass:append(string.format("{\\1a&H%X&\\2a&H%X&\\3a&H%X&\\4a&H%X&}", ar[1], ar[2], ar[3], ar[4]))end local function ass_draw_rr_h_cw(ass, x0, y0, x1, y1, r1, hexagon, r2) if hexagon then ass:hexagon_cw(x0, y0, x1, y1, r1, r2) else ass:round_rect_cw(x0, y0, x1, y1, r1, r2) endend local function ass_draw_rr_h_ccw(ass, x0, y0, x1, y1, r1, hexagon, r2) if hexagon then ass:hexagon_ccw(x0, y0, x1, y1, r1, r2) else ass:round_rect_ccw(x0, y0, x1, y1, r1, r2) endend local function get_hidetimeout() if user_opts.visibility == "always" then return -1 -- disable autohide end return user_opts.hidetimeoutend local function get_touchtimeout() if state.touchtime == nil then return 0 end return state.touchtime + (get_hidetimeout() / 1000) - mp.get_time()end local function reset_margins() if state.using_video_margins then for _, mopt in ipairs(margins_opts) do mp.set_property_number(mopt[2], 0.0) end state.using_video_margins = false endend local function update_margins() local margins = osc_param.video_margins -- Don't use margins if it's visible only temporarily. if not state.osc_visible or get_hidetimeout() >= 0 or (state.fullscreen and not user_opts.showfullscreen) or (not state.fullscreen and not user_opts.showwindowed) then margins = {l = 0, r = 0, t = 0, b = 0} end if user_opts.boxvideo then -- check whether any margin option has a non-default value local margins_used = false if not state.using_video_margins then for _, mopt in ipairs(margins_opts) do if mp.get_property_number(mopt[2], 0.0) ~= 0.0 then margins_used = true end end end if not margins_used then for _, mopt in ipairs(margins_opts) do local v = margins[mopt[1]] if v ~= 0 or state.using_video_margins then mp.set_property_number(mopt[2], v) state.using_video_margins = true end end end else reset_margins() end mp.set_property_native("user-data/osc/margins", margins)end Lines 1–500 of 2831. Load more
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 osc.conf local user_opts = { showwindowed = true, -- show OSC when windowed? showfullscreen = true, -- show OSC when fullscreen? idlescreen = true, -- show mpv logo on idle scalewindowed = 1, -- scaling of the controller when windowed scalefullscreen = 1, -- scaling of the controller when fullscreen vidscale = "auto", -- scale the controller with the video? valign = 0.8, -- vertical alignment, -1 (top) to 1 (bottom) halign = 0, -- horizontal alignment, -1 (left) to 1 (right) barmargin = 0, -- vertical margin of top/bottombar boxalpha = 80, -- alpha of the background box, -- 0 (opaque) to 255 (fully transparent) hidetimeout = 500, -- duration in ms until the OSC hides if no -- mouse movement. enforced non-negative for the -- user, but internally negative is "always-on". fadeduration = 200, -- duration of fade out in ms, 0 = no fade deadzonesize = 0.5, -- size of deadzone minmousemove = 0, -- minimum amount of pixels the mouse has to -- move between ticks to make the OSC show up layout = "bottombar", seekbarstyle = "bar", -- bar, diamond or knob seekbarhandlesize = 0.6, -- size ratio of the diamond and knob handle seekrangestyle = "inverted",-- bar, line, slider, inverted or none seekrangeseparate = true, -- whether the seekranges overlay on the bar-style seekbar seekrangealpha = 200, -- transparency of seekranges seekbarkeyframes = true, -- use keyframes when dragging the seekbar scrollcontrols = true, -- allow scrolling when hovering certain OSC elements title = "${!playlist-count==1:[${playlist-pos-1}/${playlist-count}] }${media-title}", -- to be shown as OSC title tooltipborder = 1, -- border of tooltip in bottom/topbar timetotal = false, -- display total time instead of remaining time? remaining_playtime = true, -- display the remaining time in playtime or video-time mode -- playtime takes speed into account, whereas video-time doesn't timems = false, -- display timecodes with milliseconds? tcspace = 100, -- timecode spacing (compensate font size estimation) visibility = "auto", -- only used at init to set visibility_mode(...) boxmaxchars = 80, -- title crop threshold for box layout boxvideo = false, -- apply osc_param.video_margins to video windowcontrols = "auto", -- whether to show window controls windowcontrols_alignment = "right", -- which side to show window controls on windowcontrols_title = "${media-title}", -- same as title but for windowcontrols greenandgrumpy = false, -- disable santa hat livemarkers = true, -- update seekbar chapter markers on duration change chapter_fmt = "Chapter: %s", -- chapter print format for seekbar-hover. "no" to disable unicodeminus = false, -- whether to use the Unicode minus sign character background_color = "#000000", -- background color of the osc timecode_color = "#FFFFFF", -- color of the progress bar and time color title_color = "#FFFFFF", -- color of the title time_pos_color = "#FFFFFF", -- color of the timecode at hovered position buttons_color = "#FFFFFF", -- color of big buttons, wc buttons, and bar small buttons small_buttonsL_color = "#FFFFFF", -- color of left small buttons small_buttonsR_color = "#FFFFFF", -- color of right small buttons top_buttons_color = "#FFFFFF", -- color of top buttons held_element_color = "#999999", -- color of an element while held down time_pos_outline_color = "#000000", -- color of the border timecodes in slimbox and TimePosBar tick_delay = 1 / 60, -- minimum interval between OSC redraws in seconds tick_delay_follow_display_fps = false, -- use display fps as the minimum interval -- luacheck: push ignore -- luacheck: max line length title_mbtn_left_command = "script-binding select/select-playlist; script-message-to osc osc-hide", title_mbtn_mid_command = "show-text ${filename}", title_mbtn_right_command = "script-binding stats/display-page-5", playlist_prev_mbtn_left_command = "playlist-prev", playlist_prev_mbtn_mid_command = "show-text ${playlist} 3000", playlist_prev_mbtn_right_command = "show-text ${playlist} 3000", playlist_next_mbtn_left_command = "playlist-next", playlist_next_mbtn_mid_command = "show-text ${playlist} 3000", playlist_next_mbtn_right_command = "show-text ${playlist} 3000", play_pause_mbtn_left_command = "cycle pause", play_pause_mbtn_mid_command = "", play_pause_mbtn_right_command = "cycle-values loop-file inf no", chapter_prev_mbtn_left_command = "osd-msg add chapter -1", chapter_prev_mbtn_mid_command = "show-text ${chapter-list} 3000", chapter_prev_mbtn_right_command = "script-binding select/select-chapter; script-message-to osc osc-hide", chapter_next_mbtn_left_command = "osd-msg add chapter 1", 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_mid_command = "show-text ${track-list/audio} 3000", audio_track_mbtn_right_command = "cycle audio", 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_mid_command = "show-text ${track-list/sub} 3000", sub_track_mbtn_right_command = "cycle sub", sub_track_wheel_down_command = "cycle sub", sub_track_wheel_up_command = "cycle sub down", volume_mbtn_left_command = "no-osd cycle mute", volume_mbtn_mid_command = "", volume_mbtn_right_command = "script-binding select/select-audio-device; script-message-to osc osc-hide", volume_wheel_down_command = "add volume -5", volume_wheel_up_command = "add volume 5", fullscreen_mbtn_left_command = "cycle fullscreen", fullscreen_mbtn_mid_command = "", fullscreen_mbtn_right_command = "cycle window-maximized", -- luacheck: pop } local osc_param = { -- calculated by osc_init() playresy = 0, -- canvas size Y playresx = 0, -- canvas size X display_aspect = 1, unscaled_y = 0, areas = {}, video_margins = { l = 0, r = 0, t = 0, b = 0, -- left/right/top/bottom }, } local margins_opts = { {"l", "video-margin-ratio-left"}, {"r", "video-margin-ratio-right"}, {"t", "video-margin-ratio-top"}, {"b", "video-margin-ratio-bottom"}, } local tick_delay = 1 / 60 local audio_track_count = 0 local sub_track_count = 0 local window_control_box_width = 80 local layouts = {} local is_december = os.date("*t").month == 12 local UNICODE_MINUS = string.char(0xe2, 0x88, 0x92) -- UTF-8 for U+2212 MINUS SIGN local function osc_color_convert(color) return color:sub(6,7) .. color:sub(4,5) .. color:sub(2,3) end -- luacheck: push ignore -- luacheck: max line length local osc_styles local function set_osc_styles() osc_styles = { bigButtons = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.buttons_color) .. "\\3c&HFFFFFF\\fs50\\fnmpv-osd-symbols}", smallButtonsL = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.small_buttonsL_color) .. "\\3c&HFFFFFF\\fs19\\fnmpv-osd-symbols}", smallButtonsLlabel = "{\\fscx105\\fscy105\\fn" .. mp.get_property("options/osd-font") .. "}", smallButtonsR = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.small_buttonsR_color) .. "\\3c&HFFFFFF\\fs30\\fnmpv-osd-symbols}", topButtons = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.top_buttons_color) .. "\\3c&HFFFFFF\\fs12\\fnmpv-osd-symbols}", elementDown = "{\\1c&H" .. osc_color_convert(user_opts.held_element_color) .."}", timecodes = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.timecode_color) .. "\\3c&HFFFFFF\\fs20}", vidtitle = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.title_color) .. "\\3c&HFFFFFF\\fs14\\q2}", box = "{\\rDefault\\blur0\\bord1\\1c&H" .. osc_color_convert(user_opts.background_color) .. "\\3c&HFFFFFF}", topButtonsBar = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.top_buttons_color) .. "\\3c&HFFFFFF\\fs18\\fnmpv-osd-symbols}", smallButtonsBar = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.buttons_color) .. "\\3c&HFFFFFF\\fs28\\fnmpv-osd-symbols}", timecodesBar = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.timecode_color) .."\\3c&HFFFFFF\\fs27}", timePosBar = "{\\blur0\\bord".. user_opts.tooltipborder .."\\1c&H" .. osc_color_convert(user_opts.time_pos_color) .. "\\3c&H" .. osc_color_convert(user_opts.time_pos_outline_color) .. "\\fs30}", vidtitleBar = "{\\blur0\\bord0\\1c&H" .. osc_color_convert(user_opts.title_color) .. "\\3c&HFFFFFF\\fs18\\q2}", wcButtons = "{\\1c&H" .. osc_color_convert(user_opts.buttons_color) .. "\\fs24\\fnmpv-osd-symbols}", wcTitle = "{\\1c&H" .. osc_color_convert(user_opts.title_color) .. "\\fs24\\q2}", wcBar = "{\\1c&H" .. osc_color_convert(user_opts.background_color) .. "}", } end -- internal states, do not touch local state = { showtime = nil, -- time of last invocation (last mouse move) touchtime = nil, -- time of last invocation (last touch event) osc_visible = false, anistart = nil, -- time when the animation started anitype = nil, -- current type of animation animation = nil, -- current animation alpha mouse_down_counter = 0, -- used for softrepeat active_element = nil, -- nil = none, 0 = background, 1+ = see elements[] active_event_source = nil, -- the "button" that issued the current event rightTC_trem = not user_opts.timetotal, -- if the right timecode should display total or remaining time tc_ms = user_opts.timems, -- Should the timecodes display their time with milliseconds screen_sizeX = nil, screen_sizeY = nil, -- last screen-resolution, to detect resolution changes to issue reINITs initREQ = false, -- is a re-init request pending? marginsREQ = false, -- is a margins update pending? last_mouseX = nil, last_mouseY = nil, -- last mouse position, to detect significant mouse movement mouse_in_window = false, fullscreen = false, tick_timer = nil, tick_last_time = 0, -- when the last tick() was run hide_timer = nil, cache_state = nil, idle = false, enabled = true, input_enabled = true, showhide_enabled = false, windowcontrols_buttons = false, windowcontrols_title = false, dmx_cache = 0, using_video_margins = false, border = true, maximized = false, osd = mp.create_osd_overlay("ass-events"), chapter_list = {}, -- sorted by time } local logo_lines = { -- White border "{\\c&HE5E5E5&\\p6}m 895 10 b 401 10 0 410 0 905 0 1399 401 1800 895 1800 1390 1800 1790 1399 1790 905 1790 410 1390 10 895 10 {\\p0}", -- Purple fill "{\\c&H682167&\\p6}m 925 42 b 463 42 87 418 87 880 87 1343 463 1718 925 1718 1388 1718 1763 1343 1763 880 1763 418 1388 42 925 42{\\p0}", -- Darker fill "{\\c&H430142&\\p6}m 1605 828 b 1605 1175 1324 1456 977 1456 631 1456 349 1175 349 828 349 482 631 200 977 200 1324 200 1605 482 1605 828{\\p0}", -- White fill "{\\c&HDDDBDD&\\p6}m 1296 910 b 1296 1131 1117 1310 897 1310 676 1310 497 1131 497 910 497 689 676 511 897 511 1117 511 1296 689 1296 910{\\p0}", -- Triangle "{\\c&H691F69&\\p6}m 762 1113 l 762 708 b 881 776 1000 843 1119 911 1000 978 881 1046 762 1113{\\p0}", } local santa_hat_lines = { -- Pompoms "{\\c&HC0C0C0&\\p6}m 500 -323 b 491 -322 481 -318 475 -311 465 -312 456 -319 446 -318 434 -314 427 -304 417 -297 410 -290 404 -282 395 -278 390 -274 387 -267 381 -265 377 -261 379 -254 384 -253 397 -244 409 -232 425 -228 437 -228 446 -218 457 -217 462 -216 466 -213 468 -209 471 -205 477 -203 482 -206 491 -211 499 -217 508 -222 532 -235 556 -249 576 -267 584 -272 584 -284 578 -290 569 -305 550 -312 533 -309 523 -310 515 -316 507 -321 505 -323 503 -323 500 -323{\\p0}", "{\\c&HE0E0E0&\\p6}m 315 -260 b 286 -258 259 -240 246 -215 235 -210 222 -215 211 -211 204 -188 177 -176 172 -151 170 -139 163 -128 154 -121 143 -103 141 -81 143 -60 139 -46 125 -34 129 -17 132 -1 134 16 142 30 145 56 161 80 181 96 196 114 210 133 231 144 266 153 303 138 328 115 373 79 401 28 423 -24 446 -73 465 -123 483 -174 487 -199 467 -225 442 -227 421 -232 402 -242 384 -254 364 -259 342 -250 322 -260 320 -260 317 -261 315 -260{\\p0}", -- Main cap "{\\c&H0000F0&\\p6}m 1151 -523 b 1016 -516 891 -458 769 -406 693 -369 624 -319 561 -262 526 -252 465 -235 479 -187 502 -147 551 -135 588 -111 1115 165 1379 232 1909 761 1926 800 1952 834 1987 858 2020 883 2053 912 2065 952 2088 1000 2146 962 2139 919 2162 836 2156 747 2143 662 2131 615 2116 567 2122 517 2120 410 2090 306 2089 199 2092 147 2071 99 2034 64 1987 5 1928 -41 1869 -86 1777 -157 1712 -256 1629 -337 1578 -389 1521 -436 1461 -476 1407 -509 1343 -507 1284 -515 1240 -519 1195 -521 1151 -523{\\p0}", -- Cap shadow "{\\c&H0000AA&\\p6}m 1657 248 b 1658 254 1659 261 1660 267 1669 276 1680 284 1689 293 1695 302 1700 311 1707 320 1716 325 1726 330 1735 335 1744 347 1752 360 1761 371 1753 352 1754 331 1753 311 1751 237 1751 163 1751 90 1752 64 1752 37 1767 14 1778 -3 1785 -24 1786 -45 1786 -60 1786 -77 1774 -87 1760 -96 1750 -78 1751 -65 1748 -37 1750 -8 1750 20 1734 78 1715 134 1699 192 1694 211 1689 231 1676 246 1671 251 1661 255 1657 248 m 1909 541 b 1914 542 1922 549 1917 539 1919 520 1921 502 1919 483 1918 458 1917 433 1915 407 1930 373 1942 338 1947 301 1952 270 1954 238 1951 207 1946 214 1947 229 1945 239 1939 278 1936 318 1924 356 1923 362 1913 382 1912 364 1906 301 1904 237 1891 175 1887 150 1892 126 1892 101 1892 68 1893 35 1888 2 1884 -9 1871 -20 1859 -14 1851 -6 1854 9 1854 20 1855 58 1864 95 1873 132 1883 179 1894 225 1899 273 1908 362 1910 451 1909 541{\\p0}", -- Brim and tip pompom "{\\c&HF8F8F8&\\p6}m 626 -191 b 565 -155 486 -196 428 -151 387 -115 327 -101 304 -47 273 2 267 59 249 113 219 157 217 213 215 265 217 309 260 302 285 283 373 264 465 264 555 257 608 252 655 292 709 287 759 294 816 276 863 298 903 340 972 324 1012 367 1061 394 1125 382 1167 424 1213 462 1268 482 1322 506 1385 546 1427 610 1479 662 1510 690 1534 725 1566 752 1611 796 1664 830 1703 880 1740 918 1747 986 1805 1005 1863 991 1897 932 1916 880 1914 823 1945 777 1961 725 1979 673 1957 622 1938 575 1912 534 1862 515 1836 473 1790 417 1755 351 1697 305 1658 266 1633 216 1593 176 1574 138 1539 116 1497 110 1448 101 1402 77 1371 37 1346 -16 1295 15 1254 6 1211 -27 1170 -62 1121 -86 1072 -104 1027 -128 976 -133 914 -130 851 -137 794 -162 740 -181 679 -168 626 -191 m 2051 917 b 1971 932 1929 1017 1919 1091 1912 1149 1923 1214 1970 1254 2000 1279 2027 1314 2066 1325 2139 1338 2212 1295 2254 1238 2281 1203 2287 1158 2282 1116 2292 1061 2273 1006 2229 970 2206 941 2167 938 2138 918{\\p0}", } -- luacheck: pop -- -- Helper functions -- local function kill_animation() state.anistart = nil state.animation = nil state.anitype = nil end local function set_osd(res_x, res_y, text, z) if state.osd.res_x == res_x and state.osd.res_y == res_y and state.osd.data == text then return end state.osd.res_x = res_x state.osd.res_y = res_y state.osd.data = text state.osd.z = z state.osd:update() end local function set_time_styles(timetotal_changed, timems_changed) if timetotal_changed then state.rightTC_trem = not user_opts.timetotal end if timems_changed then state.tc_ms = user_opts.timems end end -- scale factor for translating between real and virtual ASS coordinates local function get_virt_scale_factor() local w, h = mp.get_osd_size() if w <= 0 or h <= 0 then return 0, 0 end return osc_param.playresx / w, osc_param.playresy / h end -- return mouse position in virtual ASS coordinates (playresx/y) local function get_virt_mouse_pos() if state.mouse_in_window then local sx, sy = get_virt_scale_factor() local x, y = mp.get_mouse_pos() return x * sx, y * sy else return -1, -1 end end local function set_virt_mouse_area(x0, y0, x1, y1, name) local sx, sy = get_virt_scale_factor() mp.set_mouse_area(x0 / sx, y0 / sy, x1 / sx, y1 / sy, name) end local function scale_value(x0, x1, y0, y1, val) local m = (y1 - y0) / (x1 - x0) local b = y0 - (m * x0) return (m * val) + b end -- returns hitbox spanning coordinates (top left, bottom right corner) -- according to alignment local function get_hitbox_coords(x, y, an, w, h) local alignments = { [1] = function () return x, y-h, x+w, y end, [2] = function () return x-(w/2), y-h, x+(w/2), y end, [3] = function () return x-w, y-h, x, y end, [4] = function () return x, y-(h/2), x+w, y+(h/2) end, [5] = function () return x-(w/2), y-(h/2), x+(w/2), y+(h/2) end, [6] = function () return x-w, y-(h/2), x, y+(h/2) end, [7] = function () return x, y, x+w, y+h end, [8] = function () return x-(w/2), y, x+(w/2), y+h end, [9] = function () return x-w, y, x, y+h end, } return alignments[an]() end local function get_hitbox_coords_geo(geometry) return get_hitbox_coords(geometry.x, geometry.y, geometry.an, geometry.w, geometry.h) end local function get_element_hitbox(element) return element.hitbox.x1, element.hitbox.y1, element.hitbox.x2, element.hitbox.y2 end local function mouse_hit_coords(bX1, bY1, bX2, bY2) local mX, mY = get_virt_mouse_pos() return (mX >= bX1 and mX <= bX2 and mY >= bY1 and mY <= bY2) end local function mouse_hit(element) return mouse_hit_coords(get_element_hitbox(element)) end local function limit_range(min, max, val) if val > max then val = max elseif val < min then val = min end return val end -- translate value into element coordinates local function get_slider_ele_pos_for(element, val) local ele_pos = scale_value( element.slider.min.value, element.slider.max.value, element.slider.min.ele_pos, element.slider.max.ele_pos, val) return limit_range( element.slider.min.ele_pos, element.slider.max.ele_pos, ele_pos) end -- translates global (mouse) coordinates to value local function get_slider_value_at(element, glob_pos) local val = scale_value( element.slider.min.glob_pos, element.slider.max.glob_pos, element.slider.min.value, element.slider.max.value, glob_pos) return limit_range( element.slider.min.value, element.slider.max.value, val) end -- get value at current mouse position local function get_slider_value(element) return get_slider_value_at(element, get_virt_mouse_pos()) end -- align: -1 .. +1 -- frame: size of the containing area -- obj: size of the object that should be positioned inside the area -- margin: min. distance from object to frame (as long as -1 <= align <= +1) local function get_align(align, frame, obj, margin) return (frame / 2) + (((frame / 2) - margin - (obj / 2)) * align) end -- multiplies two alpha values, formular can probably be improved local function mult_alpha(alphaA, alphaB) return 255 - (((1-(alphaA/255)) * (1-(alphaB/255))) * 255) end local function add_area(name, x1, y1, x2, y2) -- create area if needed if osc_param.areas[name] == nil then osc_param.areas[name] = {} end table.insert(osc_param.areas[name], {x1=x1, y1=y1, x2=x2, y2=y2}) end local function ass_append_alpha(ass, alpha, modifier) local ar = {} for ai, av in pairs(alpha) do av = mult_alpha(av, modifier) if state.animation then av = mult_alpha(av, state.animation) end ar[ai] = av end ass:append(string.format("{\\1a&H%X&\\2a&H%X&\\3a&H%X&\\4a&H%X&}", ar[1], ar[2], ar[3], ar[4])) end local function ass_draw_rr_h_cw(ass, x0, y0, x1, y1, r1, hexagon, r2) if hexagon then ass:hexagon_cw(x0, y0, x1, y1, r1, r2) else ass:round_rect_cw(x0, y0, x1, y1, r1, r2) end end local function ass_draw_rr_h_ccw(ass, x0, y0, x1, y1, r1, hexagon, r2) if hexagon then ass:hexagon_ccw(x0, y0, x1, y1, r1, r2) else ass:round_rect_ccw(x0, y0, x1, y1, r1, r2) end end local function get_hidetimeout() if user_opts.visibility == "always" then return -1 -- disable autohide end return user_opts.hidetimeout end local function get_touchtimeout() if state.touchtime == nil then return 0 end return state.touchtime + (get_hidetimeout() / 1000) - mp.get_time() end local function reset_margins() if state.using_video_margins then for _, mopt in ipairs(margins_opts) do mp.set_property_number(mopt[2], 0.0) end state.using_video_margins = false end end local function update_margins() local margins = osc_param.video_margins -- Don't use margins if it's visible only temporarily. if not state.osc_visible or get_hidetimeout() >= 0 or (state.fullscreen and not user_opts.showfullscreen) or (not state.fullscreen and not user_opts.showwindowed) then margins = {l = 0, r = 0, t = 0, b = 0} end if user_opts.boxvideo then -- check whether any margin option has a non-default value local margins_used = false if not state.using_video_margins then for _, mopt in ipairs(margins_opts) do if mp.get_property_number(mopt[2], 0.0) ~= 0.0 then margins_used = true end end end if not margins_used then for _, mopt in ipairs(margins_opts) do local v = margins[mopt[1]] if v ~= 0 or state.using_video_margins then mp.set_property_number(mopt[2], v) state.using_video_margins = true end end end else reset_margins() end mp.set_property_native("user-data/osc/margins", margins) end