feat: add editable internal instruments, automation and versioned presets

This commit is contained in:
Johannes Findeisen 2026-11-05 23:47:54 +01:00
commit 159fa939a1
21 changed files with 295 additions and 52 deletions

View file

@ -462,6 +462,26 @@ static xtc_result read_project(reader *input, xtc_project *project, const char *
READ("MODULE",2U); if (!decode_bytes(input->tokens[1],s->path,sizeof(s->path))) return XTC_ERR_FORMAT;
READ("IDENTITY",2U);
if (strcmp(input->tokens[1],"-") && !decode_bytes(input->tokens[1],s->identifier,sizeof(s->identifier))) return XTC_ERR_FORMAT;
if (format_version >= 14U) {
size_t k;
READ("INSTRUMENT_CONTROLS",2U);NUM(1U,value);
if(value>XTC_PLUGIN_CONTROLS)return XTC_ERR_FORMAT;
s->control_count=(unsigned int)value;
for(k=0;k<s->control_count;++k) {
READ("CONTROL",3U);NUM(1U,value);if(value>=64)return XTC_ERR_FORMAT;
s->ports[k]=(unsigned int)value;
if(!decode_float(input->tokens[2],s->values+k))return XTC_ERR_FORMAT;
}
READ("INSTRUMENT_AUTOMATION",2U);NUM(1U,value);
if(value>XTC_PLUGIN_POINTS)return XTC_ERR_FORMAT;
s->point_count=(unsigned int)value;
for(k=0;k<s->point_count;++k) {
xtc_plugin_point *a=s->points+k;
READ("PARAM",5U);NUM(1U,a->tick);NUM(2U,value);if(value>=64)return XTC_ERR_FORMAT;
a->port=(unsigned int)value;NUM(3U,value);if(value>1)return XTC_ERR_FORMAT;
a->step=(unsigned int)value;if(!decode_float(input->tokens[4],&a->value))return XTC_ERR_FORMAT;
}
}
if (xtc_plugin_spec_validate(s) != XTC_OK) return XTC_ERR_FORMAT;
}
READ("LIVE_INSTRUMENT",2U); NUM(1U,project->live_instrument);
@ -621,6 +641,19 @@ static xtc_result write_project(FILE *file, const xtc_project *project, const ch
if (fprintf(file,"INSTRUMENT %" PRIu64 " %u %u %u ",project->tracks[i].id,(unsigned int)s->format,s->index,s->unique_id) < 0 ||
!write_name(file,s->label) || fputs("MODULE ",file) == EOF || !write_name(file,s->path) || fputs("IDENTITY ",file) == EOF ||
(s->identifier[0] ? !write_name(file,s->identifier) : fputs("-\n",file) == EOF)) return XTC_ERR_IO;
{
size_t k;
if(fprintf(file,"INSTRUMENT_CONTROLS %u\n",s->control_count)<0)return XTC_ERR_IO;
for(k=0;k<s->control_count;++k) {
uint32_t bits;memcpy(&bits,s->values+k,4);
if(fprintf(file,"CONTROL %u %08" PRIx32 "\n",s->ports[k],bits)<0)return XTC_ERR_IO;
}
if(fprintf(file,"INSTRUMENT_AUTOMATION %u\n",s->point_count)<0)return XTC_ERR_IO;
for(k=0;k<s->point_count;++k) {
uint32_t bits;memcpy(&bits,&s->points[k].value,4);
if(fprintf(file,"PARAM %" PRIu64 " %u %u %08" PRIx32 "\n",s->points[k].tick,s->points[k].port,s->points[k].step,bits)<0)return XTC_ERR_IO;
}
}
}
if (fprintf(file,"LIVE_INSTRUMENT %" PRIu64 "\n",project->live_instrument) < 0) return XTC_ERR_IO;
}