Reusing code in multiple SynthDefs #496
-
I'm in the process of implementing phase modulation operators based on sclang examples provided by someone in the SuperCollider forums. Here's the code, for reference: Without feedback:
With feedback:
My question relates to the best way to do something like the I've already made version of the above in Supriya. Here they are. Without feedback:
With feedback:
I want to create some algorithms (operators in specific arrangements) using the above code. I previously did this for frequency modulation operators by making one SynthDef per algorithm. That meant creating 4 operators per SynthDef rather than having a generic SynthDef for an operator and using that over and over again. This resulted in a lot of duplicate code, but it didn't seem like there was a better way to do it. However, now I'm wondering if there's a way to encapsulate this block of code, for example:
so I can reuse it. Other wise I'll need to copy and paste that code block three to four times per SynthDef. Would creating a pseudo-UGen be the best way? If so, is there a place in the Supriya repo I could look for an example of how to do that? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
You have
There are a handful of pseudo ugens adapted from sclang. You can find them in the codebase by searching for
Personally, I think these are awkward and tend to confuse people because they look like UGens from a user-facing perspective, but are just function calls. Writing
^ You can use a function like that inside a |
Beta Was this translation helpful? Give feedback.
-
This is kind of advanced, but there's a supriya/supriya/ugens/factories.py Lines 363 to 381 in 1187c91 You can do similar if you want to really set up a library of composable synthdef-building functions. |
Beta Was this translation helpful? Give feedback.
You have
threetwo and a half options:UGenOperable
@synthdef
and start usingSynthDefBuilder
so you can re-use it in function calls (more advanced)There are a handful of pseudo ugens adapted from sclang. You can find them in the codebase by searching for
PseudoUGen
:supriya/supriya/ugens/filters.py
Line 99 in 1187c91
supriya/supriya/ugens/dynamics.py
Line 43 in 1187c91
supriya/supriya/ugens/lines.py
Line 137 in 1187c91
Personally, I think these are awkward and tend to confuse peo…