Specifications

5.3 Editing 51
code, the message to c reate a sine wave is sent explicitly through a
send
because
$0- inside a mess age box is trea ted in a different way.
SECTION 5.3
Editing
my-tabosc my-tabosc my-tabosc
110 220 330
*~ 0.333
dac~
fig 5.9: Three harmonics
using the table oscillator
abstraction
Now that we have an abstracted table oscillator let’s in-
stantiate a few copies. In Fig. 5.9 there ar e three copies.
Notice that no error messages appear at the console, as
far as Pd is c oncerned each table is now unique. There
is something important to note here though. If you
open one of the abstraction instances and begin to edit
it the changes you make will immediately take effect as
with a subpatch, but they will only affect that instance. Not until you save an
edited abstraction do the changes take place in all instances of the abstraction.
Unlike subpatches, abstractions will not automatically be saved along with their
parent patch and must be saved explicitly. Always be extra careful when editing
abstractions to consider what the effects will be on all patches that use them. As
you begin to build a library of reusable abstractions you may so metimes make
a change for the be nefit of one project that bre aks another. How do you get
around this problem? The answer is to develop a disciplined use of namespac e s,
prefixing each abs traction with something unique until you are sure you have a
finished, general version that can used in all patches and will not change any
more. It is also good practice to write help files fo r your abstractions. A file in
the same directory as an abstraction, with the same name but ending -help.pd
will be displayed when using the object help facility.
SECTION 5.4
Parameters
Making local data and variables is only one of the benefits of abstraction.
A far more powerful property is that an abstraction passes any para meters
given as creation arguments through local variables $1, $2, $3. . . In traditional
programming terms this behaviour is more like a function than a code block.
Each instance of an abstraction can be created with completely different initial
arguments. Let’s see this in action by modifying our table oscillator to take
arguments for initial frequency and waveform. In Fig. 5.10 we see several
interesting changes. Firstly, there are two
float
boxes that have $n parameters.
You can use as many of these as you like and each of them will contain the nth
creation parameter. They are all banged when the abstra c tion is loaded by the
loadbang
. The first sets the initial pitch of the oscillator, though of course this can
still be over-ridden by later messages at the pitch inlet. The second activates one
of three messages via
select
which contain harmonic series of square, sawtooth
and sine waves res pectively.