feat: ripple timeline ranges with markers and automation atomically

This commit is contained in:
Johannes Findeisen 2026-11-06 00:32:33 +01:00
commit 7084e660fe
9 changed files with 95 additions and 5 deletions

View file

@ -1,4 +1,6 @@
#include "project_internal.h"
#include "../graph/graph_internal.h"
#include "xtc/xtc_editing.h"
#include <string.h>
xtc_result xtc_project_marker_count(const xtc_project *p,size_t *out)
@ -50,3 +52,43 @@ xtc_result xtc_project_section(const xtc_project *p,uint64_t tick,uint64_t *begi
if(finish<=p->markers[i-1].tick)return XTC_ERR_INVALID_STATE;
*begin=p->markers[i-1].tick;*end=finish;return XTC_OK;
}
static xtc_result ripple_tick(uint64_t *tick,uint64_t begin,uint64_t length,int remove,int *keep)
{
*keep=1;
if(*tick<begin)return XTC_OK;
if(remove){if(*tick<begin+length)*keep=0;else *tick-=length;}
else {if(*tick>XTC_PROJECT_MAX_TICK-length)return XTC_ERR_INVALID_ARGUMENT;*tick+=length;}
return XTC_OK;
}
static xtc_result ripple_plugin(xtc_plugin_spec *spec,uint64_t begin,uint64_t length,int remove)
{
unsigned int i,n=0;int keep;xtc_result r;
for(i=0;i<spec->point_count;++i) {
xtc_plugin_point point=spec->points[i];r=ripple_tick(&point.tick,begin,length,remove,&keep);
if(r!=XTC_OK)return r;
if(keep)spec->points[n++]=point;
}
spec->point_count=n;return XTC_OK;
}
xtc_result xtc_project_ripple_time(xtc_project *p,uint64_t begin,uint64_t length,int remove)
{
xtc_project *copy=NULL;size_t i,n;int keep;xtc_result r;
if(!p || !length || begin>XTC_PROJECT_MAX_TICK || length>XTC_PROJECT_MAX_TICK-begin || (remove!=0 && remove!=1))return XTC_ERR_INVALID_ARGUMENT;
r=xtc_project_clone(p,&copy);if(r!=XTC_OK)return r;
for(i=copy->clip_count;r==XTC_OK && i>0;--i) {
xtc_clip_info c=copy->clips[i-1];uint64_t end=c.start_tick+c.length_tick;
if((c.start_tick<begin && end>begin) || (remove && c.start_tick<begin+length && end>begin+length)){r=XTC_ERR_INVALID_STATE;break;}
r=ripple_tick(&c.start_tick,begin,length,remove,&keep);
if(r==XTC_OK)r=keep ? xtc_project_edit_clip(copy,c.id,c.track_id,c.start_tick,c.length_tick,c.offset_tick) : xtc_project_remove_clip(copy,c.id);
}
n=0;
for(i=0;r==XTC_OK && i<copy->marker_count;++i){xtc_marker m=copy->markers[i];r=ripple_tick(&m.tick,begin,length,remove,&keep);if(r==XTC_OK && keep)copy->markers[n++]=m;}
copy->marker_count=n;n=0;
for(i=0;r==XTC_OK && i<copy->automation_count;++i){xtc_automation_point a=copy->automation[i];r=ripple_tick(&a.tick,begin,length,remove,&keep);if(r==XTC_OK && keep)copy->automation[n++]=a;}
copy->automation_count=n;
for(i=0;r==XTC_OK && i<copy->track_count;++i)r=ripple_plugin(copy->instruments+i,begin,length,remove);
for(i=0;r==XTC_OK && i<copy->graph->node_count;++i)if(copy->graph->nodes[i].type==XTC_NODE_PLUGIN)r=ripple_plugin(&copy->graph->nodes[i].plugin,begin,length,remove);
if(r==XTC_OK){xtc_graph *old=p->graph;*p=*copy;copy->graph=old;}
xtc_project_destroy(copy);return r;
}