Effect initialization?


#1

Where is the best place to initialize a large data structure that needs to be read from disk? In VST3, there is the initialize() function. In AAX, there is effectInit(). But the only place I see that is obvious in JUCE is the Processor’s constructor. But it’s always been my practice to postpone such initializations until initialize()/effectInit(). Is there an equivalent place in JUCE to initialize()/effectInit() where I can put these kinds of larger initialization tasks? Or do I need to do this in the constructor?


#2

prepareToPlay.


#3

That gets called a lot, doesn’t it? I can use a flag to say if I’ve done the initializations already or not, but I was hoping there was a direct equivalent to initialize()/effectInit(); something that is called just once after construction but before the plug-in is actually used or its UI created.


#4

Well, it really depends, why you want to move that out of the constructor:

  • not doing it when plugin is probed
  • speeding up build of graphs

Solution: moving to prepareToPlay:

  • might be called last second before playback starts, so you delay playback

What about triggering your initialisation on an extra thread from the constructor, and block prepareToPlay, until is really initialised?

Just an idea…


#5

Yes - if what you’re doing takes so long that you have to ask this question at all, then it’s too slow to put in ANY of the callbacks that the host makes - it needs to go on its own thread.

But no, please don’t block prepareToPlay waiting for your background task to finish! The correct thing to do is for your plugin to run but remain silent if it’s still loading - and show something on its UI to indicate that to the user. Never ever block any of the callbacks!


#6

True, doing something sensible meanwhile is the far better option! (…if it is achievable)


#7

There have been two primary reasons for putting that kind of stuff outside the constructor. One is that we previously used derived classes of a common Processor base class, and we needed to avoid calling virtual functions from the constructor. (Not calling virtual functions for this any more in my JUCE projects, so that problem goes away anyway.) The other was to speed up loading times when simply being probed/analyzed by the host. The loading time for reading these files does not seem to be an issue (at least not yet) in my project, so at least for now I have that work done in prepareToPlay(), (rather than a separate thread), with a flag showing if it’s been done already or not, to prevent doing it multiple times. Thanks, everyone!