Some code semantics refactoring.

This commit is contained in:
Johannes Findeisen 2026-10-27 01:37:21 +01:00
commit 0f04e056b2
42 changed files with 3374 additions and 1357 deletions

View file

@ -2,12 +2,14 @@
#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)
@ -19,6 +21,7 @@ static void remember_ids(xtc_history *h, const xtc_project *p)
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;
@ -28,6 +31,7 @@ void xtc_history_destroy(xtc_history *h)
xtc_project_destroy(h->states[i]);
free(h);
}
xtc_result xtc_history_create(const xtc_project *p, xtc_history **out)
{
xtc_history *h;
@ -50,6 +54,7 @@ xtc_result xtc_history_create(const xtc_project *p, xtc_history **out)
*out = h;
return XTC_OK;
}
xtc_result xtc_history_record(xtc_history *h, const xtc_project *p)
{
xtc_project *copy;
@ -73,10 +78,12 @@ xtc_result xtc_history_record(xtc_history *h, const xtc_project *p)
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)
@ -97,6 +104,7 @@ xtc_result xtc_history_checkout(const xtc_history *h, int redo, xtc_project **ou
return r;
}
}
xtc_result xtc_history_accept(xtc_history *h, int redo)
{
if (!h || (redo != 0 && redo != 1))