// Segregate tracks in channel space. // Changes channel coding so that each track has its own private channel. // First verifies that no track uses more than one channel. #include #include #include "h.h" static int gcount(ui x) {int c=0; while(x){++c; x &= x-1;} return c;} BP bp; note * mus = 0; int main(){note * music = Read("", &bp); ui const tc=bp.trks; unsigned short usg[tc]; {int j=tc; while(j--) usg[j] = 0;} {void fed(note n){if(!n.trk || n.trk> tc) exit(printf("Foo\n")); if(n.dur!=OpaqueStuff) {usg[n.trk-1] |= 1<< (n.chan-1);}} scan(fed, music, 0); {int j=tc; int b = 0; while(j--) if(gcount(usg[j])>1) {b=1; printf("Track %d uses these channels: %04X\n", j+1, usg[j]);} if(b) exit(printf("No conversion performed\n"));}} {void fed(note n){n.chan = n.trk; aug(n, &mus);} scan(fed, music, 0);} Write("nsh.midi", mus, &bp); return 0;}