Storing 'addresses' in a ValueTree

I have two Array, Array<Osc> and Array<Wave>. Each Osc have a pointer to a Wave. User may reorder, remove, or add elements to both Arrays.

How could you store Array<Osc> with the pointer/address to a Wave element in a ValueTree?

My current approach is storing the Wave indexes in the ValueTree which contains the Array<Osc>, and refresh all indexes when user modify the Array. It works, but it seems ugly.

Another approach would be Wave have an unique member ‘id’, and storing that ID. But, how could I make sure I’m always generating new IDs for each new Wave the user generates?

It could be done if you make your Osc and Wave classes derive from ReferenceCountedObject. You can then store this as as a var on the ValueTree.

But I would really caution you against this, as you’ll run into lots of problems. I think this might be one of those times when you should re-think your approach instead.

ValueTrees work best at storing Strings, ints, bools, etc. that correspond to user-defined data. You can then build wrapper classes around them to customize your Osc and Wave classes, using the ValueTreeListener functions to respond to changes. Remember that a ValueTree is already ordered in its parent node. Maybe you can use this ordering to keep track of your Osc and Wave?

often it makes sense to come up with meaningful systems of identifiers for your stuff so that the valueTree doesn’t actually hold the stuff or a pointer to the stuff, but just enough information to recreate the stuff on demand, just like how it’s done with parameters

Thanks for the replies. After doing some research, I’m going to take the way to store unique identifiers, it makes more sense, and it will keep my sanity in a good state