Phase 8: Add stereo track mixer, automation and undo/redo
This commit is contained in:
parent
cacc086805
commit
7db5fb7738
45 changed files with 1611 additions and 130 deletions
|
|
@ -4,3 +4,7 @@ project_file.c implements bounded version-2 project metadata loading (including
|
|||
temporary-file/fsync/rename saving in C. Loading validates a candidate before
|
||||
replacing the existing model. All I/O is control-thread only.
|
||||
See docs/PROJECT_FORMAT.md for the schema, limits and durability guarantees.
|
||||
|
||||
Phase 8 writes format v4 with per-track MIX records and bounded AUTOMATION/POINT
|
||||
records, reading v1–v3 with unity/center/no-automation defaults. History stays
|
||||
session-only. See ../../docs/PROJECT_FORMAT.md.
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ static xtc_result read_project(reader *input, xtc_project *project)
|
|||
size_t i, j;
|
||||
xtc_graph *graph = project->graph;
|
||||
READ("XTC_PROJECT", 2U); NUM(1U, version);
|
||||
if (version < 1U || version > 3U) return XTC_ERR_UNSUPPORTED;
|
||||
if (version < 1U || version > 4U) return XTC_ERR_UNSUPPORTED;
|
||||
format_version = version;
|
||||
READ("APP", 4U);
|
||||
for (i = 1U; i < 4U; ++i) { NUM(i, value); if (value > UINT_MAX) return XTC_ERR_FORMAT; }
|
||||
|
|
@ -124,6 +124,14 @@ static xtc_result read_project(reader *input, xtc_project *project)
|
|||
for (i = 0U; i < project->track_count; ++i) {
|
||||
READ("TRACK", 3U); NUM(1U, project->tracks[i].id);
|
||||
if (!decode_name(input->tokens[2], project->tracks[i].name)) return XTC_ERR_FORMAT;
|
||||
project->tracks[i].gain = 1;
|
||||
if (format_version >= 4U) {
|
||||
READ("MIX", 5U);
|
||||
if (!decode_float(input->tokens[1], &project->tracks[i].gain) ||
|
||||
!decode_float(input->tokens[2], &project->tracks[i].pan)) return XTC_ERR_FORMAT;
|
||||
NUM(3U, value); if (value > 1) return XTC_ERR_FORMAT; project->tracks[i].mute = (int)value;
|
||||
NUM(4U, value); if (value > 1) return XTC_ERR_FORMAT; project->tracks[i].solo = (int)value;
|
||||
}
|
||||
}
|
||||
READ("CLIPS", 2U); NUM(1U, value);
|
||||
if (value > XTC_PROJECT_MAX_CLIPS) return XTC_ERR_FORMAT;
|
||||
|
|
@ -167,6 +175,19 @@ static xtc_result read_project(reader *input, xtc_project *project)
|
|||
NUM(7U, value); if (value > 15) return XTC_ERR_FORMAT; n->channel = (unsigned int)value;
|
||||
}
|
||||
}
|
||||
if (format_version >= 4U) {
|
||||
READ("AUTOMATION", 2U); NUM(1U, value);
|
||||
if (value > XTC_MAX_AUTOMATION_POINTS) return XTC_ERR_FORMAT;
|
||||
project->automation_count = (size_t)value;
|
||||
for (i = 0; i < project->automation_count; ++i) {
|
||||
xtc_automation_point *a = project->automation + i;
|
||||
READ("POINT", 5U); NUM(1U, a->track_id); NUM(2U, value);
|
||||
if (value > 1) return XTC_ERR_FORMAT;
|
||||
a->parameter = (xtc_automation_parameter)value;
|
||||
NUM(3U, a->tick);
|
||||
if (!decode_float(input->tokens[4], &a->value)) return XTC_ERR_FORMAT;
|
||||
}
|
||||
}
|
||||
READ("END", 1U);
|
||||
if (fgetc(input->file) != EOF) return XTC_ERR_FORMAT;
|
||||
if (ferror(input->file)) return XTC_ERR_IO;
|
||||
|
|
@ -183,7 +204,7 @@ static xtc_result write_project(FILE *file, const xtc_project *project)
|
|||
const xtc_graph *graph = project->graph;
|
||||
size_t i;
|
||||
if (sizeof(float) != sizeof(uint32_t) || FLT_RADIX != 2 || FLT_MANT_DIG != 24 || FLT_MAX_EXP != 128) return XTC_ERR_UNSUPPORTED;
|
||||
if (fprintf(file, "XTC_PROJECT 3\nAPP %d %d %d\nTEMPO %u\nIDS %" PRIu64 " %" PRIu64 "\nGRAPH %d %zu %zu %zu\n",
|
||||
if (fprintf(file, "XTC_PROJECT 4\nAPP %d %d %d\nTEMPO %u\nIDS %" PRIu64 " %" PRIu64 "\nGRAPH %d %zu %zu %zu\n",
|
||||
XTC_VERSION_MAJOR, XTC_VERSION_MINOR, XTC_VERSION_PATCH, project->tempo,
|
||||
project->next_track_id, project->next_clip_id, graph->require_output_nodes,
|
||||
graph->next_id, graph->node_count, graph->edge_count) < 0) return XTC_ERR_IO;
|
||||
|
|
@ -197,8 +218,13 @@ static xtc_result write_project(FILE *file, const xtc_project *project)
|
|||
if (fprintf(file, "EDGE %zu %zu\n", graph->nodes[graph->edges[i].source].id,
|
||||
graph->nodes[graph->edges[i].destination].id) < 0) return XTC_ERR_IO;
|
||||
if (fprintf(file, "TRACKS %zu\n", project->track_count) < 0) return XTC_ERR_IO;
|
||||
for (i = 0U; i < project->track_count; ++i)
|
||||
if (fprintf(file, "TRACK %" PRIu64 " ", project->tracks[i].id) < 0 || !write_name(file, project->tracks[i].name)) return XTC_ERR_IO;
|
||||
for (i = 0U; i < project->track_count; ++i) {
|
||||
uint32_t gain, pan;
|
||||
const xtc_track_info *t = project->tracks + i;
|
||||
memcpy(&gain, &t->gain, sizeof(gain)); memcpy(&pan, &t->pan, sizeof(pan));
|
||||
if (fprintf(file, "TRACK %" PRIu64 " ", t->id) < 0 || !write_name(file, t->name) ||
|
||||
fprintf(file, "MIX %08" PRIx32 " %08" PRIx32 " %d %d\n", gain, pan, t->mute, t->solo) < 0) return XTC_ERR_IO;
|
||||
}
|
||||
if (fprintf(file, "CLIPS %zu\n", project->clip_count) < 0) return XTC_ERR_IO;
|
||||
for (i = 0U; i < project->clip_count; ++i) {
|
||||
const xtc_clip_info *clip = project->clips + i;
|
||||
|
|
@ -217,6 +243,13 @@ static xtc_result write_project(FILE *file, const xtc_project *project)
|
|||
if (fprintf(file, "NOTE %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %u %u %u\n",
|
||||
n->id, n->clip_id, n->start_tick, n->length_tick, n->pitch, n->velocity, n->channel) < 0) return XTC_ERR_IO;
|
||||
}
|
||||
if (fprintf(file, "AUTOMATION %zu\n", project->automation_count) < 0) return XTC_ERR_IO;
|
||||
for (i = 0; i < project->automation_count; ++i) {
|
||||
uint32_t bits; const xtc_automation_point *a = project->automation + i;
|
||||
memcpy(&bits, &a->value, sizeof(bits));
|
||||
if (fprintf(file, "POINT %" PRIu64 " %u %" PRIu64 " %08" PRIx32 "\n",
|
||||
a->track_id, (unsigned int)a->parameter, a->tick, bits) < 0) return XTC_ERR_IO;
|
||||
}
|
||||
return fputs("END\n", file) == EOF ? XTC_ERR_IO : XTC_OK;
|
||||
}
|
||||
static size_t path_length(const char *path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue