my_value_of_somekind should be int or double, but should still show as proper numbers in the Label. This is due to two reasons:
I need to use those values in realtime parts of the software.
I want to save the ValueTree where those values are into a file without them being there in text format.
How do I achieve that? I assume that Label::getTextValue() works only with text so when I actually get that value from ValueTree, it’ll do some kind of slow text to int/double conversions? How to avoid that?
Also, when I use ValueTree::setProperty to create an initial value which uses int/double, it won’t help. So what’s going on? Is there a way to ensure the Value uses internally something else than String to contain the current value?
I also tested what gets saved into the file if I don’t do that “referTo()” part at all. The result was that the saved file contained proper binary data instead of a string. I really want to keep that data as binary data also in the memory at all times.
Value and ValueTree are poor choices for use on the realtime thread. They don’t make any guarantees about what operations might cause allocations, and it’s a bad idea to allocate on the audio thread. Additionally, it’s difficult to safely synchronise access to ValueTrees from multiple threads because multiple Values might all be referencing the same shared state. If you’re accessing the ValueTree from the UI thread and the audio thread simultaneously, you’ll almost certainly end up with data races.
The label needs to display the value as text, so some sort of text<->numeric conversion is unavoidable. I think in order to keep the ValueTree entry stored as a numeric value rather than text, you’d have to write your own conversion. That is, instead of using label.getTextValue().referTo() you can use a Label::Listener to detect when the label text changes, convert it to a number, and store it into the ValueTree; and you can also listen to that Value and update the Label’s text appropriately when the Value changes.