crude feedback gain control
This commit is contained in:
parent
12189efe88
commit
974b2ac941
@ -1,3 +1,8 @@
|
|||||||
|
#if defined(STFU_MAIN) && !defined(STFU_SLIDER)
|
||||||
|
#define STFU_SLIDER
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "../config.h"
|
#include "../config.h"
|
||||||
#include "border.c"
|
#include "border.c"
|
||||||
|
|
||||||
@ -8,6 +13,7 @@ struct stfu_slider {
|
|||||||
float width, height;
|
float width, height;
|
||||||
float r, g, b;
|
float r, g, b;
|
||||||
float min, max, cur;
|
float min, max, cur;
|
||||||
|
bool integeric;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void stfu_draw_slider(struct stfu_slider slider) {
|
static void stfu_draw_slider(struct stfu_slider slider) {
|
||||||
@ -36,3 +42,21 @@ static void stfu_draw_slider(struct stfu_slider slider) {
|
|||||||
sgl_end();
|
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
|
||||||
|
@ -32,6 +32,14 @@ static unsigned int crossfade_frames_left = 0;
|
|||||||
// 1.0 is with A at 440
|
// 1.0 is with A at 440
|
||||||
static float octave = 0.5;
|
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) {
|
static void stream(float *buffer, int num_frames, int num_channels) {
|
||||||
/* Fade away */
|
/* Fade away */
|
||||||
for (size_t i = 0; crossfade_frames_left > 0;
|
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) {
|
static void event(const sapp_event *e) {
|
||||||
switch (e->type) {
|
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: {
|
case SAPP_EVENTTYPE_KEY_DOWN: {
|
||||||
if (e->key_repeat)
|
if (e->key_repeat)
|
||||||
break;
|
break;
|
||||||
@ -221,13 +239,7 @@ static void frame(void) {
|
|||||||
sgl_load_default_pipeline();
|
sgl_load_default_pipeline();
|
||||||
sgl_load_identity();
|
sgl_load_identity();
|
||||||
sgl_ortho(0, STFU_MAKER_WINDOW_WIDTH, STFU_MAKER_WINDOW_HEIGHT, 0, -1, 1);
|
sgl_ortho(0, STFU_MAKER_WINDOW_WIDTH, STFU_MAKER_WINDOW_HEIGHT, 0, -1, 1);
|
||||||
stfu_draw_slider((struct stfu_slider){.x = 16,
|
stfu_draw_slider(feedback_slider);
|
||||||
.y = 16,
|
|
||||||
.width = 120,
|
|
||||||
.height = 16,
|
|
||||||
.min = 10,
|
|
||||||
.max = 100,
|
|
||||||
.cur = 55});
|
|
||||||
// sgl_pop_matrix();
|
// sgl_pop_matrix();
|
||||||
sgl_draw();
|
sgl_draw();
|
||||||
sg_end_pass();
|
sg_end_pass();
|
||||||
|
Loading…
Reference in New Issue
Block a user