1
0
Fork 0
forked from hanez/xtc

Phase 26: add common parameter targets, step automation and MIDI control mapping

This commit is contained in:
Johannes Findeisen 2026-10-27 16:37:59 +01:00
commit 901a536f10
38 changed files with 740 additions and 67 deletions

View file

@ -62,7 +62,7 @@ int main(void)
assert(xtc_project_set_mix(p,bus,.5f,1,1,1)==XTC_OK);
render(p,left,right,meters); assert(right[0]==0 && meters[0]==.5f && meters[7*64]==0);
assert(xtc_project_set_mix(p,bus,.5f,0,0,0)==XTC_OK);
point=(xtc_automation_point){bus,0,XTC_AUTOMATION_GAIN,.25f};
point=(xtc_automation_point){bus,0,XTC_AUTOMATION_GAIN,.25f,0};
assert(xtc_project_set_automation(p,&point)==XTC_OK);
render(p,left,right,meters); assert(left[0]==.5f && right[0]==.5f); /* .25 bus + .25 direct */
assert(xtc_project_save(p,song)==XTC_OK && xtc_project_load(q,song)==XTC_OK);

View file

@ -1,4 +1,5 @@
#include "xtc/xtc_midi.h"
#include "xtc/xtc_control.h"
#include <assert.h>
#include <math.h>
#include <stdio.h>
@ -29,10 +30,55 @@ int main(void)
for (i = 0; i < 400; ++i) assert(whole[i] == split[i]);
assert(whole[6] != 0); /* Sustain retains the released note. */
for (i = 250; i < 400; ++i) assert(whole[i] == 0); /* CC7 ramp reaches zero in 240 samples. */
{
xtc_midi_plan *mapped = NULL, *disabled = NULL;
xtc_parameter_state state;
xtc_parameter_key key = {XTC_PARAMETER_LIVE,2,2};
unsigned int bindings[3] = {1,74,11};
xtc_midi_event remapped[9];
float actual[400], right[400];
unsigned char message[3] = {0xb2,1,0};
assert(xtc_midi_decode(message,3,0,&decoded) == XTC_OK && decoded.type == XTC_MIDI_CONTROL);
message[1] = 120;
assert(xtc_midi_decode(message,3,0,&decoded) == XTC_OK && decoded.type == XTC_MIDI_ALL_OFF);
assert(xtc_project_parameter(project,key,48000,&state) == XTC_OK && !state.automated &&
(state.flags & XTC_PLUGIN_TOGGLED) && state.value == 0);
assert(xtc_project_automate(project,key,48000,0,1,1,0) == XTC_ERR_UNSUPPORTED);
assert(xtc_project_set_control_map(project,2,bindings) == XTC_OK);
assert(xtc_midi_plan_create(project,48000,&mapped) == XTC_OK);
for (i = 0; i < 8; ++i) {
remapped[i+(i ? 1 : 0)] = events[i];
if (events[i].type == XTC_MIDI_CONTROL)
remapped[i+1].pitch = events[i].pitch == 7 ? 1 : events[i].pitch == 10 ? 74 : 11;
}
// Former CC7 binding is ignored, not an additional volume binding.
remapped[1] = (xtc_midi_event){1,XTC_MIDI_CONTROL,2,7,0};
assert(xtc_midi_plan_render(mapped,0,remapped,9,actual,400) == XTC_OK);
for (i = 0; i < 400; ++i) assert(actual[i] == whole[i]);
{
const xtc_midi_event pan[] = {{0,XTC_MIDI_NOTE_ON,2,69,127},{0,XTC_MIDI_CONTROL,2,74,127}};
xtc_midi_plan_reset(mapped);
assert(xtc_midi_plan_render_stereo(mapped,0,pan,2,actual,right,400) == XTC_OK);
assert(actual[300] == 0 && right[300] != 0);
}
// Mutating the model does not change an already prepared mapping.
bindings[0] = bindings[1] = bindings[2] = XTC_CC_DISABLED;
assert(xtc_project_set_control_map(project,2,bindings) == XTC_OK);
xtc_midi_plan_reset(mapped);
assert(xtc_midi_plan_render(mapped,0,remapped,9,actual,400) == XTC_OK);
for (i = 0; i < 400; ++i) assert(actual[i] == whole[i]);
assert(xtc_midi_plan_create(project,48000,&disabled) == XTC_OK);
{
const xtc_midi_event unbound[] = {{0,XTC_MIDI_NOTE_ON,2,69,127},{3,XTC_MIDI_CONTROL,2,1,0}};
assert(xtc_midi_plan_render(disabled,0,unbound,2,actual,400) == XTC_OK);
assert(actual[300] != 0); // No mapped volume ramp reaches zero.
}
xtc_midi_plan_destroy(mapped); xtc_midi_plan_destroy(disabled);
}
xtc_midi_plan_reset(a);
assert(xtc_midi_plan_render(a,400,NULL,0,whole,400) == XTC_OK);
for (i = 0; i < 400; ++i) assert(whole[i] == 0);
xtc_midi_plan_destroy(a); xtc_midi_plan_destroy(b); xtc_project_destroy(project);
puts("Sample-timed CC7/CC10/sustain, retrigger, note-off and block partition checks passed.");
puts("Sample-timed default/remapped/disabled controllers, immutable maps, sustain, retrigger, note-off and block partition checks passed.");
return 0;
}

