Specifications

3.7 Common idioms 37
to y = 2x
2
1 for the range 1.0 to +1.0 and fills a 256 step table with the
result. As s oon as the bang button is pressed a co unter is reset to zero and then
until
begins sending out bang s. These cause the counter to rapidly increment
until
select
matches 256 whereupon a bang is sent to the right inlet of
until
stopping the process. All this will happen in a fra ction of a millisecond. Mean-
while we use the counter output to calculate a Chebyshev curve and put it into
the table.
256
min 1
until
fig 3.33: for
256
A safer way to use
until
is shown in Fig. 3.33. If you k now in
advance that you want to perfor m a fixed number of operations
then use it like a for loop. In this case you pass a non-zero
float to the left inlet. There is no terminating condition, it
stops when the specified number o f bangs has been sent, 25 6
bangs in the example shown.
Message complement and inverse
swap 1
-
0.25
0.75
swap 1
0.5
2
/
fig 3.34: Message re-
ciprocal and inverse
Here is how we obtain the number that is 1x for any x.
The complement of x is use ful when you want to balance
two numbers so they add up to a constant value, such as
in panning. The
swap
object exchanges its inlet values,
or any left inlet value with its first argument. Therefore,
what happens with the left example of Fig. 3.34 is the
-
calculates 1 x, which for an input of 0.25 gives 0.75.
Similarly the inverse o f a float message 1/x can be ca lculated by replacing the
-
with a
/
.
Random selection
metro 500
random 4
select 0 1 2 3
fig 3.35:
Random
select.
To choose one of several events at random a combination of
random
and
select
will generate a bang mess age on the select outlet corre-
sp onding to one of its arguments. With an initial ar gument of 4
random
produces a range of 4 random integer numbers sta rting at 0,
so we use
select 0 1 2 3
to select amongst them. Each has an equal
probability, so every outlet will be triggered 25% of the time on
avera ge.
Weighted random selection
metro 500
moses 10
random 100
moses 50
fig 3.36:
Weighted
random select.
A simple way to get a bunch of events with a certain proba-
bility distribution is to generate uniformly dis tributed numbers
and stre am them with
moses
. For example
moses 10
sends integers
greater tha n 9.0 to its right outlet. A c ascade of
moses
objects
will distribute them in a ratio over the combined outlets when
the sum of all ratios eq uals the range of random numbers. The
outlets of
moses 10
distribute the numbers in the ratio 1 : 9. When
the right outlet is further split by
moses 50
as in Fig. 3.36 numbers
in the range 0.0 to 100.0 are split in the ratio 10 : 40 : 50, and