我编译了一本大型的歌曲书,为此我希望有很多本地的函数定义,最终会在\include
d文件中,但这没有区别.为此,我需要在\score{ ... }
范围内定义函数.但是,LilyPond一直在抛出错误.
非工作的例子:
\version "2.17.26" \book { \header { title = "This is a book" } \score { xyz = { a' b' c'' } abc = #(define-music-function ( parser location musicnotes ) ( ly:music? ) #{ c' $musicnotes e' #} ) { \abc { d' } f' \xyz } \header { piece = "First piece" opus = "op. 1024" } } \score { xyz = { a' a' a' } abc = #(define-music-function ( parser location musicnotes ) ( ly:music? ) #{ e' $musicnotes c' #} ) { \abc { d' } f' \xyz } \header { piece = "Second piece" opus = "op. 1025" } } }
抛出错误:
test.ly:10:17: error: unrecognized string, not in text script or \lyricmode xyz = { a' b' c'' }
但是,下面的工作,我必须赋予函数唯一的名称,这是不赞成的.
\version "2.17.26" xyz = { a' b' c'' } abc = #(define-music-function ( parser location musicnotes ) ( ly:music? ) #{ c' $musicnotes e' #} ) xxyz = { a' a' a' } aabc = #(define-music-function ( parser location musicnotes ) ( ly:music? ) #{ e' $musicnotes c' #} ) \book { \header { title = "This is a book" } \score { { \abc { d' } f' \xyz } \header { piece = "First piece" opus = "op. 1024" } } \score { { \aabc { d' } f' \xxyz } \header { piece = "Second piece" opus = "op. 1025" } } }
Owen S... 6
不幸的是,不可能在分数中坚持分配.您只能在以下位置放置作业:
顶级,
内\display
,\header
和\midi
块
LilyPond语法非常清楚,即使手册的其余部分对它有点回避.(查看http://lilypond.org/doc/v2.17/Documentation/contributor/lilypond-grammar,查找assignment
规则的使用位置).
假设您的分配不适合上面列出的块(在本例中肯定是这种情况),并且假设您不想做一些奇特的事情,比如去定义您自己的Scheme模块并弄清楚如何在你的LilyPond文件,你有两个选择:
定义xyz
和abc
,然后定义的音乐,将进入第一次得分.然后重新定义 xyz
并abc
在为下一个乐谱定义音乐之前.这是有效的,因为赋值会覆盖之前的任何内容,并且因为LilyPond定义通常按顺序处理.但是,如果您希望某些定义在两个分数中使用并且相同,则可能会感到困惑.
定制你的方法,虽然我会选择一个前缀或后缀,使其更清楚定义所依据的分数.
第一个选项看起来像这样:
\version "2.18.0" xyz = { a' b' c'' } abc = #(define-music-function (parser location musicnotes) (ly:music?) #{ c' $musicnotes e' #}) smus_a = { \abc { d' } f' \xyz } xyz = { a' a' a' } abc = #(define-music-function (parser location musicnotes) (ly:music?) #{ e' $musicnotes c' #}) smus_b = { \abc { d' } f' \xyz } \book { \header { title = "A Book!" } \score { \smus_a \header { piece = "First piece" } } \score { \smus_b \header { piece = "Second piece" } } }
如果音乐定义部分被重构为单独的LilyPond源文件,这也适用.
不幸的是,不可能在分数中坚持分配.您只能在以下位置放置作业:
顶级,
内\display
,\header
和\midi
块
LilyPond语法非常清楚,即使手册的其余部分对它有点回避.(查看http://lilypond.org/doc/v2.17/Documentation/contributor/lilypond-grammar,查找assignment
规则的使用位置).
假设您的分配不适合上面列出的块(在本例中肯定是这种情况),并且假设您不想做一些奇特的事情,比如去定义您自己的Scheme模块并弄清楚如何在你的LilyPond文件,你有两个选择:
定义xyz
和abc
,然后定义的音乐,将进入第一次得分.然后重新定义 xyz
并abc
在为下一个乐谱定义音乐之前.这是有效的,因为赋值会覆盖之前的任何内容,并且因为LilyPond定义通常按顺序处理.但是,如果您希望某些定义在两个分数中使用并且相同,则可能会感到困惑.
定制你的方法,虽然我会选择一个前缀或后缀,使其更清楚定义所依据的分数.
第一个选项看起来像这样:
\version "2.18.0" xyz = { a' b' c'' } abc = #(define-music-function (parser location musicnotes) (ly:music?) #{ c' $musicnotes e' #}) smus_a = { \abc { d' } f' \xyz } xyz = { a' a' a' } abc = #(define-music-function (parser location musicnotes) (ly:music?) #{ e' $musicnotes c' #}) smus_b = { \abc { d' } f' \xyz } \book { \header { title = "A Book!" } \score { \smus_a \header { piece = "First piece" } } \score { \smus_b \header { piece = "Second piece" } } }
如果音乐定义部分被重构为单独的LilyPond源文件,这也适用.