View file

@ -71,12 +71,12 @@ int main(void)
assert(xtc_project_set_mix(p, a, NAN, 0, 0, 0) == XTC_ERR_INVALID_ARGUMENT);
assert(xtc_project_set_mix(p, a, 1, 2, 0, 0) == XTC_ERR_INVALID_ARGUMENT);
assert(xtc_project_set_mix(p, a, 1, 0, 2, 0) == XTC_ERR_INVALID_ARGUMENT);
point = (xtc_automation_point){a, 0, XTC_AUTOMATION_GAIN, 0};
point = (xtc_automation_point){a, 0, XTC_AUTOMATION_GAIN, 0,0};
assert(xtc_project_set_automation(p, &point) == XTC_OK);
point.tick = 20;
point.value = 1;
assert(xtc_project_set_automation(p, &point) == XTC_OK); /* sample 500 */
point = (xtc_automation_point){a, 0, XTC_AUTOMATION_PAN, -1};
point = (xtc_automation_point){a, 0, XTC_AUTOMATION_PAN, -1,0};
assert(xtc_project_set_automation(p, &point) == XTC_OK);
point.tick = 20;
point.value = 1;
@ -165,8 +165,8 @@ int main(void)
{
const char *bad[] = {"MIX 7fc00000 00000000 0 0", "MIX 40800001 00000000 0 0",
"MIX 3f800000 40000000 0 0", "MIX 3f800000 00000000 2 0",
"POINT 999 0 0 3f800000", "POINT 0 2 0 3f800000",
"POINT 0 0 0 7f800000", "POINT 0 0 20 3f800000"};
"POINT 999 0 0 3f800000 0", "POINT 0 2 0 3f800000 0",
"POINT 0 0 0 7f800000 0", "POINT 0 0 20 3f800000 0", "POINT 0 0 0 3f800000 2"};
for (i = 0; i < sizeof(bad) / sizeof(*bad); ++i) {
char *start = strstr(bytes, i < 4 ? "MIX " : "POINT "), *end;
assert(start);
@ -197,7 +197,7 @@ int main(void)
fputc('\n',legacy); continue;
}
if (strncmp(line, "MIX ", 4) && strncmp(line, "AUTOMATION ", 11) &&
strncmp(line, "POINT ", 6) && strncmp(line, "AUDIO ", 6) && strncmp(line, "ROUTE ", 6))
strncmp(line, "POINT ", 6) && strncmp(line, "AUDIO ", 6) && strncmp(line, "ROUTE ", 6) && strncmp(line,"CONTROL_MAPS ",13) && strncmp(line,"MAP ",4))
assert(fputs(line, legacy) >= 0);
}
assert(fclose(f) == 0 && fclose(legacy) == 0);
@ -237,7 +237,7 @@ int main(void)
xtc_history_destroy(history);
assert(xtc_project_remove_track(p, a) == XTC_OK &&
xtc_project_automation_count(p, &count) == XTC_OK && count == 0);
point = (xtc_automation_point){b, 0, XTC_AUTOMATION_GAIN, 1};
point = (xtc_automation_point){b, 0, XTC_AUTOMATION_GAIN, 1,0};
for (i = 0; i < XTC_MAX_AUTOMATION_POINTS; ++i) {
point.tick = i;
assert(xtc_project_set_automation(p, &point) == XTC_OK);

View file

@ -0,0 +1,97 @@
#define _POSIX_C_SOURCE 200809L
#include "xtc/xtc_control.h"
#include "xtc/xtc_midi.h"
#include "../../src/mixer/mix_internal.h"
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
int main(void)
{
xtc_project *p = NULL, *loaded = NULL;
xtc_midi_plan *reference = NULL, *whole = NULL, *split = NULL;
xtc_parameter_state state, sentinel;
uint64_t track, clip, note;
float base[80], left[80], right[80], sl[80], sr[80];
unsigned int map[3] = {1,2,3}, actual[3];
size_t i, cursor;
char path[] = "/tmp/xtc-parameters-XXXXXX";
int fd = mkstemp(path); assert(fd >= 0); close(fd);
assert(xtc_project_create(&p) == XTC_OK);
assert(xtc_project_add_track(p,"Parameters",&track) == XTC_OK);
assert(xtc_project_add_midi_clip(p,track,0,960,&clip) == XTC_OK);
assert(xtc_project_add_note(p,clip,0,960,69,127,0,&note) == XTC_OK);
assert(xtc_midi_plan_create(p,48000,&reference) == XTC_OK);
assert(xtc_midi_plan_render(reference,0,NULL,0,base,80) == XTC_OK);
{
xtc_parameter_key gain = {XTC_PARAMETER_TRACK,track,0}, pan = {XTC_PARAMETER_TRACK,track,1};
xtc_parameter_key missing = {XTC_PARAMETER_TRACK,UINT64_MAX,0};
xtc_mix_snapshot mix;
assert(xtc_project_parameter(p,gain,48000,&state) == XTC_OK && !state.automated && state.value == 1);
assert(!strcmp(state.info.unit,"linear") && state.info.minimum == 0 && state.info.maximum == 4);
sentinel = state;
assert(xtc_project_parameter(p,missing,48000,&state) == XTC_ERR_NOT_FOUND && !memcmp(&state,&sentinel,sizeof(state)));
assert(xtc_project_automate(p,missing,48000,0,0,1,0) == XTC_ERR_NOT_FOUND);
assert(xtc_project_automate(p,gain,48000,0,1,.25f,0) == XTC_OK);
assert(xtc_project_automate(p,gain,48000,1,0,1,0) == XTC_OK);
assert(xtc_project_automate(p,gain,48000,2,0,.5f,0) == XTC_OK);
assert(xtc_project_automate(p,pan,48000,0,1,-1,0) == XTC_OK);
assert(xtc_project_automate(p,pan,48000,2,1,1,0) == XTC_OK);
assert(xtc_project_automate(p,gain,48000,3,2,.5f,0) == XTC_ERR_INVALID_ARGUMENT);
assert(xtc_project_set_parameter(p,gain,48000,3) == XTC_OK);
assert(xtc_project_parameter(p,gain,48000,&state) == XTC_OK && state.automated && state.value == 3);
assert(xtc_project_set_parameter(p,gain,48000,NAN) == XTC_ERR_INVALID_ARGUMENT);
assert(xtc_mix_prepare(p,1,&mix) == XTC_OK && xtc_mix_level(&mix,0,0,2) == .5f); // Colliding ticks: latest wins.
}
assert(xtc_project_get_control_map(p,0,actual) == XTC_OK && actual[0] == 7 && actual[1] == 10 && actual[2] == 64);
assert(xtc_project_set_control_map(p,0,map) == XTC_OK);
map[1] = 1;
assert(xtc_project_set_control_map(p,0,map) == XTC_ERR_INVALID_ARGUMENT);
map[1] = 120;
assert(xtc_project_set_control_map(p,0,map) == XTC_ERR_INVALID_ARGUMENT);
assert(xtc_project_get_control_map(p,0,actual) == XTC_OK && actual[0] == 1 && actual[1] == 2 && actual[2] == 3);
assert(xtc_project_save(p,path) == XTC_OK);
assert(xtc_project_create(&loaded) == XTC_OK && xtc_project_load(loaded,path) == XTC_OK);
assert(xtc_project_get_control_map(loaded,0,actual) == XTC_OK && actual[0] == 1 && actual[1] == 2 && actual[2] == 3);
{
xtc_automation_point point;
assert(xtc_project_get_automation(loaded,0,&point) == XTC_OK && point.step == 1);
}
assert(xtc_midi_plan_create(loaded,48000,&whole) == XTC_OK && xtc_midi_plan_create(loaded,48000,&split) == XTC_OK);
assert(xtc_midi_plan_render_stereo(whole,0,NULL,0,left,right,80) == XTC_OK);
for (cursor = 0; cursor < 80;) {
size_t frames = 13; if (frames > 80-cursor) frames = 80-cursor;
assert(xtc_midi_plan_render_stereo(split,cursor,NULL,0,sl+cursor,sr+cursor,frames) == XTC_OK);
cursor += frames;
}
for (i = 0; i < 80; ++i) {
float gain = i < 25 ? .25f : i < 50 ? 1-(float)(i-25)/50 : .5f;
assert(left[i] == sl[i] && right[i] == sr[i]);
assert(fabsf(left[i] - (i < 50 ? base[i]*gain : 0)) < .000001f);
assert(fabsf(right[i] - (i < 50 ? 0 : base[i]*gain)) < .000001f);
}
assert(xtc_midi_plan_render_stereo(split,29,NULL,0,sl,sr,13) == XTC_OK);
for (i = 0; i < 13; ++i) assert(sl[i] == left[i+29] && sr[i] == right[i+29]);
// Explicit backward transport wrap (no loop transport feature is implied).
assert(xtc_midi_plan_render_stereo(split,0,NULL,0,sl,sr,80) == XTC_OK);
for (i = 0; i < 80; ++i) assert(sl[i] == left[i] && sr[i] == right[i]);
{
FILE *source = fopen(path,"r"), *dest;
char bad[128], line[1024];
snprintf(bad,sizeof(bad),"%s-bad",path); dest = fopen(bad,"w"); assert(source && dest);
while (fgets(line,sizeof(line),source)) {
if (!strncmp(line,"MAP 0 ",6)) fputs("MAP 0 1 1 3\n",dest); else fputs(line,dest);
}
fclose(source); assert(fclose(dest) == 0);
assert(xtc_project_load(loaded,bad) == XTC_ERR_FORMAT);
assert(xtc_project_get_control_map(loaded,0,actual) == XTC_OK && actual[1] == 2);
unlink(bad);
}
xtc_midi_plan_destroy(reference); xtc_midi_plan_destroy(whole); xtc_midi_plan_destroy(split);
xtc_project_destroy(p); xtc_project_destroy(loaded); unlink(path);
puts("Common parameter identity, hold/linear lanes, static precedence, persistence, seeks and wrap passed.");
return 0;
}