i’m very new at all of this and trying to get my head around using both JUCE and C++ at the same time. I have managed to make a few working plugins but i keep falling over what i think must be very simple problems. My current one is trying to use a Value Tree to store an OSC port number for save and load. iv been following the tutorial but the code quoted there does not seem to work for me. i’m sure i’m just putting it in the wrong place.
in my processor.h at the bottom under private i inserted the quoted code:
static Identifier myNodeType (“MyNode”); // pre-create an Identifier
ValueTree myNode (myNodeType); // This is a valid node, of type “MyNode”
this gives the errors:
“expected )” on the top line and
“unknown type name” on the bottom line.
could someone point me in the right direction?
If you are using a recent version of JUCE/Reprojucer, the JuceHeader.h header doesn’t do
using namespace juce; by default anymore. This means that you have to prefix types from JUCE with
static juce::Identifier myNodeType ("MyNode");
juce::ValueTree myNode (myNodeType);
I hope this helps.
thanks for that. using your code in the Processor.h still thew the same errors.
it did get me thinking tho so i tried using this code in the processor.cpp constructor and it works fine. i’m still learning the basics of how to layout my code but i think i’m getting there.
I happened to look this up last week. Initialising static variables in a header is a C++17 extension (that is also what Xcode wrote as warning btw.)
If you use a language standard before C++17 you need to declare the variable in the header and initialise it in the cpp.
I am happy to hear alternatives, but found several blogs saying it is not possible.
Construct and add parameters in an old way
But get mistake in juce_ValueTree.cpp
jassert (object != nullptr); // Trying to add a property to a null ValueTree will fail!
If i create AudioProcessorValueTreeState should i also create ValueTree?
The public ValueTree variable
state is undefined by default, that’s why you get the assert.
To remedy that you will have to set the variable to a valid ValueTree, like
tree.state = ValueTree ("PARAMETERS");
The name you give the tree doesn’t matter, but you can use it to check in the setStateInformation, if you got a valid state, that you wrote.
IIRC you had to set the tree at the end of the constructor, but cannot be sure after the changes. This workflow has a problem called “two phase initialisation”, that’s why you should consider updating to the new way of using the constructor that takes a ParameterLayout.