First attempt to fix "the" piano staves problem
[opera_libre.git] / definitions / functions.ly
blob7fd6cf99ad508f950dd3390383e3735c15ec6a02
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 %%% Piano stuff (Issue #442 workaround)
50 #(define (event-filter event)
51 (let ((n (ly:music-property event 'name)))
52 (not
53 (or ;; add here event name you do NOT want
54 (eq? n 'ContextSpeccedMusic)
55 (eq? n 'ContextChange)
56 (eq? n 'SimultaneousMusic))
57 )))
59 makeGhost =
60 #(define-music-function (parser location music) (ly:music?)
61 (context-spec-music (music-filter event-filter music) 'PseudoVoice))
63 showAnyway =
64 #(define-music-function (parser location music) (ly:music?)
66 \unset Score.keepAliveInterfaces
67 $music
68 \set Score.keepAliveInterfaces = #'(rhythmic-grob-interface
69 lyric-interface percent-repeat-item-interface
70 percent-repeat-interface stanza-number-interface)
71 #})
73 md = { \change Staff = "md" }
75 mg = { \change Staff = "mg" }
77 PianoDeuxMains=
78 #(define-music-function (parser location droite gauche) (ly:music? ly:music?)
80 \new PianoStaff <<
81 \new Staff = "md" \with { \remove Accidental_engraver }
83 \new Voice \with { \consists Accidental_engraver } { \clef treble $droite }
84 %\new Voice { \makeGhost $gauche }
86 \new Staff = "mg" \with { \remove Accidental_engraver }
88 \new Voice \with { \consists Accidental_engraver } { \clef bass $gauche }
89 %\new Voice { \makeGhost $droite }
92 #})
94 droite = { \change Staff = "percuDroite" }
96 gauche = { \change Staff = "percuGauche" }
98 PercuDeuxMains=
99 #(define-music-function (parser location droite gauche) (ly:music? ly:music?)
100 #{ << %%%FIXME: I /definitely/ should get rid of this option.
101 \new Staff = "percuDroite"
102 { \clef treble $droite }
103 \new Staff = "percuGauche" \with { \override VerticalAxisGroup #'remove-empty = ##f }
104 { \clef bass $gauche }
105 >> #})
108 %% Music formatting -----------------------------------------------%
110 graceNotes =
111 #(define-music-function (parser location notes) (ly:music?)
112 #{ \tiny $notes \normalsize #})
114 parlato =
115 #(define-music-function (parser location notes) (ly:music?)
116 #{ \override NoteHead #'style = #'cross
117 $notes
118 \revert NoteHead #'style #})
120 slap =
121 #(define-music-function (parser location music) (ly:music?)
122 #{\override NoteHead #'stencil = #ly:text-interface::print
123 \override NoteHead #'text = \markup \musicglyph #"scripts.sforzato"
124 \override NoteHead #'extra-offset = #'(0.1 . 0.0 )
125 $music
126 \revert NoteHead #'stencil
127 \revert NoteHead #'text
128 \revert NoteHead #'extra-offset #})
130 hideNote = {
131 \once \override NoteHead #'transparent = ##t
132 \once \override NoteHead #'no-ledgers = ##t
133 \once \override Stem #'transparent = ##t
134 \once \override Beam #'transparent = ##t
135 \once \override Accidental #'transparent = ##t
138 noTuplet = {
139 \once \override TupletBracket #'transparent = ##t
140 \once \override TupletNumber #'transparent = ##t
143 oneStemDown = {
144 \once \override Stem #'direction = #DOWN
147 oneStemUp = {
148 \once \override Stem #'direction = #UP
151 %% Music shortcuts ------------------------------------------------%
153 sk = \set Score.skipTypesetting = ##t
155 unsk = \set Score.skipTypesetting = ##f
157 % This might not be needed
158 #(define (octave-up noteevent)
159 (let* ((pitch (ly:music-property noteevent 'pitch))
160 (octave (ly:pitch-octave pitch))
161 (note (ly:pitch-notename pitch))
162 (alteration (ly:pitch-alteration pitch))
163 (duration (ly:music-property noteevent 'duration))
164 (newnoteevent
165 (make-music 'NoteEvent
166 'duration duration
167 'pitch (ly:make-pitch (1- octave) note alteration))))
168 newnoteevent))
170 #(define (octavize-chord elements)
171 (cond ((null? elements) elements)
172 ((eq? (ly:music-property (car elements) 'name) 'NoteEvent)
173 (cons (car elements)
174 (cons (octave-up (car elements))
175 (octavize-chord (cdr elements)))))
176 (else (cons (car elements) (octavize-chord (cdr elements))))))
178 #(define (octavize music)
179 (let* ((es (ly:music-property music 'elements))
180 (e (ly:music-property music 'element))
181 (name (ly:music-property music 'name)))
182 (cond ((eq? name 'EventChord)
183 (ly:music-set-property! music 'elements (octavize-chord es)))
184 ((pair? es)
185 (for-each (lambda(x) (octavize x)) es))
186 ((ly:music? e)
187 (octavize e))))
188 music)
190 oct = #(define-music-function (parser location mus) (ly:music?)
191 (octavize mus))
194 %%%%%%%%%%%%%%%%%%%%%%%%% Music Decoration %%%%%%%%%%%%%%%%%%%%%%%%%
196 %% Articulation marks ---------------------------------------------%
198 #(define (make-script x)
199 (make-music 'ArticulationEvent
200 'articulation-type x))
202 #(define (add-script m x)
203 (let ( (eventname (ly:music-property m 'name)))
204 (if (equal? eventname 'EventChord)
205 (let ( (elements (ly:music-property m 'elements)) )
206 (if (not (equal? (ly:music-property (car elements)
207 'name) 'RestEvent))
208 (set! (ly:music-property m 'elements)
209 (append elements (list
210 (make-script x)))))))
213 #(define (double-script m t tt)
214 (add-script (add-script m t) tt))
216 st =
217 #(define-music-function (parser location music)
218 (ly:music?)
219 (define (make-script-music m)
220 (add-script m "staccato"))
221 (music-map make-script-music music))
223 acc =
224 #(define-music-function (parser location music)
225 (ly:music?)
226 (define (make-script-music m)
227 (add-script m "accent"))
228 (music-map make-script-music music))
230 det =
231 #(define-music-function (parser location music)
232 (ly:music?)
233 (define (make-script-music m)
234 (add-script m "tenuto"))
235 (music-map make-script-music music))
237 marc =
238 #(define-music-function (parser location music)
239 (ly:music?)
240 (define (make-script-music m)
241 (add-script m "marcato"))
242 (music-map make-script-music music))
244 stdet =
245 #(define-music-function (parser location music)
246 (ly:music?)
247 (define (make-script-music m)
248 (add-script m "portato"))
249 (music-map make-script-music music))
251 accdet =
252 #(define-music-function (parser location music)
253 (ly:music?)
254 (define (make-script-music m)
255 (double-script m "tenuto" "accent"))
256 (music-map make-script-music music))
258 marcdet =
259 #(define-music-function (parser location music)
260 (ly:music?)
261 (define (make-script-music m)
262 (double-script m "tenuto" "marcato"))
263 (music-map make-script-music music))
265 accst =
266 #(define-music-function (parser location music)
267 (ly:music?)
268 (define (make-script-music m)
269 (double-script m "accent" "staccato"))
270 (music-map make-script-music music))
272 marcst =
273 #(define-music-function (parser location music)
274 (ly:music?)
275 (define (make-script-music m)
276 (double-script m "marcato" "staccato"))
277 (music-map make-script-music music))
280 CaV=
281 #(let ((m (make-music 'ArticulationEvent
282 'articulation-type "flageolet")))
283 (set! (ly:music-property m 'tweaks)
284 (acons 'font-size -3
285 (ly:music-property m 'tweaks)))
287 harmo =
288 #(define-music-function (parser location chord result) (ly:music? ly:music?)
289 #{ << \oneStemDown $chord \\ { \stemUp %FIXME: ties could look better.
290 \override NoteHead #'stencil = #ly:text-interface::print
291 \override NoteHead #'text = \markup { \null \musicglyph #"noteheads.s2"}
292 \once \override NoteHead #'text = \markup {\null \override #'(direction . 1)
293 \dir-column {\musicglyph #"noteheads.s2" \teeny \musicglyph #"eight"}}
294 \override Stem #'stencil = ##f $result
295 \revert Stem #'stencil \revert NoteHead #'stencil \stemNeutral } >> #})
297 thumbpizz =
298 #(make-music 'TextScriptEvent
299 'direction 1
300 'text (markup #:hspace .4 #:rotate 45
301 #:musicglyph "scripts.stopped"))
303 leftpizz =
304 #(make-articulation "stopped")
306 arpeggUp =
307 #(let* ((m (make-music 'ArpeggioEvent)))
308 (ly:music-set-property! m 'tweaks
309 (acons 'arpeggio-direction 1
310 (ly:music-property m 'tweaks)))
313 arpeggDown =
314 #(let* ((m (make-music 'ArpeggioEvent)))
315 (ly:music-set-property! m 'tweaks
316 (acons 'arpeggio-direction -1
317 (ly:music-property m 'tweaks)))
320 plak =
321 #(let* ((m (make-music 'ArpeggioEvent)))
322 (ly:music-set-property! m 'tweaks
323 (acons 'stencil ly:arpeggio::brew-chord-bracket
324 (ly:music-property m 'tweaks)))
327 %%%%%%%%%%%%%%%%%%%%%%%% Layout Functions %%%%%%%%%%%%%%%%%%%%%%%%%%
329 %% Music layout ---------------------------------------------------%
331 #(define modern-auto-beam-settings
332 (append default-auto-beam-settings
334 ((end * * 3 4) . ,(ly:make-moment 1 4))
335 ((end * * 3 4) . ,(ly:make-moment 1 2))
336 ((end * * 4 4) . ,(ly:make-moment 1 4))
337 ((end * * 4 4) . ,(ly:make-moment 3 4))
338 ((end * * 2 2) . ,(ly:make-moment 1 4))
339 ((end * * 2 2) . ,(ly:make-moment 1 2))
340 ((end * * 2 2) . ,(ly:make-moment 3 4))
341 ((end * * 2 8) . ,(ly:make-moment 1 4))
342 ((be * * 5 8) . ,(ly:make-moment 1 8))
343 ((end * * 5 8) . ,(ly:make-moment 5 8))
346 #(define modern-accidentals-style
347 `(Staff ,(make-accidental-rule 'same-octave 0)
348 ,(make-accidental-rule 'any-octave 0)
349 ,(make-accidental-rule 'same-octave 1)
350 ,neo-modern-accidental-rule))
351 #(define modern-cautionaries-style
352 `(Staff ,(make-accidental-rule 'same-octave 1)
353 ,(make-accidental-rule 'any-octave 1)))
355 %%%%%%%%%%%%%%%%%%%%%%%%%%%% Editorial %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
357 %% Individual parts -----------------------------------------------%
359 makePart =
360 #(define-music-function (parser location part ref)
361 (ly:music? ly:music?)
362 #{\context Staff << $part \new GhostVoice $ref >> #})
364 makeSection =
365 #(define-music-function (parser location part-one part-two ref)
366 (ly:music? ly:music? ly:music?)
367 #{\new StaffGroup <<
368 \new Staff << $part-one \new GhostVoice $ref >>
369 \new Staff $part-two
370 >> #})
372 makeExtraSection = % for violins
373 #(define-music-function (parser location part-one part-two part-three ref)
374 (ly:music? ly:music? ly:music? ly:music?)
375 #{\new StaffGroup <<
376 \new Staff << $part-one \new GhostVoice $ref >>
377 \new Staff $part-two
378 \new Staff $part-three
379 >> #})
381 makePianoPart =
382 #(define-music-function (parser location part-one ref)
383 (ly:music? ly:music?)
384 #{<< $part-one \new GhostVoice $ref >> #})
386 %%-----------------------------------------------------------------%