Sample Rate changes
-
Is there a function that can automatically run when the DAW's sampling rate changes? Or how can we achieve this?
-
@resonant Transport handler perhaps https://docs.hise.audio/scripting/scripting-api/transporthandler/index.html
-
@David-Healey There doesn't seem to be anything related to sample rate in Transport Handler :(
-
We do have it in c++ nodes (function called prepare() gets loaded with sample rate when it changes)
If you need Hise to know about sr changes you can make a c++ node that then uses a global cable to trigger a hise global cable callback when sr changes...
But yeah that's obviously a workaround.Maybe Christoph can add a Hise function for this so that there is an easier way.
But if its something you absolutely need, I can show you how to set it up. -
@resonant There is no callback that can be automatically called when the audio state changes, but you can periodically call
Settings.getCurrentSampleRate()EDIT: or like @griffinboy suggested by getting it from the audio thread...
-
@griffinboy you don't need a cable, just read a
globalvar that updates from any scriptFX modulefunction prepareToPlay(sampleRate, blockSize) { g_SAMPLERATE = sampleRate; }from there you can compare to the old value and create your own callback
-
@griffinboy @resonant Oh wait! Actually there's a broadcaster for this!
// Broadcaster definition const var SamplerateChanged = Engine.createBroadcaster({ "id": "SamplerateChanged", "args": ["sampleRate", "blockSize"], "tags": [] }); // attach to event Type SamplerateChanged.attachToProcessingSpecs(""); // attach first listener SamplerateChanged.addListener("", "md", function(sampleRate, blockSize) { Console.print(sampleRate); }); -
@ustk This is it, I will try this thanks!
-
By the way,
attachToProcessingSpecsbroadcaster also seems to get buffer size! -
@resonant absolutely:
function(sampleRate, blockSize)
blockSize = buffer size