]> git.sesse.net Git - nageru/blobdiff - theme.lua
Fix some broken culling code in the theme (no idea why this does not trigger more...
[nageru] / theme.lua
index e8adb6cde8390d8e7f13c80e25899ef23fda29df..7f47c8491341879c350dd7babe489163ce56a19b 100644 (file)
--- a/theme.lua
+++ b/theme.lua
@@ -261,10 +261,29 @@ function num_channels()
        return 4
 end
 
+-- Helper function to write e.g. “720p60”. The difference between this
+-- and get_channel_resolution_raw() is that this one also can say that
+-- there's no signal.
+function get_channel_resolution(signal_num)
+       res = last_resolution[signal_num]
+       if (not res) or res.height <= 0 then
+               return "no signal"
+       end
+       if not res.has_signal then
+               if res.height == 525 then
+                       -- Special mode for the USB3 cards.
+                       return "no signal"
+               end
+               return get_channel_resolution_raw(res) .. ", no signal"
+       else
+               return get_channel_resolution_raw(res)
+       end
+end
+
 -- Helper function to write e.g. “60” or “59.94”.
-function get_frame_rate(signal_num)
-       local nom = last_resolution[signal_num].frame_rate_nom
-       local den = last_resolution[signal_num].frame_rate_den
+function get_frame_rate(res)
+       local nom = res.frame_rate_nom
+       local den = res.frame_rate_den
        if nom % den == 0 then
                return nom / den
        else
@@ -273,17 +292,11 @@ function get_frame_rate(signal_num)
 end
 
 -- Helper function to write e.g. “720p60”.
-function get_channel_resolution(signal_num)
-       if last_resolution[signal_num] 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)
-               else
-                       return last_resolution[signal_num].height .. "p" .. get_frame_rate(signal_num)
-               end
+function get_channel_resolution_raw(res)
+       if res.interlaced then
+               return res.height .. "i" .. get_frame_rate(res)
        else
-               return "no signal"
+               return res.height .. "p" .. get_frame_rate(res)
        end
 end
 
@@ -320,6 +333,41 @@ function channel_signal(channel)
        end
 end
 
+-- API ENTRY POINT
+-- Called every frame. Returns the color (if any) to paint around the given
+-- channel. Returns a CSS color (typically to mark live and preview signals);
+-- "transparent" is allowed.
+-- Will never be called for live (0) or preview (1).
+function channel_color(channel)
+       if channel_involved_in(channel, live_signal_num) then
+               return "#f00"
+       end
+       if channel_involved_in(channel, preview_signal_num) then
+               return "#0f0"
+       end
+       return "transparent"
+end
+
+function channel_involved_in(channel, signal_num)
+       if signal_num == INPUT0_SIGNAL_NUM then
+               return channel == 2
+       end
+       if signal_num == INPUT1_SIGNAL_NUM then
+               return channel == 3
+       end
+       if signal_num == SBS_SIGNAL_NUM then
+               return (channel == 2 or channel == 3)
+       end
+       if signal_num == STATIC_SIGNAL_NUM then
+               return (channel == 5)
+       end
+       if signal_num == FADE_SIGNAL_NUM then
+               return (channel_involved_in(channel, fade_src_signal) or
+                       channel_involved_in(channel, fade_dst_signal))
+       end
+       return false
+end
+
 -- API ENTRY POINT
 -- Returns if a given channel supports setting white balance (starting from 2).
 -- Called only once for each channel, at the start of the program.
@@ -387,8 +435,7 @@ function get_transitions(t)
 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.
+-- Called when the user clicks a transition button.
 function transition_clicked(num, t)
        if num == 0 then
                -- Cut.
@@ -650,10 +697,15 @@ function place_rectangle(resample_effect, resize_effect, padding_effect, x0, y0,
 
        -- Cull.
        if x0 > screen_width or x1 < 0.0 or y0 > screen_height or y1 < 0.0 then
-               resample_effect:set_int("width", 1)
-               resample_effect:set_int("height", 1)
-               resample_effect:set_float("zoom_x", screen_width)
-               resample_effect:set_float("zoom_y", screen_height)
+               if resample_effect ~= nil then
+                       resample_effect:set_int("width", 1)
+                       resample_effect:set_int("height", 1)
+                       resample_effect:set_float("zoom_x", screen_width)
+                       resample_effect:set_float("zoom_y", screen_height)
+               else
+                       resize_effect:set_int("width", 1)
+                       resize_effect:set_int("height", 1)
+               end
                padding_effect:set_int("left", screen_width + 100)
                padding_effect:set_int("top", screen_height + 100)
                return
@@ -807,9 +859,9 @@ end
 function calc_fade_progress(t, transition_start, transition_end)
        local tt = (t - transition_start) / (transition_end - transition_start)
        if tt < 0.0 then
-               tt = 0.0
+               return 0.0
        elseif tt > 1.0 then
-               tt = 1.0
+               return 1.0
        end
 
        -- Make the fade look maybe a tad more natural, by pumping it