]> git.sesse.net Git - nageru/blob - theme.lua
Hook up IntegralPaddingEffect.
[nageru] / theme.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, setting their parameters and then deciding which to show when.
5 --
6 -- Themes are written in Lua, which reflects a simplified form of the Movit API
7 -- where all the low-level details (such as texture formats) are handled by the
8 -- C++ side and you generally just build chains.
9 io.write("hello from lua\n");
10
11 local live_signal_num = 0;
12 local preview_signal_num = 1;
13
14 -- The main live chain. Currently just about input 0 with some color correction.
15 local main_chain = EffectChain.new(16, 9);
16 local input0 = main_chain:add_live_input();
17 input0:connect_signal(0);
18 local resample_effect = main_chain:add_effect(ResampleEffect.new(), input0);
19 resample_effect:set_int("width", 320);
20 resample_effect:set_int("height", 180);
21 local padding_effect = main_chain:add_effect(IntegralPaddingEffect.new(), resample_effect);
22 padding_effect:set_int("width", 1280);
23 padding_effect:set_int("height", 720);
24 padding_effect:set_int("left", 30);
25 padding_effect:set_int("top", 60);
26 local wb_effect = main_chain:add_effect(WhiteBalanceEffect.new(), padding_effect);
27 main_chain:finalize(true);
28 -- local input1 = main_chain.add_input(Inputs.create(1));
29 -- local resample_effect = main_chain.add_effect(ResampleEffect.new(), input0);
30 -- local padding_effect = main_chain.add_effect(IntegralPaddingEffect.new());
31
32 -- A chain to show a single input on screen.
33 local simple_chain = EffectChain.new(16, 9);
34 local simple_chain_input = simple_chain:add_live_input();
35 simple_chain_input:connect_signal(0);  -- First input card. Can be changed whenever you want.
36 simple_chain:finalize(false);
37
38 -- Returns the number of outputs in addition to the live (0) and preview (1).
39 -- Called only once, at the start of the program.
40 function num_channels()
41         return 2;
42 end
43
44 -- Called every frame.
45 function get_transitions()
46         return {"Cut", "Fade", "Zoom!"};
47 end
48
49 function transition_clicked(num, t)
50         -- Only a cut for now.
51         local temp = live_signal_num;
52         live_signal_num = preview_signal_num;
53         preview_signal_num = temp;
54 end
55
56 function channel_clicked(num, t)
57         -- Presumably change the preview here.
58         io.write("STUB: channel_clicked\n");
59 end
60
61 -- Called every frame. Get the chain for displaying at input <num>,
62 -- where 0 is live, 1 is preview, 2 is the first channel to display
63 -- in the bottom bar, and so on up to num_channels()+1. t is the 
64 -- current time in seconds. width and height are the dimensions of
65 -- the output, although you can ignore them if you don't need them
66 -- (they're useful if you want to e.g. know what to resample by).
67 --
68 -- You should return two objects; the chain itself, and then a
69 -- function (taking no parameters) that is run just before rendering.
70 -- The function needs to call connect_signal on any inputs, so that
71 -- it gets updated video data for the given frame. (You are allowed
72 -- to switch which input your input is getting from between frames,
73 -- but not calling connect_signal results in undefined behavior.)
74 -- If you want to change any parameters in the chain, this is also
75 -- the right place.
76 --
77 -- NOTE: The chain returned must be finalized with the Y'CbCr flag
78 -- if and only if num==0.
79 function get_chain(num, t, width, height)
80         if num == 0 then  -- Live.
81                 prepare = function()
82                         input0:connect_signal(live_signal_num);
83                         wb_effect:set_float("output_color_temperature", 3500.0 + t * 100.0);
84                 end
85                 return main_chain, prepare;
86         end
87         if num == 1 then  -- Preview.
88                 prepare = function()
89                         simple_chain_input:connect_signal(preview_signal_num);
90                 end
91                 return simple_chain, prepare;
92         end
93         if num == 2 then
94                 prepare = function()
95                         simple_chain_input:connect_signal(0);
96                 end
97                 return simple_chain, prepare;
98         end
99         if num == 3 then
100                 prepare = function()
101                         simple_chain_input:connect_signal(1);
102                 end
103                 return simple_chain, prepare;
104         end
105 end
106