]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/snippets/center-text-below-hairpin-dynamics.ly
Imported Upstream version 2.19.45
[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                (par-x (ly:grob-parent grob X))
45                (dyn-text (grob::has-interface par-x 'dynamic-text-interface))
46                (dyn-text-stencil-x-length
47                  (if dyn-text
48                    (interval-length
49                      (ly:stencil-extent (ly:grob-property par-x 'stencil) X))
50                    0))
51                (x-shift
52                  (if dyn-text
53                    (-
54                      (+ staff-space dyn-text-stencil-x-length)
55                      (* 0.5 staff-line-thickness)) 0)))
56
57         (ly:grob-set-property! grob 'Y-offset 0)
58         (ly:grob-set-property! grob 'stencil
59            (ly:stencil-translate-axis
60             new-stencil
61             x-shift X))))
62   #})
63
64 hairpinMolto =
65 \hairpinWithCenteredText \markup { \italic molto }
66
67 hairpinMore =
68 \hairpinWithCenteredText \markup { \larger moltissimo }
69
70 \layout { ragged-right = ##f }
71
72 \relative c' {
73   \hairpinMolto
74   c2\< c\f
75   \hairpinMore
76   c2\ppppp\< c\f
77   \break
78   \hairpinMolto
79   c2^\< c\f
80   \hairpinMore
81   c2\ppppp\< c\f
82 }