[sdiy] OT (but very synthy): C question

Tom Wiltshire tom at electricdruid.net
Tue Mar 29 19:15:22 CEST 2011


On 29 Mar 2011, at 16:32, Olivier Gillet wrote:

>> and then the big question is why are we processing
>> midi and LFO in the MIDI header?
> 
> Tom has to answer this one!

OK, I'll have a go. Tim also said:

> My comment is midi functions shouldn't contain pointers or
> structures for LFOs, VCOs etc. MIDI functions should receive a pointer
> to the data to be sent or return data received.


I don't think it's that simple (but I've been wrong before). If you're handling MIDI input, it needs to do something. The problem is not so much the MIDI serial comms handling, but rather the MIDI message handlers. These need to be called by the MIDI parsing code, and then they need to call other bits of code to do stuff. In my case, to call routines to set LFO parameters - and, no, I'm not setting LFO parameters directly, I'm sticking with an OOPish style and using an API.
I can only really see two options; either the MIDI message handlers return something to tell us which function to call and what parameter to use, or we pass a reference to the LFO down to the MIDI message handler so it can do it itself. I chose the second option.

Tim also suggested that if you finish up with the circular dependencies, you should be looking at moving the offending code up a level. Whilst that would work, I agree with Olivier that everything that deals with MIDI should be in MIDI.h. Otherwise what's the point? I could just stuff the whole lot in some hideous great long file and solve all my dependency problems (excepting "alcohol" and "tobacco"!) in one fell swoop.

T.




More information about the Synth-diy mailing list