Translate Inhaltsverzeichnis caption
[orchestrallily.git] / orchestrallily.ily
blobebb5fa7f258c98c845208da3c974f75ee3f413ed
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"))
164   ;("Organ" "SimultaneousMusic" ("OGroup" "RealizedContinuo"))
165   ;("BassGroup" "ParallelVoicesStaff" ("Organ" "O" "BC" "VceB"))
166   ("BassGroup" "StaffGroup" ("O" "RealizedContinuo" "Vc" "Cb" "VcB"))
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          ;; The page numbers are pages counts in the pdf file, not visible page number!
829          ;; So we have to offset them if the first page is not page #1
830          (first-page-offset (1- (ly:output-def-lookup layout 'first-page-number))))
831     (if (not (null? label-table))
832       (let* ((format-line (lambda (toc-item)
833              (let* ((label (car toc-item))
834                     (text  (caddr toc-item))
835                     (label-page (and (list? label-table)
836                                      (assoc label label-table)))
837                     (page (and label-page (cdr label-page))))
838                (format #f "~a, section, 1, {~a}, ~a" (- page first-page-offset) text label))))
839              (formatted-toc-items (map format-line (toc-items)))
840              (whole-string (string-join formatted-toc-items ",\n"))
841              (output-name (ly:parser-output-name parser))
842              (outfilename (format "~a.toc" output-name))
843              (outfile (open-output-file outfilename)))
844         (if (output-port? outfile)
845             (display whole-string outfile)
846             (ly:warning (_ "Unable to open output file ~a for the TOC information") outfilename))
847         (close-output-port outfile)))))
850 #(define-public (oly:add-toc-item parser markup-symbol text)
851   (oly:music_handler parser (add-toc-item! markup-symbol text)))
854 #(define (oly:add-score parser score piecename)
855   (if (not-null? piecename)
856     (oly:add-toc-item parser 'tocItemMarkup piecename))
857   (oly:score_handler parser score)
859 % The helper function to build a score.
860 #(define (oly:createScoreHelper parser location piece children func)
861   (let* (
862          (staves    (oly:staff_group_handler parser piece "" "SimultaneousMusic" children))
863          (music     (if (not-null? staves)
864                         ((ly:music-function-extract func) parser location staves)
865                         '()
866                     ))
867          (score     '())
868          (piecename (namedPieceInstrObject piece (car children) "PieceName"))
869          (piecenametacet (namedPieceInstrObject piece (car children) "PieceNameTacet"))
870          (header    '())
871         )
872     (if (null? music)
873       ; No staves, print tacet
874       (begin
875         (if (not-null? piecenametacet) (set! piecename piecenametacet))
876         (if (not-null? piecename)
877           (oly:add-score parser (list (oly:piece-title-markup piecename)) piecename)
878           (ly:warning (_ "No music and no score title found for part ~a and instrument ~a") piece children)
879         )
880       )
881       ; we have staves, apply the piecename to the score and add layout/midi blocks if needed
882       (begin
883         (set! score (scorify-music music parser))
884         (oly:set_piece_header score piecename)
885         (oly:apply_score_midi score)
886         (oly:apply_score_layout score)
887         ; Schedule the score for typesetting
888         (oly:add-score parser score piecename)
889       )
890     )
891   )
892   ; This is a void function, the score has been schedulled for typesetting already
893   (make-music 'Music 'void #t)
896 createVoice = #(define-music-function (parser location piece name) (string? string?)
897   (let* ((vc (oly:create_voice parser piece name)))
898     (make-music 'SimultaneousMusic
899                 'elements vc)))
901 createStaff = #(define-music-function (parser location piece name) (string? string?)
902   (oly:create_staff_or_group parser piece name))
903 createStaffForContents = #(define-music-function (parser location piece name contents) (string? string? ly:music?)
904   (let* ((tstruct (assoc-ref oly:orchestral_score_structure name))
905          (type (if (list? tstruct) (car tstruct) "Staff")))
906     (oly:staff_handler_internal parser piece name type (list contents))))
909 createScore = #(define-music-function (parser location piece children) (string? list?)
910   (oly:createScoreHelper parser location piece children keepcuefilter)
912 createNoCuesScore = #(define-music-function (parser location piece children) (string? list?)
913   (oly:createScoreHelper parser location piece children removecuefilter)
916 createHeadline = #(define-music-function (parser location headline) (string?)
917   (oly:add-toc-item parser 'tocItemMarkup headline)
918   (oly:score_handler parser (list (oly:piece-title-markup headline)))
919   (make-music 'Music 'void #t)
924 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
925 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
926 %%%%%   CUE NOTES
927 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
928 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
930 newInstrument = #(define-music-function (parser location instr) (string?)
932   \set Voice.instrumentCueName = #$(string-join (list "+" instr))
935 cueText = #(define-music-function (parser location instr) (string?)
937   \set Voice.instrumentCueName = $instr
940 cueMarkup = #(define-music-function (parser location instr) (markup?)
942   \set Voice.instrumentCueName = $instr
946 clearCueText = #(define-music-function (parser location) ()
948   \unset Voice.instrumentCueName
952 insertCueText = #(define-music-function (parser location instr) (string?)
953   (if (string-null? instr)
954     #{ \tag #'cued \clearCueText #}
955     #{ \tag #'cued \cueText #$instr #}
958 % generate a cue music section with instrument names
959 % Parameters: \namedCueDuring NameOfQuote CueDirection CueInstrument OriginalInstrument music
960 %                 -) NameOfQuote CueDirection music are the parameters for \cueDuring
961 %                 -) CueInstrument and OriginalInstrument are the displayed instrument names
962 % typical call:
963 % \namedCueDuring #"vIQuote" #UP #"V.I" #"Sop." { R1*3 }
964 %      This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
965 %      the beginning of the cue notes and "Sop." at the end
966 namedCueDuring = #(define-music-function (parser location cuevoice direction instrcue instr cuemusic) (string? number? string? string? ly:music?)
968   \cueDuring #$cuevoice #$direction {
969     \insertCueText #$instrcue
970     $cuemusic
971     \insertCueText #$instr
972   }
975 namedTransposedCueDuring = #(define-music-function (parser location cuevoice direction instrcue instr trans cuemusic) (string? number? string? string? ly:music? ly:music?)
976    #{
977      \transposedCueDuring #$cuevoice #$direction $trans {
978        \insertCueText #$instrcue
979        $cuemusic
980        \insertCueText #$instr
981      }
982    #}
985 % set the cue instrument name and clef
986 setClefCue = #(define-music-function (parser location instr clef)
987                                                      (string? ly:music?)
988    #{
989      \once \override Staff.Clef #'font-size = #-3 $clef
990      \insertCueText $instr
991    #} )
993 % generate a cue music section with instrument names and clef changes
994 % Parameters: \cleffedCueDuring NameOfQuote CueDirection CueInstrument CueClef OriginalInstrument OriginalClef music
995 %                 -) NameOfQuote CueDirection music are the parameters for \cueDuring
996 %                 -) CueInstrument and OriginalInstrument are the displayed instrument names
997 %                 -) CueClef and OriginalClef are the clefs for the the cue notes and the clef of the containing voice
998 % typical call:
999 % \cleffedCueDuring #"vIQuote" #UP #"V.I" #"treble" #"Basso" #"bass" { R1*3 }
1000 %      This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
1001 %      the beginning of the cue notes and "Basso" at the end. The clef is changed to treble at the
1002 %      beginning of the cue notes and reset to bass at the end
1003 cleffedCueDuring = #(define-music-function (parser location cuevoice direction instrcue clefcue instr clefinstr cuemusic)
1004                                                         (string? number? string? ly:music? string? ly:music? ly:music?)
1005    #{
1006      \cueDuring #$cuevoice #$direction {
1007        \tag #'cued \setClefCue #$instrcue $clefcue
1008        $cuemusic
1009        \tag #'cued \setClefCue #$instr $clefinstr
1010      }
1011    #}
1013 % generate a cue music section with instrument names and clef changes
1014 % Parameters: \namedCueDuringClef NameOfQuote CueDirection CueInstrument CueClef OriginalInstrument music
1015 %                 -) NameOfQuote CueDirection music are the parameters for \cueDuring
1016 %                 -) CueInstrument and OriginalInstrument are the displayed instrument names
1017 %                 -) CueClef is the clef for the the cue notes
1018 % typical call:
1019 % \namedCueDuringClef #"vIQuote" #UP #"V.I" #"treble" #"Basso" { R1*3 }
1020 %      This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
1021 %      the beginning of the cue notes and "Basso" at the end. The clef is changed to treble at the
1022 %      beginning of the cue notes and reset to bass at the end
1023 namedCueDuringWithClef = #(define-music-function (parser location cuevoice direction instrcue clefcue instr cuemusic)
1024                                              (string? number? string? string? string? ly:music?)
1025    #{
1026      \cueDuringWithClef #$cuevoice #$direction #$clefcue {
1027        \insertCueText #$instrcue
1028        $cuemusic
1029        \insertCueText #$instr
1030      }
1031    #}
1036 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1037 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1038 %%%%%   DYNAMICS
1039 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1043 dynamicsX = #(define-music-function (parser location offset) (number?)
1045     \once \override DynamicText #'X-offset = $offset
1046     \once \override DynamicLineSpanner #'Y-offset = #0
1049 % Move the dynamic sign inside the staff to a fixed staff-relative position
1050 % posY (where 0 means vertically starts at the middle staff line)
1051 dynamicsAllInside = #(define-music-function (parser location offsetX posY)
1052 (number? number?)
1054   % Invalid y-extent -> hidden from skyline calculation and collisions
1055 %   \once \override DynamicLineSpanner #'Y-extent = #(cons +0 -0.01)
1056   \once \override DynamicLineSpanner #'Y-extent = $(lambda (grob)
1057     (let* ((ext (ly:axis-group-interface::height grob))
1058            (dir (ly:grob-property grob 'direction)))
1059       (if (eq? dir UP)
1060             (cons (- (cdr ext) 0.1) (cdr ext))
1061             (cons (car ext)         (+ (car ext) 0.1)))))
1062   % move by X offset and to fixed Y-position (use Y-offset of parent!)
1063   \once \override DynamicText #'X-offset = $offsetX
1064   \once \override DynamicText #'Y-offset =
1065     $(lambda (grob)
1066        (let* ((head (ly:grob-parent grob Y))
1067               (offset (ly:grob-property head 'Y-offset)))
1068          (- posY  offset (- 0.6))))
1069   \once \override DynamicLineSpanner #'Y-offset = $posY
1072 dynamicsUpInside = #(define-music-function (parser location offsetX) (number?)
1073   ((ly:music-function-extract dynamicsAllInside) parser location offsetX 1.5)
1076 dynamicsDownInside = #(define-music-function (parser location offsetX) (number?)
1077   ((ly:music-function-extract dynamicsAllInside) parser location offsetX -3.5)
1080 hairpinOffset = #(define-music-function (parser location posY) (number?)
1082   \once \override DynamicLineSpanner #'Y-offset = $posY
1083   \once \override DynamicLineSpanner #'Y-extent = #(cons +0 -0.01)
1086 #(define ((line-break-offset before after) grob)
1087   (let* ((orig (ly:grob-original grob))
1088          ; All siblings if line-broken:
1089          (siblings (if (ly:grob? orig) (ly:spanner-broken-into orig) '() )))
1090     (if (>= (length siblings) 2)
1091       ; We have been line-broken
1092       (if (eq? (car (last-pair siblings)) grob)
1093         ; Last sibling:
1094         (ly:grob-set-property! grob 'Y-offset after)
1095         ; Others get the before value:
1096         (ly:grob-set-property! grob 'Y-offset before)
1097       )
1098     )
1099   )
1102 ffz = #(make-dynamic-script "ffz")
1103 pf = #(make-dynamic-script "pf")
1104 sempp = #(make-dynamic-script (markup #:line( #:with-dimensions '(0 . 0)
1105 '(0 . 0) #:right-align #:normal-text #:italic "sempre" #:dynamic "pp")))
1106 parenf = #(make-dynamic-script (markup #:line(#:normal-text #:italic #:fontsize 2 "(" #:dynamic "f" #:normal-text #:italic #:fontsize 2 ")")))
1107 parenp = #(make-dynamic-script (markup #:line(#:normal-text #:italic #:fontsize 2 "(" #:dynamic "p" #:normal-text #:italic #:fontsize 2 ")")))
1108 pdolce = #(make-dynamic-script (markup #:line(#:dynamic "p" #:with-dimensions '(0 . 0) '(0 . 0) #:normal-text #:italic "dolce")))
1109 dolce = #(make-dynamic-script (markup #:line(#:normal-text #:italic "dolce")))
1110 sfpdolce = #(make-dynamic-script (markup #:line(#:dynamic "sfp" #:with-dimensions '(0 . 0) '(0 . 0) #:normal-text #:italic "dolce"  )))
1111 bracketf = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 3 "[" #:dynamic "f" #:hspace 0.1 #:normal-text #:fontsize 3 "]"))))
1112 bracketmf = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 3 "[" #:dynamic "mf" #:hspace 0.1 #:normal-text #:fontsize 3 "]"))))
1113 bracketmp = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 2 "[" #:hspace 0.2 #:dynamic "mp" #:normal-text #:fontsize 2 "]"))))
1114 bracketp = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 2 "[" #:hspace 0.2 #:dynamic "p" #:normal-text #:fontsize 2 "]"))))
1116 whiteoutp = #(make-dynamic-script (markup #:whiteout #:pad-markup 0.5 #:dynamic "p"))
1117 whiteoutf = #(make-dynamic-script (markup #:whiteout #:pad-markup 0.5 #:dynamic "f"))
1118 whiteoutff = #(make-dynamic-script (markup #:whiteout #:pad-markup 0.25 #:dynamic "ff"))
1121 % cresc = #(make-music 'CrescendoEvent 'span-direction START 'crescendoSpanner 'text 'crescendoText "cresc.")
1122 % endcresc =  #(make-span-event 'CrescendoEvent STOP)
1123 % dim = #(make-music 'DecrescendoEvent 'span-direction START 'decrescendoSpanner 'text 'decrescendoText "dim.")
1124 % enddim =  #(make-span-event 'DecrescendoEvent STOP)
1125 % decresc = #(make-music 'DecrescendoEvent 'span-direction START 'decrescendoSpanner 'text 'decrescendoText "decresc.")
1126 % enddecresc =  #(make-span-event 'DecrescendoEvent STOP)
1128 % setCresc = {}
1129 % setDecresc = {}
1130 % setDim = {}
1131 cresc = #(make-music 'CrescendoEvent 'span-direction START
1132                      'span-type 'text 'span-text "cresc.")
1133 dim = #(make-music 'DecrescendoEvent 'span-direction START
1134                    'span-type 'text 'span-text "dim.")
1135 decresc = #(make-music 'DecrescendoEvent 'span-direction START
1136                        'span-type 'text 'span-text "decresc.")
1138 % newOrOldClef = #(define-music-function (parser location new old ) (string? string?)
1139 %     (if (ly:get-option 'old-clefs) #{ \clef $old #} #{ \clef $new #})
1140 % )
1144 %%% Thanks to "Gilles THIBAULT" <gilles.thibault@free.fr>, there is a way
1145 %   to remove also the fermata from R1-\fermataMarkup: By filtering the music
1146 %   and removing the corresponding events.
1147 %   Documented as an LSR snippet: http://lsr.dsi.unimi.it/LSR/Item?id=372
1148 #(define (filterOneEventsMarkup event)
1149 ( let ( (eventname (ly:music-property  event 'name)) )
1150  (not
1151   (or     ;; add here event name you do NOT want
1152    (eq? eventname 'MultiMeasureTextEvent)
1153    (eq? eventname 'AbsoluteDynamicEvent)
1154    (eq? eventname 'TextScriptEvent)
1155    (eq? eventname 'ArticulationEvent)
1156    (eq? eventname 'CrescendoEvent)
1157    (eq? eventname 'DecrescendoEvent)
1158   )
1162 filterArticulations = #(define-music-function (parser location music) (ly:music?)
1163   (music-filter filterOneEventsMarkup music)
1170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1171 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1172 %%%%%   Tempo markings
1173 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1174 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1178 rit = \markup {\italic "rit."}
1179 atempo = \markup {\italic "a tempo"}
1180 pocorit = \markup {\italic "poco rit."}
1181 ppmosso = \markup {\italic "poco più mosso"}
1182 pizz = \markup {\italic "pizz."}
1183 arco = \markup {\italic "arco"}
1184 perd = \markup {\italic "perdend."}
1189 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1190 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1191 %%%%%   REST COMBINATION
1192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1193 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1197 %% REST COMBINING, TAKEN FROM http://lsr.dsi.unimi.it/LSR/Item?id=336
1199 %% Usage:
1200 %%   \new Staff \with {
1201 %%     \override RestCollision #'positioning-done = #merge-rests-on-positioning
1202 %%   } << \somevoice \\ \othervoice >>
1203 %% or (globally):
1204 %%   \layout {
1205 %%     \context {
1206 %%       \Staff
1207 %%       \override RestCollision #'positioning-done = #merge-rests-on-positioning
1208 %%     }
1209 %%   }
1211 %% Limitations:
1212 %% - only handles two voices
1213 %% - does not handle multi-measure/whole-measure rests
1215 #(define (rest-score r)
1216   (let ((score 0)
1217   (yoff (ly:grob-property-data r 'Y-offset))
1218   (sp (ly:grob-property-data r 'staff-position)))
1219     (if (number? yoff)
1220   (set! score (+ score 2))
1221   (if (eq? yoff 'calculation-in-progress)
1222       (set! score (- score 3))))
1223     (and (number? sp)
1224    (<= 0 2 sp)
1225    (set! score (+ score 2))
1226    (set! score (- score (abs (- 1 sp)))))
1227     score))
1229 #(define (merge-rests-on-positioning grob)
1230   (let* ((can-merge #f)
1231    (elts (ly:grob-object grob 'elements))
1232    (num-elts (and (ly:grob-array? elts)
1233       (ly:grob-array-length elts)))
1234    (two-voice? (= num-elts 2)))
1235     (if two-voice?
1236   (let* ((v1-grob (ly:grob-array-ref elts 0))
1237          (v2-grob (ly:grob-array-ref elts 1))
1238          (v1-rest (ly:grob-object v1-grob 'rest))
1239          (v2-rest (ly:grob-object v2-grob 'rest)))
1240     (and
1241      (ly:grob? v1-rest)
1242      (ly:grob? v2-rest)
1243      (let* ((v1-duration-log (ly:grob-property v1-rest 'duration-log))
1244       (v2-duration-log (ly:grob-property v2-rest 'duration-log))
1245       (v1-dot (ly:grob-object v1-rest 'dot))
1246       (v2-dot (ly:grob-object v2-rest 'dot))
1247       (v1-dot-count (and (ly:grob? v1-dot)
1248              (ly:grob-property v1-dot 'dot-count -1)))
1249       (v2-dot-count (and (ly:grob? v2-dot)
1250              (ly:grob-property v2-dot 'dot-count -1))))
1251        (set! can-merge
1252        (and
1253         (number? v1-duration-log)
1254         (number? v2-duration-log)
1255         (= v1-duration-log v2-duration-log)
1256         (eq? v1-dot-count v2-dot-count)))
1257        (if can-merge
1258      ;; keep the rest that looks best:
1259      (let* ((keep-v1? (>= (rest-score v1-rest)
1260               (rest-score v2-rest)))
1261       (rest-to-keep (if keep-v1? v1-rest v2-rest))
1262       (dot-to-kill (if keep-v1? v2-dot v1-dot)))
1263        ;; uncomment if you're curious of which rest was chosen:
1264        ;;(ly:grob-set-property! v1-rest 'color green)
1265        ;;(ly:grob-set-property! v2-rest 'color blue)
1266        (ly:grob-suicide! (if keep-v1? v2-rest v1-rest))
1267        (if (ly:grob? dot-to-kill)
1268            (ly:grob-suicide! dot-to-kill))
1269        (ly:grob-set-property! rest-to-keep 'direction 0)
1270        (ly:rest::y-offset-callback rest-to-keep)))))))
1271     (if can-merge
1272   #t
1273   (ly:rest-collision::calc-positioning-done grob))))
1279 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1280 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1281 %%%%%   TABLE OF CONTENTS
1282 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1283 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1286 contentsTitle = "Inhalt / Contents"
1288 \paper {
1289   tocTitleMarkup = \markup \fill-line{
1290     \null
1291     \column {
1292       \override #(cons 'line-width (* 7 cm))
1293       \line{ \fill-line {\piece-title {\contentsTitle} \null }}
1294       \hspace #1
1295     }
1296     \null
1297   }
1298   tocItemMarkup = \markup \fill-line {
1299     \null
1300     \column {
1301       \override #(cons 'line-width (* 7 cm ))
1302       \line { \fill-line{\fromproperty #'toc:text \fromproperty #'toc:page }}
1303     }
1304     \null
1305   }
1309 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1310 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1311 %%%%%   TITLE PAGE / HEADER
1312 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1313 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1315 #(define-markup-command (when-property layout props symbol markp) (symbol? markup?)
1316   (if (chain-assoc-get symbol props)
1317       (interpret-markup layout props markp)
1318       (ly:make-stencil '()  '(1 . -1) '(1 . -1))))
1320 #(define-markup-command (vspace layout props amount) (number?)
1321   "This produces a invisible object taking vertical space."
1322   (let ((amount (* amount 3.0)))
1323     (if (> amount 0)
1324         (ly:make-stencil "" (cons -1 1) (cons 0 amount))
1325         (ly:make-stencil "" (cons -1 1) (cons amount amount)))))
1329 titlePageMarkup = \markup \abs-fontsize #10 \when-property #'header:title \column {
1330     \vspace #4
1331     \fill-line { \fontsize #8 \fromproperty #'header:composer }
1332     \vspace #1
1333     \fill-line { \fontsize #8 \fromproperty #'header:poet }
1334     \vspace #4
1335     \fill-line { \fontsize #10 \bold \fromproperty #'header:titlepagetitle }
1336     \vspace #1
1337     \fontsize #2 \when-property #'header:titlepagesubtitle {
1338       \fill-line { \fromproperty #'header:titlepagesubtitle }
1339       \vspace #1
1340     }
1341     \fill-line { \postscript #"-20 0 moveto 40 0 rlineto stroke" }
1342     \vspace #8
1343     \fill-line { \fontsize #5 \fromproperty #'header:ensemble }
1344     \vspace #0.02
1345     \fill-line { \fontsize #2 \fromproperty #'header:instruments }
1346     \vspace #9
1347     \fill-line { \fontsize #5 \fromproperty #'header:date }
1348     \vspace #1
1349     \fill-line { \fontsize #5 \fromproperty #'header:scoretype }
1350     \vspace #1
1351     \when-property #'header:instrument {
1352       \fill-line { \bold \fontsize #6 \rounded-box \fromproperty #'header:instrument }
1353     }
1354     \vspace #7
1355     \fontsize #2 \when-property #'header:enteredby \override #'(baseline-skip . 3.75) \left-align\center-column {
1356       \fill-line { "Herausgegeben von: / Edited by:"}
1357       \vspace #0.
1358       \fill-line { \fromproperty #'header:enteredby }
1359     }
1360     \fill-line {
1361       \when-property #'header:arrangement \column {
1362         \vspace #8
1363         \fill-line { \fontsize #3 \fromproperty #'header:arrangement }
1364       }
1365     }
1366   \vspace #6
1367   \fill-line { \fromproperty #'header:copyright }
1370 titleHeaderMarkup = \markup {
1371   \override #'(baseline-skip . 3.5)
1372   \column {
1373     \fill-line {
1374       \fromproperty #'header:logo
1375       \override #'(baseline-skip . 4.5) \center-column {
1376         \bold \abs-fontsize #18 \fromproperty #'header:title
1377         \bold \abs-fontsize #12 \fromproperty #'header:subtitle
1378         \abs-fontsize #11 \fromproperty #'header:subsubtitle
1379       }
1380       \bold \abs-fontsize #11 \when-property #'header:instrument \rounded-box \fromproperty #'header:instrument
1381     }
1382     \fill-line {
1383       \with-dimensions #'( 0 . 0) #'( 0 . 1 ) \null
1384     }
1386     \fill-line {
1387             \abs-fontsize #10 \fromproperty #'header:poet
1388             \abs-fontsize #10 \fromproperty #'header:composer
1389     }
1390     \fill-line {
1391             \abs-fontsize #10 \fromproperty #'header:meter
1392             \abs-fontsize #10 \fromproperty #'header:arranger
1393     }
1394   }
1398 titleScoreMarkup = \markup \piece-title \fromproperty #'header:piece
1400 \paper {
1401   scoreTitleMarkup = \titleScoreMarkup
1402   bookTitleMarkup = \titleHeaderMarkup
1407 %%%%%%%%%%%%%% headers and footers %%%%%%%%%%%%%%%%%%%%%%%%%%
1409 #(define (first-score-page layout props arg)
1410   (let* ((label 'first-score-page)
1411          (table (ly:output-def-lookup layout 'label-page-table))
1412          (label-page (and (list? table) (assoc label table)))
1413          (page-number (and label-page (cdr label-page)))
1414         )
1415     (if (eq? (chain-assoc-get 'page:page-number props -1) page-number)
1416       (interpret-markup layout props arg)
1417       empty-stencil)))
1419 #(define no-header-table '())
1420 thisPageNoHeader = #(define-music-function (parser location) ()
1421   (let* ((label (gensym "header")))
1422     (set! no-header-table (cons label no-header-table))
1423     (make-music 'Music
1424       'page-marker #t
1425       'page-label label)))
1428 % TODO: Use the no-header-table!
1429 #(define (is-header-page layout props arg)
1430   (let* ((page-number (chain-assoc-get 'page:page-number props -1))
1431         )
1432     ;(if (and (> page-number 2) (!= page-number 7))
1433     (if (> page-number 1)
1434       (interpret-markup layout props arg)
1435       empty-stencil)))
1437 #(define no-footer-table '())
1438 thisPageNoFooter = #(define-music-function (parser location) ()
1439   (let* ((label (gensym "footer")))
1440     (set! no-footer-table (cons label no-footer-table))
1441     (make-music 'Music
1442       'page-marker #t
1443       'page-label label)))
1445 % TODO: Use the no-footer-table!
1446 #(define (is-footer-page layout props arg)
1447   (let* ((page-number (chain-assoc-get 'page:page-number props -1))
1448          (label 'first-score-page)
1449          (table (ly:output-def-lookup layout 'label-page-table))
1450          (label-page (and (list? table) (assoc label table)))
1451          ;(page-number (and label-page (cdr label-page)))
1452         )
1453     (if (and (> page-number 1))
1454       (interpret-markup layout props arg)
1455       empty-stencil)))
1458 #(define copyright-footer-table '())
1459 thisPageCopyrightFooter = #(define-music-function (parser location) ()
1460   (let* ((label (gensym "copyrightfooter")))
1461     (set! copyright-footer-table (cons label copyright-footer-table))
1462     (make-music 'Music
1463       'page-marker #t
1464       'page-label label)))
1466 #(define copyright-pg 1)
1467 #(define (set-copyright-page page)
1468   (set! copyright-pg page)
1471 % TODO: Use the copyright-footer-table!
1472 #(define (copyright-page layout props arg)
1473     (if (= (chain-assoc-get 'page:page-number props -1) copyright-pg)
1474       (interpret-markup layout props arg)
1475       empty-stencil))
1478 \paper {
1479   oddHeaderMarkup = \markup \fill-line {
1480     %% force the header to take some space, otherwise the
1481     %% page layout becomes a complete mess.
1482     " "
1483     \on-the-fly #is-header-page \fromproperty #'header:title
1484     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1485   }
1486   evenHeaderMarkup = \markup \fill-line {
1487     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1488     \on-the-fly #is-header-page \fromproperty #'header:composer
1489     " "
1490   }
1492   oddFooterMarkup = \markup {
1493     \column {
1494       \fill-line {
1495         %% publisher header field only on title page.
1496         \on-the-fly #first-page \fromproperty #'header:publisher
1497       }
1498       \fill-line {
1499         %% copyright on the first real score page
1500         \on-the-fly #copyright-page \fromproperty #'header:copyright
1501         \on-the-fly #copyright-page \null
1502       }
1503       \fill-line {
1504         %% All other pages get the number of the edition centered
1505         \on-the-fly #is-footer-page \fromproperty #'header:scorenumber
1506       }
1507     }
1508   }
1522 % Interpret the given markup with the header fields added to the props.
1523 % This way, one can re-use the same functions (using fromproperty
1524 % #'header:field) in the header block and as top-level markup.
1526 % This function is originally copied from mark-up-title (file scm/titling.scm),
1527 % which is lilypond's internal function to handle the title markups. I needed
1528 % to replace the scopes and manually add the $defaultheader (which is internally
1529 % done in paper-book.cc before calling mark-up-title. Also, I don't extract the
1530 % markup from the header block, but use the given markup.
1532 % I'm not sure if I really need the page properties in props, too... But I
1533 % suppose it does not hurt, either.
1534 #(define-markup-command (markupWithHeader layout props markup) (markup?)
1535   "Interpret the given markup with the header fields added to the props.
1536    This way, one can re-use the same functions (using fromproperty
1537    #'header:field) in the header block and as top-level markup."
1538   (let* (
1539       ; TODO: If we are inside a score, add the score's local header block, too!
1540       ; Currently, I only use the global header block, stored in $defaultheader
1541       (scopes (list $defaultheader))
1542       (alists (map ly:module->alist scopes))
1544       (prefixed-alist
1545         (map (lambda (alist)
1546           (map (lambda (entry)
1547             (cons
1548               (string->symbol (string-append "header:" (symbol->string (car entry))))
1549               (cdr entry)))
1550             alist))
1551           alists))
1552       (props (append prefixed-alist
1553               props
1554               (layout-extract-page-properties layout)))
1555     )
1556     (interpret-markup layout props markup)
1557   )
1565 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1566 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1567 %%%%%   Equally spacing multiple columns (e.g. for translations)
1568 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1569 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1571 % Credits: Nicolas Sceaux on the lilypond-user mailinglist
1572 #(define-markup-command (columns layout props args) (markup-list?)
1573    (let ((line-width (/ (chain-assoc-get 'line-width props
1574                          (ly:output-def-lookup layout 'line-width))
1575                         (max (length args) 1))))
1576      (interpret-markup layout props
1577        (make-line-markup (map (lambda (line)
1578                                 (markup #:pad-to-box `(0 . ,line-width) '(0 . 0)
1579                                   #:override `(line-width . ,line-width)
1580                                   line))
1581                                args)))))
1585 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1586 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1587 %%%%%   SCORE (HEADER / LAYOUT) SETTINGS
1588 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1589 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1592 startSlashedGraceMusic =  {
1593   \override Stem  #'stroke-style = #"grace"
1596 stopSlashedGraceMusic =  {
1597   \revert Stem #'stroke-style
1600 slashedGrace =
1601 #(def-grace-function startSlashedGraceMusic stopSlashedGraceMusic
1602    (_i "Create slashed graces (slashes through stems, but no slur)from the following music expression"))
1605 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1606 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1607 %%%%%   SCORE (HEADER / LAYOUT) SETTINGS
1608 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1609 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1611 \paper {
1612   footnote-separator-markup = \markup { \fill-line { \override #`(span-factor . 1/4) { \draw-hline } \null }}
1614   left-margin = 2\cm
1615   right-margin = 1.5\cm
1616   line-width = 17.5\cm
1617 %   bottom-margin = 1.5\cm
1618   top-margin = 0.7\cm
1619 %   after-title-space = 0.5\cm
1620   ragged-right = ##f
1621   ragged-last = ##f
1622   ragged-bottom = ##f
1623   ragged-last-bottom = ##f
1625 \layout {
1626   \context {
1627     \ChoirStaff
1628     % If only one non-empty staff in a system exists, still print the backet
1629     \override SystemStartBracket #'collapse-height = #1
1630     \consists "Instrument_name_engraver"
1631     \consists "Keep_alive_together_engraver"
1632   }
1633   \context {
1634     \StaffGroup
1635     % If only one non-empty staff in a system exists, still print the backet
1636     \override SystemStartBracket #'collapse-height = #1
1637     \consists "Instrument_name_engraver"
1638   }
1639   \context {
1640     \GrandStaff
1641     \override SystemStartBracket #'collapse-height = #1
1642     \consists "Instrument_name_engraver"
1643   }
1644   \context {
1645     \FiguredBass
1646 %     \override VerticalAxisGroup #'keep-fixed-while-stretching = ##t
1647 %     \override VerticalAxisGroup #'minimum-Y-extent  = #'(0 . 1) % TODO: Removed
1648     \override VerticalAxisGroup #'padding = #0
1649   }
1650   \context {
1651     \Score
1652     % Force multi-measure rests to be written as one span
1653     \override MultiMeasureRest #'expand-limit = #3
1654     skipBars = ##t
1655     autoBeaming = ##f
1656 %     \override Hairpin #'to-barline = ##f
1657 %     \override BarNumber #'break-visibility = #end-of-line-invisible
1658 %     \override BarNumber #'self-alignment-X = #0
1659 %     barNumberVisibility = #(every-nth-bar-number-visible 5)
1660     \override CombineTextScript #'avoid-slur = #'outside
1661     \override DynamicTextSpanner #'dash-period = #-1.0
1662     \override InstrumentSwitch #'font-size = #-1
1664     % Rest collision
1665     \override RestCollision #'positioning-done = #merge-rests-on-positioning
1666     % Auto-Accidentals: Use modern-cautionary style...
1667     extraNatural = ##f
1668     % Accidental rules (the rule giving the most accidentals wins!)
1669     % -) Reset accidentals at each barline -> accs not in key sig will always be printed
1670     % -) Same octave accidentals are remembered for two measures -> cancellation
1671     % -) other octave accidentals are remembered for next measure -> cancellation
1672     autoAccidentals = #`(Staff  ,(make-accidental-rule 'same-octave 0)
1673                                 ,(make-accidental-rule 'any-octave 0)
1674                                 ,(make-accidental-rule 'any-octave 1)
1675                                 ,(make-accidental-rule 'same-octave 2))
1676     % No auto-cautionaries, we always use autoAccidentals!
1677 %     autoCautionaries = #`(Staff ,(make-accidental-rule 'any-octave 0)
1678 %                                 ,(make-accidental-rule 'same-octave 1))
1679     printKeyCancellation = ##t
1680     quotedEventTypes = #'(StreamEvent)
1681     quotedCueEventTypes = #'(
1682       rhythmic-event
1683       tie-event
1684       beam-event
1685       tuplet-span-event
1686       tremolo-event
1687       glissando-event
1688       harmonic-event
1689       repeat-tie-event
1690       articulation-event
1691       slur-event
1692       trill-span-event
1693       tremolo-span-event
1694     )
1695     implicitBassFigures = #'(0 100)
1696   }
1697   \context {
1698     \Staff
1699     \RemoveEmptyStaves
1700   }
1704 ts = ^\markup{"t.s."}
1705 tt = ^\markup{"Tutti"}
1706 solo = ^\markup{"Solo"}
1707 tutti = ^\markup{"Tutti"}
1708 bracketts = ^\markup{"[Solo]"}
1709 brackettt = ^\markup{"[Tutti]"}
1710 bracketsolo = ^\markup{"[Solo]"}
1712 sottovoce = \markup "sotto voce"
1714 dashedSlur = -\tweak #'dash-definition #'((0 1 0.4 0.75))(
1715 dashedTie = -\tweak #'dash-definition #'((0 1 0.4 0.75))~
1717 divisi = #(define-music-function (parser location vc1 vc2) (ly:music? ly:music?)
1719   << { \voiceOne $vc1 \oneVoice} \context Voice = "divisi2" { \voiceTwo $vc2 } >>
1723 #(define twoVoice divisi)
1725 #(define-public (bracket-stencils grob)
1726   (let ((lp (grob-interpret-markup grob (markup #:fontsize 3.5 #:translate (cons -0.3 -0.5) "[")))
1727         (rp (grob-interpret-markup grob (markup #:fontsize 3.5 #:translate (cons -0.3 -0.5) "]"))))
1728     (list lp rp)))
1730 bracketify = #(define-music-function (parser loc arg) (ly:music?)
1731    (_i "Tag @var{arg} to be parenthesized.")
1733   \once \override ParenthesesItem #'stencils = #bracket-stencils
1734   \parenthesize $arg
1739 #(define-markup-command (hat layout props arg) (markup?)
1740   "Draw a hat above the given string @var{arg}."
1741   (interpret-markup layout props (markup #:combine #:raise 1.5 "^" arg)))
1745 smallFlageolet =
1746 #(let ((m (make-music 'ArticulationEvent
1747                       'articulation-type "flageolet")))
1748    (ly:music-set-property! m 'tweaks
1749      (acons 'font-size -2
1750        (ly:music-property m 'tweaks)))
1751   m)
1754 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1755 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1756 %%%%%   LICENSE TEXTS
1757 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1758 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1760 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" }}
1761 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" }}
1762 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" }}
1763 LicenseNoRestrictions = \markup{\line {Die Ausgabe darf kopiert und ohne Einschränkungen aufgeführt werden. / May be copied and performed without restriction.}}
1765 \include "sceaux_clef-key.ily"
1768 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1769 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1770 %%%%%   VARIOUS
1771 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1772 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1774 startUnremovableSection = \set Staff.keepAliveInterfaces =
1775  #'(rhythmic-grob-interface
1776     rest-interface
1777     lyric-interface
1778     percent-repeat-item-interface
1779     percent-repeat-interface
1780     stanza-number-interface)
1782 endUnremovableSection = \unset Staff.keepAliveInterfaces
1785 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1786 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1787 %%%%%   EDITORIAL ANNOTATIONS
1788 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1789 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1791 #(define-public (editorial-bracket-stencil stil padding widen)
1792 "Add brackets for editorial annoations around STIL, producing a new stencil."
1793 (let* ((axis Y)
1794        (other-axis (lambda (a) (remainder (+ a 1) 2)))
1795        (ext (interval-widen (ly:stencil-extent stil axis) widen))
1796        (thick 0.15)
1797        (protrusion 0.3)
1798        (lb (ly:bracket axis ext thick protrusion))
1799        (rb (ly:bracket axis ext thick (- protrusion))))
1800   (set! stil (ly:stencil-combine-at-edge stil (other-axis axis) 1 rb padding))
1801   (set! stil
1802     (ly:stencil-combine-at-edge lb (other-axis axis) 1 stil padding))
1803   stil))
1805 editorialHairpin = \once \override Hairpin     #'stencil = #(lambda (grob) (editorial-bracket-stencil (ly:hairpin::print grob) 0.2 0.55))
1806 editorialDynamic = \once \override DynamicText #'stencil = #(lambda (grob) (editorial-bracket-stencil (ly:text-interface::print grob) 0.2 0.55))
1807 editorialMarkup =  \once \override TextScript  #'stencil = #(lambda (grob) (editorial-bracket-stencil (ly:text-interface::print grob) 0.2 0.55))
1809 % videStart = \mark \markup { \hspace #1 \musicglyph #"scripts.coda"  \with-dimensions #'(0 . 0) #'(0 . 0) \left-align { vi-} }
1810 videStart = \mark \markup \halign #-2.3 \concat { \hspace #4.5 \musicglyph #"scripts.coda" \left-align { vi- } }
1811 % videEnd = \notemode {
1812 %   \once \override Score.RehearsalMark #'break-visibility = #begin-of-line-invisible
1813 %   \mark \markup \concat{ \with-dimensions #'(0 . 0) #'(0 . 0) \right-align { -de } \hspace #1 \musicglyph #"scripts.coda" }
1815 videEnd = \notemode {
1816         \once \override Score.RehearsalMark #'break-visibility = #begin-of-line-invisible
1817         \mark \markup \concat{ \right-align { -de } \hspace #1.5 \musicglyph #"scripts.coda" \hspace #4.2 }
1822 \layout {
1823         \context {\Staff
1824                 soloText = #"I"
1825                 soloIIText = #"II"
1826                 aDueText = #"a2"
1827         }
1830 \paper {
1831 %         markup-system-spacing = #'((space . 4) (padding . 2) (stretchability . 20))
1832         markup-system-spacing #'minimum-distance = #0
1833         markup-system-spacing #'space = #4
1834         markup-system-spacing #'padding = #2
1835         markup-system-spacing #'stretchability = #40
1836 %       system-system-spacing = #'((space . 0) (padding . 20) (stretchability . 50))
1837         system-system-spacing #'minimum-distance = #0
1838         system-system-spacing #'space = #5
1839         system-system-spacing #'padding = #2
1840         system-system-spacing #'stretchability = #50
1841         top-system-spacing #'minimum-distance = #0
1842         top-system-spacing #'space = #5
1843         top-system-spacing #'padding = #2
1844         top-system-spacing #'stretchability = #20
1845         last-bottom-spacing #'minimum-distance = #0
1846         last-bottom-spacing #'space = #5
1847         last-bottom-spacing #'padding = #2
1848         last-bottom-spacing #'stretchability = #20
1850         score-markup-spacing #'space = #5
1851         score-markup-spacing #'stretchability = #50
1853         markup-markup-spacing #'space = #5
1854         markup-markup-spacing #'stretchability = #30
1856 \layout {
1857         \context { \StaffGroup
1858 %               \override StaffGrouper #'staff-staff-spacing #'space = 5
1859                 \override StaffGrouper #'staff-staff-spacing #'stretchability = #4.5
1860         }
1861         \context { \GrandStaff
1862 %               \override StaffGrouper #'staff-staff-spacing #'space = 5
1863                 \override StaffGrouper #'staff-staff-spacing #'stretchability = #4.5
1864         }
1865         \context { \ChoirStaff
1866 %               \override StaffGrouper #'staff-staff-spacing #'space = 5
1867                 \override StaffGrouper #'staff-staff-spacing #'stretchability = #3
1868         }
1869         \context { \Staff
1870 %               \override StaffGrouper #'staff-staff-spacing #'space = 1
1871                 \override StaffGrouper #'staff-staff-spacing #'stretchability = #4.9
1872         }
1873         \context { \Score
1874 %               \override StaffGrouper #'staff-staff-spacing #'space = 5
1875                 \override StaffGrouper #'staff-staff-spacing #'stretchability = #5
1876         }
1877         \context { \Lyrics
1878                 \override VerticalAxisGroup #'nonstaff-nonstaff-spacing #'minimum-distance = ##f
1879         }
1882   system-system-spacing = #'((space . 12) (minimum-distance . 8) (padding . 1) (stretchability . 60))
1883   score-system-spacing = #'((space . 14) (minimum-distance . 8) (padding . 1) (stretchability . 120))
1884   markup-system-spacing = #'((space . 5) (padding . 0.5) (stretchability . 30))
1885   score-markup-spacing = #'((space . 12) (padding . 0.5) (stretchability . 60))
1886   markup-markup-spacing = #'((space . 1) (padding . 0.5))
1887   top-system-spacing = #'((space . 1) (padding . 1) (minimum-distance . 0))
1888   top-markup-spacing = #'((space . 0) (padding . 1) (minimum-distance . 0))
1889   last-bottom-spacing = #'((space . 1) (padding . 1) (minimum-distance . 0) (stretchability . 30))%}