It would be super useful if there was a default parameter on ValueTreePropertyValueSource, the underlying class you get when you call ValueTree::getPropertyAsValue() .
Use case: I’m using lots of CachedValues to manage ValueTree properties, and I usually use the defaultTouse parameter so that I get a default value if the property is empty. I also use getPropertyAsValue() to link properties to sliders etc. But since this doesn’t have the same default parameter, it doesn’t link up very well, and the sliders have the wrong default parameters. Of course you can fix this by defining the property, but it would be nice if it could work with default parameters out of the box.
The modification would be really easy: just add a new defaultValue var parameter to the ValueTreePropertyValueSource class and then call getProperty like this:
juce::var getValue() const override { return tree.getProperty(property, defaultVar); }
If you modify the ValueTree member function to take a null var for the default parameter, nobody’s code will break.
getPropertyAsValue (const Identifier& name, UndoManager* undoManager, bool updateSynchronously = false, var defaultValue = {})
If this is too intrusive, then it would be just as easy to inherit from ValueTreePropertyValueSource, add the default parameter to the derived class, override getPropertyAsValue again, and then add a new ValueTree member function to access the new ValueSource.
I’ve had my own version of this running for a while now, and it works very smoothly. I think it would make a good addition to Juce.
