Where to paste after copy?
Captain's Log: Stardate 77834.8
The last couple of days I've just been hammering away on small usability issues in my "must fix before release" list.
Yesterday I solved a whole host of problems related to how the simulator backend handles error cases, and how the user can reset the simulator (either because it got into an error state, or because the physics got into a weird state). I had been putting this off for a long time because making the stateful reset logic robust seemed really tricky, especially since new state keeps creeping in (delay line audio state, modulator state, etc).
I laughed when I realized that the simplest/best solution was to just serialize the whole model, reset everything completely, and then unserialize it. Basically cut and paste the whole preset. Since serialization only records durable attributes and not state, this guarantees that all state is fully reset, even if I add further state in the future. I can't believe I almost spent days adding a bunch of per-state reset logic, etc! With this approach I got things working perfectly in less than a day.
Today I was mostly working on the copy+paste, duplicate, and import code that figures out where to put a set of entities such that they don't overlap with existing entities. For example, if you select some stuff and press ctrl+d to duplicate, previously it just pasted things 1 cm above where they were copied from. Or if you imported a preset, it would just stick it right in the center of your current instrument, overlapping and causing grief.
Now things are much smarter. A minimal axis-aligned bounding box (AABB) is computed for the copied entities, and when you paste (or duplicate/import), it automatically looks for a minimal offset to that box that will put things in a clear space with no intersections. There are a couple strategies, ending with moving it just outside the AABB containing the entire preset, so it can guarantee that it never pastes over existing stuff.