From a4acc4cd3a4ef237fb7238894336bbc4af659e07 Mon Sep 17 00:00:00 2001 From: grm Date: Sun, 23 Nov 2025 22:54:56 +0200 Subject: add lsan supression --- src/synth_gui.c | 52 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 10 deletions(-) (limited to 'src/synth_gui.c') diff --git a/src/synth_gui.c b/src/synth_gui.c index f7a541f..77e1876 100644 --- a/src/synth_gui.c +++ b/src/synth_gui.c @@ -34,7 +34,7 @@ draw_text(synth_t * synth, int x, int y) void mouse(synth_t *synth) { - float m = GetMouseWheelMove(); + float m = GetMouseWheelMove(); int x = 0; if (m < 0) x = -1; else if (m > 0) x = 1; @@ -237,14 +237,6 @@ void frequencyToColor(float frequency, int *red, int *green, int *blue) { #include "fftw3.h" -float -amp(float re, float im) { - float a = fabsf(re); - float b = fabsf(im); - if (a < b) return b; - return a; -} - void draw_adsr(synth_t *synth, int x, int y, int width, int height) { @@ -609,6 +601,44 @@ generic_vbar(float val, float def, float min, float max, int x, int y, int widt return val; } +float +generic_hbar(float val, float def, float min, float max, + int x, int y, int width, int height) +{ + Vector2 p = GetMousePosition(); + uint checksum = rect_checksum(x, y, width, height); + + if (CheckCollisionPointRec(p, (Rectangle){x, y, width, height})) { + if (IsMouseButtonPressed(0)) { + rect_id_pressed = checksum; + } + if (IsMouseButtonPressed(1)) { + val = def; + } + } + + if (IsMouseButtonDown(0) && rect_id_pressed == checksum) { + if (p.x < x) { + val = min; + } else if (p.x >= x + width) { + val = max; + } else { + val = min + (max - min) * ((p.x - x) / (float)width); + } + } + + if (IsMouseButtonReleased(0) && rect_id_pressed == checksum) { + rect_id_pressed = 0; + } + + int fill_width = map(val, min, max, 0, width - 2); + + DrawRectangleLines(x, y, width, height, WHITE); + DrawRectangle(x + 1, y + 1, fill_width, height - 2, Fade(MAROON, 0.7f)); + + return val; +} + void draw_signals(synth_t * synth, int x, int y, int width, int height) { @@ -1210,7 +1240,9 @@ draw_main(synth_t *synth) // GUI char buf[64]; snprintf(buf, sizeof buf, "%d", synth->wvt_pos); - synth->wvt_pos = GuiSlider((Rectangle){WIDTH / 2.0 - 108, 150 + 42 + 42, 216, 24 }, "", buf, synth->wvt_pos , 0, 127); + float wvt_pos_x = WIDTH / 2.0 - 108, wvt_pos_y = 150 + 42 + 42, wvt_pos_width = 216, wvt_pos_height = 24, wvt_pos_font_size = 10; + synth->wvt_pos = generic_hbar(synth->wvt_pos, 1.0, 0, 127, wvt_pos_x, wvt_pos_y, wvt_pos_width, wvt_pos_height); + DrawText(buf, wvt_pos_x + wvt_pos_width + 5, wvt_pos_y + wvt_pos_height / 2 - wvt_pos_font_size / 2, wvt_pos_font_size, GRAY); set_sound_start(synth->wvt_pos*2048); set_sound_len(synth->wvt_pos*2048 + 2048); -- cgit v1.2.3