]> git.sesse.net Git - nageru/blobdiff - nageru/theme.cpp
Make it possible to get and set EQ parameters from the theme.
[nageru] / nageru / theme.cpp
index ade4e8fd2dc7f8f6359c9bea8acf05e5e7ccf748..71d6000439cbf61a9533d0185fbd3437c91d5a8f 100644 (file)
@@ -1412,6 +1412,52 @@ int Nageru_set_audio_bus_mute(lua_State *L)
        return 0;
 }
 
+int Nageru_get_audio_bus_eq_level_db(lua_State *L)
+{
+       if (global_audio_mixer == nullptr) {
+               // The audio mixer isn't set up until we know how many FFmpeg inputs we have.
+               luaL_error(L, "Audio functions can not be called before the theme is done initializing.");
+       }
+
+       int bus_index = luaL_checknumber(L, 1);
+       int band = luaL_checknumber(L, 2);
+       if (bus_index < 0 || size_t(bus_index) >= global_audio_mixer->num_buses()) {
+               // Doesn't fix the race, but fixes other out-of-bounds.
+               print_warning(L, "Theme called get_audio_bus_eq_level_db() on nonexistent bus %d; returning 0.0.\n", bus_index);
+               lua_pushnumber(L, 0.0);
+       } else if (band != EQ_BAND_BASS && band != EQ_BAND_MID && band != EQ_BAND_TREBLE) {
+               print_warning(L, "Theme called get_audio_bus_eq_level_db() on nonexistent band; returning 0.0.\n", bus_index);
+               lua_pushnumber(L, 0.0);
+       } else {
+               lua_pushnumber(L, global_audio_mixer->get_eq(bus_index, EQBand(band)));
+       }
+       return 1;
+}
+
+int Nageru_set_audio_bus_eq_level_db(lua_State *L)
+{
+       if (global_audio_mixer == nullptr || global_mainwindow == nullptr) {
+               // The audio mixer isn't set up until we know how many FFmpeg inputs we have.
+               luaL_error(L, "Audio functions can not be called before the theme is done initializing.");
+       }
+
+       int bus_index = luaL_checknumber(L, 1);
+       int band = luaL_checknumber(L, 2);
+       if (bus_index < 0 || size_t(bus_index) >= global_audio_mixer->num_buses()) {
+               // Doesn't fix the race, but fixes other out-of-bounds.
+               print_warning(L, "Theme called set_audio_bus_eq_level_db() on nonexistent bus %d; ignoring.\n", bus_index);
+               return 0;
+       } else if (band != EQ_BAND_BASS && band != EQ_BAND_MID && band != EQ_BAND_TREBLE) {
+               print_warning(L, "Theme called set_audio_bus_eq_level_db() on nonexistent band; returning 0.0.\n", bus_index);
+               return 0;
+       }
+       double level_db = luaL_checknumber(L, 3);
+
+       // Go through the UI, so that it gets updated.
+       global_mainwindow->set_eq_absolute(bus_index, EQBand(band), level_db);
+       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)
 {
@@ -1538,6 +1584,9 @@ void Theme::register_globals()
                { "VIDEO_FORMAT_YCBCR", bmusb::PixelFormat_8BitYCbCrPlanar },
                { "CHECKABLE", MenuEntry::CHECKABLE },
                { "CHECKED", MenuEntry::CHECKED },
+               { "EQ_BAND_BASS", EQ_BAND_BASS },
+               { "EQ_BAND_MID", EQ_BAND_MID },
+               { "EQ_BAND_TREBLE", EQ_BAND_TREBLE },
        };
        const vector<pair<string, string>> str_constants = {
                { "THEME_PATH", theme_path },
@@ -1568,6 +1617,8 @@ void Theme::register_globals()
                { "get_audio_bus_name", Nageru_get_audio_bus_name },
                { "get_audio_bus_fader_level_db", Nageru_get_audio_bus_fader_level_db },
                { "set_audio_bus_fader_level_db", Nageru_set_audio_bus_fader_level_db },
+               { "get_audio_bus_eq_level_db", Nageru_get_audio_bus_eq_level_db },
+               { "set_audio_bus_eq_level_db", Nageru_set_audio_bus_eq_level_db },
                { "get_audio_bus_mute", Nageru_get_audio_bus_mute },
                { "set_audio_bus_mute", Nageru_set_audio_bus_mute },