Reorganizing definition files
[opera_libre.git] / definitions / functions.ly
blob4f3b1ee039a1717753feaf5df1e499c23dcfbc08
1 %------------------------------------------------------------------%
2 % Opéra Libre -- functions.ly %
3 % %
4 % (c) Valentin Villenave, 2008 %
5 % %
6 %------------------------------------------------------------------%
9 % Various additional functions.
10 % TODO: split and rearrange.
12 %%%%%%%%%%%%%%%%%%%%%%%%% Music Shortcuts %%%%%%%%%%%%%%%%%%%%%%%%%%
14 %% Rhythm shortcuts -----------------------------------------------%
16 t =
17 #(define-music-function (parser location music) (ly:music?)
18 #{ \times 2/3 $music #})
20 tt =
21 #(define-music-function (parser location music) (ly:music?)
22 #{ \times 4/5 $music #})
24 ttt =
25 #(define-music-function (parser location music) (ly:music?)
26 #{ \times 4/6 $music #})
28 tttt =
29 #(define-music-function (parser location music) (ly:music?)
30 #{ \times 4/7 $music #})
33 %% Polyphony shortcuts --------------------------------------------%
35 pl =
36 #(define-music-function (parser location one two) (ly:music? ly:music?)
37 #{ << { \voiceTwo $one } \\ { \voiceOne $two } >> #})
39 plperc =
40 #(define-music-function (parser location one two) (ly:music? ly:music?)
41 #{ << { \stemDown $one \stemNeutral } \new DrumVoice { \stemUp $two } >> #})
43 parallel=
44 #(define-music-function (parser location droite gauche) (ly:music? ly:music?)
45 #{ <<
46 \context Staff = "md" $droite
47 \context Staff = "mg" $gauche
48 >> #})
50 md = { \change Staff = "md" }
52 mg = { \change Staff = "mg" }
54 PianoDeuxMains=
55 #(define-music-function (parser location droite gauche) (ly:music? ly:music?)
56 #{ <<
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 }
61 >> #})
63 droite = { \change Staff = "percuDroite" }
65 gauche = { \change Staff = "percuGauche" }
67 PercuDeuxMains=
68 #(define-music-function (parser location droite gauche) (ly:music? ly:music?)
69 #{ <<
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 }
74 >> #})
76 showAnyway =
77 #(define-music-function (parser location music) (ly:music?)
79 \unset Score.keepAliveInterfaces
80 $(music)
81 \set Score.keepAliveInterfaces = #'(rhythmic-grob-interface
82 lyric-interface percent-repeat-item-interface
83 percent-repeat-interface stanza-number-interface)
84 #})
86 %% Articulation shortcuts -----------------------------------------%
88 harmo =
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)
108 'name) 'RestEvent))
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))
117 st =
118 #(define-music-function (parser location music)
119 (ly:music?)
120 (define (make-script-music m)
121 (add-script m "staccato"))
122 (music-map make-script-music music))
124 acc =
125 #(define-music-function (parser location music)
126 (ly:music?)
127 (define (make-script-music m)
128 (add-script m "accent"))
129 (music-map make-script-music music))
131 det =
132 #(define-music-function (parser location music)
133 (ly:music?)
134 (define (make-script-music m)
135 (add-script m "tenuto"))
136 (music-map make-script-music music))
138 marc =
139 #(define-music-function (parser location music)
140 (ly:music?)
141 (define (make-script-music m)
142 (add-script m "marcato"))
143 (music-map make-script-music music))
145 stdet =
146 #(define-music-function (parser location music)
147 (ly:music?)
148 (define (make-script-music m)
149 (add-script m "portato"))
150 (music-map make-script-music music))
152 accdet =
153 #(define-music-function (parser location music)
154 (ly:music?)
155 (define (make-script-music m)
156 (double-script m "tenuto" "accent"))
157 (music-map make-script-music music))
159 marcdet =
160 #(define-music-function (parser location music)
161 (ly:music?)
162 (define (make-script-music m)
163 (double-script m "tenuto" "marcato"))
164 (music-map make-script-music music))
166 accst =
167 #(define-music-function (parser location music)
168 (ly:music?)
169 (define (make-script-music m)
170 (double-script m "accent" "staccato"))
171 (music-map make-script-music music))
173 marcst =
174 #(define-music-function (parser location music)
175 (ly:music?)
176 (define (make-script-music m)
177 (double-script m "marcato" "staccato"))
178 (music-map make-script-music music))
181 CaV=
182 #(let ((m (make-music 'ArticulationEvent
183 'articulation-type "flageolet")))
184 (set! (ly:music-property m 'tweaks)
185 (acons 'font-size -3
186 (ly:music-property m 'tweaks)))
189 thumbpizz =
190 #(make-music 'TextScriptEvent
191 'direction 1
192 'text (markup #:hspace .4 #:rotate 45
193 #:musicglyph "scripts.stopped"))
195 leftpizz =
196 #(make-articulation "stopped")
198 arpeggUp =
199 #(let* ((m (make-music 'ArpeggioEvent)))
200 (ly:music-set-property! m 'tweaks
201 (acons 'arpeggio-direction 1
202 (ly:music-property m 'tweaks)))
205 arpeggDown =
206 #(let* ((m (make-music 'ArpeggioEvent)))
207 (ly:music-set-property! m 'tweaks
208 (acons 'arpeggio-direction -1
209 (ly:music-property m 'tweaks)))
212 plak =
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))
232 (newnoteevent
233 (make-music 'NoteEvent
234 'duration duration
235 'pitch (ly:make-pitch (1- octave) note alteration))))
236 newnoteevent))
238 #(define (octavize-chord elements)
239 (cond ((null? elements) elements)
240 ((eq? (ly:music-property (car elements) 'name) 'NoteEvent)
241 (cons (car elements)
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)))
252 ((pair? es)
253 (for-each (lambda(x) (octavize x)) es))
254 ((ly:music? e)
255 (octavize e))))
256 music)
258 oct = #(define-music-function (parser location mus) (ly:music?)
259 (octavize mus))
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 -----------------------------------------------%
292 graceNotes =
293 #(define-music-function (parser location notes) (ly:music?)
294 #{ \tiny $notes \normalsize #})
296 parlato =
297 #(define-music-function (parser location notes) (ly:music?)
298 #{ \override NoteHead #'style = #'cross
299 $notes
300 \revert NoteHead #'style #})
302 slap =
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 )
307 $music
308 \revert NoteHead #'stencil
309 \revert NoteHead #'text
310 \revert NoteHead #'extra-offset #})
312 hideNote = {
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
320 noTuplet = {
321 \once \override TupletBracket #'transparent = ##t
322 \once \override TupletNumber #'transparent = ##t
325 oneStemDown = {
326 \once \override Stem #'direction = #DOWN
329 oneStemUp = {
330 \once \override Stem #'direction = #UP