在LilyPond中定义\ score内的函数

 perfect_rl 发布于 2023-02-07 12:48

我编译了一本大型的歌曲书,为此我希望有很多本地的函数定义,最终会在\included文件中,但这没有区别.为此,我需要在\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文件,你有两个选择:

    定义xyzabc,然后定义的音乐,将进入第一次得分.然后重新定义 xyzabc在为下一个乐谱定义音乐之前.这是有效的,因为赋值会覆盖之前的任何内容,并且因为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源文件,这也适用.

1 个回答
  • 不幸的是,不可能在分数中坚持分配.您只能在以下位置放置作业:

    顶级,

    \display,\header\midi

    LilyPond语法非常清楚,即使手册的其余部分对它有点回避.(查看http://lilypond.org/doc/v2.17/Documentation/contributor/lilypond-grammar,查找assignment规则的使用位置).

    假设您的分配不适合上面列出的块(在本例中肯定是这种情况),并且假设您不想做一些奇特的事情,比如去定义您自己的Scheme模块并弄清楚如何在你的LilyPond文件,你有两个选择:

      定义xyzabc,然后定义的音乐,将进入第一次得分.然后重新定义 xyzabc在为下一个乐谱定义音乐之前.这是有效的,因为赋值会覆盖之前的任何内容,并且因为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源文件,这也适用.

    2023-02-07 12:50 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有