Minor improvements in full score.
[opera_libre.git] / definitions / functions.ly
blob786c80e2a70110413606b06494987013d4018db6
1 %------------------------------------------------------------------%
2 % Opéra Libre -- functions.ly %
3 % %
4 % (c) Valentin Villenave, 2008 %
5 % %
6 %------------------------------------------------------------------%
9 %%%%%%%%%%%%%%%%%%%%%%%%% Music Shortcuts %%%%%%%%%%%%%%%%%%%%%%%%%%
11 %% Rhythm shortcuts -----------------------------------------------%
13 t =
14 #(define-music-function (parser location music) (ly:music?)
15 #{ \times 2/3 $music #})
17 tt =
18 #(define-music-function (parser location music) (ly:music?)
19 #{ \times 4/5 $music #})
21 ttt =
22 #(define-music-function (parser location music) (ly:music?)
23 #{ \times 4/6 $music #})
25 tttt =
26 #(define-music-function (parser location music) (ly:music?)
27 #{ \times 4/7 $music #})
30 %% Polyphony shortcuts --------------------------------------------%
32 pl =
33 #(define-music-function (parser location one two) (ly:music? ly:music?)
34 #{ << { \voiceTwo $one } \\ { \voiceOne $two } >> #})
36 parallel=
37 #(define-music-function (parser location droite gauche) (ly:music? ly:music?)
38 #{ <<
39 \context Staff = "droite" $droite
40 \context Staff = "gauche" $gauche
41 >> #})
43 PianoDeuxMains=
44 #(define-music-function (parser location droite gauche) (ly:music? ly:music?)
45 #{ <<
46 \new Staff = "droite" \with { \override VerticalAxisGroup #'remove-empty = ##f }
47 $droite
48 \new Staff = "gauche" \with { \override VerticalAxisGroup #'remove-empty = ##f }
49 $gauche
50 >> #})
52 %% Articulation shortcuts -----------------------------------------%
54 % Are these really needed?
55 #(define (make-script x)
56 (make-music 'ArticulationEvent
57 'articulation-type x))
59 #(define (add-script m x)
60 (let ( (eventname (ly:music-property m 'name)))
61 (if (equal? eventname 'EventChord)
62 (let ( (elements (ly:music-property m 'elements)) )
63 (if (not (equal? (ly:music-property (car elements)
64 'name) 'RestEvent))
65 (set! (ly:music-property m 'elements)
66 (append elements (list
67 (make-script x)))))))
68 m))
70 #(define (double-script m t tt)
71 (add-script (add-script m t) tt))
73 st =
74 #(define-music-function (parser location music)
75 (ly:music?)
76 (define (make-script-music m)
77 (add-script m "staccato"))
78 (music-map make-script-music music))
80 acc =
81 #(define-music-function (parser location music)
82 (ly:music?)
83 (define (make-script-music m)
84 (add-script m "accent"))
85 (music-map make-script-music music))
87 det =
88 #(define-music-function (parser location music)
89 (ly:music?)
90 (define (make-script-music m)
91 (add-script m "tenuto"))
92 (music-map make-script-music music))
94 marc =
95 #(define-music-function (parser location music)
96 (ly:music?)
97 (define (make-script-music m)
98 (add-script m "marcato"))
99 (music-map make-script-music music))
101 stdet =
102 #(define-music-function (parser location music)
103 (ly:music?)
104 (define (make-script-music m)
105 (add-script m "portato"))
106 (music-map make-script-music music))
108 accdet =
109 #(define-music-function (parser location music)
110 (ly:music?)
111 (define (make-script-music m)
112 (double-script m "tenuto" "accent"))
113 (music-map make-script-music music))
115 marcdet =
116 #(define-music-function (parser location music)
117 (ly:music?)
118 (define (make-script-music m)
119 (double-script m "tenuto" "marcato"))
120 (music-map make-script-music music))
122 accst =
123 #(define-music-function (parser location music)
124 (ly:music?)
125 (define (make-script-music m)
126 (double-script m "accent" "staccato"))
127 (music-map make-script-music music))
129 marcst =
130 #(define-music-function (parser location music)
131 (ly:music?)
132 (define (make-script-music m)
133 (double-script m "marcato" "staccato"))
134 (music-map make-script-music music))
137 CaV=
138 #(let ((m (make-music 'ArticulationEvent
139 'articulation-type "flageolet")))
140 (set! (ly:music-property m 'tweaks)
141 (acons 'font-size -3
142 (ly:music-property m 'tweaks)))
146 %% Music shortcuts ------------------------------------------------%
148 % This might not be needed
149 #(define (octave-up noteevent)
150 (let* ((pitch (ly:music-property noteevent 'pitch))
151 (octave (ly:pitch-octave pitch))
152 (note (ly:pitch-notename pitch))
153 (alteration (ly:pitch-alteration pitch))
154 (duration (ly:music-property noteevent 'duration))
155 (newnoteevent
156 (make-music 'NoteEvent
157 'duration duration
158 'pitch (ly:make-pitch (1- octave) note alteration))))
159 newnoteevent))
161 #(define (octavize-chord elements)
162 (cond ((null? elements) elements)
163 ((eq? (ly:music-property (car elements) 'name) 'NoteEvent)
164 (cons (car elements)
165 (cons (octave-up (car elements))
166 (octavize-chord (cdr elements)))))
167 (else (cons (car elements) (octavize-chord (cdr elements))))))
169 #(define (octavize music)
170 (let* ((es (ly:music-property music 'elements))
171 (e (ly:music-property music 'element))
172 (name (ly:music-property music 'name)))
173 (cond ((eq? name 'EventChord)
174 (ly:music-set-property! music 'elements (octavize-chord es)))
175 ((pair? es)
176 (for-each (lambda(x) (octavize x)) es))
177 ((ly:music? e)
178 (octavize e))))
179 music)
181 oct = #(define-music-function (parser location mus) (ly:music?)
182 (octavize mus))
184 %%%%%%%%%%%%%%%%%%%%%%%% Layout Functions %%%%%%%%%%%%%%%%%%%%%%%%%%
186 %% Music layout ---------------------------------------------------%
188 droite = { \change StaffPiano = "droite" }
190 gauche = { \change StaffPiano = "gauche" }
192 #(define modern-auto-beam-settings
193 (append default-auto-beam-settings
195 ((end * * 3 4) . ,(ly:make-moment 1 4))
196 ((end * * 3 4) . ,(ly:make-moment 1 2))
197 ((end * * 4 4) . ,(ly:make-moment 1 4))
198 ((end * * 4 4) . ,(ly:make-moment 3 4))
199 ((end * * 2 2) . ,(ly:make-moment 1 4))
200 ((end * * 2 2) . ,(ly:make-moment 1 2))
201 ((end * * 2 2) . ,(ly:make-moment 3 4))
202 ((end * * 2 8) . ,(ly:make-moment 1 4))
203 ((be * * 5 8) . ,(ly:make-moment 1 8))
204 ((end * * 5 8) . ,(ly:make-moment 5 8))
207 #(define modern-style
208 '(Staff
209 (same-octave . 0)
210 (any-octave . 0)
211 (same-octave . 1)))
213 %% Music formatting -----------------------------------------------%
215 graceNotes =
216 #(define-music-function (parser location notes) (ly:music?)
217 #{ \tiny $notes \normalsize #})
219 parlato =
220 #(define-music-function (parser location notes) (ly:music?)
221 #{ \override NoteHead #'style = #'cross
222 $notes
223 \revert NoteHead #'style #})
225 hideNote = {
226 \once \override NoteHead #'transparent = ##t
227 \once \override NoteHead #'no-ledgers = ##t
228 \once \override Stem #'transparent = ##t
229 \once \override Beam #'transparent = ##t
230 \once \override Accidental #'transparent = ##t
232 %%%%%%%%%%%%%%%%%%%%%%%%%% In-score Text %%%%%%%%%%%%%%%%%%%%%%%%%%%
234 %% Expressive indications -----------------------------------------%
236 #(define-markup-command (indic layout props arg) (markup?)
237 (interpret-markup layout props
238 (markup #:whiteout #:small #:italic arg)))
240 cmb =
241 #(define-music-function (parser location nuance texte )
242 (string? string? )
243 (make-dynamic-script
244 (markup #:dynamic nuance
245 #:hspace .6
246 #:text #:medium #:upright texte )))
248 bmc =
249 #(define-music-function (parser location texte nuance )
250 (string? string? )
251 (make-dynamic-script
252 (markup #:text #:medium #:upright texte
253 #:hspace .6
254 #:dynamic nuance )))
256 ten =
257 #(define-music-function (parser location music) (ly:music?)
259 (equal? (ly:music-property music 'name) 'EventChord)
260 (set! (ly:music-property music 'elements)
261 (append (ly:music-property music 'elements)
262 (list (make-music 'TextScriptEvent 'text
263 (markup #:translate (cons 4 0)
264 #:indic "(ten.)"))))))
265 music)
267 ind =
268 #(define-music-function (parser location text music) (string? ly:music?)
270 (equal? (ly:music-property music 'name) 'EventChord)
271 (set! (ly:music-property music 'elements)
272 (append (ly:music-property music 'elements)
273 (list (make-music 'TextScriptEvent 'direction 1
274 'text (markup #:indic text))))))
275 music)
277 pizz =
278 #(define-music-function (parser location music) (ly:music?)
279 #{ \ind #"pizz." $music #})
281 arco =
282 #(define-music-function (parser location music) (ly:music?)
283 #{ \ind #"arco" $music #})
285 simile =
286 #(define-music-function (parser location music) (ly:music?)
287 #{ \ind #"simile" $music #})
289 #(define (make-text-span music t)
290 (set! (ly:music-property music 'elements)
291 (append (ly:music-property music 'elements)
292 (list (make-music 'TextSpanEvent
293 'span-direction t))))
294 music)
295 startTxt =
296 #(define-music-function (parser location texte music ) (string? ly:music?)
297 #{ \override TextSpanner #'bound-details #'left #'text =
298 \markup { \bold $texte }
299 $(make-text-span music -1)#})
301 stopTxt =
302 #(define-music-function (parser location music ) (ly:music?)
303 (make-text-span music 1))
305 %% Tempo indications ----------------------------------------------%
306 #(define-markup-command (mvt layout props arg) (markup?)
307 (interpret-markup layout props
308 (markup #:huge #:bold arg)))
310 %%%%%%%%%%%%%%%%%%%%%%%%%% Text Functions %%%%%%%%%%%%%%%%%%%%%%%%%%
312 %% Lyrics formatting ----------------------------------------------%
314 freestyleOn = {
315 \override Lyrics . LyricExtender #'stencil = ##f }
317 freestyleOff = {
318 \revert Lyrics . LyricExtender #'stencil }
320 leftSyl = {
321 \once \override LyricText #'self-alignment-X = #0.9 }
323 dash = {
324 \once \override LyricHyphen #'minimum-distance = #4
325 \once \override LyricHyphen #'length = #2
326 \once \override LyricHyphen #'thickness = #1.2
329 ital = {
330 \once \override LyricText #'font-shape = #'italic }
332 smallcaps = {
333 \override LyricText #'font-shape = #'caps }
335 normal = {
336 \revert LyricText #'font-shape }
339 %% Scenography formatting ---------------------------------------%
340 long = {
341 \once \override TextScript #'extra-spacing-width = #'(0 . 0)
342 \once \override TextScript #'infinite-spacing-height = ##t
345 #(define-markup-command (did layout props text) (markup?)
346 (interpret-markup layout props
347 (markup #:override '(line-width . 40)
348 #:override '(box-padding . 1)
349 #:override '(corner-radius . 2)
350 #:rounded-box #:sans #:italic #:small #:justify-string text)))
352 #(define-markup-command (init-did layout props text) (markup?)
353 (interpret-markup layout props
354 (markup
355 ; #:override (cons 'line-width (* 1 (chain-assoc-get 'line-width props)))
356 #:fill-line (
357 #:override '(line-width . 60)
358 #:override '(box-padding . 1.5)
359 #:override '(corner-radius . 2)
360 #:rounded-box #:sans #:italic #:small #:justify-string text))))
362 #(define-markup-command (vspace layout props amount) (number?)
363 (let ((amount (* amount 3.0)))
364 (if (> amount 0)
365 (ly:make-stencil "" (cons -1 1) (cons 0 amount))
366 (ly:make-stencil "" (cons -1 1) (cons amount amount)))))