onTimer swap between samplers
-
I wouldn't use a timer for that. You get a precise timing with Engine.getUptime() that you can use in the onNoteOff callback to get the duration of the note:
// This is only monophonic so for a real use case you might want to // use another data storage type. reg start = 0.0; function onNoteOn() { start = Engine.getUptime(); } function onNoteOff() { local durationMs = (Engine.getUptime() - start) * 1000.0; // do something with the duration }
-
@Christoph-Hart Thank you. That's interesting. I'll play around with it and see if I can make it work :)
-
@Christoph-Hart That works well and gives me precise values. Excellent. I'm off to the next steps :) Thank you!
-
@Christoph-Hart I was wondering if you could give me a little nudge here. It seems that I am missing something. Everything compiles ok, but the quick fade-out I am trying to achieve is not happening. It seems to be getting ignored. I get no errors. This is what I have:
onInit reg start = 0.0; const var evtList = []; evtList.reserve(64000); function onNoteOn() { start = Engine.getUptime(); } function onNoteOff() { local durationMs = (Engine.getUptime() - start) * 1000.0; // do something with the duration if (durationMs < 96) { for(eventId in evtList) { Synth.addVolumeFade(eventId, 50, -100); } // Clear all notes evtList.clear(); } Console.print("open surdo timer is "+durationMs); }
-
@gorangrooves Is it possible for durationMs to ever be less than 1000 ?
Console.print(durationMs);
Also evtList isn't being populated. And why are you reserving 64000 elements, that seems like a lot? -
@d-healey Yes, the duration is between 45-95ms when quickly striking the keys.
I guess I could lower the even list reserve since it is getting cleared all the time. I did it a while ago on a hi-hat script fearing that it wouldn't be enough, but now I realized that it gets cleared.Why isn't the event list isn't being populated?
-
Because you didn't push anything in there :)
-
@Christoph-Hart "That's what she said!" Ha!
Let me see if I can stick that in there.
-
Yes, I suck at coding, but I am good at recycling! I reused this nice little bit of your code @Christoph-Hart and made it work :)
onNoteOn start = Engine.getUptime(); Message.makeArtificial(); evtList.push(Message.getEventId());
Thank you kindly, gentlemen!
-
@gorangrooves That's not a good way to do it. You're essentially just adding an endless number of event IDs into the array, the more notes played the less efficient your instrument will become. You should use a MIDI list instead.
-
@d-healey I have no idea how to go about that. Isn't that array getting emptied every time with
evtList.clear();
?
-
@gorangrooves Oh yeah so it is, so you're just wasting memory and CPU cycles with your
evtList.reserve(64000);
:pYou should use a midi list.
I have no idea how to go about that.
Now is a good time to learn. https://docs.hise.audio/scripting/scripting-api/midilist/index.html
-
@d-healey Thanks, Dave. I'll try to make some sense of it and see if I can make it work.