Looping Score Sections

Music often contains phrases that repeat. Having to write out all of the score events for a repeated section can be tedious and error-prone, even if you use the copy/paste commands in your text editor. Csound defines a couple of different score statements with which sections can be repeated. The repetitions don’t have to be identical; there are ways to introduce variations.

The r-statement

The r-statement is simple to use but has some limitations. The r-statement takes two arguments. The first is an integer that defines the number of repetitions that will be played. The second is in the form of text and defines a macro. The value of the macro will be incremented each time the loop repeats: It will be 1 on the first repetition, 2 on the second repetition, and so on.

The macro can be used in calculations of the values of p-fields, by enclosing the calculations in square brackets. The syntax for using a loop macro is the same as for any other Csound score macro: When the macro is referenced in the code, it is preceded by a dollar sign.

The repeating section that begins with an r-statement ends when an s-statement or e-statement is encountered.

Here is an example. In this example, p5 is being sent to one of the cpspch family of opcodes. The macro is named FERD. It is being used both to increase the pitches of the three notes by a chromatic half-step on each repetition and to increase the tempo on each repetition. The tempo will be 110 bpm the first time through the loop, 140 bpm the second time, and so on.


  r 7 FERD
  t 0 [80 + 30 * $FERD]

  i1 0 1 0.4 [3.0 + 0.01 * $FERD]
  i1 + . . [3.03 + 0.01 * $FERD]
  i1 + 2 . [3.06 + 0.01 * $FERD]
  s

The main limitation of the r-statement is that only one section of a Csound score can be running at any given time. A new section can begin only after the preceding section has ended. This fact makes it difficult (impossible, basically) to use r-statement loops in music where the loop is only one element in a polyphonic texture. It also has consequences if the instrument playing the last note in the loop has one or more envelopes defined with release segments: The loop can’t begin its next iteration until the envelope release is complete, which will likely dislocate the rhythm.

The { and } Statements

Considerably more flexibility is provided by the {-statement and }-statement, but the syntax is not quite as simple as with the r-statement. The braces enclose a repeating loop. Like the r-statement, the {-statement has two parameters—an integer for the number of repetitions desired and a text macro that can be used to vary the repetitions.

Unlike the r-statement, the macro defined by the {-statement begins with a value of 0. It is incremented with each repetition, so with n repetitions, during the last repetition it has a value of n1.

The tricky bit about using this type of loop is that the p2 values of events between the { and } lines are not automatically advanced. It’s up to you to advance them manually, using the macro. If you fail to do this, all of the repetitions of the loop will play at once!

This type of loop can run concurrently with other events in the score. Here is an example, similar to the previous one, in which two {} loops of different lengths run at the same time:


  #define LOOPLEN1 #4#
  { 5 FERD
  i1  [0 + $LOOPLEN1 * $FERD] 1 0.4 [3.0 + 0.01 * $FERD]
  i1  [1 + $LOOPLEN1 * $FERD].. [3.03 + 0.01 * $FERD]
  i1  [2 + $LOOPLEN1 * $FERD] 2.3. [3.06 + 0.01 * $FERD]
  }

  #define LOOPLEN2 #5#
  { 4 WIMP
  i1 [0 + $LOOPLEN2 * $WIMP] 3 0.3 2.0
  i1 [3 + $LOOPLEN2 * $WIMP] 0.5
  i1 [3.5 + $LOOPLEN2 * $WIMP].
  i1 [4 + $LOOPLEN2 * $WIMP] 1.1 0.3 2.03
  }

Notice the handling of p2. The rhythm within each loop is defined by the constants (0, 1, and 2 in the first loop; 0, 3, 3.5, and 4 in the second). These values have to be adjusted using the loop macros (FERD and WIMP) and the desired length of each loop.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.104.153