目前我写的lilypond代码如下所示:
\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 >>
#})
但这使用<<
.. >>
而不是<
.. >
,它没有呈现我想要的方式(和警告),我不知道为什么\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
}
好的,所以这是我为你创建的一个功能,它允许你重复单个音高。唯一的问题是它不会使用\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
}
这里仍有一些捕获:当参数是没有{ }
的单个注释时,此函数将仅括号。这在上面的代码中得到了很好的评论。
我希望这会以某种方式帮助你。如果我在这里遇到八度换位问题的解决方案,我会更新这个答案。
我刚从LilyPond的开发人员之一David Kastrup那里得到了这个答案:
发生“八度转换”是因为基本上\ transpose c c与\ absolute相同(因为LilyPond不适用\相对于转置音乐)。
\ 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 =#(define-music-function(解析器位置注释)(ly:music?)(make-relative(note)note#{$ 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操作,然后将结果粘贴到音乐表达式中。
根据你问题中的代码和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' { … }
。
要添加注释的括号,用note2
替换octNote
中对(parenthesize note2)
的最后一个引用 - 我更喜欢非括号版本供我自己使用。 (在这种情况下,您应该将函数重命名为octPNote
和octP
,以避免混淆。我曾短暂地尝试将octPNote
编写为调用octNote
的函数,并对结果进行后处理以括号化第二个音符,但未成功。)
你几乎肯定也需要扩展copy-articulation?
谓词 - tie和fermate只是我遇到的两种清晰度。 (它默认不复制未知的关节,所以如果谓词不完整,你会在复制的笔记上看到它缺少关节。)