crude feedback gain control

This commit is contained in:
veclavtalica 2024-06-29 18:33:59 +03:00
parent 12189efe88
commit 974b2ac941
2 changed files with 43 additions and 7 deletions

View File

@ -1,3 +1,8 @@
#if defined(STFU_MAIN) && !defined(STFU_SLIDER)
#define STFU_SLIDER
#include <stdbool.h>
#include "../config.h"
#include "border.c"
@ -8,6 +13,7 @@ struct stfu_slider {
float width, height;
float r, g, b;
float min, max, cur;
bool integeric;
};
static void stfu_draw_slider(struct stfu_slider slider) {
@ -36,3 +42,21 @@ static void stfu_draw_slider(struct stfu_slider slider) {
sgl_end();
}
}
static struct stfu_slider stfu_press_slider(struct stfu_slider slider, float x,
float y) {
if (x < slider.x || x > slider.x + slider.width)
return slider;
if (y < slider.y || y > slider.y + slider.height)
return slider;
slider.cur = slider.min +
((x - slider.x) / (slider.width)) * (slider.max - slider.min);
if (slider.integeric)
slider.cur = floorf(slider.cur);
return slider;
}
#endif

View File

@ -32,6 +32,14 @@ static unsigned int crossfade_frames_left = 0;
// 1.0 is with A at 440
static float octave = 0.5;
static struct stfu_slider feedback_slider = {.x = 16,
.y = 16,
.width = 120,
.height = 16,
.min = 0,
.max = 1,
.cur = 0.25};
static void stream(float *buffer, int num_frames, int num_channels) {
/* Fade away */
for (size_t i = 0; crossfade_frames_left > 0;
@ -95,6 +103,16 @@ static void cleanup(void) { saudio_shutdown(); }
static void event(const sapp_event *e) {
switch (e->type) {
case SAPP_EVENTTYPE_MOUSE_DOWN: {
if (e->mouse_button != SAPP_MOUSEBUTTON_LEFT)
break;
feedback_slider =
stfu_press_slider(feedback_slider, e->mouse_x, e->mouse_y);
synth.feedback_gain = feedback_slider.cur;
break;
}
case SAPP_EVENTTYPE_KEY_DOWN: {
if (e->key_repeat)
break;
@ -221,13 +239,7 @@ static void frame(void) {
sgl_load_default_pipeline();
sgl_load_identity();
sgl_ortho(0, STFU_MAKER_WINDOW_WIDTH, STFU_MAKER_WINDOW_HEIGHT, 0, -1, 1);
stfu_draw_slider((struct stfu_slider){.x = 16,
.y = 16,
.width = 120,
.height = 16,
.min = 10,
.max = 100,
.cur = 55});
stfu_draw_slider(feedback_slider);
// sgl_pop_matrix();
sgl_draw();
sg_end_pass();