Next: Manipulating music expressions, Previous: Internal music representation, Up: Programmer interfaces for input
The syntax of composite music expressions, like \repeat
,
\transpose
, and \context
follows the general form of
\keyword
non-music-arguments music-arguments
Such syntax can also be defined as user code. To do this, it is
necessary to create a music function. This is a specially marked
Scheme function. For example, the music function \applymusic
applies
a user-defined function to a music expression. Its syntax is
\applymusic #func music
A music function is created with ly:make-music-function
,
(ly:make-music-function
\applymusic
takes a Scheme function and a Music expression as
arguments. This is encoded in its parameter list,
(list procedure? ly:music?)
The function itself takes another argument, an Input location
object. That object is used to provide error messages with file names
and line numbers. The definition is the second argument of
ly:make-music-function
. The body simply calls the function
(lambda (where func music) (func music))
The above Scheme code only defines the functionality. The tag
\applymusic
is selected by defining
applymusic = #(ly:make-music-function (list procedure? ly:music?) (lambda (parser location func music) (func music)))
A def-music-function
macro is introduced on top of
ly:make-music-function
to ease the definition of music
functions:
applymusic = #(def-music-function (parser location func music) (procedure? ly:music?) (func music))
Examples of the use of \applymusic
are in the next section.
ly/music-functions-init.ly.
This page is for LilyPond-2.5.11 (development-branch).