首页 > 解决方案 > 如何创建一个函数来自动创建标题?

问题描述

我有一些转录要做,使用 lilypond。它由几首歌曲组成,都是同一位作曲家/诗人,但可能还会有更多。我已经在每个分数中包含了一些辅助函数,但我想要一个函数来自动创建标题,我可以这样调用:

\mkheader "my song"

或类似的东西。

这将避免需要写

\header {
  composer = "the composer of all the songs"
  title = "my song"
}

在每一首歌里。

从两天前开始,我一直在(重新)阅读 lilypond 文档,但我无法让它工作。有任何想法吗?

标签: lilypond

解决方案


您可能需要包含文件

目录结构

.
├── my_include.ly
├── my_main.ly

my_include.ly

\header {
  composer = "the composer of all the songs"
  title = "my song"
} 

my_main.ly

\version "2.20.0"

\include "my_include.ly"

melody = \relative c {
  \key c \major
  \time 4/4
  c c c c |
}

\score {
  <<
    \new Staff { \melody }
  >>
}

您可能希望稍后在主 lilypond 文件中添加额外信息,在这种情况下,您只需添加另一个头块 my_main.ly

\version "2.20.0"

\include "./my_include.ly"

\header {
 subtitle = "my_subtitle"
 subsubtitle = "my_subsubtitle"
}

melody = \relative c'' {
  \key c \major
  \time 4/4
  c c c c |
}

\score {
  <<
    \new Staff { \melody }
  >>
}

推荐阅读