5.6.2 置換関数の例

このセクションでは、置換関数の例をいくつか紹介します。高度なことはしていませんが、シンプルな置換関数を実現する方法を示しています。

最初の例では、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" d e f
  \padText #2.6
  c4^"piu mosso" fis a g
}

[image of music]

数値のほかに、音符などの音楽表記を音楽関数への引数にすることができます:

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 }

[image of music]

複数の引数をとる置換関数を定義することもできます:

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
}

[image of music]


他の言語: English, català, deutsch, español, français, italiano
About automatic language selection.

LilyPond — 記譜法リファレンス v2.21.0 (開発版).