+-- 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
+ if nom % den == 0 then
+ return nom / den
+ else
+ return string.format("%.2f", nom / den)
+ end
+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
+ 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
+ else
+ return "no signal"
+ end
+end
+
+-- API ENTRY POINT
+-- Returns the name for each additional channel (starting from 2).
+-- Called at the start of the program, and then each frame for live
+-- channels in case they change resolution.
+function channel_name(channel)
+ if channel == 2 then
+ return "Input 1 (" .. get_channel_resolution(0) .. ")"
+ elseif channel == 3 then
+ return "Input 2 (" .. get_channel_resolution(1) .. ")"
+ elseif channel == 4 then
+ return "Side-by-side"
+ elseif channel == 5 then
+ return "Static picture"
+ end
+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.
+-- 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
+ else
+ return -1
+ end
+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.
+function supports_set_wb(channel)
+ return channel == 2 or channel == 3
+end
+
+-- API ENTRY POINT
+-- Gets called with a new gray point when the white balance is changing.
+-- The color is in linear light (not sRGB gamma).
+function set_wb(channel, red, green, blue)
+ if channel == 2 then
+ input0_neutral_color = { red, green, blue }
+ elseif channel == 3 then
+ input1_neutral_color = { red, green, blue }
+ end
+end
+
+function finish_transitions(t)
+ -- If live is SBS but de-facto single, make it so.
+ if live_signal_num == SBS_SIGNAL_NUM and t >= transition_end and zoom_dst == 1.0 then
+ live_signal_num = zoom_poi
+ end
+
+ -- If live is fade but de-facto single, make it so.
+ if live_signal_num == FADE_SIGNAL_NUM and t >= transition_end then
+ live_signal_num = fade_dst_signal
+ end
+end
+
+-- API ENTRY POINT