]> git.sesse.net Git - nageru/blobdiff - theme.lua
Fix an off-by-one in the indexing.
[nageru] / theme.lua
index c2014141c3e94a6597dc650d92256c35bf51cc45..e8adb6cde8390d8e7f13c80e25899ef23fda29df 100644 (file)
--- a/theme.lua
+++ b/theme.lua
@@ -31,7 +31,7 @@ local STATIC_SIGNAL_NUM = 3
 -- to the next.
 local FADE_SIGNAL_NUM = 4
 
--- Last width/height/resolution for each channel, if we have it.
+-- Last width/height/frame rate for each channel, if we have it.
 -- Note that unlike the values we get from Nageru, the resolution is per
 -- frame and not per field, since we deinterlace.
 local last_resolution = {}
@@ -57,7 +57,6 @@ end
 function make_sbs_input(chain, signal, deint, hq)
        local input = chain:add_live_input(not deint, deint)  -- Override bounce only if not deinterlacing.
        input:connect_signal(signal)
-       local wb_effect = chain:add_effect(WhiteBalanceEffect.new())
 
        local resample_effect = nil
        local resize_effect = nil
@@ -66,6 +65,7 @@ function make_sbs_input(chain, signal, deint, hq)
        else
                resize_effect = chain:add_effect(ResizeEffect.new())
        end
+       local wb_effect = chain:add_effect(WhiteBalanceEffect.new())
 
        local padding_effect = chain:add_effect(IntegralPaddingEffect.new())
 
@@ -113,9 +113,8 @@ function make_fade_input(chain, signal, live, deint, scale)
        local input, wb_effect, resample_effect, last
        if live then
                input = chain:add_live_input(false, deint)
-               wb_effect = chain:add_effect(WhiteBalanceEffect.new())
                input:connect_signal(signal)
-               last = wb_effect
+               last = input
        else
                input = chain:add_effect(ImageInput.new("bg.jpeg"))
                last = input
@@ -128,6 +127,12 @@ function make_fade_input(chain, signal, live, deint, scale)
                last = resample_effect
        end
 
+       -- Make sure to put the white balance after the scaling (usually more efficient).
+       if live then
+               wb_effect = chain:add_effect(WhiteBalanceEffect.new())
+               last = wb_effect
+       end
+
        return {
                input = input,
                wb_effect = wb_effect,
@@ -177,8 +182,6 @@ function make_simple_chain(input_deint, input_scale, hq)
 
        local input = chain:add_live_input(false, input_deint)
        input:connect_signal(0)  -- First input card. Can be changed whenever you want.
-       local wb_effect = chain:add_effect(WhiteBalanceEffect.new())
-       chain:finalize(hq)
 
        local resample_effect, resize_effect
        if scale then
@@ -189,6 +192,9 @@ function make_simple_chain(input_deint, input_scale, hq)
                end
        end
 
+       local wb_effect = chain:add_effect(WhiteBalanceEffect.new())
+       chain:finalize(hq)
+
        return {
                chain = chain,
                input = input,
@@ -269,8 +275,7 @@ end
 -- Helper function to write e.g. “720p60”.
 function get_channel_resolution(signal_num)
        if last_resolution[signal_num] then
-               if last_resolution[signal_num].height == 0 or
-                  last_resolution[signal_num].height == 525 then
+               if not last_resolution[signal_num].has_signal then
                        return "no signal"
                elseif last_resolution[signal_num].interlaced then
                        return last_resolution[signal_num].height .. "i" .. get_frame_rate(signal_num)
@@ -301,6 +306,8 @@ end
 -- API ENTRY POINT
 -- Returns, given a channel number, which signal it corresponds to (starting from 0).
 -- Should return -1 if the channel does not correspond to a simple signal.
+-- (The information is used for whether right-click on the channel should bring up
+-- an input selector or not.)
 -- 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)
@@ -349,6 +356,7 @@ function get_transitions(t)
        finish_transitions(t)
 
        if live_signal_num == preview_signal_num then
+               -- No transitions possible.
                return {}
        end
 
@@ -378,6 +386,9 @@ function get_transitions(t)
        return {"Cut"}
 end
 
+-- API ENTRY POINT
+-- Called when the user clicks a transition button. For our case,
+-- we only do cuts, so we ignore the parameters; just switch live and preview.
 function transition_clicked(num, t)
        if num == 0 then
                -- Cut.
@@ -496,6 +507,7 @@ function get_chain(num, t, width, height, signals)
                        width = signals:get_width(signal_num),
                        height = signals:get_height(signal_num),
                        interlaced = signals:get_interlaced(signal_num),
+                       has_signal = signals:get_has_signal(signal_num),
                        frame_rate_nom = signals:get_frame_rate_nom(signal_num),
                        frame_rate_den = signals:get_frame_rate_den(signal_num)
                }
@@ -633,6 +645,9 @@ function place_rectangle(resample_effect, resize_effect, padding_effect, x0, y0,
        local srcy0 = 0.0
        local srcy1 = 1.0
 
+       padding_effect:set_int("width", screen_width)
+       padding_effect:set_int("height", screen_height)
+
        -- Cull.
        if x0 > screen_width or x1 < 0.0 or y0 > screen_height or y1 < 0.0 then
                resample_effect:set_int("width", 1)