Thomas Morley <thomasmorle...@gmail.com> writes: >>>>You can write: >>>>colorizeDir = >>>>#(define-music-function (parser location item) >>>> (symbol-list-or-music?) >>>> (define (grob-colorize-dir grob) >>>> (let ((ev (event-cause grob))) >>>> (case (ly:event-property ev 'direction) >>>> ((1) red) >>>> ((-1) blue) >>>> (else '())))) >>>> #{ \tweak color #grob-colorize-dir #item #}) >>> >>> Thanks, this works perfectly. >>> >>> I would like to add this to a Frescobaldi addition and later (once >>> 2.18 is out) to a LilyPond addition proposal. Do you have any >>> objections? >> >> You can add it wherever you want. I don't see it making any sense as an >> addition to LilyPond proper as it is a rather special use case. It may >> still be nice as a snippet as it is simple, flexible, and powerful. The >> use cases also show \tweak as an internal workhorse for both tweaks and >> overrides. >> >> As a snippet, it makes sense _in_ 2.18 as it illustrates current >> programming techniques. > > I thought it would be nice to apply such a function to not only one > grob, but rather a list of grobs or all possible grobs. > Though, I didn't manage to generalize David K's tweak-function.
Here is a generalization:
colorizeDir = #(define-music-function (parser location item) (symbol-list-or-music?) (define (grob-colorize-dir grob) (let ((ev (event-cause grob))) (case (ly:event-property ev 'direction) ((1) red) ((-1) blue) (else '())))) #{ \tweak color #grob-colorize-dir #item #}) mapList = #(define-music-function (parser location fun lst) (ly:music-function? list?) #{ $@(map (lambda (s) #{ $fun $s #}) lst) #}) \new Voice \with { \mapList #colorizeDir Slur.StringNumber.TextScript } { a4-( b) a4^( b) a''4_( b) c''-3\4-"xy" c''_3^\4^"xy" c''^3_\4_"xy" }
-- David Kastrup
_______________________________________________ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user