Added didascalies to ActeDeuxSceneUn & ActeDeuxSceneUnBis
[opera_libre.git] / definitions / functions.ly
blob69b3f9f639207cab243e52c8691c833ba410fe4c
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 #(define (make-script x)
55 (make-music 'ArticulationEvent
56 'articulation-type x))
58 #(define (add-script m x)
59 (let ( (eventname (ly:music-property m 'name)))
60 (if (equal? eventname 'EventChord)
61 (let ( (elements (ly:music-property m 'elements)) )
62 (if (not (equal? (ly:music-property (car elements)
63 'name) 'RestEvent))
64 (set! (ly:music-property m 'elements)
65 (append elements (list
66 (make-script x)))))))
67 m))
69 #(define (double-script m t tt)
70 (add-script (add-script m t) tt))
72 st =
73 #(define-music-function (parser location music)
74 (ly:music?)
75 (define (make-script-music m)
76 (add-script m "staccato"))
77 (music-map make-script-music music))
79 acc =
80 #(define-music-function (parser location music)
81 (ly:music?)
82 (define (make-script-music m)
83 (add-script m "accent"))
84 (music-map make-script-music music))
86 det =
87 #(define-music-function (parser location music)
88 (ly:music?)
89 (define (make-script-music m)
90 (add-script m "tenuto"))
91 (music-map make-script-music music))
93 marc =
94 #(define-music-function (parser location music)
95 (ly:music?)
96 (define (make-script-music m)
97 (add-script m "marcato"))
98 (music-map make-script-music music))
100 stdet =
101 #(define-music-function (parser location music)
102 (ly:music?)
103 (define (make-script-music m)
104 (add-script m "portato"))
105 (music-map make-script-music music))
107 accdet =
108 #(define-music-function (parser location music)
109 (ly:music?)
110 (define (make-script-music m)
111 (double-script m "tenuto" "accent"))
112 (music-map make-script-music music))
114 marcdet =
115 #(define-music-function (parser location music)
116 (ly:music?)
117 (define (make-script-music m)
118 (double-script m "tenuto" "marcato"))
119 (music-map make-script-music music))
121 accst =
122 #(define-music-function (parser location music)
123 (ly:music?)
124 (define (make-script-music m)
125 (double-script m "accent" "staccato"))
126 (music-map make-script-music music))
128 marcst =
129 #(define-music-function (parser location music)
130 (ly:music?)
131 (define (make-script-music m)
132 (double-script m "marcato" "staccato"))
133 (music-map make-script-music music))
136 CaV=
137 #(let ((m (make-music 'ArticulationEvent
138 'articulation-type "flageolet")))
139 (set! (ly:music-property m 'tweaks)
140 (acons 'font-size -3
141 (ly:music-property m 'tweaks)))
145 %% Music shortcuts ------------------------------------------------%
147 #(define (octave-up noteevent)
148 (let* ((pitch (ly:music-property noteevent 'pitch))
149 (octave (ly:pitch-octave pitch))
150 (note (ly:pitch-notename pitch))
151 (alteration (ly:pitch-alteration pitch))
152 (duration (ly:music-property noteevent 'duration))
153 (newnoteevent
154 (make-music 'NoteEvent
155 'duration duration
156 'pitch (ly:make-pitch (1- octave) note alteration))))
157 newnoteevent))
159 #(define (octavize-chord elements)
160 (cond ((null? elements) elements)
161 ((eq? (ly:music-property (car elements) 'name) 'NoteEvent)
162 (cons (car elements)
163 (cons (octave-up (car elements))
164 (octavize-chord (cdr elements)))))
165 (else (cons (car elements) (octavize-chord (cdr elements))))))
167 #(define (octavize music)
168 (let* ((es (ly:music-property music 'elements))
169 (e (ly:music-property music 'element))
170 (name (ly:music-property music 'name)))
171 (cond ((eq? name 'EventChord)
172 (ly:music-set-property! music 'elements (octavize-chord es)))
173 ((pair? es)
174 (for-each (lambda(x) (octavize x)) es))
175 ((ly:music? e)
176 (octavize e))))
177 music)
179 oct = #(define-music-function (parser location mus) (ly:music?)
180 (octavize mus))
182 %%%%%%%%%%%%%%%%%%%%%%%% Layout Functions %%%%%%%%%%%%%%%%%%%%%%%%%%
184 %% Music layout ---------------------------------------------------%
186 droite = { \change StaffPiano = "droite" }
188 gauche = { \change StaffPiano = "gauche" }
190 #(define modern-auto-beam-settings
191 (append default-auto-beam-settings
193 ((end * * 3 4) . ,(ly:make-moment 1 4))
194 ((end * * 3 4) . ,(ly:make-moment 1 2))
195 ((end * * 4 4) . ,(ly:make-moment 1 4))
196 ((end * * 4 4) . ,(ly:make-moment 3 4))
197 ((end * * 2 2) . ,(ly:make-moment 1 4))
198 ((end * * 2 2) . ,(ly:make-moment 1 2))
199 ((end * * 2 2) . ,(ly:make-moment 3 4))
200 ((end * * 2 8) . ,(ly:make-moment 1 4))
201 ((be * * 5 8) . ,(ly:make-moment 1 8))
202 ((end * * 5 8) . ,(ly:make-moment 5 8))
205 #(define modern-style
206 '(Staff
207 (same-octave . 0)
208 (any-octave . 0)
209 (same-octave . 1)))
211 %% Music formatting -----------------------------------------------%
213 graceNotes =
214 #(define-music-function (parser location notes) (ly:music?)
215 #{ \tiny $notes \normalsize #})
217 parlato =
218 #(define-music-function (parser location notes) (ly:music?)
219 #{ \override NoteHead #'style = #'cross
220 $notes
221 \revert NoteHead #'style #})
223 hideNote = {
224 \once \override NoteHead #'transparent = ##t
225 \once \override NoteHead #'no-ledgers = ##t
226 \once \override Stem #'transparent = ##t
227 \once \override Beam #'transparent = ##t
228 \once \override Accidental #'transparent = ##t
230 %%%%%%%%%%%%%%%%%%%%%%%%%% In-score Text %%%%%%%%%%%%%%%%%%%%%%%%%%%
232 %% Expressive indications -----------------------------------------%
234 #(define-markup-command (indic layout props arg) (markup?)
235 (interpret-markup layout props
236 (markup #:whiteout #:small #:italic arg)))
238 cmb =
239 #(define-music-function (parser location nuance texte )
240 (string? string? )
241 (make-dynamic-script
242 (markup #:dynamic nuance
243 #:hspace .6
244 #:text #:medium #:upright texte )))
247 ten =
248 #(define-music-function (parser location music) (ly:music?)
250 (equal? (ly:music-property music 'name) 'EventChord)
251 (set! (ly:music-property music 'elements)
252 (append (ly:music-property music 'elements)
253 (list (make-music 'TextScriptEvent 'text
254 (markup #:translate (cons 4 0)
255 #:indic "(ten.)"))))))
256 music)
258 ind =
259 #(define-music-function (parser location text music) (string? ly:music?)
261 (equal? (ly:music-property music 'name) 'EventChord)
262 (set! (ly:music-property music 'elements)
263 (append (ly:music-property music 'elements)
264 (list (make-music 'TextScriptEvent 'direction 1
265 'text (markup #:indic text))))))
266 music)
268 #(define (make-text-span music t)
269 (set! (ly:music-property music 'elements)
270 (append (ly:music-property music 'elements)
271 (list (make-music 'TextSpanEvent
272 'span-direction t))))
273 music)
274 startTxt =
275 #(define-music-function (parser location texte music ) (string? ly:music?)
276 #{ \override TextSpanner #'bound-details #'left #'text =
277 \markup { \bold $texte }
278 $(make-text-span music -1)#})
280 stopTxt =
281 #(define-music-function (parser location music ) (ly:music?)
282 (make-text-span music 1))
284 %% Tempo indications ----------------------------------------------%
285 #(define-markup-command (mvt layout props arg) (markup?)
286 (interpret-markup layout props
287 (markup #:huge #:bold arg)))
289 %%%%%%%%%%%%%%%%%%%%%%%%%% Text Functions %%%%%%%%%%%%%%%%%%%%%%%%%%
291 %% Lyrics formatting ----------------------------------------------%
293 freestyleOn = {
294 \override Lyrics . LyricExtender #'stencil = ##f }
296 freestyleOff = {
297 \revert Lyrics . LyricExtender #'stencil }
299 leftSyl = {
300 \once \override LyricText #'self-alignment-X = #0.9 }
302 dash = {
303 \once \override LyricHyphen #'minimum-distance = #4
304 \once \override LyricHyphen #'length = #2
305 \once \override LyricHyphen #'thickness = #1.2
308 ital = {
309 \once \override LyricText #'font-shape = #'italic }
311 smallcaps = {
312 \override LyricText #'font-shape = #'caps }
314 normal = {
315 \revert LyricText #'font-shape }
318 %% Scenography formatting ---------------------------------------%
319 long = {
320 \once \override TextScript #'extra-spacing-width = #'(0 . 0)
321 \once \override TextScript #'infinite-spacing-height = ##t
324 #(define-markup-command (did layout props text) (markup?)
325 (interpret-markup layout props
326 (markup #:override '(line-width . 40)
327 #:override '(box-padding . 1)
328 #:override '(corner-radius . 2)
329 #:rounded-box #:sans #:italic #:small #:justify-string text)))
331 #(define-markup-command (init-did layout props text) (markup?)
332 (interpret-markup layout props
333 (markup
334 ; #:override (cons 'line-width (* 1 (chain-assoc-get 'line-width props)))
335 #:fill-line (
336 #:override '(line-width . 50)
337 #:override '(box-padding . 1.5)
338 #:override '(corner-radius . 2)
339 #:rounded-box #:sans #:italic #:small #:justify-string text))))
341 #(define-markup-command (vspace layout props amount) (number?)
342 (let ((amount (* amount 3.0)))
343 (if (> amount 0)
344 (ly:make-stencil "" (cons -1 1) (cons 0 amount))
345 (ly:make-stencil "" (cons -1 1) (cons amount amount)))))