4 lsrtags = "rhythms, tweaks-and-overrides"
7 The @code{stencil} property of the Flag grob can be set to a custom scheme
8 function to generate the glyph for the flag.
11 doctitle = "Generating custom flags"
14 #(define-public (weight-flag grob)
15 (let* ((stem-grob (ly:grob-parent grob X))
16 (log (- (ly:grob-property stem-grob 'duration-log) 2))
17 (is-up? (eqv? (ly:grob-property stem-grob 'direction) UP))
18 (yext (if is-up? (cons (* log -0.8) 0) (cons 0 (* log 0.8))))
19 (flag-stencil (make-filled-box-stencil '(-0.4 . 0.4) yext))
20 (stroke-style (ly:grob-property grob 'stroke-style))
21 (stroke-stencil (if (equal? stroke-style "grace")
22 (make-line-stencil 0.2 -0.9 -0.4 0.9 -0.4)
24 (ly:stencil-add flag-stencil stroke-stencil)))
27 % Create a flag stencil by looking up the glyph from the font
28 #(define (inverted-flag grob)
29 (let* ((stem-grob (ly:grob-parent grob X))
30 (dir (if (eqv? (ly:grob-property stem-grob 'direction) UP) "d" "u"))
31 (flag (retrieve-glyph-flag "" dir "" grob))
32 (line-thickness (ly:staff-symbol-line-thickness grob))
33 (stem-thickness (ly:grob-property stem-grob 'thickness))
34 (stem-width (* line-thickness stem-thickness))
35 (stroke-style (ly:grob-property grob 'stroke-style))
36 (stencil (if (null? stroke-style)
38 (add-stroke-glyph flag stem-grob dir stroke-style "")))
39 (rotated-flag (ly:stencil-rotate-absolute stencil 180 0 0)))
40 (ly:stencil-translate rotated-flag (cons (- (/ stem-width 2)) 0))))
42 snippetexamplenotes = { \autoBeamOff c'8 d'16 c'32 d'64 \acciaccatura {c'8} d'64 }
45 \override Score.RehearsalMark #'self-alignment-X = #LEFT
50 \mark "Custom flag: inverted"
51 \override Flag #'stencil = #inverted-flag
54 \mark "Custom flag: weight"
55 \override Flag #'stencil = #weight-flag
58 \mark "Revert to normal"
59 \revert Flag #'stencil