lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accidentals not changing colour


From: David Kastrup
Subject: Re: Accidentals not changing colour
Date: Wed, 12 Jun 2013 23:28:35 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Evian <address@hidden> writes:

> 2 years ago I was provided with the following code. The idea 
> was to change de colour when having an  accidental. This in the 
> new version is not working. 
>
> Can anybody help?

> coloraccidentals = #(define-music-function (parser location music) (ly:music?)
> (music-map
>  (lambda (event)
>    (if (eq? 'EventChord (ly:music-property event 'name))
>        (map (lambda (note)
>             (if (accidentals? note SHARP)
>                 (ly:music-set-property! note 'tweaks (list (cons 'color 
> red))) note)
>             (if (accidentals? note FLAT)
>                 (ly:music-set-property! note 'tweaks (list (cons 'color 
> cyan))) note))
>           (ly:music-property event 'elements))) event) music))

This is broken anyway as it would, for example, have bombed out on c\f.
Replying on a certain input structure is always worse than just checking
that have what you want directly where you need it.

It's easier to do something like
coloraccidentals =
#(define-music-function (parser location music) (ly:music?)
  (map-some-music
    (lambda (note)
      (and (music-is-of-type? note 'note-event)
           (cond ((accidentals? note SHARP)
                  #{ \tweak #'color #red #note #})
                 ((accidentals? note FLAT)
                  #{ \tweak #'color #cyan #note #})
                 (else note))))
   music))

-- 
David Kastrup




reply via email to

[Prev in Thread] Current Thread [Next in Thread]