From 4732b861f377ee8ff5c7740c171ea6d2b412ad90 Mon Sep 17 00:00:00 2001 From: Joep Vanlier Date: Fri, 20 Sep 2024 00:09:55 +0200 Subject: [PATCH] ysfx: don't allow making undefined sliders visible --- sources/ysfx_api_reaper.cpp | 47 ++++++++++++++++++++----------------- tests/ysfx_test_slider.cpp | 3 +++ 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/sources/ysfx_api_reaper.cpp b/sources/ysfx_api_reaper.cpp index 153ad9c..de58ade 100644 --- a/sources/ysfx_api_reaper.cpp +++ b/sources/ysfx_api_reaper.cpp @@ -131,31 +131,34 @@ static EEL_F NSEEL_CGEN_CALL ysfx_api_slider_show(void *opaque, EEL_F *mask_or_s ysfx_t *fx = REAPER_GET_INTERFACE(opaque); uint32_t slider = ysfx_get_slider_of_var(fx, mask_or_slider_); - uint8_t group; - uint64_t mask; - if (slider < ysfx_max_sliders) { - group = ysfx_fetch_slider_group_index(slider); - mask = ysfx_slider_mask(slider, group); - } else { - group = 0; - mask = ysfx_eel_round(std::fabs(*mask_or_slider_)); - } + if (ysfx_slider_exists(fx, slider)) { + uint8_t group; + uint64_t mask; + if (slider < ysfx_max_sliders) { + group = ysfx_fetch_slider_group_index(slider); + mask = ysfx_slider_mask(slider, group); + } else { + group = 0; + mask = ysfx_eel_round(std::fabs(*mask_or_slider_)); + } - if (*value_ >= (EEL_F)+0.5) { - // show - fx->slider.visible_mask[group] |= mask; - } - else if (*value_ >= (EEL_F)-0.5) { - // hide - mask = ~mask; - fx->slider.visible_mask[group] &= mask; - } - else { - // toggle - mask = fx->slider.visible_mask[group].fetch_xor(mask) ^ mask; + if (*value_ >= (EEL_F)+0.5) { + // show + fx->slider.visible_mask[group] |= mask; + } + else if (*value_ >= (EEL_F)-0.5) { + // hide + mask = ~mask; + fx->slider.visible_mask[group] &= mask; + } + else { + // toggle + mask = fx->slider.visible_mask[group].fetch_xor(mask) ^ mask; + } + return (EEL_F)mask; } - return (EEL_F)mask; + return (EEL_F)0; } static EEL_F NSEEL_CGEN_CALL ysfx_api_midisend(void *opaque, INT_PTR np, EEL_F **parms) diff --git a/tests/ysfx_test_slider.cpp b/tests/ysfx_test_slider.cpp index d0d4f7d..1008da5 100644 --- a/tests/ysfx_test_slider.cpp +++ b/tests/ysfx_test_slider.cpp @@ -105,6 +105,7 @@ TEST_CASE("slider manipulation", "[sliders]") "slider_show(slider5,1);" "\n" "slider_show(slider6,-1);" "\n" "slider_show(slider254,1);" "\n" + "slider_show(8,1);" "\n" "slider_show(slider255,-1);" "\n"; scoped_new_dir dir_fx("${root}/Effects"); @@ -136,6 +137,7 @@ TEST_CASE("slider manipulation", "[sliders]") REQUIRE(!slider_is_visible(3)); REQUIRE(!slider_is_visible(4)); REQUIRE(!slider_is_visible(5)); + REQUIRE(!slider_is_visible(7)); visible = ysfx_get_slider_visibility(fx.get(), 3); REQUIRE(!slider_is_visible(253)); @@ -150,6 +152,7 @@ TEST_CASE("slider manipulation", "[sliders]") REQUIRE(!slider_is_visible(3)); REQUIRE(slider_is_visible(4)); REQUIRE(slider_is_visible(5)); + REQUIRE(!slider_is_visible(7)); visible = ysfx_get_slider_visibility(fx.get(), 3); REQUIRE(slider_is_visible(253));