Phase 8: Add stereo track mixer, automation and undo/redo

This commit is contained in:
Johannes Findeisen 2026-10-27 01:06:57 +01:00
commit 7db5fb7738
45 changed files with 1611 additions and 130 deletions

View file

@ -24,6 +24,8 @@ void xtc_audio_plan_destroy(xtc_audio_plan *plan);
size_t xtc_audio_plan_issues(const xtc_audio_plan *plan, const char **out_first_path);
/* Single consumer; output replaced with overlap-summed mono at unity gain.
* Linear rate conversion, no time stretching. Output must have frames floats. */
/* Stereo outputs must be distinct; NULL right selects mono gain-only rendering. */
xtc_result xtc_audio_plan_render_stereo(const xtc_audio_plan *, uint64_t, float *left, float *right, size_t);
xtc_result xtc_audio_plan_render(const xtc_audio_plan *plan, uint64_t position,
float *output, size_t frames);
/* Control-thread creation opens a same-directory temporary float32 WAV.

View file

@ -13,9 +13,10 @@ typedef struct {
xtc_backend_kind kind;
const char *client_name; /* Borrowed for open only; nonempty. */
size_t max_frames; /* 1..65536, at least the server's current block. */
size_t channel_count; /* Currently must be 1. */
size_t channel_count; /* 1 mono or 2 stereo output; input/recording remain mono. */
} xtc_backend_config;
typedef struct {
float peak_left, peak_right; /* Last-block output peaks, zero while stopped. */
unsigned int sample_rate;
unsigned int buffer_frames;
unsigned int xruns; /* Wraps modulo UINT_MAX + 1. */
@ -63,6 +64,8 @@ void xtc_backend_collect(xtc_backend *backend);
/* Snapshot fields are individually coherent, not a transactional snapshot. */
xtc_result xtc_backend_get_status(const xtc_backend *backend, xtc_backend_status *out_status);
/* Borrowed names valid until close. Direction is the client's own port. */
/* Output channel 0 is legacy output, channel 1 is output_right in stereo. */
xtc_result xtc_backend_output_name(const xtc_backend *, size_t channel, const char **out_name);
xtc_result xtc_backend_port_name(const xtc_backend *backend, xtc_port_direction direction,
const char **out_name);
/* Enumerates available mono audio ports (devices and software routes). Visitor

View file

@ -109,6 +109,12 @@ void xtc_plan_destroy(xtc_plan *plan);
* unless require_output_nodes is set. Empty graphs produce silence.
* Unconnected gain/meter/output inputs receive external input. */
/* Separate mono source buffers; NULL is silence. Existing wrappers omit MIDI. */
/* Stereo graph with paired source buffers and a mono external input duplicated
* to both sides. Output buffers must be distinct and must not alias sources.
* Stereo oscillator phase advances once per frame. NULL right selects mono. */
xtc_result xtc_plan_process_stereo(xtc_plan *, const float *input,
const float *audio_left, const float *audio_right, const float *midi_left, const float *midi_right,
float *left, float *right, size_t frames);
xtc_result xtc_plan_process_sources(xtc_plan *plan, const float *input, const float *timeline,
const float *instrument, float *output, size_t frames);
/* timeline is a separate mono input for XTC_NODE_AUDIO, NULL means silence. */

View file

@ -49,6 +49,8 @@ void xtc_midi_plan_panic(xtc_midi_plan *plan, uint64_t position);
* caller order, count<=256, frames<=65536. Invalid input leaves state/output alone.
* Renders [position,position+frames); discontinuity clears live voices, chases
* scheduled notes at their correct phase. Note-off is immediate (no envelope). */
/* Distinct stereo outputs; NULL right retains mono (gain only). */
xtc_result xtc_midi_plan_render_stereo(xtc_midi_plan *, uint64_t, const xtc_midi_event *, size_t, float *left, float *right, size_t);
xtc_result xtc_midi_plan_render(xtc_midi_plan *plan, uint64_t position,
const xtc_midi_event *events, size_t count, float *output, size_t frames);
#ifdef __cplusplus

40
include/xtc/xtc_mixer.h Normal file
View file

@ -0,0 +1,40 @@
#ifndef XTC_MIXER_H
#define XTC_MIXER_H
#include "xtc_project.h"
#ifdef __cplusplus
extern "C" {
#endif
#define XTC_MAX_AUTOMATION_POINTS 1024U
#define XTC_HISTORY_EDITS 32U
typedef enum { XTC_AUTOMATION_GAIN = 0, XTC_AUTOMATION_PAN = 1 } xtc_automation_parameter;
typedef struct {
uint64_t track_id, tick;
xtc_automation_parameter parameter;
float value;
} xtc_automation_point;
/* Gain 0..4, pan -1..1, mute/solo 0 or 1. Track audio and scheduled MIDI only.
* Linear pan: center unity on both outputs; hard pan attenuates opposite side.
* Automation replaces the corresponding static value, linear between points,
* holds first/last outside the lane. Duplicate track/parameter/tick replaces. */
xtc_result xtc_project_set_mix(xtc_project *, uint64_t track, float gain, float pan, int mute,
int solo);
xtc_result xtc_project_set_automation(xtc_project *, const xtc_automation_point *);
xtc_result xtc_project_remove_automation(xtc_project *, uint64_t track, xtc_automation_parameter,
uint64_t tick);
xtc_result xtc_project_automation_count(const xtc_project *, size_t *);
xtc_result xtc_project_get_automation(const xtc_project *, size_t, xtc_automation_point *);
/* Control-thread snapshot history; 32 edits plus baseline, no assets/DSP/GUI.
* record clones before changing history; failure retains all history. checkout
* clones adjacent state without moving cursor; accept only after installation.
* Allocation ID high-water marks survive checkout/branching.
* Reset by creating a new history for New/Open. */
typedef struct xtc_history xtc_history;
xtc_result xtc_history_create(const xtc_project *, xtc_history **);
void xtc_history_destroy(xtc_history *);
xtc_result xtc_history_record(xtc_history *, const xtc_project *);
xtc_result xtc_history_checkout(const xtc_history *, int redo, xtc_project **);
xtc_result xtc_history_accept(xtc_history *, int redo);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -11,7 +11,9 @@ extern "C" {
#define XTC_TICKS_PER_QUARTER 960U
#define XTC_PROJECT_MAX_TICK UINT64_C(38400000)
typedef struct xtc_project xtc_project;
typedef struct { uint64_t id; char name[XTC_PROJECT_NAME_BYTES]; } xtc_track_info;
typedef struct { uint64_t id; char name[XTC_PROJECT_NAME_BYTES];
float gain, pan; int mute, solo;
} xtc_track_info;
/* Arrangement region: empty asset_path means silent metadata.
* All musical positions are integer ticks, constant tempo and 4/4 meter. */
typedef struct {

View file

@ -31,6 +31,9 @@ xtc_result xtc_realtime_get_status(const xtc_realtime *engine,
* frame_count must be <= configured max_frames and output must hold it.
* Oversized buffers are silenced too; callers must bound their own frame count.
* NULL input means silence. Zero frames is a no-op. */
xtc_result xtc_realtime_process_stereo(xtc_realtime *, const float *input,
const float *audio_left, const float *audio_right, const float *midi_left, const float *midi_right,
float *left, float *right, size_t frames);
xtc_result xtc_realtime_process_sources(xtc_realtime *engine, const float *input, const float *timeline,
const float *instrument, float *output, size_t frames);
xtc_result xtc_realtime_process_audio(xtc_realtime *engine, const float *input, const float *timeline,