On Tue, Aug 18, 2015 at 5:34 PM, David Nalesnik <david.nales...@gmail.com>
wrote:
>
>
> Something else I can't explain: the spacing appears to be slightly
> different between the default and modified stencils in both files. This
> only affects the positioning of naturals: Padding should only be added in
> case of an overlap. The rewrite finds overlaps in m. 2 where the original
> function doesn't apparently. Any ideas what causes this?
>
>
Turned out to be a misplaced parenthesis. The attached gets the spacing of
naturals right.
David
\version "2.19.23"
#(define key-signature-colors `(
((3 . ,SHARP) . ,green) ; F
((3 . ,FLAT) . ,red)
((0 . ,SHARP) . ,blue) ; C
((0 . ,FLAT) . ,blue)
((3 . ,NATURAL) . ,magenta) ; F
((0 . ,NATURAL) . ,cyan) ; C
((6 . ,FLAT) . ,darkred)
))
#(define key-signature::special-print
(lambda (grob)
(let* ((inter (/ (ly:staff-symbol-staff-space grob) 2.0))
(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 empty-stencil)
(last-glyph-name #f)
(overlapping-pos empty-interval))
(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 overlapping-pos))
(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 overlapping-pos))
(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))
(pitch (car s))
(color (assoc-get pitch key-signature-colors))
(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))
; extra padding for naturals
((and
(string=? glyph-name "accidentals.natural")
(not (interval-empty?
(interval-intersection overlapping-pos pos))))
(+ padding 0.3))
(else padding))))
(loop (cdr s)
(ly:stencil-combine-at-edge
stil
X
LEFT
column
padding)
glyph-name
(coord-translate (interval-widen pos 4) 2))))))))
(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
\override Staff.KeyCancellation.stencil =
#key-signature::special-print
\music
}
{
\override Staff.KeySignature.stencil =
#key-signature::special-print
\override Staff.KeyCancellation.stencil =
#key-signature::special-print
\clef bass
\music
}
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user