Skip to content

Commit

Permalink
ysfx: don't allow making undefined sliders visible
Browse files Browse the repository at this point in the history
  • Loading branch information
JoepVanlier committed Sep 19, 2024
1 parent 63db1d2 commit 4732b86
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
47 changes: 25 additions & 22 deletions sources/ysfx_api_reaper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t>(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<uint64_t>(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)
Expand Down
3 changes: 3 additions & 0 deletions tests/ysfx_test_slider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand Down

0 comments on commit 4732b86

Please sign in to comment.