Code cleaning and reordering.
[opera_libre.git] / definitions / functions.ly
blobd25904529cd7e9126175457a319632879f0665da
1 %------------------------------------------------------------------%
2 % Opéra Libre -- functions.ly %
3 % %
4 % (c) Valentin Villenave, 2008 %
5 % %
6 %------------------------------------------------------------------%
8 % Various additional functions.
10 %%%%%%%%%%%%%%%%%%%%%%%%% Music Shortcuts %%%%%%%%%%%%%%%%%%%%%%%%%%
12 %% Rhythm shortcuts -----------------------------------------------%
14 t =
15 #(define-music-function (parser location music) (ly:music?)
16 #{ \times 2/3 $music #})
18 tt =
19 #(define-music-function (parser location music) (ly:music?)
20 #{ \times 4/5 $music #})
22 ttt =
23 #(define-music-function (parser location music) (ly:music?)
24 #{ \times 4/6 $music #})
26 tttt =
27 #(define-music-function (parser location music) (ly:music?)
28 #{ \times 4/7 $music #})
31 %% Polyphony shortcuts --------------------------------------------%
33 pl =
34 #(define-music-function (parser location one two) (ly:music? ly:music?)
35 #{ << { \voiceTwo $one } \\ { \voiceOne $two } >> #})
37 plperc =
38 #(define-music-function (parser location one two) (ly:music? ly:music?)
39 #{ << { \stemDown $one \stemNeutral } \new DrumVoice { \stemUp $two } >> #})
41 parallel=
42 #(define-music-function (parser location droite gauche) (ly:music? ly:music?)
43 #{ <<
44 \context Staff = "md" $droite
45 \context Staff = "mg" $gauche
46 >> #})
48 md = { \change Staff = "md" }
50 mg = { \change Staff = "mg" }
52 PianoDeuxMains=
53 #(define-music-function (parser location droite gauche) (ly:music? ly:music?)
54 #{ <<
55 \new Staff = "md" \with { \override VerticalAxisGroup #'remove-empty = ##f }
56 { \clef treble $droite }
57 \new Staff = "mg" \with { \override VerticalAxisGroup #'remove-empty = ##f }
58 { \clef bass $gauche }
59 >> #})
61 droite = { \change Staff = "percuDroite" }
63 gauche = { \change Staff = "percuGauche" }
65 PercuDeuxMains=
66 #(define-music-function (parser location droite gauche) (ly:music? ly:music?)
67 #{ <<
68 \new Staff = "percuDroite" \with { \override VerticalAxisGroup #'remove-empty = ##f }
69 { \clef treble $droite }
70 \new Staff = "percuGauche" \with { \override VerticalAxisGroup #'remove-empty = ##f }
71 { \clef bass $gauche }
72 >> #})
74 showAnyway =
75 #(define-music-function (parser location music) (ly:music?)
77 \unset Score.keepAliveInterfaces
78 $music
79 \set Score.keepAliveInterfaces = #'(rhythmic-grob-interface
80 lyric-interface percent-repeat-item-interface
81 percent-repeat-interface stanza-number-interface)
82 #})
84 %% Articulation shortcuts -----------------------------------------%
86 harmo =
87 #(define-music-function (parser location chord result) (ly:music? ly:music?)
88 #{ << \oneVoice $chord \\ { \voiceTwo %FIXME: ties could look better.
89 \override NoteHead #'stencil = #ly:text-interface::print
90 \override NoteHead #'text = \markup { \null \musicglyph #"noteheads.s2"}
91 \once \override NoteHead #'text = \markup {\null \override #'(direction . 1)
92 \dir-column {\musicglyph #"noteheads.s2" \teeny \musicglyph #"eight"}}
93 \override Stem #'stencil = ##f $result
94 \revert Stem #'stencil \revert NoteHead #'stencil } >> #})
96 % Are these really needed?
97 #(define (make-script x)
98 (make-music 'ArticulationEvent
99 'articulation-type x))
101 #(define (add-script m x)
102 (let ( (eventname (ly:music-property m 'name)))
103 (if (equal? eventname 'EventChord)
104 (let ( (elements (ly:music-property m 'elements)) )
105 (if (not (equal? (ly:music-property (car elements)
106 'name) 'RestEvent))
107 (set! (ly:music-property m 'elements)
108 (append elements (list
109 (make-script x)))))))
112 #(define (double-script m t tt)
113 (add-script (add-script m t) tt))
115 st =
116 #(define-music-function (parser location music)
117 (ly:music?)
118 (define (make-script-music m)
119 (add-script m "staccato"))
120 (music-map make-script-music music))
122 acc =
123 #(define-music-function (parser location music)
124 (ly:music?)
125 (define (make-script-music m)
126 (add-script m "accent"))
127 (music-map make-script-music music))
129 det =
130 #(define-music-function (parser location music)
131 (ly:music?)
132 (define (make-script-music m)
133 (add-script m "tenuto"))
134 (music-map make-script-music music))
136 marc =
137 #(define-music-function (parser location music)
138 (ly:music?)
139 (define (make-script-music m)
140 (add-script m "marcato"))
141 (music-map make-script-music music))
143 stdet =
144 #(define-music-function (parser location music)
145 (ly:music?)
146 (define (make-script-music m)
147 (add-script m "portato"))
148 (music-map make-script-music music))
150 accdet =
151 #(define-music-function (parser location music)
152 (ly:music?)
153 (define (make-script-music m)
154 (double-script m "tenuto" "accent"))
155 (music-map make-script-music music))
157 marcdet =
158 #(define-music-function (parser location music)
159 (ly:music?)
160 (define (make-script-music m)
161 (double-script m "tenuto" "marcato"))
162 (music-map make-script-music music))
164 accst =
165 #(define-music-function (parser location music)
166 (ly:music?)
167 (define (make-script-music m)
168 (double-script m "accent" "staccato"))
169 (music-map make-script-music music))
171 marcst =
172 #(define-music-function (parser location music)
173 (ly:music?)
174 (define (make-script-music m)
175 (double-script m "marcato" "staccato"))
176 (music-map make-script-music music))
179 CaV=
180 #(let ((m (make-music 'ArticulationEvent
181 'articulation-type "flageolet")))
182 (set! (ly:music-property m 'tweaks)
183 (acons 'font-size -3
184 (ly:music-property m 'tweaks)))
187 thumbpizz =
188 #(make-music 'TextScriptEvent
189 'direction 1
190 'text (markup #:hspace .4 #:rotate 45
191 #:musicglyph "scripts.stopped"))
193 leftpizz =
194 #(make-articulation "stopped")
196 arpeggUp =
197 #(let* ((m (make-music 'ArpeggioEvent)))
198 (ly:music-set-property! m 'tweaks
199 (acons 'arpeggio-direction 1
200 (ly:music-property m 'tweaks)))
203 arpeggDown =
204 #(let* ((m (make-music 'ArpeggioEvent)))
205 (ly:music-set-property! m 'tweaks
206 (acons 'arpeggio-direction -1
207 (ly:music-property m 'tweaks)))
210 plak =
211 #(let* ((m (make-music 'ArpeggioEvent)))
212 (ly:music-set-property! m 'tweaks
213 (acons 'stencil ly:arpeggio::brew-chord-bracket
214 (ly:music-property m 'tweaks)))
217 %% Music shortcuts ------------------------------------------------%
219 sk = \set Score.skipTypesetting = ##t
221 unsk = \set Score.skipTypesetting = ##f
223 % This might not be needed
224 #(define (octave-up noteevent)
225 (let* ((pitch (ly:music-property noteevent 'pitch))
226 (octave (ly:pitch-octave pitch))
227 (note (ly:pitch-notename pitch))
228 (alteration (ly:pitch-alteration pitch))
229 (duration (ly:music-property noteevent 'duration))
230 (newnoteevent
231 (make-music 'NoteEvent
232 'duration duration
233 'pitch (ly:make-pitch (1- octave) note alteration))))
234 newnoteevent))
236 #(define (octavize-chord elements)
237 (cond ((null? elements) elements)
238 ((eq? (ly:music-property (car elements) 'name) 'NoteEvent)
239 (cons (car elements)
240 (cons (octave-up (car elements))
241 (octavize-chord (cdr elements)))))
242 (else (cons (car elements) (octavize-chord (cdr elements))))))
244 #(define (octavize music)
245 (let* ((es (ly:music-property music 'elements))
246 (e (ly:music-property music 'element))
247 (name (ly:music-property music 'name)))
248 (cond ((eq? name 'EventChord)
249 (ly:music-set-property! music 'elements (octavize-chord es)))
250 ((pair? es)
251 (for-each (lambda(x) (octavize x)) es))
252 ((ly:music? e)
253 (octavize e))))
254 music)
256 oct = #(define-music-function (parser location mus) (ly:music?)
257 (octavize mus))
260 %%%%%%%%%%%%%%%%%%%%%%%% Layout Functions %%%%%%%%%%%%%%%%%%%%%%%%%%
262 %% Music layout ---------------------------------------------------%
264 #(define modern-auto-beam-settings
265 (append default-auto-beam-settings
267 ((end * * 3 4) . ,(ly:make-moment 1 4))
268 ((end * * 3 4) . ,(ly:make-moment 1 2))
269 ((end * * 4 4) . ,(ly:make-moment 1 4))
270 ((end * * 4 4) . ,(ly:make-moment 3 4))
271 ((end * * 2 2) . ,(ly:make-moment 1 4))
272 ((end * * 2 2) . ,(ly:make-moment 1 2))
273 ((end * * 2 2) . ,(ly:make-moment 3 4))
274 ((end * * 2 8) . ,(ly:make-moment 1 4))
275 ((be * * 5 8) . ,(ly:make-moment 1 8))
276 ((end * * 5 8) . ,(ly:make-moment 5 8))
279 #(define modern-accidentals-style
280 `(Staff ,(make-accidental-rule 'same-octave 0)
281 ,(make-accidental-rule 'any-octave 0)
282 ,(make-accidental-rule 'same-octave 1)
283 ,neo-modern-accidental-rule))
284 #(define modern-cautionaries-style
285 `(Staff ,(make-accidental-rule 'same-octave 1)
286 ,(make-accidental-rule 'any-octave 1)))
288 %% Music formatting -----------------------------------------------%
290 graceNotes =
291 #(define-music-function (parser location notes) (ly:music?)
292 #{ \tiny $notes \normalsize #})
294 parlato =
295 #(define-music-function (parser location notes) (ly:music?)
296 #{ \override NoteHead #'style = #'cross
297 $notes
298 \revert NoteHead #'style #})
300 slap =
301 #(define-music-function (parser location music) (ly:music?)
302 #{\override NoteHead #'stencil = #ly:text-interface::print
303 \override NoteHead #'text = \markup \musicglyph #"scripts.sforzato"
304 \override NoteHead #'extra-offset = #'(0.1 . 0.0 )
305 $music
306 \revert NoteHead #'stencil
307 \revert NoteHead #'text
308 \revert NoteHead #'extra-offset #})
310 hideNote = {
311 \once \override NoteHead #'transparent = ##t
312 \once \override NoteHead #'no-ledgers = ##t
313 \once \override Stem #'transparent = ##t
314 \once \override Beam #'transparent = ##t
315 \once \override Accidental #'transparent = ##t
318 noTuplet = {
319 \once \override TupletBracket #'transparent = ##t
320 \once \override TupletNumber #'transparent = ##t
323 oneStemDown = {
324 \once \override Stem #'direction = #DOWN
327 oneStemUp = {
328 \once \override Stem #'direction = #UP
331 %%-----------------------------------------------------------------%