]> git.sesse.net Git - nageru/commitdiff
Ask the Lua script for number of channels.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 7 Oct 2015 22:06:21 +0000 (00:06 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 7 Oct 2015 22:06:21 +0000 (00:06 +0200)
mixer.cpp
theme.cpp
theme.h
theme.lua

index 99aa33cbecd33f06e08a9a5ee8cc2f3dd8b2b9b6..ce3d04eda86a2a3213197296f61d9dc16804d6c9 100644 (file)
--- 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<EffectChain *, function<void()>> chain = theme->get_chain(i, frame / 60.0f, WIDTH, HEIGHT);  // FIXME: dimensions
                        display_frame.chain = chain.first;
index 5d42c3d661d8a05d99f05613bb18c1eb2470e4c7..31eb23d2e36a67a4c7c14737d18cfb8bd3d1ef41 100644 (file)
--- 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 f58681d080666dfe8fb3861512dc44b4de9bdd68..473985a22cb3b82ae9e639c994141d64b5a99037 100644 (file)
--- 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 {
index fbe2cbf4e0b0c7f3b31da707e0514a1757b5375c..82339f8d33db7c03d9fb8c51f1b6060373cef6b9 100644 (file)
--- 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.