Streams of Events and Iteration

Often it is necessary to repeat some simple event iteratively in order to form a stream of similar events. One example of this might be repeatedly striking an object at short (random) intervals in order to create a dense granular texture. This section describes a common technique for implementing such streams of events 2.

In order to describe an iterated event we will use the technique of nested control structures described in the previous section, but in a particular way, which allows an event to reschedule itself once its time is up. The following example script schedules a series of events to occur at one second intervals. Each individual event is trivial in nature, simply printing a message to the shell window showing the time at which it occurs (performance-time, not real-time).

    Audio rate: 44100;

    Param eventStart=0.0, eventDur=0.01, interval=1.0;

    Init:
        ...

    Score 10 secs:
        At eventStart for eventDur:
            At start:
                Print "Time=", Time, newline;
                ...
            At end:
                eventStart += interval;
                ...
            ...
        ...

The first thing to note about this script is that it contains a hierarchy of nested control structures. The outermost Score control structure contains a single At..for structure, which in turn contains two further At structures. The rest of the script is quite straightforward to understand. The parameters eventStart and eventDur are used to define the start time and duration of each event and the parameter interval is used to define the interval between successive events. The key element is the use of the At end: control structure. Every time the event occurs the body of the At end: structure is executed just once at the very end of the event, and when it is a new start time is calculated for the next event.

The script produces the following output:

    Sample rate=44100 KHz
    Score duration=10 seconds
    Time=0
    Time=1
    Time=2
    Time=3
    Time=4
    Time=5
    Time=6
    Time=7
    Time=8
    Time=9
    Time=10

Of course the time interval between events does not have to be fixed. The value by which the eventStart parameter is incremented can be derived from an arbitrary mathematical expression (see section * for details of expression syntax). Since expressions can include numerical values derived from physical attributes read off the various instruments and devices, this technique opens the way for quite complex self-evolving events to be described. This is one of Tao's strengths: any physical attribute, such as the velocity of a point on an instrument or the current height of a hammer device can potentially be used as input to an algorithm which is playing the very same instruments and devices.


©1999,2000 Mark Pearson m.pearson@ukonline.co.uk April 30, 2000