return nullptr;
}
+InputState *get_input_state(lua_State *L, int idx)
+{
+ if (luaL_testudata(L, idx, "InputState")) {
+ return (InputState *)lua_touserdata(L, idx);
+ }
+ luaL_error(L, "Error: Index #%d was not InputState\n", idx);
+ return nullptr;
+}
+
bool checkbool(lua_State* L, int idx)
{
luaL_checktype(L, idx, LUA_TBOOLEAN);
return 0;
}
-int LiveInputWrapper_get_width(lua_State* L)
-{
- assert(lua_gettop(L) == 1);
- LiveInputWrapper *input = (LiveInputWrapper *)luaL_checkudata(L, 1, "LiveInputWrapper");
- lua_pushnumber(L, input->get_width());
- return 1;
-}
-
-int LiveInputWrapper_get_height(lua_State* L)
-{
- assert(lua_gettop(L) == 1);
- LiveInputWrapper *input = (LiveInputWrapper *)luaL_checkudata(L, 1, "LiveInputWrapper");
- lua_pushnumber(L, input->get_height());
- return 1;
-}
-
int ImageInput_new(lua_State* L)
{
assert(lua_gettop(L) == 1);
return wrap_lua_object<MixEffect>(L, "MixEffect");
}
+int InputState_gc(lua_State* L)
+{
+ assert(lua_gettop(L) == 1);
+ InputState *input_state = get_input_state(L, 1);
+ input_state->~InputState();
+ return 0;
+}
+
+int InputState_get_width(lua_State* L)
+{
+ assert(lua_gettop(L) == 2);
+ InputState *input_state = (InputState *)lua_touserdata(L, 1);
+ int signal_num = luaL_checknumber(L, 2);
+ BufferedFrame frame = input_state->buffered_frames[signal_num][0];
+ const PBOFrameAllocator::Userdata *userdata = (const PBOFrameAllocator::Userdata *)frame.frame->userdata;
+ lua_pushnumber(L, userdata->last_width[frame.field_number]);
+ return 1;
+}
+
+int InputState_get_height(lua_State* L)
+{
+ assert(lua_gettop(L) == 2);
+ InputState *input_state = (InputState *)lua_touserdata(L, 1);
+ int signal_num = luaL_checknumber(L, 2);
+ BufferedFrame frame = input_state->buffered_frames[signal_num][0];
+ const PBOFrameAllocator::Userdata *userdata = (const PBOFrameAllocator::Userdata *)frame.frame->userdata;
+ lua_pushnumber(L, userdata->last_height[frame.field_number]);
+ return 1;
+}
+
int Effect_set_float(lua_State *L)
{
assert(lua_gettop(L) == 3);
const luaL_Reg LiveInputWrapper_funcs[] = {
{ "connect_signal", LiveInputWrapper_connect_signal },
- // These are only valid during calls to get_chain and the setup chain callback.
- { "get_width", LiveInputWrapper_get_width },
- { "get_height", LiveInputWrapper_get_height },
{ NULL, NULL }
};
{ NULL, NULL }
};
+const luaL_Reg InputState_funcs[] = {
+ { "__gc", InputState_gc },
+ { "get_width", InputState_get_width },
+ { "get_height", InputState_get_height },
+ { NULL, NULL }
+};
+
} // namespace
LiveInputWrapper::LiveInputWrapper(Theme *theme, EffectChain *chain, bool override_bounce)
input->set_height(userdata->last_height[frame.field_number]);
}
-unsigned LiveInputWrapper::get_width() const
-{
- if (last_connected_signal_num == -1) {
- return 0;
- }
- BufferedFrame frame = theme->input_state->buffered_frames[last_connected_signal_num][0];
- const PBOFrameAllocator::Userdata *userdata = (const PBOFrameAllocator::Userdata *)frame.frame->userdata;
- return userdata->last_width[frame.field_number];
-}
-
-unsigned LiveInputWrapper::get_height() const
-{
- if (last_connected_signal_num == -1) {
- return 0;
- }
- BufferedFrame frame = theme->input_state->buffered_frames[last_connected_signal_num][0];
- const PBOFrameAllocator::Userdata *userdata = (const PBOFrameAllocator::Userdata *)frame.frame->userdata;
- return userdata->last_height[frame.field_number];
-}
-
Theme::Theme(const char *filename, ResourcePool *resource_pool, unsigned num_cards)
: resource_pool(resource_pool), num_cards(num_cards)
{
register_class("OverlayEffect", OverlayEffect_funcs);
register_class("ResizeEffect", ResizeEffect_funcs);
register_class("MixEffect", MixEffect_funcs);
+ register_class("InputState", InputState_funcs);
// Run script.
lua_settop(L, 0);
lua_pushnumber(L, t);
lua_pushnumber(L, width);
lua_pushnumber(L, height);
+ wrap_lua_object<InputState>(L, "InputState", input_state);
- this->input_state = &input_state;
- if (lua_pcall(L, 4, 2, 0) != 0) {
+ if (lua_pcall(L, 5, 2, 0) != 0) {
fprintf(stderr, "error running function `get_chain': %s\n", lua_tostring(L, -1));
exit(1);
}
-- the output, although you can ignore them if you don't need them
-- (they're useful if you want to e.g. know what to resample by).
--
+-- <signals> is basically an exposed InputState, which you can use to
+-- query for information about the signals at the point of the current
+-- frame. In particular, you can call get_width() and get_height()
+-- for any signal number, and use that to e.g. assist in chain selection.
+--
-- You should return two objects; the chain itself, and then a
-- function (taking no parameters) that is run just before rendering.
-- The function needs to call connect_signal on any inputs, so that
--
-- NOTE: The chain returned must be finalized with the Y'CbCr flag
-- if and only if num==0.
-function get_chain(num, t, width, height)
+function get_chain(num, t, width, height, signals)
if num == 0 then -- Live.
if live_signal_num == INPUT0_SIGNAL_NUM or live_signal_num == INPUT1_SIGNAL_NUM then -- Plain input.
prepare = function()