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: Thu, 13 Jun 2013 00:31:09 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Thomas Morley <address@hidden> writes:

> 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)

That's distasteful and backwards.  Why don't you look at

(ly:event-property (event-cause grob) 'pitch)

instead?  That does not require the accidental grob to have been
calculated and does not depend on accidental names.

>     (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?

Why would it depend on chords?  Chords just group stuff at the music
expression level.  They are already dissolved at the stream event level:
event-chord-event does not make it beyond the Event_chord_iterator.

Regarding "you can't use overrides for notes within chords": that is
actually "you can't use overrides for _individual_ notes within chords"
since overrides travel through context properties while tweaks travel
through events.  Now here you are overriding the NoteHead.color property
with a callback function, and indeed every note within the chord will
use the same callback.  But that does not mean that the callback needs
to arrive at the same value for every note in a chord.

It just means that \coloraccidentals will apply to every note inside of
a chord.  Unless you use \single\coloraccidentals on a note inside of a
chord, of course...

-- 
David Kastrup



reply via email to

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