]> git.sesse.net Git - nageru/blob - nageru/simple.lua
Fix a comment typo.
[nageru] / nageru / simple.lua
1 -- The theme is what decides what's actually shown on screen, what kind of
2 -- transitions are available (if any), and what kind of inputs there are,
3 -- if any. In general, it drives the entire display logic by creating Movit
4 -- chains (called “scenes”), setting their parameters and then deciding which
5 -- to show when.
6 --
7 -- Themes are written in Lua, which reflects a simplified form of the Movit API
8 -- where all the low-level details (such as texture formats) and alternatives
9 -- (e.g. turning scaling on or off) are handled by the C++ side and you
10 -- generally just build scenes.
11 --
12 -- This is a much simpler theme than the default theme; it only allows you to
13 -- switch between inputs and set white balance, no transitions or the likes.
14 -- Thus, it should be simpler to understand.
15
16 local input_neutral_color = {{0.5, 0.5, 0.5}, {0.5, 0.5, 0.5}}
17
18 local live_signal_num = 0
19 local preview_signal_num = 1
20
21 local img = ImageInput.new("bg.jpeg")
22
23 local scene = Scene.new(16, 9)
24 local input = scene:add_input()
25 local wb_effect = scene:add_effect(WhiteBalanceEffect.new())
26 scene:finalize()
27
28 -- Set some global state. Unless marked otherwise, these can only be set once,
29 -- at the start of the program.
30 Nageru.set_num_channels(2)
31
32 -- Sets, for each channel, which signal it corresponds to (starting from 0).
33 -- The information is used for whether right-click on the channel should bring up
34 -- an input selector or not. Only call this for channels that actually correspond
35 -- directly to a signal (ie., live inputs, not live (0) or preview (1)).
36 Nageru.set_channel_signal(2, 0)
37 Nageru.set_channel_signal(3, 1)
38
39 -- Set whether a given channel supports setting white balance. (Default is false.)
40 Nageru.set_supports_wb(2, true)
41 Nageru.set_supports_wb(3, true)
42
43 -- These can be set at any time.
44 Nageru.set_channel_name(2, "First input")
45 Nageru.set_channel_name(3, "Second input")
46
47 -- API ENTRY POINT
48 -- Called every frame. Returns the color (if any) to paint around the given
49 -- channel. Returns a CSS color (typically to mark live and preview signals);
50 -- "transparent" is allowed.
51 -- Will never be called for live (0) or preview (1).
52 function channel_color(channel)
53         return "transparent"
54 end
55
56 -- API ENTRY POINT
57 -- Gets called with a new gray point when the white balance is changing.
58 -- The color is in linear light (not sRGB gamma).
59 function set_wb(channel, red, green, blue)
60         if channel == 2 then
61                 input_neutral_color[1] = { red, green, blue }
62         elseif channel == 3 then
63                 input_neutral_color[2] = { red, green, blue }
64         end
65 end
66
67 -- API ENTRY POINT
68 -- Called every frame.
69 function get_transitions(t)
70         if live_signal_num == preview_signal_num then
71                 -- No transitions possible.
72                 return {}
73         else
74                 return {"Cut"}
75         end
76 end
77
78 -- API ENTRY POINT
79 -- Called when the user clicks a transition button. For our case,
80 -- we only do cuts, so we ignore the parameters; just switch live and preview.
81 function transition_clicked(num, t)
82         local temp = live_signal_num
83         live_signal_num = preview_signal_num
84         preview_signal_num = temp
85 end
86
87 -- API ENTRY POINT
88 function channel_clicked(num)
89         preview_signal_num = num
90 end
91
92 -- API ENTRY POINT
93 -- Called every frame. Get the scene for displaying at input <num>,
94 -- where 0 is live, 1 is preview, 2 is the first channel to display
95 -- in the bottom bar, and so on up to num_channels()+1. t is the
96 -- current time in seconds. width and height are the dimensions of
97 -- the output, although you can ignore them if you don't need them
98 -- (they're useful if you want to e.g. know what to resample by).
99 --
100 -- <signals> is basically an exposed InputState, which you can use to
101 -- query for information about the signals at the point of the current
102 -- frame. In particular, you can call get_frame_width() and get_frame_height()
103 -- for any signal number, and use that to e.g. assist in scene selection.
104 -- (You can also use get_width() and get_height(), which return the
105 -- _field_ size. This has half the height for interlaced signals.)
106 --
107 -- You should return the scene to use, after having set any parameters you
108 -- want to set (through set_int() etc.). The parameters will be snapshot
109 -- at return time and used during rendering.
110 function get_scene(num, t, width, height, signals)
111         local signal_num
112         if num == 0 then  -- Live (right pane).
113                 signal_num = live_signal_num
114         elseif num == 1 then  -- Preview (left pane).
115                 signal_num = preview_signal_num
116         else  -- One of the two previews (bottom panes).
117                 signal_num = num - 2
118         end
119
120         if num == 3 then
121                 input:display(img)
122         else
123                 input:display(signal_num)
124         end
125
126         local color = input_neutral_color[signal_num + 1]
127         wb_effect:set_vec3("neutral_color", color[1], color[2], color[3])
128
129         return scene
130 end