Hello,
when I recover saved processor value tree state in setStateInformation() I would like to send initial sendPropertyChangeMessage() to all paramaters listeners. But it is called only if I pass to setProperty() the value which is different then old one.
So to ensure sendPropertyChangeMessage() is called I need to call it by myself. But in that case if I really pass new value to setProperty() then the sendPropertyChangeMessage() will be called twice. First time inside setProperty(valueDifferentThanOldOne) and second time by myself.
So to avoid that firstly I need to get old value by getProperty(), and check if it is the same as new one, than call setProperty(), and then if old value was the same as new one I will call by myself sendPropertyChangeMessage(). It is little bit neckbreak.
So I wonder if is there any better way to solve that issue?
For any help great thanks in advance.
Best regards
I don’t know of an alternative method, but I am using the described getProperty()/sendPropertyChange() method successfully. For me it’s part of a base class, so I only had to code it once.
I know, that there sometimes doesn’t seem to be any other way (and I really don’t want to impose!!!) - but for me that problem sounds rather like a problem in the software design using the ValueTrees and now you are trying to go around that problem.
I’ve never been in this particular situation, were I wanted to receive an update, even though nothing changed. Maybe you could share in a few words what is happening in more detail. There could be a way around this problem
Thanks for all answers. Actually Rincewind tell truth. I designed it in wrong way from the beginning. But now it is really a lot of work to repair that. Of course this is further target, to make all of it properly, but at the moment I need some emergency solution. So it looks like I will stay with cpr2323 proposition.
By the way I have another problem with ValueTree, and I wonder if any of you met similar problem.
And the issue is as following:
Reading ValueTree::fromXml() lost all var types, and for all I get var::isString() true. And in my case this is big problem. While mainly var::equal() still work, but for some float values it loses precision when casting from String and then var::equal() is considered as false.
So now after I read from xml I have my own method which repairs all types in my ValueTree. But it also seems to be very neckbreak. So I wonder if is there any solution for such issue?
For me this is a design benefit. I want the flexibility of both when controlling hardware over bandwidth limited transports, like USB serial and Bluetooth. When initializing the hw with a known state I want all the data to get sent, but when changing a single parameter after that I only want the value sent if it has actually changed.
I’ve been seeing your name for some time in this forum, so you probably know what you are doing!
So yeah, this is a totally valid use case it just so happens, that ValueTree didn’t seem to be designed that way.
I totally get your pain!! I had a very similar issue. I was trying to assert, that the Value (/var) being passed to my object is a boolean. BIG MISTAKE! I spend two hours trying to prevent that assert from firing with all my tests and then gave up.
In your case, I wouldn’t consider using equal at all when working with floating point numbers. That’s not a particular problem from var, but also for the built in types. Try to get around it and if it is absolutely not possible, you could A) represent your value as an int (as in don’t save seconds as float but milliseconds in int) or B) compare that two types using a float epsilon (std::numeric_limits<T>::epsilon - cppreference.com)
Adding some more info: it’s not only when serialising to string, the juce::var doesn’t have a float type, it is all stored in double, so you can get numerical hickups at any time.