]> git.sesse.net Git - nageru/commitdiff
Make it possible to set number of channels imperatively instead of using a callback.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 21 Jun 2019 17:43:29 +0000 (19:43 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 21 Jun 2019 17:44:15 +0000 (19:44 +0200)
num_channels() will still be used if it exists, for compatibility with older
themes.

nageru/simple.lua
nageru/theme.cpp
nageru/theme.h
nageru/theme.lua

index 8d5b3e673c1266a788d8eea043a337411a99b9bb..5444a200be9787c0e8c1f62269dcf6f0d7ccfe45 100644 (file)
@@ -25,14 +25,8 @@ local input = scene:add_input()
 local wb_effect = scene:add_effect(WhiteBalanceEffect.new())
 scene:finalize()
 
 local wb_effect = scene:add_effect(WhiteBalanceEffect.new())
 scene:finalize()
 
--- API ENTRY POINT
--- 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 2
-end
-
 -- Set some global state.
 -- Set some global state.
+Nageru.set_num_channels(2)  -- Can only be called at the start of the program.
 Nageru.set_channel_name(2, "First input")
 Nageru.set_channel_name(3, "Second input")
 
 Nageru.set_channel_name(2, "First input")
 Nageru.set_channel_name(3, "Second input")
 
index 6a4de4baa248ece934994332de8d559b29736010..f7f752250615323ebcc1c4f7d37c4fd8770a0006 100644 (file)
@@ -1212,6 +1212,7 @@ int call_num_channels(lua_State *L)
 
        if (lua_pcall(L, 0, 1, 0) != 0) {
                fprintf(stderr, "error running function `num_channels': %s\n", lua_tostring(L, -1));
 
        if (lua_pcall(L, 0, 1, 0) != 0) {
                fprintf(stderr, "error running function `num_channels': %s\n", lua_tostring(L, -1));
+               fprintf(stderr, "Try Nageru.set_num_channels(...) at the start of the script instead.\n");
                abort();
        }
 
                abort();
        }
 
@@ -1234,6 +1235,18 @@ int Nageru_set_channel_name(lua_State *L)
        return 0;
 }
 
        return 0;
 }
 
+int Nageru_set_num_channels(lua_State *L)
+{
+       // NOTE: m is already locked.
+       Theme *theme = get_theme_updata(L);
+       if (theme->startup_finished) {
+               luaL_error(L, "set_num_channels() can only be called at startup.");
+       }
+       theme->num_channels = luaL_checknumber(L, 1);
+       lua_pop(L, 1);
+       return 0;
+}
+
 Theme::Theme(const string &filename, const vector<string> &search_dirs, ResourcePool *resource_pool, unsigned num_cards)
        : resource_pool(resource_pool), num_cards(num_cards), signal_to_card_mapping(global_flags.default_stream_mapping)
 {
 Theme::Theme(const string &filename, const vector<string> &search_dirs, ResourcePool *resource_pool, unsigned num_cards)
        : resource_pool(resource_pool), num_cards(num_cards), signal_to_card_mapping(global_flags.default_stream_mapping)
 {
@@ -1335,8 +1348,11 @@ Theme::Theme(const string &filename, const vector<string> &search_dirs, Resource
        }
        assert(lua_gettop(L) == 0);
 
        }
        assert(lua_gettop(L) == 0);
 
-       // Ask it for the number of channels.
-       num_channels = call_num_channels(L);
+       if (num_channels == -1) {
+               // Ask it for the number of channels.
+               num_channels = call_num_channels(L);
+       }
+       startup_finished = true;
 }
 
 Theme::~Theme()
 }
 
 Theme::~Theme()
@@ -1371,6 +1387,7 @@ void Theme::register_globals()
 
        const luaL_Reg Nageru_funcs[] = {
                { "set_channel_name", Nageru_set_channel_name },
 
        const luaL_Reg Nageru_funcs[] = {
                { "set_channel_name", Nageru_set_channel_name },
+               { "set_num_channels", Nageru_set_num_channels },
                { NULL, NULL }
        };
        lua_pushlightuserdata(L, this);
                { NULL, NULL }
        };
        lua_pushlightuserdata(L, this);
index 794542525e9e84f60f65679b63cab8d6ae85b469..34a8d29fffb141475f5705242b2d01898fa7b74a 100644 (file)
@@ -191,8 +191,9 @@ private:
        lua_State *L;  // Protected by <m>.
        const InputState *input_state = nullptr;  // Protected by <m>. Only set temporarily, during chain setup.
        movit::ResourcePool *resource_pool;
        lua_State *L;  // Protected by <m>.
        const InputState *input_state = nullptr;  // Protected by <m>. Only set temporarily, during chain setup.
        movit::ResourcePool *resource_pool;
-       int num_channels;
+       int num_channels = -1;
        unsigned num_cards;
        unsigned num_cards;
+       bool startup_finished = false;
 
        std::mutex map_m;
        std::map<int, int> signal_to_card_mapping;  // Protected by <map_m>.
 
        std::mutex map_m;
        std::map<int, int> signal_to_card_mapping;  // Protected by <map_m>.
@@ -223,6 +224,7 @@ private:
        friend class Scene;
        friend int ThemeMenu_set(lua_State *L);
        friend int Nageru_set_channel_name(lua_State *L);
        friend class Scene;
        friend int ThemeMenu_set(lua_State *L);
        friend int Nageru_set_channel_name(lua_State *L);
+       friend int Nageru_set_num_channels(lua_State *L);
 };
 
 // LiveInputWrapper is a facade on top of an YCbCrInput, exposed to
 };
 
 // LiveInputWrapper is a facade on top of an YCbCrInput, exposed to
index c762a3f6d82ce1fafe1995d3f1de7ca988a2ab40..c524d566deb1a2ddf057ad5a0b6f25265f97e6a5 100644 (file)
@@ -111,16 +111,10 @@ static_scene:add_input(static_image)  -- Note: Locks this input to images only.
 static_scene:finalize()
 
 -- Set some global state.
 static_scene:finalize()
 
 -- Set some global state.
+Nageru.set_num_channels(4)  -- Can only be called at the start of the program.
 Nageru.set_channel_name(SBS_SIGNAL_NUM + 2, "Side-by-side")
 Nageru.set_channel_name(STATIC_SIGNAL_NUM + 2, "Static picture")
 
 Nageru.set_channel_name(SBS_SIGNAL_NUM + 2, "Side-by-side")
 Nageru.set_channel_name(STATIC_SIGNAL_NUM + 2, "Static picture")
 
--- API ENTRY POINT
--- 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 4
-end
-
 function is_plain_signal(num)
        return num == INPUT0_SIGNAL_NUM or num == INPUT1_SIGNAL_NUM
 end
 function is_plain_signal(num)
        return num == INPUT0_SIGNAL_NUM or num == INPUT1_SIGNAL_NUM
 end