Overview of music functions - GNU LilyPond
Description: GNU LilyPond

Next: Simple substitution functions, Up: Music functions

#### 12.1.1 Overview of music functions

Making a function which substitutes a variable into LilyPond code is easy. The general form of these functions is

    function =
    #(define-music-function (parser location var1 var2... )
                            (var1-type? var2-type?...)
      #{
        ...music...
      #})

where

argi | ith variable
argi-type? | type of variable
...music... | normal LilyPond input, using variables as `#$var1`.

There following input types may be used as variables in a music function. This list is not exhaustive; see other documentation specifically about Scheme for more variable types.

Input type | argi-type? notation
--- | ---
Integer | `integer?`
Float (decimal number) | `number?`
Text string | `string?`
Markup | `markup?`
Music expression | `ly:music?`
A pair of variables | `pair?`

The `parser` and `location` argument are mandatory, and are used in some advanced situations. The `parser` argument is used to access to the value of another LilyPond variable. The `location` argument is used to set the “origin” of the music expression that is built by the music function, so that in case of a syntax error LilyPond can tell the user an appropriate place to look in the input file.

Next: Simple substitution functions, Up: Music functions

This page is for LilyPond-2.10.33 (stable-branch).