Specifications

3.4 List objects and operations 29
foo
bar
2
1
r packed
unpack s s f f
fig 3.17: List unpacking
The
unpack s s f f
will expect two symbols and two
floats and send them to its four outlets. Items are
packed and unpacked in the sequence given in the
list, but in right to left order. That means the floats
from
unpack s s f f
will appear first, starting with the
rightmost one, then the two sy mbols ending on the
leftmost one. Of course this happens so quickly you
cannot se e the ordering, but it makes sense to happen this way so that if you are
unpacking data, changing it and re-packing into a list everything occurs in the
right order. Note that the types of data in the list must match the arguments
of each object. Unless you use the a (any) type Pd will complain if you try to
pack or unpack a mismatched type.
Substitutions
$1
5
5 6 7
$3 $1 $2
pack 5 10 15
unpack f f f
15 5 10
fig 3.18: Dollar substitu-
tion.
A message box can also act as a template. When
an item in a message box is written $1 it behaves
as an empty slot that assumes the value of the first
element of a given list. Each of the dollar arguments
$1, $2 and so on, ar e replaced by the co rrespond-
ing item in the input list. The message box then
sends the new mess age with any slots filled in. List
elements can be substituted in multiple positions as
seen in Fig. 3.18. The list {5 10 15 } becomes {15 5 10 } when put through
the substitution
$3 $1 $2
.
Persistence
You will often want to set up a patch so it’s in a certain state when loaded.
It’s possible to tell most GUI objects to output the la st value they had when
the patch was saved. You can do this by setting the init checkbox in the
properties panel. But what if the data you want to keep comes from another
source, like an external MIDI fa der board? A use ful object is
loadbang
which
generates a bang message as soon as the patch loads.
4 6 8
set $1 $2 $3
loadbang
pd synthesiser
t a a
4 6 8
fig 3.19: Persistence using
messages
You can use this in combination with a message
box to initialise some values. The contents o f message
boxes are saved and loaded with the patch. When you
need to stop working on a project but have it lo ad the
last state next time around then list data can be saved
in the patch with a message box by using the special
set prefix. If a message box receives a list prefixed by
set it will be filled with the list, but not immediately
ouput it. The arrangement in Fig. 3.19 is used to keep
a 3 element list for pd synthesiser in a message box that will be saved with
the patch, then g enerate it to initialise the synthesiser again when the patch is
reloaded.