ActeUnSceneTroisTer, take 2...
[opera_libre.git] / definitions / functions.ly
blob5b163573da317c1d8817e004f9620e5296f701df
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 %% 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 Staff = "droite" }
190 gauche = { \change Staff = "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 ,(make-accidental-rule 'same-octave 0)
209 ,(make-accidental-rule 'any-octave 0)
210 ,(make-accidental-rule 'same-octave 1)
211 ,neo-modern-accidental-rule))
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 %FIXME: because of the use of a music-function,
241 % Composite dynamics have to be entered *before*
242 % the affected beat (unlike standard dynamics).
243 cmb =
244 #(define-music-function (parser location dyn str) (string? string?)
245 (make-music 'SequentialMusic 'elements
246 (list
247 (make-music 'OverrideProperty
248 'symbol 'DynamicText
249 'grob-property-path (list 'self-alignment-X)
250 'grob-value -0.6 'once #t)
251 (make-music 'AbsoluteDynamicEvent
252 'text
253 (markup #:dynamic dyn
254 #:hspace .5
255 #:text #:medium #:upright str)))))
257 bmc =
258 #(define-music-function (parser location str dyn) (string? string?)
259 (make-music 'SequentialMusic 'elements
260 (list
261 (make-music 'OverrideProperty
262 'symbol 'DynamicText
263 'grob-property-path (list 'self-alignment-X)
264 'grob-value -0.6 'once #t)
265 (make-music 'AbsoluteDynamicEvent
266 'text
267 (markup #:text #:medium #:upright str
268 #:hspace .5
269 #:dynamic dyn)))))
271 nind =
272 #(define-music-function (parser location texte)
273 (string? )
274 (make-dynamic-script
275 (markup #:text #:indic texte)))
277 ten =
278 #(define-music-function (parser location music) (ly:music?)
280 (equal? (ly:music-property music 'name) 'EventChord)
281 (set! (ly:music-property music 'elements)
282 (append (ly:music-property music 'elements)
283 (list (make-music 'TextScriptEvent 'text
284 (markup #:translate (cons 4 0)
285 #:indic "(ten.)"))))))
286 music)
288 ind =
289 #(define-music-function (parser location text music) (string? ly:music?)
291 (equal? (ly:music-property music 'name) 'EventChord)
292 (set! (ly:music-property music 'elements)
293 (append (ly:music-property music 'elements)
294 (list (make-music 'TextScriptEvent 'direction 1
295 'text (markup #:indic text))))))
296 music)
298 pizz =
299 #(define-music-function (parser location music) (ly:music?)
300 #{ \ind #"pizz." $music #})
302 arco =
303 #(define-music-function (parser location music) (ly:music?)
304 #{ \ind #"arco" $music #})
306 simile =
307 #(define-music-function (parser location music) (ly:music?)
308 #{ \ind #"simile" $music #})
310 loco =
311 #(define-music-function (parser location music) (ly:music?)
312 #{ \ind #"loco" $music #})
314 ordin =
315 #(define-music-function (parser location music) (ly:music?)
316 #{ \ind #"(ordin.)" $music #})
318 #(define (make-text-span music t)
319 (set! (ly:music-property music 'elements)
320 (append (ly:music-property music 'elements)
321 (list (make-music 'TextSpanEvent
322 'span-direction t))))
323 music)
324 startTxt =
325 #(define-music-function (parser location texte music ) (string? ly:music?)
326 #{ \override TextSpanner #'bound-details #'left #'text =
327 \markup { \bold $texte }
328 $(make-text-span music -1)#})
330 stopTxt =
331 #(define-music-function (parser location music ) (ly:music?)
332 (make-text-span music 1))
334 %% Tempo indications ----------------------------------------------%
335 #(define-markup-command (mvt layout props arg) (markup?)
336 (interpret-markup layout props
337 (markup #:huge #:bold arg)))
339 %%%%%%%%%%%%%%%%%%%%%%%%%% Text Functions %%%%%%%%%%%%%%%%%%%%%%%%%%
341 %% Lyrics formatting ----------------------------------------------%
343 freestyleOn = {
344 \override Lyrics . LyricExtender #'stencil = ##f }
346 freestyleOff = {
347 \revert Lyrics . LyricExtender #'stencil }
349 leftSyl = {
350 \once \override LyricText #'self-alignment-X = #0.9 }
352 dash = {
353 \once \override LyricHyphen #'minimum-distance = #4
354 \once \override LyricHyphen #'length = #2
355 \once \override LyricHyphen #'thickness = #1.2
358 ital = {
359 \once \override LyricText #'font-shape = #'italic }
361 smallcaps = {
362 \override LyricText #'font-shape = #'caps }
364 normal = {
365 \revert LyricText #'font-shape }
368 %% Scenography formatting ---------------------------------------%
369 long = {
370 \once \override TextScript #'extra-spacing-width = #'(0 . 0)
371 \once \override TextScript #'infinite-spacing-height = ##t
374 #(define-markup-command (did layout props text) (markup?)
375 (interpret-markup layout props
376 (markup #:override '(line-width . 40)
377 #:override '(box-padding . 1)
378 #:override '(corner-radius . 2)
379 #:rounded-box #:sans #:italic #:small #:justify-string text)))
381 #(define-markup-command (init-did layout props text) (markup?)
382 (interpret-markup layout props
383 (markup
384 ; #:override (cons 'line-width (* 1 (chain-assoc-get 'line-width props)))
385 #:fill-line (
386 #:override '(line-width . 60)
387 #:override '(box-padding . 1.5)
388 #:override '(corner-radius . 2)
389 #:rounded-box #:sans #:italic #:small #:justify-string text))))
391 #(define-markup-command (vspace layout props amount) (number?)
392 (let ((amount (* amount 3.0)))
393 (if (> amount 0)
394 (ly:make-stencil "" (cons -1 1) (cons 0 amount))
395 (ly:make-stencil "" (cons -1 1) (cons amount amount)))))