]> git.sesse.net Git - ultimatescore/blobdiff - nageru/ultimate.lua
Find the location of the HTML file from the location of the Nageru theme.
[ultimatescore] / nageru / ultimate.lua
index ecd43c72c23517d0b29f18cb2cf2cf28475ab07e..7d06451c8f1378fa7f48cdc6147979cc8ef50c12 100644 (file)
@@ -9,7 +9,9 @@ local transition_dst_signal = 0
 local neutral_colors = {
        {0.5, 0.5, 0.5},  -- Input 0.
        {0.5, 0.5, 0.5},  -- Input 1.
-       {0.5, 0.5, 0.5}   -- Input 2.
+       {0.5, 0.5, 0.5},  -- Input 2.
+       {0.5, 0.5, 0.5},  -- Input 3.
+       {0.5, 0.5, 0.5}   -- Input 4.
 }
 
 local overlay_transition_start = -2.0
@@ -20,16 +22,19 @@ local overlay_enabled = false
 
 local live_signal_num = 0
 local preview_signal_num = 1
+local NUM_CAMERAS = 5  -- Remember to update neutral_colors, too.
 
 -- Valid values for live_signal_num and preview_signal_num.
 local INPUT0_SIGNAL_NUM = 0
 local INPUT1_SIGNAL_NUM = 1
 local INPUT2_SIGNAL_NUM = 2
-local STATIC_SIGNAL_NUM = 3
+local INPUT3_SIGNAL_NUM = 3
+local INPUT4_SIGNAL_NUM = 4
+local STATIC_SIGNAL_NUM = NUM_CAMERAS
 
 -- Preview-only signal showing the current signal with the overlay.
 -- Not valid for live_signal_num!
-local OVERLAY_SIGNAL_NUM = 4
+local OVERLAY_SIGNAL_NUM = NUM_CAMERAS + 1
 
 -- Valid values for transition_type. (Cuts are done directly, so they need no entry.)
 local NO_TRANSITION = 0
@@ -40,8 +45,14 @@ local FADE_TRANSITION = 2
 -- frame and not per field, since we deinterlace.
 local last_resolution = {}
 
-local caspar_input = VideoInput.new("unix:///tmp/caspar.sock", Nageru.VIDEO_FORMAT_BGRA)
-caspar_input:change_rate(2.0)
+local cef_path = Nageru.THEME_PATH:match("(.*)/nageru/")
+local cef_input = HTMLInput.new("file://" .. cef_path .. "/score.html")
+cef_input:execute_javascript_async("play()")
+
+function reload_cef()
+       cef_input:reload()
+       cef_input:execute_javascript_async("play()")
+end
 
 -- Utility function to help creating many similar chains that can differ
 -- in a free set of chosen parameters.
@@ -63,7 +74,7 @@ end
 
 -- An overlay with variable alpha.
 function make_overlay(chain, base)
-       local image = chain:add_video_input(caspar_input, false)
+       local image = chain:add_html_input(cef_input)
        local multiply_effect = chain:add_effect(MultiplyEffect.new())
        local overlay_effect = chain:add_effect(OverlayEffect.new(), base, multiply_effect)
        return {
@@ -228,7 +239,7 @@ end)
 -- A chain to show the overlay and nothing more. LQ only,
 -- since it is not a valid live signal.
 local overlay_chain_lq = EffectChain.new(16, 9)
-local overlay_chain_lq_input = overlay_chain_lq:add_video_input(caspar_input, false)
+local overlay_chain_lq_input = overlay_chain_lq:add_html_input(cef_input)
 overlay_chain_lq:finalize(false)
 
 -- Used for indexing into the tables of chains.
@@ -265,11 +276,11 @@ end
 -- Returns the number of outputs in addition to the live (0) and preview (1).
 -- Called only once, at the start of the program.
 function num_channels()
-       return 5
+       return NUM_CAMERAS + 2  -- static picture and overlay
 end
 
 function is_plain_signal(num)
-       return num >= INPUT0_SIGNAL_NUM and num <= INPUT2_SIGNAL_NUM
+       return num >= INPUT0_SIGNAL_NUM and num <= INPUT4_SIGNAL_NUM
 end
 
 -- Helper function to write e.g. “720p60”. The difference between this
@@ -320,12 +331,16 @@ end
 -- channels in case they change resolution.
 function channel_name(channel)
        local signal_num = channel - 2
-       if signal_num == 0 then
+       if signal_num == INPUT0_SIGNAL_NUM then
                return "Main (" .. get_channel_resolution(signal_num) .. ")"
-       elseif signal_num == 1 then
-               return "Goal 1 (" .. get_channel_resolution(signal_num) .. ")"
-       elseif signal_num == 2 then
-               return "Goal 2 (" .. get_channel_resolution(signal_num) .. ")"
+       elseif signal_num == INPUT1_SIGNAL_NUM then
+               return "Secondary (" .. get_channel_resolution(signal_num) .. ")"
+       elseif signal_num == INPUT2_SIGNAL_NUM then
+               return "Goal L (" .. get_channel_resolution(signal_num) .. ")"
+       elseif signal_num == INPUT3_SIGNAL_NUM then
+               return "Goal R (" .. get_channel_resolution(signal_num) .. ")"
+       elseif signal_num == INPUT4_SIGNAL_NUM then
+               return "Ambience (" .. get_channel_resolution(signal_num) .. ")"
        elseif signal_num == STATIC_SIGNAL_NUM then
                return "Static picture"
        elseif signal_num == OVERLAY_SIGNAL_NUM then
@@ -341,10 +356,8 @@ end
 -- Called once for each channel, at the start of the program.
 -- Will never be called for live (0) or preview (1).
 function channel_signal(channel)
-       if channel == 2 then
-               return 0
-       elseif channel == 3 then
-               return 1
+       if is_plain_signal(channel - 2) then
+               return channel - 2
        else
                return -1
        end
@@ -377,7 +390,7 @@ function channel_involved_in(channel, signal_num)
                return channel == (signal_num + 2)
        end
        if signal_num == STATIC_SIGNAL_NUM then
-               return (channel == 5)
+               return (channel == NUM_CAMERAS)
        end
        return false
 end
@@ -593,7 +606,7 @@ end
 -- if and only if num==0.
 function get_chain(num, t, width, height, signals)
        local input_resolution = {}
-       for signal_num=0,2 do
+       for signal_num=0,(NUM_CAMERAS-1) do
                local res = {
                        width = signals:get_width(signal_num),
                        height = signals:get_height(signal_num),
@@ -753,3 +766,7 @@ function calc_fade_progress(t, transition_start, transition_end)
 
        return tt
 end
+
+ThemeMenu.set(
+       { "Reload overlay", reload_cef }
+)