[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: problems trying to write a conditional \transpose
From: |
David Kastrup |
Subject: |
Re: problems trying to write a conditional \transpose |
Date: |
Tue, 06 Aug 2013 05:54:10 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
Mark Polesky <address@hidden> writes:
> I'm trying to write a conditional version of the \transpose
> function, that would work something like this:
>
> input = {
> c c
> \conditionalTransposition c c' { c c }
> }
>
> \input
> => { c c c c }
>
> \processConditionalTransposition \input
> => { c c c' c' }
conditionalTransposition =
#(define-music-function (parser location from to music)
(ly:pitch? ly:pitch? ly:music?)
(set! music #{ \transpose c' c' #music #})
(set! (ly:music-property 'from-to music) (cons from to))
music)
processConditionalTransposition =
#(define-music-function (parser location music) (ly:music?)
(map-some-music
(lambda (m)
(and (music-is-of-type? m 'transposed-music)
(pair? (ly:music-property m 'from-to music))
#{ \transpose #(car (ly:music-property m 'from-to-music))
#(cdr (ly:music-property m 'from-to-music))
#(ly:music-property m 'element)
#}))
music))
This is assuming that you don't nest processConditionalTransposition, if
you do, you need to write
\processConditionalTransposition #(ly:music-property m 'element) at the
appropriate place.
Untested.
--
David Kastrup