\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)) (pos empty-interval) (overlapping-pos empty-interval) (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))) (if (not (string? glyph-name)) (begin (ly:warning "No glyph found for alteration: ~a" alt) (loop (cdr s) stil last-glyph-name)) (let ((acc (ly:font-get-glyph fm glyph-name))) (if (equal? acc empty-stencil) (begin (ly:warning "alteration not found") (loop (cdr s) stil last-glyph-name)) (let ((column empty-stencil) (pos empty-interval)) (let inner ((pos-list (key-signature-interface::alteration-positions (car s) c0s grob))) (if (pair? pos-list) (let* ((p (car pos-list)) (color (assoc-get p alt-color-list)) (acc (if (color? color) (stencil-with-color acc color) acc))) (set! pos (add-point pos p)) (set! column (ly:stencil-add column (ly:stencil-translate-axis acc (* p inter) Y))) (inner (cdr pos-list)))) (let* ((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") (not (interval-empty? (interval-intersection overlapping-pos pos)))) (+ padding 0.3)) (else padding)))) (set! pos (interval-widen pos 4)) (set! overlapping-pos (coord-translate pos 2)) (loop (cdr s) (ly:stencil-combine-at-edge stil X LEFT column padding) glyph-name)))))))) (ly:stencil-aligned-to stil X LEFT)))))) music = { \key ces \major ces'1 \key a \major a'1 \key g \major g'1 \override Staff.KeySignature.flat-positions = #'((-5 . 5)) \override Staff.KeyCancellation.flat-positions = #'((-5 . 5)) \clef bass \key es \major es g bes d \clef treble \bar "||" \key es \major es g bes d \override Staff.KeySignature.sharp-positions = #'(2) \bar "||" \key b \major b fis b2 \override Staff.KeySignature.padding-pairs = #'((("accidentals.flat" . "accidentals.sharp") . 2)) \set Staff.keyAlterations = #`(((0 . 6) . ,FLAT) ((0 . 5) . ,FLAT) ((0 . 3) . ,SHARP)) c4 d e fis aes4 bes c'1 } %% DEFAULT: { \music } %% WITH OVERRIDES: { \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))) \music }