feat: add save/load thread and WAV file I/O for clip persistence

Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
This commit is contained in:
Loic Coenen
2026-05-02 10:18:04 +00:00
parent c48394f341
commit f37cb5c0a6
6 changed files with 505 additions and 1 deletions

View File

@@ -6,6 +6,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <stdatomic.h>
#include <pthread.h>
#include "transport.h"
#define MAX_SCENES 8
@@ -114,6 +115,25 @@ typedef struct {
atomic_uint read_index;
} CommandQueue;
// Save/Load request types
typedef enum {
REQ_SAVE_CLIP,
REQ_LOAD_CLIP
} SaveLoadType;
typedef struct {
SaveLoadType type;
int clip_index;
char filename[256];
} SaveLoadRequest;
// Lock-free queue for save/load requests (audio thread -> save/load thread)
typedef struct {
SaveLoadRequest buffer[MAX_QUEUED_COMMANDS];
atomic_uint write_index;
atomic_uint read_index;
} SaveLoadQueue;
// Queued trigger for quantization
typedef struct QueuedTrigger {
int clip_index;
@@ -154,6 +174,11 @@ typedef struct {
// Undo/Redo
UndoHistory undo_history;
// Save/Load queue and thread
SaveLoadQueue save_load_queue;
pthread_t save_load_thread;
volatile bool save_load_running;
} Engine;
// Engine lifecycle
@@ -189,6 +214,16 @@ void engine_process_commands(Engine *engine);
// Initialize command queue (exposed for testing)
void command_queue_init(CommandQueue *q);
// Save/Load queue management
void save_load_queue_init(SaveLoadQueue *q);
int save_load_queue_push(SaveLoadQueue *q, SaveLoadType type, int clip_index, const char *filename);
int save_load_queue_pop(SaveLoadQueue *q, SaveLoadRequest *req);
// Save/Load thread
void* save_load_thread_func(void *arg);
int engine_start_save_load_thread(Engine *engine);
void engine_stop_save_load_thread(Engine *engine);
// Utility
const char* clip_state_to_string(ClipState state);
uint8_t clip_state_to_velocity(ClipState state);