1 %------------------------------------------------------------------%
2 % Opéra Libre -- functions.ly %
4 % (c) Valentin Villenave, 2008 %
6 %------------------------------------------------------------------%
8 % Various additional functions.
10 %%%%%%%%%%%%%%%%%%%%%%%%% Music Shortcuts %%%%%%%%%%%%%%%%%%%%%%%%%%
12 %% Rhythm shortcuts -----------------------------------------------%
15 #(define-music-function
(parser location music
) (ly
:music?
)
16 #{ \times 2/3 $music
#})
19 #(define-music-function
(parser location music
) (ly
:music?
)
20 #{ \times 4/5 $music
#})
23 #(define-music-function
(parser location music
) (ly
:music?
)
24 #{ \times 4/6 $music
#})
27 #(define-music-function
(parser location music
) (ly
:music?
)
28 #{ \times 4/7 $music
#})
31 %% Polyphony shortcuts --------------------------------------------%
34 #(define-music-function
(parser location one two
) (ly
:music? ly
:music?
)
35 #{ << { \voiceTwo $one
} \\ { \voiceOne $two
} >> #})
38 #(define-music-function
(parser location one two
) (ly
:music? ly
:music?
)
39 #{ << { \stemDown $one
\stemNeutral } \new DrumVoice
{ \stemUp $two
} >> #})
42 #(define-music-function
(parser location droite gauche
) (ly
:music? ly
:music?
)
44 \context Staff
= "md" $droite
45 \context Staff
= "mg" $gauche
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
)))
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
))))
64 #(define-music-function
(parser location music
) (ly
:music?
)
65 (context-spec-music
(music-filter event-filter music
) 'PseudoVoice
))
68 #(define-music-function
(parser location music
) (ly
:music?
)
70 \unset Score
.keepAliveInterfaces
72 \set Score
.keepAliveInterfaces
= #'(rhythmic-grob-interface
73 lyric-interface percent-repeat-item-interface
74 percent-repeat-interface stanza-number-interface
)
77 md
= { \change Staff
= "md" }
79 mg
= { \change Staff
= "mg" }
82 #(define-music-function
(parser location droite gauche
) (ly
:music? ly
:music?
)
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
}
98 droite
= { \change Staff
= "percuDroite" }
100 gauche
= { \change Staff
= "percuGauche" }
103 #(define-music-function
(parser location droite gauche
) (ly
:music? ly
:music?
)
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 -----------------------------------------------%
123 #(define-music-function
(parser location notes
) (ly
:music?
)
124 #{ \tiny $notes
\normalsize #})
127 #(define-music-function
(parser location notes
) (ly
:music?
)
128 #{ \override NoteHead
#'style
= #'cross
130 \revert NoteHead
#'style
#})
133 #(define-music-function
(parser location music
) (ly
:music?
)
134 #{ \override Hairpin
#'to-barline
= ##f
135 $music
\revert Hairpin
#'to-barline
#})
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 )
143 \revert NoteHead
#'stencil
144 \revert NoteHead
#'text
145 \revert NoteHead
#'extra-offset
#})
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
156 \once \override TupletBracket
#'transparent
= ##t
157 \once \override TupletNumber
#'transparent
= ##t
161 \once \override Stem
#'direction
= #DOWN
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
))
182 (make-music
'NoteEvent
184 'pitch
(ly
:make-pitch
(1- octave
) note alteration
))))
187 #(define
(octavize-chord elements
)
188 (cond
((null? elements
) elements
)
189 ((eq?
(ly
:music-property
(car elements
) 'name
) 'NoteEvent
)
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)))
202 (for-each
(lambda
(x
) (octavize x
)) es))
207 oct
= #(define-music-function
(parser location mus
) (ly
:music?
)
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
)
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
))
234 #(define-music-function
(parser location music
)
236 (define
(make-script-music m
)
237 (add-script m
"staccato"))
238 (music-map make-script-music music
))
241 #(define-music-function
(parser location music
)
243 (define
(make-script-music m
)
244 (add-script m
"accent"))
245 (music-map make-script-music music
))
248 #(define-music-function
(parser location music
)
250 (define
(make-script-music m
)
251 (add-script m
"tenuto"))
252 (music-map make-script-music music
))
255 #(define-music-function
(parser location music
)
257 (define
(make-script-music m
)
258 (add-script m
"marcato"))
259 (music-map make-script-music music
))
262 #(define-music-function
(parser location music
)
264 (define
(make-script-music m
)
265 (add-script m
"portato"))
266 (music-map make-script-music music
))
269 #(define-music-function
(parser location music
)
271 (define
(make-script-music m
)
272 (double-script m
"tenuto" "accent"))
273 (music-map make-script-music music
))
276 #(define-music-function
(parser location music
)
278 (define
(make-script-music m
)
279 (double-script m
"tenuto" "marcato"))
280 (music-map make-script-music music
))
283 #(define-music-function
(parser location music
)
285 (define
(make-script-music m
)
286 (double-script m
"accent" "staccato"))
287 (music-map make-script-music music
))
290 #(define-music-function
(parser location music
)
292 (define
(make-script-music m
)
293 (double-script m
"marcato" "staccato"))
294 (music-map make-script-music music
))
297 #(define-music-function
(parser location music
)
299 (define
(make-script-music m
)
300 (add-script m
"downbow"))
301 (music-map make-script-music music
))
304 #(let
((m
(make-music
'ArticulationEvent
305 'articulation-type
"flageolet")))
306 (set
! (ly
:music-property m
'tweaks
)
308 (ly
:music-property m
'tweaks
)))
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 } >> #})
321 #(let
* ((m
(make-music
'ArticulationEvent
322 'articulation-type
"stopped"
324 (ly
:music-set-property
! m
'tweaks
329 #:musicglyph
"scripts.stopped")
330 (acons
'stencil ly
:text-interface
::print
331 (ly
:music-property m
'tweaks
)))))
335 #(let
* ((m
(make-music
'ArticulationEvent
336 'articulation-type
"stopped"
338 (ly
:music-set-property
! m
'tweaks
340 (ly
:music-property m
'tweaks
)))
344 #(let
* ((m
(make-music
'ArpeggioEvent
)))
345 (ly
:music-set-property
! m
'tweaks
346 (acons
'arpeggio-direction
1
347 (ly
:music-property m
'tweaks
)))
351 #(let
* ((m
(make-music
'ArpeggioEvent
)))
352 (ly
:music-set-property
! m
'tweaks
353 (acons
'arpeggio-direction -
1
354 (ly
:music-property m
'tweaks
)))
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 -----------------------------------------------%
397 #(define-music-function
(parser location part ref
)
398 (ly
:music? ly
:music?
)
399 #{\context Staff
<< $part
\new GhostVoice $ref
>> #})
402 #(define-music-function
(parser location part-one part-two ref
)
403 (ly
:music? ly
:music? ly
:music?
)
405 \new Staff
<< $part-one
\new GhostVoice $ref
>>
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?
)
413 \new Staff
<< $part-one
\new GhostVoice $ref
>>
415 \new Staff $part-three
419 #(define-music-function
(parser location part-one ref
)
420 (ly
:music? ly
:music?
)
421 #{<< $part-one
\new GhostVoice $ref
>> #})
423 %%-----------------------------------------------------------------%