refactor: split monolithic main.c into modular source files

Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
This commit is contained in:
Loic Coenen
2026-05-08 21:03:10 +00:00
parent f1a92f1e95
commit 96295fdb4c
8 changed files with 423 additions and 336 deletions

38
src/channel.c Normal file
View File

@@ -0,0 +1,38 @@
#include <stdio.h>
#include <string.h>
#include <jack/jack.h>
#include <stdatomic.h>
#include "channel.h"
void channel_add(jack_client_t *client, int idx)
{
channels[idx].active = 1;
atomic_store(&channels[idx].state, STATE_IDLE);
channels[idx].prev_state = -1;
channels[idx].loop_count = 0;
channels[idx].record_pos = 0;
channels[idx].playback_pos = 0;
char in_name[64], out_name[64];
snprintf(in_name, sizeof(in_name), "channel%d_input", next_channel_id);
snprintf(out_name, sizeof(out_name), "channel%d_output", next_channel_id);
channels[idx].audio_in = jack_port_register(client, in_name,
JACK_DEFAULT_AUDIO_TYPE,
JackPortIsInput, 0);
channels[idx].audio_out = jack_port_register(client, out_name,
JACK_DEFAULT_AUDIO_TYPE,
JackPortIsOutput, 0);
if (!channels[idx].audio_in || !channels[idx].audio_out)
fprintf(stderr, "Failed to register ports for channel %d\n", next_channel_id);
next_channel_id++;
channel_count++;
}
void channel_remove(jack_client_t *client, int idx)
{
jack_port_unregister(client, channels[idx].audio_in);
jack_port_unregister(client, channels[idx].audio_out);
channels[idx].active = 0;
channel_count--;
}