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