Detect *any* changes in a ValueTree


#1

Right now if you want to listen to changes on a ValueTree you have to implement several pure virtual methods from ValueTree::Listener: one when a property has changed, another one when a child is added, and so on.

My question: is there a general method to detect any kind of changes done to a ValueTree? I don’t care if it’s a new property or a child removal, I just want to do something when the ValueTree changes.

Thanks in advance :wink:


#2

Very easy to roll your own - e.g. this is a helper class we use in Tracktion

struct ValueTreeAllEventListener  : public juce::ValueTree::Listener
{
    virtual void valueTreeChanged() = 0;

    //==============================================================================
    void valueTreePropertyChanged (juce::ValueTree&, const juce::Identifier&) override  { valueTreeChanged(); }
    void valueTreeChildAdded (juce::ValueTree&, juce::ValueTree&) override              { valueTreeChanged(); }
    void valueTreeChildRemoved (juce::ValueTree&, juce::ValueTree&, int) override       { valueTreeChanged(); }
    void valueTreeChildOrderChanged (juce::ValueTree&, int, int) override               { valueTreeChanged(); }
    void valueTreeParentChanged (juce::ValueTree&) override                             { valueTreeChanged(); }
    void valueTreeRedirected (juce::ValueTree&) override                                { valueTreeChanged(); }
};

Might be a handy thing to add to juce, I guess.


#3

Hi jules, that’s exactly what I need. Thanks!