Nested control structures and the special variables start and end

The way in which compound events are describedin a score is by nesting control structures representing low-level events within higher level ones. The following (trivial) script illustrates this technique, at the same time as introducing two special variables called start and end, which play a central role in describing compound events:

    Audio rate: 44100;
    
    Init:
        ...
    
    Score 2 secs:
        From 0 secs to 1 secs:
            At start:
                Print "For interval 0-1 seconds start=", Time, newline;
                ...
    
            At end:
                Print "For interval 0-1 seconds end=", Time, newline;
                ...
            ...
    
        From 1 secs to 2 secs:
            At start:
                Print "For interval 1-2 seconds start=", Time, newline;
                ...
    
            At end:
                Print "For interval 1-2 seconds end=", Time, newline;
                ...
            ...
        ...

When invoked this script produces the following output:

    Sample rate=44100 Hz
    Score duration=2 seconds
    For interval 0-1 seconds start=0
    For interval 0-1 seconds end=1
    For interval 1-2 seconds start=1
    For interval 1-2 seconds end=2

The four Print statements in this example print out the values of the start and end variables at various points during the performance. Note that the values change depending on where the variables are actually accessed. This is due to the concept of scope. Each control structure which defines a time interval during the performance - i.e. each instance of At..for, From..to, Before or After - has its own scope. Within that scope the values of start and end are set to refer to the start and end times of that particular time interval. This is useful for defining sub-events in terms of the higher-level event in which they are enclosed.

Another example is given below to clarify this point:

    Audio rate: 44100;
    
    Init:
        ...
    
    Score 5 secs:
        At start:
            Print "For score, start=", Time, newline;
            ...
        At end:
            Print "For score, end=", Time, newline;
            ...

        From 1 secs to 4 secs:
            At start:
                Print "For interval 1-4 seconds, start=", Time, newline;
                ...
            At end:
                Print "For interval 1-4 seconds, end=", Time, newline;
                ...
            ...
        ...

In this example the first pair of At structures are enclosed within the scope of the top-level Score structure, whilst the second pair of At structures are enclosed or nested within the From..to structure. As you can see from the output from this script, the values of start and end are altered accordingly depending on their scope:

    Sample rate=44100 KHz
    Score duration=5 seconds
    For score, start=0
    For interval 1-4 seconds, start=1
    For interval 1-4 seconds, end=4
    For score, end=5

Note also that it doesn't matter in which textual order events are given in a score, the only thing which matters is the instant in time, or time interval defined by the values in the head of the control structure.

The ability to nest events and define the start and end times of a sub-event in relative rather than absolute terms provides a rudimentary mechanism for describing compound events 1.


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