Fix generate_oly_score.py
[orchestrallily.git] / orchestrallily.ily
blobb2448cc204cd4c635701c8db86b386746ba0475f
1 \version "2.13.17"
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: Dual-licensed under either:
12 %      -) GPL v3.0, http://www.gnu.org/licenses/gpl.html
13 %      -) Creative Commons BY-NC 3.0, http://creativecommons.org/licenses/by-nc/3.0/at/
15 % Version History:
16 % 0.01 (2008-03-02): Initial Version
17 % 0.02 (2008-03-06): Added basic MIDI support (*MidiInstrument and \setCreateMIDI)
18 % 0.03 (2008-07-xx): General staff/voice types, title pages, etc.
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21 #(use-modules (ice-9 match))
24 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25 % GLOBAL OPTIONS
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28 % Use relative include pathes!
29 #(ly:set-option 'relative-includes #t)
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34 %%%%%   SCORE STRUCTURE AND AUTOMATIC GENERATION
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 % Helper functions
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 % Helper function to filter all non-null entries
46 #(define (not-null? x) (not (null? x)))
48 % Helper function to extract a given variable, built from [Piece][Instrument]Identifier
49 #(define (namedPieceInstrObject piece instr name)
50   (let* (
51          (fullname  (string->symbol (string-append piece instr name)))
52          (instrname (string->symbol (string-append instr name)))
53          (piecename (string->symbol (string-append piece name)))
54          (fallback  (string->symbol name))
55         )
56     (cond
57       ((defined? fullname) (primitive-eval fullname))
58       ((defined? instrname) (primitive-eval instrname))
59       ((defined? piecename) (primitive-eval piecename))
60       ((defined? fallback) (primitive-eval fallback))
61       (else '())
62     )
63   )
66 %% Print text as a justified paragraph, taken from the lilypond Notation Reference
67 #(define-markup-list-command (paragraph layout props args) (markup-list?)
68    (let ((indent (chain-assoc-get 'par-indent props 2)))
69      (interpret-markup-list layout props
70        (make-justified-lines-markup-list (cons (make-hspace-markup indent)
71                                                args)))))
73 conditionalBreak = #(define-music-function (parser location) ()
74    #{ \tag #'instrumental-score \pageBreak #}
77 #(define (oly:piece-title-markup title) (markup #:column (#:line (#:fontsize #'3 #:bold title))) )
79 #(define-markup-command (piece-title layout props title) (markup?)
80      (interpret-markup layout props (oly:piece-title-markup title))
83 #(define (oly:generate_object_name piece instr obj )
84   (if (and (string? piece) (string? instr) (string? obj))
85     (string-append piece instr obj)
86     #f
87   )
89 #(define (oly:generate_staff_name piece instr) (oly:generate_object_name piece instr "St"))
91 #(define (set-context-property context property value)
92   (set! (ly:music-property context property) value)
96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97 % Score structure and voice types
98 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100 #(define oly:LiedScoreStructure '(
101   ("SoloScore" "SimultaneousMusic" ("Singstimme"))
102   ("Pfe" "PianoStaff" ("PfeI" "PfeII"))
103   ;("PfeI" "ParallelVoicesStaff" ("OIa" "OIb"))
104   ;("PfeII" "ParallelVoicesStaff" ("OIIa" "OIIb"))
105   ("FullScore" "SimultaneousMusic" ("Singstimme" "Pfe"))
106   ("VocalScore" "SimultaneousMusic" ("Singstimme" "Pfe"))
109 #(define oly:fullOrchestraScoreStructure '(
110 ; Part-combined staves for full score
111   ("Fl" "PartCombinedStaff" ("FlI" "FlII"))
112   ("Ob" "PartCombinedStaff" ("ObI" "ObII"))
113   ("Cl" "PartCombinedStaff" ("ClI" "ClII"))
114   ("Fag" "PartCombinedStaff" ("FagI" "FagII"))
115   ("Wd" "StaffGroup" ("Fl" "Ob" "Cl" "Fag" "CFag"))
117   ("Cor" "PartCombinedStaff" ("CorI" "CorII"))
118   ("Tbe" "PartCombinedStaff" ("TbeI" "TbeII"))
119   ("Clni" "PartCombinedStaff" ("ClnoI" "ClnoII"))
120   ("Trb" "PartCombinedStaff" ("TrbI" "TrbII"))
121   ("Br" "StaffGroup" ("Cor" "Tbe" "Clni" "Trb" "Tba"))
123 ; long score; no part-combined staves, but GrandStaves instead
124   ("FlLong" "GrandStaff" ("FlI" "FlII"))
125   ("ObLong" "GrandStaff" ("ObI" "ObII"))
126   ("ClLong" "GrandStaff" ("ClI" "ClII"))
127   ("FagLong" "GrandStaff" ("FagI" "FagII"))
128   ("WdLong" "StaffGroup" ("FlLong" "ObLong" "ClLong" "FagLong" "CFag"))
130   ("CorLong" "GrandStaff" ("CorI" "CorII"))
131   ("TbeLong" "GrandStaff" ("TbeI" "TbeII"))
132   ("ClniLong" "GrandStaff" ("ClnoI" "ClnoII" "ClnoIII"))
133   ("TrbLong" "GrandStaff" ("TrbI" "TrbII" "TrbIII"))
134   ("BrLong" "StaffGroup" ("CorLong" "TbeLong" "ClniLong" "TrbLong" "Tba"))
136 ; Percussion
137   ("Perc" "StaffGroup" ("Tim"))
139 ; Strings, they are the same in long and short full score
140   ("VV" "GrandStaff" ("VI" "VII"))
141   ("Str" "StaffGroup" ("VV" "Va"))
142   ("VceB" "StaffGroup" ("Vc" "Cb" "VcB"))
143   ("FullStr" "StaffGroup" ("VV" "Va" "Vc" "Cb" "VcB"))
145 ; Choral score
146   ("Solo" "SimultaneousMusic" ("SSolo" "ASolo" "TSolo" "BSolo"))
147   ("Ch" "ChoirStaff" ("S" "A" "T" "B"))
148   ("ChoralScore" "SimultaneousMusic" ("Ch"))
149   ("SoloScore" "SimultaneousMusic" ("Solo"))
150   ("SoloChoirScore" "SimultaneousMusic" ("Solo" "Ch"))
152 ; Organ score (inkl. Figured bass)
153   ("BCFb" "FiguredBass" ())
154   ("FiguredBass" "FiguredBass" ())
155   ;("Organ" "SimultaneousMusic" ("BCFb" "O"))
156   ("Continuo" "ParallelVoicesStaff" ("BCFb" "BC" "FiguredBass"))
157   ("RealizedContinuo" "PianoStaff" ("BCRealization" "Continuo"))
159   ("P" "PianoStaff" ("PI" "PII"))
160   ("O" "PianoStaff" ("OI" "OII"))
161   ("OI" "ParallelVoicesStaff" ("OIa" "OIb"))
162   ("OII" "ParallelVoicesStaff" ("OIIa" "OIIb"))
163   
164   ;("Organ" "SimultaneousMusic" ("OGroup" "RealizedContinuo"))
165   ;("BassGroup" "ParallelVoicesStaff" ("Organ" "O" "BC" "VceB"))
166   ("BassGroup" "StaffGroup" ("O" "RealizedContinuo" "Vc" "Cb" "VcB"))
167   
168 ; Full Scores
169   ("FullScore" "SimultaneousMusic" ("Wd" "Br" "Perc" "Str" "SoloChoirScore" "BassGroup"))
170   ("LongScore" "SimultaneousMusic" ("WdLong" "BrLong" "Perc" "Str" "SoloChoirScore" "BassGroup"))
171   ("OriginalScore" "SimultaneousMusic" ("BrLong" "WdLong" "Perc" "Str" "SoloChoirScore" "BassGroup"))
173 ; Piano reduction
174   ;("Piano" "SimultaneousMusic" ("Organ"))
175   ("OrganScore" "SimultaneousMusic" ("ChoralScore" "O"))
176   ("VocalScore" "SimultaneousMusic" ("ChoralScore" "P"))
177   ("Particell"  "SimultaneousMusic" ("ChoralScore" "BassGroup"))
179 ; Full scores: Orchestral score and long score including organ
180   ("ChStrQ" "SimultaneousMusic" ("Str" "Ch" "VceB"))
182 #(define oly:orchestral_score_structure oly:fullOrchestraScoreStructure)
184 #(define (oly:set_score_structure struct)
185   (if (list? struct)
186     (set! oly:orchestral_score_structure struct)
187     (ly:warning (_ "oly:set_score_structure needs an association list as argument!"))
188   )
191 #(define (oly:modify_score_structure entry)
192   (if (list? entry)
193     (set! oly:orchestral_score_structure (assoc-set! oly:orchestral_score_structure  (car entry) (cdr entry)))
194     (ly:warning (_ "oly:modify_score_structure expects a list (\"key\" \"type\" '(children)) as argument!"))))
196 #(define (oly:remove_from_score_structure entry)
197   (if (list? entry)
198     (map oly:remove_from_score_structure entry)
199     (set! oly:orchestral_score_structure (assoc-remove! oly:orchestral_score_structure  entry))))
201 orchestralScoreStructure = #(define-music-function (parser location structure) (list?)
202   (oly:set_score_structure structure)
203   (make-music 'Music 'void #t)
206 #(define oly:voice_types '())
208 #(define (oly:set_voice_types types)
209   (if (list? types)
210     (set! oly:voice_types types)
211     (ly:warning (_ "oly:set_voice_types needs an association list as argument!"))
212   )
215 orchestralVoiceTypes = #(define-music-function (parser location types) (list?)
216   (oly:set_voice_types types)
217   (make-music 'Music 'void #t)
221 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
222 % Automatic staff and group generation
223 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
225 % Retrieve all music definitions for the given
226 #(define (oly:get_music_object piece instrument)
227   (namedPieceInstrObject piece instrument "Music")
229 #(define (oly:get_music_objects piece instruments)
230   (filter not-null? (map (lambda (i) (oly:get_music_object piece i)) instruments))
233 % Given a property name and the extensions, either generate the pair to set
234 % the property or an empty list, if no pre-defined variable could be found
235 #(define (oly:generate_property_pair prop piece instr type)
236   (let* ((val (namedPieceInstrObject piece instr type)))
237     (if (not-null? val) (list 'assign prop val) '() )
238   )
241 #(define (oly:staff_type type)
242   (cond
243     ((string? type) (string->symbol type))
244     ((symbol? type) type)
245     (else 'Staff)
246   )
249 #(define (oly:extractPitch music)
250   (let* (
251          (elems  (if (ly:music? music) (ly:music-property music 'elements)))
252          (note   (if (pair? elems) (car elems)))
253          (pitch  (if (ly:music? note) (ly:music-property note 'pitch)))
254         )
255     (if (and (not-null? music) (not (ly:pitch? pitch)))
256       (ly:warning "Unable to interpret as a pitch!")
257     )
258     pitch
259   )
262 #(define (oly:extractTranspositionPitch piece name)
263   (let* (
264          (trpFromPitch (oly:extractPitch (namedPieceInstrObject piece name "TransposeFrom")))
265          (trpToPitch   (oly:extractPitch (namedPieceInstrObject piece name "TransposeTo")))
266         )
267     (if (ly:pitch? trpFromPitch)
268       (if (ly:pitch? trpToPitch)
269         ; Both pitches
270         (ly:pitch-diff trpFromPitch trpToPitch)
271         (ly:pitch-diff trpFromPitch (ly:make-pitch 0 0 0))
272       )
273       (if (ly:pitch? trpToPitch)
274         (ly:pitch-diff (ly:make-pitch 0 0 0) trpToPitch)
275         #f
276       )
277     )
278   )
282 %%=====================================================================
283 %% Extract context modifications for given objects
284 %%---------------------------------------------------------------------
287 % TODO: join these property extractors to avoid code duplication
289 % Generate the properties for the lyrics for piece and instr.
290 % Also check whether we have a modifications object to fech mods from.
291 % return a (possibly empty) list of all assignments.
292 #(define (oly:lyrics_handler_properties piece name lyricsid)
293   (let* (
294          (mods (namedPieceInstrObject piece name (string-append lyricsid "Modifications")))
295          (mod-list (if (not-null? mods) (ly:get-context-mods mods) '()))
296          (mapping '(
297              ;(instrumentName . "InstrumentName")
298              ;(shortInstrumentName . "ShortInstrumentName")
299              ;(midiInstrument . "MidiInstrument")
300             ))
301          (assignments (map
302              (lambda (pr)
303                  (oly:generate_property_pair (car pr) piece name (cdr pr))
304              )
305              mapping))
306          (olyprops (filter not-null? assignments))
307          (props (append mod-list olyprops))
308         )
309     props
310   )
313 % Generate the properties for the voice for piece and instr.
314 % Also check whether we have a modifications object to fech mods from.
315 % return a (possibly empty) list of all assignments.
316 #(define (oly:voice_handler_properties piece name)
317   (let* (
318          (mods (namedPieceInstrObject piece name "VoiceModifications"))
319          (mod-list (if (not-null? mods) (ly:get-context-mods mods) '()))
320          (mapping '(
321              ;(instrumentName . "InstrumentName")
322              ;(shortInstrumentName . "ShortInstrumentName")
323              ;(midiInstrument . "MidiInstrument")
324             ))
325          (assignments (map
326              (lambda (pr)
327                  (oly:generate_property_pair (car pr) piece name (cdr pr))
328              )
329              mapping))
330          (olyprops (filter not-null? assignments))
331          (props (append mod-list olyprops))
332         )
333     props
334   )
337 % Generate the properties for the staff for piece and instr. Typically, these
338 % are the instrument name and the short instrument name (if defined).
339 % Also check whether we have a modifications object to fech mods from.
340 % return a (possibly empty) list of all assignments.
341 #(define (oly:staff_handler_properties piece instr)
342   (let* (
343          (mods (namedPieceInstrObject piece instr "StaffModifications"))
344          (mod-list (if (not-null? mods) (ly:get-context-mods mods) '()))
345          (mapping '(
346               (instrumentName . "InstrumentName")
347               (shortInstrumentName . "ShortInstrumentName")
348               (midiInstrument . "MidiInstrument")
349             ))
350          (assignments (map
351              (lambda (pr)
352                  (oly:generate_property_pair (car pr) piece instr (cdr pr))
353              )
354              mapping))
355          (olyprops (filter not-null? assignments))
356          (props (append mod-list olyprops))
357         )
358     props
359   )
365 %%=====================================================================
366 %% Extract contents for voices
367 %%---------------------------------------------------------------------
369 #(define (oly:musiccontent_for_voice parser piece name music additional)
370   (let* ((musiccontent additional))
372     ; Append the settings, key and clef (if defined)
373     (map
374       (lambda (type)
375         (let* ((object (namedPieceInstrObject piece name type)))
376           (if (ly:music? object)
377             (set! musiccontent (append musiccontent (list (ly:music-deep-copy object))))
378             (if (not-null? object) (ly:warning (_ "Wrong type (no ly:music) for ~S for instrument ~S in piece ~S") type name piece))
379           )
380         )
381       )
382       ; TODO: Does the "Tempo" work here???
383       '("Settings" "Key" "Clef" "TimeSignature" "ExtraSettings";"Tempo"
384       )
385     )
387     (if (ly:music? music)
388       (begin
389         (set! musiccontent (make-simultaneous-music (append musiccontent (list music))))
390         ;(ly:message "Generating staff for ~a" name)
391         (let* ((trpPitch (oly:extractTranspositionPitch piece name)))
392           (if (ly:pitch? trpPitch)
393             (set! musiccontent (ly:music-transpose musiccontent trpPitch))
394           )
395         )
396         musiccontent
397       )
398       ; For empty music, return empty
399       '()
400     )
401   )
406 %%=====================================================================
407 %% create Lyrics
408 %%---------------------------------------------------------------------
411 #(define (oly:lyrics_create_single_context parser piece name voicename lyricsid)
412   ; If we have lyrics, create a lyrics context containing LyricCombineMusic
413   ; and add that as second element to the staff's elements list...
414   ; Also add possibly configured LyricsModifications
415   (let* ((id (string-append "Lyrics" lyricsid))
416          (lyricsmods (oly:lyrics_handler_properties piece name id))
417          (lyrics (namedPieceInstrObject piece name id))
418          (ctx (if (ly:music? lyrics)
419                   (context-spec-music (make-music 'LyricCombineMusic
420                                                   'element lyrics
421                                                   'associated-context voicename)
422                                       'Lyrics
423                                       (oly:generate_object_name piece name id))
424                   '())))
425     (if (and (not-null? lyricsmods) (not-null? ctx))
426       (set! (ly:music-property ctx 'property-operations) lyricsmods)
427     )
428     ctx
429   )
432 #(define (oly:lyrics_create_contexts parser piece name voicename)
433   (filter not-null?
434     (map (lambda (str)
435                  (oly:lyrics_create_single_context parser piece name voicename str))
436          (list "" "I" "II" "III"  "IV" "V" "VI"))))
439 %%=====================================================================
440 %% Voice handling
441 %%---------------------------------------------------------------------
444 #(define (oly:voice_handler_internal parser piece name type music)
445   (if (ly:music? music)
446     (let* (
447            (voicename    (oly:generate_object_name piece name "Voice" ))
448            (lyrics       (oly:lyrics_create_contexts parser piece name voicename))
449            (additional   (if (not-null? lyrics) (list dynamicUp) '()))
450            (musiccontent (oly:musiccontent_for_voice parser piece name music additional))
451            (voicetype    (oly:staff_type type))
452            (voice        (context-spec-music musiccontent voicetype voicename))
453            (voiceprops   (oly:voice_handler_properties piece name))
454           )
455       (if (not-null? voiceprops)
456         (set! (ly:music-property voice 'property-operations) voiceprops)
457       )
458       (cons voice lyrics)
459     )
460     ; For empty music, return empty
461     '()
462   )
465 #(define (oly:voice_handler parser piece name type)
466   (oly:voice_handler_internal parser piece name type (oly:get_music_object piece name)))
469 %%=====================================================================
470 %% Staff/Group handling
471 %%---------------------------------------------------------------------
474 #(define (oly:staff_handler_internal parser piece name type voices)
475   (if (not-null? voices)
476     (let* (
477            (staffname  (oly:generate_staff_name piece name))
478            (stafftype  (oly:staff_type type))
479            (staff      (make-simultaneous-music voices))
480            (propops    (oly:staff_handler_properties piece name))
481           )
482       (case stafftype
483         ((SimultaneousMusic ParallelMusic) #f)
484         (else (set! staff (context-spec-music staff stafftype staffname)))
485       )
486       (if (not-null? propops)
487         (set! (ly:music-property staff 'property-operations) propops)
488       )
489       staff
490     )
491     ; For empty music, return empty
492     '()
493   )
496 #(define (oly:staff_handler parser piece name type children)
497   (let* ((c (if (not-null? children) children (list name)))
498          (voices (apply append (map (lambda (v) (oly:create_voice parser piece v)) c)) )
499         )
500     (if (not-null? voices)
501       (oly:staff_handler_internal parser piece name type voices)
502       '()
503     )
504   )
507 #(define (oly:devnull_handler parser piece name type children)
508   (oly:voice_handler parser piece name type)
511 #(define (oly:parallel_voices_staff_handler parser piece name type children)
512   (let* (
513          (voices (map (lambda (i) (oly:create_voice parser piece i)) children))
514          ; get the list of non-empty voices and flatten it!
515          (nonemptyvoices (apply append (filter not-null? voices)))
516         )
517     (if (not-null? nonemptyvoices)
518       (oly:staff_handler_internal parser piece name "Staff" nonemptyvoices)
519       '()
520     )
521   )
524 #(define (oly:remove-with-tag tag music)
525   (if (ly:music? music)
526       (music-filter
527         (lambda (m)
528           (let* ((tags (ly:music-property m 'tags))
529                  (res (memq tag tags)))
530             (not res)))
531         music)
532       music))
534 % Remove all music tagged a not-part-combine
535 #(define (oly:remove-non-part-combine-events music)
536   (oly:remove-with-tag 'non-partcombine music))
538 #(define (oly:part_combined_staff_handler parser piece name type children)
539   (let* ((rawmusic (map (lambda (c) (oly:musiccontent_for_voice parser piece name (oly:get_music_object piece c) '())) children))
540          (filteredmusic (map (lambda (m) (oly:remove-non-part-combine-events m)) rawmusic))
541          (music (filter not-null? filteredmusic)))
542   (cond
543       ((and (pair? music) (ly:music? (car music)) (not-null? (cdr music)) (ly:music? (cadr music)))
544           ;(ly:message "Part-combine with two music expressions")
545           (oly:staff_handler_internal parser piece name "Staff" (list (make-part-combine-music parser music))))
546       ((null? music)
547           ;;(ly:warning "Part-combine without any music expressions")
548           '())
549       ; exactly one is a music expression, simply use that by joining
550       ((list? music)
551           ;;(ly:message "Part-combine with only one music expressions")
552           (oly:staff_handler_internal parser piece name "Staff" (list (apply append music))))
553       (else
554           ;(ly:message "make_part_combined_staff: ~S ~S ~a" piece instr instruments)
555           '() )
556     )
557   )
560 % Figured bass is a special case, as it can be voice- or staff-type. When
561 % given as a staff type, simply call the voice handler, instead
563 #(define (oly:figured_bass_staff_handler parser piece name type children)
564   (let* ((c (if (not-null? children) children (list name)))
565          (voice  (oly:voice_handler parser piece (car c) type)))
566     (if (pair? voice) (car voice) ())
567   )
570 #(define (flatten lst)
571   (define (f remaining result)
572     (cond
573       ((null? remaining) result)
574       ((pair? (car remaining)) (f (cdr remaining) (f (car remaining) result)))
575       (else (f (cdr remaining) (cons (car remaining) result)))))
576   (reverse! (f lst '())))
578 #(define (oly:staff_group_handler parser piece name type children)
579   (let* (
580          (staves (flatten (map (lambda (i) (oly:create_staff_or_group parser piece i)) children)))
581          (nonemptystaves (filter not-null? staves))
582         )
583     (if (not-null? nonemptystaves)
584       (let* (
585              (musicexpr (if (= 1 (length nonemptystaves))
586                           (car nonemptystaves)
587                           (make-simultaneous-music nonemptystaves)))
588              (groupname (oly:generate_staff_name piece name))
589              (grouptype (oly:staff_type type))
590              (group     musicexpr)
591              (propops   (oly:staff_handler_properties piece name))
592             )
593         (case grouptype
594           ((SimultaneousMusic ParallelMusic) #f)
595           (else (set! group (context-spec-music group grouptype groupname)))
596         )
597         (if (pair? propops)
598           (set! (ly:music-property group 'property-operations) propops))
599         group
600       )
601       ; Return empty list if no staves are generated
602       '()
603     )
604   )
607 #(define (oly:create_voice parser piece name)
608   (let* ( (voice (namedPieceInstrObject piece name "Voice"))
609           (type (assoc-ref oly:voice_types name)) )
610     (if (not-null? voice)
611       ; Explicit voice variable, use that
612       voice
614       (if (not type)
615         ; No entry in structure found => simple voice
616         (oly:voice_handler parser piece name "Voice")
617         ; Entry found in structure => use the handler for the given type
618         (let* (
619                (voicetype (car type))
620                (handler (assoc-ref oly:voice_handlers voicetype))
621               )
622           (if handler
623             ((primitive-eval handler) parser piece name voicetype)
624             (begin
625               (ly:warning "No handler found for voice type ~a, using default voice handler" voicetype)
626               (oly:voice_handler parser piece name voicetype)
627             )
628           )
629         )
630       )
631     )
632   )
635 #(define (oly:create_staff_or_group parser piece name)
636   (let* ( (staff (namedPieceInstrObject piece name "Staff"))
637           (type_from_structure (assoc-ref oly:orchestral_score_structure name)) )
638     ;(if (not-null? staff)
639     ;  (ly:message "Found staff variable for instrument ~a in piece ~a"  instr piece)
640     ;  (ly:message "Staff variable for instrument ~a in piece ~a NOT FOUND"  instr piece)
641     ;)
642     (if (not-null? staff)
643       ; Explicit staff variable, use that
644       staff
646       (if (not (list? type_from_structure))
647         ; No entry in structure found => simple staff
648         (oly:staff_handler parser piece name "Staff" '())
650         ; Entry found in structure => use the handler for the given type
651         (let* ((type (car type_from_structure))
652                (handler (assoc-ref oly:staff_handlers type))
653                (children (cadr type_from_structure))
654               )
655           (if handler
656             ((primitive-eval handler) parser piece name type children)
657             (begin
658               (ly:warning "No handler found for staff type ~a, using default staff handler" type)
659               (oly:staff_handler parser piece name type children)
660             )
661           )
662         )
663       )
664     )
665   )
668 #(define (oly:dynamics_handler parser piece name type children)
669   (oly:voice_handler parser piece name type)
673 %%=====================================================================
674 %% Handler definitions
675 %%---------------------------------------------------------------------
677 #(define oly:staff_handlers
678   (list
679     ; staff group types
680     '("GrandStaff" . oly:staff_group_handler )
681     '("PianoStaff" . oly:staff_group_handler )
682     '("ChoirStaff" . oly:staff_group_handler )
683     '("StaffGroup" . oly:staff_group_handler )
684     '("ParallelMusic" . oly:staff_group_handler )
685     '("SimultaneousMusic" . oly:staff_group_handler )
686     ; staff types
687     '("Staff" . oly:staff_handler )
688     '("DrumStaff" . oly:staff_handler )
689     '("RhythmicStaff" . oly:staff_handler )
690     '("TabStaff" . oly:staff_handler )
691     '("GregorianTranscriptionStaff" . oly:staff_handler )
692     '("MensuralStaff" . oly:staff_handler )
693     '("VaticanaStaff" . oly:staff_handler )
694     ; staves with multiple voices
695     '("PartCombinedStaff" . oly:part_combined_staff_handler )
696     '("ParallelVoicesStaff" . oly:parallel_voices_staff_handler )
697     ; special cases: Figured bass can be staff or voice type!
698     '("FiguredBass" . oly:figured_bass_staff_handler )
699     ; Devnull is like a staff, only that it doesn't craete output
700     '("Devnull" . oly:devnull_handler )
701     '("Dynamics" . oly:dynamics_handler )
702   )
705 #(define oly:voice_handlers
706   (list
707     ; voice types
708     '("Voice" . oly:voice_handler )
709     '("CueVoice" . oly:voice_handler )
710     '("DrumVoice" . oly:voice_handler )
711     '("FiguredBass" . oly:voice_handler )
712     '("GregorianTranscriptionVoice" . oly:voice_handler )
713     '("NoteNames" . oly:voice_handler )
714     '("TabVoice" . oly:voice_handler )
715     '("VaticanaVoice" . oly:voice_handler )
716   )
720 #(define (oly:register_staff_type_handler type func)
721 ;  (ly:message "Registering staff handler ~a for type ~a" func type)
722   (set! oly:staff_handlers (assoc-set! oly:staff_handlers type func))
725 #(define (oly:register_voice_type_handler type func)
726 ;  (ly:message "Registering voice type handler ~a for type ~a" func type)
727   (set! oly:voice_handlers (assoc-set! oly:voice_handlers type func))
730 % handlers for deprecated API
731 #(oly:register_staff_type_handler 'StaffGroup 'oly:staff_group_handler)
732 #(oly:register_staff_type_handler 'GrandStaff 'oly:staff_group_handler)
733 #(oly:register_staff_type_handler 'PianoStaff 'oly:staff_group_handler)
734 #(oly:register_staff_type_handler 'ChoirStaff 'oly:staff_group_handler)
735 #(oly:register_staff_type_handler 'Staff 'oly:staff_handler )
736 #(oly:register_staff_type_handler 'ParallelMusic 'oly:staff_group_handler)
737 #(oly:register_staff_type_handler 'SimultaneousMusic 'oly:staff_group_handler)
738 #(oly:register_staff_type_handler #t 'oly:part_combined_staff_handler )
739 #(oly:register_staff_type_handler #f 'oly:parallel_voices_staff_handler )
743 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
744 % Automatic score generation
745 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
747 #(define oly:score_handler add-score)
748 #(define oly:music_handler add-music)
749 #(define oly:text_handler add-text)
752 % TODO: deprecate
753 setUseBook = #(define-music-function (parser location usebook) (boolean?)
754   (ly:warning "\\setUseBook has been deprecated! Books are now automatically handled without any hacks")
755   (make-music 'Music 'void #t)
759 % Two functions to handle midi-blocks: Either don't set one, or set an empty
760 % one so that MIDI is generated
761 #(define (oly:set_no_midi_block score) '())
762 #(define (oly:set_midi_block score)
763   (let* ((midiblock (if (defined? '$defaultmidi)
764                         (ly:output-def-clone $defaultmidi)
765                         (ly:make-output-def))))
766     (ly:output-def-set-variable! midiblock 'is-midi #t)
767     (ly:score-add-output-def! score midiblock)
768   )
771 % \setCreateMidi ##t/##f sets a flag to determine wheter MIDI output should
772 % be generated
773 #(define oly:apply_score_midi oly:set_no_midi_block)
774 setCreateMIDI = #(define-music-function (parser location createmidi) (boolean?)
775   (if createmidi
776     (set! oly:apply_score_midi oly:set_midi_block)
777     (set! oly:apply_score_midi oly:set_no_midi_block)
778   )
779   (make-music 'Music 'void #t)
783 % Two functions to handle layout-blocks: Either don't set one, or set an empty
784 % one so that a PDF is generated
785 #(define (oly:set_no_layout_block score) '())
786 #(define (oly:set_layout_block score)
787   (let* ((layoutblock (if (defined? '$defaultlayout)
788                         (ly:output-def-clone $defaultlayout)
789                         (ly:make-output-def))))
790     (ly:output-def-set-variable! layoutblock 'is-layout #t)
791     (ly:score-add-output-def! score layoutblock)
792   )
795 % \setCreatePDF ##t/##f sets a flag to determine wheter PDF output should
796 % be generated
797 #(define oly:apply_score_layout oly:set_no_layout_block)
798 setCreatePDF = #(define-music-function (parser location createlayout) (boolean?)
799   (if createlayout
800     (set! oly:apply_score_layout oly:set_layout_block)
801     (set! oly:apply_score_layout oly:set_no_layout_block)
802   )
803   (make-music 'Music 'void #t)
807 % Set the piece title in a new header block.
808 #(define (oly:set_piece_header score piecename)
809   (if (not-null? piecename)
810     (let* ((header (make-module)))
811       (module-define! header 'piece piecename)
812       (ly:score-set-header! score header)
813     )
814   )
818 % post-filter functions. By default, no filtering is done. However,
819 % for the *NoCues* function, the cue notes should be killed
820 keepcuefilter = #(define-music-function (parser location music) (ly:music?) 
821   ((ly:music-function-extract removeWithTag) parser location 'non-cued music))
822 removecuefilter = #(define-music-function (parser location music) (ly:music?)
823   ((ly:music-function-extract removeWithTag) parser location 'cued ((ly:music-function-extract killCues) parser location music)))
826 #(define (oly:create-toc-file layout pages)
827   (let* ((label-table (ly:output-def-lookup layout 'label-page-table)))
828     (if (not (null? label-table))
829       (let* ((format-line (lambda (toc-item)
830              (let* ((label (car toc-item))
831                     (text  (caddr toc-item))
832                     (label-page (and (list? label-table)
833                                      (assoc label label-table)))
834                     (page (and label-page (cdr label-page))))
835                (format #f "~a, section, 1, {~a}, ~a" page text label))))
836              (formatted-toc-items (map format-line (toc-items)))
837              (whole-string (string-join formatted-toc-items ",\n"))
838              (output-name (ly:parser-output-name parser))
839              (outfilename (format "~a.toc" output-name))
840              (outfile (open-output-file outfilename)))
841         (if (output-port? outfile)
842             (display whole-string outfile)
843             (ly:warning (_ "Unable to open output file ~a for the TOC information") outfilename))
844         (close-output-port outfile)))))
847 #(define-public (oly:add-toc-item parser markup-symbol text)
848   (oly:music_handler parser (add-toc-item! markup-symbol text)))
851 #(define (oly:add-score parser score piecename)
852   (if (not-null? piecename)
853     (oly:add-toc-item parser 'tocItemMarkup piecename))
854   (oly:score_handler parser score)
856 % The helper function to build a score.
857 #(define (oly:createScoreHelper parser location piece children func)
858   (let* (
859          (staves    (oly:staff_group_handler parser piece "" "SimultaneousMusic" children))
860          (music     (if (not-null? staves)
861                         ((ly:music-function-extract func) parser location staves)
862                         '()
863                     ))
864          (score     '())
865          (piecename (namedPieceInstrObject piece (car children) "PieceName"))
866          (piecenametacet (namedPieceInstrObject piece (car children) "PieceNameTacet"))
867          (header    '())
868         )
869     (if (null? music)
870       ; No staves, print tacet
871       (begin
872         (if (not-null? piecenametacet) (set! piecename piecenametacet))
873         (if (not-null? piecename)
874           (oly:add-score parser (list (oly:piece-title-markup piecename)) piecename)
875           (ly:warning (_ "No music and no score title found for part ~a and instrument ~a") piece children)
876         )
877       )
878       ; we have staves, apply the piecename to the score and add layout/midi blocks if needed
879       (begin
880         (set! score (scorify-music music parser))
881         (oly:set_piece_header score piecename)
882         (oly:apply_score_midi score)
883         (oly:apply_score_layout score)
884         ; Schedule the score for typesetting
885         (oly:add-score parser score piecename)
886       )
887     )
888   )
889   ; This is a void function, the score has been schedulled for typesetting already
890   (make-music 'Music 'void #t)
893 createScore = #(define-music-function (parser location piece children) (string? list?)
894   (oly:createScoreHelper parser location piece children keepcuefilter)
896 createNoCuesScore = #(define-music-function (parser location piece children) (string? list?)
897   (oly:createScoreHelper parser location piece children removecuefilter)
900 createHeadline = #(define-music-function (parser location headline) (string?)
901   (oly:add-toc-item parser 'tocItemMarkup headline)
902   (oly:score_handler parser (list (oly:piece-title-markup headline)))
903   (make-music 'Music 'void #t)
908 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
909 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
910 %%%%%   CUE NOTES
911 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
912 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
914 newInstrument = #(define-music-function (parser location instr) (string?)
916   \set Voice.instrumentCueName = #$(string-join (list "+" instr))
919 cueText = #(define-music-function (parser location instr) (string?)
921   \set Voice.instrumentCueName = $instr
925 clearCueText = #(define-music-function (parser location) ()
927   \unset Voice.instrumentCueName
931 insertCueText = #(define-music-function (parser location instr) (string?)
932   (if (string-null? instr)
933     #{ \tag #'cued \clearCueText #}
934     #{ \tag #'cued \cueText #$instr #}
937 % generate a cue music section with instrument names
938 % Parameters: \namedCueDuring NameOfQuote CueDirection CueInstrument OriginalInstrument music
939 %                 -) NameOfQuote CueDirection music are the parameters for \cueDuring
940 %                 -) CueInstrument and OriginalInstrument are the displayed instrument names
941 % typical call:
942 % \namedCueDuring #"vIQuote" #UP #"V.I" #"Sop." { R1*3 }
943 %      This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
944 %      the beginning of the cue notes and "Sop." at the end
945 namedCueDuring = #(define-music-function (parser location cuevoice direction instrcue instr cuemusic) (string? number? string? string? ly:music?)
947   \cueDuring #$cuevoice #$direction {
948     \insertCueText #$instrcue
949     $cuemusic
950     \insertCueText #$instr
951   }
954 namedTransposedCueDuring = #(define-music-function (parser location cuevoice direction instrcue instr trans cuemusic) (string? number? string? string? ly:music? ly:music?)
955    #{
956      \transposedCueDuring #$cuevoice #$direction $trans {
957        \insertCueText #$instrcue
958        $cuemusic
959        \insertCueText #$instr
960      }
961    #}
964 % set the cue instrument name and clef
965 setClefCue = #(define-music-function (parser location instr clef)
966                                                      (string? ly:music?)
967    #{
968      \once \override Staff.Clef #'font-size = #-3 $clef
969      \insertCueText $instr
970    #} )
972 % generate a cue music section with instrument names and clef changes
973 % Parameters: \cleffedCueDuring NameOfQuote CueDirection CueInstrument CueClef OriginalInstrument OriginalClef music
974 %                 -) NameOfQuote CueDirection music are the parameters for \cueDuring
975 %                 -) CueInstrument and OriginalInstrument are the displayed instrument names
976 %                 -) CueClef and OriginalClef are the clefs for the the cue notes and the clef of the containing voice
977 % typical call:
978 % \cleffedCueDuring #"vIQuote" #UP #"V.I" #"treble" #"Basso" #"bass" { R1*3 }
979 %      This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
980 %      the beginning of the cue notes and "Basso" at the end. The clef is changed to treble at the
981 %      beginning of the cue notes and reset to bass at the end
982 cleffedCueDuring = #(define-music-function (parser location cuevoice direction instrcue clefcue instr clefinstr cuemusic)
983                                                         (string? number? string? ly:music? string? ly:music? ly:music?)
984    #{
985      \cueDuring #$cuevoice #$direction {
986        \tag #'cued \setClefCue #$instrcue $clefcue
987        $cuemusic
988        \tag #'cued \setClefCue #$instr $clefinstr
989      }
990    #}
996 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
997 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
998 %%%%%   DYNAMICS
999 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1000 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1003 dynamicsX = #(define-music-function (parser location offset) (number?)
1005     \once \override DynamicText #'X-offset = $offset
1006     \once \override DynamicLineSpanner #'Y-offset = #0
1009 % Move the dynamic sign inside the staff to a fixed staff-relative position
1010 % posY (where 0 means vertically starts at the middle staff line)
1011 dynamicsAllInside = #(define-music-function (parser location offsetX posY)
1012 (number? number?)
1014   % Invalid y-extent -> hidden from skyline calculation and collisions
1015 %   \once \override DynamicLineSpanner #'Y-extent = #(cons +0 -0.01)
1016   \once \override DynamicLineSpanner #'Y-extent = $(lambda (grob)
1017     (let* ((ext (ly:axis-group-interface::height grob))
1018            (dir (ly:grob-property grob 'direction)))
1019       (if (eq? dir UP)
1020             (cons (- (cdr ext) 0.1) (cdr ext))
1021             (cons (car ext)         (+ (car ext) 0.1)))))
1022   % move by X offset and to fixed Y-position (use Y-offset of parent!)
1023   \once \override DynamicText #'X-offset = $offsetX
1024   \once \override DynamicText #'Y-offset =
1025     $(lambda (grob)
1026        (let* ((head (ly:grob-parent grob Y))
1027               (offset (ly:grob-property head 'Y-offset)))
1028          (- posY  offset (- 0.6))))
1029   \once \override DynamicLineSpanner #'Y-offset = $posY
1032 dynamicsUpInside = #(define-music-function (parser location offsetX) (number?)
1033   ((ly:music-function-extract dynamicsAllInside) parser location offsetX 1.5)
1036 dynamicsDownInside = #(define-music-function (parser location offsetX) (number?)
1037   ((ly:music-function-extract dynamicsAllInside) parser location offsetX -3.5)
1040 hairpinOffset = #(define-music-function (parser location posY) (number?)
1042   \once \override DynamicLineSpanner #'Y-offset = $posY
1043   \once \override DynamicLineSpanner #'Y-extent = #(cons +0 -0.01)
1046 #(define ((line-break-offset before after) grob)
1047   (let* ((orig (ly:grob-original grob))
1048          ; All siblings if line-broken:
1049          (siblings (if (ly:grob? orig) (ly:spanner-broken-into orig) '() )))
1050     (if (>= (length siblings) 2)
1051       ; We have been line-broken
1052       (if (eq? (car (last-pair siblings)) grob)
1053         ; Last sibling:
1054         (ly:grob-set-property! grob 'Y-offset after)
1055         ; Others get the before value:
1056         (ly:grob-set-property! grob 'Y-offset before)
1057       )
1058     )
1059   )
1062 ffz = #(make-dynamic-script "ffz")
1063 pf = #(make-dynamic-script "pf")
1064 sempp = #(make-dynamic-script (markup #:line( #:with-dimensions '(0 . 0)
1065 '(0 . 0) #:right-align #:normal-text #:italic "sempre" #:dynamic "pp")))
1066 parenf = #(make-dynamic-script (markup #:line(#:normal-text #:italic #:fontsize 2 "(" #:dynamic "f" #:normal-text #:italic #:fontsize 2 ")")))
1067 parenp = #(make-dynamic-script (markup #:line(#:normal-text #:italic #:fontsize 2 "(" #:dynamic "p" #:normal-text #:italic #:fontsize 2 ")")))
1068 pdolce = #(make-dynamic-script (markup #:line(#:dynamic "p" #:with-dimensions '(0 . 0) '(0 . 0) #:normal-text #:italic "dolce")))
1069 dolce = #(make-dynamic-script (markup #:line(#:normal-text #:italic "dolce")))
1070 sfpdolce = #(make-dynamic-script (markup #:line(#:dynamic "sfp" #:with-dimensions '(0 . 0) '(0 . 0) #:normal-text #:italic "dolce"  )))
1071 bracketf = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 3 "[" #:dynamic "f" #:hspace 0.1 #:normal-text #:fontsize 3 "]"))))
1072 bracketmf = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 3 "[" #:dynamic "mf" #:hspace 0.1 #:normal-text #:fontsize 3 "]"))))
1073 bracketmp = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 2 "[" #:hspace 0.2 #:dynamic "mp" #:normal-text #:fontsize 2 "]"))))
1074 bracketp = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 2 "[" #:hspace 0.2 #:dynamic "p" #:normal-text #:fontsize 2 "]"))))
1076 whiteoutp = #(make-dynamic-script (markup #:whiteout #:pad-markup 0.5 #:dynamic "p"))
1077 whiteoutf = #(make-dynamic-script (markup #:whiteout #:pad-markup 0.5 #:dynamic "f"))
1080 % cresc = #(make-music 'CrescendoEvent 'span-direction START 'crescendoSpanner 'text 'crescendoText "cresc.")
1081 % endcresc =  #(make-span-event 'CrescendoEvent STOP)
1082 % dim = #(make-music 'DecrescendoEvent 'span-direction START 'decrescendoSpanner 'text 'decrescendoText "dim.")
1083 % enddim =  #(make-span-event 'DecrescendoEvent STOP)
1084 % decresc = #(make-music 'DecrescendoEvent 'span-direction START 'decrescendoSpanner 'text 'decrescendoText "decresc.")
1085 % enddecresc =  #(make-span-event 'DecrescendoEvent STOP)
1087 % setCresc = {}
1088 % setDecresc = {}
1089 % setDim = {}
1090 cresc = #(make-music 'CrescendoEvent 'span-direction START
1091                      'span-type 'text 'span-text "cresc.")
1092 dim = #(make-music 'DecrescendoEvent 'span-direction START
1093                    'span-type 'text 'span-text "dim.")
1094 decresc = #(make-music 'DecrescendoEvent 'span-direction START
1095                        'span-type 'text 'span-text "decresc.")
1097 % newOrOldClef = #(define-music-function (parser location new old ) (string? string?)
1098 %     (if (ly:get-option 'old-clefs) #{ \clef $old #} #{ \clef $new #})
1099 % )
1103 %%% Thanks to "Gilles THIBAULT" <gilles.thibault@free.fr>, there is a way
1104 %   to remove also the fermata from R1-\fermataMarkup: By filtering the music
1105 %   and removing the corresponding events.
1106 %   Documented as an LSR snippet: http://lsr.dsi.unimi.it/LSR/Item?id=372
1107 #(define (filterOneEventsMarkup event)
1108 ( let ( (eventname (ly:music-property  event 'name)) )
1109  (not
1110   (or     ;; add here event name you do NOT want
1111    (eq? eventname 'MultiMeasureTextEvent)
1112    (eq? eventname 'AbsoluteDynamicEvent)
1113    (eq? eventname 'TextScriptEvent)
1114    (eq? eventname 'ArticulationEvent)
1115    (eq? eventname 'CrescendoEvent)
1116    (eq? eventname 'DecrescendoEvent)
1117   )
1121 filterArticulations = #(define-music-function (parser location music) (ly:music?)
1122    (music-filter filterOneEventsMarkup music)
1129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1131 %%%%%   Tempo markings
1132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1133 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1137 rit = \markup {\italic "rit."}
1138 pocorit = \markup {\italic "poco rit."}
1139 ppmosso = \markup {\italic "poco più mosso"}
1140 pizz = \markup {\italic "pizz."}
1141 arco = \markup {\italic "arco"}
1142 perd = \markup {\italic "perdend."}
1147 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1148 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1149 %%%%%   REST COMBINATION
1150 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1151 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1155 %% REST COMBINING, TAKEN FROM http://lsr.dsi.unimi.it/LSR/Item?id=336
1157 %% Usage:
1158 %%   \new Staff \with {
1159 %%     \override RestCollision #'positioning-done = #merge-rests-on-positioning
1160 %%   } << \somevoice \\ \othervoice >>
1161 %% or (globally):
1162 %%   \layout {
1163 %%     \context {
1164 %%       \Staff
1165 %%       \override RestCollision #'positioning-done = #merge-rests-on-positioning
1166 %%     }
1167 %%   }
1169 %% Limitations:
1170 %% - only handles two voices
1171 %% - does not handle multi-measure/whole-measure rests
1173 #(define (rest-score r)
1174   (let ((score 0)
1175   (yoff (ly:grob-property-data r 'Y-offset))
1176   (sp (ly:grob-property-data r 'staff-position)))
1177     (if (number? yoff)
1178   (set! score (+ score 2))
1179   (if (eq? yoff 'calculation-in-progress)
1180       (set! score (- score 3))))
1181     (and (number? sp)
1182    (<= 0 2 sp)
1183    (set! score (+ score 2))
1184    (set! score (- score (abs (- 1 sp)))))
1185     score))
1187 #(define (merge-rests-on-positioning grob)
1188   (let* ((can-merge #f)
1189    (elts (ly:grob-object grob 'elements))
1190    (num-elts (and (ly:grob-array? elts)
1191       (ly:grob-array-length elts)))
1192    (two-voice? (= num-elts 2)))
1193     (if two-voice?
1194   (let* ((v1-grob (ly:grob-array-ref elts 0))
1195          (v2-grob (ly:grob-array-ref elts 1))
1196          (v1-rest (ly:grob-object v1-grob 'rest))
1197          (v2-rest (ly:grob-object v2-grob 'rest)))
1198     (and
1199      (ly:grob? v1-rest)
1200      (ly:grob? v2-rest)
1201      (let* ((v1-duration-log (ly:grob-property v1-rest 'duration-log))
1202       (v2-duration-log (ly:grob-property v2-rest 'duration-log))
1203       (v1-dot (ly:grob-object v1-rest 'dot))
1204       (v2-dot (ly:grob-object v2-rest 'dot))
1205       (v1-dot-count (and (ly:grob? v1-dot)
1206              (ly:grob-property v1-dot 'dot-count -1)))
1207       (v2-dot-count (and (ly:grob? v2-dot)
1208              (ly:grob-property v2-dot 'dot-count -1))))
1209        (set! can-merge
1210        (and
1211         (number? v1-duration-log)
1212         (number? v2-duration-log)
1213         (= v1-duration-log v2-duration-log)
1214         (eq? v1-dot-count v2-dot-count)))
1215        (if can-merge
1216      ;; keep the rest that looks best:
1217      (let* ((keep-v1? (>= (rest-score v1-rest)
1218               (rest-score v2-rest)))
1219       (rest-to-keep (if keep-v1? v1-rest v2-rest))
1220       (dot-to-kill (if keep-v1? v2-dot v1-dot)))
1221        ;; uncomment if you're curious of which rest was chosen:
1222        ;;(ly:grob-set-property! v1-rest 'color green)
1223        ;;(ly:grob-set-property! v2-rest 'color blue)
1224        (ly:grob-suicide! (if keep-v1? v2-rest v1-rest))
1225        (if (ly:grob? dot-to-kill)
1226            (ly:grob-suicide! dot-to-kill))
1227        (ly:grob-set-property! rest-to-keep 'direction 0)
1228        (ly:rest::y-offset-callback rest-to-keep)))))))
1229     (if can-merge
1230   #t
1231   (ly:rest-collision::calc-positioning-done grob))))
1237 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1238 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1239 %%%%%   TABLE OF CONTENTS
1240 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1241 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1244 contentsTitle = "Inhalt / Contents"
1246 \paper {
1247   tocTitleMarkup = \markup \fill-line{
1248     \null
1249     \column {
1250       \override #(cons 'line-width (* 7 cm))
1251       \line{ \fill-line {\piece-title {\contentsTitle} \null }}
1252       \hspace #1
1253     }
1254     \null
1255   }
1256   tocItemMarkup = \markup \fill-line {
1257     \null
1258     \column {
1259       \override #(cons 'line-width (* 7 cm ))
1260       \line { \fill-line{\fromproperty #'toc:text \fromproperty #'toc:page }}
1261     }
1262     \null
1263   }
1267 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1268 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1269 %%%%%   TITLE PAGE / HEADER
1270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1271 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1273 #(define-markup-command (when-property layout props symbol markp) (symbol? markup?)
1274   (if (chain-assoc-get symbol props)
1275       (interpret-markup layout props markp)
1276       (ly:make-stencil '()  '(1 . -1) '(1 . -1))))
1278 #(define-markup-command (vspace layout props amount) (number?)
1279   "This produces a invisible object taking vertical space."
1280   (let ((amount (* amount 3.0)))
1281     (if (> amount 0)
1282         (ly:make-stencil "" (cons -1 1) (cons 0 amount))
1283         (ly:make-stencil "" (cons -1 1) (cons amount amount)))))
1287 titlePageMarkup = \markup \abs-fontsize #10 \when-property #'header:title \column {
1288     \vspace #4
1289     \fill-line { \fontsize #8 \fromproperty #'header:composer }
1290     \vspace #1
1291     \fill-line { \fontsize #8 \fromproperty #'header:poet }
1292     \vspace #4
1293     \fill-line { \fontsize #10 \bold \fromproperty #'header:titlepagetitle }
1294     \vspace #1
1295     \fontsize #2 \when-property #'header:titlepagesubtitle {
1296       \fill-line { \fromproperty #'header:titlepagesubtitle }
1297       \vspace #1
1298     }
1299     \fill-line { \postscript #"-20 0 moveto 40 0 rlineto stroke" }
1300     \vspace #8
1301     \fill-line { \fontsize #5 \fromproperty #'header:ensemble }
1302     \vspace #0.02
1303     \fill-line { \fontsize #2 \fromproperty #'header:instruments }
1304     \vspace #9
1305     \fill-line { \fontsize #5 \fromproperty #'header:date }
1306     \vspace #1
1307     \fill-line { \fontsize #5 \fromproperty #'header:scoretype }
1308     \when-property #'header:instrument {
1309       \fill-line { \bold \fontsize #6 \rounded-box \fromproperty #'header:instrument }
1310     }
1311     \vspace #8
1312     \fontsize #2 \when-property #'header:enteredby {
1313       \fill-line { "Herausgegeben von: / Edited by:"}
1314       \vspace #0.
1315       \fill-line { \fromproperty #'header:enteredby }
1316     }
1317     \fill-line {
1318       \when-property #'header:arrangement \column {
1319         \vspace #8
1320         \fill-line { \fontsize #3 \fromproperty #'header:arrangement }
1321       }
1322     }
1323   \vspace #6
1324   \fill-line { \fromproperty #'header:copyright }
1327 titleHeaderMarkup = \markup {
1328   \override #'(baseline-skip . 3.5)
1329   \column {
1330     \fill-line {
1331       \fromproperty #'header:logo
1332       \center-column {
1333         \huge \larger \bold \larger \fromproperty #'header:title
1334         \large \smaller \bold \larger \fromproperty #'header:subtitle
1335         \smaller \bold \fromproperty #'header:subsubtitle
1336       }
1337       \bold \when-property #'header:instrument \rounded-box \fromproperty #'header:instrument
1338     }
1339     \fill-line {
1340       \with-dimensions #'( 0 . 0) #'( 0 . 1 ) \null
1341     }
1343 %     \fill-line {
1344 %       { \large \bold \fromproperty #'header:instrument }
1345 %     }
1346     \fill-line {
1347       \fromproperty #'header:poet
1348       \fromproperty #'header:composer
1349     }
1350     \fill-line {
1351       \fromproperty #'header:meter
1352       \fromproperty #'header:arranger
1353     }
1354   }
1357 titleScoreMarkup = \markup \piece-title \fromproperty #'header:piece
1359 \paper {
1360   scoreTitleMarkup = \titleScoreMarkup
1361   bookTitleMarkup = \titleHeaderMarkup
1366 %%%%%%%%%%%%%% headers and footers %%%%%%%%%%%%%%%%%%%%%%%%%%
1368 #(define (first-score-page layout props arg)
1369   (let* ((label 'first-score-page)
1370          (table (ly:output-def-lookup layout 'label-page-table))
1371          (label-page (and (list? table) (assoc label table)))
1372          (page-number (and label-page (cdr label-page)))
1373         )
1374     (if (eq? (chain-assoc-get 'page:page-number props -1) page-number)
1375       (interpret-markup layout props arg)
1376       empty-stencil)))
1378 #(define no-header-table '())
1379 thisPageNoHeader = #(define-music-function (parser location) ()
1380   (let* ((label (gensym "header")))
1381     (set! no-header-table (cons label no-header-table))
1382     (make-music 'Music
1383       'page-marker #t
1384       'page-label label)))
1387 % TODO: Use the no-header-table!
1388 #(define (is-header-page layout props arg)
1389   (let* ((page-number (chain-assoc-get 'page:page-number props -1))
1390         )
1391     ;(if (and (> page-number 2) (!= page-number 7))
1392     (if (> page-number 1)
1393       (interpret-markup layout props arg)
1394       empty-stencil)))
1396 #(define no-footer-table '())
1397 thisPageNoFooter = #(define-music-function (parser location) ()
1398   (let* ((label (gensym "footer")))
1399     (set! no-footer-table (cons label no-footer-table))
1400     (make-music 'Music
1401       'page-marker #t
1402       'page-label label)))
1404 % TODO: Use the no-footer-table!
1405 #(define (is-footer-page layout props arg)
1406   (let* ((page-number (chain-assoc-get 'page:page-number props -1))
1407          (label 'first-score-page)
1408          (table (ly:output-def-lookup layout 'label-page-table))
1409          (label-page (and (list? table) (assoc label table)))
1410          ;(page-number (and label-page (cdr label-page)))
1411         )
1412     (if (and (> page-number 1))
1413       (interpret-markup layout props arg)
1414       empty-stencil)))
1417 #(define copyright-footer-table '())
1418 thisPageCopyrightFooter = #(define-music-function (parser location) ()
1419   (let* ((label (gensym "copyrightfooter")))
1420     (set! copyright-footer-table (cons label copyright-footer-table))
1421     (make-music 'Music
1422       'page-marker #t
1423       'page-label label)))
1425 #(define copyright-pg 1)
1426 #(define (set-copyright-page page)
1427   (set! copyright-pg page)
1430 % TODO: Use the copyright-footer-table!
1431 #(define (copyright-page layout props arg)
1432     (if (= (chain-assoc-get 'page:page-number props -1) copyright-pg)
1433       (interpret-markup layout props arg)
1434       empty-stencil))
1437 \paper {
1438   oddHeaderMarkup = \markup \fill-line {
1439     %% force the header to take some space, otherwise the
1440     %% page layout becomes a complete mess.
1441     " "
1442     \on-the-fly #is-header-page \fromproperty #'header:title
1443     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1444   }
1445   evenHeaderMarkup = \markup \fill-line {
1446     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1447     \on-the-fly #is-header-page \fromproperty #'header:composer
1448     " "
1449   }
1451   oddFooterMarkup = \markup {
1452     \column {
1453       \fill-line {
1454         %% publisher header field only on title page.
1455         \on-the-fly #first-page \fromproperty #'header:publisher
1456       }
1457       \fill-line {
1458         %% copyright on the first real score page
1459         \on-the-fly #copyright-page \fromproperty #'header:copyright
1460         \on-the-fly #copyright-page \null
1461       }
1462       \fill-line {
1463         %% All other pages get the number of the edition centered
1464         \on-the-fly #is-footer-page \fromproperty #'header:scorenumber
1465       }
1466     }
1467   }
1481 % Interpret the given markup with the header fields added to the props.
1482 % This way, one can re-use the same functions (using fromproperty
1483 % #'header:field) in the header block and as top-level markup.
1485 % This function is originally copied from mark-up-title (file scm/titling.scm),
1486 % which is lilypond's internal function to handle the title markups. I needed
1487 % to replace the scopes and manually add the $defaultheader (which is internally
1488 % done in paper-book.cc before calling mark-up-title. Also, I don't extract the
1489 % markup from the header block, but use the given markup.
1491 % I'm not sure if I really need the page properties in props, too... But I
1492 % suppose it does not hurt, either.
1493 #(define-markup-command (markupWithHeader layout props markup) (markup?)
1494   "Interpret the given markup with the header fields added to the props.
1495    This way, one can re-use the same functions (using fromproperty
1496    #'header:field) in the header block and as top-level markup."
1497   (let* (
1498       ; TODO: If we are inside a score, add the score's local header block, too!
1499       ; Currently, I only use the global header block, stored in $defaultheader
1500       (scopes (list $defaultheader))
1501       (alists (map ly:module->alist scopes))
1503       (prefixed-alist
1504         (map (lambda (alist)
1505           (map (lambda (entry)
1506             (cons
1507               (string->symbol (string-append "header:" (symbol->string (car entry))))
1508               (cdr entry)))
1509             alist))
1510           alists))
1511       (props (append prefixed-alist
1512               props
1513               (layout-extract-page-properties layout)))
1514     )
1515     (interpret-markup layout props markup)
1516   )
1524 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1525 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1526 %%%%%   Equally spacing multiple columns (e.g. for translations)
1527 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1528 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1530 % Credits: Nicolas Sceaux on the lilypond-user mailinglist
1531 #(define-markup-command (columns layout props args) (markup-list?)
1532    (let ((line-width (/ (chain-assoc-get 'line-width props
1533                          (ly:output-def-lookup layout 'line-width))
1534                         (max (length args) 1))))
1535      (interpret-markup layout props
1536        (make-line-markup (map (lambda (line)
1537                                 (markup #:pad-to-box `(0 . ,line-width) '(0 . 0)
1538                                   #:override `(line-width . ,line-width)
1539                                   line))
1540                                args)))))
1544 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1545 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1546 %%%%%   SCORE (HEADER / LAYOUT) SETTINGS
1547 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1548 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1551 startSlashedGraceMusic =  {
1552   \override Stem  #'stroke-style = #"grace"
1555 stopSlashedGraceMusic =  {
1556   \revert Stem #'stroke-style
1559 slashedGrace =
1560 #(def-grace-function startSlashedGraceMusic stopSlashedGraceMusic
1561    (_i "Create slashed graces (slashes through stems, but no slur)from the following music expression"))
1564 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1565 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1566 %%%%%   SCORE (HEADER / LAYOUT) SETTINGS
1567 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1568 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1570 \paper {
1571   left-margin = 2\cm
1572   right-margin = 1.5\cm
1573   line-width = 17.5\cm
1574 %   bottom-margin = 1.5\cm
1575   top-margin = 0.7\cm
1576 %   after-title-space = 0.5\cm
1577   ragged-right = ##f
1578   ragged-last = ##f
1579   ragged-bottom = ##f
1580   ragged-last-bottom = ##f
1582 \layout {
1583   \context {
1584     \ChoirStaff
1585     % If only one non-empty staff in a system exists, still print the backet
1586     \override SystemStartBracket #'collapse-height = #1
1587     \consists "Instrument_name_engraver"
1588   }
1589   \context {
1590     \StaffGroup
1591     % If only one non-empty staff in a system exists, still print the backet
1592     \override SystemStartBracket #'collapse-height = #1
1593     \consists "Instrument_name_engraver"
1594   }
1595   \context {
1596     \GrandStaff
1597     \override SystemStartBracket #'collapse-height = #1
1598     \consists "Instrument_name_engraver"
1599   }
1600   \context {
1601     \FiguredBass
1602 %     \override VerticalAxisGroup #'keep-fixed-while-stretching = ##t
1603 %     \override VerticalAxisGroup #'minimum-Y-extent  = #'(0 . 1) % TODO: Removed
1604     \override VerticalAxisGroup #'padding = #0
1605   }
1606   \context {
1607     \Score
1608     % Force multi-measure rests to be written as one span
1609     \override MultiMeasureRest #'expand-limit = #3
1610     skipBars = ##t
1611     autoBeaming = ##f
1612 %     \override Hairpin #'to-barline = ##f
1613 %     \override BarNumber #'break-visibility = #end-of-line-invisible
1614 %     \override BarNumber #'self-alignment-X = #0
1615 %     barNumberVisibility = #(every-nth-bar-number-visible 5)
1616     \override CombineTextScript #'avoid-slur = #'outside
1617     \override DynamicTextSpanner #'dash-period = #-1.0
1618     \override InstrumentSwitch #'font-size = #-1
1620     % Rest collision
1621     \override RestCollision #'positioning-done = #merge-rests-on-positioning
1622     % Auto-Accidentals: Use modern-cautionary style...
1623     extraNatural = ##f
1624     % Accidental rules (the rule giving the most accidentals wins!)
1625     % -) Reset accidentals at each barline -> accs not in key sig will always be printed
1626     % -) Same octave accidentals are remembered for two measures -> cancellation
1627     % -) other octave accidentals are remembered for next measure -> cancellation
1628     autoAccidentals = #`(Staff  ,(make-accidental-rule 'same-octave 0)
1629                                 ,(make-accidental-rule 'any-octave 0)
1630                                 ,(make-accidental-rule 'any-octave 1)
1631                                 ,(make-accidental-rule 'same-octave 2))
1632     % No auto-cautionaries, we always use autoAccidentals!
1633 %     autoCautionaries = #`(Staff ,(make-accidental-rule 'any-octave 0)
1634 %                                 ,(make-accidental-rule 'same-octave 1))
1635     printKeyCancellation = ##t
1636     quotedEventTypes = #'(StreamEvent)
1637     quotedCueEventTypes = #'(
1638       rhythmic-event
1639       tie-event
1640       beam-event
1641       tuplet-span-event
1642       tremolo-event
1643       glissando-event
1644       harmonic-event
1645       repeat-tie-event
1646       articulation-event
1647       slur-event
1648       trill-span-event
1649       tremolo-span-event
1650     )
1651     implicitBassFigures = #'(0 100)
1652   }
1653   \context {
1654     \Staff
1655     \RemoveEmptyStaves
1656   }
1660 ts = ^\markup{"t.s."}
1661 tt = ^\markup{"Tutti"}
1662 solo = ^\markup{"Solo"}
1663 tutti = ^\markup{"Tutti"}
1664 bracketts = ^\markup{"[Solo]"}
1665 brackettt = ^\markup{"[Tutti]"}
1666 bracketsolo = ^\markup{"[Solo]"}
1668 sottovoce = \markup "sotto voce"
1670 dashedSlur = -\tweak #'dash-definition #'((0 1 0.4 0.75))(
1671 dashedTie = -\tweak #'dash-definition #'((0 1 0.4 0.75))~
1673 divisi = #(define-music-function (parser location vc1 vc2) (ly:music? ly:music?)
1675   << { \voiceOne $vc1 \oneVoice} \context Voice = "divisi2" { \voiceTwo $vc2 } >>
1679 #(define twoVoice divisi)
1681 #(define-public (bracket-stencils grob)
1682   (let ((lp (grob-interpret-markup grob (markup #:fontsize 3.5 #:translate (cons -0.3 -0.5) "[")))
1683         (rp (grob-interpret-markup grob (markup #:fontsize 3.5 #:translate (cons -0.3 -0.5) "]"))))
1684     (list lp rp)))
1686 bracketify = #(define-music-function (parser loc arg) (ly:music?)
1687    (_i "Tag @var{arg} to be parenthesized.")
1689   \once \override ParenthesesItem #'stencils = #bracket-stencils
1690   \parenthesize $arg
1695 #(define-markup-command (hat layout props arg) (markup?)
1696   "Draw a hat above the given string @var{arg}."
1697   (interpret-markup layout props (markup #:combine #:raise 1.5 "^" arg)))
1701 smallFlageolet =
1702 #(let ((m (make-music 'ArticulationEvent
1703                       'articulation-type "flageolet")))
1704    (ly:music-set-property! m 'tweaks
1705      (acons 'font-size -2
1706        (ly:music-property m 'tweaks)))
1707   m)
1710 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1711 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1712 %%%%%   LICENSE TEXTS
1713 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1714 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1716 LicenseCCBYPlain = \markup {Creative Commons BY \with-url #"http://creativecommons.org/licenses/by/3.0/at/" {\translate #'(0 . -0.7) \epsfile #Y #3 #"orchestrallily/cc-by.eps" }}
1717 LicenseCCBY = \markup {Lizensiert unter / Licensed under: Creative Commons BY \with-url #"http://creativecommons.org/licenses/by/3.0/at/" {\translate #'(0 . -0.7) \epsfile #Y #3 #"orchestrallily/cc-by.eps" }}
1718 LicenseCCBYNC = \markup {Lizensiert unter / Licensed under: Creative Commons BY-NC \with-url #"http://creativecommons.org/licenses/by-nc/3.0/at/" {\translate #'(0 . -0.7) \epsfile #Y #3 #"orchestrallily/cc-by-nc.eps" }}
1719 LicenseNoRestrictions = \markup{\line {Die Ausgabe darf kopiert und ohne Einschränkungen aufgeführt werden. / May be copied and performed without restriction.}}
1721 \include "sceaux_clef-key.ily"
1724 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1725 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1726 %%%%%   VARIOUS
1727 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1728 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1730 startUnremovableSection = \set Staff.keepAliveInterfaces =
1731  #'(rhythmic-grob-interface
1732     rest-interface
1733     lyric-interface
1734     percent-repeat-item-interface
1735     percent-repeat-interface
1736     stanza-number-interface)
1738 endUnremovableSection = \unset Staff.keepAliveInterfaces
1741 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1742 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1743 %%%%%   EDITORIAL ANNOTATIONS
1744 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1745 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1747 #(define-public (editorial-bracket-stencil stil padding widen)
1748 "Add brackets for editorial annoations around STIL, producing a new stencil."
1749 (let* ((axis Y)
1750        (other-axis (lambda (a) (remainder (+ a 1) 2)))
1751        (ext (interval-widen (ly:stencil-extent stil axis) widen))
1752        (thick 0.15)
1753        (protrusion 0.3)
1754        (lb (ly:bracket axis ext thick protrusion))
1755        (rb (ly:bracket axis ext thick (- protrusion))))
1756   (set! stil (ly:stencil-combine-at-edge stil (other-axis axis) 1 rb padding))
1757   (set! stil
1758     (ly:stencil-combine-at-edge lb (other-axis axis) 1 stil padding))
1759   stil))
1761 editorialHairpin = \once \override Hairpin     #'stencil = #(lambda (grob) (editorial-bracket-stencil (ly:hairpin::print grob) 0.2 0.55))
1762 editorialDynamic = \once \override DynamicText #'stencil = #(lambda (grob) (editorial-bracket-stencil (ly:text-interface::print grob) 0.2 0.55))
1763 editorialMarkup =  \once \override TextScript  #'stencil = #(lambda (grob) (editorial-bracket-stencil (ly:text-interface::print grob) 0.2 0.55))
1765 % videStart = \mark \markup { \hspace #1 \musicglyph #"scripts.coda"  \with-dimensions #'(0 . 0) #'(0 . 0) \left-align { vi-} }
1766 videStart = \mark \markup \halign #-2.3 \concat { \hspace #4.5 \musicglyph #"scripts.coda" \left-align { vi- } }
1767 % videEnd = \notemode {
1768 %   \once \override Score.RehearsalMark #'break-visibility = #begin-of-line-invisible
1769 %   \mark \markup \concat{ \with-dimensions #'(0 . 0) #'(0 . 0) \right-align { -de } \hspace #1 \musicglyph #"scripts.coda" }
1771 videEnd = \notemode {
1772         \once \override Score.RehearsalMark #'break-visibility = #begin-of-line-invisible
1773         \mark \markup \concat{ \right-align { -de } \hspace #1.5 \musicglyph #"scripts.coda" \hspace #4.2 }
1778 \layout {
1779         \context {\Staff
1780                 soloText = #"I"
1781                 soloIIText = #"II"
1782                 aDueText = #"a2"
1783         }
1786 \paper {
1787         %   after-title-spacing = #'((space . 2) (padding . 2) (stretchability . 5))
1788         %   between-system-spacing = #'((space . 0) (padding . 2) (stretchability . 35))
1789         %   bottom-system-spacing = #'((space . 10) (padding . 2) (stretchability . 5))
1790           markup-system-spacing = #'((space . 4) (padding . 2) (stretchability . 20))
1791 %           system-system-spacing = #'((space . 0) (padding . 20) (stretchability . 50))
1792           system-system-spacing = #'((space . 0) (padding . 2) (stretchability . 50))
1793           top-system-spacing = #'((space . 5) (padding . 2) (stretchability . 20))
1794           last-bottom-spacing = #'((space . 5) (padding . 2) (stretchability . 20))
1795 %         system-markup-spacing = #'((space . 5) (padding . 2) (stretchability . 35))
1797 \layout {
1798         \context { \StaffGroup
1799                 \override StaffGrouper #'between-staff-spacing #'space = 5
1800                 \override StaffGrouper #'between-staff-spacing #'stretchability = #4.5
1801         }
1802         \context { \GrandStaff
1803                 \override StaffGrouper #'between-staff-spacing #'space = 5
1804                 \override StaffGrouper #'between-staff-spacing #'stretchability = #4.5
1805         }
1806         \context { \ChoirStaff
1807                 \override StaffGrouper #'between-staff-spacing #'space = 5
1808                 \override StaffGrouper #'between-staff-spacing #'stretchability = #3
1809         }
1810         \context { \Staff
1811                 \override StaffGrouper #'between-staff-spacing #'space = 1
1812                 \override StaffGrouper #'between-staff-spacing #'stretchability = #4.9
1813         }
1814         \context { \Score
1815                 \override StaffGrouper #'between-staff-spacing #'space = 5
1816                 \override StaffGrouper #'between-staff-spacing #'stretchability = #5
1817         }