Specifications

47
CHAPTER 5
Abstraction
SECTION 5.1
Subpatches
Any patch canvas can contain subpatches which have their own canvas but
reside within the same file as the main patch, called the parent. They have inlets
and outlets, which you define, so they behave very much like regular objects.
When you save a canvas all s ubpatches that belong to it are automatically saved.
A subpatch is just a nea t way to hide code, it does not automatically offer the
benefit of local scope
1
.
100 500
osc~ 440
*~
dac~
pd envelope
fig 5.1: Using an envelope
subpatch
Any object that you create with a name beginning
pd will be a s ubpatch. If we create a subpatch called
pd envelope
as seen in Fig. 5.1 a new canvas will appear
and we ca n make
inlet
and
outlet
objects inside it as
shown in Fig. 5.2. These appear as connections on
the outside of the subpatch box in the same order
they appea r left to right inside the subpatch. I’ve
given extra (optional) name parameters to the sub-
patch inlets and outlets. These are unnecessary, but when you have a subpatch
with several inlets or outlets it’s good to give them names to keep track of things
and remind yourself of their function.
inlet attack inlet decay
line~
1 $1 0 $1
inlet trigger
t b b
f f
del
outlet~ envelope
fig 5.2: Inside the envelope sub-
patch
To use
pd envelope
we supply a bang on the firs t
inlet to trigger it, and two values for attack
and decay. In Fig. 5.1 it modulates the output
of an oscillator running at 440Hz before the
signal is sent to
dac~
. The envelope has a
trigger inlet for a messa ge to bang two floats
stored from the remaining inlets, one for the
attack time in milliseconds and one for the
decay time in milliseconds. The attack time
also sets the period of a delay so that the decay
portion of the envelope is not triggered until the attack part has finished. These
values are substituted into the time parameter of a 2 element list for
line~
.
Copying subpatches
So long a s we haven’t used any objects requiring unique names any subpatch
can be copied. Select
pd envelope
and hit CTRL+D to duplicate it. Having made
1
As an advanced topic subpatches can be used as target name for dynamic patching com-
mands or to hold datastructures.