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