Trivial title page change
[orchestrallily.git] / orchestrallily.ily
blob5f6fff2aebe88507575d42383bd0813f8322cbaf
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     (if (not (null? label-table))
829       (let* ((format-line (lambda (toc-item)
830              (let* ((label (car toc-item))
831                     (text  (caddr toc-item))
832                     (label-page (and (list? label-table)
833                                      (assoc label label-table)))
834                     (page (and label-page (cdr label-page))))
835                (format #f "~a, section, 1, {~a}, ~a" page text label))))
836              (formatted-toc-items (map format-line (toc-items)))
837              (whole-string (string-join formatted-toc-items ",\n"))
838              (output-name (ly:parser-output-name parser))
839              (outfilename (format "~a.toc" output-name))
840              (outfile (open-output-file outfilename)))
841         (if (output-port? outfile)
842             (display whole-string outfile)
843             (ly:warning (_ "Unable to open output file ~a for the TOC information") outfilename))
844         (close-output-port outfile)))))
847 #(define-public (oly:add-toc-item parser markup-symbol text)
848   (oly:music_handler parser (add-toc-item! markup-symbol text)))
851 #(define (oly:add-score parser score piecename)
852   (if (not-null? piecename)
853     (oly:add-toc-item parser 'tocItemMarkup piecename))
854   (oly:score_handler parser score)
856 % The helper function to build a score.
857 #(define (oly:createScoreHelper parser location piece children func)
858   (let* (
859          (staves    (oly:staff_group_handler parser piece "" "SimultaneousMusic" children))
860          (music     (if (not-null? staves)
861                         ((ly:music-function-extract func) parser location staves)
862                         '()
863                     ))
864          (score     '())
865          (piecename (namedPieceInstrObject piece (car children) "PieceName"))
866          (piecenametacet (namedPieceInstrObject piece (car children) "PieceNameTacet"))
867          (header    '())
868         )
869     (if (null? music)
870       ; No staves, print tacet
871       (begin
872         (if (not-null? piecenametacet) (set! piecename piecenametacet))
873         (if (not-null? piecename)
874           (oly:add-score parser (list (oly:piece-title-markup piecename)) piecename)
875           (ly:warning (_ "No music and no score title found for part ~a and instrument ~a") piece children)
876         )
877       )
878       ; we have staves, apply the piecename to the score and add layout/midi blocks if needed
879       (begin
880         (set! score (scorify-music music parser))
881         (oly:set_piece_header score piecename)
882         (oly:apply_score_midi score)
883         (oly:apply_score_layout score)
884         ; Schedule the score for typesetting
885         (oly:add-score parser score piecename)
886       )
887     )
888   )
889   ; This is a void function, the score has been schedulled for typesetting already
890   (make-music 'Music 'void #t)
893 createVoice = #(define-music-function (parser location piece name) (string? string?)
894   (let* ((vc (oly:create_voice parser piece name)))
895     (make-music 'SimultaneousMusic
896                 'elements vc)))
898 createStaff = #(define-music-function (parser location piece name) (string? string?)
899   (oly:create_staff_or_group parser piece name))
900 createStaffForContents = #(define-music-function (parser location piece name type contents) (string? string? string? ly:music?)
901   (oly:staff_handler_internal parser piece name type (list contents)))
904 createScore = #(define-music-function (parser location piece children) (string? list?)
905   (oly:createScoreHelper parser location piece children keepcuefilter)
907 createNoCuesScore = #(define-music-function (parser location piece children) (string? list?)
908   (oly:createScoreHelper parser location piece children removecuefilter)
911 createHeadline = #(define-music-function (parser location headline) (string?)
912   (oly:add-toc-item parser 'tocItemMarkup headline)
913   (oly:score_handler parser (list (oly:piece-title-markup headline)))
914   (make-music 'Music 'void #t)
919 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
920 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
921 %%%%%   CUE NOTES
922 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
923 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
925 newInstrument = #(define-music-function (parser location instr) (string?)
927   \set Voice.instrumentCueName = #$(string-join (list "+" instr))
930 cueText = #(define-music-function (parser location instr) (string?)
932   \set Voice.instrumentCueName = $instr
935 cueMarkup = #(define-music-function (parser location instr) (markup?)
937   \set Voice.instrumentCueName = $instr
941 clearCueText = #(define-music-function (parser location) ()
943   \unset Voice.instrumentCueName
947 insertCueText = #(define-music-function (parser location instr) (string?)
948   (if (string-null? instr)
949     #{ \tag #'cued \clearCueText #}
950     #{ \tag #'cued \cueText #$instr #}
953 % generate a cue music section with instrument names
954 % Parameters: \namedCueDuring NameOfQuote CueDirection CueInstrument OriginalInstrument music
955 %                 -) NameOfQuote CueDirection music are the parameters for \cueDuring
956 %                 -) CueInstrument and OriginalInstrument are the displayed instrument names
957 % typical call:
958 % \namedCueDuring #"vIQuote" #UP #"V.I" #"Sop." { R1*3 }
959 %      This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
960 %      the beginning of the cue notes and "Sop." at the end
961 namedCueDuring = #(define-music-function (parser location cuevoice direction instrcue instr cuemusic) (string? number? string? string? ly:music?)
963   \cueDuring #$cuevoice #$direction {
964     \insertCueText #$instrcue
965     $cuemusic
966     \insertCueText #$instr
967   }
970 namedTransposedCueDuring = #(define-music-function (parser location cuevoice direction instrcue instr trans cuemusic) (string? number? string? string? ly:music? ly:music?)
971    #{
972      \transposedCueDuring #$cuevoice #$direction $trans {
973        \insertCueText #$instrcue
974        $cuemusic
975        \insertCueText #$instr
976      }
977    #}
980 % set the cue instrument name and clef
981 setClefCue = #(define-music-function (parser location instr clef)
982                                                      (string? ly:music?)
983    #{
984      \once \override Staff.Clef #'font-size = #-3 $clef
985      \insertCueText $instr
986    #} )
988 % generate a cue music section with instrument names and clef changes
989 % Parameters: \cleffedCueDuring NameOfQuote CueDirection CueInstrument CueClef OriginalInstrument OriginalClef music
990 %                 -) NameOfQuote CueDirection music are the parameters for \cueDuring
991 %                 -) CueInstrument and OriginalInstrument are the displayed instrument names
992 %                 -) CueClef and OriginalClef are the clefs for the the cue notes and the clef of the containing voice
993 % typical call:
994 % \cleffedCueDuring #"vIQuote" #UP #"V.I" #"treble" #"Basso" #"bass" { R1*3 }
995 %      This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
996 %      the beginning of the cue notes and "Basso" at the end. The clef is changed to treble at the
997 %      beginning of the cue notes and reset to bass at the end
998 cleffedCueDuring = #(define-music-function (parser location cuevoice direction instrcue clefcue instr clefinstr cuemusic)
999                                                         (string? number? string? ly:music? string? ly:music? ly:music?)
1000    #{
1001      \cueDuring #$cuevoice #$direction {
1002        \tag #'cued \setClefCue #$instrcue $clefcue
1003        $cuemusic
1004        \tag #'cued \setClefCue #$instr $clefinstr
1005      }
1006    #}
1012 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1013 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1014 %%%%%   DYNAMICS
1015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1016 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1019 dynamicsX = #(define-music-function (parser location offset) (number?)
1021     \once \override DynamicText #'X-offset = $offset
1022     \once \override DynamicLineSpanner #'Y-offset = #0
1025 % Move the dynamic sign inside the staff to a fixed staff-relative position
1026 % posY (where 0 means vertically starts at the middle staff line)
1027 dynamicsAllInside = #(define-music-function (parser location offsetX posY)
1028 (number? number?)
1030   % Invalid y-extent -> hidden from skyline calculation and collisions
1031 %   \once \override DynamicLineSpanner #'Y-extent = #(cons +0 -0.01)
1032   \once \override DynamicLineSpanner #'Y-extent = $(lambda (grob)
1033     (let* ((ext (ly:axis-group-interface::height grob))
1034            (dir (ly:grob-property grob 'direction)))
1035       (if (eq? dir UP)
1036             (cons (- (cdr ext) 0.1) (cdr ext))
1037             (cons (car ext)         (+ (car ext) 0.1)))))
1038   % move by X offset and to fixed Y-position (use Y-offset of parent!)
1039   \once \override DynamicText #'X-offset = $offsetX
1040   \once \override DynamicText #'Y-offset =
1041     $(lambda (grob)
1042        (let* ((head (ly:grob-parent grob Y))
1043               (offset (ly:grob-property head 'Y-offset)))
1044          (- posY  offset (- 0.6))))
1045   \once \override DynamicLineSpanner #'Y-offset = $posY
1048 dynamicsUpInside = #(define-music-function (parser location offsetX) (number?)
1049   ((ly:music-function-extract dynamicsAllInside) parser location offsetX 1.5)
1052 dynamicsDownInside = #(define-music-function (parser location offsetX) (number?)
1053   ((ly:music-function-extract dynamicsAllInside) parser location offsetX -3.5)
1056 hairpinOffset = #(define-music-function (parser location posY) (number?)
1058   \once \override DynamicLineSpanner #'Y-offset = $posY
1059   \once \override DynamicLineSpanner #'Y-extent = #(cons +0 -0.01)
1062 #(define ((line-break-offset before after) grob)
1063   (let* ((orig (ly:grob-original grob))
1064          ; All siblings if line-broken:
1065          (siblings (if (ly:grob? orig) (ly:spanner-broken-into orig) '() )))
1066     (if (>= (length siblings) 2)
1067       ; We have been line-broken
1068       (if (eq? (car (last-pair siblings)) grob)
1069         ; Last sibling:
1070         (ly:grob-set-property! grob 'Y-offset after)
1071         ; Others get the before value:
1072         (ly:grob-set-property! grob 'Y-offset before)
1073       )
1074     )
1075   )
1078 ffz = #(make-dynamic-script "ffz")
1079 pf = #(make-dynamic-script "pf")
1080 sempp = #(make-dynamic-script (markup #:line( #:with-dimensions '(0 . 0)
1081 '(0 . 0) #:right-align #:normal-text #:italic "sempre" #:dynamic "pp")))
1082 parenf = #(make-dynamic-script (markup #:line(#:normal-text #:italic #:fontsize 2 "(" #:dynamic "f" #:normal-text #:italic #:fontsize 2 ")")))
1083 parenp = #(make-dynamic-script (markup #:line(#:normal-text #:italic #:fontsize 2 "(" #:dynamic "p" #:normal-text #:italic #:fontsize 2 ")")))
1084 pdolce = #(make-dynamic-script (markup #:line(#:dynamic "p" #:with-dimensions '(0 . 0) '(0 . 0) #:normal-text #:italic "dolce")))
1085 dolce = #(make-dynamic-script (markup #:line(#:normal-text #:italic "dolce")))
1086 sfpdolce = #(make-dynamic-script (markup #:line(#:dynamic "sfp" #:with-dimensions '(0 . 0) '(0 . 0) #:normal-text #:italic "dolce"  )))
1087 bracketf = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 3 "[" #:dynamic "f" #:hspace 0.1 #:normal-text #:fontsize 3 "]"))))
1088 bracketmf = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 3 "[" #:dynamic "mf" #:hspace 0.1 #:normal-text #:fontsize 3 "]"))))
1089 bracketmp = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 2 "[" #:hspace 0.2 #:dynamic "mp" #:normal-text #:fontsize 2 "]"))))
1090 bracketp = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 2 "[" #:hspace 0.2 #:dynamic "p" #:normal-text #:fontsize 2 "]"))))
1092 whiteoutp = #(make-dynamic-script (markup #:whiteout #:pad-markup 0.5 #:dynamic "p"))
1093 whiteoutf = #(make-dynamic-script (markup #:whiteout #:pad-markup 0.5 #:dynamic "f"))
1094 whiteoutff = #(make-dynamic-script (markup #:whiteout #:pad-markup 0.25 #:dynamic "ff"))
1097 % cresc = #(make-music 'CrescendoEvent 'span-direction START 'crescendoSpanner 'text 'crescendoText "cresc.")
1098 % endcresc =  #(make-span-event 'CrescendoEvent STOP)
1099 % dim = #(make-music 'DecrescendoEvent 'span-direction START 'decrescendoSpanner 'text 'decrescendoText "dim.")
1100 % enddim =  #(make-span-event 'DecrescendoEvent STOP)
1101 % decresc = #(make-music 'DecrescendoEvent 'span-direction START 'decrescendoSpanner 'text 'decrescendoText "decresc.")
1102 % enddecresc =  #(make-span-event 'DecrescendoEvent STOP)
1104 % setCresc = {}
1105 % setDecresc = {}
1106 % setDim = {}
1107 cresc = #(make-music 'CrescendoEvent 'span-direction START
1108                      'span-type 'text 'span-text "cresc.")
1109 dim = #(make-music 'DecrescendoEvent 'span-direction START
1110                    'span-type 'text 'span-text "dim.")
1111 decresc = #(make-music 'DecrescendoEvent 'span-direction START
1112                        'span-type 'text 'span-text "decresc.")
1114 % newOrOldClef = #(define-music-function (parser location new old ) (string? string?)
1115 %     (if (ly:get-option 'old-clefs) #{ \clef $old #} #{ \clef $new #})
1116 % )
1120 %%% Thanks to "Gilles THIBAULT" <gilles.thibault@free.fr>, there is a way
1121 %   to remove also the fermata from R1-\fermataMarkup: By filtering the music
1122 %   and removing the corresponding events.
1123 %   Documented as an LSR snippet: http://lsr.dsi.unimi.it/LSR/Item?id=372
1124 #(define (filterOneEventsMarkup event)
1125 ( let ( (eventname (ly:music-property  event 'name)) )
1126  (not
1127   (or     ;; add here event name you do NOT want
1128    (eq? eventname 'MultiMeasureTextEvent)
1129    (eq? eventname 'AbsoluteDynamicEvent)
1130    (eq? eventname 'TextScriptEvent)
1131    (eq? eventname 'ArticulationEvent)
1132    (eq? eventname 'CrescendoEvent)
1133    (eq? eventname 'DecrescendoEvent)
1134   )
1138 filterArticulations = #(define-music-function (parser location music) (ly:music?)
1139   (music-filter filterOneEventsMarkup music)
1146 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1147 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1148 %%%%%   Tempo markings
1149 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1150 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1154 rit = \markup {\italic "rit."}
1155 pocorit = \markup {\italic "poco rit."}
1156 ppmosso = \markup {\italic "poco più mosso"}
1157 pizz = \markup {\italic "pizz."}
1158 arco = \markup {\italic "arco"}
1159 perd = \markup {\italic "perdend."}
1164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1165 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1166 %%%%%   REST COMBINATION
1167 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1168 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1172 %% REST COMBINING, TAKEN FROM http://lsr.dsi.unimi.it/LSR/Item?id=336
1174 %% Usage:
1175 %%   \new Staff \with {
1176 %%     \override RestCollision #'positioning-done = #merge-rests-on-positioning
1177 %%   } << \somevoice \\ \othervoice >>
1178 %% or (globally):
1179 %%   \layout {
1180 %%     \context {
1181 %%       \Staff
1182 %%       \override RestCollision #'positioning-done = #merge-rests-on-positioning
1183 %%     }
1184 %%   }
1186 %% Limitations:
1187 %% - only handles two voices
1188 %% - does not handle multi-measure/whole-measure rests
1190 #(define (rest-score r)
1191   (let ((score 0)
1192   (yoff (ly:grob-property-data r 'Y-offset))
1193   (sp (ly:grob-property-data r 'staff-position)))
1194     (if (number? yoff)
1195   (set! score (+ score 2))
1196   (if (eq? yoff 'calculation-in-progress)
1197       (set! score (- score 3))))
1198     (and (number? sp)
1199    (<= 0 2 sp)
1200    (set! score (+ score 2))
1201    (set! score (- score (abs (- 1 sp)))))
1202     score))
1204 #(define (merge-rests-on-positioning grob)
1205   (let* ((can-merge #f)
1206    (elts (ly:grob-object grob 'elements))
1207    (num-elts (and (ly:grob-array? elts)
1208       (ly:grob-array-length elts)))
1209    (two-voice? (= num-elts 2)))
1210     (if two-voice?
1211   (let* ((v1-grob (ly:grob-array-ref elts 0))
1212          (v2-grob (ly:grob-array-ref elts 1))
1213          (v1-rest (ly:grob-object v1-grob 'rest))
1214          (v2-rest (ly:grob-object v2-grob 'rest)))
1215     (and
1216      (ly:grob? v1-rest)
1217      (ly:grob? v2-rest)
1218      (let* ((v1-duration-log (ly:grob-property v1-rest 'duration-log))
1219       (v2-duration-log (ly:grob-property v2-rest 'duration-log))
1220       (v1-dot (ly:grob-object v1-rest 'dot))
1221       (v2-dot (ly:grob-object v2-rest 'dot))
1222       (v1-dot-count (and (ly:grob? v1-dot)
1223              (ly:grob-property v1-dot 'dot-count -1)))
1224       (v2-dot-count (and (ly:grob? v2-dot)
1225              (ly:grob-property v2-dot 'dot-count -1))))
1226        (set! can-merge
1227        (and
1228         (number? v1-duration-log)
1229         (number? v2-duration-log)
1230         (= v1-duration-log v2-duration-log)
1231         (eq? v1-dot-count v2-dot-count)))
1232        (if can-merge
1233      ;; keep the rest that looks best:
1234      (let* ((keep-v1? (>= (rest-score v1-rest)
1235               (rest-score v2-rest)))
1236       (rest-to-keep (if keep-v1? v1-rest v2-rest))
1237       (dot-to-kill (if keep-v1? v2-dot v1-dot)))
1238        ;; uncomment if you're curious of which rest was chosen:
1239        ;;(ly:grob-set-property! v1-rest 'color green)
1240        ;;(ly:grob-set-property! v2-rest 'color blue)
1241        (ly:grob-suicide! (if keep-v1? v2-rest v1-rest))
1242        (if (ly:grob? dot-to-kill)
1243            (ly:grob-suicide! dot-to-kill))
1244        (ly:grob-set-property! rest-to-keep 'direction 0)
1245        (ly:rest::y-offset-callback rest-to-keep)))))))
1246     (if can-merge
1247   #t
1248   (ly:rest-collision::calc-positioning-done grob))))
1254 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1255 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1256 %%%%%   TABLE OF CONTENTS
1257 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1258 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1261 contentsTitle = "Inhalt / Contents"
1263 \paper {
1264   tocTitleMarkup = \markup \fill-line{
1265     \null
1266     \column {
1267       \override #(cons 'line-width (* 7 cm))
1268       \line{ \fill-line {\piece-title {\contentsTitle} \null }}
1269       \hspace #1
1270     }
1271     \null
1272   }
1273   tocItemMarkup = \markup \fill-line {
1274     \null
1275     \column {
1276       \override #(cons 'line-width (* 7 cm ))
1277       \line { \fill-line{\fromproperty #'toc:text \fromproperty #'toc:page }}
1278     }
1279     \null
1280   }
1284 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1285 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1286 %%%%%   TITLE PAGE / HEADER
1287 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1288 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1290 #(define-markup-command (when-property layout props symbol markp) (symbol? markup?)
1291   (if (chain-assoc-get symbol props)
1292       (interpret-markup layout props markp)
1293       (ly:make-stencil '()  '(1 . -1) '(1 . -1))))
1295 #(define-markup-command (vspace layout props amount) (number?)
1296   "This produces a invisible object taking vertical space."
1297   (let ((amount (* amount 3.0)))
1298     (if (> amount 0)
1299         (ly:make-stencil "" (cons -1 1) (cons 0 amount))
1300         (ly:make-stencil "" (cons -1 1) (cons amount amount)))))
1304 titlePageMarkup = \markup \abs-fontsize #10 \when-property #'header:title \column {
1305     \vspace #4
1306     \fill-line { \fontsize #8 \fromproperty #'header:composer }
1307     \vspace #1
1308     \fill-line { \fontsize #8 \fromproperty #'header:poet }
1309     \vspace #4
1310     \fill-line { \fontsize #10 \bold \fromproperty #'header:titlepagetitle }
1311     \vspace #1
1312     \fontsize #2 \when-property #'header:titlepagesubtitle {
1313       \fill-line { \fromproperty #'header:titlepagesubtitle }
1314       \vspace #1
1315     }
1316     \fill-line { \postscript #"-20 0 moveto 40 0 rlineto stroke" }
1317     \vspace #8
1318     \fill-line { \fontsize #5 \fromproperty #'header:ensemble }
1319     \vspace #0.02
1320     \fill-line { \fontsize #2 \fromproperty #'header:instruments }
1321     \vspace #9
1322     \fill-line { \fontsize #5 \fromproperty #'header:date }
1323     \vspace #1
1324     \fill-line { \fontsize #5 \fromproperty #'header:scoretype }
1325     \vspace #1
1326     \when-property #'header:instrument {
1327       \fill-line { \bold \fontsize #6 \rounded-box \fromproperty #'header:instrument }
1328     }
1329     \vspace #7
1330     \fontsize #2 \when-property #'header:enteredby \override #'(baseline-skip . 3.75) \left-align\center-column {
1331       \fill-line { "Herausgegeben von: / Edited by:"}
1332       \vspace #0.
1333       \fill-line { \fromproperty #'header:enteredby }
1334     }
1335     \fill-line {
1336       \when-property #'header:arrangement \column {
1337         \vspace #8
1338         \fill-line { \fontsize #3 \fromproperty #'header:arrangement }
1339       }
1340     }
1341   \vspace #6
1342   \fill-line { \fromproperty #'header:copyright }
1345 titleHeaderMarkup = \markup {
1346   \override #'(baseline-skip . 2.75)
1347   \column {
1348     \fill-line {
1349       \fromproperty #'header:logo
1350       \override #'(baseline-skip . 3.25) \center-column {
1351         \bold \abs-fontsize #18 \fromproperty #'header:title
1352         \bold \abs-fontsize #12 \fromproperty #'header:subtitle
1353         \abs-fontsize #11 \fromproperty #'header:subsubtitle
1354       }
1355       \bold \abs-fontsize #11 \when-property #'header:instrument \rounded-box \fromproperty #'header:instrument
1356     }
1357     \fill-line {
1358       \with-dimensions #'( 0 . 0) #'( 0 . 1 ) \null
1359     }
1361     \fill-line {
1362             \abs-fontsize #10 \fromproperty #'header:poet
1363             \abs-fontsize #10 \fromproperty #'header:composer
1364     }
1365     \fill-line {
1366             \abs-fontsize #10 \fromproperty #'header:meter
1367             \abs-fontsize #10 \fromproperty #'header:arranger
1368     }
1369   }
1373 titleScoreMarkup = \markup \piece-title \fromproperty #'header:piece
1375 \paper {
1376   scoreTitleMarkup = \titleScoreMarkup
1377   bookTitleMarkup = \titleHeaderMarkup
1382 %%%%%%%%%%%%%% headers and footers %%%%%%%%%%%%%%%%%%%%%%%%%%
1384 #(define (first-score-page layout props arg)
1385   (let* ((label 'first-score-page)
1386          (table (ly:output-def-lookup layout 'label-page-table))
1387          (label-page (and (list? table) (assoc label table)))
1388          (page-number (and label-page (cdr label-page)))
1389         )
1390     (if (eq? (chain-assoc-get 'page:page-number props -1) page-number)
1391       (interpret-markup layout props arg)
1392       empty-stencil)))
1394 #(define no-header-table '())
1395 thisPageNoHeader = #(define-music-function (parser location) ()
1396   (let* ((label (gensym "header")))
1397     (set! no-header-table (cons label no-header-table))
1398     (make-music 'Music
1399       'page-marker #t
1400       'page-label label)))
1403 % TODO: Use the no-header-table!
1404 #(define (is-header-page layout props arg)
1405   (let* ((page-number (chain-assoc-get 'page:page-number props -1))
1406         )
1407     ;(if (and (> page-number 2) (!= page-number 7))
1408     (if (> page-number 1)
1409       (interpret-markup layout props arg)
1410       empty-stencil)))
1412 #(define no-footer-table '())
1413 thisPageNoFooter = #(define-music-function (parser location) ()
1414   (let* ((label (gensym "footer")))
1415     (set! no-footer-table (cons label no-footer-table))
1416     (make-music 'Music
1417       'page-marker #t
1418       'page-label label)))
1420 % TODO: Use the no-footer-table!
1421 #(define (is-footer-page layout props arg)
1422   (let* ((page-number (chain-assoc-get 'page:page-number props -1))
1423          (label 'first-score-page)
1424          (table (ly:output-def-lookup layout 'label-page-table))
1425          (label-page (and (list? table) (assoc label table)))
1426          ;(page-number (and label-page (cdr label-page)))
1427         )
1428     (if (and (> page-number 1))
1429       (interpret-markup layout props arg)
1430       empty-stencil)))
1433 #(define copyright-footer-table '())
1434 thisPageCopyrightFooter = #(define-music-function (parser location) ()
1435   (let* ((label (gensym "copyrightfooter")))
1436     (set! copyright-footer-table (cons label copyright-footer-table))
1437     (make-music 'Music
1438       'page-marker #t
1439       'page-label label)))
1441 #(define copyright-pg 1)
1442 #(define (set-copyright-page page)
1443   (set! copyright-pg page)
1446 % TODO: Use the copyright-footer-table!
1447 #(define (copyright-page layout props arg)
1448     (if (= (chain-assoc-get 'page:page-number props -1) copyright-pg)
1449       (interpret-markup layout props arg)
1450       empty-stencil))
1453 \paper {
1454   oddHeaderMarkup = \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   evenHeaderMarkup = \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   }
1467   oddFooterMarkup = \markup {
1468     \column {
1469       \fill-line {
1470         %% publisher header field only on title page.
1471         \on-the-fly #first-page \fromproperty #'header:publisher
1472       }
1473       \fill-line {
1474         %% copyright on the first real score page
1475         \on-the-fly #copyright-page \fromproperty #'header:copyright
1476         \on-the-fly #copyright-page \null
1477       }
1478       \fill-line {
1479         %% All other pages get the number of the edition centered
1480         \on-the-fly #is-footer-page \fromproperty #'header:scorenumber
1481       }
1482     }
1483   }
1497 % Interpret the given markup with the header fields added to the props.
1498 % This way, one can re-use the same functions (using fromproperty
1499 % #'header:field) in the header block and as top-level markup.
1501 % This function is originally copied from mark-up-title (file scm/titling.scm),
1502 % which is lilypond's internal function to handle the title markups. I needed
1503 % to replace the scopes and manually add the $defaultheader (which is internally
1504 % done in paper-book.cc before calling mark-up-title. Also, I don't extract the
1505 % markup from the header block, but use the given markup.
1507 % I'm not sure if I really need the page properties in props, too... But I
1508 % suppose it does not hurt, either.
1509 #(define-markup-command (markupWithHeader layout props markup) (markup?)
1510   "Interpret the given markup with the header fields added to the props.
1511    This way, one can re-use the same functions (using fromproperty
1512    #'header:field) in the header block and as top-level markup."
1513   (let* (
1514       ; TODO: If we are inside a score, add the score's local header block, too!
1515       ; Currently, I only use the global header block, stored in $defaultheader
1516       (scopes (list $defaultheader))
1517       (alists (map ly:module->alist scopes))
1519       (prefixed-alist
1520         (map (lambda (alist)
1521           (map (lambda (entry)
1522             (cons
1523               (string->symbol (string-append "header:" (symbol->string (car entry))))
1524               (cdr entry)))
1525             alist))
1526           alists))
1527       (props (append prefixed-alist
1528               props
1529               (layout-extract-page-properties layout)))
1530     )
1531     (interpret-markup layout props markup)
1532   )
1540 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1541 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1542 %%%%%   Equally spacing multiple columns (e.g. for translations)
1543 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1544 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1546 % Credits: Nicolas Sceaux on the lilypond-user mailinglist
1547 #(define-markup-command (columns layout props args) (markup-list?)
1548    (let ((line-width (/ (chain-assoc-get 'line-width props
1549                          (ly:output-def-lookup layout 'line-width))
1550                         (max (length args) 1))))
1551      (interpret-markup layout props
1552        (make-line-markup (map (lambda (line)
1553                                 (markup #:pad-to-box `(0 . ,line-width) '(0 . 0)
1554                                   #:override `(line-width . ,line-width)
1555                                   line))
1556                                args)))))
1560 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1561 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1562 %%%%%   SCORE (HEADER / LAYOUT) SETTINGS
1563 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1564 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1567 startSlashedGraceMusic =  {
1568   \override Stem  #'stroke-style = #"grace"
1571 stopSlashedGraceMusic =  {
1572   \revert Stem #'stroke-style
1575 slashedGrace =
1576 #(def-grace-function startSlashedGraceMusic stopSlashedGraceMusic
1577    (_i "Create slashed graces (slashes through stems, but no slur)from the following music expression"))
1580 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1581 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1582 %%%%%   SCORE (HEADER / LAYOUT) SETTINGS
1583 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1584 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1586 \paper {
1587   left-margin = 2\cm
1588   right-margin = 1.5\cm
1589   line-width = 17.5\cm
1590 %   bottom-margin = 1.5\cm
1591   top-margin = 0.7\cm
1592 %   after-title-space = 0.5\cm
1593   ragged-right = ##f
1594   ragged-last = ##f
1595   ragged-bottom = ##f
1596   ragged-last-bottom = ##f
1598 \layout {
1599   \context {
1600     \ChoirStaff
1601     % If only one non-empty staff in a system exists, still print the backet
1602     \override SystemStartBracket #'collapse-height = #1
1603     \consists "Instrument_name_engraver"
1604     \consists "Keep_alive_together_engraver"
1605   }
1606   \context {
1607     \StaffGroup
1608     % If only one non-empty staff in a system exists, still print the backet
1609     \override SystemStartBracket #'collapse-height = #1
1610     \consists "Instrument_name_engraver"
1611   }
1612   \context {
1613     \GrandStaff
1614     \override SystemStartBracket #'collapse-height = #1
1615     \consists "Instrument_name_engraver"
1616   }
1617   \context {
1618     \FiguredBass
1619 %     \override VerticalAxisGroup #'keep-fixed-while-stretching = ##t
1620 %     \override VerticalAxisGroup #'minimum-Y-extent  = #'(0 . 1) % TODO: Removed
1621     \override VerticalAxisGroup #'padding = #0
1622   }
1623   \context {
1624     \Score
1625     % Force multi-measure rests to be written as one span
1626     \override MultiMeasureRest #'expand-limit = #3
1627     skipBars = ##t
1628     autoBeaming = ##f
1629 %     \override Hairpin #'to-barline = ##f
1630 %     \override BarNumber #'break-visibility = #end-of-line-invisible
1631 %     \override BarNumber #'self-alignment-X = #0
1632 %     barNumberVisibility = #(every-nth-bar-number-visible 5)
1633     \override CombineTextScript #'avoid-slur = #'outside
1634     \override DynamicTextSpanner #'dash-period = #-1.0
1635     \override InstrumentSwitch #'font-size = #-1
1637     % Rest collision
1638     \override RestCollision #'positioning-done = #merge-rests-on-positioning
1639     % Auto-Accidentals: Use modern-cautionary style...
1640     extraNatural = ##f
1641     % Accidental rules (the rule giving the most accidentals wins!)
1642     % -) Reset accidentals at each barline -> accs not in key sig will always be printed
1643     % -) Same octave accidentals are remembered for two measures -> cancellation
1644     % -) other octave accidentals are remembered for next measure -> cancellation
1645     autoAccidentals = #`(Staff  ,(make-accidental-rule 'same-octave 0)
1646                                 ,(make-accidental-rule 'any-octave 0)
1647                                 ,(make-accidental-rule 'any-octave 1)
1648                                 ,(make-accidental-rule 'same-octave 2))
1649     % No auto-cautionaries, we always use autoAccidentals!
1650 %     autoCautionaries = #`(Staff ,(make-accidental-rule 'any-octave 0)
1651 %                                 ,(make-accidental-rule 'same-octave 1))
1652     printKeyCancellation = ##t
1653     quotedEventTypes = #'(StreamEvent)
1654     quotedCueEventTypes = #'(
1655       rhythmic-event
1656       tie-event
1657       beam-event
1658       tuplet-span-event
1659       tremolo-event
1660       glissando-event
1661       harmonic-event
1662       repeat-tie-event
1663       articulation-event
1664       slur-event
1665       trill-span-event
1666       tremolo-span-event
1667     )
1668     implicitBassFigures = #'(0 100)
1669   }
1670   \context {
1671     \Staff
1672     \RemoveEmptyStaves
1673   }
1677 ts = ^\markup{"t.s."}
1678 tt = ^\markup{"Tutti"}
1679 solo = ^\markup{"Solo"}
1680 tutti = ^\markup{"Tutti"}
1681 bracketts = ^\markup{"[Solo]"}
1682 brackettt = ^\markup{"[Tutti]"}
1683 bracketsolo = ^\markup{"[Solo]"}
1685 sottovoce = \markup "sotto voce"
1687 dashedSlur = -\tweak #'dash-definition #'((0 1 0.4 0.75))(
1688 dashedTie = -\tweak #'dash-definition #'((0 1 0.4 0.75))~
1690 divisi = #(define-music-function (parser location vc1 vc2) (ly:music? ly:music?)
1692   << { \voiceOne $vc1 \oneVoice} \context Voice = "divisi2" { \voiceTwo $vc2 } >>
1696 #(define twoVoice divisi)
1698 #(define-public (bracket-stencils grob)
1699   (let ((lp (grob-interpret-markup grob (markup #:fontsize 3.5 #:translate (cons -0.3 -0.5) "[")))
1700         (rp (grob-interpret-markup grob (markup #:fontsize 3.5 #:translate (cons -0.3 -0.5) "]"))))
1701     (list lp rp)))
1703 bracketify = #(define-music-function (parser loc arg) (ly:music?)
1704    (_i "Tag @var{arg} to be parenthesized.")
1706   \once \override ParenthesesItem #'stencils = #bracket-stencils
1707   \parenthesize $arg
1712 #(define-markup-command (hat layout props arg) (markup?)
1713   "Draw a hat above the given string @var{arg}."
1714   (interpret-markup layout props (markup #:combine #:raise 1.5 "^" arg)))
1718 smallFlageolet =
1719 #(let ((m (make-music 'ArticulationEvent
1720                       'articulation-type "flageolet")))
1721    (ly:music-set-property! m 'tweaks
1722      (acons 'font-size -2
1723        (ly:music-property m 'tweaks)))
1724   m)
1727 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1728 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1729 %%%%%   LICENSE TEXTS
1730 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1731 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1733 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" }}
1734 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" }}
1735 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" }}
1736 LicenseNoRestrictions = \markup{\line {Die Ausgabe darf kopiert und ohne Einschränkungen aufgeführt werden. / May be copied and performed without restriction.}}
1738 \include "sceaux_clef-key.ily"
1741 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1742 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1743 %%%%%   VARIOUS
1744 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1745 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1747 startUnremovableSection = \set Staff.keepAliveInterfaces =
1748  #'(rhythmic-grob-interface
1749     rest-interface
1750     lyric-interface
1751     percent-repeat-item-interface
1752     percent-repeat-interface
1753     stanza-number-interface)
1755 endUnremovableSection = \unset Staff.keepAliveInterfaces
1758 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1759 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1760 %%%%%   EDITORIAL ANNOTATIONS
1761 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1762 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1764 #(define-public (editorial-bracket-stencil stil padding widen)
1765 "Add brackets for editorial annoations around STIL, producing a new stencil."
1766 (let* ((axis Y)
1767        (other-axis (lambda (a) (remainder (+ a 1) 2)))
1768        (ext (interval-widen (ly:stencil-extent stil axis) widen))
1769        (thick 0.15)
1770        (protrusion 0.3)
1771        (lb (ly:bracket axis ext thick protrusion))
1772        (rb (ly:bracket axis ext thick (- protrusion))))
1773   (set! stil (ly:stencil-combine-at-edge stil (other-axis axis) 1 rb padding))
1774   (set! stil
1775     (ly:stencil-combine-at-edge lb (other-axis axis) 1 stil padding))
1776   stil))
1778 editorialHairpin = \once \override Hairpin     #'stencil = #(lambda (grob) (editorial-bracket-stencil (ly:hairpin::print grob) 0.2 0.55))
1779 editorialDynamic = \once \override DynamicText #'stencil = #(lambda (grob) (editorial-bracket-stencil (ly:text-interface::print grob) 0.2 0.55))
1780 editorialMarkup =  \once \override TextScript  #'stencil = #(lambda (grob) (editorial-bracket-stencil (ly:text-interface::print grob) 0.2 0.55))
1782 % videStart = \mark \markup { \hspace #1 \musicglyph #"scripts.coda"  \with-dimensions #'(0 . 0) #'(0 . 0) \left-align { vi-} }
1783 videStart = \mark \markup \halign #-2.3 \concat { \hspace #4.5 \musicglyph #"scripts.coda" \left-align { vi- } }
1784 % videEnd = \notemode {
1785 %   \once \override Score.RehearsalMark #'break-visibility = #begin-of-line-invisible
1786 %   \mark \markup \concat{ \with-dimensions #'(0 . 0) #'(0 . 0) \right-align { -de } \hspace #1 \musicglyph #"scripts.coda" }
1788 videEnd = \notemode {
1789         \once \override Score.RehearsalMark #'break-visibility = #begin-of-line-invisible
1790         \mark \markup \concat{ \right-align { -de } \hspace #1.5 \musicglyph #"scripts.coda" \hspace #4.2 }
1795 \layout {
1796         \context {\Staff
1797                 soloText = #"I"
1798                 soloIIText = #"II"
1799                 aDueText = #"a2"
1800         }
1803 \paper {
1804 %         markup-system-spacing = #'((space . 4) (padding . 2) (stretchability . 20))
1805         markup-system-spacing #'minimum-distance = #0
1806         markup-system-spacing #'space = #4
1807         markup-system-spacing #'padding = #2
1808         markup-system-spacing #'stretchability = #40
1809 %       system-system-spacing = #'((space . 0) (padding . 20) (stretchability . 50))
1810         system-system-spacing #'minimum-distance = #0
1811         system-system-spacing #'space = #5
1812         system-system-spacing #'padding = #2
1813         system-system-spacing #'stretchability = #50
1814         top-system-spacing #'minimum-distance = #0
1815         top-system-spacing #'space = #5
1816         top-system-spacing #'padding = #2
1817         top-system-spacing #'stretchability = #20
1818         last-bottom-spacing #'minimum-distance = #0
1819         last-bottom-spacing #'space = #5
1820         last-bottom-spacing #'padding = #2
1821         last-bottom-spacing #'stretchability = #20
1823         score-markup-spacing #'space = #5
1824         score-markup-spacing #'stretchability = #50
1826         markup-markup-spacing #'space = #5
1827         markup-markup-spacing #'stretchability = #30
1829 \layout {
1830         \context { \StaffGroup
1831 %               \override StaffGrouper #'staff-staff-spacing #'space = 5
1832                 \override StaffGrouper #'staff-staff-spacing #'stretchability = #4.5
1833         }
1834         \context { \GrandStaff
1835 %               \override StaffGrouper #'staff-staff-spacing #'space = 5
1836                 \override StaffGrouper #'staff-staff-spacing #'stretchability = #4.5
1837         }
1838         \context { \ChoirStaff
1839 %               \override StaffGrouper #'staff-staff-spacing #'space = 5
1840                 \override StaffGrouper #'staff-staff-spacing #'stretchability = #3
1841         }
1842         \context { \Staff
1843 %               \override StaffGrouper #'staff-staff-spacing #'space = 1
1844                 \override StaffGrouper #'staff-staff-spacing #'stretchability = #4.9
1845         }
1846         \context { \Score
1847 %               \override StaffGrouper #'staff-staff-spacing #'space = 5
1848                 \override StaffGrouper #'staff-staff-spacing #'stretchability = #5
1849         }
1850         \context { \Lyrics
1851                 \override VerticalAxisGroup #'nonstaff-nonstaff-spacing #'minimum-distance = ##f
1852         }
1855   system-system-spacing = #'((space . 12) (minimum-distance . 8) (padding . 1) (stretchability . 60))
1856   score-system-spacing = #'((space . 14) (minimum-distance . 8) (padding . 1) (stretchability . 120))
1857   markup-system-spacing = #'((space . 5) (padding . 0.5) (stretchability . 30))
1858   score-markup-spacing = #'((space . 12) (padding . 0.5) (stretchability . 60))
1859   markup-markup-spacing = #'((space . 1) (padding . 0.5))
1860   top-system-spacing = #'((space . 1) (padding . 1) (minimum-distance . 0))
1861   top-markup-spacing = #'((space . 0) (padding . 1) (minimum-distance . 0))
1862   last-bottom-spacing = #'((space . 1) (padding . 1) (minimum-distance . 0) (stretchability . 30))%}