LMMS/lmms — pull request #902 by diizy (2014-06-27 15:38:42+00:00)
Title: FxMixer: rewrite mixer routing

@tobydox, another merge warning... this will again conflict with master. If you want, I can handle the porting to master branch again...

Anyway, I got a bit tired of constantly fixing bugs caused by design flaws in the new fx mixer routing. I'll try to keep it short here, but basically:
- earlier, we were keeping track of channel sends by each channel holding a vector of integer indices, corresponding to the channel indices. Each channel had 3 vectors: sends, receives, and a vector of FloatModel*s for send amounts.
- problem was, keeping all these vectors in sync had to be done manually, it was very error-prone and hard to get working right. Especially when moving or deleting channels... if a send/receive got out of sync, it would inevitably lead to failure and crash. Especially, since the sendamount models were thrown in the mix... common situation: channel x claims to be receiving from channel y, but channel y doesn't know about that, channel x gets processed and tries to get send amount model from channel y, gets null pointer and crashes.

Now, I rewrote the whole thing. Instead of these haphazard int vectors, I wrote a new abstraction: FxRoute. The FxRoute object holds direct pointers to both sender and receiver channels, and a pointer to the send amount model.
Now each fxchannel still has "sends" and "receives", but the sends and receives are pointers to the FxRoute objects, which are designed so that once they're created, they're between those channels forever until deleted.
This is much more robust, as there's literally no way for the routes to get out-of-sync: when a route is removed, it is always removed from both sender and receiver vectors, and we don't have to worry about moving channels at all, since we don't keep track of indices any more, but instead use direct pointers.
The amount model will also always be found, since it's kept in the FxRoute: if there's a routing, there is a model.

Also, I incorporated the other fxmixer fix in this branch: when fx channels are moved, if they're still named the original "FX %1" name, they get renamed according to the new index.