Specifications

52 Abstraction
loadbang
tabosc4~ $0-array1
inlet pitch
sinesum 64 1 0 0.333 0 0.2 0 0.143 0 0.111 0 0.0909
s $0-array1
outlet~
f $1
f $2
sinesum 64 0.5 0.25 0.125 0.062 0.031 0.015 0.007
sinesum 64 1
sel 0 1 2
$0-array1
fig 5.10: Table oscillator abstraction with initialised frequency and shape.
SECTION 5.5
Defaults and states
A quick word about default par ameters. Try creating some instances of
the abstraction in Fig. 5.10 (shown as my-tabsosc2 in Fig. 5.11)
2
. Give one
a first parameter of 100Hz but no second parameter. What happens is useful,
the missing parameter is taken to be zero. That’s because
float
defaults to
zero for an undefined argument. Tha t’s fine most of the time, because you can
arrange for a zero to produce the behaviour you want. But, what happens if
you create the object with no parameters at all? The frequency is set to 0Hz of
course, which is probably useful behaviour, but let’s say we wanted to have the
oscillator start at 440Hz when the pitch is unspecified. You can do this with
sel 0
so that zero value floats trigger a message with the desired default. Be
careful choosing default behaviours for abstractions, they are one of the most
common causes of problems later when the defaults that s e e me d good in one case
are wrong in another. Ano ther important point pertains to initial parameters
of GUI components, which will be clearer in just a moment as we consider
abstractions with built in interfaces. Any object that persistently maintains
state (keeps its value between saves and loads) will be the sa me for all instances
of the abstrac tion loaded. It can only have one s et of values (those saved in the
abstraction file). In other words it is the abstraction class that ho lds state, not
the object instances. This is a nnoying when you have several instances of the
same abstraction in a patch and want them to individually maintain pers istent
state. To do this you need a state saving wrapper like
memento
or
sssad
, but that
is a bit beyond the scope of this textbook.
2
The graphs with connections to them shown here, and elsewhere in the book, are ab-
stractions that contain everything necsessary to display a small time or spectrum graph from
signals received at an i nlet. This is done to save space by not showing this in every diagram.