Added slap function for flutes
[opera_libre.git] / definitions / functions.ly
blobcc32eea19e78290b8e30444b6b1b11a1fac46ab6
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 { \clef treble $droite }
48 \new Staff = "gauche" \with { \override VerticalAxisGroup #'remove-empty = ##f }
49 { \clef bass $gauche }
50 >> #})
52 harmo =
53 #(define-music-function (parser location chord result) (ly:music? ly:music?)
54 #{ << \oneVoice $chord \\ { \voiceTwo %FIXME: ties could look better.
55 \override NoteHead #'stencil = #ly:text-interface::print
56 \override NoteHead #'text = \markup { \null \musicglyph #"noteheads.s2"}
57 \once \override NoteHead #'text = \markup {\null \override #'(direction . 1)
58 \dir-column {\musicglyph #"noteheads.s2" \teeny \musicglyph #"eight"}}
59 \override Stem #'stencil = ##f $result
60 \revert Stem #'stencil \revert NoteHead #'stencil } >> #})
62 %% Articulation shortcuts -----------------------------------------%
64 % Are these really needed?
65 #(define (make-script x)
66 (make-music 'ArticulationEvent
67 'articulation-type x))
69 #(define (add-script m x)
70 (let ( (eventname (ly:music-property m 'name)))
71 (if (equal? eventname 'EventChord)
72 (let ( (elements (ly:music-property m 'elements)) )
73 (if (not (equal? (ly:music-property (car elements)
74 'name) 'RestEvent))
75 (set! (ly:music-property m 'elements)
76 (append elements (list
77 (make-script x)))))))
78 m))
80 #(define (double-script m t tt)
81 (add-script (add-script m t) tt))
83 st =
84 #(define-music-function (parser location music)
85 (ly:music?)
86 (define (make-script-music m)
87 (add-script m "staccato"))
88 (music-map make-script-music music))
90 acc =
91 #(define-music-function (parser location music)
92 (ly:music?)
93 (define (make-script-music m)
94 (add-script m "accent"))
95 (music-map make-script-music music))
97 det =
98 #(define-music-function (parser location music)
99 (ly:music?)
100 (define (make-script-music m)
101 (add-script m "tenuto"))
102 (music-map make-script-music music))
104 marc =
105 #(define-music-function (parser location music)
106 (ly:music?)
107 (define (make-script-music m)
108 (add-script m "marcato"))
109 (music-map make-script-music music))
111 stdet =
112 #(define-music-function (parser location music)
113 (ly:music?)
114 (define (make-script-music m)
115 (add-script m "portato"))
116 (music-map make-script-music music))
118 accdet =
119 #(define-music-function (parser location music)
120 (ly:music?)
121 (define (make-script-music m)
122 (double-script m "tenuto" "accent"))
123 (music-map make-script-music music))
125 marcdet =
126 #(define-music-function (parser location music)
127 (ly:music?)
128 (define (make-script-music m)
129 (double-script m "tenuto" "marcato"))
130 (music-map make-script-music music))
132 accst =
133 #(define-music-function (parser location music)
134 (ly:music?)
135 (define (make-script-music m)
136 (double-script m "accent" "staccato"))
137 (music-map make-script-music music))
139 marcst =
140 #(define-music-function (parser location music)
141 (ly:music?)
142 (define (make-script-music m)
143 (double-script m "marcato" "staccato"))
144 (music-map make-script-music music))
147 CaV=
148 #(let ((m (make-music 'ArticulationEvent
149 'articulation-type "flageolet")))
150 (set! (ly:music-property m 'tweaks)
151 (acons 'font-size -3
152 (ly:music-property m 'tweaks)))
155 thumbpizz =
156 #(make-music 'TextScriptEvent
157 'direction 1
158 'text (markup #:hspace .4 #:rotate 45
159 #:musicglyph "scripts.stopped"))
161 %% Music shortcuts ------------------------------------------------%
163 % This might not be needed
164 #(define (octave-up noteevent)
165 (let* ((pitch (ly:music-property noteevent 'pitch))
166 (octave (ly:pitch-octave pitch))
167 (note (ly:pitch-notename pitch))
168 (alteration (ly:pitch-alteration pitch))
169 (duration (ly:music-property noteevent 'duration))
170 (newnoteevent
171 (make-music 'NoteEvent
172 'duration duration
173 'pitch (ly:make-pitch (1- octave) note alteration))))
174 newnoteevent))
176 #(define (octavize-chord elements)
177 (cond ((null? elements) elements)
178 ((eq? (ly:music-property (car elements) 'name) 'NoteEvent)
179 (cons (car elements)
180 (cons (octave-up (car elements))
181 (octavize-chord (cdr elements)))))
182 (else (cons (car elements) (octavize-chord (cdr elements))))))
184 #(define (octavize music)
185 (let* ((es (ly:music-property music 'elements))
186 (e (ly:music-property music 'element))
187 (name (ly:music-property music 'name)))
188 (cond ((eq? name 'EventChord)
189 (ly:music-set-property! music 'elements (octavize-chord es)))
190 ((pair? es)
191 (for-each (lambda(x) (octavize x)) es))
192 ((ly:music? e)
193 (octavize e))))
194 music)
196 oct = #(define-music-function (parser location mus) (ly:music?)
197 (octavize mus))
199 %%%%%%%%%%%%%%%%%%%%%%%% Layout Functions %%%%%%%%%%%%%%%%%%%%%%%%%%
201 %% Music layout ---------------------------------------------------%
203 droite = { \change Staff = "droite" }
205 gauche = { \change Staff = "gauche" }
207 #(define modern-auto-beam-settings
208 (append default-auto-beam-settings
210 ((end * * 3 4) . ,(ly:make-moment 1 4))
211 ((end * * 3 4) . ,(ly:make-moment 1 2))
212 ((end * * 4 4) . ,(ly:make-moment 1 4))
213 ((end * * 4 4) . ,(ly:make-moment 3 4))
214 ((end * * 2 2) . ,(ly:make-moment 1 4))
215 ((end * * 2 2) . ,(ly:make-moment 1 2))
216 ((end * * 2 2) . ,(ly:make-moment 3 4))
217 ((end * * 2 8) . ,(ly:make-moment 1 4))
218 ((be * * 5 8) . ,(ly:make-moment 1 8))
219 ((end * * 5 8) . ,(ly:make-moment 5 8))
222 #(define modern-accidentals-style
223 `(Staff ,(make-accidental-rule 'same-octave 0)
224 ,(make-accidental-rule 'any-octave 0)
225 ,(make-accidental-rule 'same-octave 1)
226 ,neo-modern-accidental-rule))
227 #(define modern-cautionaries-style
228 `(Staff ,(make-accidental-rule 'same-octave 1)
229 ,(make-accidental-rule 'any-octave 1)))
231 %% Music formatting -----------------------------------------------%
233 graceNotes =
234 #(define-music-function (parser location notes) (ly:music?)
235 #{ \tiny $notes \normalsize #})
237 parlato =
238 #(define-music-function (parser location notes) (ly:music?)
239 #{ \override NoteHead #'style = #'cross
240 $notes
241 \revert NoteHead #'style #})
243 slap =
244 #(define-music-function (parser location music) (ly:music?)
245 #{\override NoteHead #'stencil = #ly:text-interface::print
246 \override NoteHead #'text = \markup \musicglyph #"scripts.sforzato"
247 \override NoteHead #'extra-offset = #'(0.1 . 0.0 )
248 $music
249 \revert NoteHead #'stencil
250 \revert NoteHead #'text
251 \revert NoteHead #'extra-offset #})
253 hideNote = {
254 \once \override NoteHead #'transparent = ##t
255 \once \override NoteHead #'no-ledgers = ##t
256 \once \override Stem #'transparent = ##t
257 \once \override Beam #'transparent = ##t
258 \once \override Accidental #'transparent = ##t
261 noTuplet = {
262 \once \override TupletBracket #'transparent = ##t
263 \once \override TupletNumber #'transparent = ##t
265 %%%%%%%%%%%%%%%%%%%%%%%%%% In-score Text %%%%%%%%%%%%%%%%%%%%%%%%%%%
267 %% Expressive indications -----------------------------------------%
269 #(define-markup-command (indic layout props arg) (markup?)
270 (interpret-markup layout props
271 (markup #:whiteout #:small #:italic arg)))
273 % because of the use of a music-function,
274 % non-predefined composite dynamics have to be entered *before*
275 % the affected beat (unlike standard or predefined dynamics).
276 cmb =
277 #(define-music-function (parser location dyn str) (string? string?)
278 (make-music 'SequentialMusic 'elements
279 (list
280 (make-music 'OverrideProperty
281 'symbol 'DynamicText
282 'grob-property-path (list 'self-alignment-X)
283 'grob-value -0.6 'once #t)
284 (make-music 'AbsoluteDynamicEvent
285 'text
286 (markup #:dynamic dyn
287 #:hspace .5
288 #:text #:medium #:upright str)))))
290 bmc =
291 #(define-music-function (parser location str dyn) (string? string?)
292 (make-music 'SequentialMusic 'elements
293 (list
294 (make-music 'OverrideProperty
295 'symbol 'DynamicText
296 'grob-property-path (list 'self-alignment-X)
297 'grob-value -0.6 'once #t)
298 (make-music 'AbsoluteDynamicEvent
299 'text
300 (markup #:text #:medium #:upright str
301 #:hspace .5
302 #:dynamic dyn)))))
304 %%% This function was provided by Graham Percival.
305 #(define (make-dynamic-extra dynamic string)
306 (make-music
307 'AbsoluteDynamicEvent
308 'tweaks
309 ;; calculate centering for text
310 (list (cons (quote X-offset)
311 (+ -0.5 (* -0.5 (string-length dynamic)))))
312 'text
313 (markup
314 ;; uncomment next line for debugging
315 ;;#:box
316 #:line(
317 dynamic
318 #:hspace -0.3
319 #:normal-text #:italic string))
322 #(define (make-extra-dynamic string dynamic)
323 (make-music
324 'AbsoluteDynamicEvent
325 'tweaks
326 ;; calculate centering for text
327 (list (cons (quote X-offset)
328 (+ -0.5 (* -0.5 (string-length dynamic)))))
329 'text
330 (markup
331 ;; uncomment next line for debugging
332 ;;#:box
333 #:line(
334 #:normal-text #:italic string
335 #:hspace -0.3
336 #:dynamic dynamic))
339 ffsubito = #(make-dynamic-extra "ff" "subito")
340 fsubito = #(make-dynamic-extra "f" "subito")
341 fmolto = #(make-dynamic-extra "f" "molto")
342 ppsempre = #(make-dynamic-extra "pp" "sempre")
343 mfsempre = #(make-dynamic-extra "mf" "sempre")
344 mpsostenuto = #(make-dynamic-extra "mp" "sostenuto")
345 pdolce = #(make-dynamic-extra "p" "dolce")
346 mfleggiero = #(make-dynamic-extra "mf" "leggiero")
348 piuf = #(make-extra-dynamic "più" "f")
349 pocof = #(make-extra-dynamic "poco" "f")
351 nind =
352 #(define-music-function (parser location texte)
353 (string? )
354 (make-dynamic-script
355 (markup #:text #:indic texte)))
357 ten =
358 #(define-music-function (parser location music) (ly:music?)
360 (equal? (ly:music-property music 'name) 'EventChord)
361 (set! (ly:music-property music 'elements)
362 (append (ly:music-property music 'elements)
363 (list (make-music 'TextScriptEvent 'text
364 (markup #:translate (cons 4 0)
365 #:indic "(ten.)"))))))
366 music)
368 ind =
369 #(define-music-function (parser location text music) (string? ly:music?)
371 (equal? (ly:music-property music 'name) 'EventChord)
372 (set! (ly:music-property music 'elements)
373 (append (ly:music-property music 'elements)
374 (list (make-music 'TextScriptEvent 'direction 1
375 'text (markup #:indic text))))))
376 music)
378 pizz =
379 #(define-music-function (parser location music) (ly:music?)
380 #{ \ind #"pizz." $music #})
382 arco =
383 #(define-music-function (parser location music) (ly:music?)
384 #{ \ind #"arco" $music #})
386 simile =
387 #(define-music-function (parser location music) (ly:music?)
388 #{ \ind #"simile" $music #})
390 loco =
391 #(define-music-function (parser location music) (ly:music?)
392 #{ \ind #"loco" $music #})
394 ordin =
395 #(define-music-function (parser location music) (ly:music?)
396 #{ \ind #"(ordin.)" $music #})
398 #(define (make-text-span music t)
399 (set! (ly:music-property music 'elements)
400 (append (ly:music-property music 'elements)
401 (list (make-music 'TextSpanEvent
402 'span-direction t))))
403 music)
404 startTxt =
405 #(define-music-function (parser location texte music ) (string? ly:music?)
406 #{ \override TextSpanner #'bound-details #'left #'text =
407 \markup { \bold $texte }
408 $(make-text-span music -1)#})
410 stopTxt =
411 #(define-music-function (parser location music ) (ly:music?)
412 (make-text-span music 1))
414 %% Tempo indications ----------------------------------------------%
415 #(define-markup-command (mvt layout props arg) (markup?)
416 (interpret-markup layout props
417 (markup #:huge #:bold arg)))
419 %%%%%%%%%%%%%%%%%%%%%%%%%% Text Functions %%%%%%%%%%%%%%%%%%%%%%%%%%
421 %% Lyrics formatting ----------------------------------------------%
423 freestyleOn = {
424 \override Lyrics . LyricExtender #'stencil = ##f }
426 freestyleOff = {
427 \revert Lyrics . LyricExtender #'stencil }
429 leftSyl = {
430 \once \override LyricText #'self-alignment-X = #0.9 }
432 dash = {
433 \once \override LyricHyphen #'minimum-distance = #4
434 \once \override LyricHyphen #'length = #2
435 \once \override LyricHyphen #'thickness = #1.2
438 ital = {
439 \once \override LyricText #'font-shape = #'italic }
441 smallcaps = {
442 \override LyricText #'font-shape = #'caps }
444 normal = {
445 \revert LyricText #'font-shape }
448 %% Scenography formatting ---------------------------------------%
449 long = {
450 \once \override TextScript #'extra-spacing-width = #'(0 . 0)
451 \once \override TextScript #'infinite-spacing-height = ##t
454 #(define-markup-command (did layout props text) (markup?)
455 (interpret-markup layout props
456 (markup #:override '(line-width . 40)
457 #:override '(box-padding . 1)
458 #:override '(corner-radius . 2)
459 #:rounded-box #:sans #:italic #:small #:justify-string text)))
461 #(define-markup-command (init-did layout props text) (markup?)
462 (interpret-markup layout props
463 (markup
464 ; #:override (cons 'line-width (* 1 (chain-assoc-get 'line-width props)))
465 #:fill-line (
466 #:override '(line-width . 60)
467 #:override '(box-padding . 1.5)
468 #:override '(corner-radius . 2)
469 #:rounded-box #:sans #:italic #:small #:justify-string text))))
471 #(define-markup-command (vspace layout props amount) (number?)
472 (let ((amount (* amount 3.0)))
473 (if (> amount 0)
474 (ly:make-stencil "" (cons -1 1) (cons 0 amount))
475 (ly:make-stencil "" (cons -1 1) (cons amount amount)))))