[PD] Good programming practice

Peter Todd peter_todd82 at yahoo.co.uk
Fri Oct 22 01:26:18 CEST 2004


I had meant to mention this earlier, and even got as far as typing, but 
didn't for some unknown reason.  Maybe the feeling that all this might 
change if I had OSC working.  OSCroute sounds pretty useful.  Anyway, the 
new talk of GripD and $0 has incited me again.

Personally, I use $1 for a kind of address space for abstractions, rather 
than making things private.  For example, a patch with two similar synths , 
which uses two similar envelopes, would be structured so that each synth and 
envelope was given a friendly name (maybe 'lead' or 'bass' or whatever) as 
the first argument.  Synth-wide parameters use $1.parameterName, while the 
envelopes have names $1.ampEnv and $1.filterEnv.  Similarly, within the 
envelope abstraction, $1.parameterName is used for sends and recieves.  So, 
the sends and recieves for the attack [$1.A] of the lead synth's filter 
envelope become [lead.filterEnv.A], and so on.  If access to the parameters 
is desired from anywhere else, there are no particular dirty tricks 
involved, and nothing changes when you reopen the patch.  Of course, you can 
still use $0 as part of the name if you want to make it private at a high 
level.  There isn't too much risk of accidentally conflicting send, receive, 
values or whatever, but names could get a bit long - so I try to keep them 
short.

In order to make GOP patches work with polyphony, I've decided to use 
separate abstractions for the interface and the actual processing, and 
anything which is made polyphonic is given another argument for voice 
number.  Then messages destined for a particular voice are prepended with 
the voice number, and [route $2] is used to filter out the appropriate 
messages.  [throw~ $1.channel] is used at the 'instrument level'.  This 
allows voices and patches to be built dynamically quite easily.

Nothing terribly revolutionary, but perhaps it could be RRADical, none the 
less (did I mention OSC isn't working for me).  I'm sure there are some 
related points that aren't ocurring to me now, and things outside the 
midi-polysynth box.  I'll stop now before I ramble too much.

Hope this is useful,

Peter 





More information about the Pd-list mailing list