问题描述
我有一种情况,我有一段重复出现的音乐,只有轻微的变化。我想把一个基础部分作为一个变量。然后多次重复使用,每次都通过替换一些音符或小节来改变它。这是一个简化的例子
base = { c4 c c c }
% pseudo function \replace MUSIC FROM TO ORIG
% FROM and To are pairs of numbers COUNT DURATION
from = #'(1 2)
to = #'(3 4)
var1 = \replace { d4 } \from \to \base
% this means replace
% from "after 1 half note into the music"
% to "after 3 quarter notes into the music"
% that is replace the third beat with { d4 }
% this will be equivalent to
var1 = { c4 c d c }
我该怎么做?
解决方法
LilyPond 对此的解决方案是 \tag
。我还没有找到用于即时更改音乐表达的内置功能。但是,对于变体用例,标签用于此目的。上面的例子是这个
base = { c4 c \tag #'base c \tag #'var1 d c }
var1 = \keepWithTag #'var1 \base