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
(event-filter event
)
51 (let
((n
(ly
:music-property event
'name
)))
53 (or ;; add here event name you do NOT want
54 (eq? n
'ContextSpeccedMusic
)
55 (eq? n
'ContextChange
)
56 (eq? n
'SimultaneousMusic
))
60 #(define-music-function
(parser location music
) (ly
:music?
)
61 (context-spec-music
(music-filter event-filter music
) 'PseudoVoice
))
64 #(define-music-function
(parser location music
) (ly
:music?
)
66 \unset Score
.keepAliveInterfaces
68 \set Score
.keepAliveInterfaces
= #'(rhythmic-grob-interface
69 lyric-interface percent-repeat-item-interface
70 percent-repeat-interface stanza-number-interface
)
73 md
= { \change Staff
= "md" }
75 mg
= { \change Staff
= "mg" }
78 #(define-music-function
(parser location droite gauche
) (ly
:music? ly
:music?
)
81 \new Staff
= "md" \with { \remove Accidental
_engraver
}
83 \new Voice
\with { \consists Accidental
_engraver
} { \clef treble $droite
}
84 %\new Voice { \makeGhost $gauche }
86 \new Staff
= "mg" \with { \remove Accidental
_engraver
}
88 \new Voice
\with { \consists Accidental
_engraver
} { \clef bass $gauche
}
89 %\new Voice { \makeGhost $droite }
94 droite
= { \change Staff
= "percuDroite" }
96 gauche
= { \change Staff
= "percuGauche" }
99 #(define-music-function
(parser location droite gauche
) (ly
:music? ly
:music?
)
100 #{ << %%%FIXME: I /definitely/ should get rid of this option.
101 \new Staff
= "percuDroite"
102 { \clef treble $droite
}
103 \new Staff
= "percuGauche" \with { \override VerticalAxisGroup
#'remove-empty
= ##f }
104 { \clef bass $gauche
}
108 %% Music formatting -----------------------------------------------%
111 #(define-music-function
(parser location notes
) (ly
:music?
)
112 #{ \tiny $notes
\normalsize #})
115 #(define-music-function
(parser location notes
) (ly
:music?
)
116 #{ \override NoteHead
#'style
= #'cross
118 \revert NoteHead
#'style
#})
121 #(define-music-function
(parser location music
) (ly
:music?
)
122 #{\override NoteHead
#'stencil
= #ly
:text-interface
::print
123 \override NoteHead
#'text
= \markup \musicglyph #"scripts.sforzato"
124 \override NoteHead
#'extra-offset
= #'(0.1 . 0.0 )
126 \revert NoteHead
#'stencil
127 \revert NoteHead
#'text
128 \revert NoteHead
#'extra-offset
#})
131 \once \override NoteHead
#'transparent
= ##t
132 \once \override NoteHead
#'no-ledgers
= ##t
133 \once \override Stem
#'transparent
= ##t
134 \once \override Beam
#'transparent
= ##t
135 \once \override Accidental
#'transparent
= ##t
139 \once \override TupletBracket
#'transparent
= ##t
140 \once \override TupletNumber
#'transparent
= ##t
144 \once \override Stem
#'direction
= #DOWN
148 \once \override Stem
#'direction
= #UP
151 %% Music shortcuts ------------------------------------------------%
153 sk
= \set Score
.skipTypesetting
= ##t
155 unsk
= \set Score
.skipTypesetting
= ##f
157 % This might not be needed
158 #(define
(octave-up noteevent
)
159 (let
* ((pitch
(ly
:music-property noteevent
'pitch
))
160 (octave
(ly
:pitch-octave pitch
))
161 (note
(ly
:pitch-notename pitch
))
162 (alteration
(ly
:pitch-alteration pitch
))
163 (duration
(ly
:music-property noteevent
'duration
))
165 (make-music
'NoteEvent
167 'pitch
(ly
:make-pitch
(1- octave
) note alteration
))))
170 #(define
(octavize-chord elements
)
171 (cond
((null? elements
) elements
)
172 ((eq?
(ly
:music-property
(car elements
) 'name
) 'NoteEvent
)
174 (cons
(octave-up
(car elements
))
175 (octavize-chord
(cdr elements
)))))
176 (else
(cons
(car elements
) (octavize-chord
(cdr elements
))))))
178 #(define
(octavize music
)
179 (let
* ((es (ly
:music-property music
'elements
))
180 (e (ly
:music-property music
'element
))
181 (name
(ly
:music-property music
'name
)))
182 (cond
((eq? name
'EventChord
)
183 (ly
:music-set-property
! music
'elements
(octavize-chord
es)))
185 (for-each
(lambda
(x
) (octavize x
)) es))
190 oct
= #(define-music-function
(parser location mus
) (ly
:music?
)
194 %%%%%%%%%%%%%%%%%%%%%%%%% Music Decoration %%%%%%%%%%%%%%%%%%%%%%%%%
196 %% Articulation marks ---------------------------------------------%
198 #(define
(make-script x
)
199 (make-music
'ArticulationEvent
200 'articulation-type x
))
202 #(define
(add-script m x
)
203 (let
( (eventname
(ly
:music-property m
'name
)))
204 (if
(equal? eventname
'EventChord
)
205 (let
( (elements
(ly
:music-property m
'elements
)) )
206 (if
(not
(equal?
(ly
:music-property
(car elements
)
208 (set
! (ly
:music-property m
'elements
)
209 (append elements
(list
210 (make-script x
)))))))
213 #(define
(double-script m t tt
)
214 (add-script
(add-script m t
) tt
))
217 #(define-music-function
(parser location music
)
219 (define
(make-script-music m
)
220 (add-script m
"staccato"))
221 (music-map make-script-music music
))
224 #(define-music-function
(parser location music
)
226 (define
(make-script-music m
)
227 (add-script m
"accent"))
228 (music-map make-script-music music
))
231 #(define-music-function
(parser location music
)
233 (define
(make-script-music m
)
234 (add-script m
"tenuto"))
235 (music-map make-script-music music
))
238 #(define-music-function
(parser location music
)
240 (define
(make-script-music m
)
241 (add-script m
"marcato"))
242 (music-map make-script-music music
))
245 #(define-music-function
(parser location music
)
247 (define
(make-script-music m
)
248 (add-script m
"portato"))
249 (music-map make-script-music music
))
252 #(define-music-function
(parser location music
)
254 (define
(make-script-music m
)
255 (double-script m
"tenuto" "accent"))
256 (music-map make-script-music music
))
259 #(define-music-function
(parser location music
)
261 (define
(make-script-music m
)
262 (double-script m
"tenuto" "marcato"))
263 (music-map make-script-music music
))
266 #(define-music-function
(parser location music
)
268 (define
(make-script-music m
)
269 (double-script m
"accent" "staccato"))
270 (music-map make-script-music music
))
273 #(define-music-function
(parser location music
)
275 (define
(make-script-music m
)
276 (double-script m
"marcato" "staccato"))
277 (music-map make-script-music music
))
281 #(let
((m
(make-music
'ArticulationEvent
282 'articulation-type
"flageolet")))
283 (set
! (ly
:music-property m
'tweaks
)
285 (ly
:music-property m
'tweaks
)))
288 #(define-music-function
(parser location chord result
) (ly
:music? ly
:music?
)
289 #{ << \oneStemDown $chord
\\ { \stemUp %FIXME: ties could look better.
290 \override NoteHead
#'stencil
= #ly
:text-interface
::print
291 \override NoteHead
#'text
= \markup { \null \musicglyph #"noteheads.s2"}
292 \once \override NoteHead
#'text
= \markup {\null \override #'(direction
. 1)
293 \dir-column
{\musicglyph #"noteheads.s2" \teeny \musicglyph #"eight"}}
294 \override Stem
#'stencil
= ##f $result
295 \revert Stem
#'stencil
\revert NoteHead
#'stencil
\stemNeutral } >> #})
298 #(make-music
'TextScriptEvent
300 'text
(markup
#:hspace
.4 #:rotate
45
301 #:musicglyph
"scripts.stopped"))
304 #(make-articulation
"stopped")
307 #(let
* ((m
(make-music
'ArpeggioEvent
)))
308 (ly
:music-set-property
! m
'tweaks
309 (acons
'arpeggio-direction
1
310 (ly
:music-property m
'tweaks
)))
314 #(let
* ((m
(make-music
'ArpeggioEvent
)))
315 (ly
:music-set-property
! m
'tweaks
316 (acons
'arpeggio-direction -
1
317 (ly
:music-property m
'tweaks
)))
321 #(let
* ((m
(make-music
'ArpeggioEvent
)))
322 (ly
:music-set-property
! m
'tweaks
323 (acons
'stencil ly
:arpeggio
::brew-chord-bracket
324 (ly
:music-property m
'tweaks
)))
327 %%%%%%%%%%%%%%%%%%%%%%%% Layout Functions %%%%%%%%%%%%%%%%%%%%%%%%%%
329 %% Music layout ---------------------------------------------------%
331 #(define modern-auto-beam-settings
332 (append default-auto-beam-settings
334 ((end
* * 3 4) . ,(ly
:make-moment
1 4))
335 ((end
* * 3 4) . ,(ly
:make-moment
1 2))
336 ((end
* * 4 4) . ,(ly
:make-moment
1 4))
337 ((end
* * 4 4) . ,(ly
:make-moment
3 4))
338 ((end
* * 2 2) . ,(ly
:make-moment
1 4))
339 ((end
* * 2 2) . ,(ly
:make-moment
1 2))
340 ((end
* * 2 2) . ,(ly
:make-moment
3 4))
341 ((end
* * 2 8) . ,(ly
:make-moment
1 4))
342 ((be
* * 5 8) . ,(ly
:make-moment
1 8))
343 ((end
* * 5 8) . ,(ly
:make-moment
5 8))
346 #(define modern-accidentals-style
347 `
(Staff
,(make-accidental-rule
'same-octave
0)
348 ,(make-accidental-rule
'any-octave
0)
349 ,(make-accidental-rule
'same-octave
1)
350 ,neo-modern-accidental-rule
))
351 #(define modern-cautionaries-style
352 `
(Staff
,(make-accidental-rule
'same-octave
1)
353 ,(make-accidental-rule
'any-octave
1)))
355 %%%%%%%%%%%%%%%%%%%%%%%%%%%% Editorial %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
357 %% Individual parts -----------------------------------------------%
360 #(define-music-function
(parser location part ref
)
361 (ly
:music? ly
:music?
)
362 #{\context Staff
<< $part
\new GhostVoice $ref
>> #})
365 #(define-music-function
(parser location part-one part-two ref
)
366 (ly
:music? ly
:music? ly
:music?
)
368 \new Staff
<< $part-one
\new GhostVoice $ref
>>
372 makeExtraSection
= % for violins
373 #(define-music-function
(parser location part-one part-two part-three ref
)
374 (ly
:music? ly
:music? ly
:music? ly
:music?
)
376 \new Staff
<< $part-one
\new GhostVoice $ref
>>
378 \new Staff $part-three
382 #(define-music-function
(parser location part-one ref
)
383 (ly
:music? ly
:music?
)
384 #{<< $part-one
\new GhostVoice $ref
>> #})
386 %%-----------------------------------------------------------------%