feat: add 8x8 scene/channel grid, MIDI clock sync, and quantization engine
Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
This commit is contained in:
58
engine.h
58
engine.h
@@ -6,8 +6,15 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define MAX_CLIPS 128
|
||||
#define MAX_SCENES 8
|
||||
#define MAX_CHANNELS 8
|
||||
#define MAX_CLIPS (MAX_SCENES * MAX_CHANNELS) // 64
|
||||
#define MAX_BUFFER_SIZE 441000 // 10 seconds at 44.1kHz
|
||||
#define MIDI_CLOCKS_PER_BEAT 24
|
||||
#define BEATS_PER_BAR 4
|
||||
|
||||
// Convert scene/channel to flat clip index
|
||||
#define CLIP_INDEX(scene, channel) ((scene) * MAX_CHANNELS + (channel))
|
||||
|
||||
typedef enum {
|
||||
CLIP_EMPTY,
|
||||
@@ -16,6 +23,20 @@ typedef enum {
|
||||
CLIP_STOPPED
|
||||
} ClipState;
|
||||
|
||||
typedef enum {
|
||||
QUANTIZE_OFF,
|
||||
QUANTIZE_BEAT,
|
||||
QUANTIZE_BAR
|
||||
} QuantizeMode;
|
||||
|
||||
typedef struct {
|
||||
bool rolling;
|
||||
uint32_t clock_count;
|
||||
uint32_t beat_position; // 0-3
|
||||
uint32_t bar_position;
|
||||
uint32_t sample_position; // derived from clock at current sample rate
|
||||
} TransportState;
|
||||
|
||||
typedef struct {
|
||||
ClipState state;
|
||||
float *buffer;
|
||||
@@ -25,17 +46,36 @@ typedef struct {
|
||||
bool is_playing;
|
||||
} Clip;
|
||||
|
||||
// Queued trigger for quantization
|
||||
typedef struct QueuedTrigger {
|
||||
int clip_index;
|
||||
bool is_scene;
|
||||
jack_nframes_t trigger_time;
|
||||
struct QueuedTrigger *next;
|
||||
} QueuedTrigger;
|
||||
|
||||
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 *audio_in_ports[MAX_CHANNELS];
|
||||
jack_port_t *audio_out_ports[MAX_CHANNELS];
|
||||
jack_port_t *midi_in_port; // Control channel MIDI
|
||||
jack_port_t *midi_scene_in_port; // Scene launch MIDI
|
||||
jack_port_t *midi_clock_in_port; // MIDI clock input
|
||||
jack_port_t *midi_out_port;
|
||||
|
||||
Clip clips[MAX_CLIPS];
|
||||
int control_channel;
|
||||
jack_nframes_t sample_rate;
|
||||
|
||||
// Transport and clock
|
||||
TransportState transport;
|
||||
bool clock_sync_enabled;
|
||||
|
||||
// Quantization
|
||||
QuantizeMode quantize_mode;
|
||||
jack_nframes_t quantize_threshold; // in samples (lookahead)
|
||||
QueuedTrigger *queued_triggers;
|
||||
|
||||
bool running;
|
||||
} Engine;
|
||||
|
||||
@@ -47,10 +87,20 @@ void engine_stop(Engine *engine);
|
||||
|
||||
// Clip management
|
||||
void engine_trigger_clip(Engine *engine, int clip_index);
|
||||
void engine_trigger_scene(Engine *engine, int scene_index);
|
||||
void engine_reset_clip(Engine *engine, int clip_index);
|
||||
|
||||
// Transport
|
||||
void engine_set_quantize_mode(Engine *engine, QuantizeMode mode);
|
||||
void engine_set_quantize_threshold(Engine *engine, jack_nframes_t samples);
|
||||
void engine_reset_transport(Engine *engine);
|
||||
|
||||
// Queue management (exposed for testing)
|
||||
void queue_trigger(Engine *engine, int clip_index, bool is_scene, jack_nframes_t time);
|
||||
|
||||
// Utility
|
||||
const char* clip_state_to_string(ClipState state);
|
||||
uint8_t clip_state_to_velocity(ClipState state);
|
||||
const char* quantize_mode_to_string(QuantizeMode mode);
|
||||
|
||||
#endif // ENGINE_H
|
||||
|
||||
Reference in New Issue
Block a user