]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/snippets/generating-custom-flags.ly
cea693d5cd56df43a9f2f037aa5f52ac8e8cd605
[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 %% Translation of GIT committish: 57f9346bb030f49336a858fcbf1519366fe56454
12   texidocfr = "
13 Une fonction Scheme personnalisée permet de redéfinir la propriété
14 @code{stencil} de l'objet @code{Flag}, de sorte à modifier le glyphe
15 utilisé pour les crochets de croche.
16
17 "
18   doctitlefr = "Génération de crochets personnalisés"
19
20   lsrtags = "rhythms, tweaks-and-overrides"
21
22   texidoc = "
23 The @code{stencil} property of the Flag grob can be set to a custom scheme
24 function to generate the glyph for the flag.
25
26 "
27   doctitle = "Generating custom flags"
28 } % begin verbatim
29
30
31 #(define-public (weight-flag grob)
32    (let* ((stem-grob (ly:grob-parent grob X))
33           (log (- (ly:grob-property stem-grob 'duration-log) 2))
34           (is-up? (eqv? (ly:grob-property stem-grob 'direction) UP))
35           (yext (if is-up? (cons (* log -0.8) 0) (cons 0 (* log 0.8))))
36           (flag-stencil (make-filled-box-stencil '(-0.4 . 0.4) yext))
37           (stroke-style (ly:grob-property grob 'stroke-style))
38           (stroke-stencil (if (equal? stroke-style "grace")
39                               (make-line-stencil 0.2 -0.9 -0.4 0.9 -0.4)
40                               empty-stencil)))
41      (ly:stencil-add flag-stencil stroke-stencil)))
42
43
44 % Create a flag stencil by looking up the glyph from the font
45 #(define (inverted-flag grob)
46    (let* ((stem-grob (ly:grob-parent grob X))
47           (dir (if (eqv? (ly:grob-property stem-grob 'direction) UP) "d" "u"))
48           (flag (retrieve-glyph-flag "" dir "" grob))
49           (line-thickness (ly:staff-symbol-line-thickness grob))
50           (stem-thickness (ly:grob-property stem-grob 'thickness))
51           (stem-width (* line-thickness stem-thickness))
52           (stroke-style (ly:grob-property grob 'stroke-style))
53           (stencil (if (null? stroke-style)
54                        flag
55                        (add-stroke-glyph flag stem-grob dir stroke-style "")))
56           (rotated-flag (ly:stencil-rotate-absolute stencil 180 0 0)))
57      (ly:stencil-translate rotated-flag (cons (- (/ stem-width 2)) 0))))
58
59 snippetexamplenotes = { \autoBeamOff c'8 d'16 c'32 d'64 \acciaccatura {c'8} d'64 }
60
61 {
62   \override Score.RehearsalMark #'self-alignment-X = #LEFT
63   \time 1/4
64   \mark "Normal flags"
65   \snippetexamplenotes
66
67   \mark "Custom flag: inverted"
68   \override Flag #'stencil = #inverted-flag
69   \snippetexamplenotes
70
71   \mark "Custom flag: weight"
72   \override Flag #'stencil = #weight-flag
73   \snippetexamplenotes
74
75   \mark "Revert to normal"
76   \revert Flag #'stencil
77   \snippetexamplenotes
78 }
79