1 %------------------------------------------------------------------%
2 % Opéra Libre -- functions.ly %
4 % (c) Valentin Villenave, 2008 %
6 %------------------------------------------------------------------%
9 % Various additional functions.
10 % TODO: split and rearrange.
12 %%%%%%%%%%%%%%%%%%%%%%%%% Music Shortcuts %%%%%%%%%%%%%%%%%%%%%%%%%%
14 %% Rhythm shortcuts -----------------------------------------------%
17 #(define-music-function
(parser location music
) (ly
:music?
)
18 #{ \times 2/3 $music
#})
21 #(define-music-function
(parser location music
) (ly
:music?
)
22 #{ \times 4/5 $music
#})
25 #(define-music-function
(parser location music
) (ly
:music?
)
26 #{ \times 4/6 $music
#})
29 #(define-music-function
(parser location music
) (ly
:music?
)
30 #{ \times 4/7 $music
#})
33 %% Polyphony shortcuts --------------------------------------------%
36 #(define-music-function
(parser location one two
) (ly
:music? ly
:music?
)
37 #{ << { \voiceTwo $one
} \\ { \voiceOne $two
} >> #})
40 #(define-music-function
(parser location one two
) (ly
:music? ly
:music?
)
41 #{ << { \stemDown $one
\stemNeutral } \new DrumVoice
{ \stemUp $two
} >> #})
44 #(define-music-function
(parser location droite gauche
) (ly
:music? ly
:music?
)
46 \context Staff
= "md" $droite
47 \context Staff
= "mg" $gauche
50 md
= { \change Staff
= "md" }
52 mg
= { \change Staff
= "mg" }
55 #(define-music-function
(parser location droite gauche
) (ly
:music? ly
:music?
)
57 \new Staff
= "md" \with { \override VerticalAxisGroup
#'remove-empty
= ##f }
58 { \clef treble $droite
}
59 \new Staff
= "mg" \with { \override VerticalAxisGroup
#'remove-empty
= ##f }
60 { \clef bass $gauche
}
63 droite
= { \change Staff
= "percuDroite" }
65 gauche
= { \change Staff
= "percuGauche" }
68 #(define-music-function
(parser location droite gauche
) (ly
:music? ly
:music?
)
70 \new Staff
= "percuDroite" \with { \override VerticalAxisGroup
#'remove-empty
= ##f }
71 { \clef treble $droite
}
72 \new Staff
= "percuGauche" \with { \override VerticalAxisGroup
#'remove-empty
= ##f }
73 { \clef bass $gauche
}
77 #(define-music-function
(parser location music
) (ly
:music?
)
79 \unset Score
.keepAliveInterfaces
81 \set Score
.keepAliveInterfaces
= #'(rhythmic-grob-interface
82 lyric-interface percent-repeat-item-interface
83 percent-repeat-interface stanza-number-interface
)
86 %% Articulation shortcuts -----------------------------------------%
89 #(define-music-function
(parser location chord result
) (ly
:music? ly
:music?
)
90 #{ << \oneVoice $chord
\\ { \voiceTwo %FIXME: ties could look better.
91 \override NoteHead
#'stencil
= #ly
:text-interface
::print
92 \override NoteHead
#'text
= \markup { \null \musicglyph #"noteheads.s2"}
93 \once \override NoteHead
#'text
= \markup {\null \override #'(direction
. 1)
94 \dir-column
{\musicglyph #"noteheads.s2" \teeny \musicglyph #"eight"}}
95 \override Stem
#'stencil
= ##f $result
96 \revert Stem
#'stencil
\revert NoteHead
#'stencil
} >> #})
98 % Are these really needed?
99 #(define
(make-script x
)
100 (make-music
'ArticulationEvent
101 'articulation-type x
))
103 #(define
(add-script m x
)
104 (let
( (eventname
(ly
:music-property m
'name
)))
105 (if
(equal? eventname
'EventChord
)
106 (let
( (elements
(ly
:music-property m
'elements
)) )
107 (if
(not
(equal?
(ly
:music-property
(car elements
)
109 (set
! (ly
:music-property m
'elements
)
110 (append elements
(list
111 (make-script x
)))))))
114 #(define
(double-script m t tt
)
115 (add-script
(add-script m t
) tt
))
118 #(define-music-function
(parser location music
)
120 (define
(make-script-music m
)
121 (add-script m
"staccato"))
122 (music-map make-script-music music
))
125 #(define-music-function
(parser location music
)
127 (define
(make-script-music m
)
128 (add-script m
"accent"))
129 (music-map make-script-music music
))
132 #(define-music-function
(parser location music
)
134 (define
(make-script-music m
)
135 (add-script m
"tenuto"))
136 (music-map make-script-music music
))
139 #(define-music-function
(parser location music
)
141 (define
(make-script-music m
)
142 (add-script m
"marcato"))
143 (music-map make-script-music music
))
146 #(define-music-function
(parser location music
)
148 (define
(make-script-music m
)
149 (add-script m
"portato"))
150 (music-map make-script-music music
))
153 #(define-music-function
(parser location music
)
155 (define
(make-script-music m
)
156 (double-script m
"tenuto" "accent"))
157 (music-map make-script-music music
))
160 #(define-music-function
(parser location music
)
162 (define
(make-script-music m
)
163 (double-script m
"tenuto" "marcato"))
164 (music-map make-script-music music
))
167 #(define-music-function
(parser location music
)
169 (define
(make-script-music m
)
170 (double-script m
"accent" "staccato"))
171 (music-map make-script-music music
))
174 #(define-music-function
(parser location music
)
176 (define
(make-script-music m
)
177 (double-script m
"marcato" "staccato"))
178 (music-map make-script-music music
))
182 #(let
((m
(make-music
'ArticulationEvent
183 'articulation-type
"flageolet")))
184 (set
! (ly
:music-property m
'tweaks
)
186 (ly
:music-property m
'tweaks
)))
190 #(make-music
'TextScriptEvent
192 'text
(markup
#:hspace
.4 #:rotate
45
193 #:musicglyph
"scripts.stopped"))
196 #(make-articulation
"stopped")
199 #(let
* ((m
(make-music
'ArpeggioEvent
)))
200 (ly
:music-set-property
! m
'tweaks
201 (acons
'arpeggio-direction
1
202 (ly
:music-property m
'tweaks
)))
206 #(let
* ((m
(make-music
'ArpeggioEvent
)))
207 (ly
:music-set-property
! m
'tweaks
208 (acons
'arpeggio-direction -
1
209 (ly
:music-property m
'tweaks
)))
213 #(let
* ((m
(make-music
'ArpeggioEvent
)))
214 (ly
:music-set-property
! m
'tweaks
215 (acons
'stencil ly
:arpeggio
::brew-chord-bracket
216 (ly
:music-property m
'tweaks
)))
219 %% Music shortcuts ------------------------------------------------%
221 sk
= \set Score
.skipTypesetting
= ##t
223 unsk
= \set Score
.skipTypesetting
= ##f
225 % This might not be needed
226 #(define
(octave-up noteevent
)
227 (let
* ((pitch
(ly
:music-property noteevent
'pitch
))
228 (octave
(ly
:pitch-octave pitch
))
229 (note
(ly
:pitch-notename pitch
))
230 (alteration
(ly
:pitch-alteration pitch
))
231 (duration
(ly
:music-property noteevent
'duration
))
233 (make-music
'NoteEvent
235 'pitch
(ly
:make-pitch
(1- octave
) note alteration
))))
238 #(define
(octavize-chord elements
)
239 (cond
((null? elements
) elements
)
240 ((eq?
(ly
:music-property
(car elements
) 'name
) 'NoteEvent
)
242 (cons
(octave-up
(car elements
))
243 (octavize-chord
(cdr elements
)))))
244 (else
(cons
(car elements
) (octavize-chord
(cdr elements
))))))
246 #(define
(octavize music
)
247 (let
* ((es (ly
:music-property music
'elements
))
248 (e (ly
:music-property music
'element
))
249 (name
(ly
:music-property music
'name
)))
250 (cond
((eq? name
'EventChord
)
251 (ly
:music-set-property
! music
'elements
(octavize-chord
es)))
253 (for-each
(lambda
(x
) (octavize x
)) es))
258 oct
= #(define-music-function
(parser location mus
) (ly
:music?
)
262 %%%%%%%%%%%%%%%%%%%%%%%% Layout Functions %%%%%%%%%%%%%%%%%%%%%%%%%%
264 %% Music layout ---------------------------------------------------%
266 #(define modern-auto-beam-settings
267 (append default-auto-beam-settings
269 ((end
* * 3 4) . ,(ly
:make-moment
1 4))
270 ((end
* * 3 4) . ,(ly
:make-moment
1 2))
271 ((end
* * 4 4) . ,(ly
:make-moment
1 4))
272 ((end
* * 4 4) . ,(ly
:make-moment
3 4))
273 ((end
* * 2 2) . ,(ly
:make-moment
1 4))
274 ((end
* * 2 2) . ,(ly
:make-moment
1 2))
275 ((end
* * 2 2) . ,(ly
:make-moment
3 4))
276 ((end
* * 2 8) . ,(ly
:make-moment
1 4))
277 ((be
* * 5 8) . ,(ly
:make-moment
1 8))
278 ((end
* * 5 8) . ,(ly
:make-moment
5 8))
281 #(define modern-accidentals-style
282 `
(Staff
,(make-accidental-rule
'same-octave
0)
283 ,(make-accidental-rule
'any-octave
0)
284 ,(make-accidental-rule
'same-octave
1)
285 ,neo-modern-accidental-rule
))
286 #(define modern-cautionaries-style
287 `
(Staff
,(make-accidental-rule
'same-octave
1)
288 ,(make-accidental-rule
'any-octave
1)))
290 %% Music formatting -----------------------------------------------%
293 #(define-music-function
(parser location notes
) (ly
:music?
)
294 #{ \tiny $notes
\normalsize #})
297 #(define-music-function
(parser location notes
) (ly
:music?
)
298 #{ \override NoteHead
#'style
= #'cross
300 \revert NoteHead
#'style
#})
303 #(define-music-function
(parser location music
) (ly
:music?
)
304 #{\override NoteHead
#'stencil
= #ly
:text-interface
::print
305 \override NoteHead
#'text
= \markup \musicglyph #"scripts.sforzato"
306 \override NoteHead
#'extra-offset
= #'(0.1 . 0.0 )
308 \revert NoteHead
#'stencil
309 \revert NoteHead
#'text
310 \revert NoteHead
#'extra-offset
#})
313 \once \override NoteHead
#'transparent
= ##t
314 \once \override NoteHead
#'no-ledgers
= ##t
315 \once \override Stem
#'transparent
= ##t
316 \once \override Beam
#'transparent
= ##t
317 \once \override Accidental
#'transparent
= ##t
321 \once \override TupletBracket
#'transparent
= ##t
322 \once \override TupletNumber
#'transparent
= ##t
326 \once \override Stem
#'direction
= #DOWN
330 \once \override Stem
#'direction
= #UP