How to sort / order child components?


In my piano roll, i am adding child note components, and storing pointers to them in an OwnedArray.

What's the best way to tag or sort these so I can find a child / children by their position in the grid?  When i create them, i am using "stepX" and "noteY" values to define their position on the X and Y axis, so that is available to be sent to a sorting function. 

Should i be giving the child components an ID string and sort them with that, or should i be sorting the OwnedArray, or is there another better option?





Depends entirely on how you need to access them.. Could be that the component order doesn't matter, but in something like a MIDI editor you may want overlapping notes to be ordered more flexibly to make them easier to edit.

But often it's wise to not worry about this kind of thing unless it's actually a problem. Unless you're frequently searching the array in a particular way which causes a performance hit, then maybe just ignore the order and do a brute-force search when you need it. And when you do hit that kind of performance problem, it'll be obvious what the criteria is by which you need to optimise things.


having a look at how it's done in the Animation demo.  brute force should be fine in this case.