Is it possible to delay midi notes / sampler playback by a few ms?
-
To be consistent with the subtle timing errors of old drum machines, I'd like to give include the possibility to have slight timing issues (+/- 5-7ms) on drum hits. / one shots. Is there a way to delay an incoming midi note before it is played on a sampler by that little amount or maybe add a random output delay to a sampler on a per note basis? if so, how?
-
Message.delayEvent should do it?
-
@Simon i tried that but all i get is an error
Call of delayEvent() outside of midi event callback
function onNoteOn() { Message.delayEvent(Math.randInt(0, 2000)); local nn = Message.getNoteNumber(); if (drumNotes.contains(nn)) { var idx = drumNotes.indexOf(nn); drumPads[idx].data.alpha = 1; drumPads[idx].changed(); } }
-
Have you tried in a blank project?
HiseSnippet 932.3oc4WEraaaDDcWKwfJk1flhffbjG5Amhf.RaEYazCw1xRoBMxVvzIs2BVSNzZgI2kc4R0JTz+wdteE4OncVRYSRGFGU0lbnUGDzLyNbe6al4wUSUReHMUpHztmsHAHzO2xagPOavLFWPFeDgdOqIrTMnrKbc3hDVZJDPnzVuv3f1oMI+yae9grHlvGJcQHuVx8gWxi45RuS2+64QQiXAvY73Jqt29i8khAxHYFhmVVNjDl+krKfiYlksgE46XoyHzuwx4Y8AXmsCCBXaucP+982a285smKKzoG6b2960aqd6r0t6DRn2YX.WKUdZlFRIz1GJCV3MS9yhhM307T94Qfwvk3g6bg6Qxn.yQz7axfY7nfoWQToDB0ZZIs0pf1df0Dd.+Z+kz2WlGvtLipDHci5vqUM3499fWCPhVARsKfz8s77U7DcYDCdtq0XAVMCYXcpJTJVKg9GVCj3BD5mFytDFoPiqSXy9NNOwF+5weaXlvWykBao3XoFNQr4i69qc6LA2Hrf8z.HhsX3b7wroqiiIgt+VW6alTXXQV2HlA.JYTDnZLrooQcaItoHK9bP8D64rnL35EhDSc19NqFa6WvGUVnTLVv0mj.KsKaWban1PVRn3ud03iXZlobszGttDPo4F3POBliCKEEuNVGAoWpkI33x6TYwdJYPVDSWuQyLNtL.xG0ptlRnHkqWTcb8lcese+7gSiCGMdZWQ3deqobs+rlw6FMfWj09Xi2kyxeg0vvPvWWB11Vi9wacv8ecnbuBnbWKOt.xUjyAxCyss+A1bv9Ef.TFR08VDk+8UUTNYkEkOwWia+YJlHMQlV6A6Aw7yjBCiT57UonLB7SmZpxU8OPxTMF5sOeDdHaLGOlNSk2tbPrLSnq0dzZkqIUGuqO0TY8Mnx19ikv+mzQu+4JEsVM39AdOUmqvnGONIBFJlCQnbXNF+JT+KjkEouxa8l7IRgLYlTv8q1AbJnU7Kt.TUwdiGnCzZ7pEkddv9mBQ.qZ27Wu+KwtPlB4IXM4h+9uytw50irJfqsYxz9+FJ7s9+oB+oxLMWbwDF1n9K3EIONK1CEV8ADIBADgajEcCi3XgsiwtPYUDja7m3mkAcM1zkAcuJ3mj8Hl4qjuwu39Vld4OK2CdtE42UuC9mFPaaWR9cvpViiQUw236W+Q8NIt05l31qah8V2De15lX+0MwcV2D28Cmn4kVGjokwEirDxjoCyuzJkNTvvN97oCxeA7JjQGI
-
@Morphoice probably because your script is deferred. Are you trying this in the interface script?
You can't reserve your interface for interface stuff and ask it to deal with midi messages at the same time -
@ustk it's in the onNoteOn function not the onInit... though I don't really know the difference
-
@Simon it does work there yes. probably the deferred thing
-
@ustk there is a Synth.deferCallbacks(true); in my main script but even if I remove that, I get the same error
-
@Morphoice remove and reload the project, this sounds familiar to me...
onNoteOn
,onNoteOff
, etc... are callbacks within the interface (or other) script, not different/independent scripts, so they all "see" what is inonInit
-
@ustk superb! quitting hise and reloading did the trick. thank you so much
-
@Morphoice said in Is it possible to delay midi notes / sampler playback by a few ms?:
even if I remove that
You should keep it, it forces good programming habits by preventing you doing real-time stuff in your ui script. You should make a secondary script for playing your notes and connect your GUI to it.
-
@Morphoice When you save a script to clipboard, it shows like this:
function onNoteOn() { } function onNoteOff() { } function onController() { } function onTimer() { } function onControl(number, value) { }
So you see they are just functions within
onInit
-
@Morphoice Dave said it, just keep it and do your MIDI things in another script
-
@d-healey this might sound like a totally stupid noob question, but how exactly do I do that? I have only ever put stuff inside the interface script or put some functions into an include which I recon are "included" so not really out of the script
-
@Morphoice said in Is it possible to delay midi notes / sampler playback by a few ms?:
but how exactly do I do that
This is the simple explanation, but not necessarily the best way:
- Add a new MIDI processor.
- Take all your MIDI note generating code, your button grid, etc. and copy it to this new MIDI processor.
- Remove the MIDI note generating code from your UI script.
- Connect the buttons on your UI to the buttons on the new MIDI processor.
A better approach would avoid duplicating the grid and would allow the new MIDI processor to handle an arbitrary number of grid buttons on the UI so that it could be reused in other projects. But this would require more work so probably not worth the trouble at this stage of your HISE journey.
Another, more modular approach, would have a separate MIDI processor for each of your samplers.
-
@d-healey the delay needn't be on the pads, I'm fine with it on the real midi input only
so I created a new MidiProcessor and put the delay code in it's onNoteOnfunction onNoteOn() { Message.delayEvent(Math.randInt(0, 30000)); }
that seems to do the trick and I can reenable the deferCallbacks on the interface script! Unless I'm mistaken this was an easy fix that should work
-
@d-healey ofc the delay value is just around 300, I'm just looking for phase variance when the oneshots appear on a strict grid they sound better that way, as not every kick/snare is exactly at the same position as all the other sounds. It's what gives the organic 80s vibe ;)
-
@Morphoice said in Is it possible to delay midi notes / sampler playback by a few ms?:
so I created a new MidiProcessor and put the delay code in it's onNoteOn
That should do it.
-
@d-healey what you suggested with duplicating the controls to pilot the other script is what I would go with as well, but... Would there be a simpler way using instead a global broadcaster of some sort?
-
@ustk said in Is it possible to delay midi notes / sampler playback by a few ms?:
a global broadcaster of some sort
I tried adding a broadcaster to a global variable but it didn't go well. I asked Christoph about it and he says not to do it.
The way I suggested is the way all the other built-in modules of HISE work, so I think it's a good way to do it.