【问题标题】:How to abbreviate 'note with the same note an octave higher, parenthesized' in Lilypond?如何在 Lilypond 中缩写“相同音符的音符高八度,带括号”?
【发布时间】:2013-10-28 03:34:06
【问题描述】:

目前我编写的 代码如下所示:

\version "2.14.2"

P = #parenthesize

\relative c, {
  \clef bass 
    <c \P c'> <e \P e'> <g \P g'>2 <c, \P c'>4 <d \P d'> <e \P e'>2
}

我重复的意思是“这个音符,连同高一个八度的同一个音符,用括号括起来”。

我想要一个缩写的方法,这样我就可以写这样的东西:

\version "2.14.2"

poct = ...

\relative c, {
  \clef bass 
  \poct c \poct e \poct g2 \poct c,4 \poct d \poct e2
}

正如a helpful answer to an earlier question of mine 中所建议的那样,我尝试使用a music function,但我无法让它工作。我能得到的最接近的是

poct = #(define-music-function
     (parser location note)
     (ly:music?)
   #{
     << $note \transpose c c \parenthesize $note >>
   #})

但这使用&lt;&lt; .. &gt;&gt; 而不是&lt; .. &gt;,它不会呈现我想要的方式(并且带有警告),我不知道为什么\transpose c c 实际上转置任何东西。

最后,切线相关,在尝试音乐功能时,我发现仅仅创建一个模仿\repeat unfold 2的音乐功能是不可能的;以下在第三个和第四个c之间跳了一个八度:

\version "2.14.2"

double = #(define-music-function
     (parser location note)
     (ly:music?)
   #{
     $note $note
   #})

\relative c, {
  \clef bass 
  \double c \double e \double g2 \double c,4 \double d \double e2
}

标签: lilypond scheme guile lilypond music-notation


【解决方案1】:

好的,这是我为您创建的功能,可让您重复单个音高。唯一的问题是它不会使用\relative 表示法。这是因为,在相对符号中,以下音符序列c' c' c' 显然会比前一个音符高一个八度。不幸的是,我仍然找不到像\function #3 c' 这样可以输出c' c c 的函数的方法。也就是说,这是我的功能和一些示例:

\version "2.17.28"

times = #(define-music-function
     (parser location N note)
     (integer? ly:music?)
     (cond 
       ((>= N 2)
         #{ \repeat unfold $N { \absolute $note } #}
       )
       ((= N 1) 
         #{ \absolute $note #}
       )
     )
)

{
 a4 \times #3 b4
 R1
 \times #4 { c'8 d' }
 R1
 \times #1 { c''1 }
}

所以语法就是\times #"number of repetition" { ...music... }。如果只重复一个音符,可以省略{}\times #"number of repetition" "single note"

您可以在\relative 段落的中间使用此功能,但您应该为该功能输入绝对音高。看看:

\version "2.17.28"

times = #(define-music-function
     (parser location N note)
     (integer? ly:music?)
     (cond 
       ((>= N 2)
         #{ \repeat unfold $N { \absolute $note } #}
       )
       ((= N 1) 
         #{ \absolute $note #}
       )
     )
)

\relative c'' {
  c4 d \times #4 e'' f g
}

请注意,以上所有音符都在同一个八度音阶中。音符f的八度位置也不受此函数影响,它受函数前面的音符影响,即d

当然有办法为此编写更好的代码,但我无法使用任何 \relative\transpose 命令来完成此操作。


这里有一些尝试帮助您使用带括号的八度音阶(上面的功能相同,但有一些小的改动):

\version "2.17.28"

timesP = #(define-music-function
     (parser location N note)
     (integer? ly:music?)
     (cond 
       ((>= N 2)
         #{ 
           << 
             \repeat unfold $N { \absolute $note } 
             \transpose c c' \repeat unfold $N { \absolute \parenthesize $note } 
           >>
         #}
       )
       ((= N 1) 
         #{ 
           << 
             \absolute $note 
             { \transpose c c' \parenthesize $note }
           >>
         #}
       )
     )
)

{
 a4 \timesP #3 b4
 \timesP #8 c'16
 \timesP #2 g4
 \timesP #4 { c'8 d' } % no parenthesis here because there are two notes as arguments...
 \timesP #1 { c''1 } % no parenthesis here because of the { }
}

\relative c'' {
  c4 d \timesP #4 e'' f g
}

