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 #(define-music-function
(parser location music
) (ly
:music?
)
245 #{\override NoteHead
#'stencil
= #ly
:text-interface
::print
246 \override NoteHead
#'text
= \markup \musicglyph #"scripts.sforzato"
247 \override NoteHead
#'extra-offset
= #'(0.1 . 0.0 )
249 \revert NoteHead
#'stencil
250 \revert NoteHead
#'text
251 \revert NoteHead
#'extra-offset
#})
254 \once \override NoteHead
#'transparent
= ##t
255 \once \override NoteHead
#'no-ledgers
= ##t
256 \once \override Stem
#'transparent
= ##t
257 \once \override Beam
#'transparent
= ##t
258 \once \override Accidental
#'transparent
= ##t
262 \once \override TupletBracket
#'transparent
= ##t
263 \once \override TupletNumber
#'transparent
= ##t
265 %%%%%%%%%%%%%%%%%%%%%%%%%% In-score Text %%%%%%%%%%%%%%%%%%%%%%%%%%%
267 %% Expressive indications -----------------------------------------%
269 #(define-markup-command
(indic layout props arg
) (markup?
)
270 (interpret-markup layout props
271 (markup
#:whiteout
#:small
#:italic arg
)))
273 % because of the use of a music-function,
274 % non-predefined composite dynamics have to be entered *before*
275 % the affected beat (unlike standard or predefined dynamics).
277 #(define-music-function
(parser location dyn str
) (string? string?
)
278 (make-music
'SequentialMusic
'elements
280 (make-music
'OverrideProperty
282 'grob-property-path
(list
'self-alignment-X
)
283 'grob-value -
0.6 'once
#t
)
284 (make-music
'AbsoluteDynamicEvent
286 (markup
#:dynamic dyn
288 #:text
#:medium
#:upright str
)))))
291 #(define-music-function
(parser location str dyn
) (string? string?
)
292 (make-music
'SequentialMusic
'elements
294 (make-music
'OverrideProperty
296 'grob-property-path
(list
'self-alignment-X
)
297 'grob-value -
0.6 'once
#t
)
298 (make-music
'AbsoluteDynamicEvent
300 (markup
#:text
#:medium
#:upright str
304 %%% This function was provided by Graham Percival.
305 #(define
(make-dynamic-extra dynamic string
)
307 'AbsoluteDynamicEvent
309 ;; calculate centering for text
310 (list
(cons
(quote X-offset
)
311 (+ -
0.5 (* -
0.5 (string-length dynamic
)))))
314 ;; uncomment next line for debugging
319 #:normal-text
#:italic string
))
322 #(define
(make-extra-dynamic string dynamic
)
324 'AbsoluteDynamicEvent
326 ;; calculate centering for text
327 (list
(cons
(quote X-offset
)
328 (+ -
0.5 (* -
0.5 (string-length dynamic
)))))
331 ;; uncomment next line for debugging
334 #:normal-text
#:italic string
339 ffsubito
= #(make-dynamic-extra
"ff" "subito")
340 fsubito
= #(make-dynamic-extra
"f" "subito")
341 fmolto
= #(make-dynamic-extra
"f" "molto")
342 ppsempre
= #(make-dynamic-extra
"pp" "sempre")
343 mfsempre
= #(make-dynamic-extra
"mf" "sempre")
344 mpsostenuto
= #(make-dynamic-extra
"mp" "sostenuto")
345 pdolce
= #(make-dynamic-extra
"p" "dolce")
346 mfleggiero
= #(make-dynamic-extra
"mf" "leggiero")
348 piuf
= #(make-extra-dynamic
"più" "f")
349 pocof
= #(make-extra-dynamic
"poco" "f")
352 #(define-music-function
(parser location texte
)
355 (markup
#:text
#:indic texte
)))
358 #(define-music-function
(parser location music
) (ly
:music?
)
360 (equal?
(ly
:music-property music
'name
) 'EventChord
)
361 (set
! (ly
:music-property music
'elements
)
362 (append
(ly
:music-property music
'elements
)
363 (list
(make-music
'TextScriptEvent
'text
364 (markup
#:translate
(cons
4 0)
365 #:indic
"(ten.)"))))))
369 #(define-music-function
(parser location text music
) (string? ly
:music?
)
371 (equal?
(ly
:music-property music
'name
) 'EventChord
)
372 (set
! (ly
:music-property music
'elements
)
373 (append
(ly
:music-property music
'elements
)
374 (list
(make-music
'TextScriptEvent
'direction
1
375 'text
(markup
#:indic text
))))))
379 #(define-music-function
(parser location music
) (ly
:music?
)
380 #{ \ind #"pizz." $music
#})
383 #(define-music-function
(parser location music
) (ly
:music?
)
384 #{ \ind #"arco" $music
#})
387 #(define-music-function
(parser location music
) (ly
:music?
)
388 #{ \ind #"simile" $music
#})
391 #(define-music-function
(parser location music
) (ly
:music?
)
392 #{ \ind #"loco" $music
#})
395 #(define-music-function
(parser location music
) (ly
:music?
)
396 #{ \ind #"(ordin.)" $music
#})
398 #(define
(make-text-span music t
)
399 (set
! (ly
:music-property music
'elements
)
400 (append
(ly
:music-property music
'elements
)
401 (list
(make-music
'TextSpanEvent
402 'span-direction t
))))
405 #(define-music-function
(parser location texte music
) (string? ly
:music?
)
406 #{ \override TextSpanner
#'bound-details
#'left
#'text
=
407 \markup { \bold $texte
}
408 $
(make-text-span music -
1)#})
411 #(define-music-function
(parser location music
) (ly
:music?
)
412 (make-text-span music
1))
414 %% Tempo indications ----------------------------------------------%
415 #(define-markup-command
(mvt layout props arg
) (markup?
)
416 (interpret-markup layout props
417 (markup
#:huge
#:bold arg
)))
419 %%%%%%%%%%%%%%%%%%%%%%%%%% Text Functions %%%%%%%%%%%%%%%%%%%%%%%%%%
421 %% Lyrics formatting ----------------------------------------------%
424 \override Lyrics
. LyricExtender
#'stencil
= ##f }
427 \revert Lyrics
. LyricExtender
#'stencil
}
430 \once \override LyricText
#'self-alignment-X
= #0.9 }
433 \once \override LyricHyphen
#'minimum-distance
= #4
434 \once \override LyricHyphen
#'length
= #2
435 \once \override LyricHyphen
#'thickness
= #1.2
439 \once \override LyricText
#'font-shape
= #'italic
}
442 \override LyricText
#'font-shape
= #'caps
}
445 \revert LyricText
#'font-shape
}
448 %% Scenography formatting ---------------------------------------%
450 \once \override TextScript
#'extra-spacing-width
= #'(0 . 0)
451 \once \override TextScript
#'infinite-spacing-height
= ##t
454 #(define-markup-command
(did layout props text
) (markup?
)
455 (interpret-markup layout props
456 (markup
#:override
'(line-width
. 40)
457 #:override
'(box-padding
. 1)
458 #:override
'(corner-radius
. 2)
459 #:rounded-box
#:sans
#:italic
#:small
#:justify-string text
)))
461 #(define-markup-command
(init-did layout props text
) (markup?
)
462 (interpret-markup layout props
464 ;
#:override
(cons
'line-width
(* 1 (chain-assoc-get
'line-width props
)))
466 #:override
'(line-width
. 60)
467 #:override
'(box-padding
. 1.5)
468 #:override
'(corner-radius
. 2)
469 #:rounded-box
#:sans
#:italic
#:small
#:justify-string text
))))
471 #(define-markup-command
(vspace layout props amount
) (number?
)
472 (let
((amount
(* amount
3.0)))
474 (ly
:make-stencil
"" (cons -
1 1) (cons
0 amount
))
475 (ly
:make-stencil
"" (cons -
1 1) (cons amount amount
)))))