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