Hi Heikki,

On Mon, Aug 17, 2015 at 7:47 AM, Heikki Junes <[email protected]>
wrote:

>
> 2015-08-17 15:34 GMT+03:00 David Kastrup <[email protected]>:
>>
>>
>> Key signature is a single grob.  Your best bet probably is recoding the
>> print routine in lily/key-signature-interface.cc in Scheme (it appears
>> rather straightforward) and then add the desired color changes to it.
>> The alternative, namely calling the print routine and post-processing
>> the stencil is probably less robust against future changes in LilyPond.
>
>
> This recoding the print routine in scheme sound exactly the kind of
> solution I was looking at.
> Then that scheme code could be updated with a scheme script in the
> preamble of a .ly file,
> which would allow "\override Staff.KeySignature #'color =
> #color-keysignature".
>
> I would be very grateful, if somebody for whom this recoding is an easy job
> could take a catch on this idea.
>

In the attached file, I've recoded the print routine in Scheme, adding the
ability to color individual alterations based on their position relative to
the central line (= 0).  Note that signatures for KeySignature and
KeyCancellation are handled independently.

I ran out of steam before I duplicated everything in the C++ function, but
hopefully this will give you what you need.

Best,
David
\version "2.19.23"

#(define (key-signature::special-print alt-color-list)
   (lambda (grob)
     (let* ((inter (/ (ly:staff-symbol-staff-space grob) 2.0))
            (mol empty-stencil)
            (c0s (ly:grob-property grob 'c0-position))
            (is-cancellation? (grob::has-interface grob 'key-cancellation-interface))
            (padding-pairs (ly:grob-property grob 'padding-pairs))
            (fm (ly:grob-default-font grob))
            (alist (ly:grob-property grob 'glyph-name-alist)))
       (let loop ((s (ly:grob-property grob 'alteration-alist))
                  (stil mol)
                  (last-glyph-name #f))
         (if (pair? s)
             (let* ((alt (if is-cancellation? 0 (cdar s)))
                    (glyph-name (ly:assoc-get alt alist))
                    (acc (ly:font-get-glyph fm glyph-name))
                    (pos-list
                     (key-signature-interface::alteration-positions (car s) c0s grob))
                    (p (car pos-list))
                    (color (assoc-get p alt-color-list))
                    (acc
                     (if (color? color)
                         (stencil-with-color acc color)
                         acc))
                    (padding (ly:grob-property grob 'padding 0.0))
                    (handle (assoc (cons glyph-name last-glyph-name) padding-pairs))
                    (padding
                     (cond
                      ((pair? handle) (cdr handle))
                      ((and
                        (string=? glyph-name "accidentals.natural")
                        ; ...
                        )
                       (+ padding 0.3))
                      (else padding))))
         
               (loop (cdr s)
                 (ly:stencil-combine-at-edge
                  stil
                  X
                  LEFT
                  (ly:stencil-translate-axis acc (* p inter) Y)
                  padding)
                 glyph-name))
             (ly:stencil-aligned-to stil X LEFT))))))


{
  \override Staff.KeySignature.stencil =
  #(key-signature::special-print `((4 . ,green) (-3 . ,red) (1 . ,blue)))
  
  \override Staff.KeyCancellation.stencil =
  #(key-signature::special-print `((-3 . ,magenta) (1 . ,cyan)))
  
  \key ces \major
  ces'1
  \key a \major
  a'1
  \key g \major
  g'1
}
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to