summaryrefslogtreecommitdiffstats
path: root/src/synth_gui.c
diff options
context:
space:
mode:
authorgrm <grm@eyesin.space>2025-11-23 22:54:56 +0200
committergrm <grm@eyesin.space>2025-11-23 22:54:56 +0200
commita4acc4cd3a4ef237fb7238894336bbc4af659e07 (patch)
tree68d05d5cc4c1900e6c19ee9bf3b6b06a1ce5fafd /src/synth_gui.c
parent8f00dd3df55677beff2924d2c6eec205744ebdf6 (diff)
downloadsynth-project-a4acc4cd3a4ef237fb7238894336bbc4af659e07.tar.gz
synth-project-a4acc4cd3a4ef237fb7238894336bbc4af659e07.tar.bz2
synth-project-a4acc4cd3a4ef237fb7238894336bbc4af659e07.zip
add lsan supression
Diffstat (limited to 'src/synth_gui.c')
-rw-r--r--src/synth_gui.c52
1 files changed, 42 insertions, 10 deletions
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);