]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/snippets/generating-custom-flags.ly
LSR: Update.
[lilypond.git] / Documentation / snippets / generating-custom-flags.ly
1 %% Do not edit this file; it is automatically
2 %% generated from LSR http://lsr.dsi.unimi.it
3 %% This file is in the public domain.
4 \version "2.13.39"
5
6 \header {
7   lsrtags = "rhythms, tweaks-and-overrides"
8
9   texidoc = "
10 The @code{flag} property of the Stem grob can be set to a custom scheme
11 function to generate the glyph for the flag.
12
13 "
14   doctitle = "Generating custom flags"
15 } % begin verbatim
16
17 #(define-public (weight-flag stem-grob)
18    (let* ((log (- (ly:grob-property stem-grob 'duration-log) 2))
19           (is-up? (eqv? (ly:grob-property stem-grob 'direction) UP))
20           (yext (if is-up? (cons (* log -0.8) 0) (cons 0 (* log 0.8))))
21           (flag-stencil (make-filled-box-stencil '(-0.4 . 0.4) yext))
22           (stroke-style (ly:grob-property stem-grob 'stroke-style))
23           (stroke-stencil (if (equal? stroke-style "grace")
24                               (make-line-stencil 0.2 -0.9 -0.4 0.9 -0.4)
25                               empty-stencil)))
26      (ly:stencil-add flag-stencil stroke-stencil)))
27
28
29 % Create a flag stencil by looking up the glyph from the font
30 #(define (inverted-flag stem-grob)
31    (let* ((dir (if (eqv? (ly:grob-property stem-grob 'direction) UP) "d" "u"))
32           (flag (retrieve-glyph-flag "" dir "" stem-grob))
33           (line-thickness (ly:staff-symbol-line-thickness stem-grob))
34           (stem-thickness (ly:grob-property stem-grob 'thickness))
35           (stem-width (* line-thickness stem-thickness))
36           (stroke-style (ly:grob-property stem-grob 'stroke-style))
37           (stencil (if (null? stroke-style)
38                        flag
39                        (add-stroke-glyph flag stem-grob dir stroke-style "")))
40           (rotated-flag (ly:stencil-rotate-absolute stencil 180 0 0)))
41      (ly:stencil-translate rotated-flag (cons (- (/ stem-width 2)) 0))))
42
43 snippetexamplenotes = { \autoBeamOff c'8 d'16 c'32 d'64 \acciaccatura {c'8} d'64 }
44
45 {
46   \override Score.RehearsalMark #'self-alignment-X = #LEFT
47   \time 1/4
48   \mark "Normal flags"
49   \snippetexamplenotes
50
51   \mark "Custom flag: inverted"
52   \override Stem #'flag = #inverted-flag
53   \snippetexamplenotes
54
55   \mark "Custom flag: weight"
56   \override Stem #'flag = #weight-flag
57   \snippetexamplenotes
58
59   \mark "Revert to normal"
60   \revert Stem #'flag
61   \snippetexamplenotes
62 }
63