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 }
47 { \clef treble $droite
}
48 \new Staff
= "gauche" \with { \override VerticalAxisGroup
#'remove-empty
= ##f }
49 { \clef bass $gauche
}
53 #(define-music-function
(parser location chord result
) (ly
:music? ly
:music?
)
54 #{ << \oneVoice $chord
\\ { \voiceTwo %FIXME: ties could look better.
55 \override NoteHead
#'stencil
= #ly
:text-interface
::print
56 \override NoteHead
#'text
= \markup { \null \musicglyph #"noteheads.s2"}
57 \once \override NoteHead
#'text
= \markup {\null \override #'(direction
. 1)
58 \dir-column
{\musicglyph #"noteheads.s2" \teeny \musicglyph #"eight"}}
59 \override Stem
#'stencil
= ##f $result
60 \revert Stem
#'stencil
\revert NoteHead
#'stencil
} >> #})
62 %% Articulation shortcuts -----------------------------------------%
64 % Are these really needed?
65 #(define
(make-script x
)
66 (make-music
'ArticulationEvent
67 'articulation-type x
))
69 #(define
(add-script m x
)
70 (let
( (eventname
(ly
:music-property m
'name
)))
71 (if
(equal? eventname
'EventChord
)
72 (let
( (elements
(ly
:music-property m
'elements
)) )
73 (if
(not
(equal?
(ly
:music-property
(car elements
)
75 (set
! (ly
:music-property m
'elements
)
76 (append elements
(list
80 #(define
(double-script m t tt
)
81 (add-script
(add-script m t
) tt
))
84 #(define-music-function
(parser location music
)
86 (define
(make-script-music m
)
87 (add-script m
"staccato"))
88 (music-map make-script-music music
))
91 #(define-music-function
(parser location music
)
93 (define
(make-script-music m
)
94 (add-script m
"accent"))
95 (music-map make-script-music music
))
98 #(define-music-function
(parser location music
)
100 (define
(make-script-music m
)
101 (add-script m
"tenuto"))
102 (music-map make-script-music music
))
105 #(define-music-function
(parser location music
)
107 (define
(make-script-music m
)
108 (add-script m
"marcato"))
109 (music-map make-script-music music
))
112 #(define-music-function
(parser location music
)
114 (define
(make-script-music m
)
115 (add-script m
"portato"))
116 (music-map make-script-music music
))
119 #(define-music-function
(parser location music
)
121 (define
(make-script-music m
)
122 (double-script m
"tenuto" "accent"))
123 (music-map make-script-music music
))
126 #(define-music-function
(parser location music
)
128 (define
(make-script-music m
)
129 (double-script m
"tenuto" "marcato"))
130 (music-map make-script-music music
))
133 #(define-music-function
(parser location music
)
135 (define
(make-script-music m
)
136 (double-script m
"accent" "staccato"))
137 (music-map make-script-music music
))
140 #(define-music-function
(parser location music
)
142 (define
(make-script-music m
)
143 (double-script m
"marcato" "staccato"))
144 (music-map make-script-music music
))
148 #(let
((m
(make-music
'ArticulationEvent
149 'articulation-type
"flageolet")))
150 (set
! (ly
:music-property m
'tweaks
)
152 (ly
:music-property m
'tweaks
)))
156 #(make-music
'TextScriptEvent
158 'text
(markup
#:hspace
.4 #:rotate
45
159 #:musicglyph
"scripts.stopped"))
161 %% Music shortcuts ------------------------------------------------%
163 % This might not be needed
164 #(define
(octave-up noteevent
)
165 (let
* ((pitch
(ly
:music-property noteevent
'pitch
))
166 (octave
(ly
:pitch-octave pitch
))
167 (note
(ly
:pitch-notename pitch
))
168 (alteration
(ly
:pitch-alteration pitch
))
169 (duration
(ly
:music-property noteevent
'duration
))
171 (make-music
'NoteEvent
173 'pitch
(ly
:make-pitch
(1- octave
) note alteration
))))
176 #(define
(octavize-chord elements
)
177 (cond
((null? elements
) elements
)
178 ((eq?
(ly
:music-property
(car elements
) 'name
) 'NoteEvent
)
180 (cons
(octave-up
(car elements
))
181 (octavize-chord
(cdr elements
)))))
182 (else
(cons
(car elements
) (octavize-chord
(cdr elements
))))))
184 #(define
(octavize music
)
185 (let
* ((es (ly
:music-property music
'elements
))
186 (e (ly
:music-property music
'element
))
187 (name
(ly
:music-property music
'name
)))
188 (cond
((eq? name
'EventChord
)
189 (ly
:music-set-property
! music
'elements
(octavize-chord
es)))
191 (for-each
(lambda
(x
) (octavize x
)) es))
196 oct
= #(define-music-function
(parser location mus
) (ly
:music?
)
199 %%%%%%%%%%%%%%%%%%%%%%%% Layout Functions %%%%%%%%%%%%%%%%%%%%%%%%%%
201 %% Music layout ---------------------------------------------------%
203 droite
= { \change Staff
= "droite" }
205 gauche
= { \change Staff
= "gauche" }
207 #(define modern-auto-beam-settings
208 (append default-auto-beam-settings
210 ((end
* * 3 4) . ,(ly
:make-moment
1 4))
211 ((end
* * 3 4) . ,(ly
:make-moment
1 2))
212 ((end
* * 4 4) . ,(ly
:make-moment
1 4))
213 ((end
* * 4 4) . ,(ly
:make-moment
3 4))
214 ((end
* * 2 2) . ,(ly
:make-moment
1 4))
215 ((end
* * 2 2) . ,(ly
:make-moment
1 2))
216 ((end
* * 2 2) . ,(ly
:make-moment
3 4))
217 ((end
* * 2 8) . ,(ly
:make-moment
1 4))
218 ((be
* * 5 8) . ,(ly
:make-moment
1 8))
219 ((end
* * 5 8) . ,(ly
:make-moment
5 8))
222 #(define modern-accidentals-style
223 `
(Staff
,(make-accidental-rule
'same-octave
0)
224 ,(make-accidental-rule
'any-octave
0)
225 ,(make-accidental-rule
'same-octave
1)
226 ,neo-modern-accidental-rule
))
227 #(define modern-cautionaries-style
228 `
(Staff
,(make-accidental-rule
'same-octave
1)
229 ,(make-accidental-rule
'any-octave
1)))
231 %% Music formatting -----------------------------------------------%
234 #(define-music-function
(parser location notes
) (ly
:music?
)
235 #{ \tiny $notes
\normalsize #})
238 #(define-music-function
(parser location notes
) (ly
:music?
)
239 #{ \override NoteHead
#'style
= #'cross
241 \revert NoteHead
#'style
#})
244 \once \override NoteHead
#'transparent
= ##t
245 \once \override NoteHead
#'no-ledgers
= ##t
246 \once \override Stem
#'transparent
= ##t
247 \once \override Beam
#'transparent
= ##t
248 \once \override Accidental
#'transparent
= ##t
252 \once \override TupletBracket
#'transparent
= ##t
253 \once \override TupletNumber
#'transparent
= ##t
255 %%%%%%%%%%%%%%%%%%%%%%%%%% In-score Text %%%%%%%%%%%%%%%%%%%%%%%%%%%
257 %% Expressive indications -----------------------------------------%
259 #(define-markup-command
(indic layout props arg
) (markup?
)
260 (interpret-markup layout props
261 (markup
#:whiteout
#:small
#:italic arg
)))
263 %FIXME: because of the use of a music-function,
264 % Composite dynamics have to be entered *before*
265 % the affected beat (unlike standard dynamics).
267 #(define-music-function
(parser location dyn str
) (string? string?
)
268 (make-music
'SequentialMusic
'elements
270 (make-music
'OverrideProperty
272 'grob-property-path
(list
'self-alignment-X
)
273 'grob-value -
0.6 'once
#t
)
274 (make-music
'AbsoluteDynamicEvent
276 (markup
#:dynamic dyn
278 #:text
#:medium
#:upright str
)))))
281 #(define-music-function
(parser location str dyn
) (string? string?
)
282 (make-music
'SequentialMusic
'elements
284 (make-music
'OverrideProperty
286 'grob-property-path
(list
'self-alignment-X
)
287 'grob-value -
0.6 'once
#t
)
288 (make-music
'AbsoluteDynamicEvent
290 (markup
#:text
#:medium
#:upright str
295 #(define-music-function
(parser location texte
)
298 (markup
#:text
#:indic texte
)))
301 #(define-music-function
(parser location music
) (ly
:music?
)
303 (equal?
(ly
:music-property music
'name
) 'EventChord
)
304 (set
! (ly
:music-property music
'elements
)
305 (append
(ly
:music-property music
'elements
)
306 (list
(make-music
'TextScriptEvent
'text
307 (markup
#:translate
(cons
4 0)
308 #:indic
"(ten.)"))))))
312 #(define-music-function
(parser location text music
) (string? ly
:music?
)
314 (equal?
(ly
:music-property music
'name
) 'EventChord
)
315 (set
! (ly
:music-property music
'elements
)
316 (append
(ly
:music-property music
'elements
)
317 (list
(make-music
'TextScriptEvent
'direction
1
318 'text
(markup
#:indic text
))))))
322 #(define-music-function
(parser location music
) (ly
:music?
)
323 #{ \ind #"pizz." $music
#})
326 #(define-music-function
(parser location music
) (ly
:music?
)
327 #{ \ind #"arco" $music
#})
330 #(define-music-function
(parser location music
) (ly
:music?
)
331 #{ \ind #"simile" $music
#})
334 #(define-music-function
(parser location music
) (ly
:music?
)
335 #{ \ind #"loco" $music
#})
338 #(define-music-function
(parser location music
) (ly
:music?
)
339 #{ \ind #"(ordin.)" $music
#})
341 #(define
(make-text-span music t
)
342 (set
! (ly
:music-property music
'elements
)
343 (append
(ly
:music-property music
'elements
)
344 (list
(make-music
'TextSpanEvent
345 'span-direction t
))))
348 #(define-music-function
(parser location texte music
) (string? ly
:music?
)
349 #{ \override TextSpanner
#'bound-details
#'left
#'text
=
350 \markup { \bold $texte
}
351 $
(make-text-span music -
1)#})
354 #(define-music-function
(parser location music
) (ly
:music?
)
355 (make-text-span music
1))
357 %% Tempo indications ----------------------------------------------%
358 #(define-markup-command
(mvt layout props arg
) (markup?
)
359 (interpret-markup layout props
360 (markup
#:huge
#:bold arg
)))
362 %%%%%%%%%%%%%%%%%%%%%%%%%% Text Functions %%%%%%%%%%%%%%%%%%%%%%%%%%
364 %% Lyrics formatting ----------------------------------------------%
367 \override Lyrics
. LyricExtender
#'stencil
= ##f }
370 \revert Lyrics
. LyricExtender
#'stencil
}
373 \once \override LyricText
#'self-alignment-X
= #0.9 }
376 \once \override LyricHyphen
#'minimum-distance
= #4
377 \once \override LyricHyphen
#'length
= #2
378 \once \override LyricHyphen
#'thickness
= #1.2
382 \once \override LyricText
#'font-shape
= #'italic
}
385 \override LyricText
#'font-shape
= #'caps
}
388 \revert LyricText
#'font-shape
}
391 %% Scenography formatting ---------------------------------------%
393 \once \override TextScript
#'extra-spacing-width
= #'(0 . 0)
394 \once \override TextScript
#'infinite-spacing-height
= ##t
397 #(define-markup-command
(did layout props text
) (markup?
)
398 (interpret-markup layout props
399 (markup
#:override
'(line-width
. 40)
400 #:override
'(box-padding
. 1)
401 #:override
'(corner-radius
. 2)
402 #:rounded-box
#:sans
#:italic
#:small
#:justify-string text
)))
404 #(define-markup-command
(init-did layout props text
) (markup?
)
405 (interpret-markup layout props
407 ;
#:override
(cons
'line-width
(* 1 (chain-assoc-get
'line-width props
)))
409 #:override
'(line-width
. 60)
410 #:override
'(box-padding
. 1.5)
411 #:override
'(corner-radius
. 2)
412 #:rounded-box
#:sans
#:italic
#:small
#:justify-string text
))))
414 #(define-markup-command
(vspace layout props amount
) (number?
)
415 (let
((amount
(* amount
3.0)))
417 (ly
:make-stencil
"" (cons -
1 1) (cons
0 amount
))
418 (ly
:make-stencil
"" (cons -
1 1) (cons amount amount
)))))