Phase 32: add MIDI track CLAP, VST2 and VST3 instruments
This commit is contained in:
parent
9e0e4562d7
commit
fe484537f9
41 changed files with 1138 additions and 65 deletions
|
|
@ -119,6 +119,7 @@ xtc_result xtc_project_create(xtc_project **out_project)
|
|||
}
|
||||
project->graph->require_output_nodes = 1;
|
||||
project->tempo = 120000U;
|
||||
project->live_instrument = UINT64_MAX;
|
||||
{ size_t channel;
|
||||
for (channel = 0; channel < 16; ++channel) {
|
||||
project->control_map[channel][0] = 7;
|
||||
|
|
@ -331,6 +332,10 @@ xtc_result xtc_project_remove_track(xtc_project *project, uint64_t id)
|
|||
project->clip_count = count;
|
||||
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->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));
|
||||
memmove(project->tracks + index, project->tracks + index + 1U,
|
||||
(project->track_count - index - 1U) * sizeof(*project->tracks));
|
||||
--project->track_count;
|
||||
|
|
@ -530,7 +535,13 @@ xtc_result xtc_project_validate(const xtc_project *project)
|
|||
for (k = 0; k < j; ++k)
|
||||
if (cc != 128 && cc == project->control_map[i][k]) return XTC_ERR_FORMAT;
|
||||
}
|
||||
if (project->live_instrument != UINT64_MAX) {
|
||||
size_t target = track_index(project,project->live_instrument);
|
||||
if (target == SIZE_MAX || !project->instruments[target].instrument) return XTC_ERR_FORMAT;
|
||||
}
|
||||
for (i = 0U; i < project->track_count; ++i) {
|
||||
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))
|
||||
return XTC_ERR_FORMAT;
|
||||
{
|
||||
|
|
@ -674,6 +685,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_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));
|
||||
p->instruments[destination] = instrument; }
|
||||
track = p->tracks[i];
|
||||
if (i < destination) memmove(p->tracks+i,p->tracks+i+1,(destination-i)*sizeof(track));
|
||||
else if (i > destination) memmove(p->tracks+destination+1,p->tracks+destination,(i-destination)*sizeof(track));
|
||||
|
|
@ -718,3 +733,38 @@ xtc_result xtc_project_split_audio(xtc_project *p, uint64_t id, uint64_t tick, u
|
|||
*out = right.id;
|
||||
return XTC_OK;
|
||||
}
|
||||
|
||||
xtc_result xtc_project_set_instrument(xtc_project *p, uint64_t track, const xtc_plugin_spec *spec)
|
||||
{
|
||||
size_t i; xtc_project *candidate = NULL; xtc_result r;
|
||||
if (!p) 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) return XTC_ERR_INVALID_STATE;
|
||||
if (spec && (!spec->instrument || xtc_plugin_spec_validate(spec) != XTC_OK)) return XTC_ERR_UNSUPPORTED;
|
||||
r = xtc_project_clone(p,&candidate);
|
||||
if (r == XTC_OK && spec) r = xtc_project_ensure_midi_route(candidate);
|
||||
if (r == XTC_OK) {
|
||||
if (spec) { candidate->instruments[i] = *spec; candidate->live_instrument = track; }
|
||||
else { memset(candidate->instruments+i,0,sizeof(*candidate->instruments));
|
||||
if (candidate->live_instrument == track) candidate->live_instrument = UINT64_MAX; }
|
||||
{ xtc_graph *old = p->graph; *p = *candidate; candidate->graph = old; }
|
||||
}
|
||||
xtc_project_destroy(candidate); return r;
|
||||
}
|
||||
xtc_result xtc_project_get_instrument(const xtc_project *p, uint64_t track, xtc_plugin_spec *out)
|
||||
{
|
||||
size_t i;
|
||||
if (!p || !out) return XTC_ERR_INVALID_ARGUMENT;
|
||||
i = track_index(p,track); if (i == SIZE_MAX || !p->instruments[i].instrument) return XTC_ERR_NOT_FOUND;
|
||||
*out = p->instruments[i]; return XTC_OK;
|
||||
}
|
||||
xtc_result xtc_project_set_live_instrument(xtc_project *p, uint64_t track)
|
||||
{
|
||||
xtc_plugin_spec s;
|
||||
if (!p) return XTC_ERR_INVALID_ARGUMENT;
|
||||
if (track != UINT64_MAX && xtc_project_get_instrument(p,track,&s) != XTC_OK) return XTC_ERR_NOT_FOUND;
|
||||
p->live_instrument = track; return XTC_OK;
|
||||
}
|
||||
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; }
|
||||
|
|
|
|||
|
|
@ -4,9 +4,12 @@
|
|||
#include "xtc/xtc_project.h"
|
||||
#include "xtc/xtc_midi.h"
|
||||
#include "xtc/xtc_mixer.h"
|
||||
#include "xtc/xtc_plugin.h"
|
||||
|
||||
struct xtc_project {
|
||||
xtc_graph *graph;
|
||||
uint64_t live_instrument;
|
||||
xtc_plugin_spec instruments[XTC_PROJECT_MAX_TRACKS];
|
||||
uint64_t next_track_id, next_clip_id;
|
||||
unsigned int tempo;
|
||||
unsigned char control_map[16][3];
|
||||
|
|
@ -26,6 +29,7 @@ struct xtc_project {
|
|||
* @param name NUL-terminated name.
|
||||
* @return Nonzero for a valid name, zero otherwise.
|
||||
*/
|
||||
xtc_result xtc_project_ensure_midi_route(xtc_project *project);
|
||||
int xtc_project_valid_name(const char *name);
|
||||
/**
|
||||
* @brief Validates project IDs, timeline ranges, names, graph, notes, and automation.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue