]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/snippets/center-text-below-hairpin-dynamics.ly
Web-hu: Fix tiny mistake
[lilypond.git] / Documentation / snippets / center-text-below-hairpin-dynamics.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.19.22"
8
9 \header {
10   lsrtags = "expressive-marks, really-cool, scheme-language, text"
11
12   texidoc = "
13 This example provides a function to typeset a hairpin (de)crescendo
14 with some additional text below it, such as @qq{molto} or @qq{poco}.
15 The added text will change the direction according to the direction of
16 the hairpin. The Hairpin is aligned to DynamicText.
17
18 The example also illustrates how to modify the way an object is
19 normally printed, using some Scheme code.
20
21 "
22   doctitle = "Center text below hairpin dynamics"
23 } % begin verbatim
24
25 hairpinWithCenteredText =
26 #(define-music-function (text) (markup?)
27   #{
28     \once \override Voice.Hairpin.after-line-breaking =
29       #(lambda (grob)
30         (let* ((stencil (ly:hairpin::print grob))
31                (par-y (ly:grob-parent grob Y))
32                (dir (ly:grob-property par-y 'direction))
33                (new-stencil (ly:stencil-aligned-to
34                  (ly:stencil-combine-at-edge
35                    (ly:stencil-aligned-to stencil X CENTER)
36                    Y dir
37                    (ly:stencil-aligned-to
38                      (grob-interpret-markup grob text) X CENTER))
39                  X LEFT))
40                (staff-space (ly:output-def-lookup
41                  (ly:grob-layout grob) 'staff-space))
42                (staff-line-thickness
43                  (ly:output-def-lookup (ly:grob-layout grob) 'line-thickness))
44                (grob-name (lambda (x) (assq-ref
45                  (ly:grob-property x 'meta) 'name)))
46                (par-x (ly:grob-parent grob X))
47                (dyn-text (eq? (grob-name par-x) 'DynamicText ))
48                (dyn-text-stencil-x-length
49                  (if dyn-text
50                    (interval-length
51                      (ly:stencil-extent (ly:grob-property par-x 'stencil) X))
52                    0))
53                (x-shift
54                  (if dyn-text
55                    (-
56                      (+ staff-space dyn-text-stencil-x-length)
57                      (* 0.5 staff-line-thickness)) 0)))
58
59         (ly:grob-set-property! grob 'Y-offset 0)
60         (ly:grob-set-property! grob 'stencil
61            (ly:stencil-translate-axis
62             new-stencil
63             x-shift X))))
64   #})
65
66 hairpinMolto =
67 \hairpinWithCenteredText \markup { \italic molto }
68
69 hairpinMore =
70 \hairpinWithCenteredText \markup { \larger moltissimo }
71
72 \layout { ragged-right = ##f }
73
74 \relative c' {
75   \hairpinMolto
76   c2\< c\f
77   \hairpinMore
78   c2\ppppp\< c\f
79   \break
80   \hairpinMolto
81   c2^\< c\f
82   \hairpinMore
83   c2\ppppp\< c\f
84 }