Specifications

24 Using Pure Data
1 0
metro 1000
fig 3.6: Metronome
The left inlet toggles the metronome on and off when it
receives a 1 or 0, while the right one allows you to se t
the period. Periods that are fractions of a millisecond are
allowed. The
metro
emits a bang as soon as it is switched
on and the following bang occurs after the time period.
In Fig. 3.6 the time period is 1000ms, (equal to 1 second).
The bang button here is used as an indicator. As soon as you click the message
box to se nd 1 to
metro
it be gins se nding o ut bangs which make the bang button
flash once per second, until you send a 0 message to turn it off.
A counter timebase
We could use the metronome to trigger a so und repeatedly, like a steady drum
beat, but on their own a series of bang events aren’t much use. Although
they are separated in time we cannot keep track of time this way because bang
messages contain no information.
metro 1000
500 250
f 0 + 1
24
fig 3.7: Counter
In Fig. 3.7 we see the metro nome again. This time the
messages to start and stop it have been conveniently re-
placed by a toggle switch. I have also added two new
messages which can change the period and thus make
the metr onome fas ter or slower. The interesting part is
just below the metronome. A float box receives bang
messages on its hot inlet. Its initial value is 0 so upon
receiving the first bang message it outputs a float number 0 which the number
box then displays. Were it not for the
+ 1
object the patch would c ontinue
outputting 0 once per beat forever. However, look closely at the wiring of these
two objects,
f
and
+ 1
are connected to form an incrementor or counter.
Each time
f
recieves a bang it ouputs the number cur rently stored to
+ 1
which adds 1 to it. This is fed back into the cold inlet of
f
which updates its
value, now 1. The next time a bang arrives 1 is output, which goes r ound again,
through
+ 1
and becomes 2. This repeats as long as bang messages arrive, each
time the output increases by 1. If you start the metrono me in Fig. 3 .7 you will
see the number box slowly counting up, once per second. Clicking the message
boxes to change the period will make it count up faster with a 500ms delay
between beats (twice per second), or still faster at 4 times per second (250ms
period).
Time objects
Three r elated objects help us manipulate time in the message domain.
timer
accurately measures the interval between receiving two bang messages, the first
on its left inlet and the second on its right inlet. It is shown on the left of
Fig. 3 .8.