这里还有一些问题:只有当参数是没有{ } 的单个注释时,这个函数才会加括号。这在上面的代码中有很好的注释。


我希望这会对您有所帮助。如果我在这里遇到八度转置问题的解决方案,我会更新这个答案。

【讨论】:

    【解决方案2】:

    我刚刚从 LilyPond 的开发者之一 David Kastrup 那里得到了这个答案:


    “八度转置”的发生是因为基本上 \transpose c c 与 \absolute 相同(因为 LilyPond 不适用于 \relative 到转置的音乐)。

    \absolute 对于\repeat 展开不是必需的:\repeat 展开知道如何处理相关音乐。

    版本 2.14.2 非常旧。无论如何,目前 LilyPond 跟踪器中存在问题http://code.google.com/p/lilypond/issues/detail?id=3673,相应的代码可以在https://codereview.appspot.com/30890043/diff/40001/scm/music-functions.scm找到。

    我们确实进入了 Scheme 编程。尽管 #{ #} 可能无法正常工作,但相应的 defmacro-public 甚至在 2.14 中也可能工作。

    有了这个定义,你的双重定义就会变成:

    double = #(定义音乐功能 (解析器位置说明) (ly:音乐?) (make-relative (note) note #{ $注$注 #}))

    然后将在绝对和相对模式下工作。如果 2.14 #{ #} 与 make-relative 不兼容,写作 (make-sequential-music (list (ly:music-deep-copy note) (ly:music-deep-copy note))) 应该作为方案替换。

    一旦你意识到它只是一个简单的代码替换,原来的问题就变得更容易理解了,所以 \relative { \double c' } 变成了 \relative { c' c' } 使用不同的八度。 make-relative 宏将只对单个音符进行 \relative 操作,然后将结果粘贴到音乐表达式中。

    【讨论】:

      【解决方案3】:

      根据您问题中的代码以及另一篇回复中引用的 David Kastrup 的回答,我构建了以下代码,以将音符转换为相同音符高一个八度的和弦,不是括号:

      #(define (octavate-pitch pitch octaves)
         (ly:make-pitch
          (+ (ly:pitch-octave pitch) octaves)
          (ly:pitch-notename pitch)
          (ly:pitch-alteration pitch)))
      
      #(define (articulation-is-of-type? art type)
         (string=? (ly:music-property art 'articulation-type) type))
      
      #(define (copy-articulation? art)
         (cond ((music-is-of-type? art 'tie-event)
                #t)
               ((and (music-is-of-type? art 'articulation-event)
                     (articulation-is-of-type? art "fermata"))
                #f)
               ; TODO add more cases
               (else
                #f)))
      
      #(define (octNote note)
         (if (null? (ly:music-property note 'pitch))
             note
             (make-relative (note) note
                            (let ((note2 (ly:music-deep-copy note))
                                  (pitch (ly:music-property note 'pitch)))
                              (set! (ly:music-property note2 'pitch)
                                    (octavate-pitch pitch 1))
                              (set! (ly:music-property note2 'articulations)
                                    (filter copy-articulation? (ly:music-property note2 'articulations)))
                              (make-event-chord (list note note2))))))
      
      oct = #(define-music-function
                 (parser location music)
                 (ly:music?)
               (music-map octNote music))
      

      它可以应用于单个音符或完整的音乐表达:

      \relative c' \oct {
        c d e f |
        g2 g |
      }
      

      它也以相反的顺序工作,\oct \relative c' { … }

      要给添加的注释加上括号,请将octNote 中对note2 的最后引用替换为(parenthesize note2)——我只是更喜欢不带括号的版本供我自己使用。 (在这种情况下,您可能应该将函数重命名为 octPNoteoctP,以避免混淆。我简要地尝试将 octPNote 编写为调用 octNote 的函数,并对结果进行后处理以将第二个注释括起来,但没有成功。)

      您几乎肯定还需要扩展 copy-articulation? 谓词 - tie 和 fermate 只是我遇到的两种表达方式。 (它默认不复制未知的发音,所以如果谓词不完整,您会在复制的音符上看到它缺少发音。)

      【讨论】:

        猜你喜欢
        • 2017-09-05
        • 2011-01-14
        • 1970-01-01
        • 2019-06-01
        • 1970-01-01
        • 1970-01-01
        • 2010-10-17
        • 1970-01-01
        • 2019-12-08
        相关资源
        最近更新 更多