Phase 32: add MIDI track CLAP, VST2 and VST3 instruments

This commit is contained in:
Johannes Findeisen 2026-10-27 17:51:48 +01:00
commit fe484537f9
41 changed files with 1138 additions and 65 deletions

View file

@ -443,6 +443,29 @@ static xtc_result read_project(reader *input, xtc_project *project, const char *
}
}
}
if (format_version >= 12U) {
size_t bindings;
READ("TRACK_INSTRUMENTS",2U); NUM(1U,value);
if (value > project->track_count) return XTC_ERR_FORMAT;
bindings = (size_t)value;
for (i = 0; i < bindings; ++i) {
uint64_t track; size_t slot; xtc_plugin_spec *s;
READ("INSTRUMENT",6U); NUM(1U,track);
for (slot = 0; slot < project->track_count && project->tracks[slot].id != track; ++slot) {}
if (slot == project->track_count || project->tracks[slot].is_bus || project->instruments[slot].instrument) return XTC_ERR_FORMAT;
s = project->instruments+slot; s->instrument = 1; s->tempo = project->tempo;
NUM(2U,value); if (value < XTC_PLUGIN_CLAP || value > XTC_PLUGIN_VST3) return XTC_ERR_UNSUPPORTED;
s->format = (xtc_plugin_format)value;
NUM(3U,value); if (value >= 1024) return XTC_ERR_FORMAT; s->index = (unsigned int)value;
NUM(4U,value); if (value > UINT32_MAX) return XTC_ERR_FORMAT; s->unique_id = (unsigned int)value;
if (!decode_bytes(input->tokens[5],s->label,sizeof(s->label))) return XTC_ERR_FORMAT;
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 (xtc_plugin_spec_validate(s) != XTC_OK) return XTC_ERR_FORMAT;
}
READ("LIVE_INSTRUMENT",2U); NUM(1U,project->live_instrument);
}
READ("END", 1U);
if (fgetc(input->file) != EOF)
return XTC_ERR_FORMAT;
@ -590,6 +613,17 @@ static xtc_result write_project(FILE *file, const xtc_project *project, const ch
for (i = 0; i < 16; ++i)
if (fprintf(file,"MAP %zu %u %u %u\n",i,(unsigned int)project->control_map[i][0],
(unsigned int)project->control_map[i][1],(unsigned int)project->control_map[i][2]) < 0) return XTC_ERR_IO;
{ size_t bindings = 0;
for (i = 0; i < project->track_count; ++i) if (project->instruments[i].instrument) ++bindings;
if (fprintf(file,"TRACK_INSTRUMENTS %zu\n",bindings) < 0) return XTC_ERR_IO;
for (i = 0; i < project->track_count; ++i) if (project->instruments[i].instrument) {
const xtc_plugin_spec *s = project->instruments+i;
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;
}
if (fprintf(file,"LIVE_INSTRUMENT %" PRIu64 "\n",project->live_instrument) < 0) return XTC_ERR_IO;
}
return fputs("END\n", file) == EOF ? XTC_ERR_IO : XTC_OK;
}