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

@ -2,6 +2,7 @@
#include "xtc/xtc_audio.h"
#include "../graph/graph_internal.h"
#include <stdlib.h>
#include <math.h>
#include <string.h>
int xtc_project_valid_name(const char *name)
@ -127,7 +128,7 @@ xtc_result xtc_project_add_track(xtc_project *project, const char *name, uint64_
xtc_track_info track = {0};
if (project == NULL || id == NULL || !xtc_project_valid_name(name)) return XTC_ERR_INVALID_ARGUMENT;
if (project->track_count == XTC_PROJECT_MAX_TRACKS || project->next_track_id == UINT64_MAX) return XTC_ERR_CAPACITY;
track.id = project->next_track_id++;
track.id = project->next_track_id++; track.gain = 1.0f;
memcpy(track.name, name, strlen(name) + 1U);
project->tracks[project->track_count++] = track; *id = track.id; return XTC_OK;
}
@ -146,7 +147,11 @@ xtc_result xtc_project_remove_track(xtc_project *project, uint64_t id)
count = 0;
for (i = 0; i < project->note_count; ++i)
if (clip_index(project, project->notes[i].clip_id) != SIZE_MAX) project->notes[count++] = project->notes[i];
project->note_count = count; return XTC_OK;
project->note_count = count;
count = 0;
for (i = 0; i < project->automation_count; ++i)
if (project->automation[i].track_id != id) project->automation[count++] = project->automation[i];
project->automation_count = count; return XTC_OK;
}
xtc_result xtc_project_add_clip(xtc_project *project, uint64_t track, const char *name,
uint64_t start, uint64_t length, uint64_t *id)
@ -246,6 +251,21 @@ xtc_result xtc_project_validate(const xtc_project *project)
n->length_tick > project->clips[c].source_length_tick - n->start_tick) return XTC_ERR_FORMAT;
for (j = 0; j < i; ++j) if (project->notes[j].id == n->id) return XTC_ERR_FORMAT;
}
if (project->automation_count > XTC_MAX_AUTOMATION_POINTS) return XTC_ERR_FORMAT;
for (i = 0; i < project->track_count; ++i) {
const xtc_track_info *t = project->tracks + i;
if (!isfinite(t->gain) || t->gain < 0 || t->gain > 4 || !isfinite(t->pan) || t->pan < -1 || t->pan > 1 ||
(t->mute != 0 && t->mute != 1) || (t->solo != 0 && t->solo != 1)) return XTC_ERR_FORMAT;
}
for (i = 0; i < project->automation_count; ++i) {
const xtc_automation_point *a = project->automation + i;
if (track_index(project, a->track_id) == SIZE_MAX || a->tick > XTC_PROJECT_MAX_TICK ||
!isfinite(a->value) || (a->parameter != XTC_AUTOMATION_GAIN && a->parameter != XTC_AUTOMATION_PAN) ||
a->value < (a->parameter == XTC_AUTOMATION_GAIN ? 0 : -1) ||
a->value > (a->parameter == XTC_AUTOMATION_GAIN ? 4 : 1)) return XTC_ERR_FORMAT;
for (j = 0; j < i; ++j) if (project->automation[j].track_id == a->track_id &&
project->automation[j].parameter == a->parameter && project->automation[j].tick == a->tick) return XTC_ERR_FORMAT;
}
return XTC_OK;
}