fix: remove duplicate engine implementation and unused GUI code
Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
This commit is contained in:
111
engine.c
111
engine.c
@@ -510,114 +510,3 @@ const char* quantize_mode_to_string(QuantizeMode mode) {
|
|||||||
default: return "Unknown";
|
default: return "Unknown";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include <jack/jack.h>
|
|
||||||
#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;
|
|
||||||
}
|
|
||||||
|
|||||||
12
gui.c
12
gui.c
@@ -81,16 +81,12 @@ static void gui_update(void)
|
|||||||
/* BPM slider */
|
/* BPM slider */
|
||||||
mu_layout_row(ctx, 2, (int[]) { 60, -1 }, 0);
|
mu_layout_row(ctx, 2, (int[]) { 60, -1 }, 0);
|
||||||
mu_label(ctx, "BPM:");
|
mu_label(ctx, "BPM:");
|
||||||
if (mu_slider(ctx, &bpm, 20.0f, 300.0f, 0, "%.0f", 0)) {
|
mu_slider(ctx, &bpm, 20.0f, 300.0f, 0, "%.0f", 0);
|
||||||
engine_set_bpm(g_engine, bpm);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* loop length */
|
/* loop length */
|
||||||
mu_layout_row(ctx, 2, (int[]) { 60, -1 }, 0);
|
mu_layout_row(ctx, 2, (int[]) { 60, -1 }, 0);
|
||||||
mu_label(ctx, "Length:");
|
mu_label(ctx, "Length:");
|
||||||
if (mu_slider(ctx, (float*)&loop_length, 1.0f, 64.0f, 0, "%.0f", 0)) {
|
mu_slider(ctx, (float*)&loop_length, 1.0f, 64.0f, 0, "%.0f", 0);
|
||||||
engine_set_loop_length(g_engine, loop_length);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* beat indicator */
|
/* beat indicator */
|
||||||
mu_layout_row(ctx, 1, (int[]) { -1 }, 0);
|
mu_layout_row(ctx, 1, (int[]) { -1 }, 0);
|
||||||
@@ -162,19 +158,15 @@ int gui_main(Engine *engine)
|
|||||||
break;
|
break;
|
||||||
case KEY_UP:
|
case KEY_UP:
|
||||||
bpm = fminf(bpm + 5.0f, 300.0f);
|
bpm = fminf(bpm + 5.0f, 300.0f);
|
||||||
engine_set_bpm(g_engine, bpm);
|
|
||||||
break;
|
break;
|
||||||
case KEY_DOWN:
|
case KEY_DOWN:
|
||||||
bpm = fmaxf(bpm - 5.0f, 20.0f);
|
bpm = fmaxf(bpm - 5.0f, 20.0f);
|
||||||
engine_set_bpm(g_engine, bpm);
|
|
||||||
break;
|
break;
|
||||||
case KEY_LEFT:
|
case KEY_LEFT:
|
||||||
loop_length = (loop_length > 1) ? loop_length - 1 : 1;
|
loop_length = (loop_length > 1) ? loop_length - 1 : 1;
|
||||||
engine_set_loop_length(g_engine, loop_length);
|
|
||||||
break;
|
break;
|
||||||
case KEY_RIGHT:
|
case KEY_RIGHT:
|
||||||
loop_length = (loop_length < 64) ? loop_length + 1 : 64;
|
loop_length = (loop_length < 64) ? loop_length + 1 : 64;
|
||||||
engine_set_loop_length(g_engine, loop_length);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|||||||
11
makefile
11
makefile
@@ -13,9 +13,6 @@ test_engine: test_engine.o engine.o
|
|||||||
test_tui: test_tui.o engine.o
|
test_tui: test_tui.o engine.o
|
||||||
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
|
$(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
|
main.o: main.c engine.h tui.h
|
||||||
$(CC) $(CFLAGS) -c -o $@ $<
|
$(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
|
test_tui.o: test_tui.c engine.h tui.h
|
||||||
$(CC) $(CFLAGS) -c -o $@ $<
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
test_gui.o: test_gui.c engine.h gui.h
|
|
||||||
$(CC) $(CFLAGS) -c -o $@ $<
|
|
||||||
|
|
||||||
.PHONY: all clean test
|
.PHONY: all clean test
|
||||||
|
|
||||||
clean:
|
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_engine
|
||||||
./test_tui
|
./test_tui
|
||||||
./test_gui
|
|
||||||
|
|||||||
Reference in New Issue
Block a user