joegomain
joegomain

Reputation: 864

In LiliyPond, how do you alter a music expression?

I have a situation where I have a recurring piece of music with only slight variations. I want to lay down a base piece as a variable. Then reuse it multiple times, each time altering it by replacing a few notes or measures. Here's a simplified example

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 }

How do I do this?

Upvotes: 3

Views: 105

Answers (1)

joegomain
joegomain

Reputation: 864

A LilyPond solution to this is \tag. I haven't found a built-in functionality for altering a music expression on the fly. However, for the variations usecase, tags serve this purpose. The above example would be this

base = { c4 c \tag #'base c \tag #'var1 d c }
var1 = \keepWithTag #'var1 \base

Upvotes: 4

Related Questions