lilypond-user
[Top][All Lists]
Advanced

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

Re: Accidentals not changing colour


From: Thomas Morley
Subject: Re: Accidentals not changing colour
Date: Thu, 13 Jun 2013 00:17:04 +0200

2013/6/12 David Kastrup <address@hidden>:
> 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
>

Hi,

I tried it different:
(Note the version, it doesn't work with 2.16.2)

\version "2.17.20"

coloraccidentals =
\override NoteHead #'color =
  #(lambda (grob)
    (let* ((acc (ly:grob-object grob 'accidental-grob))
           (glyph-name
              (if (ly:grob? acc)
                  (ly:grob-property acc 'glyph-name)
                  "."))
           (which-acc (cadr (string-split glyph-name #\.))))
           (display glyph-name)
    (cond ((string=? which-acc "sharp")
           red)
          ((string=? which-acc "flat")
           cyan))))

m = \new Staff \relative c' { c8\f ces^"xy" cis <c cis'-1\2 ces'>\p }

\new Score \with { \coloraccidentals }
        <<
                \m
                \m
        >>


Though I wonder why it works. It's an override and not a tweak, but it
colors NoteHeads different even in chords.
Have I missed something?

Cheers,
  Harm



reply via email to

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