Dynamics to Entracte
[opera_libre.git] / definitions / functions.ly
blob8ee19d1b7f505ae83573783e826aaf44b6e0b26c
1 %------------------------------------------------------------------%
2 % Opéra Libre -- functions.ly %
3 % %
4 % (c) Valentin Villenave, 2008 %
5 % %
6 %------------------------------------------------------------------%
8 % Various additional functions.
10 %%%%%%%%%%%%%%%%%%%%%%%%% Music Shortcuts %%%%%%%%%%%%%%%%%%%%%%%%%%
12 %% Rhythm shortcuts -----------------------------------------------%
14 t =
15 #(define-music-function (parser location music) (ly:music?)
16 #{ \times 2/3 $music #})
18 tt =
19 #(define-music-function (parser location music) (ly:music?)
20 #{ \times 4/5 $music #})
22 ttt =
23 #(define-music-function (parser location music) (ly:music?)
24 #{ \times 4/6 $music #})
26 tttt =
27 #(define-music-function (parser location music) (ly:music?)
28 #{ \times 4/7 $music #})
31 %% Polyphony shortcuts --------------------------------------------%
33 pl =
34 #(define-music-function (parser location one two) (ly:music? ly:music?)
35 #{ << { \voiceTwo $one } \\ { \voiceOne $two } >> #})
37 plperc =
38 #(define-music-function (parser location one two) (ly:music? ly:music?)
39 #{ << { \stemDown $one \stemNeutral } \new DrumVoice { \stemUp $two } >> #})
41 parallel=
42 #(define-music-function (parser location droite gauche) (ly:music? ly:music?)
43 #{ <<
44 \context Staff = "md" $droite
45 \context Staff = "mg" $gauche
46 >> #})
48 %%% Piano stuff (Issue #442 workaround)
50 #(define (remove music)
51 "Sends the whole thing to Devnull whenever possible"
52 (context-spec-music music 'Devnull))
54 #(define (event-filter event)
55 (let ((n (ly:music-property event 'name)))
56 (if (or
57 (eq? n 'ContextSpeccedMusic) ; to avoid clefs and ottavas
58 (eq? n 'ContextChange)) ; cross-staff voices are supported
59 (music-map remove event))
60 (if (eq? n 'SimultaneousMusic) ; we don't want a new Voice to be created
61 (ly:music-set-property! event 'name 'NoteEvent))))
63 makeGhost =
64 #(define-music-function (parser location music) (ly:music?)
65 (context-spec-music (music-filter event-filter music) 'PseudoVoice))
67 showAnyway =
68 #(define-music-function (parser location music) (ly:music?)
70 \unset Score.keepAliveInterfaces
71 $music
72 \set Score.keepAliveInterfaces = #'(rhythmic-grob-interface
73 lyric-interface percent-repeat-item-interface
74 percent-repeat-interface stanza-number-interface)
75 #})
77 md = { \change Staff = "md" }
79 mg = { \change Staff = "mg" }
81 PianoDeuxMains=
82 #(define-music-function (parser location droite gauche) (ly:music? ly:music?)
84 \new PianoStaff <<
85 \new Staff = "md" \with { \remove Accidental_engraver }
87 \new Voice \with { \consists Accidental_engraver } { \clef treble $droite }
88 \new Voice { \makeGhost $gauche }
90 \new Staff = "mg" \with { \remove Accidental_engraver }
92 \new Voice \with { \consists Accidental_engraver } { \clef bass $gauche }
93 \new Voice { \makeGhost $droite }
96 #})
98 droite = { \change Staff = "percuDroite" }
100 gauche = { \change Staff = "percuGauche" }
102 PercuDeuxMains=
103 #(define-music-function (parser location droite gauche) (ly:music? ly:music?)
105 \new PianoStaff <<
106 \new Staff = "percuDroite" \with { \remove Accidental_engraver }
108 \new Voice \with { \consists Accidental_engraver } { \clef treble $droite }
109 \new Voice { \makeGhost $gauche }
111 \new Staff = "percuGauche" \with { \remove Accidental_engraver }
113 \new Voice \with { \consists Accidental_engraver } { \clef bass $gauche }
114 \new Voice { \makeGhost $droite }
120 %% Music formatting -----------------------------------------------%
122 graceNotes =
123 #(define-music-function (parser location notes) (ly:music?)
124 #{ \tiny $notes \normalsize #})
126 parlato =
127 #(define-music-function (parser location notes) (ly:music?)
128 #{ \override NoteHead #'style = #'cross
129 $notes
130 \revert NoteHead #'style #})
132 longHairpins =
133 #(define-music-function (parser location music) (ly:music?)
134 #{ \override Hairpin #'to-barline = ##f
135 $music \revert Hairpin #'to-barline #})
137 slap =
138 #(define-music-function (parser location music) (ly:music?)
139 #{\override NoteHead #'stencil = #ly:text-interface::print
140 \override NoteHead #'text = \markup \musicglyph #"scripts.sforzato"
141 \override NoteHead #'extra-offset = #'(0.1 . 0.0 )
142 $music
143 \revert NoteHead #'stencil
144 \revert NoteHead #'text
145 \revert NoteHead #'extra-offset #})
147 hideNote = {
148 \once \override NoteHead #'transparent = ##t
149 \once \override NoteHead #'no-ledgers = ##t
150 \once \override Stem #'transparent = ##t
151 \once \override Beam #'transparent = ##t
152 \once \override Accidental #'transparent = ##t
155 noTuplet = {
156 \once \override TupletBracket #'transparent = ##t
157 \once \override TupletNumber #'transparent = ##t
160 oneStemDown = {
161 \once \override Stem #'direction = #DOWN
164 oneStemUp = {
165 \once \override Stem #'direction = #UP
168 %% Music shortcuts ------------------------------------------------%
170 sk = \set Score.skipTypesetting = ##t
172 unsk = \set Score.skipTypesetting = ##f
174 % This might not be needed
175 #(define (octave-up noteevent)
176 (let* ((pitch (ly:music-property noteevent 'pitch))
177 (octave (ly:pitch-octave pitch))
178 (note (ly:pitch-notename pitch))
179 (alteration (ly:pitch-alteration pitch))
180 (duration (ly:music-property noteevent 'duration))
181 (newnoteevent
182 (make-music 'NoteEvent
183 'duration duration
184 'pitch (ly:make-pitch (1- octave) note alteration))))
185 newnoteevent))
187 #(define (octavize-chord elements)
188 (cond ((null? elements) elements)
189 ((eq? (ly:music-property (car elements) 'name) 'NoteEvent)
190 (cons (car elements)
191 (cons (octave-up (car elements))
192 (octavize-chord (cdr elements)))))
193 (else (cons (car elements) (octavize-chord (cdr elements))))))
195 #(define (octavize music)
196 (let* ((es (ly:music-property music 'elements))
197 (e (ly:music-property music 'element))
198 (name (ly:music-property music 'name)))
199 (cond ((eq? name 'EventChord)
200 (ly:music-set-property! music 'elements (octavize-chord es)))
201 ((pair? es)
202 (for-each (lambda(x) (octavize x)) es))
203 ((ly:music? e)
204 (octavize e))))
205 music)
207 oct = #(define-music-function (parser location mus) (ly:music?)
208 (octavize mus))
211 %%%%%%%%%%%%%%%%%%%%%%%%% Music Decoration %%%%%%%%%%%%%%%%%%%%%%%%%
213 %% Articulation marks ---------------------------------------------%
215 #(define (make-script x)
216 (make-music 'ArticulationEvent
217 'articulation-type x))
219 #(define (add-script m x)
220 (let ( (eventname (ly:music-property m 'name)))
221 (if (equal? eventname 'EventChord)
222 (let ( (elements (ly:music-property m 'elements)) )
223 (if (not (equal? (ly:music-property (car elements)
224 'name) 'RestEvent))
225 (set! (ly:music-property m 'elements)
226 (append elements (list
227 (make-script x)))))))
230 #(define (double-script m t tt)
231 (add-script (add-script m t) tt))
233 st =
234 #(define-music-function (parser location music)
235 (ly:music?)
236 (define (make-script-music m)
237 (add-script m "staccato"))
238 (music-map make-script-music music))
240 acc =
241 #(define-music-function (parser location music)
242 (ly:music?)
243 (define (make-script-music m)
244 (add-script m "accent"))
245 (music-map make-script-music music))
247 det =
248 #(define-music-function (parser location music)
249 (ly:music?)
250 (define (make-script-music m)
251 (add-script m "tenuto"))
252 (music-map make-script-music music))
254 marc =
255 #(define-music-function (parser location music)
256 (ly:music?)
257 (define (make-script-music m)
258 (add-script m "marcato"))
259 (music-map make-script-music music))
261 stdet =
262 #(define-music-function (parser location music)
263 (ly:music?)
264 (define (make-script-music m)
265 (add-script m "portato"))
266 (music-map make-script-music music))
268 accdet =
269 #(define-music-function (parser location music)
270 (ly:music?)
271 (define (make-script-music m)
272 (double-script m "tenuto" "accent"))
273 (music-map make-script-music music))
275 marcdet =
276 #(define-music-function (parser location music)
277 (ly:music?)
278 (define (make-script-music m)
279 (double-script m "tenuto" "marcato"))
280 (music-map make-script-music music))
282 accst =
283 #(define-music-function (parser location music)
284 (ly:music?)
285 (define (make-script-music m)
286 (double-script m "accent" "staccato"))
287 (music-map make-script-music music))
289 marcst =
290 #(define-music-function (parser location music)
291 (ly:music?)
292 (define (make-script-music m)
293 (double-script m "marcato" "staccato"))
294 (music-map make-script-music music))
296 dwnb =
297 #(define-music-function (parser location music)
298 (ly:music?)
299 (define (make-script-music m)
300 (add-script m "downbow"))
301 (music-map make-script-music music))
303 CaV=
304 #(let ((m (make-music 'ArticulationEvent
305 'articulation-type "flageolet")))
306 (set! (ly:music-property m 'tweaks)
307 (acons 'font-size -3
308 (ly:music-property m 'tweaks)))
310 harmo =
311 #(define-music-function (parser location chord result) (ly:music? ly:music?)
312 #{ << \oneStemDown $chord \\ { \stemUp %FIXME: ties could look better.
313 \override NoteHead #'stencil = #ly:text-interface::print
314 \override NoteHead #'text = \markup { \null \musicglyph #"noteheads.s2"}
315 \once \override NoteHead #'text = \markup {\null \override #'(direction . 1)
316 \dir-column {\musicglyph #"noteheads.s2" \teeny \musicglyph #"eight"}}
317 \override Stem #'stencil = ##f $result
318 \revert Stem #'stencil \revert NoteHead #'stencil \stemNeutral } >> #})
320 thumbpizz =
321 #(let* ((m (make-music 'ArticulationEvent
322 'articulation-type "stopped"
323 'direction 1)))
324 (ly:music-set-property! m 'tweaks
325 (acons 'font-size 3
326 (acons 'text (markup
327 #:hspace 0
328 #:rotate 45
329 #:musicglyph "scripts.stopped")
330 (acons 'stencil ly:text-interface::print
331 (ly:music-property m 'tweaks)))))
334 leftpizz =
335 #(let* ((m (make-music 'ArticulationEvent
336 'articulation-type "stopped"
337 'direction 1)))
338 (ly:music-set-property! m 'tweaks
339 (acons 'font-size 3
340 (ly:music-property m 'tweaks)))
343 arpeggUp =
344 #(let* ((m (make-music 'ArpeggioEvent)))
345 (ly:music-set-property! m 'tweaks
346 (acons 'arpeggio-direction 1
347 (ly:music-property m 'tweaks)))
350 arpeggDown =
351 #(let* ((m (make-music 'ArpeggioEvent)))
352 (ly:music-set-property! m 'tweaks
353 (acons 'arpeggio-direction -1
354 (ly:music-property m 'tweaks)))
357 plak =
358 #(let* ((m (make-music 'ArpeggioEvent)))
359 (ly:music-set-property! m 'tweaks
360 (acons 'stencil ly:arpeggio::brew-chord-bracket
361 (ly:music-property m 'tweaks)))
364 %%%%%%%%%%%%%%%%%%%%%%%% Layout Functions %%%%%%%%%%%%%%%%%%%%%%%%%%
366 %% Music layout ---------------------------------------------------%
368 #(define modern-auto-beam-settings
369 (append default-auto-beam-settings
371 ((end * * 3 4) . ,(ly:make-moment 1 4))
372 ((end * * 3 4) . ,(ly:make-moment 1 2))
373 ((end * * 4 4) . ,(ly:make-moment 1 4))
374 ((end * * 4 4) . ,(ly:make-moment 3 4))
375 ((end * * 2 2) . ,(ly:make-moment 1 4))
376 ((end * * 2 2) . ,(ly:make-moment 1 2))
377 ((end * * 2 2) . ,(ly:make-moment 3 4))
378 ((end * * 2 8) . ,(ly:make-moment 1 4))
379 ((be * * 5 8) . ,(ly:make-moment 1 8))
380 ((end * * 5 8) . ,(ly:make-moment 5 8))
383 #(define modern-accidentals-style
384 `(Staff ,(make-accidental-rule 'same-octave 0)
385 ,(make-accidental-rule 'any-octave 0)
386 ,(make-accidental-rule 'same-octave 1)
387 ,neo-modern-accidental-rule))
388 #(define modern-cautionaries-style
389 `(Staff ,(make-accidental-rule 'same-octave 1)
390 ,(make-accidental-rule 'any-octave 1)))
392 %%%%%%%%%%%%%%%%%%%%%%%%%%%% Editorial %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
394 %% Individual parts -----------------------------------------------%
396 makePart =
397 #(define-music-function (parser location part ref)
398 (ly:music? ly:music?)
399 #{\context Staff << $part \new GhostVoice $ref >> #})
401 makeSection =
402 #(define-music-function (parser location part-one part-two ref)
403 (ly:music? ly:music? ly:music?)
404 #{\new StaffGroup <<
405 \new Staff << $part-one \new GhostVoice $ref >>
406 \new Staff $part-two
407 >> #})
409 makeExtraSection = % for violins
410 #(define-music-function (parser location part-one part-two part-three ref)
411 (ly:music? ly:music? ly:music? ly:music?)
412 #{\new StaffGroup <<
413 \new Staff << $part-one \new GhostVoice $ref >>
414 \new Staff $part-two
415 \new Staff $part-three
416 >> #})
418 makePianoPart =
419 #(define-music-function (parser location part-one ref)
420 (ly:music? ly:music?)
421 #{<< $part-one \new GhostVoice $ref >> #})
423 %%-----------------------------------------------------------------%