Since I didnt knew anything about the valueTree-class, but want to use it to connect my gui with the processor, I made a little demo to learn about it.
I know, its more than answering one simple question, but I would be really happy if someone could give me feedback and point me to possible mistakes.
Its a simple Plugin, where you can add and delete tonegenerators:
for the tonegenerators, i made a class called AudioClip, containing a ToneGeneratorAudioSource wich is connected to a main-mixer. In the processor there is an OwnedArray for the audioClips and an audioClipGrpValTree, wich contains all the parameters.
there is an viewport, wich is viewing an Component named audioClipViewer, this component contains an OwnedArray holding audioClipGui-Components, wich represent the audioClips with two Sliders and a remove-Button.
The processor, the audioClips and the audioClipViewer are Listeners to the ValueTree.
when the users clicks the add-Button, in the Editor there is an new valueTree-Node created, and given to the processor(function in Editor):
ValueTree audioClipTree(AUDIOCLIP);
audioClipTree.setProperty(VOLUME, gain, nullptr);
audioClipTree.setProperty(FREQ, freq, nullptr);
audioClipTree.setProperty(DELETE_FLAG, false, nullptr);
audioClipTree.setProperty(INDEX, processor.indexCount, nullptr);
processor.addAudioClipFromTree(audioClipTree);
the processor.addAudioClipFromTree()-method gets called by the editor and adds an audioClip to the OwnedArray and the Child-threeNode to the valueTree:
audioClipArray.add(new AudioClip(mixer, *audioClipGrpValTree, indexCount));
audioClipGrpValTree->addChild(valTree, indexCount, nullptr);
indexCount++;
as a result, the audioClipViewer gets notified about the change of ValueTree and adds an Gui-Element:
addAndMakeVisible(audioClipGuiArray.add(new AudioClipGui(childWhichHasBeenAdded)));
the audioClipGui-Components gets a reference to its child node, and connects the Sliders and the remove-Button to the TreeNode like this:
gainSld->getValueObject().referTo(valTreeChildToConnect.getPropertyAsValue(VOLUME, nullptr));
…
Now the Gui ist connected with the related threeNode, and if the Sliders are moved, the audioClips get notified about it and respond. The remove- toogle Button is connected to the DELETE_FLAG-Value, if it is set by the user, the child-tree will be removed
(valueTreePropertyChanged-Callback of AudioClip:)
if (int(treeWhosePropertyHasChanged.getProperty(INDEX)) == index)
{
toneAudioSource.setAmplitude(treeWhosePropertyHasChanged.getProperty(VOLUME));
toneAudioSource.setFrequency(treeWhosePropertyHasChanged.getProperty(FREQ));
if(bool(treeWhosePropertyHasChanged.getProperty(DELETE_FLAG)) == true)
audioClipGrpValTree.removeChild(treeWhosePropertyHasChanged, nullptr);
}
if the child-tree is removed, the audioClipViewer gets notified and removes the Gui-Element, after that the processor gets notified and removes the audioClip itself.
If the plugin gets closed and reopened in the DAW, the audioClipViewer recreates all the Elements in its Constructor:
for (int i = 0; i < valTree.getNumChildren(); i++)
{
ValueTree& valTreeChild = valTree.getChild(i);
//valTreeChild& = valTree.getChild(i);
addAndMakeVisible(audioClipGuiArray.add(new AudioClipGui(valTreeChild)));
}
is there any downside of this structure, especially when a project gets bigger? If so, what are the alternatives to this?