1
0
Fork 0
forked from hanez/xtc

Phase 5: Add project persistence and sequencer foundation

This commit is contained in:
Johannes Findeisen 2026-10-27 00:10:45 +01:00
commit 65640c4aad
28 changed files with 1307 additions and 84 deletions

View file

@ -18,6 +18,7 @@ typedef struct {
unsigned int buffer_frames;
unsigned int xruns; /* Wraps modulo UINT_MAX + 1. */
unsigned int processed_blocks;
uint64_t sample_position; /* Successful callback frames; retained across stop/submit. */
unsigned int submitted_revision, active_revision;
int running;
int server_lost;
@ -37,6 +38,8 @@ xtc_result xtc_backend_open(const xtc_backend_config *config, xtc_backend **out_
xtc_result xtc_backend_close(xtc_backend *backend);
xtc_result xtc_backend_start(xtc_backend *backend);
xtc_result xtc_backend_stop(xtc_backend *backend);
/* Stopped only; changes transport clock, not oscillator phase. */
xtc_result xtc_backend_seek(xtc_backend *backend, uint64_t sample);
/* Copies graph. While running, capacity means pending slot busy.
* While stopped, transactionally replaces all retained plans (counters/revisions
* restart); failed compilation leaves the previous engine intact. */

View file

@ -1,22 +1,59 @@
#ifndef XTC_PROJECT_H
#define XTC_PROJECT_H
#include "xtc_types.h"
#include "xtc_engine.h"
#ifdef __cplusplus
extern "C" {
#endif
#define XTC_PROJECT_MAX_TRACKS 64U
#define XTC_PROJECT_MAX_CLIPS 1024U
#define XTC_PROJECT_NAME_BYTES 64U
#define XTC_TICKS_PER_QUARTER 960U
#define XTC_PROJECT_MAX_TICK UINT64_C(38400000)
typedef struct xtc_project xtc_project;
/* Project persistence is not implemented in this scaffold yet. */
typedef struct { uint64_t id; char name[XTC_PROJECT_NAME_BYTES]; } xtc_track_info;
/* Silent arrangement region: audio assets and MIDI content are future phases.
* All musical positions are integer ticks, constant tempo and 4/4 meter. */
typedef struct {
uint64_t id, track_id, start_tick, length_tick, offset_tick, source_length_tick;
char name[XTC_PROJECT_NAME_BYTES];
} xtc_clip_info;
/* Single control-thread ownership. Names: nonempty UTF-8, <=63 bytes, no ASCII controls.
* IDs are monotonic, never reused, UINT64_MAX reserved. Snapshots are copies. */
xtc_result xtc_project_create(xtc_project **out_project);
void xtc_project_destroy(xtc_project *project);
xtc_result xtc_project_clone(const xtc_project *project, xtc_project **out_project);
xtc_result xtc_project_get_counts(const xtc_project *project, size_t *out_tracks, size_t *out_clips);
xtc_result xtc_project_get_track(const xtc_project *project, size_t index, xtc_track_info *out_track);
xtc_result xtc_project_get_clip(const xtc_project *project, size_t index, xtc_clip_info *out_clip);
xtc_result xtc_project_find_clip(const xtc_project *project, uint64_t id, xtc_clip_info *out_clip);
xtc_result xtc_project_add_track(xtc_project *project, const char *name, uint64_t *out_id);
/* Removing a track also removes its clips. */
xtc_result xtc_project_remove_track(xtc_project *project, uint64_t id);
xtc_result xtc_project_add_clip(xtc_project *project, uint64_t track_id, const char *name,
uint64_t start_tick, uint64_t length_tick, uint64_t *out_id);
xtc_result xtc_project_remove_clip(xtc_project *project, uint64_t id);
/* Atomic move/trim: source bounds remain unchanged, no destructive edits. */
xtc_result xtc_project_edit_clip(xtc_project *project, uint64_t id, uint64_t track_id,
uint64_t start_tick, uint64_t length_tick, uint64_t offset_tick);
/* Borrowed opaque graph valid until project mutation/destruction. set_graph
* copies before replacing; max 64 nodes, preserving IDs, edges and output policy. */
const xtc_graph *xtc_project_graph(const xtc_project *project);
xtc_result xtc_project_set_graph(xtc_project *project, const xtc_graph *graph);
/* Constant tempo in milli-BPM: 20000..300000, default 120000. */
unsigned int xtc_project_tempo(const xtc_project *project);
xtc_result xtc_project_set_tempo(xtc_project *project, unsigned int milli_bpm);
/* Floor conversion, no accumulated drift. Rate: 1..768000. Tick <= MAX_TICK.
* Excess sample/tick positions return capacity; outputs unchanged on error. */
xtc_result xtc_project_tick_to_sample(const xtc_project *project, uint64_t tick,
unsigned int sample_rate, uint64_t *out_sample);
xtc_result xtc_project_sample_to_tick(const xtc_project *project, uint64_t sample,
unsigned int sample_rate, uint64_t *out_tick);
/* Control-thread I/O. Versioned, bounded format; see docs/PROJECT_FORMAT.md.
* Load is transactional. Save fsyncs a same-directory temporary and renames it;
* failures before rename preserve the previous destination. No asset I/O. */
xtc_result xtc_project_save(const xtc_project *project, const char *path);
xtc_result xtc_project_load(xtc_project *project, const char *path);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -17,7 +17,8 @@ typedef enum {
XTC_ERR_IO,
XTC_ERR_UNSUPPORTED,
XTC_ERR_CAPACITY,
XTC_ERR_GRAPH_CYCLE
XTC_ERR_GRAPH_CYCLE,
XTC_ERR_FORMAT
} xtc_result;
const char *xtc_result_string(xtc_result result);