A nice feature of the Pure Data programming language is the possibility of using abstractions and sub-patches to clean up a complex patch and break it down to several entities which have a reason to exist on their own.
An abstraction is a Pd patch (like “anything.pd”) that is used as an object in another Pd patch.
Here’s an example. I first created a patch called “amplify.pd” that looks like this :
I saved this patch in a location where Pd can get objects from (read this post to learn how to setup the default “Path…” in Pd). I then created another patch in which I inserted i new object called [amplify]. Here’s the result :
If you right-click on the [amplify] object, the “amplify.pd” patch pops up. [amplify] is an abstraction of the “amplify.pd” patch.
Abstractions are particularly useful if you think that you will need to replicate a portion of your patch many times. For instance, if you have 10 effects in your multi-effects patch for your guitar, you might want to control the volume of each effect individually. You can create a patch that does just that (“volume.pd”), and use the abstraction [volume] 10 times in your main patch.
Pure Data also allows the user to make sub-patches in the main patch. To create a sub-patch called, say, “synthesis”, create an object and type “pd synthesis” inside. A blank Pd window will pop up in which you can put whatever you want there to be in your sub-patch. Once you close the sub-patch you’ll see that it is represented by a [pd synthesis] object in your main patch.
Sub-patches aren’t as flexible as abstraction if you want to duplicate them.
Both abstractions and sub-patches can be used as a GUI object. To do so, right-click in your abstraction or sub-patch and choose “Properties”. A window should pop up. Click “Graph on parent”, and close the window. A red rectangle has now appeared (see image below). This is the area that will be graphed as GUI on the “parent” patch. Any GUI object that you put in this area (slider, number, bang, toggle…) will appear in the main patch.
Inside the sub-patch :
And the parent graph with the sub-patch-turned-GUI :
You can download the patch here.
Finally, please note that abstractions accept creation arguments. This is a very useful feature, and it’s well documented in Pd’s help, so I encourage you to read it (“Help -> Browser… -> Pure Data -> 2.Control examples -> 14.dollarsigns.pd”).