At the end I choose a personal way of programming in C++ my VST Plugin instead of using ValueTree component class…
I have some arrays of float ( Array ) in a separate object called “Presets” (class “Presets.h”).
I have one constructor and some methods to initialize and retrieve arrays and their values but when I try to change an array parameter via preset.set() method, it doesn’t change…
Here is the code:
Preset Object:
class Presets
{
public:
Presets()
{
configurations = { "CHORUS,DLY,REV", "PSHIFT,DELAY", "REVERB", "DELAY,REVERB", "CHORUS,DELAY", "PSHIFT,DELAY" };
presetNames = { "01 crs Pan Verb", "02 liquid Shift", "03 crs Delay Verb" };
}
Array<float> getPresetsArray(int presetNumber)
{
switch (presetNumber)
{
case 0:
return crsPanVerb;
break;
case 1:
return liquidShift;
break;
case 2:
return crsDelayVerb;
break;
}
}
String getPresetConfig(Array<float> arr)
{
return configurations[arr[0]];
}
void setParamToArray(Array<float> arr, int index, float value)
{
arr.set(index, value);
}
Array<String> configurations;
Array<String> presetNames;
// Preset Arrays
Array<float> crsPanVerb = { 0.0, // Configuration
0.0, 0.0, // Pitch LA
0.0, 0.0, // Pitch RA
0.0, 0.0, // Pitch LB
0.0, 0.0, // Pitch RB
500.0, 0.4, 0.15, 0.5, // Chorus
0.0, 0.0, 0.0, 0.0, // Delay
1.0, 0.18, 0.5, 0.5 }; // Reverb
Array<float> liquidShift = { 1.0, // Configuration
-0.7, 0.75, // Pitch LA
0.5, 0.25, // Pitch RA
-0.3, 0.75, // Pitch LB
0.5, 0.25, // Pitch RB
0.0, 0.0, 0.0, 0.0, // Chorus
0.0, 0.0, 0.0, 0.0, // Delay
0.0, 0.0, 0.0, 0.0 }; // Reverb
Array<float> crsDelayVerb = { 0.0, // Configuration
0.0, 0.0, // Pitch LA
0.0, 0.0, // Pitch RA
0.0, 0.0, // Pitch LB
0.0, 0.0, // Pitch RB
500.0, 0.6, 0.3, 0.5, // Chorus
9261.0, 1.0, 9261.0, 0.5, // Delay
1.0, 0.2, 0.8, 0.5 }; // Reverb
};
And here the code in the PluginProcessorEditor.cpp inside a SliderListener callback:
if (slider == ¶mSlider && menuPage)
{
if (selEffect == 0) // Pitch A
{
paramSlider.setRange(pitchA.minValues[selParam - 1], pitchA.maxValues[selParam - 1], 0.1);
Array<float> presetArray = preset.getPresetsArray(selPreset);
float paramVal = paramSlider.getValue();
//preset.setParamToArray(presetArray, selParam, paramVal);
presetArray.set(selParam, paramVal);
float curParam = presetArray[selParam];
lcdText.setText(pitchA.params[selParam - 1] + " " + std::to_string(curParam), dontSendNotification);
}
if (selEffect == 1) // Pitch B
{
paramSlider.setRange(pitchB.minValues[selParam - 1], pitchB.maxValues[selParam - 1], 0.1);
Array<float> presetArray = preset.getPresetsArray(selPreset);
float paramVal = paramSlider.getValue();
//preset.setParamToArray(presetArray, selParam, paramVal);
presetArray.set(selParam, paramVal);
float curParam = presetArray[selParam];
lcdText.setText(pitchA.params[selParam - 1] + " " + std::to_string(curParam), dontSendNotification);
}
}
Am I wrong in declaring the arrays in the Preset object?