Specifications

48 Abstraction
one envelope generator it’s a few simple steps to turn it into a MIDI mono
synthesiser (shown in Fig. 5.3) based on an earlier example by replacing the
osc~
with a
phasor~
and adding a filter controlled by the second envelope in the
range 0 to 2000Hz. Try duplicating the envelope again to add a pitch sweep to
the synthesiser.
10 500
*~
dac~
pd envelope
pd envelope
40 500
trigger bang bang
vcf~ 1 1
*~ 2000
phasor~ 55
notein
mtof
> 0
sel 1
fig 5.3: Simple mono MIDI synth made using two copies of the same envelope subpatch
Deep subpatches
Consider an object giving us the vector magnitude of two numbers. This is the
same as the hypotenuse c of a right angled triangle with opposite and adjacent
sides a and b and has the formula c =
√
a
2
+ b
2
. There is no intrinsic object to
compute this, so let’s make our own subpatch to do the job as an exercise.
3 4
5
pd magnitude
fig 5.4: Vec-
tor magnitude
We begin by creating a new object box and typing pd magnitude
into it. A new blank canvas will immediately open for us to
define the internals. Inside this new canvas create two new object
boxes at the top by typing the word inlet into each. Create
one more object box at the bottom as an outlet. Two input
numbers a and b will come in through these inlets and the result c will go to
the outlet.
inlet inlet
pd squaredpd squared
sqrt
+
outlet
fig 5.5: Subpatch
calculates
√
a
2
+ b
2
When turning a formula into a dataflow patch it sometimes
helps to think in reverse, from the bottom up towards the
top. In words, c is the square root of the sum of two other
terms, the square of a and the s quare of b. Begin by cre ating
a
sqrt
object and connecting it to the outlet. Now cre ate and
connect a
+
object to the inlet of the
sqrt
. All we need to
complete the exa mple is a n object that gives us the square
of a numb e r. We will define our own as a way to show
that subpatches can contain other subpatches. And in fact this can go as deep
as you like. It is one of the principles of abstraction, tha t we can define new