Proposal for SynthDef pre and post processors to make custom SynthDefs composable

Some Quarks make their own versions of SynthDef, inheriting from it to extended it. This is usually to create another global variable which will catch the UGens (or some other class), or to edit the graph of ugens. While this works well, if you have two different versions of SynthDef, they cannot be used at the same time because they cannot be composed easily (diamond inheritance).

What do people think about something like the following as an addition to the class library.


SynthDef.addPostFunc({ |synthdef|
   \\ note return value

Synthdef(...).add; // does pre and post, returning the result of calling all postFuncs in order they were added.

These would add the function objects to an FunctionList and evaluate them in, before the synth function is called, and then just before returning, passing the normal synthdef instance to the first post function and chaining their outputs, returning that result.

The actual interface here is not great because you can’t easily revert this, but explains what I’m suggesting clearly.

Perhaps this might be a better interface?

SynthDef.addPrePostProcessor(\foo, {...}, {...});

   [\foo, \othersInExecutionOrder...], 

Anyway, what do you all think about this as an addition to the class library? It is relatively niche and there aren’t many times that one needs to do this, but when it does come up there isn’t an easy solution.

1 Like