From 01998dd1a0ec3769d75bfdc7e6bee866850304c5 Mon Sep 17 00:00:00 2001 From: Loic Coenen Date: Fri, 1 May 2026 14:04:50 +0000 Subject: [PATCH] fix: remove duplicate engine implementation and unused GUI code Co-authored-by: aider (deepseek/deepseek-coder) --- engine.c | 111 ------------------------------------------------------- gui.c | 12 +----- makefile | 11 +----- 3 files changed, 4 insertions(+), 130 deletions(-) diff --git a/engine.c b/engine.c index 378f93c..9de91f2 100644 --- a/engine.c +++ b/engine.c @@ -510,114 +510,3 @@ const char* quantize_mode_to_string(QuantizeMode mode) { default: return "Unknown"; } } -#include -#include -#include -#include -#include -#include "engine.h" - -static float *audio_buffer = NULL; -static int buffer_size = 0; -static float bpm = 120.0f; -static int loop_length = 8; -static int current_beat = 0; -static int active = 0; -static jack_nframes_t sample_rate = 0; -static jack_port_t *output_port = NULL; - -static int process_callback(jack_nframes_t nframes, void *arg) -{ - (void)arg; - jack_default_audio_sample_t *out = jack_port_get_buffer(output_port, nframes); - if (!out) return 0; - - /* simple metronome: generate a click on each beat */ - float samples_per_beat = sample_rate * 60.0f / bpm; - static float phase = 0.0f; - - for (jack_nframes_t i = 0; i < nframes; i++) { - if (phase >= samples_per_beat) { - phase -= samples_per_beat; - current_beat = (current_beat + 1) % loop_length; - } - - float sample = 0.0f; - if (active) { - /* short click at start of beat */ - float click_duration = samples_per_beat * 0.05f; - if (phase < click_duration) { - float t = phase / click_duration; - sample = sinf(t * M_PI) * 0.3f; - } - } - out[i] = sample; - phase += 1.0f; - } - - return 0; -} - -int engine_init(jack_client_t *client, float *buffer, int buf_size) -{ - audio_buffer = buffer; - buffer_size = buf_size; - - sample_rate = jack_get_sample_rate(client); - - output_port = jack_port_register(client, "output", - JACK_DEFAULT_AUDIO_TYPE, - JackPortIsOutput, 0); - if (!output_port) { - fprintf(stderr, "no more JACK ports available\n"); - return -1; - } - - jack_set_process_callback(client, process_callback, NULL); - - if (jack_activate(client)) { - fprintf(stderr, "cannot activate client\n"); - return -1; - } - - return 0; -} - -void engine_cleanup(jack_client_t *client) -{ - jack_deactivate(client); - jack_port_unregister(client, output_port); -} - -int engine_start(jack_client_t *client) -{ - (void)client; - active = 1; - return 0; -} - -int engine_stop(jack_client_t *client) -{ - (void)client; - active = 0; - return 0; -} - -void engine_set_bpm(jack_client_t *client, float new_bpm) -{ - (void)client; - bpm = new_bpm; -} - -void engine_set_loop_length(jack_client_t *client, int beats) -{ - (void)client; - loop_length = beats; - if (current_beat >= loop_length) current_beat = 0; -} - -int engine_get_current_beat(jack_client_t *client) -{ - (void)client; - return current_beat; -} diff --git a/gui.c b/gui.c index 7404752..6f5bf23 100644 --- a/gui.c +++ b/gui.c @@ -81,16 +81,12 @@ static void gui_update(void) /* BPM slider */ 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(g_engine, bpm); - } + mu_slider(ctx, &bpm, 20.0f, 300.0f, 0, "%.0f", 0); /* 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(g_engine, loop_length); - } + mu_slider(ctx, (float*)&loop_length, 1.0f, 64.0f, 0, "%.0f", 0); /* beat indicator */ mu_layout_row(ctx, 1, (int[]) { -1 }, 0); @@ -162,19 +158,15 @@ int gui_main(Engine *engine) break; case KEY_UP: bpm = fminf(bpm + 5.0f, 300.0f); - engine_set_bpm(g_engine, bpm); break; case KEY_DOWN: bpm = fmaxf(bpm - 5.0f, 20.0f); - engine_set_bpm(g_engine, bpm); break; case KEY_LEFT: loop_length = (loop_length > 1) ? loop_length - 1 : 1; - engine_set_loop_length(g_engine, loop_length); break; case KEY_RIGHT: loop_length = (loop_length < 64) ? loop_length + 1 : 64; - engine_set_loop_length(g_engine, loop_length); break; default: break; diff --git a/makefile b/makefile index 608c6db..f6f0112 100644 --- a/makefile +++ b/makefile @@ -13,9 +13,6 @@ test_engine: test_engine.o engine.o test_tui: test_tui.o engine.o $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -test_gui: test_gui.o engine.o gui.o - $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) - main.o: main.c engine.h tui.h $(CC) $(CFLAGS) -c -o $@ $< @@ -34,15 +31,11 @@ test_engine.o: test_engine.c engine.h test_tui.o: test_tui.c engine.h tui.h $(CC) $(CFLAGS) -c -o $@ $< -test_gui.o: test_gui.c engine.h gui.h - $(CC) $(CFLAGS) -c -o $@ $< - .PHONY: all clean test clean: - rm -f *.o jack-looper test_engine test_tui test_gui + rm -f *.o jack-looper test_engine test_tui -test: test_engine test_tui test_gui +test: test_engine test_tui ./test_engine ./test_tui - ./test_gui