Why Doesn't This Choke Script Work?
-
I get what you mean.
The issue with that is when several voices are overlapped and ringing together (like a 32nd note snare roll for example), so only killing the previously-stored event does not always guarantee the ringing sound of the snare will fade out.
One can argue that a snare can be treated as a monophonic instrument, but then there is the case where a hard note followed by a soft note would sound unnatural since the hard hit ring would be faded too quickly.
I'm aiming for more realism by having this choke script in place, and it will apply to many other drums too.
-
@ericchesek So the problem is you need to have multiple note IDs per note?
By the way, is there a reason you're not using the built in choke script?
-
@d-healey Yes, I need multiple IDs per note.
I'm not using the built in choke script because I need more control over when and how chokes are triggered. For example, the velocity-based choking thing I mentioned above where a soft note results in a longer choke fade time than two notes with a more similar velocity. -
@ericchesek I'm not sure you do need multiple IDs per note. When a new note is played, kill the old event that is attached to that note number. Don't fade it out, kill it with
Synth.noteOffByEventId()
. That will stop the note but the tail will continue to the length of the envelope or the length of the sample, whichever is shortest. -
Isn't that already happening in my switch/case statement? I call a synth.playNote(), then immediately afterwards I call a synth.noteOffDelayedByEventId(). That has a time of 1 sample currently for testing purposes, but it works just the same if I use synth.NoteOffByEventId().
Setting the note off is only clearing the eventID, but not stopping the sound. Is my understanding correct?
-
@ericchesek
Synth.noteOffByEventId()
will kill the note immediately. -
@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) { }
-
@ericchesek Clear the event ID in the note off callback
-
@d-healey Do you mean in place of the separate Synth.noteOffByEventId(eventID);
statements I have in each case statement? -
@ericchesek in addition, everytime a note is released you can kill it so you don't get a build up