]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/snippets/center-text-below-hairpin-dynamics.ly
Merge remote-tracking branch 'origin/master' into translation
[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.18.0"
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 (parser location 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 (grob-interpret-markup grob text) X CENTER))
38                  X LEFT))
39                (staff-space (ly:output-def-lookup (ly:grob-layout grob) 'staff-space))
40                (staff-line-thickness
41                  (ly:output-def-lookup (ly:grob-layout grob) 'line-thickness))
42                (grob-name (lambda (x) (assq-ref (ly:grob-property x 'meta) 'name)))
43                (par-x (ly:grob-parent grob X))
44                (dyn-text (eq? (grob-name par-x) 'DynamicText ))
45                (dyn-text-stencil-x-length
46                  (if dyn-text
47                    (interval-length
48                      (ly:stencil-extent (ly:grob-property par-x 'stencil) X))
49                    0))
50                (x-shift
51                  (if dyn-text
52                    (-
53                      (+ staff-space dyn-text-stencil-x-length)
54                      (* 0.5 staff-line-thickness)) 0)))
55
56         (ly:grob-set-property! grob 'Y-offset 0)
57         (ly:grob-set-property! grob 'stencil
58            (ly:stencil-translate-axis
59             new-stencil
60             x-shift X))))
61   #})
62
63 hairpinMolto =
64 \hairpinWithCenteredText \markup { \italic molto }
65
66 hairpinMore =
67 \hairpinWithCenteredText \markup { \larger moltissimo }
68
69 \layout { ragged-right = ##f }
70
71 \relative c' {
72   \hairpinMolto
73   c2\< c\f
74   \hairpinMore
75   c2\ppppp\< c\f
76   \break
77   \hairpinMolto
78   c2^\< c\f
79   \hairpinMore
80   c2\ppppp\< c\f
81 }