feat(project): persist bounded per-track effect chains (phase 81)
This commit is contained in:
parent
e9d783146f
commit
7489f86351
15 changed files with 159 additions and 12 deletions
|
|
@ -306,6 +306,8 @@ xtc_result xtc_project_add_track(xtc_project *project, const char *name, uint64_
|
|||
track.gain = 1.0f;
|
||||
track.bus_id = UINT64_MAX;
|
||||
memcpy(track.name, name, strlen(name) + 1U);
|
||||
memset(project->chains+project->track_count,0,sizeof(*project->chains));
|
||||
project->chains[project->track_count].output_gain=1;
|
||||
project->tracks[project->track_count++] = track;
|
||||
*id = track.id;
|
||||
return XTC_OK;
|
||||
|
|
@ -333,6 +335,9 @@ xtc_result xtc_project_remove_track(xtc_project *project, uint64_t id)
|
|||
for (i = 0; i < project->track_count; ++i)
|
||||
if (project->tracks[i].bus_id == id) project->tracks[i].bus_id = UINT64_MAX;
|
||||
if (project->live_instrument == id) project->live_instrument = UINT64_MAX;
|
||||
memmove(project->chains+index,project->chains+index+1,
|
||||
(project->track_count-index-1)*sizeof(*project->chains));
|
||||
memset(project->chains+project->track_count-1,0,sizeof(*project->chains));
|
||||
memmove(project->instruments+index,project->instruments+index+1,
|
||||
(project->track_count-index-1)*sizeof(*project->instruments));
|
||||
memset(project->instruments+project->track_count-1,0,sizeof(*project->instruments));
|
||||
|
|
@ -544,6 +549,8 @@ xtc_result xtc_project_validate(const xtc_project *project)
|
|||
if (target == SIZE_MAX || !project->instruments[target].instrument) return XTC_ERR_FORMAT;
|
||||
}
|
||||
for (i = 0U; i < project->track_count; ++i) {
|
||||
if(xtc_track_chain_validate(project->chains+i)!=XTC_OK ||
|
||||
(project->tracks[i].is_bus && project->chains[i].count))return XTC_ERR_FORMAT;
|
||||
if (project->instruments[i].instrument && (project->tracks[i].is_bus ||
|
||||
xtc_plugin_spec_validate(project->instruments+i) != XTC_OK)) return XTC_ERR_FORMAT;
|
||||
if (project->tracks[i].id >= project->next_track_id || !xtc_project_valid_name(project->tracks[i].name))
|
||||
|
|
@ -689,6 +696,10 @@ xtc_result xtc_project_move_track(xtc_project *p, uint64_t id, size_t destinatio
|
|||
size_t i; xtc_track_info track;
|
||||
if (!p || destination >= p->track_count) return XTC_ERR_INVALID_ARGUMENT;
|
||||
i = track_index(p,id); if (i == SIZE_MAX) return XTC_ERR_NOT_FOUND;
|
||||
{ xtc_track_chain chain=p->chains[i];
|
||||
if(i<destination)memmove(p->chains+i,p->chains+i+1,(destination-i)*sizeof(chain));
|
||||
else if(i>destination)memmove(p->chains+destination+1,p->chains+destination,(i-destination)*sizeof(chain));
|
||||
p->chains[destination]=chain; }
|
||||
{ xtc_plugin_spec instrument = p->instruments[i];
|
||||
if (i < destination) memmove(p->instruments+i,p->instruments+i+1,(destination-i)*sizeof(instrument));
|
||||
else if (i > destination) memmove(p->instruments+destination+1,p->instruments+destination,(i-destination)*sizeof(instrument));
|
||||
|
|
@ -772,3 +783,28 @@ xtc_result xtc_project_set_live_instrument(xtc_project *p, uint64_t track)
|
|||
}
|
||||
xtc_result xtc_project_get_live_instrument(const xtc_project *p, uint64_t *track)
|
||||
{ if (!p || !track) return XTC_ERR_INVALID_ARGUMENT; *track = p->live_instrument; return XTC_OK; }
|
||||
|
||||
xtc_result xtc_track_chain_validate(const xtc_track_chain *c)
|
||||
{
|
||||
size_t i;
|
||||
if(!c || c->count>XTC_TRACK_INSERTS || !isfinite(c->output_gain) || c->output_gain<0 || c->output_gain>4)return XTC_ERR_INVALID_ARGUMENT;
|
||||
for(i=0;i<c->count;++i) {
|
||||
const xtc_track_insert *s=c->slots+i;
|
||||
if(s->enabled>1 || !isfinite(s->wet) || s->wet<0 || s->wet>1 || s->plugin.instrument ||
|
||||
s->plugin.inputs!=1 || s->plugin.sample_path[0] || xtc_plugin_spec_validate(&s->plugin)!=XTC_OK)return XTC_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
return XTC_OK;
|
||||
}
|
||||
xtc_result xtc_project_get_chain(const xtc_project *p,uint64_t track,xtc_track_chain *out)
|
||||
{
|
||||
size_t i;if(!p || !out)return XTC_ERR_INVALID_ARGUMENT;
|
||||
i=track_index(p,track);if(i==SIZE_MAX)return XTC_ERR_NOT_FOUND;
|
||||
*out=p->chains[i];return XTC_OK;
|
||||
}
|
||||
xtc_result xtc_project_set_chain(xtc_project *p,uint64_t track,const xtc_track_chain *c)
|
||||
{
|
||||
size_t i;if(!p || xtc_track_chain_validate(c)!=XTC_OK)return XTC_ERR_INVALID_ARGUMENT;
|
||||
i=track_index(p,track);if(i==SIZE_MAX)return XTC_ERR_NOT_FOUND;
|
||||
if(p->tracks[i].is_bus && c->count)return XTC_ERR_UNSUPPORTED;
|
||||
p->chains[i]=*c;return XTC_OK;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue