From 6d011e4760be6e45680b41a98b9049c1ec44c951 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Thu, 8 Oct 2015 00:06:21 +0200 Subject: [PATCH] Ask the Lua script for number of channels. --- mixer.cpp | 4 ++-- theme.cpp | 26 ++++++++++++++++++-------- theme.h | 2 ++ theme.lua | 2 +- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/mixer.cpp b/mixer.cpp index 99aa33c..ce3d04e 100644 --- a/mixer.cpp +++ b/mixer.cpp @@ -422,8 +422,8 @@ void Mixer::thread_func() live_frame.temp_textures = { rgba_tex }; output_channel[OUTPUT_LIVE].output_frame(live_frame); - // Set up non-live inputs. - for (unsigned i = 1; i < 4; ++i) { // FIXME: Don't lock to 4, ask Lua. + // Set up preview and any additional channels. + for (unsigned i = 1; i < theme->get_num_channels() + 2; ++i) { DisplayFrame display_frame; pair> chain = theme->get_chain(i, frame / 60.0f, WIDTH, HEIGHT); // FIXME: dimensions display_frame.chain = chain.first; diff --git a/theme.cpp b/theme.cpp index 5d42c3d..31eb23d 100644 --- a/theme.cpp +++ b/theme.cpp @@ -191,14 +191,24 @@ Theme::Theme(const char *filename, ResourcePool *resource_pool) register_class("LiveInputWrapper", LiveInputWrapper_funcs); register_class("WhiteBalanceEffect", WhiteBalanceEffect_funcs); - // Run script. - lua_settop(L, 0); - if (luaL_dofile(L, filename)) { - fprintf(stderr, "error: %s\n", lua_tostring(L, -1)); - lua_pop(L, 1); - exit(1); - } - assert(lua_gettop(L) == 0); + // Run script. + lua_settop(L, 0); + if (luaL_dofile(L, filename)) { + fprintf(stderr, "error: %s\n", lua_tostring(L, -1)); + lua_pop(L, 1); + exit(1); + } + assert(lua_gettop(L) == 0); + + // Ask it for the number of channels. + lua_getglobal(L, "num_channels"); + + if (lua_pcall(L, 0, 1, 0) != 0) { + fprintf(stderr, "error running function `num_channels': %s", lua_tostring(L, -1)); + exit(1); + } + + num_channels = luaL_checknumber(L, 1); } void Theme::register_class(const char *class_name, const luaL_Reg *funcs) diff --git a/theme.h b/theme.h index f58681d..473985a 100644 --- a/theme.h +++ b/theme.h @@ -24,6 +24,7 @@ public: input_textures[signal_num].tex_y = tex_y; input_textures[signal_num].tex_cbcr = tex_cbcr; } + int get_num_channels() { return num_channels; } void connect_signal(movit::YCbCrInput *input, int signal_num); void transition_clicked(int transition_num, float t); @@ -35,6 +36,7 @@ private: struct { GLuint tex_y = 0, tex_cbcr = 0; } input_textures[16]; // FIXME + int num_channels; }; class LiveInputWrapper { diff --git a/theme.lua b/theme.lua index fbe2cbf..82339f8 100644 --- a/theme.lua +++ b/theme.lua @@ -30,7 +30,7 @@ simple_chain:finalize(false); -- Returns the number of outputs in addition to the live (0) and preview (1). -- Called only once, at the start of the program. function num_channels() - return 0; + return 2; end -- Called every frame. -- 2.39.2