+ unique_lock<mutex> lock(m);
+ lua_getglobal(L, "channel_signal");
+ lua_pushnumber(L, channel);
+ if (lua_pcall(L, 1, 1, 0) != 0) {
+ fprintf(stderr, "error running function `channel_signal': %s\n", lua_tostring(L, -1));
+ exit(1);
+ }
+
+ int ret = luaL_checknumber(L, 1);
+ lua_pop(L, 1);
+ assert(lua_gettop(L) == 0);
+ return ret;
+}
+
+std::string Theme::get_channel_color(unsigned channel)
+{
+ unique_lock<mutex> lock(m);
+ lua_getglobal(L, "channel_color");
+ lua_pushnumber(L, channel);
+ if (lua_pcall(L, 1, 1, 0) != 0) {
+ fprintf(stderr, "error running function `channel_color': %s\n", lua_tostring(L, -1));
+ exit(1);
+ }
+
+ const char *ret = lua_tostring(L, -1);
+ if (ret == nullptr) {
+ fprintf(stderr, "function `channel_color' returned nil for channel %d\n", channel);
+ exit(1);
+ }
+
+ string retstr = ret;
+ lua_pop(L, 1);
+ assert(lua_gettop(L) == 0);
+ return retstr;
+}
+
+bool Theme::get_supports_set_wb(unsigned channel)
+{
+ unique_lock<mutex> lock(m);
+ lua_getglobal(L, "supports_set_wb");
+ lua_pushnumber(L, channel);
+ if (lua_pcall(L, 1, 1, 0) != 0) {
+ fprintf(stderr, "error running function `supports_set_wb': %s\n", lua_tostring(L, -1));
+ exit(1);
+ }
+
+ bool ret = checkbool(L, -1);
+ lua_pop(L, 1);
+ assert(lua_gettop(L) == 0);
+ return ret;
+}
+
+void Theme::set_wb(unsigned channel, double r, double g, double b)
+{
+ unique_lock<mutex> lock(m);
+ lua_getglobal(L, "set_wb");
+ lua_pushnumber(L, channel);
+ lua_pushnumber(L, r);
+ lua_pushnumber(L, g);
+ lua_pushnumber(L, b);
+ if (lua_pcall(L, 4, 0, 0) != 0) {
+ fprintf(stderr, "error running function `set_wb': %s\n", lua_tostring(L, -1));
+ exit(1);
+ }
+
+ assert(lua_gettop(L) == 0);
+}
+
+vector<string> Theme::get_transition_names(float t)
+{
+ unique_lock<mutex> lock(m);
+ lua_getglobal(L, "get_transitions");
+ lua_pushnumber(L, t);
+ if (lua_pcall(L, 1, 1, 0) != 0) {
+ fprintf(stderr, "error running function `get_transitions': %s\n", lua_tostring(L, -1));
+ exit(1);
+ }
+
+ vector<string> ret;
+ lua_pushnil(L);
+ while (lua_next(L, -2) != 0) {
+ ret.push_back(lua_tostring(L, -1));
+ lua_pop(L, 1);
+ }
+ lua_pop(L, 1);
+ assert(lua_gettop(L) == 0);
+ return ret;
+}
+
+int Theme::map_signal(int signal_num)
+{
+ unique_lock<mutex> lock(map_m);
+ if (signal_to_card_mapping.count(signal_num)) {
+ return signal_to_card_mapping[signal_num];
+ }
+
+ int card_index;
+ if (global_flags.output_card != -1 && num_cards > 1) {
+ // Try to exclude the output card from the default card_index.
+ card_index = signal_num % (num_cards - 1);
+ if (card_index >= global_flags.output_card) {
+ ++card_index;
+ }
+ if (signal_num >= int(num_cards - 1)) {
+ fprintf(stderr, "WARNING: Theme asked for input %d, but we only have %u input card(s) (card %d is busy with output).\n",
+ signal_num, num_cards - 1, global_flags.output_card);
+ fprintf(stderr, "Mapping to card %d instead.\n", card_index);
+ }
+ } else {
+ card_index = signal_num % num_cards;
+ if (signal_num >= int(num_cards)) {
+ fprintf(stderr, "WARNING: Theme asked for input %d, but we only have %u card(s).\n", signal_num, num_cards);
+ fprintf(stderr, "Mapping to card %d instead.\n", card_index);
+ }
+ }
+ signal_to_card_mapping[signal_num] = card_index;
+ return card_index;
+}
+
+void Theme::set_signal_mapping(int signal_num, int card_num)
+{
+ unique_lock<mutex> lock(map_m);
+ assert(card_num < int(num_cards));
+ signal_to_card_mapping[signal_num] = card_num;