Hey Jules,
Made the transition this week from using JUCE to write a standalone app to an audio plugin (VST/AU), and quickly got up and running learning from your example code. Implementing parameter changes/saving presets seems to work great (following how you do it for the gain/delay knobs), however, we are a bit confused on saving presets/programs which aren’t necessarily parameters like a gain knob or delay knob.
As an example, in our plugin, we have 16 values stored in TextBoxes (derived in a custom class called NumberBox) which control things like gain. Each NumberBox class also has an array to store preset values for the TextBox. In our main gui, we then have a button which allows a user to store the state of the number boxes in each of their respective arrays, and a combobox, which allows the user to select the saved presets. We are trying to save the state of the entire program (the combobox and the arrays of presets in each NumberBox class), but can’t seem to get this to work properly, in the same way regular params do. How do we store an array of floats as a param?
Here is what we currently have implemented, thanks!
void CarwashAudioProcessor::getStateInformation (MemoryBlock& destData)
{
// You should use this method to store your parameters in the memory block.
// You could do that either as raw data, or use the XML or ValueTree classes
// as intermediaries to make it easy to save and load complex data.
CarwashAudioProcessorEditor* ourEditor = (CarwashAudioProcessorEditor*)getActiveEditor();
// Create an outer XML element..
XmlElement xml ("AUDIOCARWASHPRESETS");
xml.setAttribute ("gain", gain);
//add our attributes
for(int i = 0; i < ourEditor->volumeCoefficients.size(); i++){ //for each gain numberbox we have
for (int j= 0; j < ourEditor->presetSelector->getNumItems(); j++){ //for each saved preset value
xml.setAttribute("volumeCoefficient"+(String)i, ourEditor->volumeCoefficients[i]->values[j]); //store the gain value
xml.setAttribute("probabilityMatrix"+(String)i, ourEditor->probabilityMatrix[i]->values[j]); //store the probability value
xml.setAttribute("presetMenu"+(String)(j+1), j+1); //store the preset number/name used in the ComboBox selector
}
}
// then use this helper function to stuff it into the binary blob and return it..
copyXmlToBinary (xml, destData);
}
void CarwashAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{
// You should use this method to restore your parameters from this memory block,
// whose contents will have been created by the getStateInformation() call.
// This getXmlFromBinary() helper function retrieves our XML from the binary blob..
CarwashAudioProcessorEditor* ourEditor = (CarwashAudioProcessorEditor*)getActiveEditor();
ScopedPointer<XmlElement> xmlState (getXmlFromBinary (data, sizeInBytes));
if (xmlState != 0)
{
// make sure that it's actually our type of XML object..
if (xmlState->hasTagName ("AUDIOCARWASHPRESETS"))
{
gain = (float) xmlState->getDoubleAttribute ("gain", gain);
for(int i = 0; i < ourEditor->volumeCoefficients.size(); i++){ //for each gain numberbox we have
for (int j= 0; j < ourEditor->presetSelector->getNumItems(); j++){ //for each saved preset value
ourEditor->volumeCoefficients[i]->setValue((float)(xmlState->getDoubleAttribute ("volumeCoefficient"+(String)j), 1.0)); //set the gain value
ourEditor->probabilityMatrix[i]->setValue((float)(xmlState->getDoubleAttribute ("probabilityMatrix"+(String)j), 100)); //store the probability value
ourEditor->presetSelector->addItem((String)(j+1), (j+1) ); //store the preset number/name used in the ComboBox selector
}
}
}
}
}