fix: update GUI to use Engine struct and remove duplicate definitions
Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
This commit is contained in:
20
gui.c
20
gui.c
@@ -35,13 +35,11 @@ static mu_Context *ctx = NULL;
|
||||
static int running = 1;
|
||||
|
||||
/* engine state */
|
||||
static jack_client_t *client = NULL;
|
||||
static Engine *g_engine = NULL;
|
||||
static int active = 0;
|
||||
static float bpm = 120.0f;
|
||||
static int loop_length = 8; /* beats */
|
||||
static int current_beat = 0;
|
||||
static float *buffer = NULL;
|
||||
static int buffer_size = 0;
|
||||
|
||||
/* ---------------------------------------------------------------------------
|
||||
* drawing helpers (stubs for microui)
|
||||
@@ -68,9 +66,9 @@ static void gui_update(void)
|
||||
if (mu_button(ctx, active ? "Stop" : "Play")) {
|
||||
active = !active;
|
||||
if (active) {
|
||||
engine_start(client);
|
||||
engine_start(g_engine);
|
||||
} else {
|
||||
engine_stop(client);
|
||||
engine_stop(g_engine);
|
||||
}
|
||||
}
|
||||
if (mu_button(ctx, "Reset")) {
|
||||
@@ -84,14 +82,14 @@ static void gui_update(void)
|
||||
mu_layout_row(ctx, 2, (int[]) { 60, -1 }, 0);
|
||||
mu_label(ctx, "BPM:");
|
||||
if (mu_slider(ctx, &bpm, 20.0f, 300.0f, 0, "%.0f", 0)) {
|
||||
engine_set_bpm(client, bpm);
|
||||
engine_set_bpm(g_engine, bpm);
|
||||
}
|
||||
|
||||
/* loop length */
|
||||
mu_layout_row(ctx, 2, (int[]) { 60, -1 }, 0);
|
||||
mu_label(ctx, "Length:");
|
||||
if (mu_slider(ctx, (float*)&loop_length, 1.0f, 64.0f, 0, "%.0f", 0)) {
|
||||
engine_set_loop_length(client, loop_length);
|
||||
engine_set_loop_length(g_engine, loop_length);
|
||||
}
|
||||
|
||||
/* beat indicator */
|
||||
@@ -124,11 +122,9 @@ static void gui_update(void)
|
||||
/* ---------------------------------------------------------------------------
|
||||
* main loop
|
||||
* ------------------------------------------------------------------------- */
|
||||
int gui_main(jack_client_t *jack_client, float *audio_buffer, int buf_size)
|
||||
int gui_main(Engine *engine)
|
||||
{
|
||||
client = jack_client;
|
||||
buffer = audio_buffer;
|
||||
buffer_size = buf_size;
|
||||
g_engine = engine;
|
||||
|
||||
/* initialise microui */
|
||||
ctx = malloc(sizeof(mu_Context));
|
||||
@@ -186,7 +182,7 @@ int gui_main(jack_client_t *jack_client, float *audio_buffer, int buf_size)
|
||||
}
|
||||
|
||||
/* update engine state */
|
||||
current_beat = engine_get_current_beat(client);
|
||||
current_beat = engine_get_current_beat(g_engine);
|
||||
|
||||
/* render GUI */
|
||||
gui_update();
|
||||
|
||||
4
gui.h
4
gui.h
@@ -1,8 +1,8 @@
|
||||
#ifndef GUI_H
|
||||
#define GUI_H
|
||||
|
||||
#include <jack/jack.h>
|
||||
#include "engine.h"
|
||||
|
||||
int gui_main(jack_client_t *client, float *audio_buffer, int buf_size);
|
||||
int gui_main(Engine *engine);
|
||||
|
||||
#endif /* GUI_H */
|
||||
|
||||
@@ -45,7 +45,7 @@ int main(void)
|
||||
int ret = gui_main(client, buffer, buffer_size);
|
||||
|
||||
/* cleanup */
|
||||
engine_cleanup(client);
|
||||
engine_cleanup(g_engine);
|
||||
free(buffer);
|
||||
jack_client_close(client);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user