[ << Changing defaults ] | [Part superior][Continguts][Índex][ ? ] | [ Notation manual tables >> ] | ||
[ < Substitution function syntax ] | [ Amunt : Using music functions ] | [ Notation manual tables > ] |
5.6.2 Substitution function examples
This section introduces some substitution function examples. These are not intended to be exhaustive, but rather to demonstrate some of the possibilities of simple substitution functions.
In the first example, a function is defined that simplifies setting the padding of a TextScript:
padText = #(define-music-function (padding) (number?) #{ \once \override TextScript.padding = #padding #}) \relative { c''4^"piu mosso" b a b \padText #1.8 c4^"piu mosso" b a b \padText #2.6 c4^"piu mosso" b a b }
In addition to numbers, we can use music expressions such as notes for arguments to music functions:
custosNote = #(define-music-function (note) (ly:music?) #{ \tweak NoteHead.stencil #ly:text-interface::print \tweak NoteHead.text \markup \musicglyph #"custodes.mensural.u0" \tweak Stem.stencil ##f #note #}) \relative { c'4 d e f \custosNote g }
Both of those functions are simple single expressions where only
the last element of a function call or override is missing. For
those particular function definitions, there is a simpler
alternative syntax, namely just writing out the constant part of
the expression and replacing its final missing element with
\etc
:
padText = \once \override TextScript.padding = \etc \relative { c''4^"piu mosso" b a b \padText #1.8 c4^"piu mosso" b a b \padText #2.6 c4^"piu mosso" b a b }
custosNote = \tweak NoteHead.stencil #ly:text-interface::print \tweak NoteHead.text \markup \musicglyph #"custodes.mensural.u0" \tweak Stem.stencil ##f \etc \relative { c'4 d e f \custosNote g }
Substitution functions with multiple arguments can be defined:
tempoPadded = #(define-music-function (padding tempotext) (number? markup?) #{ \once \override Score.MetronomeMark.padding = #padding \tempo \markup { \bold #tempotext } #}) \relative { \tempo \markup { "Low tempo" } c''4 d e f g1 \tempoPadded #4.0 "High tempo" g4 f e d c1 }
[ << Changing defaults ] | [Part superior][Continguts][Índex][ ? ] | [ Notation manual tables >> ] | ||
[ < Substitution function syntax ] | [ Amunt : Using music functions ] | [ Notation manual tables > ] |
Altres idiomes: English, deutsch, español, français, italiano, 日本語.
Quant a la selecció automàtica de la llengua.