Reading Values In Processor::setState (IBStream* state)

I’m new to VST3 and trying to read back values from a saved preset. This works fine in the Contoller::setState(IBStream*state) method but any attempt to do so in the Processor::setState function bails out with an error, e.g. basic code like-

IBStreamer streamer (state, kLittleEndian);

float TestVal0 = 0;

if (streamer.readFloat(TestVal0) == false)
return kResultFalse; //Read failed

It’s like the state variable contains no content. I’m presuming that since this function is called before the controller’s setState it’s so that one can read the values saved in the preset into the processor. Is even this assumption correct?

Tearing my few remaining hairs out over this. Any pointers on what I may be doing wrong? As I said, the same code works fine in the Controller’s setState. I don’t want to use a kludge like passing the parameters via global variables or the like, as that doesn’t seem to be “in the spirit of the thing”.

The controller and processor have their own set/getState methods. So you can store both sides. The controller in addition gets the processor state via IEditController::setComponentState.

Hi Arne, thanks for replying! I’m aware they have their own methods, the problem is that I can’t seem to do anything with the variable “state” passed into the processor:SetState() method. I can read the values from it find in the controller:setState() method, but not so the processor’s setState(method). I just can’t get any kind of understanding of why.

streamer.readFloat(var) just returns false.

You read the state in the controller with IEditController::setState and write the state with IEditController::getState. For the processor it is IComponent::setState and IComponent::getState. You cannot read the state from the editcontroller in the processors setState method.

Yes I know, I have stated a couple of times now that I’m unable to get the state in the processor:SetState() method despite being able to do so in the controller:SetState() method and I am hoping to understand why that is. Here is my processor method:

tresult PLUGIN_API PD10_FirstGoProcessor::setState (IBStream* state)
// called when we load a preset, the model has to be reloaded


IBStreamer streamer (state, kLittleEndian);

const int numValues = 128;

double testArray[numValues] = { 0 };

for (int i = 0; i < numValues; i++)
{ >
if (streamer.readDouble(testArray[i]) == false)
return kResultFalse; //Read failed?

mSlider1 = testArray[0];
mSlider2 = testArray[1];
mSlider3 = testArray[2];
AHFoo.slider1 = testArray[0];
AHFoo.slider2 = testArray[1];
AHFoo.slider3 = testArray[2];

return kResultOk;

It bails at the first attempt to read a value into testArray. The same code works fine in Controller::SetState().

OK, post your PD10_FirstGoProcessor::getState (…) method.

It’s empty. I presumed the Controller::getState() is sufficient. Do I need to deliver it from both Controller and Processor? Is it thus saved twice into the .vst3preset file?

Thanks Arne, I have got it working now, I didn’t realise I had two states to save!

Arne, if you’re still watching this thread and kind enough to answer, is there a maximum amount of values I can save and load in the state stream? Like, is it a fixed number of bytes?

There is no predefined limit… but it could depend on the host to have such limit… for example Cubase only support project size up to 4GBytes

1 Like

That’s odd, because it seems after writing a certain number of values of float or int etc, it fails. I can write 64 values but not 128. I get a kResultFalse returned by


Don’t know why.

which host?
can you provide more info, like sample code?

1 Like

The supplied test host with the SDK. I’ve tried a variety of code, all based on loops of streamer.writeFloat() or streamer.writeInt() etc, and after a while they fail to write more values. So just for some n values;

for (int i=0; i < n; i++)
if (streamer.writeFloat((float)n) == false)
return kResultFalse;

kind of thing. Should this work for an arbitrarily large n?

hum…strange… If you try to load a different plugin from other company, can you save and load preset?
Could you provide a plugin example with source code which we could build?

1 Like