Wols Lists <antli...@youngman.org.uk> writes: > On 27/12/15 16:32, J Smith wrote: >> I'm trying to define a music function that transposes a chord and a >> melody multiple times. But for some reason, the transposition is done >> only once. >> >> Here's my attempt: >> >> repeatpattern = >> #(define-music-function (parser location chord pattern) (ly:music? >> ly:music?) >> #{ >> % << >> \new ChordNames { >> \transpose c d { #chord } >> \transpose c e { #chord } >> } >> \new Staff { >> \transpose c d { #pattern } >> \transpose c e { #pattern } >> } >> % >> >> #}) >> >> \score { >> \repeatpattern { c1 } { c'4 d' e' r } >> } >> >> (delete the %'s preceding << and >>; had to add them to pass Gmane's >> filter). >> >> Any ideas for why this is not working and how to fix it? (i.e., it >> should transpose "c d e" into "d e f#" and "e f# g#", not into "f# g# >> a#"). >> > Just a guess, but \transpose is funny - I think of it as taking note > NAMES. As soon as you've fed the names through anything (such as > define-music-function) they've been converted to note PITCHES, and > \transpose no longer works.
That's, uh, very imaginative. It has nothing whatsoever to do with what happens here, and pretty much nothing whatsoever to do with anything else. My guess is that your inspiration is the behavior of \transpose inside of \relative (more accurately, the behavior of \relative concerning included passages generated using \transpose). > Short answer - \transpose is very temperamental and sensitive as to > where it is used. Not really. > (And note, my understanding is almost certainly technically wrong, As well as factually. > I just find it helpful as a superficial guide to what's going on.) I don't. At any rate, the problem here is applying \transpose twice to the same music. The instances of #chord (analogously for #pattern) need to be replaced by either $chord (which inherently copies, being a lexically scoped variant of \chord) or #(ly:music-deep-copy chord) or equivalent. This is the same for _any_ multiple use of a music function argument. Otherwise they don't just experience trouble with \transpose, but also \relative, \keepWithTag and a number of other constructs. -- David Kastrup _______________________________________________ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user