]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/snippets/new/horizontally-aligning-custom-dynamics-e.g.-sempre-pp,-piu-f,-subito-p.ly
Snippets: Replace \set Staff.instrumentName
[lilypond.git] / Documentation / snippets / new / horizontally-aligning-custom-dynamics-e.g.-sempre-pp,-piu-f,-subito-p.ly
1 \version "2.19.56"
2
3 \header {
4   lsrtags = "expressive-marks, tweaks-and-overrides, version-specific"
5
6   texidoc = "
7 Some dynamic expressions involve additional text, like @qq{sempre pp}.
8 Since dynamics are usually centered under the note, the \\pp would be
9 displayed way after the note it applies to.
10
11 To correctly align the @qq{sempre pp} horizontally, so that it is
12 aligned as if it were only the \\pp, there are several approaches:
13
14 * Simply use @code{\\once\\override DynamicText.X-offset = #-9.2}
15 before the note with the dynamics to manually shift it to the correct
16 position. Drawback: This has to be done manually each time you use that
17 dynamic markup...
18
19 * Add some padding (@code{#:hspace 7.1}) into the definition of your
20 custom dynamic mark, so that after lilypond center-aligns it, it is
21 already correctly aligned. Drawback: The padding really takes up that
22 space and does not allow any other markup or dynamics to be shown in
23 that position.
24
25 * Shift the dynamic script @code{\\once\\override ... .X-offset = ..}.
26 Drawback: @code{\\once\\override} is needed for every invocation!
27
28 * Set the dimensions of the additional text to 0 (using
29 @code{#:with-dimensions '(0 . 0) '(0 . 0)}). Drawback: To LilyPond
30 @qq{sempre} has no extent, so it might put other stuff there and create
31 collisions (which are not detected by the collision detection!). Also,
32 there seems to be some spacing, so it's not exactly the same alignment
33 as without the additional text
34
35 * Add an explicit shifting directly inside the scheme function for the
36 dynamic-script.
37
38 * Set an explicit alignment inside the dynamic-script. By default, this
39 won't have any effect, only if one sets X-offset! Drawback: One needs
40 to set @code{DynamicText.X-offset}, which will apply to all dynamic
41 texts! Also, it is aligned at the right edge of the additional text,
42 not at the center of pp.
43
44
45
46
47 "
48   doctitle = "Horizontally aligning custom dynamics (e.g. \"sempre pp\" \"piu f\" \"subito p\")"
49 } % begin verbatim
50
51 \paper {
52   ragged-right = ##f
53   indent = 2.5\cm
54 }
55
56 % Solution 1: Using a simple markup with a particular halign value
57 % Drawback: It's a markup, not a dynamic command, so \dynamicDown
58 %           etc. will have no effect
59 semppMarkup = \markup { \halign #1.4 \italic "sempre" \dynamic "pp" }
60
61 % Solution 2: Using a dynamic script & shifting with
62 %             \once \override ...X-offset = ..
63 % Drawback: \once \override needed for every invocation
64 semppK =
65 #(make-dynamic-script
66   (markup #:line
67           (#:normal-text
68            #:italic "sempre"
69            #:dynamic "pp")))
70
71 % Solution 3: Padding the dynamic script so the center-alignment
72 %             puts it at the correct position
73 % Drawback: the padding really reserves the space, nothing else can be there
74 semppT =
75 #(make-dynamic-script
76   (markup #:line
77           (#:normal-text
78            #:italic "sempre"
79            #:dynamic "pp"
80            #:hspace 7.1)))
81
82 % Solution 4: Dynamic, setting the dimensions of the additional text to 0
83 % Drawback: To lilypond "sempre" has no extent, so it might put
84 %           other stuff there => collisions
85 % Drawback: Also, there seems to be some spacing, so it's not exactly the
86 %           same alignment as without the additional text
87 semppM =
88 #(make-dynamic-script
89   (markup #:line
90           (#:with-dimensions '(0 . 0) '(0 . 0)
91                              #:right-align
92                              #:normal-text
93                              #:italic "sempre"
94                              #:dynamic "pp")))
95
96 % Solution 5: Dynamic with explicit shifting inside the scheme function
97 semppG =
98 #(make-dynamic-script
99   (markup #:hspace 0
100           #:translate '(-18.85 . 0)
101           #:line (#:normal-text
102                   #:italic "sempre"
103                   #:dynamic "pp")))
104
105 % Solution 6: Dynamic with explicit alignment. This has only effect
106 %             if one sets X-offset!
107 % Drawback: One needs to set DynamicText.X-offset!
108 % Drawback: Aligned at the right edge of the additional text,
109 %           not at the center of pp
110 semppMII =
111 #(make-dynamic-script
112   (markup #:line (#:right-align
113                   #:normal-text
114                   #:italic "sempre"
115                   #:dynamic "pp")))
116
117 \new StaffGroup <<
118   \new Staff = "s" \with { instrumentName = \markup \column { Normal } }
119   <<
120     \relative c'' {
121       \key es \major
122       c4\pp c\p c c | c\ff c c\pp c
123     }
124   >>
125   \new Staff = "sMarkup" \with {
126     instrumentName = \markup \column { Normal markup }
127   }
128   <<
129     \relative c'' {
130       \key es \major
131       c4-\semppMarkup c\p c c | c\ff c c-\semppMarkup c
132     }
133   >>
134   \new Staff = "sK" \with {
135     instrumentName = \markup \column { Explicit shifting }
136   }
137   <<
138     \relative c'' {
139       \key es \major
140       \once \override DynamicText.X-offset = #-9.2
141       c4\semppK c\p c c
142       c4\ff c
143       \once \override DynamicText.X-offset = #-9.2
144       c4\semppK c
145     }
146   >>
147   \new Staff = "sT" \with {
148     instrumentName = \markup \column { Right padding }
149   }
150   <<
151     \relative c'' {
152       \key es \major
153       c4\semppT c\p c c | c\ff c c\semppT c
154     }
155   >>
156   \new Staff = "sM" \with {
157     instrumentName = \markup \column { Set dimension "to zero" }
158   }
159   <<
160     \relative c'' {
161       \key es \major
162       c4\semppM c\p c c | c\ff c c\semppM c
163     }
164   >>
165   \new Staff = "sG" \with {
166     instrumentName = \markup \column { Shift inside dynamics}
167   }
168   <<
169     \relative c'' {
170       \key es \major
171       c4\semppG c\p c c | c\ff c c\semppG c
172     }
173   >>
174   \new Staff = "sMII" \with {
175     instrumentName = \markup \column { Alignment inside dynamics }
176   }
177   <<
178     \relative c'' {
179       \key es \major
180       % Setting to ##f (false) gives the same result
181       \override DynamicText.X-offset = #0
182       c4\semppMII c\p c c | c\ff c c\semppMII c
183     }
184   >>
185 >>
186
187 \layout { \override Staff.InstrumentName.self-alignment-X = #LEFT }