Until I learn more about JUCE and all it can do, for now I have done the following to save and retrieve my wavetables. I am fully aware there are so people many here, most actually, that know JUCE and C++ much better than I do, and because so they can therefore do it better, more efficient, but hey I gotta do what I can to move this project along.
Saving;
void MutineerAudioProcessor::getStateInformation (MemoryBlock& destData)
{
auto s = parameters.copyState ();
std::unique_ptr<juce::XmlElement> xml (s.createXml ());
// UI settings stored here
for (int module = 0; module < maxModules; module++)
{
// Some parameters saved here
// Checking here if saving is necessary (custom table), or just default type
std::string wavetable = "";
for (int i = 0; i < wtSize; i++)
{
// The below precision, which keeps string getting to big,
// is acceptable to me!
//wavetable = wavetable + std::to_string (int (
// tgPS.tgActiveWaveform[module][i] * 32767)) + "|";
// Compared to the above commented out line, the below code eliminates
// about 12KB, the "-" character, on 8 x 4096 tables
wavetable = wavetable + std::to_string (unsigned int
((synthParams.tgActiveWaveform[module][i] + 1.0f) * 65535)) + "|";
}
xml->setAttribute ("wavetable" + String (module), wavetable);
// More parameters stored here
}
copyXmlToBinary (*xml, destData);
}
Retrieving;
void MutineerAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{
std::unique_ptr<juce::XmlElement> xmlState (getXmlFromBinary (data,
sizeInBytes));
if (xmlState != nullptr) {
if (xmlState->hasTagName (parameters.state.getType ())) {
// UI setting retrieved here
for (int module = 0; module < maxModules; module++)
{
// Parameters retrieved here
// Checking here if table is default type or custom table
String temp = xmlState->getStringAttribute ("wavetable" +
String (module), "");
std::string wavetable = temp.toStdString ();
for (int i = 0; i < wtSize; i++)
{
tgPS.tgActiveWaveform[module][i] =
float (std::stoi (wavetable)) / 65535 + 1.0f;
wavetable = wavetable.substr (wavetable.find_first_of ("|")
+ 1);
}
// More parameters retrieved here
}
parameters.replaceState (ValueTree::fromXml (*xmlState));
}
}
}
