Dealing with asynchronousness of the VSTPlugin opening

Hi, Loading a VSTPlugin is an asynchronous process?
How to wait until the plugin is loaded to perform its configuration (e.g. load a preset) ?
In my example, loading a preset returns an error no plugin! in executed at once, but works fine if executed line by line.

(
	~bassvst = VSTPluginController(Synth(\bassvst));

	// open a plugin by name/key (might require VSTPlugin.search!)
	~bassvst.open("sforzando.vst3", editor: true, verbose: false);
	try {
		~bassvst.loadPreset("MeatBallPizz");
	} { |err| format("While loading the preset: %",err.errorString).warn;
		~usevst=false;
	};

};
)

The .open command has an action argument which you can supply with a function that will be called when it’s ready. You can put the preset loading stuff in there and it will happen nicely and when it’s ready :slight_smile:

3 Likes

Not for me :frowning:

try {
	~bassvst.open("sforzando.vst3", editor: true, verbose: false,
		action:
		try {
			this.loadPreset("MeatBallPizz"); // <-- ERR: 'loadPreset' not understood, RECEIVER: an Interpreter
			// loadPreset("MeatBallPizz"); // <-- ERR: 'loadPreset' not understood, RECEIVER: MeatBallPizz
			//~bassvst.loadPreset("MeatBallPizz"); // <-- ERR: loadPreset: no plugin!
			~usevst=true;
		} { |err| format("While setting preset: %",err.errorString).warn;
			~usevst=false;

		};
	);
} { |err| format("While loading the plugin: %",err.errorString).warn;
	~usevst=false;
};

I tried various ways to load the preset, all are returning an error. What is the correct syntax ?

It’s just like Buffer, or GUI, or MIDI or OSC action functions – you have to give a function.

You left out the curly braces.

hjh

1 Like

Indeed. Thanks.
To be noted that the doc leads to confusion:
" action: an action to be called with this and a Boolean (success/fail)."
In this “action” function, one must not refer to the controller by this but by the variable holding it ( ~bassvst in my case).

1 Like

To be noted that the doc leads to confusion:
" action: an action to be called with this and a Boolean (success/fail)."

Yeah, the wording is a bit misleading. What I meant was that the function will be called with the VSTPluginController instance and a Boolean as arguments. This means that you don’t need a variable to refer to the instance:

~bassvst.open("sforzando.vst3",
    action: { |x, success|
        if (success) { x.loadPreset("foo"); } { "couldn't load plugin".warn; }
    });   

Seems like I don’t really have an example in the docs… Will fix this.

3 Likes