@d-healey Yeah that's fine. I switched to that instead of the delayed one and everything is still good.
I found a solution! Still using my round robin loop and an array to store previous event IDs for now.
It seems I do need to check if artificial events are active to make this work properly.
Eventually, I probably need to clear artificial events that are not active so the array doesn't just keep filling up if a sidestick note is never played.
Sampler.enableRoundRobin(false);
const eventList = [];
eventList.reserve(32);
reg prevEvent = 0;
inline function RoundRobin(low,hi)
{
local RRVal;
local PrevRRVal;
while (RRVal == PrevRRVal)
{
RRVal = Math.randInt(low, hi+1);
}
PrevRRVal = RRVal;
return RRVal;
}
/*
inline function RoundRobin(low,hi)
{
// this function results in repeating round robins for some reason...
// as evidenced by Console.print(RRVal)
local RRVal;
counter = (lastCount - 1 + Math.randInt(low, hi + 1)) % (hi - low);
RRVal = counter + low + 1; // adding low because my RR is note-based
lastCount = counter;
Console.print(RRVal);
return RRVal;
}
*/
function onNoteOn()
{
Message.ignoreEvent(true);
local eventID = Message.makeArtificialOrLocal();
local noteNum = Message.getNoteNumber();
local noteVel = Message.getVelocity();
switch(noteNum)
{
case 37: // side stick
for (i in eventList)
{
if (Synth.isArtificialEventActive(i))
{
Synth.addVolumeFade(i, 10, -100);
}
}
eventList.clear();
Synth.playNote(RoundRobin(39,47),noteVel);
Synth.noteOffByEventId(eventID);
break;
case 38: // hit
prevEvent = Synth.playNote(RoundRobin(0,15),noteVel);
eventList.push(prevEvent);
Synth.noteOffByEventId(eventID);
break;
case 39: // flam
prevEvent = Synth.playNote(RoundRobin(34,37),noteVel);
eventList.push(prevEvent);
Synth.noteOffByEventId(eventID);
break;
case 40: // rimshot
prevEvent = Synth.playNote(RoundRobin(17,32),noteVel);
eventList.push(prevEvent);
Synth.noteOffByEventId(eventID);
break;
}
}
function onNoteOff()
{
Message.ignoreEvent(true);
}
function onController()
{
}
function onTimer()
{
}
function onControl(number, value)
{
}