Changed score structure; allows a lot more staves / voices and more flexibility
[orchestrallily.git] / orchestrallily.ly
blobf847d7fa76729dd281f17963675e3b0b2af6ecda
1 \version "2.11.41"
3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 % OrchestralLily
5 % ==============
6 % Desciption: Lilypond package to make writing large orchestral scores easier.
7 % Documentation: http://wiki.kainhofer.com/lilypond/orchestrallily
8 % Version: 0.02, 2008-03-06
9 % Author: Reinhold Kainhofer, reinhold@kainhofer.com
10 % Copyright: (C) 2008 by Reinhold Kainhofer
11 % License: GPL v3.0, http://www.gnu.org/licenses/gpl.html
13 % Version History:
14 % 0.01 (2008-03-02): Initial Version
15 % 0.02 (2008-03-06): Added basic MIDI support (*MidiInstrument and \setCreateMIDI)
16 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18 #(use-modules (ice-9 match))
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23 %%%%% SCORE STRUCTURE AND AUTOMATIC GENERATION
24 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 % Helper functions
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34 % Helper function to filter all non-null entries
35 #(define (not-null? x) (not (null? x)))
37 % Helper function to extract a given variable, built from [Piece][Instrument]Identifier
38 #(define (namedPieceInstrObject piece instr name)
39 (let* (
40 (fullname (string->symbol (string-append piece instr name)))
41 (instrname (string->symbol (string-append instr name)))
42 (piecename (string->symbol (string-append piece name)))
44 (cond
45 ((defined? fullname) (primitive-eval fullname))
46 ((defined? instrname) (primitive-eval instrname))
47 ((defined? piecename) (primitive-eval piecename))
48 (else '())
53 %% Print text as a justified paragraph, taken from the lilypond Notation Reference
54 #(define-markup-list-command (paragraph layout props args) (markup-list?)
55 (let ((indent (chain-assoc-get 'par-indent props 2)))
56 (interpret-markup-list layout props
57 (make-justified-lines-markup-list (cons (make-hspace-markup indent)
58 args)))))
60 conditionalBreak = #(define-music-function (parser location) ()
61 #{ \tag #'instrumental-score \pageBreak #}
64 #(define (oly:piece-title-markup title) (markup #:column (#:line (#:fontsize #'3 #:bold title))) )
66 #(define-markup-command (piece-title layout props title) (markup?)
67 ; (toc-item title)
68 (interpret-markup layout props (oly:piece-title-markup title))
71 #(define (oly:generate_object_name piece instr obj )
72 (if (and (string? piece) (string? instr) (string? obj))
73 (string-append piece instr obj)
77 #(define (oly:generate_staff_name piece instr) (oly:generate_object_name piece instr "St"))
79 #(define (set-context-property context property value)
80 (set! (ly:music-property context property) value)
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 % Score structure and voice types
86 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 #(define oly:orchestral_score_structure '())
90 #(define (oly:set_score_structure struct)
91 (if (list? struct)
92 (set! oly:orchestral_score_structure struct)
93 (ly:warning (_ "oly:set_score_structure needs an association list as argument!"))
97 orchestralScoreStructure = #(define-music-function (parser location structure) (list?)
98 (oly:set_score_structure structure)
99 (make-music 'Music 'void #t)
102 #(define oly:voice_types '())
104 #(define (oly:set_voice_types types)
105 (if (list? types)
106 (set! oly:voice_types types)
107 (ly:warning (_ "oly:set_voice_types needs an association list as argument!"))
111 orchestralVoiceTypes = #(define-music-function (parser location types) (list?)
112 (oly:set_voice_types types)
113 (make-music 'Music 'void #t)
117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118 % Automatic staff and group generation
119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121 % Retrieve all music definitions for the given
122 #(define (oly:get_music_object piece instrument)
123 (namedPieceInstrObject piece instrument "Music")
125 #(define (oly:get_music_objects piece instruments)
126 (filter not-null? (map (lambda (i) (oly:get_music_object piece i)) instruments))
129 % Given a property name and the extensions, either generate the pair to set
130 % the property or an empty list, if no pre-defined variable could be found
131 #(define (oly:generate_property_pair prop piece instr type)
132 (let* ((val (namedPieceInstrObject piece instr type)))
133 (if (not-null? val) (list 'assign prop val) '() )
137 #(define (oly:staff_type type)
138 (cond
139 ((string? type) (string->symbol type))
140 ((symbol? type) type)
141 (else 'Staff)
146 #(define (oly:voice_handler_internal parser piece name type music)
147 (let* (
148 (tempo (namedPieceInstrObject piece name "Tempo"))
149 (lyrics (namedPieceInstrObject piece name "Lyrics"))
150 (musiccontent '())
153 (if (ly:music? lyrics)
154 (set! musiccontent (append musiccontent (list dynamicUp)))
155 (if (not-null? lyrics) (ly:warning (_ "Wrong type (no lyrics) for lyrics for instrument ~S in piece ~S") name piece))
157 ; Append the settings, key and clef (if defined)
158 (map
159 (lambda (type)
160 (let* ((object (namedPieceInstrObject piece name type)))
161 (if (ly:music? object)
162 (set! musiccontent (append musiccontent (list object)))
163 (if (not-null? object) (ly:warning (_ "Wrong type (no ly:music) for ~S for instrument ~S in piece ~S") type name piece))
167 '("Settings" "Key" "Clef" "TimeSignature")
170 (if (ly:music? music)
171 (begin
172 (set! musiccontent (append musiccontent (list music)))
173 ;(ly:message "Generating staff for ~a" name)
175 (let* (
176 (voicename (oly:generate_object_name piece name "Voice" ))
177 (voicetype (oly:staff_type type))
178 (voice (context-spec-music (make-simultaneous-music musiccontent) voicetype voicename))
179 (staffcont (list voice))
181 ; If we have lyrics, create a lyrics context containing LyricCombineMusic
182 ; and add that as second element to the staff's elements list...
183 (if (ly:music? lyrics)
184 (let* (
185 (lyricsname (oly:generate_object_name piece name "Lyrics" ))
186 (lyricscont (make-music 'LyricCombineMusic 'element lyrics 'associated-context voicename))
188 (set! staffcont (append staffcont
189 (list (context-spec-music lyricscont 'Lyrics lyricsname))))
192 staffcont
195 ; For empty music, return empty
201 #(define (oly:voice_handler parser piece name type)
202 (let* ((music (oly:get_music_object piece name))
204 (oly:voice_handler_internal parser piece name type music)
209 #(define (oly:staff_handler_internal parser piece name type voices)
210 (if (not-null? voices)
211 (let* (
212 (staffname (oly:generate_staff_name piece name))
213 (stafftype (oly:staff_type type))
214 (staff (make-simultaneous-music voices))
215 (propops (oly:staff_handler_properties piece name))
217 (case stafftype
218 ((SimultaneousMusic ParallelMusic) #f)
219 (else (set! staff (context-spec-music staff stafftype staffname)))
221 (if (not-null? propops)
222 (set! (ly:music-property staff 'property-operations) propops)
224 staff
226 ; For empty music, return empty
231 #(define (oly:staff_handler parser piece name type children)
232 (let* ((c (if (not-null? children) children (list name)))
233 (voices (apply append (map (lambda (v) (oly:create_voice parser piece v)) c)) )
235 (if (not-null? voices)
236 (oly:staff_handler_internal parser piece name type voices)
242 #(define (oly:parallel_voices_staff_handler parser piece name type children)
243 (let* (
244 (voices (map (lambda (i) (oly:create_voice parser piece i)) children))
245 ; get the lsit of non-empty voices and flatten it!
246 (nonemptyvoices (apply append (filter not-null? voices)))
248 (if (not-null? nonemptyvoices)
249 (oly:staff_handler_internal parser piece name "Staff" nonemptyvoices)
255 #(define (oly:part_combined_staff_handler parser piece name type children)
256 (let* ((music (oly:get_music_objects piece children)))
257 (cond
258 ((and (pair? music) (ly:music? (car music)) (not-null? (cdr music)) (ly:music? (cadr music)))
259 ;(ly:message "Part-combine with two music expressions")
260 (oly:staff_handler_internal parser piece name "Staff" (list (make-part-combine-music parser music))))
261 ((null? music)
262 (ly:warning "Part-combine without any music expressions")
263 '())
264 ; exactly one is a music expression, simply use that by joining
265 ((list? music)
266 (ly:message "Part-combine with only one music expressions")
267 (oly:staff_handler_internal parser piece name "Staff" (list (apply append music))))
268 (else
269 ;(ly:message "make_part_combined_staff: ~S ~S ~a" piece instr instruments)
270 '() )
275 % Generate the properties for the staff for piece and instr. Typically, these
276 % are the instrument name and the short instrument name (if defined).
277 % return a (possibly empty) list of all assignments.
278 #(define (oly:staff_handler_properties piece instr)
279 (let* (
280 (mapping '(
281 (instrumentName . "InstrumentName")
282 (shortInstrumentName . "ShortInstrumentName")
283 (midiInstrument . "MidiInstrument")
285 (assignments (map
286 (lambda (pr)
287 (oly:generate_property_pair (car pr) piece instr (cdr pr))
289 mapping))
290 (props (filter not-null? assignments))
292 props
296 #(define (oly:staff_group_handler parser piece name type children)
297 (let* (
298 (staves (map (lambda (i) (oly:create_staff_or_group parser piece i)) children))
299 (nonemptystaves (filter not-null? staves))
301 (if (not-null? nonemptystaves)
302 (let* (
303 (musicexpr (if (= 1 (length nonemptystaves)) (car nonemptystaves) (make-simultaneous-music staves)))
304 (groupname (oly:generate_staff_name piece name))
305 (grouptype (oly:staff_type type))
306 (group musicexpr)
307 (propops (oly:staff_handler_properties piece name))
309 (case grouptype
310 ((SimultaneousMusic ParallelMusic) #f)
311 (else (set! group (context-spec-music group grouptype groupname)))
313 (set! (ly:music-property group 'property-operations) propops)
314 group
316 ; Return empty list if no staves are generated
322 #(define oly:staff_handlers
323 (list
324 ; staff group types
325 '("GrandStaff" . oly:staff_group_handler )
326 '("PianoStaff" . oly:staff_group_handler )
327 '("ChoirStaff" . oly:staff_group_handler )
328 '("StaffGroup" . oly:staff_group_handler )
329 '("ParallelMusic" . oly:staff_group_handler )
330 '("SimultaneousMusic" . oly:staff_group_handler )
331 ; staff types
332 '("Staff" . oly:staff_handler )
333 '("DrumStaff" . oly:staff_handler )
334 '("PartCombinedStaff" . oly:part_combined_staff_handler )
335 '("ParallelVoicesStaff" . oly:parallel_voices_staff_handler )
339 #(define oly:voice_handlers
340 (list
341 ; voice types
342 '("Voice" . oly:voice_handler )
343 '("FiguredBass" . oly:voice_handler )
344 '("Lyrics" . oly:lyrics_handler )
345 '("DrumVoice" . oly:voice_handler )
346 '("Dynamics" . oly:dynamics_handler )
350 #(define (oly:create_voice parser piece name)
351 (let* ( (voice (namedPieceInstrObject piece name "Voice"))
352 (type (assoc-ref oly:voice_types name)) )
353 (if (not-null? voice)
354 ; Explicit voice variable, use that
355 voice
357 (if (not type)
358 ; No entry in structure found => simple voice
359 (oly:voice_handler parser piece name "Voice")
360 ; Entry found in structure => use the handler for the given type
361 (let* (
362 (voicetype (car type))
363 (handler (assoc-ref oly:voice_handlers voicetype))
365 (if handler
366 ((primitive-eval handler) parser piece name voicetype)
367 (begin
368 (ly:warning "No handler found for voice type ~a, using default voice handler" voicetype)
369 (oly:voice_handler parser piece name voicetype)
378 #(define (oly:create_staff_or_group parser piece name)
379 (let* ( (staff (namedPieceInstrObject piece name "Staff"))
380 (type_from_structure (assoc-ref oly:orchestral_score_structure name)) )
381 ;(if (not-null? staff)
382 ; (ly:message "Found staff variable for instrument ~a in piece ~a" instr piece)
383 ; (ly:message "Staff variable for instrument ~a in piece ~a NOT FOUND" instr piece)
385 (if (not-null? staff)
386 ; Explicit staff variable, use that
387 staff
389 (if (not (list? type_from_structure))
390 ; No entry in structure found => simple staff
391 (oly:staff_handler parser piece name "Staff" '())
393 ; Entry found in structure => use the handler for the given type
394 (let* ((type (car type_from_structure))
395 (handler (assoc-ref oly:staff_handlers type))
396 (children (cadr type_from_structure))
398 (if handler
399 ((primitive-eval handler) parser piece name type children)
400 (begin
401 (ly:warning "No handler found for staff type ~a, using default staff handler" type)
402 (oly:staff_handler parser piece name type children)
411 #(define (oly:register_staff_type_handler type func)
412 ; (ly:message "Registering staff handler ~a for type ~a" func type)
413 (set! oly:staff_handlers (assoc-set! oly:staff_handlers type func))
416 #(define (oly:register_voice_type_handler type func)
417 ; (ly:message "Registering voice type handler ~a for type ~a" func type)
418 (set! oly:voice_handlers (assoc-set! oly:voice_handlers type func))
421 % handlers for deprecated API
422 #(oly:register_staff_type_handler 'StaffGroup 'oly:staff_group_handler)
423 #(oly:register_staff_type_handler 'ParallelMusic 'oly:staff_group_handler)
426 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
427 % Automatic score generation
428 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
430 % \setUserBook ##t/##f sets a flat to determine whether the calls to createScore
431 % are from within a book block or not
432 #(define oly:score_handler collect-scores-for-book)
433 setUseBook = #(define-music-function (parser location usebook) (boolean?)
434 (if usebook
435 (set! oly:score_handler book-score-handler)
436 (set! oly:score_handler toplevel-score-handler)
438 (make-music 'Music 'void #t)
442 % Two functions to handle midi-blocks: Either don't set one, or set an empty
443 % one so that MIDI is generated
444 #(define (oly:set_no_midi_block score) '())
445 #(define (oly:set_midi_block score)
446 (let* ((midiblock (if (defined? '$defaultmidi)
447 (ly:output-def-clone $defaultmidi)
448 (ly:make-output-def))))
449 (ly:output-def-set-variable! midiblock 'is-midi #t)
450 (ly:score-add-output-def! score midiblock)
454 % \setCreateMidi ##t/##f sets a flag to determine wheter MIDI output should
455 % be generated
456 #(define oly:apply_score_midi oly:set_no_midi_block)
457 setCreateMIDI = #(define-music-function (parser location createmidi) (boolean?)
458 (if createmidi
459 (set! oly:apply_score_midi oly:set_midi_block)
460 (set! oly:apply_score_midi oly:set_no_midi_block)
462 (make-music 'Music 'void #t)
466 % Two functions to handle layout-blocks: Either don't set one, or set an empty
467 % one so that a PDF is generated
468 #(define (oly:set_no_layout_block score) '())
469 #(define (oly:set_layout_block score)
470 (let* ((layoutblock (if (defined? '$defaultlayout)
471 (ly:output-def-clone $defaultlayout)
472 (ly:make-output-def))))
473 (ly:output-def-set-variable! layoutblock 'is-layout #t)
474 (ly:score-add-output-def! score layoutblock)
478 % \setCreatePDF ##t/##f sets a flag to determine wheter PDF output should
479 % be generated
480 #(define oly:apply_score_layout oly:set_no_layout_block)
481 setCreatePDF = #(define-music-function (parser location createlayout) (boolean?)
482 (if createlayout
483 (set! oly:apply_score_layout oly:set_layout_block)
484 (set! oly:apply_score_layout oly:set_no_layout_block)
486 (make-music 'Music 'void #t)
490 % Set the piece title in a new header block.
491 #(define (oly:set_piece_header score piecename)
492 (if (not-null? piecename)
493 (let* ((header (make-module)))
494 (module-define! header 'piece piecename)
495 (ly:score-set-header! score header)
502 % post-filter functions. By default, no filtering is done. However,
503 % for the *NoCues* function, the cue notes should be killed
504 identity = #(define-music-function (parser location music) (ly:music?) music)
505 cuefilter = #(define-music-function (parser location music) (ly:music?)
506 ((ly:music-function-extract removeWithTag) parser location 'cued ((ly:music-function-extract killCues) parser location music))
509 % The helper function to build a score.
510 #(define (oly:createScoreHelper parser location piece children func)
511 (let* (
512 (staves (oly:staff_group_handler parser piece "" "SimultaneousMusic" children))
513 (music (if (not-null? staves)
514 ((ly:music-function-extract func) parser location staves)
517 (score '())
518 (piecename (namedPieceInstrObject piece (car children) "PieceName"))
519 (piecenametacet (namedPieceInstrObject piece (car children) "PieceNameTacet"))
520 (header '())
522 (if (null? music)
523 ; No staves, print tacet
524 (begin
525 (if (not-null? piecenametacet) (set! piecename piecenametacet))
526 (if (not-null? piecename)
527 (collect-scores-for-book parser (list (oly:piece-title-markup piecename)))
528 (ly:warning (_ "No music and no score title found for part ~a and instrument ~a") piece children)
531 ; we have staves, apply the piecename to the score and add layout/midi blocks if needed
532 (begin
533 (set! score (scorify-music music parser))
534 (oly:set_piece_header score piecename)
535 (oly:apply_score_midi score)
536 (oly:apply_score_layout score)
537 ; Schedule the score for typesetting
538 (collect-scores-for-book parser score)
542 ; This is a void function, the score has been schedulled for typesetting already
543 (make-music 'Music 'void #t)
546 createScore = #(define-music-function (parser location piece children) (string? list?)
547 (oly:createScoreHelper parser location piece children identity)
549 createNoCuesScore = #(define-music-function (parser location piece children) (string? list?)
550 (oly:createScoreHelper parser location piece children cuefilter)
557 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
558 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
559 %%%%% CUE NOTES
560 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
561 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
563 % set the cue instrument name
564 setCue = #(define-music-function (parser location instr) (string?)
565 #{ \set Voice.instrumentCueName = $instr #} )
567 % generate a cue music section with instrument names
568 % Parameters: \namedCueDuring NameOfQuote CueDirection CueInstrument OriginalInstrument music
569 % -) NameOfQuote CueDirection music are the parameters for \cueDuring
570 % -) CueInstrument and OriginalInstrument are the displayed instrument names
571 % typical call:
572 % \namedCueDuring #"vIQuote" #UP #"V.I" #"Sop." { R1*3 }
573 % This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
574 % the beginning of the cue notes and "Sop." at the end
575 namedCueDuring = #(define-music-function (parser location cuevoice direction instrcue instr cuemusic) (string? number? string? string? ly:music?)
577 \cueDuring #$cuevoice #$direction { \tag #'cued \setCue #$instrcue $cuemusic \tag #'cued \setCue #$instr }
578 % \tag #'uncued $cuemusic
581 namedTransposedCueDuring = #(define-music-function (parser location cuevoice direction instrcue instr trans cuemusic) (string? number? string? string? ly:music? ly:music?)
583 \transposedCueDuring #$cuevoice #$direction $trans { \tag #'cued \setCue #$instrcue $cuemusic \tag #'cued \setCue #$instr }
584 % \tag #'uncued $cuemusic
588 % set the cue instrument name and clef
589 setClefCue = #(define-music-function (parser location instr clef)
590 (string? ly:music?)
592 \once \override Staff.Clef #'font-size = #-3 $clef
593 \set Voice.instrumentCueName = $instr
594 #} )
596 % generate a cue music section with instrument names and clef changes
597 % Parameters: \cleffedCueDuring NameOfQuote CueDirection CueInstrument CueClef OriginalInstrument OriginalClef music
598 % -) NameOfQuote CueDirection music are the parameters for \cueDuring
599 % -) CueInstrument and OriginalInstrument are the displayed instrument names
600 % -) CueClef and OriginalClef are the clefs for the the cue notes and the clef of the containing voice
601 % typical call:
602 % \cleffedCueDuring #"vIQuote" #UP #"V.I" #"treble" #"Basso" #"bass" { R1*3 }
603 % This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
604 % the beginning of the cue notes and "Basso" at the end. The clef is changed to treble at the
605 % beginning of the cue notes and reset to bass at the end
606 cleffedCueDuring = #(define-music-function (parser location cuevoice direction instrcue clefcue instr clefinstr cuemusic)
607 (string? number? string? ly:music? string? ly:music? ly:music?)
609 \cueDuring #$cuevoice #$direction { \tag #'cued \setClefCue #$instrcue $clefcue $cuemusic \tag #'cued \setClefCue #$instr $clefinstr }
610 % \tag #'uncued $cuemusic
617 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
618 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
619 %%%%% DYNAMICS
620 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
621 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
623 tempoMark = #(define-music-function (parser location padding marktext) (number? string?)
625 \once \override Score . RehearsalMark #'padding = $padding
626 \mark \markup { \bold \smaller $marktext }
629 shiftDynamics = #(define-music-function (parser location xshift yshift) (number? number?)
631 \once \override DynamicTextSpanner #'padding = $yshift
632 \once\override DynamicText #'extra-offset = #(cons $xshift $yshift)
635 ffz = #(make-dynamic-script "ffz")
636 pf = #(make-dynamic-script "pf")
637 sempp = #(make-dynamic-script (markup #:line( #:with-dimensions '(0 . 0)
638 '(0 . 0) #:right-align #:normal-text #:italic "sempre" #:dynamic "pp")))
639 parenf = #(make-dynamic-script (markup #:line(#:normal-text #:italic #:fontsize 2 "(" #:dynamic "f" #:normal-text #:italic #:fontsize 2 ")" )))
640 parenp = #(make-dynamic-script (markup #:line(#:normal-text #:italic #:fontsize 2 "(" #:dynamic "p" #:normal-text #:italic #:fontsize 2 ")" )))
644 dim = #(make-span-event 'DecrescendoEvent START)
645 enddim = #(make-span-event 'DecrescendoEvent STOP)
646 decresc = #(make-span-event 'DecrescendoEvent START)
647 enddecresc = #(make-span-event 'DecrescendoEvent STOP)
648 cresc = #(make-span-event 'CrescendoEvent START)
649 endcresc = #(make-span-event 'CrescendoEvent STOP)
651 setCresc = {
652 \set crescendoText = \markup { \italic "cresc." }
653 \set crescendoSpanner = #'dashed-line
655 setDecresc = {
656 \set decrescendoText = \markup { \italic "decresc." }
657 \set decrescendoSpanner = #'dashed-line
659 setDim = {
660 \set decrescendoText = \markup { \italic "dim." }
661 \set decrescendoSpanner = #'dashed-line
664 newOrOldClef = #(define-music-function (parser location new old ) (string? string?)
665 (if (ly:get-option 'old-clefs) #{ \clef $old #} #{ \clef $new #})
670 %%% Thanks to "Gilles THIBAULT" <gilles.thibault@free.fr>, there is a way
671 % to remove also the fermata from R1-\fermataMarkup: By filtering the music
672 % and removing the corresponding events.
673 % Documented as an LSR snippet: http://lsr.dsi.unimi.it/LSR/Item?id=372
674 #(define (filterOneEventsMarkup event)
675 ( let ( (eventname (ly:music-property event 'name)) )
676 (not
677 (or ;; add here event name you do NOT want
678 (eq? eventname 'MultiMeasureTextEvent)
679 (eq? eventname 'AbsoluteDynamicEvent)
680 (eq? eventname 'TextScriptEvent)
681 (eq? eventname 'ArticulationEvent)
682 (eq? eventname 'CrescendoEvent)
683 (eq? eventname 'DecrescendoEvent)
688 filterArticulations = #(define-music-function (parser location music) (ly:music?)
689    (music-filter filterOneEventsMarkup music)
702 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
703 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
704 %%%%% REST COMBINATION
705 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
706 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
710 %% REST COMBINING, TAKEN FROM http://lsr.dsi.unimi.it/LSR/Item?id=336
712 %% Usage:
713 %% \new Staff \with {
714 %% \override RestCollision #'positioning-done = #merge-rests-on-positioning
715 %% } << \somevoice \\ \othervoice >>
716 %% or (globally):
717 %% \layout {
718 %% \context {
719 %% \Staff
720 %% \override RestCollision #'positioning-done = #merge-rests-on-positioning
721 %% }
722 %% }
724 %% Limitations:
725 %% - only handles two voices
726 %% - does not handle multi-measure/whole-measure rests
728 #(define (rest-score r)
729 (let ((score 0)
730 (yoff (ly:grob-property-data r 'Y-offset))
731 (sp (ly:grob-property-data r 'staff-position)))
732 (if (number? yoff)
733 (set! score (+ score 2))
734 (if (eq? yoff 'calculation-in-progress)
735 (set! score (- score 3))))
736 (and (number? sp)
737 (<= 0 2 sp)
738 (set! score (+ score 2))
739 (set! score (- score (abs (- 1 sp)))))
740 score))
742 #(define (merge-rests-on-positioning grob)
743 (let* ((can-merge #f)
744 (elts (ly:grob-object grob 'elements))
745 (num-elts (and (ly:grob-array? elts)
746 (ly:grob-array-length elts)))
747 (two-voice? (= num-elts 2)))
748 (if two-voice?
749 (let* ((v1-grob (ly:grob-array-ref elts 0))
750 (v2-grob (ly:grob-array-ref elts 1))
751 (v1-rest (ly:grob-object v1-grob 'rest))
752 (v2-rest (ly:grob-object v2-grob 'rest)))
753 (and
754 (ly:grob? v1-rest)
755 (ly:grob? v2-rest)
756 (let* ((v1-duration-log (ly:grob-property v1-rest 'duration-log))
757 (v2-duration-log (ly:grob-property v2-rest 'duration-log))
758 (v1-dot (ly:grob-object v1-rest 'dot))
759 (v2-dot (ly:grob-object v2-rest 'dot))
760 (v1-dot-count (and (ly:grob? v1-dot)
761 (ly:grob-property v1-dot 'dot-count -1)))
762 (v2-dot-count (and (ly:grob? v2-dot)
763 (ly:grob-property v2-dot 'dot-count -1))))
764 (set! can-merge
765 (and
766 (number? v1-duration-log)
767 (number? v2-duration-log)
768 (= v1-duration-log v2-duration-log)
769 (eq? v1-dot-count v2-dot-count)))
770 (if can-merge
771 ;; keep the rest that looks best:
772 (let* ((keep-v1? (>= (rest-score v1-rest)
773 (rest-score v2-rest)))
774 (rest-to-keep (if keep-v1? v1-rest v2-rest))
775 (dot-to-kill (if keep-v1? v2-dot v1-dot)))
776 ;; uncomment if you're curious of which rest was chosen:
777 ;;(ly:grob-set-property! v1-rest 'color green)
778 ;;(ly:grob-set-property! v2-rest 'color blue)
779 (ly:grob-suicide! (if keep-v1? v2-rest v1-rest))
780 (if (ly:grob? dot-to-kill)
781 (ly:grob-suicide! dot-to-kill))
782 (ly:grob-set-property! rest-to-keep 'direction 0)
783 (ly:rest::y-offset-callback rest-to-keep)))))))
784 (if can-merge
786 (ly:rest-collision::calc-positioning-done grob))))
795 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
796 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
797 %%%%% TITLE PAGE / HEADER
798 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
799 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
802 \paper {
803 scoreTitleMarkup = \markup \piece-title \fromproperty #'header:piece
804 bookTitleMarkup = \markup {
805 \override #'(baseline-skip . 3.5)
806 \column {
807 \override #'(baseline-skip . 3.5)
808 \column {
809 \huge \bigger \bold
810 \fill-line {
811 \bigger \fromproperty #'header:title
813 \fill-line {
814 \large \smaller \bold
815 \bigger \fromproperty #'header:subtitle
817 \fill-line {
818 \smaller \bold
819 \fromproperty #'header:subsubtitle
821 \fill-line {
822 { \large \bold \fromproperty #'header:instrument }
824 \fill-line {
825 \fromproperty #'header:poet
826 \fromproperty #'header:composer
828 \fill-line {
829 \fromproperty #'header:meter
830 \fromproperty #'header:arranger
842 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
843 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
844 %%%%% SCORE (HEADER / LAYOUT) SETTINGS
845 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
846 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
848 \paper {
849 left-margin = 2\cm
850 right-margin = 2\cm
851 line-width = 17\cm
852 % after-title-space = 0.5\cm
853 ragged-bottom = ##f
854 ragged-last-bottom = ##f
856 \layout {
857 \context {
858 \ChoirStaff
859 % If only one non-empty staff in a system exists, still print the backet
860 \override SystemStartBracket #'collapse-height = #1
861 \consists "Instrument_name_engraver"
862 autoBeaming = ##f
864 \context {
865 \StaffGroup
866 % If only one non-empty staff in a system exists, still print the backet
867 \override SystemStartBracket #'collapse-height = #1
868 \consists "Instrument_name_engraver"
870 \context {
871 \GrandStaff
872 \override SystemStartBracket #'collapse-height = #1
873 \consists "Instrument_name_engraver"
875 \context {
876 \Score
877 % Force multi-measure rests to be written as one span
878 \override MultiMeasureRest #'expand-limit = #3
879 skipBars = ##t
880 autoBeaming = ##f
881 hairpinToBarline = ##f
882 \override BarNumber #'break-visibility = #end-of-line-invisible
883 barNumberVisibility = #(every-nth-bar-number-visible 5)
884 \override CombineTextScript #'avoid-slur = #'outside
885 \override DynamicTextSpanner #'dash-period = #-1.0
886 \override InstrumentSwitch #'font-size = #-1
888 % Rest collision
889 \override RestCollision #'positioning-done = #merge-rests-on-positioning
890 % Auto-Accidentals: Use modern-cautionary style...
891 extraNatural = ##f
892 autoAccidentals = #'(Staff (same-octave . 0))
893 autoCautionaries = #'(Staff (any-octave . 0) (same-octave . 1))
894 printKeyCancellation = ##t
896 \context {
897 \RemoveEmptyStaffContext
899 \context {
900 \Lyrics
901 \override VerticalAxisGroup #'minimum-Y-extent = #'(0.5 . 0.5)