Dup Ver Goto 📝

JdaMpeAllocator1

To
44 lines, 160 words, 974 chars Page 'JdaMpeAllocator1' does not exist.

This allocates notes to the first available channel. This will probably fail if more than 15 simultaneous notes are played.

desc: JDA Midi Mpe Allocator 1

@init
alloc_base = 100; // channel => pitch
alloc_chan = 200; // pitch => channel
alloc_i = 0;

loop(i=0;16,alloc_base[i]=-1;i+=1);
function off(offset,nch,p,v) (
  alloc_chan[p] = 0;
  alloc_base[nch] = -1;
  midisend(offset,0x80|nch,p,v);
);

@block
while(midirecv(offset,m1,m2,m3)) (
  cmd = m1 >> 4;
  ch = m1 & 0xF;
  ( cmd == 0x8 || ( cmd == 90 && m3 == 0 ) ) ? (
    nch = alloc_chan[m2];
    off(offset,nch,m2,( cmd == 0x80 ? v : 0));
  ) : ( cmd == 0x9 ) ? (
    nch = alloc_chan[m2];
    nch > 0 ? (
      off(offset,nch,m2,0);
    );
    fch = 0;
    i=1;
    while(i<15 && fch == 0) (
      ( alloc_base[i] == -1 ) ? ( fch = i; tmx1 = i; );
      i += 1;
    );
    alloc_chan[m2] = fch;
    alloc_base[fch] = m2;
    midisend(offset,0x90|fch,m2,m3);
  ) : (
    midisend(offset,m1,m2,m3); 
  )
);