Or, if you need it to fire sample accurate, allowing multiple impulse per block, and only for note-ons (rather than for all kinds of message, potentially)
Code:
desc:Impulse Generator 2
// after ErBird
out_pin:left output
out_pin:right output
@init
NOTEON = 0x90; // Handy constant
armed[]; // Array of block offsets at which noteons are detected (need impulse at these points in the block)
i = 0; // keep track of where this sample is in the block
@block
i= 0;
while (midirecv(offset,msg1,msg2,msg3))
(
((msg1 & 0xF0) == NOTEON) && (msg3 > 0) ?
(
armed[offset] = 1; // where should we fire in the block - perhaps more than once
);
);
@sample
spl0 = spl1 = armed[i];
armed[i] = 0;
i+=1; // count samples