1 %------------------------------------------------------------------%
2 % Opéra Libre -- functions.ly %
4 % (c) Valentin Villenave, 2008 %
6 %------------------------------------------------------------------%
9 %%%%%%%%%%%%%%%%%%%%%%%%% Music Shortcuts %%%%%%%%%%%%%%%%%%%%%%%%%%
11 %% Rhythm shortcuts -----------------------------------------------%
14 #(define-music-function
(parser location music
) (ly
:music?
)
15 #{ \times 2/3 $music
#})
18 #(define-music-function
(parser location music
) (ly
:music?
)
19 #{ \times 4/5 $music
#})
22 #(define-music-function
(parser location music
) (ly
:music?
)
23 #{ \times 4/6 $music
#})
26 #(define-music-function
(parser location music
) (ly
:music?
)
27 #{ \times 4/7 $music
#})
30 %% Polyphony shortcuts --------------------------------------------%
33 #(define-music-function
(parser location one two
) (ly
:music? ly
:music?
)
34 #{ << { \voiceTwo $one
} \\ { \voiceOne $two
} >> #})
37 #(define-music-function
(parser location droite gauche
) (ly
:music? ly
:music?
)
39 \context Staff
= "droite" $droite
40 \context Staff
= "gauche" $gauche
44 #(define-music-function
(parser location droite gauche
) (ly
:music? ly
:music?
)
46 \new Staff
= "droite" \with { \override VerticalAxisGroup
#'remove-empty
= ##f }
48 \new Staff
= "gauche" \with { \override VerticalAxisGroup
#'remove-empty
= ##f }
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
)
64 (set
! (ly
:music-property m
'elements
)
65 (append elements
(list
69 #(define
(double-script m t tt
)
70 (add-script
(add-script m t
) tt
))
73 #(define-music-function
(parser location music
)
75 (define
(make-script-music m
)
76 (add-script m
"staccato"))
77 (music-map make-script-music music
))
80 #(define-music-function
(parser location music
)
82 (define
(make-script-music m
)
83 (add-script m
"accent"))
84 (music-map make-script-music music
))
87 #(define-music-function
(parser location music
)
89 (define
(make-script-music m
)
90 (add-script m
"tenuto"))
91 (music-map make-script-music music
))
94 #(define-music-function
(parser location music
)
96 (define
(make-script-music m
)
97 (add-script m
"marcato"))
98 (music-map make-script-music music
))
101 #(define-music-function
(parser location music
)
103 (define
(make-script-music m
)
104 (add-script m
"portato"))
105 (music-map make-script-music music
))
108 #(define-music-function
(parser location music
)
110 (define
(make-script-music m
)
111 (double-script m
"tenuto" "accent"))
112 (music-map make-script-music music
))
115 #(define-music-function
(parser location music
)
117 (define
(make-script-music m
)
118 (double-script m
"tenuto" "marcato"))
119 (music-map make-script-music music
))
122 #(define-music-function
(parser location music
)
124 (define
(make-script-music m
)
125 (double-script m
"accent" "staccato"))
126 (music-map make-script-music music
))
129 #(define-music-function
(parser location music
)
131 (define
(make-script-music m
)
132 (double-script m
"marcato" "staccato"))
133 (music-map make-script-music music
))
137 #(let
((m
(make-music
'ArticulationEvent
138 'articulation-type
"flageolet")))
139 (set
! (ly
:music-property m
'tweaks
)
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
))
154 (make-music
'NoteEvent
156 'pitch
(ly
:make-pitch
(1- octave
) note alteration
))))
159 #(define
(octavize-chord elements
)
160 (cond
((null? elements
) elements
)
161 ((eq?
(ly
:music-property
(car elements
) 'name
) 'NoteEvent
)
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)))
174 (for-each
(lambda
(x
) (octavize x
)) es))
179 oct
= #(define-music-function
(parser location mus
) (ly
:music?
)
182 %%%%%%%%%%%%%%%%%%%%%%%% Layout Functions %%%%%%%%%%%%%%%%%%%%%%%%%%
184 %% Music layout ---------------------------------------------------%
186 droite
= { \change Staff
= "droite" }
188 gauche
= { \change Staff
= "gauche" }
190 %% Music formatting -----------------------------------------------%
193 #(define-music-function
(parser location notes
) (ly
:music?
)
194 #{ \tiny $notes
\normalsize #})
197 #(define-music-function
(parser location notes
) (ly
:music?
)
198 #{ \override NoteHead
#'style
= #'cross
200 \revert NoteHead
#'style
#})
202 %%%%%%%%%%%%%%%%%%%%%%%%%% In-score Text %%%%%%%%%%%%%%%%%%%%%%%%%%%
204 %% Expressive indications -----------------------------------------%
206 #(define-markup-command
(indic layout props arg
) (markup?
)
207 (interpret-markup layout props
208 (markup
#:whiteout
#:small
#:italic arg
)))
211 #(define-music-function
(parser location nuance texte
)
214 (markup
#:dynamic nuance
216 #:text
#:medium
#:upright texte
)))
220 #(define-music-function
(parser location music
) (ly
:music?
)
222 (equal?
(ly
:music-property music
'name
) 'EventChord
)
223 (set
! (ly
:music-property music
'elements
)
224 (append
(ly
:music-property music
'elements
)
225 (list
(make-music
'TextScriptEvent
'text
226 (markup
#:translate
(cons
4 0)
227 #:indic
"(ten.)"))))))
231 #(define-music-function
(parser location text music
) (string? ly
:music?
)
233 (equal?
(ly
:music-property music
'name
) 'EventChord
)
234 (set
! (ly
:music-property music
'elements
)
235 (append
(ly
:music-property music
'elements
)
236 (list
(make-music
'TextScriptEvent
'direction
1
237 'text
(markup
#:indic text
))))))
240 #(define
(make-text-span music t
)
241 (set
! (ly
:music-property music
'elements
)
242 (append
(ly
:music-property music
'elements
)
243 (list
(make-music
'TextSpanEvent
244 'span-direction t
))))
247 #(define-music-function
(parser location texte music
) (string? ly
:music?
)
248 #{ \override TextSpanner
#'bound-details
#'left
#'text
=
249 \markup { \bold $texte
}
250 $
(make-text-span music -
1)#})
253 #(define-music-function
(parser location music
) (ly
:music?
)
254 (make-text-span music
1))
256 %% Tempo indications ----------------------------------------------%
258 #(define-markup-command
(mvt layout props arg
) (markup?
)
259 (interpret-markup layout props
260 (markup
#:huge
#:bold arg
)))
262 #(define
((make-format-movement-markup-function text
) duration count context
)
263 (markup
#:mvt text
#:hspace
1
265 #:general-align Y DOWN
#:smaller
266 #:note-by-number
(ly
:duration-log duration
)
267 (ly
:duration-dot-count duration
)
270 (number-
>string count
)
274 #(define
(string-
>duration duration-string
)
275 "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a duration object."
276 (let
* ((length
(string-length duration-string
))
277 (dot-index
(or
(string-index duration-string
#\
.) length
))
278 (len
(substring duration-string
0 dot-index
))
279 (dots
(- length dot-index
)))
280 (ly
:make-duration
(cond
((string
=? len
"breve") -
1)
281 ((string
=? len
"longa") -
2)
282 ((string
=? len
"maxima") -
3)
283 (else
(log
2 (string-
>number len
))))
287 #(define-music-function
(parser location text duration count music
)
288 (string? string? integer? ly
:music?
)
290 \set Score
.metronomeMarkFormatter
= #(make-format-movement-markup-function $text
)
291 \set Score
.tempoWholesPerMinute
= #$
(ly
:moment-mul
(ly
:make-moment count
1)
293 (string-
>duration duration
)))
294 \set Score
.tempoUnitDuration
= #$
(string-
>duration duration
)
295 \set Score
.tempoUnitCount
= #$count
297 \set Score
.metronomeMarkFormatter
= #format-metronome-markup
301 %%%%%%%%%%%%%%%%%%%%%%%%%% Text Functions %%%%%%%%%%%%%%%%%%%%%%%%%%
303 %% Lyrics formatting ----------------------------------------------%
306 \override Lyrics
. LyricExtender
#'stencil
= ##f }
309 \revert Lyrics
. LyricExtender
#'stencil
}
312 \once \override LyricText
#'self-alignment-X
= #0.9 }
315 \once \override LyricHyphen
#'minimum-distance
= #4
316 \once \override LyricHyphen
#'length
= #2
317 \once \override LyricHyphen
#'thickness
= #1.2
321 \once \override LyricText
#'font-shape
= #'italic
}
323 %% Scenography formatting ---------------------------------------%
325 #(define-markup-command
(did layout props text
) (markup?
)
326 (interpret-markup layout props
327 (markup
#:override
'(line-width
. 40)
328 #:override
'(box-padding
. 1)
329 #:override
'(corner-radius
. 2)
330 #:rounded-box
#:sans
#:italic
#:small
#:justify-string text
)))
332 #(define-markup-command
(init-did layout props text
) (markup?
)
333 (interpret-markup layout props
335 ;
#:override
(cons
'line-width
(* 1 (chain-assoc-get
'line-width props
)))
337 #:override
'(line-width
. 50)
338 #:override
'(box-padding
. 1.5)
339 #:override
'(corner-radius
. 2)
340 #:rounded-box
#:sans
#:italic
#:small
#:justify-string text
))))
342 #(define-markup-command
(vspace layout props amount
) (number?
)
343 (let
((amount
(* amount
3.0)))
345 (ly
:make-stencil
"" (cons -
1 1) (cons
0 amount
))
346 (ly
:make-stencil
"" (cons -
1 1) (cons amount amount
)))))