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

@ -61,7 +61,7 @@ xtc_result xtc_midi_decode(const unsigned char *bytes, size_t size, unsigned int
if (!bytes || !size || !out)
return XTC_ERR_INVALID_ARGUMENT;
command = bytes[0] & 240U;
if (command != 128 && command != 144 && command != 176)
if (command != 128 && command != 144 && command != 176 && command != 224)
return XTC_ERR_UNSUPPORTED;
if (size != 3 || bytes[1] > 127 || bytes[2] > 127)
return XTC_ERR_INVALID_ARGUMENT;
@ -69,7 +69,7 @@ xtc_result xtc_midi_decode(const unsigned char *bytes, size_t size, unsigned int
e.channel = bytes[0] & 15U;
e.pitch = bytes[1];
e.velocity = bytes[2];
e.type = command == 176 ? (bytes[1] == 120 || bytes[1] == 123 ? XTC_MIDI_ALL_OFF : XTC_MIDI_CONTROL) : command == 128 || !e.velocity ? XTC_MIDI_NOTE_OFF : XTC_MIDI_NOTE_ON;
e.type = command == 224 ? XTC_MIDI_BEND : command == 176 ? (bytes[1] == 120 || bytes[1] == 123 ? XTC_MIDI_ALL_OFF : XTC_MIDI_CONTROL) : command == 128 || !e.velocity ? XTC_MIDI_NOTE_OFF : XTC_MIDI_NOTE_ON;
*out = e;
return XTC_OK;
}
@ -274,6 +274,7 @@ static void event(xtc_midi_plan *p, const xtc_midi_event *e, uint64_t position)
channel_off(p, e->channel, position);
return;
}
if (e->type == XTC_MIDI_BEND) return; /* Built-in sine retains its established pitch. */
if (e->type == XTC_MIDI_CONTROL) {
if (e->pitch == p->control_map[e->channel][0]) (void)xtc_gain_ramp_target(p->volume+e->channel,(float)e->velocity/127.0f,p->controller_frames);
else if (e->pitch == p->control_map[e->channel][1]) (void)xtc_gain_ramp_target(p->pan+e->channel,
@ -435,7 +436,7 @@ static xtc_result instruments(xtc_midi_plan *p, uint64_t position, const xtc_mid
if (!enqueue(p,&queued,e)) return XTC_ERR_CAPACITY;
}
}
r = xtc_plugin_process_midi(p->plugins[track],p->queue,queued,p->scratch,n);
r = xtc_plugin_process_midi_at(p->plugins[track],p->queue,queued,p->scratch,n,begin);
if (r != XTC_OK) return r;
for (j = 0; j < n; ++j) {
float sample = p->scratch[j];
@ -471,7 +472,7 @@ xtc_result xtc_midi_plan_render_stereo(xtc_midi_plan *p, uint64_t position, cons
for (i = 0; i < count; ++i) {
const xtc_midi_event *e = events + i;
if (e->offset >= frames || (i && e->offset < events[i - 1].offset) || e->type < XTC_MIDI_NOTE_ON ||
e->type > XTC_MIDI_CONTROL || e->pitch > 127 || e->velocity > 127 || e->channel > 15 ||
e->type > XTC_MIDI_BEND || e->pitch > 127 || e->velocity > 127 || e->channel > 15 ||
(e->type == XTC_MIDI_NOTE_ON && !e->velocity))
return XTC_ERR_INVALID_ARGUMENT;
}