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" b a b
\padText #2.6
c4^"piu mosso" b a b
}
|
数値のほかに、音符などの音楽表記を音楽関数への引数にすることができます:
| 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 }
|
上に挙げた例の両方では、関数やオーバライドにおける最後の引数が空きになっているだけの、単一の式の形をしています。このような特別な場合では、よりシンプルな関数の定義方法があり、一定の部分はそのまま書き出し、引数となる最後の部分を \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 }
|
複数の引数をとる置換関数を定義することもできます:
| 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
}
|
他の言語: English, català, deutsch, español, français, italiano
About automatic language selection.