为了避免代码重复,Lilypond有什么语言机制来表示简单的缩写? [英] What language mechanisms does Lilypond have for simple abbreviations, to avoid code duplication?

查看:120
本文介绍了为了避免代码重复,Lilypond有什么语言机制来表示简单的缩写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

lilypond 的问题中,我经常发现自己在写作

In lilypond, I often find myself writing things like this

\version "2.14.2"
{
  r2 c2 | gis'8 gis gis gis gis gis gis gis |
}

或此

\version "2.14.2"
{
  \time 3/4 \clef bass \relative es,
  {
    <es \parenthesize es'>8\staccato g bes
    <es, \parenthesize es'>8\staccato g c
  }
}

在这里我反复将音符加倍八度,并加括号。

where I repeatedly double some note one octave higher, parenthesized.

我已经搜索了 Lilypond文档,但是没有找到避免这种重复的简单机制。显然,更复杂的方法是编写音乐功能,但是

I have scoured the Lilypond documentation, but have not found easy mechanisms to avoid this duplication. A more complex way is apparently to write a music function, but that seems to require stepping out into Scheme.

到目前为止,我发现的唯一机制是我不了解的机制:

The only mechanism I have found to date is one for which I don't understand the mechanism:

\version "2.14.2"
S = #staccato
P = #parenthesize
{
  \time 3/4 \clef bass \relative es,
  {
    <es \P es'>8\S g bes <es, \P es'>8\S g c
  }
}

因此:如何我在Lilypond中写了我自己略微复杂的缩写,而没有转义Scheme?

So: How can I write my own slightly more complex abbreviations in Lilypond, without escaping to Scheme?

更新。我编辑了问题的一部分,以表明(1)我当前正在使用2.14.2,该版本在Ubuntu 12.04 LTS上是最新的; (2)在第二个示例中,在 bes 之后,我想回到上一个 es ,而不是高八度:而且由于我始终以 \relative 模式工作,所以我故意写了 es,; (3)我正在寻找一种方法来简化诸如' this 音符的缩写,并以相同的音高一个八度,并用括号括起来。

Update. I edited back part of my question, to indicate that (1) I'm currently using 2.14.2, which is current on Ubuntu 12.04 LTS; (2) in my second example, after the bes I want to go back to the previous es, not one octave higher: and since I'm always working in \relative mode I intentionally wrote es,; (3) I'm looking for a way to abbreviate things like 'this note with the same one an octave higher, parenthesised'.

推荐答案

所以您似乎在这里有两个问题。对于第一个,只需使用命令 \repeat unfold N {... music ...} ,该命令在此链接。因此,上面的代码将变为:

So it seems you have two questions here. For the first one, simply use the command \repeat unfold N { ...music... }, which is described in the documentation on this link. So your code above would become something like:

\version "2.17.28"
{
  c2 \repeat unfold 8 {gis'8} r2
  es1 | \repeat unfold 2{<es \parenthesize es'>8\staccato g bes4}
}

在和弦的情况下,有一个特殊命令 q 会重复最后一个和弦(它仅重复音高,并且不包含有关持续时间的信息,铰接,动力学等):

In case of chords, there is the special command q which repeats the last chord (it only repeat the pitches and it carries no information about duration, articulation, dynamics, etc):

\version "2.17.28"
{
  <a' c'' e''>4\p-> q q q |
  q-> q\ff q\p->\< q\! |
  d'8 e' q q q2 
}

您也可以定义较短的部分代码并在主代码中使用它们,例如:

You can also define shorter parts of the code and use them in the main code, such as:

\version "2.17.28"
A = {gis'8}
B = {<es \parenthesize es'>8\staccato g bes4}

{
  c2 \repeat unfold 8 {\A} r2 |
  es1 | \repeat unfold 2 {\B} | 
  \repeat unfold 16 {\A} |
  \repeat unfold 4 {\B}
}






关于第二个问题,我也开始学习在LilyPond上使用函数。但是好吧,看来您的代码等同于此代码,这是LilyPond中最基本的功能(据我所知):


As for your second question, I am also starting to learn to use functions on LilyPond. But well, it seems your code is equivalent to this code here, which is the most basic function (as far as I knew) in LilyPond:

\version "2.17.28"
S = #(define-event-function (parser location) ()
  #{ \staccato #}
)

P = #(define-event-function (parser location) ()
  #{ \parenthesize #}
)

{
es1 | <es \P es'>8\S g bes <es, \P es'>\S g bes 
}

因此,如果您只想在代码中替换一些长文本,则可以使用以下模板: functionname =#(define-event- function(parser location)()#{text#}),其中 functionname text 必须更改,但其余应保持不变。应用后,它看起来像这样:

So if you just want to substitute some long text into your code, you can use this template: functionname = #(define-event-function (parser location) () #{ text #}), where functionname and text have to be changed, but the rest should remain the same. Applied, it looks like this:

\version "2.17.28"
test = #(define-event-function (parser location) ()
  #{ ^"test"\fermata\trill->\pp #}
)
{c''1\test | d'' }

对于更复杂的内容,请看下面的示例,它是音乐功能,使用笔记作为参数。请注意,然后如何操纵参数在最终输出中的位置:

For something still a bit more complex, look at this example which is a music-function using notes as argument. Note how you can then manipulate where the arguments will be in the final output:

\version "2.17.28"
func = 
#(define-music-function
  (parser location notes)
  (ly:music?)
  #{ 
    % generates 2 low pitches with cross notehead
    \override Staff.NoteHead.style = #'cross
    g,8 a,

    % reverts back to the normal noteheads and uses the notes in the argument of the function
    \revert Staff.NoteHead.style
    $notes   % these will be substituted by the arguments when you call this function on your main code

    % generates 4 low pitches with cross notehead
    \override Staff.NoteHead.style = #'cross
    g,8 a, b, c
    % reverts back to the normal noteheads for the rest of the code
    \revert Staff.NoteHead.style
  #}
)

{
  \func { c''4 } | d''1
}

现在,如果您想做更复杂的事情,那么您将需要真正研究文档关于音乐功能,请自己尝试一下。您还可以检查链接。

Now if you want to do something more complex, then you will need to really study the documentation regarding music functions and try a lot by yourself. You can also check this and this links out.

这篇关于为了避免代码重复,Lilypond有什么语言机制来表示简单的缩写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