]> 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 ceaef45da90bbbe2b4c87b518cf02ba5474dfdba..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")
-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 {
@@ -122,8 +133,26 @@ function make_fade_chain(input0_live, input0_deint, input0_scale, input1_live, i
        local input0 = make_fade_input(chain, INPUT0_SIGNAL_NUM, input0_live, input0_deint, input0_scale)
        local input1 = make_fade_input(chain, INPUT1_SIGNAL_NUM, input1_live, input1_deint, input1_scale)
 
+       -- If fading between two live inputs, the overlay is put on top.
+       -- If fading between the static picture and a live input,
+       -- the overlay is put on the live input.
+       local overlay = nil
+       if input0_live and not input1_live then
+               overlay = possibly_make_overlay(has_overlay, chain, input0.last)
+               if overlay then
+                       input0.last = overlay.overlay_effect
+               end
+       elseif input1_live and not input0_live then
+               overlay = possibly_make_overlay(has_overlay, chain, input1.last)
+               if overlay then
+                       input1.last = overlay.overlay_effect
+               end
+       end
+
        local mix_effect = chain:add_effect(MixEffect.new(), input0.last, input1.last)
-       local overlay = possibly_make_overlay(has_overlay, chain, mix_effect)
+       if input0_live and input1_live then
+               overlay = possibly_make_overlay(has_overlay, chain, mix_effect)
+       end
 
        chain:finalize(hq)
 
@@ -194,26 +223,23 @@ local simple_chains = make_cartesian_product({
        return make_simple_chain(input_deint, input_scale, has_overlay, hq)
 end)
 
--- A chain to show a single static picture on screen.
+-- A chain to show a single static picture on screen. Never with CasparCG overlay.
 local static_chains = make_cartesian_product({
-       {true, false},           -- has_overlay
        {true, false}            -- hq
-}, function(has_overlay, hq)
+}, function(hq)
        local chain = EffectChain.new(16, 9)
        local chain_input = chain:add_effect(ImageInput.new("tfk_pause.png"))
-       local overlay = possibly_make_overlay(has_overlay, chain, chain_input)
 
        chain:finalize(hq)
        return {
-               chain = chain,
-               overlay = overlay
+               chain = chain
        }
 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.
@@ -250,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
@@ -305,8 +331,16 @@ end
 -- channels in case they change resolution.
 function channel_name(channel)
        local signal_num = channel - 2
-       if is_plain_signal(signal_num) then
-               return "Input " .. (signal_num + 1) .. " (" .. get_channel_resolution(signal_num) .. ")"
+       if signal_num == INPUT0_SIGNAL_NUM then
+               return "Main (" .. 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
@@ -322,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
@@ -358,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
@@ -574,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),
@@ -617,7 +649,7 @@ function get_chain(num, t, width, height, signals)
                        end
                        return chain.chain, prepare
                elseif live_signal_num == STATIC_SIGNAL_NUM then  -- Static picture.
-                       local chain = static_chains[overlay_enabled][true]
+                       local chain = static_chains[true]
                        prepare = function()
                                prepare_overlay_live(chain, t)
                        end
@@ -659,7 +691,7 @@ function get_chain(num, t, width, height, signals)
                return chain.chain, prepare
        end
        if num == STATIC_SIGNAL_NUM + 2 then
-               local chain = static_chains[show_overlay][false]
+               local chain = static_chains[false]
                prepare = function()
                        prepare_overlay_static(chain, t)
                end
@@ -734,3 +766,7 @@ function calc_fade_progress(t, transition_start, transition_end)
 
        return tt
 end
+
+ThemeMenu.set(
+       { "Reload overlay", reload_cef }
+)