# Feature request: default value for ValueTreePropertyValueSource

**URL:** <https://forum.juce.com/t/feature-request-default-value-for-valuetreepropertyvaluesource/61382>\
**Category:** Feature Requests\
**Created:** [May 14, 2024, 4:14am UTC](https://forum.juce.com/t/feature-request-default-value-for-valuetreepropertyvaluesource/61382 "2024-05-14T04:14:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![LiamG](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/liamg/32/6844_2.png) [@LiamG](https://forum.juce.com/u/LiamG)\
**Post date:** [May 14, 2024, 4:14am UTC](https://forum.juce.com/t/feature-request-default-value-for-valuetreepropertyvaluesource/61382/1 "2024-05-14T04:14:05Z")

</div>

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:

```auto
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.

```auto
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.
