Properly implement configurable headers/footers
[orchestrallily.git] / orchestrallily.ily
blob0f9e264219b7712be0ec497753265fc238e03451
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:StringEnsembleScoreStructure '(
110   ("FullScore" "StaffGroup" ("VI" "VII" "Va" "Vc" "Cb" "VcB"))
113 #(define oly:fullOrchestraScoreStructure '(
114 ; Part-combined staves for full score
115   ("Fl" "PartCombinedStaff" ("FlI" "FlII"))
116   ("Ob" "PartCombinedStaff" ("ObI" "ObII"))
117   ("Cl" "PartCombinedStaff" ("ClI" "ClII"))
118   ("Fag" "PartCombinedStaff" ("FagI" "FagII"))
119   ("Wd" "StaffGroup" ("Fl" "Ob" "Cl" "Fag" "CFag"))
121   ("Cor" "PartCombinedStaff" ("CorI" "CorII"))
122   ("Tbe" "PartCombinedStaff" ("TbeI" "TbeII"))
123   ("Clni" "PartCombinedStaff" ("ClnoI" "ClnoII"))
124   ("Trb" "PartCombinedStaff" ("TrbI" "TrbII"))
125   ("Br" "StaffGroup" ("Cor" "Tbe" "Clni" "Trb" "Tba"))
127 ; long score; no part-combined staves, but GrandStaves instead
128   ("FlLong" "GrandStaff" ("FlI" "FlII"))
129   ("ObLong" "GrandStaff" ("ObI" "ObII"))
130   ("ClLong" "GrandStaff" ("ClI" "ClII"))
131   ("FagLong" "GrandStaff" ("FagI" "FagII"))
132   ("WdLong" "StaffGroup" ("FlLong" "ObLong" "ClLong" "FagLong" "CFag"))
134   ("CorLong" "GrandStaff" ("CorI" "CorII"))
135   ("TbeLong" "GrandStaff" ("TbeI" "TbeII"))
136   ("ClniLong" "GrandStaff" ("ClnoI" "ClnoII" "ClnoIII"))
137   ("TrbLong" "GrandStaff" ("TrbI" "TrbII" "TrbIII"))
138   ("BrLong" "StaffGroup" ("CorLong" "TbeLong" "ClniLong" "TrbLong" "Tba"))
140 ; Percussion
141   ("Perc" "StaffGroup" ("Tim"))
143 ; Strings, they are the same in long and short full score
144   ("VV" "GrandStaff" ("VI" "VII"))
145   ("Str" "StaffGroup" ("VV" "Va"))
146   ("VceB" "StaffGroup" ("Vc" "Cb" "VcB"))
147   ("FullStr" "StaffGroup" ("VV" "Va" "Vc" "Cb" "VcB"))
149 ; Choral score
150   ("Solo" "SimultaneousMusic" ("SSolo" "ASolo" "TSolo" "BSolo"))
151   ("Ch" "ChoirStaff" ("S" "A" "T" "B"))
152   ("ChoralScore" "SimultaneousMusic" ("Ch"))
153   ("SoloScore" "SimultaneousMusic" ("Solo"))
154   ("SoloChoirScore" "SimultaneousMusic" ("Solo" "Ch"))
156 ; Organ score (inkl. Figured bass)
157   ("BCFb" "FiguredBass" ())
158   ("FiguredBass" "FiguredBass" ())
159   ;("Organ" "SimultaneousMusic" ("BCFb" "O"))
160   ("Continuo" "ParallelVoicesStaff" ("BCFb" "BC" "FiguredBass"))
161   ("RealizedContinuo" "PianoStaff" ("BCRealization" "Continuo"))
163   ("P" "PianoStaff" ("PI" "PII"))
164   ("O" "PianoStaff" ("OI" "OII"))
165   ("OI" "ParallelVoicesStaff" ("OIa" "OIb"))
166   ("OII" "ParallelVoicesStaff" ("OIIa" "OIIb"))
168   ;("Organ" "SimultaneousMusic" ("OGroup" "RealizedContinuo"))
169   ;("BassGroup" "ParallelVoicesStaff" ("Organ" "O" "BC" "VceB"))
170   ("BassGroup" "StaffGroup" ("O" "RealizedContinuo" "Vc" "Cb" "VcB"))
172 ; Full Scores
173   ("FullScore" "SimultaneousMusic" ("Wd" "Br" "Perc" "Str" "SoloChoirScore" "BassGroup"))
174   ("LongScore" "SimultaneousMusic" ("WdLong" "BrLong" "Perc" "Str" "SoloChoirScore" "BassGroup"))
175   ("OriginalScore" "SimultaneousMusic" ("BrLong" "WdLong" "Perc" "Str" "SoloChoirScore" "BassGroup"))
177 ; Piano reduction
178   ;("Piano" "SimultaneousMusic" ("Organ"))
179   ("OrganScore" "SimultaneousMusic" ("ChoralScore" "O"))
180   ("VocalScore" "SimultaneousMusic" ("ChoralScore" "P"))
181   ("Particell"  "SimultaneousMusic" ("ChoralScore" "BassGroup"))
183 ; Full scores: Orchestral score and long score including organ
184   ("ChStrQ" "SimultaneousMusic" ("Str" "Ch" "VceB"))
186 #(define oly:orchestral_score_structure oly:fullOrchestraScoreStructure)
188 #(define (oly:set_score_structure struct)
189   (if (list? struct)
190     (set! oly:orchestral_score_structure struct)
191     (ly:warning (_ "oly:set_score_structure needs an association list as argument!"))
192   )
195 #(define (oly:modify_score_structure entry)
196   (if (list? entry)
197     (set! oly:orchestral_score_structure (assoc-set! oly:orchestral_score_structure  (car entry) (cdr entry)))
198     (ly:warning (_ "oly:modify_score_structure expects a list (\"key\" \"type\" '(children)) as argument!"))))
200 #(define (oly:remove_from_score_structure entry)
201   (if (list? entry)
202     (map oly:remove_from_score_structure entry)
203     (set! oly:orchestral_score_structure (assoc-remove! oly:orchestral_score_structure  entry))))
205 orchestralScoreStructure = #(define-music-function (parser location structure) (list?)
206   (oly:set_score_structure structure)
207   (make-music 'Music 'void #t)
210 #(define oly:voice_types '())
212 #(define (oly:set_voice_types types)
213   (if (list? types)
214     (set! oly:voice_types types)
215     (ly:warning (_ "oly:set_voice_types needs an association list as argument!"))
216   )
219 orchestralVoiceTypes = #(define-music-function (parser location types) (list?)
220   (oly:set_voice_types types)
221   (make-music 'Music 'void #t)
225 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226 % Automatic staff and group generation
227 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
229 % Retrieve all music definitions for the given
230 #(define (oly:get_music_object piece instrument)
231   (namedPieceInstrObject piece instrument "Music")
233 #(define (oly:get_music_objects piece instruments)
234   (filter not-null? (map (lambda (i) (oly:get_music_object piece i)) instruments))
237 % Given a property name and the extensions, either generate the pair to set
238 % the property or an empty list, if no pre-defined variable could be found
239 #(define (oly:generate_property_pair prop piece instr type)
240   (let* ((val (namedPieceInstrObject piece instr type)))
241     (if (not-null? val) (list 'assign prop val) '() )
242   )
245 #(define (oly:staff_type type)
246   (cond
247     ((string? type) (string->symbol type))
248     ((symbol? type) type)
249     (else 'Staff)
250   )
253 #(define (oly:extractPitch music)
254   (let* (
255          (elems  (if (ly:music? music) (ly:music-property music 'elements)))
256          (note   (if (pair? elems) (car elems)))
257          (pitch  (if (ly:music? note) (ly:music-property note 'pitch)))
258         )
259     (if (and (not-null? music) (not (ly:pitch? pitch)))
260       (ly:warning "Unable to interpret as a pitch!")
261     )
262     pitch
263   )
266 #(define (oly:extractTranspositionPitch piece name)
267   (let* (
268          (trpFromPitch (oly:extractPitch (namedPieceInstrObject piece name "TransposeFrom")))
269          (trpToPitch   (oly:extractPitch (namedPieceInstrObject piece name "TransposeTo")))
270         )
271     (if (ly:pitch? trpFromPitch)
272       (if (ly:pitch? trpToPitch)
273         ; Both pitches
274         (ly:pitch-diff trpFromPitch trpToPitch)
275         (ly:pitch-diff trpFromPitch (ly:make-pitch 0 0 0))
276       )
277       (if (ly:pitch? trpToPitch)
278         (ly:pitch-diff (ly:make-pitch 0 0 0) trpToPitch)
279         #f
280       )
281     )
282   )
286 %%=====================================================================
287 %% Extract context modifications for given objects
288 %%---------------------------------------------------------------------
291 % TODO: join these property extractors to avoid code duplication
293 % Generate the properties for the lyrics for piece and instr.
294 % Also check whether we have a modifications object to fech mods from.
295 % return a (possibly empty) list of all assignments.
296 #(define (oly:lyrics_handler_properties piece name lyricsid)
297   (let* (
298          (mods (namedPieceInstrObject piece name (string-append lyricsid "Modifications")))
299          (mod-list (if (not-null? mods) (ly:get-context-mods mods) '()))
300          (mapping '(
301              ;(instrumentName . "InstrumentName")
302              ;(shortInstrumentName . "ShortInstrumentName")
303              ;(midiInstrument . "MidiInstrument")
304             ))
305          (assignments (map
306              (lambda (pr)
307                  (oly:generate_property_pair (car pr) piece name (cdr pr))
308              )
309              mapping))
310          (olyprops (filter not-null? assignments))
311          (props (append mod-list olyprops))
312         )
313     props
314   )
317 % Generate the properties for the voice for piece and instr.
318 % Also check whether we have a modifications object to fech mods from.
319 % return a (possibly empty) list of all assignments.
320 #(define (oly:voice_handler_properties piece name)
321   (let* (
322          (mods (namedPieceInstrObject piece name "VoiceModifications"))
323          (mod-list (if (not-null? mods) (ly:get-context-mods mods) '()))
324          (mapping '(
325              ;(instrumentName . "InstrumentName")
326              ;(shortInstrumentName . "ShortInstrumentName")
327              ;(midiInstrument . "MidiInstrument")
328             ))
329          (assignments (map
330              (lambda (pr)
331                  (oly:generate_property_pair (car pr) piece name (cdr pr))
332              )
333              mapping))
334          (olyprops (filter not-null? assignments))
335          (props (append mod-list olyprops))
336         )
337     props
338   )
341 % Generate the properties for the staff for piece and instr. Typically, these
342 % are the instrument name and the short instrument name (if defined).
343 % Also check whether we have a modifications object to fech mods from.
344 % return a (possibly empty) list of all assignments.
345 #(define (oly:staff_handler_properties piece instr)
346   (let* (
347          (mods (namedPieceInstrObject piece instr "StaffModifications"))
348          (mod-list (if (not-null? mods) (ly:get-context-mods mods) '()))
349          (mapping '(
350               (instrumentName . "InstrumentName")
351               (shortInstrumentName . "ShortInstrumentName")
352               (midiInstrument . "MidiInstrument")
353             ))
354          (assignments (map
355              (lambda (pr)
356                  (oly:generate_property_pair (car pr) piece instr (cdr pr))
357              )
358              mapping))
359          (olyprops (filter not-null? assignments))
360          (props (append mod-list olyprops))
361         )
362     props
363   )
369 %%=====================================================================
370 %% Extract contents for voices
371 %%---------------------------------------------------------------------
373 #(define (oly:musiccontent_for_voice parser piece name music additional)
374   (let* ((musiccontent additional))
376     ; Append the settings, key and clef (if defined)
377     (map
378       (lambda (type)
379         (let* ((object (namedPieceInstrObject piece name type)))
380           (if (ly:music? object)
381             (set! musiccontent (append musiccontent (list (ly:music-deep-copy object))))
382             (if (not-null? object) (ly:warning (_ "Wrong type (no ly:music) for ~S for instrument ~S in piece ~S") type name piece))
383           )
384         )
385       )
386       ; TODO: Does the "Tempo" work here???
387       '("Settings" "Key" "Clef" "TimeSignature" "ExtraSettings";"Tempo"
388       )
389     )
391     (if (ly:music? music)
392       (begin
393         (set! musiccontent (make-simultaneous-music (append musiccontent (list music))))
394         ;(ly:message "Generating staff for ~a" name)
395         (let* ((trpPitch (oly:extractTranspositionPitch piece name)))
396           (if (ly:pitch? trpPitch)
397             (set! musiccontent (ly:music-transpose musiccontent trpPitch))
398           )
399         )
400         musiccontent
401       )
402       ; For empty music, return empty
403       '()
404     )
405   )
410 %%=====================================================================
411 %% create Lyrics
412 %%---------------------------------------------------------------------
415 #(define (oly:lyrics_create_single_context parser piece name voicename lyricsid)
416   ; If we have lyrics, create a lyrics context containing LyricCombineMusic
417   ; and add that as second element to the staff's elements list...
418   ; Also add possibly configured LyricsModifications
419   (let* ((id (string-append "Lyrics" lyricsid))
420          (lyricsmods (oly:lyrics_handler_properties piece name id))
421          (lyrics (namedPieceInstrObject piece name id))
422          (ctx (if (ly:music? lyrics)
423                   (context-spec-music (make-music 'LyricCombineMusic
424                                                   'element lyrics
425                                                   'associated-context voicename)
426                                       'Lyrics
427                                       (oly:generate_object_name piece name id))
428                   '())))
429     (if (and (not-null? lyricsmods) (not-null? ctx))
430       (set! (ly:music-property ctx 'property-operations) lyricsmods)
431     )
432     ctx
433   )
436 #(define (oly:lyrics_create_contexts parser piece name voicename)
437   (filter not-null?
438     (map (lambda (str)
439                  (oly:lyrics_create_single_context parser piece name voicename str))
440          (list "" "I" "II" "III"  "IV" "V" "VI"))))
443 %%=====================================================================
444 %% Voice handling
445 %%---------------------------------------------------------------------
448 #(define (oly:voice_handler_internal parser piece name type music)
449   (if (ly:music? music)
450     (let* (
451            (voicename    (oly:generate_object_name piece name "Voice" ))
452            (lyrics       (oly:lyrics_create_contexts parser piece name voicename))
453            (additional   (if (not-null? lyrics) (list dynamicUp) '()))
454            (musiccontent (oly:musiccontent_for_voice parser piece name music additional))
455            (voicetype    (oly:staff_type type))
456            (voice        (context-spec-music musiccontent voicetype voicename))
457            (voiceprops   (oly:voice_handler_properties piece name))
458           )
459       (if (not-null? voiceprops)
460         (set! (ly:music-property voice 'property-operations) voiceprops)
461       )
462       (cons voice lyrics)
463     )
464     ; For empty music, return empty
465     '()
466   )
469 #(define (oly:voice_handler parser piece name type)
470   (oly:voice_handler_internal parser piece name type (oly:get_music_object piece name)))
473 %%=====================================================================
474 %% Staff/Group handling
475 %%---------------------------------------------------------------------
478 #(define (oly:staff_handler_internal parser piece name type voices)
479   (if (not-null? voices)
480     (let* (
481            (staffname  (oly:generate_staff_name piece name))
482            (stafftype  (oly:staff_type type))
483            (staff      (make-simultaneous-music voices))
484            (propops    (oly:staff_handler_properties piece name))
485           )
486       (case stafftype
487         ((SimultaneousMusic ParallelMusic) #f)
488         (else (set! staff (context-spec-music staff stafftype staffname)))
489       )
490       (if (not-null? propops)
491         (set! (ly:music-property staff 'property-operations) propops)
492       )
493       staff
494     )
495     ; For empty music, return empty
496     '()
497   )
500 #(define (oly:staff_handler parser piece name type children)
501   (let* ((c (if (not-null? children) children (list name)))
502          (voices (apply append (map (lambda (v) (oly:create_voice parser piece v)) c)) )
503         )
504     (if (not-null? voices)
505       (oly:staff_handler_internal parser piece name type voices)
506       '()
507     )
508   )
511 #(define (oly:devnull_handler parser piece name type children)
512   (oly:voice_handler parser piece name type)
515 #(define (oly:parallel_voices_staff_handler parser piece name type children)
516   (let* (
517          (voices (map (lambda (i) (oly:create_voice parser piece i)) children))
518          ; get the list of non-empty voices and flatten it!
519          (nonemptyvoices (apply append (filter not-null? voices)))
520         )
521     (if (not-null? nonemptyvoices)
522       (oly:staff_handler_internal parser piece name "Staff" nonemptyvoices)
523       '()
524     )
525   )
528 #(define (oly:remove-with-tag tag music)
529   (if (ly:music? music)
530       (music-filter
531         (lambda (m)
532           (let* ((tags (ly:music-property m 'tags))
533                  (res (memq tag tags)))
534             (not res)))
535         music)
536       music))
538 % Remove all music tagged a not-part-combine
539 #(define (oly:remove-non-part-combine-events music)
540   (oly:remove-with-tag 'non-partcombine music))
542 #(define (oly:part_combined_staff_handler parser piece name type children)
543   (let* ((rawmusic (map (lambda (c) (oly:musiccontent_for_voice parser piece name (oly:get_music_object piece c) '())) children))
544          (filteredmusic (map (lambda (m) (oly:remove-non-part-combine-events m)) rawmusic))
545          (music (filter not-null? filteredmusic)))
546   (cond
547       ((and (pair? music) (ly:music? (car music)) (not-null? (cdr music)) (ly:music? (cadr music)))
548           ;(ly:message "Part-combine with two music expressions")
549           (oly:staff_handler_internal parser piece name "Staff" (list (make-part-combine-music parser music))))
550       ((null? music)
551           ;;(ly:warning "Part-combine without any music expressions")
552           '())
553       ; exactly one is a music expression, simply use that by joining
554       ((list? music)
555           ;;(ly:message "Part-combine with only one music expressions")
556           (oly:staff_handler_internal parser piece name "Staff" (list (apply append music))))
557       (else
558           ;(ly:message "make_part_combined_staff: ~S ~S ~a" piece instr instruments)
559           '() )
560     )
561   )
564 % Figured bass is a special case, as it can be voice- or staff-type. When
565 % given as a staff type, simply call the voice handler, instead
567 #(define (oly:figured_bass_staff_handler parser piece name type children)
568   (let* ((c (if (not-null? children) children (list name)))
569          (voice  (oly:voice_handler parser piece (car c) type)))
570     (if (pair? voice) (car voice) ())
571   )
574 #(define (flatten lst)
575   (define (f remaining result)
576     (cond
577       ((null? remaining) result)
578       ((pair? (car remaining)) (f (cdr remaining) (f (car remaining) result)))
579       (else (f (cdr remaining) (cons (car remaining) result)))))
580   (reverse! (f lst '())))
582 #(define (oly:staff_group_handler parser piece name type children)
583   (let* (
584          (staves (flatten (map (lambda (i) (oly:create_staff_or_group parser piece i)) children)))
585          (nonemptystaves (filter not-null? staves))
586         )
587     (if (not-null? nonemptystaves)
588       (let* (
589              (musicexpr (if (= 1 (length nonemptystaves))
590                           (car nonemptystaves)
591                           (make-simultaneous-music nonemptystaves)))
592              (groupname (oly:generate_staff_name piece name))
593              (grouptype (oly:staff_type type))
594              (group     musicexpr)
595              (propops   (oly:staff_handler_properties piece name))
596             )
597         (case grouptype
598           ((SimultaneousMusic ParallelMusic) #f)
599           (else (set! group (context-spec-music group grouptype groupname)))
600         )
601         (if (pair? propops)
602           (set! (ly:music-property group 'property-operations) propops))
603         group
604       )
605       ; Return empty list if no staves are generated
606       '()
607     )
608   )
611 #(define (oly:create_voice parser piece name)
612   (let* ( (voice (namedPieceInstrObject piece name "Voice"))
613           (type (assoc-ref oly:voice_types name)) )
614     (if (not-null? voice)
615       ; Explicit voice variable, use that
616       voice
618       (if (not type)
619         ; No entry in structure found => simple voice
620         (oly:voice_handler parser piece name "Voice")
621         ; Entry found in structure => use the handler for the given type
622         (let* (
623                (voicetype (car type))
624                (handler (assoc-ref oly:voice_handlers voicetype))
625               )
626           (if handler
627             ((primitive-eval handler) parser piece name voicetype)
628             (begin
629               (ly:warning "No handler found for voice type ~a, using default voice handler" voicetype)
630               (oly:voice_handler parser piece name voicetype)
631             )
632           )
633         )
634       )
635     )
636   )
639 #(define (oly:create_staff_or_group parser piece name)
640   (let* ( (staff (namedPieceInstrObject piece name "Staff"))
641           (type_from_structure (assoc-ref oly:orchestral_score_structure name)) )
642     ;(if (not-null? staff)
643     ;  (ly:message "Found staff variable for instrument ~a in piece ~a"  instr piece)
644     ;  (ly:message "Staff variable for instrument ~a in piece ~a NOT FOUND"  instr piece)
645     ;)
646     (if (not-null? staff)
647       ; Explicit staff variable, use that
648       staff
650       (if (not (list? type_from_structure))
651         ; No entry in structure found => simple staff
652         (oly:staff_handler parser piece name "Staff" '())
654         ; Entry found in structure => use the handler for the given type
655         (let* ((type (car type_from_structure))
656                (handler (assoc-ref oly:staff_handlers type))
657                (children (cadr type_from_structure))
658               )
659           (if handler
660             ((primitive-eval handler) parser piece name type children)
661             (begin
662               (ly:warning "No handler found for staff type ~a, using default staff handler" type)
663               (oly:staff_handler parser piece name type children)
664             )
665           )
666         )
667       )
668     )
669   )
672 #(define (oly:dynamics_handler parser piece name type children)
673   (oly:voice_handler parser piece name type)
677 %%=====================================================================
678 %% Handler definitions
679 %%---------------------------------------------------------------------
681 #(define oly:staff_handlers
682   (list
683     ; staff group types
684     '("GrandStaff" . oly:staff_group_handler )
685     '("PianoStaff" . oly:staff_group_handler )
686     '("ChoirStaff" . oly:staff_group_handler )
687     '("StaffGroup" . oly:staff_group_handler )
688     '("ParallelMusic" . oly:staff_group_handler )
689     '("SimultaneousMusic" . oly:staff_group_handler )
690     ; staff types
691     '("Staff" . oly:staff_handler )
692     '("DrumStaff" . oly:staff_handler )
693     '("RhythmicStaff" . oly:staff_handler )
694     '("TabStaff" . oly:staff_handler )
695     '("GregorianTranscriptionStaff" . oly:staff_handler )
696     '("MensuralStaff" . oly:staff_handler )
697     '("VaticanaStaff" . oly:staff_handler )
698     ; staves with multiple voices
699     '("PartCombinedStaff" . oly:part_combined_staff_handler )
700     '("ParallelVoicesStaff" . oly:parallel_voices_staff_handler )
701     ; special cases: Figured bass can be staff or voice type!
702     '("FiguredBass" . oly:figured_bass_staff_handler )
703     ; Devnull is like a staff, only that it doesn't craete output
704     '("Devnull" . oly:devnull_handler )
705     '("Dynamics" . oly:dynamics_handler )
706   )
709 #(define oly:voice_handlers
710   (list
711     ; voice types
712     '("Voice" . oly:voice_handler )
713     '("CueVoice" . oly:voice_handler )
714     '("DrumVoice" . oly:voice_handler )
715     '("FiguredBass" . oly:voice_handler )
716     '("GregorianTranscriptionVoice" . oly:voice_handler )
717     '("NoteNames" . oly:voice_handler )
718     '("TabVoice" . oly:voice_handler )
719     '("VaticanaVoice" . oly:voice_handler )
720   )
724 #(define (oly:register_staff_type_handler type func)
725 ;  (ly:message "Registering staff handler ~a for type ~a" func type)
726   (set! oly:staff_handlers (assoc-set! oly:staff_handlers type func))
729 #(define (oly:register_voice_type_handler type func)
730 ;  (ly:message "Registering voice type handler ~a for type ~a" func type)
731   (set! oly:voice_handlers (assoc-set! oly:voice_handlers type func))
734 % handlers for deprecated API
735 #(oly:register_staff_type_handler 'StaffGroup 'oly:staff_group_handler)
736 #(oly:register_staff_type_handler 'GrandStaff 'oly:staff_group_handler)
737 #(oly:register_staff_type_handler 'PianoStaff 'oly:staff_group_handler)
738 #(oly:register_staff_type_handler 'ChoirStaff 'oly:staff_group_handler)
739 #(oly:register_staff_type_handler 'Staff 'oly:staff_handler )
740 #(oly:register_staff_type_handler 'ParallelMusic 'oly:staff_group_handler)
741 #(oly:register_staff_type_handler 'SimultaneousMusic 'oly:staff_group_handler)
742 #(oly:register_staff_type_handler #t 'oly:part_combined_staff_handler )
743 #(oly:register_staff_type_handler #f 'oly:parallel_voices_staff_handler )
747 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
748 % Automatic score generation
749 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
751 #(define oly:score_handler add-score)
752 #(define oly:music_handler add-music)
753 #(define oly:text_handler add-text)
756 % TODO: deprecate
757 setUseBook = #(define-music-function (parser location usebook) (boolean?)
758   (ly:warning "\\setUseBook has been deprecated! Books are now automatically handled without any hacks")
759   (make-music 'Music 'void #t)
763 % Two functions to handle midi-blocks: Either don't set one, or set an empty
764 % one so that MIDI is generated
765 #(define (oly:set_no_midi_block score) '())
766 #(define (oly:set_midi_block score)
767   (let* ((midiblock (if (defined? '$defaultmidi)
768                         (ly:output-def-clone $defaultmidi)
769                         (ly:make-output-def))))
770     (ly:output-def-set-variable! midiblock 'is-midi #t)
771     (ly:score-add-output-def! score midiblock)
772   )
775 % \setCreateMidi ##t/##f sets a flag to determine wheter MIDI output should
776 % be generated
777 #(define oly:apply_score_midi oly:set_no_midi_block)
778 setCreateMIDI = #(define-music-function (parser location createmidi) (boolean?)
779   (if createmidi
780     (set! oly:apply_score_midi oly:set_midi_block)
781     (set! oly:apply_score_midi oly:set_no_midi_block)
782   )
783   (make-music 'Music 'void #t)
787 % Two functions to handle layout-blocks: Either don't set one, or set an empty
788 % one so that a PDF is generated
789 #(define (oly:set_no_layout_block score) '())
790 #(define (oly:set_layout_block score)
791   (let* ((layoutblock (if (defined? '$defaultlayout)
792                         (ly:output-def-clone $defaultlayout)
793                         (ly:make-output-def))))
794     (ly:output-def-set-variable! layoutblock 'is-layout #t)
795     (ly:score-add-output-def! score layoutblock)
796   )
799 % \setCreatePDF ##t/##f sets a flag to determine wheter PDF output should
800 % be generated
801 #(define oly:apply_score_layout oly:set_no_layout_block)
802 setCreatePDF = #(define-music-function (parser location createlayout) (boolean?)
803   (if createlayout
804     (set! oly:apply_score_layout oly:set_layout_block)
805     (set! oly:apply_score_layout oly:set_no_layout_block)
806   )
807   (make-music 'Music 'void #t)
811 % Set the piece title in a new header block.
812 #(define (oly:set_piece_header score piecename)
813   (if (not-null? piecename)
814     (let* ((header (make-module)))
815       (module-define! header 'piece piecename)
816       (ly:score-set-header! score header)
817     )
818   )
822 % post-filter functions. By default, no filtering is done. However,
823 % for the *NoCues* function, the cue notes should be killed
824 keepcuefilter = #(define-music-function (parser location music) (ly:music?)
825   ((ly:music-function-extract removeWithTag) parser location 'non-cued music))
826 removecuefilter = #(define-music-function (parser location music) (ly:music?)
827   ((ly:music-function-extract removeWithTag) parser location 'cued ((ly:music-function-extract killCues) parser location music)))
830 #(define (oly:create-toc-file layout pages)
831   (let* ((label-table (ly:output-def-lookup layout 'label-page-table))
832          ;; The page numbers are pages counts in the pdf file, not visible page number!
833          ;; So we have to offset them if the first page is not page #1
834          (first-page-offset (1- (ly:output-def-lookup layout 'first-page-number))))
835     (if (not (null? label-table))
836       (let* ((format-line (lambda (toc-item)
837              (let* ((label (car toc-item))
838                     (text  (caddr toc-item))
839                     (label-page (and (list? label-table)
840                                      (assoc label label-table)))
841                     (page (and label-page (cdr label-page))))
842                (format #f "~a, section, 1, {~a}, ~a" (- page first-page-offset) text label))))
843              (formatted-toc-items (map format-line (toc-items)))
844              (whole-string (string-join formatted-toc-items ",\n"))
845              (output-name (ly:parser-output-name parser))
846              (outfilename (format "~a.toc" output-name))
847              (outfile (open-output-file outfilename)))
848         (if (output-port? outfile)
849             (display whole-string outfile)
850             (ly:warning (_ "Unable to open output file ~a for the TOC information") outfilename))
851         (close-output-port outfile)))))
854 #(define-public (oly:add-toc-item parser markup-symbol text)
855   (oly:music_handler parser (add-toc-item! markup-symbol text)))
858 #(define (oly:add-score parser score piecename)
859   (if (not-null? piecename)
860     (oly:add-toc-item parser 'tocItemMarkup piecename))
861   (oly:score_handler parser score)
863 % The helper function to build a score.
864 #(define (oly:createScoreHelper parser location piece children func)
865   (let* (
866          (staves    (oly:staff_group_handler parser piece "" "SimultaneousMusic" children))
867          (music     (if (not-null? staves)
868                         ((ly:music-function-extract func) parser location staves)
869                         '()
870                     ))
871          (score     '())
872          (piecename (namedPieceInstrObject piece (car children) "PieceName"))
873          (piecenametacet (namedPieceInstrObject piece (car children) "PieceNameTacet"))
874          (header    '())
875         )
876     (if (null? music)
877       ; No staves, print tacet
878       (begin
879         (if (not-null? piecenametacet) (set! piecename piecenametacet))
880         (if (not-null? piecename)
881           (oly:add-score parser (list (oly:piece-title-markup piecename)) piecename)
882           (ly:warning (_ "No music and no score title found for part ~a and instrument ~a") piece children)
883         )
884       )
885       ; we have staves, apply the piecename to the score and add layout/midi blocks if needed
886       (begin
887         (set! score (scorify-music music parser))
888         (oly:set_piece_header score piecename)
889         (oly:apply_score_midi score)
890         (oly:apply_score_layout score)
891         ; Schedule the score for typesetting
892         (oly:add-score parser score piecename)
893       )
894     )
895   )
896   ; This is a void function, the score has been schedulled for typesetting already
897   (make-music 'Music 'void #t)
900 createVoice = #(define-music-function (parser location piece name) (string? string?)
901   (let* ((vc (oly:create_voice parser piece name)))
902     (make-music 'SimultaneousMusic
903                 'elements vc)))
905 createStaff = #(define-music-function (parser location piece name) (string? string?)
906   (oly:create_staff_or_group parser piece name))
907 createStaffForContents = #(define-music-function (parser location piece name contents) (string? string? ly:music?)
908   (let* ((tstruct (assoc-ref oly:orchestral_score_structure name))
909          (type (if (list? tstruct) (car tstruct) "Staff")))
910     (oly:staff_handler_internal parser piece name type (list contents))))
913 createScore = #(define-music-function (parser location piece children) (string? list?)
914   (oly:createScoreHelper parser location piece children keepcuefilter)
916 createNoCuesScore = #(define-music-function (parser location piece children) (string? list?)
917   (oly:createScoreHelper parser location piece children removecuefilter)
920 createHeadline = #(define-music-function (parser location headline) (string?)
921   (oly:add-toc-item parser 'tocItemMarkup headline)
922   (oly:score_handler parser (list (oly:piece-title-markup headline)))
923   (make-music 'Music 'void #t)
928 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
929 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
930 %%%%%   CUE NOTES
931 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
932 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
934 newInstrument = #(define-music-function (parser location instr) (string?)
936   \set Voice.instrumentCueName = #$(string-join (list "+" instr))
939 cueText = #(define-music-function (parser location instr) (string?)
941   \set Voice.instrumentCueName = $instr
944 cueMarkup = #(define-music-function (parser location instr) (markup?)
946   \set Voice.instrumentCueName = $instr
950 clearCueText = #(define-music-function (parser location) ()
952   \unset Voice.instrumentCueName
956 insertCueText = #(define-music-function (parser location instr) (string?)
957   (if (string-null? instr)
958     #{ \tag #'cued \clearCueText #}
959     #{ \tag #'cued \cueText #$instr #}
962 % generate a cue music section with instrument names
963 % Parameters: \namedCueDuring NameOfQuote CueDirection CueInstrument OriginalInstrument music
964 %                 -) NameOfQuote CueDirection music are the parameters for \cueDuring
965 %                 -) CueInstrument and OriginalInstrument are the displayed instrument names
966 % typical call:
967 % \namedCueDuring #"vIQuote" #UP #"V.I" #"Sop." { R1*3 }
968 %      This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
969 %      the beginning of the cue notes and "Sop." at the end
970 namedCueDuring = #(define-music-function (parser location cuevoice direction instrcue instr cuemusic) (string? number? string? string? ly:music?)
972   \cueDuring #$cuevoice #$direction {
973     \insertCueText #$instrcue
974     $cuemusic
975     \insertCueText #$instr
976   }
979 namedTransposedCueDuring = #(define-music-function (parser location cuevoice direction instrcue instr trans cuemusic) (string? number? string? string? ly:music? ly:music?)
980    #{
981      \transposedCueDuring #$cuevoice #$direction $trans {
982        \insertCueText #$instrcue
983        $cuemusic
984        \insertCueText #$instr
985      }
986    #}
989 % set the cue instrument name and clef
990 setClefCue = #(define-music-function (parser location instr clef)
991                                                      (string? ly:music?)
992    #{
993      \once \override Staff.Clef #'font-size = #-3 $clef
994      \insertCueText $instr
995    #} )
997 % generate a cue music section with instrument names and clef changes
998 % Parameters: \cleffedCueDuring NameOfQuote CueDirection CueInstrument CueClef OriginalInstrument OriginalClef music
999 %                 -) NameOfQuote CueDirection music are the parameters for \cueDuring
1000 %                 -) CueInstrument and OriginalInstrument are the displayed instrument names
1001 %                 -) CueClef and OriginalClef are the clefs for the the cue notes and the clef of the containing voice
1002 % typical call:
1003 % \cleffedCueDuring #"vIQuote" #UP #"V.I" #"treble" #"Basso" #"bass" { R1*3 }
1004 %      This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
1005 %      the beginning of the cue notes and "Basso" at the end. The clef is changed to treble at the
1006 %      beginning of the cue notes and reset to bass at the end
1007 cleffedCueDuring = #(define-music-function (parser location cuevoice direction instrcue clefcue instr clefinstr cuemusic)
1008                                                         (string? number? string? ly:music? string? ly:music? ly:music?)
1009    #{
1010      \cueDuring #$cuevoice #$direction {
1011        \tag #'cued \setClefCue #$instrcue $clefcue
1012        $cuemusic
1013        \tag #'cued \setClefCue #$instr $clefinstr
1014      }
1015    #}
1017 % generate a cue music section with instrument names and clef changes
1018 % Parameters: \namedCueDuringClef NameOfQuote CueDirection CueInstrument CueClef OriginalInstrument music
1019 %                 -) NameOfQuote CueDirection music are the parameters for \cueDuring
1020 %                 -) CueInstrument and OriginalInstrument are the displayed instrument names
1021 %                 -) CueClef is the clef for the the cue notes
1022 % typical call:
1023 % \namedCueDuringClef #"vIQuote" #UP #"V.I" #"treble" #"Basso" { R1*3 }
1024 %      This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
1025 %      the beginning of the cue notes and "Basso" at the end. The clef is changed to treble at the
1026 %      beginning of the cue notes and reset to bass at the end
1027 namedCueDuringWithClef = #(define-music-function (parser location cuevoice direction instrcue clefcue instr cuemusic)
1028                                              (string? number? string? string? string? ly:music?)
1029    #{
1030      \cueDuringWithClef #$cuevoice #$direction #$clefcue {
1031        \insertCueText #$instrcue
1032        $cuemusic
1033        \insertCueText #$instr
1034      }
1035    #}
1040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1041 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1042 %%%%%   DYNAMICS
1043 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1044 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1047 dynamicsX = #(define-music-function (parser location offset) (number?)
1049     \once \override DynamicText #'X-offset = $offset
1050     \once \override DynamicLineSpanner #'Y-offset = #0
1053 % Move the dynamic sign inside the staff to a fixed staff-relative position
1054 % posY (where 0 means vertically starts at the middle staff line)
1055 dynamicsAllInside = #(define-music-function (parser location offsetX posY)
1056 (number? number?)
1058   % Invalid y-extent -> hidden from skyline calculation and collisions
1059 %   \once \override DynamicLineSpanner #'Y-extent = #(cons +0 -0.01)
1060   \once \override DynamicLineSpanner #'Y-extent = $(lambda (grob)
1061     (let* ((ext (ly:axis-group-interface::height grob))
1062            (dir (ly:grob-property grob 'direction)))
1063       (if (eq? dir UP)
1064             (cons (- (cdr ext) 0.1) (cdr ext))
1065             (cons (car ext)         (+ (car ext) 0.1)))))
1066   % move by X offset and to fixed Y-position (use Y-offset of parent!)
1067   \once \override DynamicText #'X-offset = $offsetX
1068   \once \override DynamicText #'Y-offset =
1069     $(lambda (grob)
1070        (let* ((head (ly:grob-parent grob Y))
1071               (offset (ly:grob-property head 'Y-offset)))
1072          (- posY  offset (- 0.6))))
1073   \once \override DynamicLineSpanner #'Y-offset = $posY
1076 dynamicsUpInside = #(define-music-function (parser location offsetX) (number?)
1077   ((ly:music-function-extract dynamicsAllInside) parser location offsetX 1.5)
1080 dynamicsDownInside = #(define-music-function (parser location offsetX) (number?)
1081   ((ly:music-function-extract dynamicsAllInside) parser location offsetX -3.5)
1084 hairpinOffset = #(define-music-function (parser location posY) (number?)
1086   \once \override DynamicLineSpanner #'Y-offset = $posY
1087   \once \override DynamicLineSpanner #'Y-extent = #(cons +0 -0.01)
1090 #(define ((line-break-offset before after) grob)
1091   (let* ((orig (ly:grob-original grob))
1092          ; All siblings if line-broken:
1093          (siblings (if (ly:grob? orig) (ly:spanner-broken-into orig) '() )))
1094     (if (>= (length siblings) 2)
1095       ; We have been line-broken
1096       (if (eq? (car (last-pair siblings)) grob)
1097         ; Last sibling:
1098         (ly:grob-set-property! grob 'Y-offset after)
1099         ; Others get the before value:
1100         (ly:grob-set-property! grob 'Y-offset before)
1101       )
1102     )
1103   )
1106 ffz = #(make-dynamic-script "ffz")
1107 pf = #(make-dynamic-script "pf")
1108 sempp = #(make-dynamic-script (markup #:line( #:with-dimensions '(0 . 0)
1109 '(0 . 0) #:right-align #:normal-text #:italic "sempre" #:dynamic "pp")))
1110 parenf = #(make-dynamic-script (markup #:line(#:normal-text #:italic #:fontsize 2 "(" #:dynamic "f" #:normal-text #:italic #:fontsize 2 ")")))
1111 parenp = #(make-dynamic-script (markup #:line(#:normal-text #:italic #:fontsize 2 "(" #:dynamic "p" #:normal-text #:italic #:fontsize 2 ")")))
1112 pdolce = #(make-dynamic-script (markup #:line(#:dynamic "p" #:with-dimensions '(0 . 0) '(0 . 0) #:normal-text #:italic "dolce")))
1113 dolce = #(make-dynamic-script (markup #:line(#:normal-text #:italic "dolce")))
1114 sfpdolce = #(make-dynamic-script (markup #:line(#:dynamic "sfp" #:with-dimensions '(0 . 0) '(0 . 0) #:normal-text #:italic "dolce"  )))
1115 bracketf = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 3 "[" #:dynamic "f" #:hspace 0.1 #:normal-text #:fontsize 3 "]"))))
1116 bracketmf = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 3 "[" #:dynamic "mf" #:hspace 0.1 #:normal-text #:fontsize 3 "]"))))
1117 bracketmp = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 2 "[" #:hspace 0.2 #:dynamic "mp" #:normal-text #:fontsize 2 "]"))))
1118 bracketp = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 2 "[" #:hspace 0.2 #:dynamic "p" #:normal-text #:fontsize 2 "]"))))
1120 whiteoutp = #(make-dynamic-script (markup #:whiteout #:pad-markup 0.5 #:dynamic "p"))
1121 whiteoutf = #(make-dynamic-script (markup #:whiteout #:pad-markup 0.5 #:dynamic "f"))
1122 whiteoutff = #(make-dynamic-script (markup #:whiteout #:pad-markup 0.25 #:dynamic "ff"))
1125 cresc = #(make-music 'CrescendoEvent 'span-direction START
1126                      'span-type 'text 'span-text "cresc.")
1127 dim = #(make-music 'DecrescendoEvent 'span-direction START
1128                    'span-type 'text 'span-text "dim.")
1129 decresc = #(make-music 'DecrescendoEvent 'span-direction START
1130                        'span-type 'text 'span-text "decresc.")
1134 %%% Thanks to "Gilles THIBAULT" <gilles.thibault@free.fr>, there is a way
1135 %   to remove also the fermata from R1-\fermataMarkup: By filtering the music
1136 %   and removing the corresponding events.
1137 %   Documented as an LSR snippet: http://lsr.dsi.unimi.it/LSR/Item?id=372
1138 #(define (filterOneEventsMarkup event)
1139 ( let ( (eventname (ly:music-property  event 'name)) )
1140  (not
1141   (or     ;; add here event name you do NOT want
1142    (eq? eventname 'MultiMeasureTextEvent)
1143    (eq? eventname 'AbsoluteDynamicEvent)
1144    (eq? eventname 'TextScriptEvent)
1145    (eq? eventname 'ArticulationEvent)
1146    (eq? eventname 'CrescendoEvent)
1147    (eq? eventname 'DecrescendoEvent)
1148   )
1152 filterArticulations = #(define-music-function (parser location music) (ly:music?)
1153   (music-filter filterOneEventsMarkup music)
1160 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1162 %%%%%   Tempo markings
1163 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1168 rit = \markup {\italic "rit."}
1169 atempo = \markup {\italic "a tempo"}
1170 pocorit = \markup {\italic "poco rit."}
1171 ppmosso = \markup {\italic "poco più mosso"}
1172 pizz = \markup {\italic "pizz."}
1173 arco = \markup {\italic "arco"}
1174 perd = \markup {\italic "perdend."}
1179 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1180 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1181 %%%%%   REST COMBINATION
1182 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1183 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1187 %% REST COMBINING, TAKEN FROM http://lsr.dsi.unimi.it/LSR/Item?id=336
1189 %% Usage:
1190 %%   \new Staff \with {
1191 %%     \override RestCollision #'positioning-done = #merge-rests-on-positioning
1192 %%   } << \somevoice \\ \othervoice >>
1193 %% or (globally):
1194 %%   \layout {
1195 %%     \context {
1196 %%       \Staff
1197 %%       \override RestCollision #'positioning-done = #merge-rests-on-positioning
1198 %%     }
1199 %%   }
1201 %% Limitations:
1202 %% - only handles two voices
1203 %% - does not handle multi-measure/whole-measure rests
1205 #(define (rest-score r)
1206   (let ((score 0)
1207   (yoff (ly:grob-property-data r 'Y-offset))
1208   (sp (ly:grob-property-data r 'staff-position)))
1209     (if (number? yoff)
1210   (set! score (+ score 2))
1211   (if (eq? yoff 'calculation-in-progress)
1212       (set! score (- score 3))))
1213     (and (number? sp)
1214    (<= 0 2 sp)
1215    (set! score (+ score 2))
1216    (set! score (- score (abs (- 1 sp)))))
1217     score))
1219 #(define (merge-rests-on-positioning grob)
1220   (let* ((can-merge #f)
1221    (elts (ly:grob-object grob 'elements))
1222    (num-elts (and (ly:grob-array? elts)
1223       (ly:grob-array-length elts)))
1224    (two-voice? (= num-elts 2)))
1225     (if two-voice?
1226   (let* ((v1-grob (ly:grob-array-ref elts 0))
1227          (v2-grob (ly:grob-array-ref elts 1))
1228          (v1-rest (ly:grob-object v1-grob 'rest))
1229          (v2-rest (ly:grob-object v2-grob 'rest)))
1230     (and
1231      (ly:grob? v1-rest)
1232      (ly:grob? v2-rest)
1233      (let* ((v1-duration-log (ly:grob-property v1-rest 'duration-log))
1234       (v2-duration-log (ly:grob-property v2-rest 'duration-log))
1235       (v1-dot (ly:grob-object v1-rest 'dot))
1236       (v2-dot (ly:grob-object v2-rest 'dot))
1237       (v1-dot-count (and (ly:grob? v1-dot)
1238              (ly:grob-property v1-dot 'dot-count -1)))
1239       (v2-dot-count (and (ly:grob? v2-dot)
1240              (ly:grob-property v2-dot 'dot-count -1))))
1241        (set! can-merge
1242        (and
1243         (number? v1-duration-log)
1244         (number? v2-duration-log)
1245         (= v1-duration-log v2-duration-log)
1246         (eq? v1-dot-count v2-dot-count)))
1247        (if can-merge
1248      ;; keep the rest that looks best:
1249      (let* ((keep-v1? (>= (rest-score v1-rest)
1250               (rest-score v2-rest)))
1251       (rest-to-keep (if keep-v1? v1-rest v2-rest))
1252       (dot-to-kill (if keep-v1? v2-dot v1-dot)))
1253        ;; uncomment if you're curious of which rest was chosen:
1254        ;;(ly:grob-set-property! v1-rest 'color green)
1255        ;;(ly:grob-set-property! v2-rest 'color blue)
1256        (ly:grob-suicide! (if keep-v1? v2-rest v1-rest))
1257        (if (ly:grob? dot-to-kill)
1258            (ly:grob-suicide! dot-to-kill))
1259        (ly:grob-set-property! rest-to-keep 'direction 0)
1260        (ly:rest::y-offset-callback rest-to-keep)))))))
1261     (if can-merge
1262   #t
1263   (ly:rest-collision::calc-positioning-done grob))))
1269 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1271 %%%%%   TABLE OF CONTENTS
1272 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1273 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1276 contentsTitle = "Inhalt / Contents"
1278 \paper {
1279   tocTitleMarkup = \markup \fill-line{
1280     \null
1281     \column {
1282       \override #(cons 'line-width (* 7 cm))
1283       \line{ \fill-line {\piece-title {\contentsTitle} \null }}
1284       \hspace #1
1285     }
1286     \null
1287   }
1288   tocItemMarkup = \markup \fill-line {
1289     \null
1290     \column {
1291       \override #(cons 'line-width (* 7 cm ))
1292       \line { \fill-line{\fromproperty #'toc:text \fromproperty #'toc:page }}
1293     }
1294     \null
1295   }
1299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1300 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1301 %%%%%   TITLE PAGE / HEADER
1302 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1303 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1305 #(define-markup-command (when-property layout props symbol markp) (symbol? markup?)
1306   (if (chain-assoc-get symbol props)
1307       (interpret-markup layout props markp)
1308       (ly:make-stencil '()  '(1 . -1) '(1 . -1))))
1310 #(define-markup-command (vspace layout props amount) (number?)
1311   "This produces a invisible object taking vertical space."
1312   (let ((amount (* amount 3.0)))
1313     (if (> amount 0)
1314         (ly:make-stencil "" (cons -1 1) (cons 0 amount))
1315         (ly:make-stencil "" (cons -1 1) (cons amount amount)))))
1319 titlePageMarkup = \markup \abs-fontsize #10 \when-property #'header:title \column {
1320     \vspace #4
1321     \fill-line { \fontsize #8 \fromproperty #'header:composer }
1322     \vspace #1
1323     \fill-line { \fontsize #8 \fromproperty #'header:poet }
1324     \vspace #4
1325     \fill-line { \fontsize #10 \bold \fromproperty #'header:titlepagetitle }
1326     \vspace #1
1327     \fontsize #2 \when-property #'header:titlepagesubtitle {
1328       \fill-line { \fromproperty #'header:titlepagesubtitle }
1329       \vspace #1
1330     }
1331     \fill-line { \postscript #"-20 0 moveto 40 0 rlineto stroke" }
1332     \vspace #8
1333     \fill-line { \fontsize #5 \fromproperty #'header:ensemble }
1334     \vspace #0.02
1335     \fill-line { \fontsize #2 \fromproperty #'header:instruments }
1336     \vspace #9
1337     \fill-line { \fontsize #5 \fromproperty #'header:date }
1338     \vspace #1
1339     \fill-line { \fontsize #5 \fromproperty #'header:scoretype }
1340     \vspace #1
1341     \when-property #'header:instrument {
1342       \fill-line { \bold \fontsize #6 \rounded-box \fromproperty #'header:instrument }
1343     }
1344     \vspace #7
1345     \fontsize #2 \when-property #'header:enteredby \override #'(baseline-skip . 3.75) \left-align\center-column {
1346       \fill-line { "Herausgegeben von: / Edited by:"}
1347       \vspace #0.
1348       \fill-line { \fromproperty #'header:enteredby }
1349     }
1350     \fill-line {
1351       \when-property #'header:arrangement \column {
1352         \vspace #8
1353         \fill-line { \fontsize #3 \fromproperty #'header:arrangement }
1354       }
1355     }
1356   \vspace #6
1357   \fill-line { \fromproperty #'header:copyright }
1360 titleHeaderMarkup = \markup {
1361   \override #'(baseline-skip . 3.5)
1362   \column {
1363     \fill-line {
1364       \fromproperty #'header:logo
1365       \override #'(baseline-skip . 4.5) \center-column {
1366         \bold \abs-fontsize #18 \fromproperty #'header:title
1367         \bold \abs-fontsize #12 \fromproperty #'header:subtitle
1368         \abs-fontsize #11 \fromproperty #'header:subsubtitle
1369       }
1370       \bold \abs-fontsize #11 \when-property #'header:instrument \rounded-box \fromproperty #'header:instrument
1371     }
1372     \fill-line {
1373       \with-dimensions #'( 0 . 0) #'( 0 . 1 ) \null
1374     }
1376     \fill-line {
1377             \abs-fontsize #10 \fromproperty #'header:poet
1378             \abs-fontsize #10 \fromproperty #'header:composer
1379     }
1380     \fill-line {
1381             \abs-fontsize #10 \fromproperty #'header:meter
1382             \abs-fontsize #10 \fromproperty #'header:arranger
1383     }
1384   }
1388 titleScoreMarkup = \markup \piece-title \fromproperty #'header:piece
1390 \paper {
1391   scoreTitleMarkup = \titleScoreMarkup
1392   bookTitleMarkup = \titleHeaderMarkup
1397 %%%%%%%%%%%%%% headers and footers %%%%%%%%%%%%%%%%%%%%%%%%%%
1399 #(define (first-score-page layout props arg)
1400   (let* ((label 'first-score-page)
1401          (table (ly:output-def-lookup layout 'label-page-table))
1402          (label-page (and (list? table) (assoc label table)))
1403          (page-number (and label-page (cdr label-page)))
1404         )
1405     (if (eq? (chain-assoc-get 'page:page-number props -1) page-number)
1406       (interpret-markup layout props arg)
1407       empty-stencil)))
1409 #(define no-header-table '(1))
1410 addNoHeaderPage = #(define-music-function (parser location nr) (number?)
1411   (set! no-header-table (cons nr no-header-table))
1412   (make-music 'Music 'void #t))
1413 setNoHeaderPages = #(define-music-function (parser location pages) (list?)
1414   (set! no-header-table pages)
1415   (make-music 'Music 'void #t))
1417 #(define (is-header-page layout props arg)
1418   (let* ((page-number (chain-assoc-get 'page:page-number props -1)))
1419     (if (not (member page-number no-header-table))
1420       (interpret-markup layout props arg)
1421       empty-stencil)))
1423 #(define no-footer-table '(1))
1424 addNoFooterPage = #(define-music-function (parser location nr) (number?)
1425   (set! no-footer-table (cons nr no-footer-table))
1426   (make-music 'Music 'void #t))
1427 setNoFooterPages = #(define-music-function (parser location pages) (list?)
1428   (set! no-footer-table pages)
1429   (make-music 'Music 'void #t))
1431 #(define (is-footer-page layout props arg)
1432   (let* ((page-number (chain-assoc-get 'page:page-number props -1)))
1433     (if (not (member page-number no-footer-table))
1434       (interpret-markup layout props arg)
1435       empty-stencil)))
1437 #(define copyright-pages-table '(1))
1438 addCopyrightPage = #(define-music-function (parser location nr) (number?)
1439   (set! copyright-pages-table (cons nr copyright-pages-table))
1440   (make-music 'Music 'void #t))
1441 setCopyrightPages = #(define-music-function (parser location pages) (list?)
1442   (set! copyright-pages-table pages)
1443   (make-music 'Music 'void #t))
1445 #(define (is-copyright-page layout props arg)
1446   (let* ((page-number (chain-assoc-get 'page:page-number props -1)))
1447     (if (member page-number copyright-pages-table)
1448       (interpret-markup layout props arg)
1449       empty-stencil)))
1453 \paper {
1454   olyStdOddHeaderMarkup = \markup \fill-line {
1455     %% force the header to take some space, otherwise the
1456     %% page layout becomes a complete mess.
1457     " "
1458     \on-the-fly #is-header-page \fromproperty #'header:title
1459     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1460   }
1461   olyStdEvenHeaderMarkup = \markup \fill-line {
1462     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1463     \on-the-fly #is-header-page \fromproperty #'header:composer
1464     " "
1465   }
1466   olyInstrumentOddHeaderMarkup = \markup \fill-line {
1467     " "
1468     \on-the-fly #is-header-page \concat { \fromproperty #'header:instrument }
1469     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1470   }
1471   olyInstrumentEvenHeaderMarkup = \markup \fill-line {
1472     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1473     \on-the-fly #is-header-page \concat { \fromproperty #'header:composer ": " \fromproperty #'header:title }
1474     " "
1475   }
1476   oddHeaderMarkup = \olyStdOddHeaderMarkup
1477   evenHeaderMarkup = \olyStdEvenHeaderMarkup
1479   olyStdOddFooterMarkup = \markup {
1480     \column {
1481       \fill-line {
1482         %% publisher header field only on title page.
1483         \on-the-fly #first-page \fromproperty #'header:publisher
1484       }
1485       \fill-line {
1486         %% copyright on the first real score page
1487         \on-the-fly #is-copyright-page \fromproperty #'header:copyright
1488         \on-the-fly #is-copyright-page \null
1489       }
1490       \fill-line {
1491         %% All other pages get the number of the edition centered
1492         \on-the-fly #is-footer-page \fromproperty #'header:scorenumber
1493       }
1494     }
1495   }
1496   olyInstrumentOddFooterMarkup = \markup {
1497     \column {
1498       \fill-line {
1499         %% copyright on the first real score page
1500         \on-the-fly #is-copyright-page \fromproperty #'header:copyright
1501         \on-the-fly #is-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   }
1509   oddFooterMarkup = \olyStdOddFooterMarkup
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 #'padding = #0
1647   }
1648   \context {
1649     \Score
1650     % Force multi-measure rests to be written as one span
1651     \override MultiMeasureRest #'expand-limit = #3
1652     skipBars = ##t
1653     autoBeaming = ##f
1654     \override CombineTextScript #'avoid-slur = #'outside
1655     \override DynamicTextSpanner #'style = #'none
1656     \override InstrumentSwitch #'font-size = #-1
1658     % Rest collision
1659     \override RestCollision #'positioning-done = #merge-rests-on-positioning
1660     % Auto-Accidentals: Use modern-cautionary style...
1661     extraNatural = ##f
1662     % Accidental rules (the rule giving the most accidentals wins!)
1663     % -) Reset accidentals at each barline -> accs not in key sig will always be printed
1664     % -) Same octave accidentals are remembered for two measures -> cancellation
1665     % -) other octave accidentals are remembered for next measure -> cancellation
1666     autoAccidentals = #`(Staff  ,(make-accidental-rule 'same-octave 0)
1667                                 ,(make-accidental-rule 'any-octave 0)
1668                                 ,(make-accidental-rule 'any-octave 1)
1669                                 ,(make-accidental-rule 'same-octave 2))
1670     % No auto-cautionaries, we always use autoAccidentals!
1671 %     autoCautionaries = #`(Staff ,(make-accidental-rule 'any-octave 0)
1672 %                                 ,(make-accidental-rule 'same-octave 1))
1673     printKeyCancellation = ##t
1674     quotedEventTypes = #'(StreamEvent)
1675     quotedCueEventTypes = #'(
1676       rhythmic-event
1677       tie-event
1678       beam-event
1679       tuplet-span-event
1680       tremolo-event
1681       glissando-event
1682       harmonic-event
1683       repeat-tie-event
1684       articulation-event
1685       slur-event
1686       trill-span-event
1687       tremolo-span-event
1688     )
1689     implicitBassFigures = #'(0 100)
1690   }
1691   \context {
1692     \Staff
1693     \RemoveEmptyStaves
1694   }
1698 ts = #(make-music 'TextScriptEvent 'text "t.s." 'direction UP )
1699 tt = #(make-music 'TextScriptEvent 'text "Tutti" 'direction UP )
1700 solo = #(make-music 'TextScriptEvent 'text "Solo" 'direction UP )
1701 tutti = #(make-music 'TextScriptEvent 'text "Tutti" 'direction UP )
1702 bracketts = #(make-music 'TextScriptEvent 'text "[t.s.]" 'direction UP )
1703 brackettt = #(make-music 'TextScriptEvent 'text "[Tutti]" 'direction UP )
1704 bracketsolo = #(make-music 'TextScriptEvent 'text "[Solo]" 'direction UP )
1706 sottovoce = #(make-music 'TextScriptEvent 'text "sotto voce" 'direction UP )
1708 dashedSlur = -\tweak #'dash-definition #'((0 1 0.4 0.75))(
1709 dashedTie = -\tweak #'dash-definition #'((0 1 0.4 0.75))~
1711 divisi = #(define-music-function (parser location vc1 vc2) (ly:music? ly:music?)
1713   << { \voiceOne $vc1 \oneVoice} \context Voice = "divisi2" { \voiceTwo $vc2 } >>
1717 #(define twoVoice divisi)
1719 #(define-public (bracket-stencils grob)
1720   (let ((lp (grob-interpret-markup grob (markup #:fontsize 3.5 #:translate (cons -0.3 -0.5) "[")))
1721         (rp (grob-interpret-markup grob (markup #:fontsize 3.5 #:translate (cons -0.3 -0.5) "]"))))
1722     (list lp rp)))
1724 bracketify = #(define-music-function (parser loc arg) (ly:music?)
1725    (_i "Tag @var{arg} to be parenthesized.")
1727   \once \override ParenthesesItem #'stencils = #bracket-stencils
1728   \parenthesize $arg
1733 #(define-markup-command (hat layout props arg) (markup?)
1734   "Draw a hat above the given string @var{arg}."
1735   (interpret-markup layout props (markup #:combine #:raise 1.5 "^" arg)))
1739 smallFlageolet =
1740 #(let ((m (make-music 'ArticulationEvent
1741                       'articulation-type "flageolet")))
1742    (ly:music-set-property! m 'tweaks
1743      (acons 'font-size -2
1744        (ly:music-property m 'tweaks)))
1745   m)
1748 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1749 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1750 %%%%%   LICENSE TEXTS
1751 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1752 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1754 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" }}
1755 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" }}
1756 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" }}
1757 LicenseNoRestrictions = \markup{\line {Die Ausgabe darf kopiert und ohne Einschränkungen aufgeführt werden. / May be copied and performed without restriction.}}
1759 \include "sceaux_clef-key.ily"
1762 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1763 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1764 %%%%%   VARIOUS
1765 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1766 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1768 startUnremovableSection = \set Staff.keepAliveInterfaces =
1769  #'(rhythmic-grob-interface
1770     rest-interface
1771     lyric-interface
1772     percent-repeat-item-interface
1773     percent-repeat-interface
1774     stanza-number-interface)
1776 endUnremovableSection = \unset Staff.keepAliveInterfaces
1779 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1780 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1781 %%%%%   EDITORIAL ANNOTATIONS
1782 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1783 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1785 #(define-public (editorial-bracket-stencil stil padding widen)
1786 "Add brackets for editorial annoations around STIL, producing a new stencil."
1787 (let* ((axis Y)
1788        (other-axis (lambda (a) (remainder (+ a 1) 2)))
1789        (ext (interval-widen (ly:stencil-extent stil axis) widen))
1790        (thick 0.15)
1791        (protrusion 0.3)
1792        (lb (ly:bracket axis ext thick protrusion))
1793        (rb (ly:bracket axis ext thick (- protrusion))))
1794   (set! stil (ly:stencil-combine-at-edge stil (other-axis axis) 1 rb padding))
1795   (set! stil
1796     (ly:stencil-combine-at-edge lb (other-axis axis) 1 stil padding))
1797   stil))
1799 editorialHairpin = \once \override Hairpin     #'stencil = #(lambda (grob) (editorial-bracket-stencil (ly:hairpin::print grob) 0.2 0.55))
1800 editorialDynamic = \once \override DynamicText #'stencil = #(lambda (grob) (editorial-bracket-stencil (ly:text-interface::print grob) 0.2 0.55))
1801 editorialMarkup =  \once \override TextScript  #'stencil = #(lambda (grob) (editorial-bracket-stencil (ly:text-interface::print grob) 0.2 0.55))
1803 % videStart = \mark \markup { \hspace #1 \musicglyph #"scripts.coda"  \with-dimensions #'(0 . 0) #'(0 . 0) \left-align { vi-} }
1804 videStart = \mark \markup \halign #-2.3 \concat { \hspace #4.5 \musicglyph #"scripts.coda" \left-align { vi- } }
1805 % videEnd = \notemode {
1806 %   \once \override Score.RehearsalMark #'break-visibility = #begin-of-line-invisible
1807 %   \mark \markup \concat{ \with-dimensions #'(0 . 0) #'(0 . 0) \right-align { -de } \hspace #1 \musicglyph #"scripts.coda" }
1809 videEnd = \notemode {
1810         \once \override Score.RehearsalMark #'break-visibility = #begin-of-line-invisible
1811         \mark \markup \concat{ \right-align { -de } \hspace #1.5 \musicglyph #"scripts.coda" \hspace #4.2 }
1816 \layout {
1817         \context {\Staff
1818                 soloText = #"I"
1819                 soloIIText = #"II"
1820                 aDueText = #"a2"
1821         }
1824 \paper {
1825 %   annotate-spacing = ##t
1826   ragged-bottom = ##f
1827   ragged-last = ##f
1828   ragged-last-bottom = ##f
1830   top-markup-spacing #'minimum-distance = #5
1831 %   top-markup-spacing #'space = #4
1832 %   top-markup-spacing #'padding = #2
1833   top-markup-spacing #'stretchability = #15
1835   top-system-spacing #'minimum-distance = #0
1836 %   top-system-spacing #'space = #3
1837   top-system-spacing #'padding = #2
1838   top-system-spacing #'stretchability = #13
1839   
1840   markup-system-spacing #'minimum-distance = #5
1841 %   markup-system-spacing #'space = #4
1842   markup-system-spacing #'padding = #3
1843   markup-system-spacing #'stretchability = #25
1844   
1845   system-system-spacing #'minimum-distance = #0
1846 %   system-system-spacing #'space = #5
1847   system-system-spacing #'padding = #2
1848   system-system-spacing #'stretchability = #15
1849   
1850   last-bottom-spacing #'basic-distance = #3
1851 %   last-bottom-spacing #'space = #7
1852   last-bottom-spacing #'padding = #4
1853   last-bottom-spacing #'stretchability = #14
1855 %   score-markup-spacing #'space = #5
1856 %   score-markup-spacing #'stretchability = #15
1858 %   markup-markup-spacing #'space = #5
1859 %   markup-markup-spacing #'stretchability = #30
1862 \layout {
1863   \context { \PianoStaff
1864     \override StaffGrouper #'staff-staff-spacing #'stretchability = #1.5
1865   }
1866   \context { \StaffGroup
1867     \override StaffGrouper #'staff-staff-spacing #'stretchability = #2.5
1868     \override SystemStartBracket #'collapse-height = #1
1869   }
1870   \context { \GrandStaff
1871     \override StaffGrouper #'staff-staff-spacing #'stretchability = #3
1872     \override StaffGrouper #'staffgroup-staff-spacing #'stretchability = #3
1873    }
1874   \context { \ChoirStaff
1875     \override StaffGrouper #'staff-staff-spacing #'stretchability = #1
1876   }
1877   \context { \Staff
1878     \override StaffGrouper #'staff-staff-spacing #'stretchability = #4.9
1879   }
1880   \context { \Score
1881     \override StaffGrouper #'staff-staff-spacing #'stretchability = #5
1882   }
1887 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1888 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1889 %%%%%   WORKAROUNDS!
1890 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1891 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1893 % _ does not work as a direction modifier in figured bass
1894 tsdown = #(make-music 'TextScriptEvent 'text "t.s." 'direction DOWN )