Macro
(process{clause}+)
Defines an iterative musical process using the same basic syntax as
Lisp's loop macro. The body of a process definition
consists of a series of clauses, each clause begins with a clausal
operator. There are four broad categories of clauses:
with | declares and initializes local process variables |
initially | performs an action before iteration starts |
finally | performs a final action immediately after process stops |
repeat | sets the number of times the process runs |
for | defines a variable over a range of values, stops process when done |
do | evaluates one or more Lisp statements |
each | iterates action clause |
output | outputs an event into the open output stream |
sprout | inserts a new object into the scheduling queue |
wait | process waits a specified amount of time before running again |
ms:output | outputs a foreign entity to a Midishare stream |
pm:output | outputs a foreign entity to a Portmidi stream |
while | evaluates an action if a test is true or stops the process if false |
until | evaluates an action if a test is or stops the process if true |
when | evaluates an action if a test is true |
unless | evaluates an action if a test is false |
if | evaluates one or more "then" or "else" actions based on a test |
Iteration and action clauses are executed in the same order in which they appear in the code but the first action clause must appear after all initialization and iteration clauses. If more than one iteration clause is specified the process terminates as soon as the earliest iteration terminates.
with var [= form] {and var2 [= form2]}*with clause are processed one time only immediately
before process iteration starts.
Each variable declaration in the with clause
can be specified as either:
=. and to separate variables if more than one variable is declared.
Declarations are processed in left to right order
so a = value may reference variables declared to the left.
with a and b = 32 and c = (* (random b) 4)
initially forminitially (print 'initializing!)
finally formdo ... finally (print 'all-done!)
repeat formrepeat 23
for var = form [then form2]then is supplied var is set to form
on the first iteration and to form2 on subsequent iterations.
for k = (now) for p = 60 then (+ p (random 10))
for var [from form] [to | below form] [by form]from sets the starting value ofvar, defaults to 0.to establishes an inclusive ceiling on the iteration and stops
the process once the value has been reached. below sets an exclusive ceiling on the iteration and stops
the process just before the value has been reached.by provides an optional increment for var, defaults to 1.for k below 10 for p from 10 to 100 by 5
for var {in | on} list [by function]in maps var over successive elements in list.on maps var over successive tails of list.by specifies an optional stepping function. Defaults to cdr.for k in '(c4 d4 ef5 fs)
for var over pattern [by length]for k over (pattern heap of keynums c4 d e f g repeat 3)
output object [to io] [at time]to is not specified the default open
output stream is used. Use at to output the current value of
now for objects such
as midi messages that do
not have a method defined for object-time. The Lisp
function output is
available for use inside a do clause definition.
wait secondswait is available
for use inside a do clause definition.
sprout object [at time]at an optional time. If the at time is not specified
the object is inserted at the current time.
The Lisp function sprout is available
for use inside a do clause definition.
do {form}+set var = formeach var {in | from} form [as ...] actionEach supports the same stepping clauses
that for does. The difference between for and each is that the
former defines a process iteration while each
defines an iterative action inside the process. The following
two clause descriptions are equivalent:
each i in lst output ... do (loop for i in lst do (output ...))
ms:output object [to stream]pm:output object [to stream] [at msec] [raw {boolean | length}]while test actionwhile (< (now) end-time) do ...
until test actionuntil (= freq 440) do ...
when test actionunless test actionif test [action {and action}*] [else action {and action}*]else action clauses.
The file intro.cm
contains numerous examples of process descriptions.