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,8 @@ project.c owns the opaque C project: graph, bounded tracks, silent/audio arrange
|
|||
regions and external asset references, tempo and stable ID allocation. The GUI borrows handles and edits through
|
||||
xtc_project.h. Tick/sample conversion and source-preserving trim validation live
|
||||
here; no FLTK, file I/O or callback scheduling belongs in this module.
|
||||
|
||||
Phase 8 adds track mix settings, bounded automation and 32-edit C snapshot
|
||||
history in history.c. Checkout/accept separates candidate installation from
|
||||
history cursor movement; allocation IDs stay monotonic across history branches.
|
||||
See ../../docs/MIXER.md.
|
||||
|
|
|
|||
111
src/project/history.c
Normal file
111
src/project/history.c
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
#include "../graph/graph_internal.h"
|
||||
#include "project_internal.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
struct xtc_history {
|
||||
xtc_project *states[XTC_HISTORY_EDITS + 1];
|
||||
size_t count, cursor;
|
||||
uint64_t next_track, next_clip, next_note;
|
||||
size_t next_node;
|
||||
};
|
||||
static void remember_ids(xtc_history *h, const xtc_project *p)
|
||||
{
|
||||
if (p->next_track_id > h->next_track)
|
||||
h->next_track = p->next_track_id;
|
||||
if (p->next_clip_id > h->next_clip)
|
||||
h->next_clip = p->next_clip_id;
|
||||
if (p->next_note_id > h->next_note)
|
||||
h->next_note = p->next_note_id;
|
||||
if (p->graph->next_id > h->next_node)
|
||||
h->next_node = p->graph->next_id;
|
||||
}
|
||||
void xtc_history_destroy(xtc_history *h)
|
||||
{
|
||||
size_t i;
|
||||
if (!h)
|
||||
return;
|
||||
for (i = 0; i < h->count; ++i)
|
||||
xtc_project_destroy(h->states[i]);
|
||||
free(h);
|
||||
}
|
||||
xtc_result xtc_history_create(const xtc_project *p, xtc_history **out)
|
||||
{
|
||||
xtc_history *h;
|
||||
xtc_result r;
|
||||
if (!out)
|
||||
return XTC_ERR_INVALID_ARGUMENT;
|
||||
*out = NULL;
|
||||
if (!p)
|
||||
return XTC_ERR_INVALID_ARGUMENT;
|
||||
h = calloc(1, sizeof(*h));
|
||||
if (!h)
|
||||
return XTC_ERR_OUT_OF_MEMORY;
|
||||
r = xtc_project_clone(p, h->states);
|
||||
if (r != XTC_OK) {
|
||||
free(h);
|
||||
return r;
|
||||
}
|
||||
remember_ids(h, p);
|
||||
h->count = 1;
|
||||
*out = h;
|
||||
return XTC_OK;
|
||||
}
|
||||
xtc_result xtc_history_record(xtc_history *h, const xtc_project *p)
|
||||
{
|
||||
xtc_project *copy;
|
||||
size_t i;
|
||||
xtc_result r;
|
||||
if (!h || !p)
|
||||
return XTC_ERR_INVALID_ARGUMENT;
|
||||
r = xtc_project_clone(p, ©);
|
||||
if (r != XTC_OK)
|
||||
return r;
|
||||
remember_ids(h, p);
|
||||
for (i = h->cursor + 1; i < h->count; ++i)
|
||||
xtc_project_destroy(h->states[i]);
|
||||
h->count = h->cursor + 1;
|
||||
if (h->count == XTC_HISTORY_EDITS + 1) {
|
||||
xtc_project_destroy(h->states[0]);
|
||||
memmove(h->states, h->states + 1, XTC_HISTORY_EDITS * sizeof(*h->states));
|
||||
--h->count;
|
||||
}
|
||||
h->states[h->count++] = copy;
|
||||
h->cursor = h->count - 1;
|
||||
return XTC_OK;
|
||||
}
|
||||
static int available(const xtc_history *h, int redo)
|
||||
{
|
||||
return redo ? h->cursor + 1 < h->count : h->cursor > 0;
|
||||
}
|
||||
xtc_result xtc_history_checkout(const xtc_history *h, int redo, xtc_project **out)
|
||||
{
|
||||
if (!out)
|
||||
return XTC_ERR_INVALID_ARGUMENT;
|
||||
*out = NULL;
|
||||
if (!h || (redo != 0 && redo != 1))
|
||||
return XTC_ERR_INVALID_ARGUMENT;
|
||||
if (!available(h, redo))
|
||||
return XTC_ERR_NOT_FOUND;
|
||||
{
|
||||
xtc_result r = xtc_project_clone(h->states[redo ? h->cursor + 1 : h->cursor - 1], out);
|
||||
if (r == XTC_OK) {
|
||||
(*out)->next_track_id = h->next_track;
|
||||
(*out)->next_clip_id = h->next_clip;
|
||||
(*out)->next_note_id = h->next_note;
|
||||
(*out)->graph->next_id = h->next_node;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
}
|
||||
xtc_result xtc_history_accept(xtc_history *h, int redo)
|
||||
{
|
||||
if (!h || (redo != 0 && redo != 1))
|
||||
return XTC_ERR_INVALID_ARGUMENT;
|
||||
if (!available(h, redo))
|
||||
return XTC_ERR_NOT_FOUND;
|
||||
if (redo)
|
||||
++h->cursor;
|
||||
else
|
||||
--h->cursor;
|
||||
return XTC_OK;
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#define XTC_PROJECT_INTERNAL_H
|
||||
#include "xtc/xtc_project.h"
|
||||
#include "xtc/xtc_midi.h"
|
||||
#include "xtc/xtc_mixer.h"
|
||||
struct xtc_project {
|
||||
xtc_graph *graph;
|
||||
uint64_t next_track_id, next_clip_id;
|
||||
|
|
@ -9,6 +10,8 @@ struct xtc_project {
|
|||
size_t track_count, clip_count;
|
||||
uint64_t next_note_id;
|
||||
size_t note_count;
|
||||
size_t automation_count;
|
||||
xtc_automation_point automation[XTC_MAX_AUTOMATION_POINTS];
|
||||
xtc_note_info notes[XTC_PROJECT_MAX_NOTES];
|
||||
xtc_track_info tracks[XTC_PROJECT_MAX_TRACKS];
|
||||
xtc_clip_info clips[XTC_PROJECT_MAX_CLIPS];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue