r Statement (Repeat Statement)
Prev | Score Statements and GEN Routines | Next

## r Statement (Repeat Statement)

r — Starts a repeated section.

## Description

Starts a repeated section, which lasts until the next s, r or e statement.

## Syntax

    r p1 p2

## Initialization

p1 -- Number of times to repeat the section.

p2 -- Macro(name) to advance with each repetition (optional).

## Performance

In order that the sections may be more flexible than simple editing, the macro named p2 is given the value of 1 for the first time through the section, 2 for the second, and 3 for the third. This can be used to change p-field parameters, or ignored.

| Warning
Because of serious problems of interaction with macro expansion, sections must start and end in the same file, and not in a macro.

## Examples

Here is an example of the r statement. It uses the file r.csd.

Example 1258. Example of the r statement.

    <CsoundSynthesizer>
    <CsOptions>
    ; Select audio/midi flags here according to platform
    ; Audio out   Audio in
    -odac           -iadc    ;;;RT audio I/O
    ; For Non-realtime ouput leave only the line below:
    ; -o r.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    ; Initialize the global variables.
    sr = 44100
    kr = 4410
    ksmps = 10
    nchnls = 1

    ; Instrument #1.
    instr 1
      ; The score's p4 parameter has the number of repeats.
      kreps = p4
      ; The score's p5 parameter has our note's frequency.
      kcps = p5

      ; Print the number of repeats.
      printks "Repeated %i time(s).\\n", 1, kreps

      ; Generate a nice beep.
      a1 oscil 20000, kcps, 1
      out a1
    endin

    </CsInstruments>
    <CsScore>

    ; Table #1, a sine wave.
    f 1 0 16384 10 1

    ; We'll repeat this section 6 times. Each time it
    ; is repeated, its macro REPS_MACRO is incremented.
    r6 REPS_MACRO

    ; Play Instrument #1.
    ; p4 = the r statement's macro, REPS_MACRO.
    ; p5 = the frequency in cycles per second.
    i 1 00.10 00.10 $REPS_MACRO 1760
    i 1 00.30 00.10 $REPS_MACRO 880
    i 1 00.50 00.10 $REPS_MACRO 440
    i 1 00.70 00.10 $REPS_MACRO 220

    ; Marks the end of the section.
    s

    e

    </CsScore>
    </CsoundSynthesizer>

## Credits

Author: John ffitch
University of Bath/Codemist Ltd.
Bath, UK
April, 1998

New in Csound version 3.48

Example written by Kevin Conder

Prev | Up | Next
q Statement | Home | s Statement