$NAME
Prev | Orchestra Opcodes and Operators | Next

## $NAME

$NAME — Calls a defined macro.

## Description

Macros are textual replacements which are made in the orchestra as it is being read. The orchestra macro system in Csound is a very simple one, and uses the characters # and $ to define and call macros. This can save typing, and can lead to a coherent structure and consistent style. This is similar to, but independent of, the macro system in the score language.

$NAME $NAME. -- calls a defined macro. To use a macro, the name is used following a $ character. The name is terminated by the first character which is neither a letter nor a number. If it is necessary for the name to be followed by a letter or number, a period, which will be ignored, can be used to terminate the name. The string, $NAME., is replaced by the replacement text from the definition. The replacement text can also include macro calls.

## Syntax

    $NAME

## Initialization

# replacement text # -- The replacement text is any character string (not containing a #) and can extend over multiple lines. The replacement text is enclosed within the # characters, which ensure that additional characters are not inadvertently captured.

## Performance

Some care is needed with textual replacement macros, as they can sometimes do strange things. They take no notice of any meaning, so spaces are significant. This is why, unlike the C programming language, the definition has the replacement text surrounded by # characters. Used carefully, this simple macro system is a powerful concept, but it can be abused.

## Examples

Here is an example of the calling a macro. It uses the file define.csd.

Example 15. An example of the calling a macro.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

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

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

    ; Define the macros.
    #define VOLUME #5000#
    #define FREQ #440#
    #define TABLE #1#

    ; Instrument #1
    instr 1
      ; Use the macros.
      ; This will be expanded to "a1 oscil 5000, 440, 1".
      a1 oscil $VOLUME, $FREQ, $TABLE

      ; Send it to the output.
      out a1
    endin

    </CsInstruments>
    <CsScore>

    ; Define Table #1 with an ordinary sine wave.
    f 1 0 32768 10 1

    ; Play Instrument #1 for two seconds.
    i 1 0 2
    e

    </CsScore>
    </CsoundSynthesizer>

Its output should include lines like this:

    Macro definition for VOLUME
    Macro definition for CPS
    Macro definition for TABLE

Here is an example of the calling a macro with arguments. It uses the file define_args.csd.

Example 16. An example of the calling a macro with arguments.

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

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

    ; Define the oscillator macro.
    #define OSCMACRO(VOLUME'FREQ'TABLE) #oscil $VOLUME, $FREQ, $TABLE#

    ; Instrument #1
    instr 1
      ; Use the oscillator macro.
      ; This will be expanded to "a1 oscil 5000, 440, 1".
      a1 $OSCMACRO(5000'440'1)

      ; Send it to the output.
      out a1
    endin

    </CsInstruments>
    <CsScore>

    ; Define Table #1 with an ordinary sine wave.
    f 1 0 32768 10 1

    ; Play Instrument #1 for two seconds.
    i 1 0 2
    e

    </CsScore>
    </CsoundSynthesizer>

Its output should include a line like this:

    Macro definition for OSCMACRO

## See also

Orchestra Macros

## Credits

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

Examples written by Kevin Conder.

New in Csound version 3.48

Prev | Up | Next
#ifndef | Home | %