#include "xtc/xtc_midi.h" #include #include #include int main(void) { xtc_project *project = NULL; xtc_midi_plan *a = NULL, *b = NULL; float whole[400], split[400]; size_t i, j, cursor = 0; xtc_midi_event decoded; const unsigned char cc[] = {0xb2,7,0}; xtc_midi_event events[] = { {0,XTC_MIDI_NOTE_ON,2,69,127}, {3,XTC_MIDI_CONTROL,2,64,127}, {5,XTC_MIDI_NOTE_OFF,2,69,0}, {9,XTC_MIDI_NOTE_ON,2,69,127}, {10,XTC_MIDI_CONTROL,2,7,0}, {11,XTC_MIDI_CONTROL,2,10,127}, {260,XTC_MIDI_NOTE_OFF,2,69,0}, {270,XTC_MIDI_CONTROL,2,64,0}}; assert(xtc_midi_decode(cc,3,10,&decoded) == XTC_OK && decoded.type == XTC_MIDI_CONTROL && decoded.pitch == 7); assert(xtc_project_create(&project) == XTC_OK); assert(xtc_midi_plan_create(project,48000,&a) == XTC_OK); assert(xtc_midi_plan_create(project,48000,&b) == XTC_OK); assert(xtc_midi_plan_render(a,0,events,8,whole,400) == XTC_OK); while (cursor < 400) { xtc_midi_event local[8]; size_t count = 0, n = 13; if (n > 400-cursor) n = 400-cursor; for (j = 0; j < 8; ++j) if (events[j].offset >= cursor && events[j].offset < cursor+n) { local[count] = events[j]; local[count++].offset -= (unsigned int)cursor; } assert(xtc_midi_plan_render(b,cursor,local,count,split+cursor,n) == XTC_OK); cursor += n; } 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_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."); return 0; }