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.
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
//vv THIS DOESN’T WORK
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?
}
}
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?
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?
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
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?