]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/snippets/center-text-below-hairpin-dynamics.ly
Rerun scripts/auxiliar/update-with-convert-ly.sh
[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.dsi.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.17.6"
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.  The example also
17 illustrates how to modify the way an object is normally printed, using
18 some Scheme code.
19
20 "
21   doctitle = "Center text below hairpin dynamics"
22 } % begin verbatim
23
24 hairpinWithCenteredText =
25 #(define-music-function (parser location text) (markup?)
26 #{
27   \once \override Voice.Hairpin.after-line-breaking =
28     #(lambda (grob)
29       (let* ((stencil (ly:hairpin::print grob))
30              (par-y (ly:grob-parent grob Y))
31              (dir (ly:grob-property par-y 'direction))
32              (new-stencil (ly:stencil-aligned-to
33                    (ly:stencil-combine-at-edge
34                      (ly:stencil-aligned-to stencil X CENTER)
35                      Y dir
36                      (ly:stencil-aligned-to (grob-interpret-markup grob text) X CENTER))
37                      X LEFT))
38              (staff-space (ly:output-def-lookup (ly:grob-layout grob) 'staff-space))
39              (staff-line-thickness (ly:output-def-lookup (ly:grob-layout grob) 'line-thickness))
40              (grob-name (lambda (x) (assq-ref (ly:grob-property x 'meta) 'name)))
41              (par-x (ly:grob-parent grob X))
42              (dyn-text (eq? (grob-name par-x) 'DynamicText ))
43              (dyn-text-stencil-x-length (if dyn-text
44                                            (interval-length (ly:stencil-extent (ly:grob-property par-x 'stencil) X))
45                                            0))
46              (x-shift (if dyn-text (- (+ staff-space dyn-text-stencil-x-length) (* 0.5 staff-line-thickness)) 0)))
47
48       (ly:grob-set-property! grob 'Y-offset 0)
49       (ly:grob-set-property! grob 'stencil
50          (ly:stencil-translate-axis
51           new-stencil
52           x-shift X))))
53 #})
54
55 hairpinMolto =
56 \hairpinWithCenteredText \markup { \italic molto }
57
58 hairpinMore =
59 \hairpinWithCenteredText \markup { \larger moltissimo }
60
61 \layout { ragged-right = ##f }
62
63 \relative c' {
64   \hairpinMolto
65   c2\< c\f
66   \hairpinMore
67   c2\ppppp\< c\f
68   \break
69   \hairpinMolto
70   c2^\< c\f
71   \hairpinMore
72   c2\ppppp\< c\f
73 }