feat: add JACK audio looper with clip state machine and tests
Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
This commit is contained in:
56
engine.h
Normal file
56
engine.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#ifndef ENGINE_H
|
||||
#define ENGINE_H
|
||||
|
||||
#include <jack/jack.h>
|
||||
#include <jack/midiport.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define MAX_CLIPS 128
|
||||
#define MAX_BUFFER_SIZE 441000 // 10 seconds at 44.1kHz
|
||||
|
||||
typedef enum {
|
||||
CLIP_EMPTY,
|
||||
CLIP_RECORDING,
|
||||
CLIP_LOOPING,
|
||||
CLIP_STOPPED
|
||||
} ClipState;
|
||||
|
||||
typedef struct {
|
||||
ClipState state;
|
||||
float *buffer;
|
||||
size_t buffer_size;
|
||||
size_t write_position;
|
||||
size_t read_position;
|
||||
bool is_playing;
|
||||
} Clip;
|
||||
|
||||
typedef struct {
|
||||
jack_client_t *client;
|
||||
jack_port_t *audio_in_port;
|
||||
jack_port_t *audio_out_port;
|
||||
jack_port_t *midi_in_port;
|
||||
jack_port_t *midi_out_port;
|
||||
|
||||
Clip clips[MAX_CLIPS];
|
||||
int control_channel;
|
||||
jack_nframes_t sample_rate;
|
||||
|
||||
bool running;
|
||||
} Engine;
|
||||
|
||||
// Engine lifecycle
|
||||
int engine_init(Engine *engine, const char *client_name);
|
||||
void engine_cleanup(Engine *engine);
|
||||
int engine_start(Engine *engine);
|
||||
void engine_stop(Engine *engine);
|
||||
|
||||
// Clip management
|
||||
void engine_trigger_clip(Engine *engine, int clip_index);
|
||||
void engine_reset_clip(Engine *engine, int clip_index);
|
||||
|
||||
// Utility
|
||||
const char* clip_state_to_string(ClipState state);
|
||||
uint8_t clip_state_to_velocity(ClipState state);
|
||||
|
||||
#endif // ENGINE_H
|
||||
Reference in New Issue
Block a user