Templates/Webshop: Also add English Translation of Orchesterstimmen
[orchestrallily.git] / orchestrallily.ily
blob37194ec90f45f5aec1a5c4d7a6194173d8beb2ea
1 \version "2.15.19"
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)
31 \include "sceaux_clef-key.ily"
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 %%%%%   SCORE STRUCTURE AND AUTOMATIC GENERATION
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 % Helper functions
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47 % Helper function to filter all non-null entries
48 #(define (not-null? x) (not (null? x)))
50 % Helper function to extract a given variable, built from [Piece][Instrument]Identifier
51 #(define (namedPieceInstrObject piece instr name)
52   (let* (
53          (fullname  (string->symbol (string-append piece instr name)))
54          (instrname (string->symbol (string-append instr name)))
55          (piecename (string->symbol (string-append piece name)))
56          (fallback  (string->symbol name))
57         )
58     (cond
59       ((defined? fullname) (primitive-eval fullname))
60       ((defined? instrname) (primitive-eval instrname))
61       ((defined? piecename) (primitive-eval piecename))
62       ((defined? fallback) (primitive-eval fallback))
63       (else '())
64     )
65   )
68 %% Print text as a justified paragraph, taken from the lilypond Notation Reference
69 #(define-markup-list-command (paragraph layout props args) (markup-list?)
70    (let ((indent (chain-assoc-get 'par-indent props 2)))
71      (interpret-markup-list layout props
72        (make-justified-lines-markup-list (cons (make-hspace-markup indent)
73                                                args)))))
75 conditionalBreak = #(define-music-function (parser location) ()
76    #{ \tag #'instrumental-score \pageBreak #}
79 #(define (oly:piece-title-markup title) (markup #:column (#:line (#:fontsize #'3 #:bold title))) )
81 #(define-markup-command (piece-title layout props title) (markup?)
82      (interpret-markup layout props (oly:piece-title-markup title))
85 #(define (oly:generate_object_name piece instr obj )
86   (if (and (string? piece) (string? instr) (string? obj))
87     (string-append piece instr obj)
88     #f
89   )
91 #(define (oly:generate_staff_name piece instr) (oly:generate_object_name piece instr "St"))
93 #(define (set-context-property context property value)
94   (set! (ly:music-property context property) value)
98 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99 % Score structure and voice types
100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102 #(define oly:LiedScoreStructure '(
103   ("SoloScore" "SimultaneousMusic" ("Singstimme"))
104   ("Pfe" "PianoStaff" ("PfeI" "PfeII"))
105   ;("PfeI" "ParallelVoicesStaff" ("OIa" "OIb"))
106   ;("PfeII" "ParallelVoicesStaff" ("OIIa" "OIIb"))
107   ("FullScore" "SimultaneousMusic" ("Singstimme" "Pfe"))
108   ("VocalScore" "SimultaneousMusic" ("Singstimme" "Pfe"))
111 #(define oly:StringEnsembleScoreStructure '(
112   ("FullScore" "StaffGroup" ("VI" "VII" "Va" "Vc" "Cb" "VcB"))
115 #(define oly:fullOrchestraScoreStructure '(
116 ; Part-combined staves for full score
117   ("Fl" "PartCombinedStaff" ("FlI" "FlII"))
118   ("Ob" "PartCombinedStaff" ("ObI" "ObII"))
119   ("Cl" "PartCombinedStaff" ("ClI" "ClII"))
120   ("Fag" "PartCombinedStaff" ("FagI" "FagII"))
121   ("Wd" "StaffGroup" ("Fl" "Ob" "Cl" "Fag" "CFag"))
123   ("Cor" "PartCombinedStaff" ("CorI" "CorII"))
124   ("Tbe" "PartCombinedStaff" ("TbeI" "TbeII"))
125   ("Clni" "PartCombinedStaff" ("ClnoI" "ClnoII"))
126   ("Trb" "PartCombinedStaff" ("TrbI" "TrbII"))
127   ("Br" "StaffGroup" ("Cor" "Tbe" "Clni" "Trb" "Tba"))
129 ; long score; no part-combined staves, but GrandStaves instead
130   ("FlLong" "GrandStaff" ("FlI" "FlII"))
131   ("ObLong" "GrandStaff" ("ObI" "ObII"))
132   ("ClLong" "GrandStaff" ("ClI" "ClII"))
133   ("FagLong" "GrandStaff" ("FagI" "FagII"))
134   ("WdLong" "StaffGroup" ("FlLong" "ObLong" "ClLong" "FagLong" "CFag"))
136   ("CorLong" "GrandStaff" ("CorI" "CorII"))
137   ("TbeLong" "GrandStaff" ("TbeI" "TbeII"))
138   ("ClniLong" "GrandStaff" ("ClnoI" "ClnoII" "ClnoIII"))
139   ("TrbLong" "GrandStaff" ("TrbI" "TrbII" "TrbIII"))
140   ("BrLong" "StaffGroup" ("CorLong" "TbeLong" "ClniLong" "TrbLong" "Tba"))
142 ; Percussion
143   ("Perc" "StaffGroup" ("Tim"))
145 ; Strings, they are the same in long and short full score
146   ("VV" "GrandStaff" ("VI" "VII"))
147   ("Str" "StaffGroup" ("VV" "Va"))
148   ("VceB" "StaffGroup" ("Vc" "Cb" "VcB"))
149   ("FullStr" "StaffGroup" ("VV" "Va" "Vc" "Cb" "VcB"))
151 ; Choral score
152   ("Solo" "SimultaneousMusic" ("SSolo" "ASolo" "TSolo" "BSolo"))
153   ("Ch" "ChoirStaff" ("S" "A" "T" "B"))
154   ("ChoralScore" "SimultaneousMusic" ("Ch"))
155   ("SoloScore" "SimultaneousMusic" ("Solo"))
156   ("SoloChoirScore" "SimultaneousMusic" ("Solo" "Ch"))
158 ; Organ score (inkl. Figured bass)
159   ("BCFb" "FiguredBass" ())
160   ("FiguredBass" "FiguredBass" ())
161   ;("Organ" "SimultaneousMusic" ("BCFb" "O"))
162   ("Continuo" "ParallelVoicesStaff" ("BCFb" "BC" "FiguredBass"))
163   ("RealizedContinuo" "PianoStaff" ("BCRealization" "Continuo"))
165   ("P" "PianoStaff" ("PI" "PII"))
166   ("O" "PianoStaff" ("OI" "OII"))
167   ("OI" "ParallelVoicesStaff" ("OIa" "OIb"))
168   ("OII" "ParallelVoicesStaff" ("OIIa" "OIIb"))
170   ;("Organ" "SimultaneousMusic" ("OGroup" "RealizedContinuo"))
171   ;("BassGroup" "ParallelVoicesStaff" ("Organ" "O" "BC" "VceB"))
172   ("BassGroup" "StaffGroup" ("O" "RealizedContinuo" "Vc" "Cb" "VcB"))
174 ; Full Scores
175   ("FullScore" "SimultaneousMusic" ("Wd" "Br" "Perc" "Str" "SoloChoirScore" "BassGroup"))
176   ("LongScore" "SimultaneousMusic" ("WdLong" "BrLong" "Perc" "Str" "SoloChoirScore" "BassGroup"))
177   ("OriginalScore" "SimultaneousMusic" ("BrLong" "WdLong" "Perc" "Str" "SoloChoirScore" "BassGroup"))
179 ; Piano reduction
180   ;("Piano" "SimultaneousMusic" ("Organ"))
181   ("OrganScore" "SimultaneousMusic" ("SoloChoirScore" "O"))
182   ("VocalScore" "SimultaneousMusic" ("SoloChoirScore" "P"))
183   ("Particell"  "SimultaneousMusic" ("ChoralScore" "BassGroup"))
185 ; Full scores: Orchestral score and long score including organ
186   ("ChStrQ" "SimultaneousMusic" ("Str" "Ch" "VceB"))
188 #(define oly:orchestral_score_structure oly:fullOrchestraScoreStructure)
190 #(define (oly:set_score_structure struct)
191   (if (list? struct)
192     (set! oly:orchestral_score_structure struct)
193     (ly:warning (_ "oly:set_score_structure needs an association list as argument!"))
194   )
197 #(define (oly:modify_score_structure entry)
198   (if (list? entry)
199     (set! oly:orchestral_score_structure (assoc-set! oly:orchestral_score_structure  (car entry) (cdr entry)))
200     (ly:warning (_ "oly:modify_score_structure expects a list (\"key\" \"type\" '(children)) as argument!"))))
202 #(define (oly:remove_from_score_structure entry)
203   (if (list? entry)
204     (map oly:remove_from_score_structure entry)
205     (set! oly:orchestral_score_structure (assoc-remove! oly:orchestral_score_structure  entry))))
207 orchestralScoreStructure = #(define-music-function (parser location structure) (list?)
208   (oly:set_score_structure structure)
209   (make-music 'Music 'void #t)
212 #(define oly:voice_types '())
214 #(define (oly:set_voice_types types)
215   (if (list? types)
216     (set! oly:voice_types types)
217     (ly:warning (_ "oly:set_voice_types needs an association list as argument!"))
218   )
221 orchestralVoiceTypes = #(define-music-function (parser location types) (list?)
222   (oly:set_voice_types types)
223   (make-music 'Music 'void #t)
227 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
228 % Automatic staff and group generation
229 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
231 % Retrieve all music definitions for the given
232 #(define (oly:get_music_object piece instrument)
233   (namedPieceInstrObject piece instrument "Music")
235 #(define (oly:get_music_objects piece instruments)
236   (filter not-null? (map (lambda (i) (oly:get_music_object piece i)) instruments))
239 % Given a property name and the extensions, either generate the pair to set
240 % the property or an empty list, if no pre-defined variable could be found
241 #(define (oly:generate_property_pair prop piece instr type)
242   (let* ((val (namedPieceInstrObject piece instr type)))
243     (if (not-null? val) (list 'assign prop val) '() )
244   )
247 #(define (oly:staff_type type)
248   (cond
249     ((string? type) (string->symbol type))
250     ((symbol? type) type)
251     (else 'Staff)
252   )
255 % extract the pitch from the music (can also be a raw pitch object!)
256 #(define (oly:extractPitch music)
257   (let* (
258          (elems  (if (ly:music? music) (ly:music-property music 'elements)))
259          (note   (if (pair? elems) (car elems)))
260          (mpitch (if (ly:music? note) (ly:music-property note 'pitch)))
261          (pitch  (if (ly:pitch? music) music mpitch))
262         )
263     (if (and (not-null? music) (not (ly:pitch? pitch)))
264       (ly:warning "Unable to interpret as a pitch!")
265     )
266     pitch
267   )
270 #(define (oly:extractTranspositionPitch piece name)
271   (let* (
272          (trpFromPitch (oly:extractPitch (namedPieceInstrObject piece name "TransposeFrom")))
273          (trpToPitch   (oly:extractPitch (namedPieceInstrObject piece name "TransposeTo")))
274         )
275     (if (ly:pitch? trpFromPitch)
276       (if (ly:pitch? trpToPitch)
277         ; Both pitches
278         (ly:pitch-diff trpFromPitch trpToPitch)
279         (ly:pitch-diff trpFromPitch (ly:make-pitch 0 0 0))
280       )
281       (if (ly:pitch? trpToPitch)
282         (ly:pitch-diff (ly:make-pitch 0 0 0) trpToPitch)
283         #f
284       )
285     )
286   )
290 %%=====================================================================
291 %% Extract context modifications for given objects
292 %%---------------------------------------------------------------------
295 % TODO: join these property extractors to avoid code duplication
297 % Generate the properties for the lyrics for piece and instr.
298 % Also check whether we have a modifications object to fech mods from.
299 % return a (possibly empty) list of all assignments.
300 #(define (oly:lyrics_handler_properties piece name lyricsid)
301   (let* (
302          (mods (namedPieceInstrObject piece name (string-append lyricsid "Modifications")))
303          (mod-list (if (not-null? mods) (ly:get-context-mods mods) '()))
304          (mapping '(
305              ;(instrumentName . "InstrumentName")
306              ;(shortInstrumentName . "ShortInstrumentName")
307              ;(midiInstrument . "MidiInstrument")
308             ))
309          (assignments (map
310              (lambda (pr)
311                  (oly:generate_property_pair (car pr) piece name (cdr pr))
312              )
313              mapping))
314          (olyprops (filter not-null? assignments))
315          (props (append mod-list olyprops))
316         )
317     props
318   )
321 % Generate the properties for the voice for piece and instr.
322 % Also check whether we have a modifications object to fech mods from.
323 % return a (possibly empty) list of all assignments.
324 #(define (oly:voice_handler_properties piece name)
325   (let* (
326          (mods (namedPieceInstrObject piece name "VoiceModifications"))
327          (mod-list (if (not-null? mods) (ly:get-context-mods mods) '()))
328          (mapping '(
329              ;(instrumentName . "InstrumentName")
330              ;(shortInstrumentName . "ShortInstrumentName")
331              ;(midiInstrument . "MidiInstrument")
332             ))
333          (assignments (map
334              (lambda (pr)
335                  (oly:generate_property_pair (car pr) piece name (cdr pr))
336              )
337              mapping))
338          (olyprops (filter not-null? assignments))
339          (props (append mod-list olyprops))
340         )
341     props
342   )
345 % Generate the properties for the staff for piece and instr. Typically, these
346 % are the instrument name and the short instrument name (if defined).
347 % Also check whether we have a modifications object to fech mods from.
348 % return a (possibly empty) list of all assignments.
349 #(define (oly:staff_handler_properties piece instr)
350   (let* (
351          (mods (namedPieceInstrObject piece instr "StaffModifications"))
352          (mod-list (if (not-null? mods) (ly:get-context-mods mods) '()))
353          (mapping '(
354               (instrumentName . "InstrumentName")
355               (shortInstrumentName . "ShortInstrumentName")
356               (midiInstrument . "MidiInstrument")
357             ))
358          (assignments (map
359              (lambda (pr)
360                  (oly:generate_property_pair (car pr) piece instr (cdr pr))
361              )
362              mapping))
363          (olyprops (filter not-null? assignments))
364          (props (append mod-list olyprops))
365         )
366     props
367   )
370 %% Process the extracted object, e.g. wrap \clef around the 
371 %% string for "type"=="Clef", etc.
372 % This allows a more fine-grained post-processing of the global vars
373 #(define (oly:processExtractedObject piece name type object)
374   (if (and (string=? type "Clef") (string? object))
375       (make-ancient-or-modern-clef object) ;; Use Nicolas Sceaux' old/modern clef notation
376       object))
380 %%=====================================================================
381 %% Extract contents for voices
382 %%---------------------------------------------------------------------
384 #(define (oly:musiccontent_for_voice parser piece name music additional)
385   (let* ((musiccontent additional))
387     ; Append the settings, key and clef (if defined)
388     (map
389       (lambda (type)
390         (let* ((object (oly:processExtractedObject piece name type (namedPieceInstrObject piece name type))))
391           (if (ly:music? object)
392             (set! musiccontent (append musiccontent (list (ly:music-deep-copy object))))
393             (if (not-null? object) (ly:warning (_ "Wrong type (no ly:music) for ~S for instrument ~S in piece ~S") type name piece))
394           )
395         )
396       )
397       ; TODO: Does the "Tempo" work here???
398       '("Settings" "Key" "Clef" "TimeSignature" "ExtraSettings";"Tempo"
399       )
400     )
402     (if (ly:music? music)
403       (begin
404         (set! musiccontent (make-sequential-music (append musiccontent (list music))))
405         ;(ly:message "Generating staff for ~a" name)
406         (let* ((trpPitch (oly:extractTranspositionPitch piece name)))
407           (if (ly:pitch? trpPitch)
408             (set! musiccontent (ly:music-transpose musiccontent trpPitch))
409           )
410         )
411         musiccontent
412       )
413       ; For empty music, return empty
414       '()
415     )
416   )
421 %%=====================================================================
422 %% create Lyrics
423 %%---------------------------------------------------------------------
426 #(define (oly:lyrics_create_single_context parser piece name voicename lyricsid)
427   ; If we have lyrics, create a lyrics context containing LyricCombineMusic
428   ; and add that as second element to the staff's elements list...
429   ; Also add possibly configured LyricsModifications
430   (let* ((id (string-append "Lyrics" lyricsid))
431          (lyricsmods (oly:lyrics_handler_properties piece name id))
432          (lyrics (namedPieceInstrObject piece name id))
433          (ctx (if (ly:music? lyrics)
434                   (context-spec-music (make-music 'LyricCombineMusic
435                                                   'element lyrics
436                                                   'associated-context voicename)
437                                       'Lyrics
438                                       (oly:generate_object_name piece name id))
439                   '())))
440     (if (and (not-null? lyricsmods) (not-null? ctx))
441       (set! (ly:music-property ctx 'property-operations) lyricsmods)
442     )
443     ctx
444   )
447 #(define (oly:lyrics_create_contexts parser piece name voicename)
448   (filter not-null?
449     (map (lambda (str)
450                  (oly:lyrics_create_single_context parser piece name voicename str))
451          (list "" "I" "II" "III"  "IV" "V" "VI"))))
454 %%=====================================================================
455 %% Voice handling
456 %%---------------------------------------------------------------------
459 #(define (oly:voice_handler_internal parser piece name type music)
460   (if (ly:music? music)
461     (let* (
462            (voicename    (oly:generate_object_name piece name "Voice" ))
463            (lyrics       (oly:lyrics_create_contexts parser piece name voicename))
464            (additional   (if (not-null? lyrics) (list dynamicUp) '()))
465            (musiccontent (oly:musiccontent_for_voice parser piece name music additional))
466            (voicetype    (oly:staff_type type))
467            (voice        (context-spec-music musiccontent voicetype voicename))
468            (voiceprops   (oly:voice_handler_properties piece name))
469           )
470       (if (not-null? voiceprops)
471         (set! (ly:music-property voice 'property-operations) voiceprops)
472       )
473       (cons voice lyrics)
474     )
475     ; For empty music, return empty
476     '()
477   )
480 #(define (oly:voice_handler parser piece name type)
481   (oly:voice_handler_internal parser piece name type (oly:get_music_object piece name)))
484 %%=====================================================================
485 %% Staff/Group handling
486 %%---------------------------------------------------------------------
489 #(define (oly:staff_handler_internal parser piece name type voices)
490   (if (not-null? voices)
491     (let* (
492            (staffname  (oly:generate_staff_name piece name))
493            (stafftype  (oly:staff_type type))
494            (staff      (make-simultaneous-music voices))
495            (propops    (oly:staff_handler_properties piece name))
496           )
497       (case stafftype
498         ((SimultaneousMusic ParallelMusic) #f)
499         (else (set! staff (context-spec-music staff stafftype staffname)))
500       )
501       (if (not-null? propops)
502         (set! (ly:music-property staff 'property-operations) propops)
503       )
504       staff
505     )
506     ; For empty music, return empty
507     '()
508   )
511 #(define (oly:staff_handler parser piece name type children)
512   (let* ((c (if (not-null? children) children (list name)))
513          (voices (apply append (map (lambda (v) (oly:create_voice parser piece v)) c)) )
514         )
515     (if (not-null? voices)
516       (oly:staff_handler_internal parser piece name type voices)
517       '()
518     )
519   )
522 #(define (oly:devnull_handler parser piece name type children)
523   (oly:voice_handler parser piece name type)
526 #(define (oly:parallel_voices_staff_handler parser piece name type children)
527   (let* (
528          (voices (map (lambda (i) (oly:create_voice parser piece i)) children))
529          ; get the list of non-empty voices and flatten it!
530          (nonemptyvoices (apply append (filter not-null? voices)))
531         )
532     (if (not-null? nonemptyvoices)
533       (oly:staff_handler_internal parser piece name "Staff" nonemptyvoices)
534       '()
535     )
536   )
539 #(define (oly:remove-with-tag tag music)
540   (if (ly:music? music)
541       (music-filter
542         (lambda (m)
543           (let* ((tags (ly:music-property m 'tags))
544                  (res (memq tag tags)))
545             (not res)))
546         music)
547       music))
549 % Remove all music tagged a not-part-combine
550 #(define (oly:remove-non-part-combine-events music)
551   (oly:remove-with-tag 'non-partcombine music))
553 #(define (oly:part_combined_staff_handler parser piece name type children)
554   (let* ((rawmusic (map (lambda (c) (oly:musiccontent_for_voice parser piece name (oly:get_music_object piece c) '())) children))
555          (filteredmusic (map (lambda (m) (oly:remove-non-part-combine-events m)) rawmusic))
556          (music (filter not-null? filteredmusic)))
557   (cond
558       ((and (pair? music) (ly:music? (car music)) (not-null? (cdr music)) (ly:music? (cadr music)))
559           ;(ly:message "Part-combine with two music expressions")
560           (oly:staff_handler_internal parser piece name "Staff" (list (make-part-combine-music parser music #f))))
561       ((null? music)
562           ;;(ly:warning "Part-combine without any music expressions")
563           '())
564       ; exactly one is a music expression, simply use that by joining
565       ((list? music)
566           ;;(ly:message "Part-combine with only one music expressions")
567           (oly:staff_handler_internal parser piece name "Staff" (list (apply append music))))
568       (else
569           ;(ly:message "make_part_combined_staff: ~S ~S ~a" piece instr instruments)
570           '() )
571     )
572   )
575 % Figured bass is a special case, as it can be voice- or staff-type. When
576 % given as a staff type, simply call the voice handler, instead
578 #(define (oly:figured_bass_staff_handler parser piece name type children)
579   (let* ((c (if (not-null? children) children (list name)))
580          (voice  (oly:voice_handler parser piece (car c) type)))
581     (if (pair? voice) (car voice) ())
582   )
585 #(define (flatten lst)
586   (define (f remaining result)
587     (cond
588       ((null? remaining) result)
589       ((pair? (car remaining)) (f (cdr remaining) (f (car remaining) result)))
590       (else (f (cdr remaining) (cons (car remaining) result)))))
591   (reverse! (f lst '())))
593 #(define (oly:staff_group_handler parser piece name type children)
594   (let* (
595          (staves (flatten (map (lambda (i) (oly:create_staff_or_group parser piece i)) children)))
596          (nonemptystaves (filter not-null? staves))
597         )
598     (if (not-null? nonemptystaves)
599       (let* (
600              (musicexpr (if (= 1 (length nonemptystaves))
601                           (car nonemptystaves)
602                           (make-simultaneous-music nonemptystaves)))
603              (groupname (oly:generate_staff_name piece name))
604              (grouptype (oly:staff_type type))
605              (group     musicexpr)
606              (propops   (oly:staff_handler_properties piece name))
607             )
608         (case grouptype
609           ((SimultaneousMusic ParallelMusic) #f)
610           (else (set! group (context-spec-music group grouptype groupname)))
611         )
612         (if (pair? propops)
613           (set! (ly:music-property group 'property-operations) propops))
614         group
615       )
616       ; Return empty list if no staves are generated
617       '()
618     )
619   )
622 #(define (oly:create_voice parser piece name)
623   (let* ( (voice (namedPieceInstrObject piece name "Voice"))
624           (type (assoc-ref oly:voice_types name)) )
625     (if (not-null? voice)
626       ; Explicit voice variable, use that
627       voice
629       (if (not type)
630         ; No entry in structure found => simple voice
631         (oly:voice_handler parser piece name "Voice")
632         ; Entry found in structure => use the handler for the given type
633         (let* (
634                (voicetype (car type))
635                (handler (assoc-ref oly:voice_handlers voicetype))
636               )
637           (if handler
638             ((primitive-eval handler) parser piece name voicetype)
639             (begin
640               (ly:warning "No handler found for voice type ~a, using default voice handler" voicetype)
641               (oly:voice_handler parser piece name voicetype)
642             )
643           )
644         )
645       )
646     )
647   )
650 #(define (oly:create_staff_or_group parser piece name)
651   (let* ( (staff (namedPieceInstrObject piece name "Staff"))
652           (type_from_structure (assoc-ref oly:orchestral_score_structure name)) )
653     ;(if (not-null? staff)
654     ;  (ly:message "Found staff variable for instrument ~a in piece ~a"  instr piece)
655     ;  (ly:message "Staff variable for instrument ~a in piece ~a NOT FOUND"  instr piece)
656     ;)
657     (if (not-null? staff)
658       ; Explicit staff variable, use that
659       staff
661       (if (not (list? type_from_structure))
662         ; No entry in structure found => simple staff
663         (oly:staff_handler parser piece name "Staff" '())
665         ; Entry found in structure => use the handler for the given type
666         (let* ((type (car type_from_structure))
667                (handler (assoc-ref oly:staff_handlers type))
668                (children (cadr type_from_structure))
669               )
670           (if handler
671             ((primitive-eval handler) parser piece name type children)
672             (begin
673               (ly:warning "No handler found for staff type ~a, using default staff handler" type)
674               (oly:staff_handler parser piece name type children)
675             )
676           )
677         )
678       )
679     )
680   )
683 #(define (oly:dynamics_handler parser piece name type children)
684   (oly:voice_handler parser piece name type)
688 %%=====================================================================
689 %% Handler definitions
690 %%---------------------------------------------------------------------
692 #(define oly:staff_handlers
693   (list
694     ; staff group types
695     '("GrandStaff" . oly:staff_group_handler )
696     '("PianoStaff" . oly:staff_group_handler )
697     '("ChoirStaff" . oly:staff_group_handler )
698     '("StaffGroup" . oly:staff_group_handler )
699     '("ParallelMusic" . oly:staff_group_handler )
700     '("SimultaneousMusic" . oly:staff_group_handler )
701     ; staff types
702     '("Staff" . oly:staff_handler )
703     '("DrumStaff" . oly:staff_handler )
704     '("RhythmicStaff" . oly:staff_handler )
705     '("TabStaff" . oly:staff_handler )
706     '("GregorianTranscriptionStaff" . oly:staff_handler )
707     '("MensuralStaff" . oly:staff_handler )
708     '("VaticanaStaff" . oly:staff_handler )
709     '("ChordNames" . oly:staff_handler )
710     ; staves with multiple voices
711     '("PartCombinedStaff" . oly:part_combined_staff_handler )
712     '("ParallelVoicesStaff" . oly:parallel_voices_staff_handler )
713     ; special cases: Figured bass can be staff or voice type!
714     '("FiguredBass" . oly:figured_bass_staff_handler )
715     ; Devnull is like a staff, only that it doesn't craete output
716     '("Devnull" . oly:devnull_handler )
717     '("Dynamics" . oly:dynamics_handler )
718   )
721 #(define oly:voice_handlers
722   (list
723     ; voice types
724     '("Voice" . oly:voice_handler )
725     '("CueVoice" . oly:voice_handler )
726     '("DrumVoice" . oly:voice_handler )
727     '("FiguredBass" . oly:voice_handler )
728     '("ChordNames" . oly:voice_handler )
729     '("GregorianTranscriptionVoice" . oly:voice_handler )
730     '("NoteNames" . oly:voice_handler )
731     '("TabVoice" . oly:voice_handler )
732     '("VaticanaVoice" . oly:voice_handler )
733   )
737 #(define (oly:register_staff_type_handler type func)
738 ;  (ly:message "Registering staff handler ~a for type ~a" func type)
739   (set! oly:staff_handlers (assoc-set! oly:staff_handlers type func))
742 #(define (oly:register_voice_type_handler type func)
743 ;  (ly:message "Registering voice type handler ~a for type ~a" func type)
744   (set! oly:voice_handlers (assoc-set! oly:voice_handlers type func))
747 % handlers for deprecated API
748 #(oly:register_staff_type_handler 'StaffGroup 'oly:staff_group_handler)
749 #(oly:register_staff_type_handler 'GrandStaff 'oly:staff_group_handler)
750 #(oly:register_staff_type_handler 'PianoStaff 'oly:staff_group_handler)
751 #(oly:register_staff_type_handler 'ChoirStaff 'oly:staff_group_handler)
752 #(oly:register_staff_type_handler 'Staff 'oly:staff_handler )
753 #(oly:register_staff_type_handler 'ParallelMusic 'oly:staff_group_handler)
754 #(oly:register_staff_type_handler 'SimultaneousMusic 'oly:staff_group_handler)
755 #(oly:register_staff_type_handler #t 'oly:part_combined_staff_handler )
756 #(oly:register_staff_type_handler #f 'oly:parallel_voices_staff_handler )
760 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
761 % Automatic score generation
762 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
764 #(define oly:score_handler add-score)
765 #(define oly:music_handler add-music)
766 #(define oly:text_handler add-text)
769 % TODO: deprecate
770 setUseBook = #(define-music-function (parser location usebook) (boolean?)
771   (ly:warning "\\setUseBook has been deprecated! Books are now automatically handled without any hacks")
772   (make-music 'Music 'void #t)
776 % Two functions to handle midi-blocks: Either don't set one, or set an empty
777 % one so that MIDI is generated
778 #(define (oly:set_no_midi_block score) '())
779 #(define (oly:set_midi_block score)
780   (let* ((midiblock (if (defined? '$defaultmidi)
781                         (ly:output-def-clone $defaultmidi)
782                         (ly:make-output-def))))
783     (ly:output-def-set-variable! midiblock 'is-midi #t)
784     (ly:score-add-output-def! score midiblock)
785   )
788 % \setCreateMidi ##t/##f sets a flag to determine wheter MIDI output should
789 % be generated
790 #(define oly:apply_score_midi oly:set_no_midi_block)
791 setCreateMIDI = #(define-music-function (parser location createmidi) (boolean?)
792   (if createmidi
793     (set! oly:apply_score_midi oly:set_midi_block)
794     (set! oly:apply_score_midi oly:set_no_midi_block)
795   )
796   (make-music 'Music 'void #t)
800 % Two functions to handle layout-blocks: Either don't set one, or set an empty
801 % one so that a PDF is generated
802 #(define (oly:set_no_layout_block score) '())
803 #(define (oly:set_layout_block score)
804   (let* ((layoutblock (if (defined? '$defaultlayout)
805                         (ly:output-def-clone $defaultlayout)
806                         (ly:make-output-def))))
807     (ly:output-def-set-variable! layoutblock 'is-layout #t)
808     (ly:score-add-output-def! score layoutblock)
809   )
812 % \setCreatePDF ##t/##f sets a flag to determine wheter PDF output should
813 % be generated
814 #(define oly:apply_score_layout oly:set_no_layout_block)
815 setCreatePDF = #(define-music-function (parser location createlayout) (boolean?)
816   (if createlayout
817     (set! oly:apply_score_layout oly:set_layout_block)
818     (set! oly:apply_score_layout oly:set_no_layout_block)
819   )
820   (make-music 'Music 'void #t)
824 % Set the piece title in a new header block.
825 #(define (oly:set_piece_header score piecename)
826   (if (not-null? piecename)
827     (let* ((header (make-module)))
828       (module-define! header 'piece piecename)
829       (ly:score-set-header! score header)
830     )
831   )
835 % post-filter functions. By default, no filtering is done. However,
836 % for the *NoCues* function, the cue notes should be killed
837 keepcuefilter = #(define-music-function (parser location music) (ly:music?)
838   ((ly:music-function-extract removeWithTag) parser location 'non-cued music))
839 removecuefilter = #(define-music-function (parser location music) (ly:music?)
840   ((ly:music-function-extract removeWithTag) parser location 'cued ((ly:music-function-extract killCues) parser location music)))
842 %% The page numbers are pages counts in the pdf file, not visible page number!
843 %% So we have to offset them if the first page is not page #1
844 %% unfortunately this means we have to store the first-page-number of the first
845 %% bookpart in a global variable, because in later layouts we don't have that
846 %% information available any more (first-page-number will be the first page
847 %% number of the currently processed bookpart!)
848 #(define oly:first-page-offset #f)
849 #(define (oly:create-toc-file layout pages)
850   (if (not oly:first-page-offset)
851       (set! oly:first-page-offset (1- (ly:output-def-lookup layout 'first-page-number))))
852   (let* ((label-table (ly:output-def-lookup layout 'label-page-table)))
853     (if (not (null? label-table))
854       (let* ((format-line (lambda (toc-item)
855              (let* ((label (car toc-item))
856                     (text  (caddr toc-item))
857                     (label-page (and (list? label-table)
858                                      (assoc label label-table)))
859                     (page (and label-page (cdr label-page))))
860                (if page
861                    (format #f "~a, section, 1, {~a}, ~a" (- page oly:first-page-offset) text label)
862                    ;; label came from a different bookpart, so ignore it!
863                    #f))))
864              (formatted-toc-items (map format-line (toc-items)))
865              (whole-string (string-join (filter (lambda (i) i) formatted-toc-items) ",\n"))
866              (output-name (ly:parser-output-name parser))
867              (outfilename (format "~a.toc" output-name))
868              (outfile (open-output-file outfilename)))
869         (if (output-port? outfile)
870             (display whole-string outfile)
871             (ly:warning (_ "Unable to open output file ~a for the TOC information") outfilename))
872         (close-output-port outfile)))))
875 #(define-public (oly:add-toc-item parser markup-symbol text)
876   (oly:music_handler parser (add-toc-item! markup-symbol text)))
879 #(define (oly:add-score parser score piecename)
880   (if (not-null? piecename)
881     (oly:add-toc-item parser 'tocItemMarkup piecename))
882   (oly:score_handler parser score)
884 % The helper function to build a score.
885 #(define (oly:createScoreHelper parser location piece children func)
886   (let* (
887          (staves    (oly:staff_group_handler parser piece "" "SimultaneousMusic" children))
888          (music     (if (not-null? staves)
889                         ((ly:music-function-extract func) parser location staves)
890                         '()
891                     ))
892          (score     '())
893          (piecename (namedPieceInstrObject piece (car children) "PieceName"))
894          (piecenametacet (namedPieceInstrObject piece (car children) "PieceNameTacet"))
895          (header    '())
896         )
897     (if (null? music)
898       ; No staves, print tacet
899       (begin
900         (if (not-null? piecenametacet) (set! piecename piecenametacet))
901         (if (not-null? piecename)
902           (oly:add-score parser (list (oly:piece-title-markup piecename)) piecename)
903           (ly:warning (_ "No music and no score title found for part ~a and instrument ~a") piece children)
904         )
905       )
906       ; we have staves, apply the piecename to the score and add layout/midi blocks if needed
907       (begin
908         (set! score (scorify-music music parser))
909         (oly:set_piece_header score piecename)
910         (oly:apply_score_midi score)
911         (oly:apply_score_layout score)
912         ; Schedule the score for typesetting
913         (oly:add-score parser score piecename)
914       )
915     )
916   )
917   ; This is a void function, the score has been schedulled for typesetting already
918   (make-music 'Music 'void #t)
921 createVoice = #(define-music-function (parser location piece name) (string? string?)
922   (let* ((vc (oly:create_voice parser piece name)))
923     (make-music 'SimultaneousMusic
924                 'elements vc)))
926 createStaff = #(define-music-function (parser location piece name) (string? string?)
927   (oly:create_staff_or_group parser piece name))
928 createStaffForContents = #(define-music-function (parser location piece name contents) (string? string? ly:music?)
929   (let* ((tstruct (assoc-ref oly:orchestral_score_structure name))
930          (type (if (list? tstruct) (car tstruct) "Staff")))
931     (oly:staff_handler_internal parser piece name type (list contents))))
934 createScore = #(define-music-function (parser location piece children) (string? list?)
935   (oly:createScoreHelper parser location piece children keepcuefilter)
937 createNoCuesScore = #(define-music-function (parser location piece children) (string? list?)
938   (oly:createScoreHelper parser location piece children removecuefilter)
941 createHeadline = #(define-music-function (parser location headline) (string?)
942   (oly:add-toc-item parser 'tocItemMarkup headline)
943   (oly:score_handler parser (list (oly:piece-title-markup headline)))
944   (make-music 'Music 'void #t)
949 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
950 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
951 %%%%%   CUE NOTES
952 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
953 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
955 newInstrument = #(define-music-function (parser location instr) (string?)
957   \set Voice.instrumentCueName = #(string-join (list "+" instr))
960 cueText = #(define-music-function (parser location instr) (string?)
962   \set Voice.instrumentCueName = $instr
965 cueMarkup = #(define-music-function (parser location instr) (markup?)
967   \set Voice.instrumentCueName = $instr
971 clearCueText = #(define-music-function (parser location) ()
973   \unset Voice.instrumentCueName
977 insertCueText = #(define-music-function (parser location instr) (string?)
978   (if (string-null? instr)
979     #{ \tag #'cued \clearCueText #}
980     #{ \tag #'cued \cueText #instr #}
983 % generate a cue music section with instrument names
984 % Parameters: \namedCueDuring NameOfQuote CueDirection CueInstrument OriginalInstrument music
985 %                 -) NameOfQuote CueDirection music are the parameters for \cueDuring
986 %                 -) CueInstrument and OriginalInstrument are the displayed instrument names
987 % typical call:
988 % \namedCueDuring #"vIQuote" #UP #"V.I" #"Sop." { R1*3 }
989 %      This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
990 %      the beginning of the cue notes and "Sop." at the end
991 namedCueDuring = #(define-music-function (parser location cuevoice direction instrcue instr cuemusic) (string? number? string? string? ly:music?)
993   \cueDuring #cuevoice #direction {
994     \insertCueText #instrcue
995     $cuemusic
996     \insertCueText #instr
997   }
1000 namedTransposedCueDuring = #(define-music-function (parser location cuevoice direction instrcue instr trans cuemusic) (string? number? string? string? ly:music? ly:music?)
1001    #{
1002      \transposedCueDuring #cuevoice #direction #trans {
1003        \insertCueText #instrcue
1004        #cuemusic
1005        \insertCueText #instr
1006      }
1007    #}
1010 % set the cue instrument name and clef
1011 % setClefCue = #(define-music-function (parser location instr clef)
1012 %                                                      (string? ly:music?)
1013 %    #{
1014 %      \once \override Staff.Clef #'font-size = #-3 \clef $clef
1015 %      \insertCueText $instr
1016 %    #} )
1018 % generate a cue music section with instrument names and clef changes
1019 % Parameters: \cleffedCueDuring NameOfQuote CueDirection CueInstrument CueClef OriginalInstrument OriginalClef music
1020 %                 -) NameOfQuote CueDirection music are the parameters for \cueDuring
1021 %                 -) CueInstrument and OriginalInstrument are the displayed instrument names
1022 %                 -) CueClef and OriginalClef are the clefs for the the cue notes and the clef of the containing voice
1023 % typical call:
1024 % \cleffedCueDuring #"vIQuote" #UP #"V.I" #"treble" #"Basso" #"bass" { R1*3 }
1025 %      This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
1026 %      the beginning of the cue notes and "Basso" at the end. The clef is changed to treble at the
1027 %      beginning of the cue notes and reset to bass at the end
1028 cleffedCueDuring = #(define-music-function (parser location cuevoice direction instrcue clefcue instr clefinstr cuemusic)
1029                                                         (string? number? string? string? string? string? ly:music?)
1030    #{
1031      \namedCueDuringWithClef $cuevoice $direction $instrcue $clefcue $instr $cuemusic
1032    #}
1034 % generate a cue music section with instrument names and clef changes
1035 % Parameters: \namedCueDuringClef NameOfQuote CueDirection CueInstrument CueClef OriginalInstrument music
1036 %                 -) NameOfQuote CueDirection music are the parameters for \cueDuring
1037 %                 -) CueInstrument and OriginalInstrument are the displayed instrument names
1038 %                 -) CueClef is the clef for the the cue notes
1039 % typical call:
1040 % \namedCueDuringWithClef #"vIQuote" #UP #"V.I" #"treble" #"Basso" { R1*3 }
1041 %      This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
1042 %      the beginning of the cue notes and "Basso" at the end. The clef is changed to treble at the
1043 %      beginning of the cue notes and reset to bass at the end
1044 namedCueDuringWithClef = #(define-music-function (parser location cuevoice direction instrcue clefcue instr cuemusic)
1045                                              (string? number? string? string? string? ly:music?)
1046    #{
1047      \cueDuringWithClef #cuevoice #direction #(extract-ancient-or-modern-clef clefcue) {
1048        \insertCueText #instrcue
1049        #cuemusic
1050        \insertCueText #instr
1051      }
1052    #}
1057 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1058 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1059 %%%%%   DYNAMICS
1060 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1061 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1064 dynamicsX = #(define-music-function (parser location offset) (number?)
1066     \once \override DynamicText #'X-offset = $offset
1067     \once \override DynamicLineSpanner #'Y-offset = #0
1070 % Move the dynamic sign inside the staff to a fixed staff-relative position
1071 % posY (where 0 means vertically starts at the middle staff line)
1072 dynamicsAllInside = #(define-music-function (parser location offsetX posY)
1073 (number? number?)
1075   % Invalid y-extent -> hidden from skyline calculation and collisions
1076 %   \once \override DynamicLineSpanner #'Y-extent = #(cons +0 -0.01)
1077   \once \override DynamicLineSpanner #'Y-extent = $(lambda (grob)
1078     (let* ((ext (ly:axis-group-interface::height grob))
1079            (dir (ly:grob-property grob 'direction)))
1080       (if (eq? dir UP)
1081             (cons (- (cdr ext) 0.1) (cdr ext))
1082             (cons (car ext)         (+ (car ext) 0.1)))))
1083   % move by X offset and to fixed Y-position (use Y-offset of parent!)
1084   \once \override DynamicText #'X-offset = $offsetX
1085   \once \override DynamicText #'Y-offset =
1086     $(lambda (grob)
1087        (let* ((head (ly:grob-parent grob Y))
1088               (offset (ly:grob-property head 'Y-offset)))
1089          (- posY  offset (- 0.6))))
1090   \once \override DynamicLineSpanner #'Y-offset = $posY
1093 dynamicsUpInside = #(define-music-function (parser location offsetX) (number?)
1094   ((ly:music-function-extract dynamicsAllInside) parser location offsetX 1.5)
1097 dynamicsDownInside = #(define-music-function (parser location offsetX) (number?)
1098   ((ly:music-function-extract dynamicsAllInside) parser location offsetX -3.5)
1101 hairpinOffset = #(define-music-function (parser location posY) (number?)
1103   \once \override DynamicLineSpanner #'Y-offset = $posY
1104   \once \override DynamicLineSpanner #'Y-extent = #(cons +0 -0.01)
1107 % #(define ((line-break-offset before after) grob)
1108 %   (let* ((orig (ly:grob-original grob))
1109 %          ; All siblings if line-broken:
1110 %          (siblings (if (ly:grob? orig) (ly:spanner-broken-into orig) '() )))
1111 %     (if (>= (length siblings) 2)
1112 %       ; We have been line-broken
1113 %       (if (eq? (car (last-pair siblings)) grob)
1114 %         ; Last sibling:
1115 %         (ly:grob-set-property! grob 'Y-offset after)
1116 %         ; Others get the before value:
1117 %         (ly:grob-set-property! grob 'Y-offset before)
1118 %       )
1119 %     )
1120 %   )
1121 % )
1125 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1126 %%% Custom dynamic commands (with optional text before/after the dynamic)
1127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1129 % calculate x-alignment based on attribute text + dynamic text
1130 % this has to be a markup-command to get stencil-extent based on (interpret-markup layout props ...)
1131 #(define-markup-command (center-dyn layout props pre-text dyn post-text)(markup? string? markup?)
1132   "x-align on center of dynamic with pre- and post-texts"
1133   (let* (
1134           (pre-stencil (interpret-markup layout props (markup #:normal-text #:italic pre-text )))
1135           (post-stencil (interpret-markup layout props (markup #:normal-text #:italic post-text)))
1136           (dyn-stencil (interpret-markup layout props (markup #:dynamic dyn)))
1137           (pre-x (interval-length (ly:stencil-extent pre-stencil X)))
1138           (dyn-x (interval-length (ly:stencil-extent dyn-stencil X)))
1139           (post-x (interval-length (ly:stencil-extent post-stencil X)))
1140           (x-align
1141             (* (-
1142                  (/ (+ pre-x (/ dyn-x 2)) (+ pre-x dyn-x post-x) )
1143                  0.5) 2)
1144           )
1145         )
1146         (interpret-markup layout props (markup #:halign x-align #:line (#:normal-text #:italic pre-text #:dynamic dyn #:normal-text #:italic post-text)))
1148 % define a 'new' attributed dynamic script
1149 #(define (make-attr-dynamic-script pre dyn post)
1150         (let ((dynamic (make-dynamic-script (markup #:center-dyn pre dyn post))))
1151              (ly:music-set-property! dynamic 'tweaks (acons 'X-offset 0 (ly:music-property dynamic 'tweaks)))
1152              dynamic))
1153 #(define (make-whiteout-attr-dynamic-script pre dyn post)
1154         (let ((dynamic (make-dynamic-script (markup #:whiteout #:center-dyn pre dyn post))))
1155               (ly:music-set-property! dynamic 'tweaks (acons 'X-offset 0 (ly:music-property dynamic 'tweaks)))
1156              dynamic))
1160 rf = #(make-dynamic-script "rf")
1161 ffz = #(make-dynamic-script "ffz")
1162 pf = #(make-dynamic-script "pf")
1163 sempp = #(make-attr-dynamic-script "sempre" "pp" "")
1164 pdolce = #(make-attr-dynamic-script "" "p" "dolce")
1165 ppdolce = #(make-attr-dynamic-script "" "pp" "dolce")
1166 dolce = -\tweak #'X-offset #0 #(make-dynamic-script (markup #:halign -0.25 #:whiteout #:pad-markup 0.5 #:normal-text #:italic "dolce"))
1167 sfpdolce = #(make-attr-dynamic-script "" "sfp" "dolce")
1170 parenf = #(make-dynamic-script (markup #:line(#:normal-text #:italic #:fontsize 2 "(" #:dynamic "f" #:normal-text #:italic #:fontsize 2 ")")))
1171 parenp = #(make-dynamic-script (markup #:line(#:normal-text #:italic #:fontsize 2 "(" #:dynamic "p" #:normal-text #:italic #:fontsize 2 ")")))
1173 bracketf = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 3 "[" #:dynamic "f" #:hspace 0.1 #:normal-text #:fontsize 3 "]"))))
1174 bracketmf = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 3 "[" #:dynamic "mf" #:hspace 0.1 #:normal-text #:fontsize 3 "]"))))
1175 bracketmp = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 2 "[" #:hspace 0.2 #:dynamic "mp" #:normal-text #:fontsize 2 "]"))))
1176 bracketp = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 2 "[" #:hspace 0.2 #:dynamic "p" #:normal-text #:fontsize 2 "]"))))
1178 whiteoutp = #(make-dynamic-script (markup #:whiteout #:pad-markup 0.5 #:dynamic "p"))
1179 whiteoutpp = #(make-dynamic-script (markup #:whiteout #:pad-markup 0.5 #:dynamic "pp"))
1180 whiteoutf = #(make-dynamic-script (markup #:whiteout #:pad-markup 0.5 #:dynamic "f"))
1181 whiteoutff = #(make-dynamic-script (markup #:whiteout #:pad-markup 0.5 #:dynamic "ff"))
1184 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1189 sim = ^\markup{\italic "sim."}
1191 %%% Thanks to "Gilles THIBAULT" <gilles.thibault@free.fr>, there is a way
1192 %   to remove also the fermata from R1-\fermataMarkup: By filtering the music
1193 %   and removing the corresponding events.
1194 %   Documented as an LSR snippet: http://lsr.dsi.unimi.it/LSR/Item?id=372
1195 #(define (filterOneEventsMarkup event)
1196 ( let ( (eventname (ly:music-property  event 'name)) )
1197  (not
1198   (or     ;; add here event name you do NOT want
1199    (eq? eventname 'MultiMeasureTextEvent)
1200    (eq? eventname 'AbsoluteDynamicEvent)
1201    (eq? eventname 'TextScriptEvent)
1202    (eq? eventname 'ArticulationEvent)
1203    (eq? eventname 'CrescendoEvent)
1204    (eq? eventname 'DecrescendoEvent)
1205   )
1209 filterArticulations = #(define-music-function (parser location music) (ly:music?)
1210   (music-filter filterOneEventsMarkup music)
1215 %%% Add the same articulation to a longer sequence of notes:
1216 #(define (make-script x)
1217    (make-music 'ArticulationEvent
1218                'articulation-type x))
1220 #(define (add-articulation music art)
1221    (map-some-music
1222      (lambda (m)
1223        (cond ((music-is-of-type? m 'event-chord)
1224                 (set! (ly:music-property m 'elements)
1225                         (append (ly:music-property m 'elements)
1226                           (list (make-script art))))
1227                 m)
1228              ((music-is-of-type? m 'note-event)
1229                 (set! (ly:music-property m 'articulations)
1230                         (append (ly:music-property m 'articulations)
1231                           (list (make-script art))))
1232                 m)
1233              (else #f)))
1234       music))
1236 addArticulation = #(define-music-function (parser location type music) 
1237                                           (string? ly:music? )
1238                 (add-articulation music type))
1243 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1244 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1245 %%%%%   Tempo markings
1246 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1251 rit = \markup {\whiteout \italic "rit."}
1252 parenrit = \markup {\whiteout \italic "(rit.)"}
1253 atempo = \markup {\whiteout \italic "a tempo"}
1254 pocorit = \markup {\whiteout \italic "poco rit."}
1255 ppmosso = \markup {\whiteout \italic "poco più mosso"}
1256 pizz = \markup {\whiteout \italic "pizz."}
1257 arco = \markup {\whiteout \italic "arco"}
1258 colarco = \markup {\whiteout \italic "Col' arco"}
1259 perd = \markup {\whiteout \italic "perdend."}
1264 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1265 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1266 %%%%%   REST COMBINATION
1267 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1268 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1272 %% REST COMBINING, TAKEN FROM http://lsr.dsi.unimi.it/LSR/Item?id=336
1274 %% Usage:
1275 %%   \new Staff \with {
1276 %%     \override RestCollision #'positioning-done = #merge-rests-on-positioning
1277 %%   } << \somevoice \\ \othervoice >>
1278 %% or (globally):
1279 %%   \layout {
1280 %%     \context {
1281 %%       \Staff
1282 %%       \override RestCollision #'positioning-done = #merge-rests-on-positioning
1283 %%     }
1284 %%   }
1286 %% Limitations:
1287 %% - only handles two voices
1288 %% - does not handle multi-measure/whole-measure rests
1290 #(define (rest-score r)
1291   (let ((score 0)
1292   (yoff (ly:grob-property-data r 'Y-offset))
1293   (sp (ly:grob-property-data r 'staff-position)))
1294     (if (number? yoff)
1295   (set! score (+ score 2))
1296   (if (eq? yoff 'calculation-in-progress)
1297       (set! score (- score 3))))
1298     (and (number? sp)
1299    (<= 0 2 sp)
1300    (set! score (+ score 2))
1301    (set! score (- score (abs (- 1 sp)))))
1302     score))
1304 #(define (merge-rests-on-positioning grob)
1305   (let* ((can-merge #f)
1306    (elts (ly:grob-object grob 'elements))
1307    (num-elts (and (ly:grob-array? elts)
1308       (ly:grob-array-length elts)))
1309    (two-voice? (= num-elts 2)))
1310     (if two-voice?
1311   (let* ((v1-grob (ly:grob-array-ref elts 0))
1312          (v2-grob (ly:grob-array-ref elts 1))
1313          (v1-rest (ly:grob-object v1-grob 'rest))
1314          (v2-rest (ly:grob-object v2-grob 'rest)))
1315     (and
1316      (ly:grob? v1-rest)
1317      (ly:grob? v2-rest)
1318      (let* ((v1-duration-log (ly:grob-property v1-rest 'duration-log))
1319       (v2-duration-log (ly:grob-property v2-rest 'duration-log))
1320       (v1-dot (ly:grob-object v1-rest 'dot))
1321       (v2-dot (ly:grob-object v2-rest 'dot))
1322       (v1-dot-count (and (ly:grob? v1-dot)
1323              (ly:grob-property v1-dot 'dot-count -1)))
1324       (v2-dot-count (and (ly:grob? v2-dot)
1325              (ly:grob-property v2-dot 'dot-count -1))))
1326        (set! can-merge
1327        (and
1328         (number? v1-duration-log)
1329         (number? v2-duration-log)
1330         (= v1-duration-log v2-duration-log)
1331         (eq? v1-dot-count v2-dot-count)))
1332        (if can-merge
1333      ;; keep the rest that looks best:
1334      (let* ((keep-v1? (>= (rest-score v1-rest)
1335               (rest-score v2-rest)))
1336       (rest-to-keep (if keep-v1? v1-rest v2-rest))
1337       (dot-to-kill (if keep-v1? v2-dot v1-dot)))
1338        ;; uncomment if you're curious of which rest was chosen:
1339        ;;(ly:grob-set-property! v1-rest 'color green)
1340        ;;(ly:grob-set-property! v2-rest 'color blue)
1341        (ly:grob-suicide! (if keep-v1? v2-rest v1-rest))
1342        (if (ly:grob? dot-to-kill)
1343            (ly:grob-suicide! dot-to-kill))
1344        (ly:grob-set-property! rest-to-keep 'direction 0)
1345        (ly:rest::y-offset-callback rest-to-keep)))))))
1346     (if can-merge
1347   #t
1348   (ly:rest-collision::calc-positioning-done grob))))
1354 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1355 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1356 %%%%%   TABLE OF CONTENTS
1357 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1358 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1361 contentsTitle = "Inhalt / Contents"
1363 \paper {
1364   tocTitleMarkup = \markup \fill-line{
1365     \null
1366     \column {
1367       \override #(cons 'line-width (* 7 cm))
1368       \line{ \fill-line {\piece-title {\contentsTitle} \null }}
1369       \hspace #1
1370     }
1371     \null
1372   }
1373   tocItemMarkup = \markup \fill-line {
1374     \null
1375     \column {
1376       \override #(cons 'line-width (* 7 cm ))
1377       \line { \fill-line{\fromproperty #'toc:text \fromproperty #'toc:page }}
1378     }
1379     \null
1380   }
1384 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1385 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1386 %%%%%   TITLE PAGE / HEADER
1387 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1388 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1390 #(define-markup-command (when-property layout props symbol markp) (symbol? markup?)
1391   (if (chain-assoc-get symbol props)
1392       (interpret-markup layout props markp)
1393       (ly:make-stencil '()  '(1 . -1) '(1 . -1))))
1395 #(define-markup-command (vspace layout props amount) (number?)
1396   "This produces a invisible object taking vertical space."
1397   (let ((amount (* amount 3.0)))
1398     (if (> amount 0)
1399         (ly:make-stencil "" (cons -1 1) (cons 0 amount))
1400         (ly:make-stencil "" (cons -1 1) (cons amount amount)))))
1404 titlePageMarkup = \markup \abs-fontsize #10 \when-property #'header:title \column {
1405     \vspace #4
1406     \fill-line { \fontsize #8 \fromproperty #'header:composer }
1407     \vspace #1
1408     \fill-line { \fontsize #8 \fromproperty #'header:poet }
1409     \vspace #4
1410     \fill-line { \fontsize #10 \bold \fromproperty #'header:titlepagetitle }
1411     \vspace #1
1412     \fontsize #2 \when-property #'header:titlepagesubtitle {
1413       \fill-line { \fromproperty #'header:titlepagesubtitle }
1414       \vspace #1
1415     }
1416     \fill-line { \postscript #"-20 0 moveto 40 0 rlineto stroke" }
1417     \vspace #8
1418     \fill-line { \fontsize #5 \fromproperty #'header:ensemble }
1419     \vspace #0.02
1420     \fill-line { \fontsize #2 \fromproperty #'header:instruments }
1421     \vspace #9
1422     \fill-line { \fontsize #5 \fromproperty #'header:date }
1423     \vspace #1
1424     \fill-line { \fontsize #5 \fromproperty #'header:scoretype }
1425     \vspace #1
1426     \when-property #'header:instrument {
1427       \fill-line { \bold \fontsize #6 \rounded-box \fromproperty #'header:instrument }
1428     }
1429     \vspace #7
1430     \fontsize #2 \when-property #'header:enteredby \override #'(baseline-skip . 3.75) \left-align\center-column {
1431       \fill-line { "Herausgegeben von: / Edited by:"}
1432       \vspace #0.
1433       \fill-line { \fromproperty #'header:enteredby }
1434     }
1435     \fill-line {
1436       \when-property #'header:arrangement \column {
1437         \vspace #8
1438         \fill-line { \fontsize #3 \fromproperty #'header:arrangement }
1439       }
1440     }
1441   \vspace #6
1442   \fill-line { \fromproperty #'header:copyright }
1445 titleHeaderMarkup = \markup {
1446   \override #'(baseline-skip . 3.5)
1447   \column {
1448     \fill-line {
1449       \fromproperty #'header:logo
1450       \override #'(baseline-skip . 4.5) \center-column {
1451         \bold \abs-fontsize #18 \fromproperty #'header:title
1452         \bold \abs-fontsize #12 \fromproperty #'header:subtitle
1453         \abs-fontsize #11 \fromproperty #'header:subsubtitle
1454       }
1455       \bold \abs-fontsize #11 \when-property #'header:instrument \rounded-box \fromproperty #'header:instrument
1456     }
1457     \fill-line {
1458       \with-dimensions #'( 0 . 0) #'( 0 . 1 ) \null
1459     }
1461     \fill-line {
1462             \abs-fontsize #10 \fromproperty #'header:poet
1463             \abs-fontsize #10 \fromproperty #'header:composer
1464     }
1465     \fill-line {
1466             \abs-fontsize #10 \fromproperty #'header:meter
1467             \abs-fontsize #10 \fromproperty #'header:arranger
1468     }
1469   }
1471 date = #(strftime "%d-%m-%Y" (localtime (current-time)))
1472 \header {
1473   logo = \date
1474   scorenumber = \markup \concat { \fromproperty #'header:scorenumberbase "-" \fromproperty #'header:instrumentnr }
1475   pdftitle = \markup \line {\concat{\fromproperty #'header:shortcomposer ":"} \concat {\fromproperty #'header:title ","} \fromproperty #'header:instrument \fromproperty #'header:scoretype }
1479 titleScoreMarkup = \markup \piece-title \fromproperty #'header:piece
1481 \paper {
1482   scoreTitleMarkup = \titleScoreMarkup
1483   bookTitleMarkup = \titleHeaderMarkup
1488 %%%%%%%%%%%%%% headers and footers %%%%%%%%%%%%%%%%%%%%%%%%%%
1490 #(define (first-score-page layout props arg)
1491   (let* ((label 'first-score-page)
1492          (table (ly:output-def-lookup layout 'label-page-table))
1493          (label-page (and (list? table) (assoc label table)))
1494          (page-number (and label-page (cdr label-page)))
1495         )
1496     (if (eq? (chain-assoc-get 'page:page-number props -1) page-number)
1497       (interpret-markup layout props arg)
1498       empty-stencil)))
1500 #(define no-header-table '(1))
1501 addNoHeaderPage = #(define-music-function (parser location nr) (number?)
1502   (set! no-header-table (cons nr no-header-table))
1503   (make-music 'Music 'void #t))
1504 setNoHeaderPages = #(define-music-function (parser location pages) (list?)
1505   (set! no-header-table pages)
1506   (make-music 'Music 'void #t))
1508 #(define (is-header-page layout props arg)
1509   (let* ((page-number (chain-assoc-get 'page:page-number props -1)))
1510     (if (not (member page-number no-header-table))
1511       (interpret-markup layout props arg)
1512       empty-stencil)))
1514 #(define no-footer-table '(1))
1515 addNoFooterPage = #(define-music-function (parser location nr) (number?)
1516   (set! no-footer-table (cons nr no-footer-table))
1517   (make-music 'Music 'void #t))
1518 setNoFooterPages = #(define-music-function (parser location pages) (list?)
1519   (set! no-footer-table pages)
1520   (make-music 'Music 'void #t))
1522 #(define (is-footer-page layout props arg)
1523   (let* ((page-number (chain-assoc-get 'page:page-number props -1)))
1524     (if (not (member page-number no-footer-table))
1525       (interpret-markup layout props arg)
1526       empty-stencil)))
1528 #(define copyright-pages-table '(1))
1529 addCopyrightPage = #(define-music-function (parser location nr) (number?)
1530   (set! copyright-pages-table (cons nr copyright-pages-table))
1531   (make-music 'Music 'void #t))
1532 setCopyrightPages = #(define-music-function (parser location pages) (list?)
1533   (set! copyright-pages-table pages)
1534   (make-music 'Music 'void #t))
1536 #(define (is-copyright-page layout props arg)
1537   (let* ((page-number (chain-assoc-get 'page:page-number props -1)))
1538     (if (member page-number copyright-pages-table)
1539       (interpret-markup layout props arg)
1540       empty-stencil)))
1544 \paper {
1545   olyStdOddHeaderMarkup = \markup \fill-line {
1546     %% force the header to take some space, otherwise the
1547     %% page layout becomes a complete mess.
1548     " "
1549     \on-the-fly #is-header-page \fromproperty #'header:title
1550     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1551   }
1552   olyStdEvenHeaderMarkup = \markup \fill-line {
1553     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1554     \on-the-fly #is-header-page \fromproperty #'header:composer
1555     " "
1556   }
1557   olyInstrumentOddHeaderMarkup = \markup \fill-line {
1558     " "
1559     \on-the-fly #is-header-page \concat { \fromproperty #'header:instrument }
1560     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1561   }
1562   olyInstrumentEvenHeaderMarkup = \markup \fill-line {
1563     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1564     \on-the-fly #is-header-page \concat { \fromproperty #'header:shortcomposer ": " \fromproperty #'header:title }
1565     " "
1566   }
1567   oddHeaderMarkup = \olyStdOddHeaderMarkup
1568   evenHeaderMarkup = \olyStdEvenHeaderMarkup
1570   olyStdOddFooterMarkup = \markup {
1571     \column {
1572       \fill-line {
1573         %% publisher header field only on title page.
1574         \on-the-fly #first-page \fromproperty #'header:publisher
1575       }
1576       \fill-line {
1577         %% copyright on the first real score page
1578         \on-the-fly #is-copyright-page \fromproperty #'header:copyright
1579         \on-the-fly #is-copyright-page \null
1580       }
1581       \fill-line {
1582         %% All other pages get the number of the edition centered
1583         \on-the-fly #is-footer-page \fromproperty #'header:scorenumber
1584       }
1585     }
1586   }
1587   olyInstrumentOddFooterMarkup = \markup {
1588     \column {
1589       \fill-line {
1590         %% copyright on the first real score page
1591         \on-the-fly #is-copyright-page \fromproperty #'header:copyright
1592         \on-the-fly #is-copyright-page \null
1593       }
1594       \fill-line {
1595         %% All other pages get the number of the edition centered
1596         \on-the-fly #is-footer-page \fromproperty #'header:scorenumber
1597       }
1598     }
1599   }
1600   oddFooterMarkup = \olyStdOddFooterMarkup
1601   evenFooterMarkup = \olyStdOddFooterMarkup
1614 % Interpret the given markup with the header fields added to the props.
1615 % This way, one can re-use the same functions (using fromproperty
1616 % #'header:field) in the header block and as top-level markup.
1618 % This function is originally copied from mark-up-title (file scm/titling.scm),
1619 % which is lilypond's internal function to handle the title markups. I needed
1620 % to replace the scopes and manually add the $defaultheader (which is internally
1621 % done in paper-book.cc before calling mark-up-title. Also, I don't extract the
1622 % markup from the header block, but use the given markup.
1624 % I'm not sure if I really need the page properties in props, too... But I
1625 % suppose it does not hurt, either.
1626 #(define-markup-command (markupWithHeader layout props markup) (markup?)
1627   "Interpret the given markup with the header fields added to the props.
1628    This way, one can re-use the same functions (using fromproperty
1629    #'header:field) in the header block and as top-level markup."
1630   (let* (
1631       ; TODO: If we are inside a score, add the score's local header block, too!
1632       ; Currently, I only use the global header block, stored in $defaultheader
1633       (scopes (list $defaultheader))
1634       (alists (map ly:module->alist scopes))
1636       (prefixed-alist
1637         (map (lambda (alist)
1638           (map (lambda (entry)
1639             (cons
1640               (string->symbol (string-append "header:" (symbol->string (car entry))))
1641               (cdr entry)))
1642             alist))
1643           alists))
1644       (props (append prefixed-alist
1645               props
1646               (layout-extract-page-properties layout)))
1647     )
1648     (interpret-markup layout props markup)
1649   )
1657 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1658 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1659 %%%%%   Equally spacing multiple columns (e.g. for translations)
1660 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1663 % Credits: Nicolas Sceaux on the lilypond-user mailinglist
1664 #(define-markup-command (columns layout props args) (markup-list?)
1665    (let ((line-width (/ (chain-assoc-get 'line-width props
1666                          (ly:output-def-lookup layout 'line-width))
1667                         (max (length args) 1))))
1668      (interpret-markup layout props
1669        (make-line-markup (map (lambda (line)
1670                                 (markup #:pad-to-box `(0 . ,line-width) '(0 . 0)
1671                                   #:override `(line-width . ,line-width)
1672                                   line))
1673                                args)))))
1677 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1678 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1679 %%%%%   SCORE (HEADER / LAYOUT) SETTINGS
1680 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1681 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1684 startSlashedGraceMusic =  {
1685   \override Flag #'stroke-style = #"grace"
1688 stopSlashedGraceMusic =  {
1689   \revert Flag #'stroke-style
1692 slashedGrace =
1693 #(def-grace-function startSlashedGraceMusic stopSlashedGraceMusic
1694    (_i "Create slashed graces (slashes through stems, but no slur)from the following music expression"))
1697 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1698 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1699 %%%%%   SCORE (HEADER / LAYOUT) SETTINGS
1700 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1701 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1703 \paper {
1704   footnote-separator-markup = \markup { \fill-line { \override #`(span-factor . 1/4) { \draw-hline } \null }}
1706   left-margin = 1.75\cm
1707   right-margin = 1.75\cm
1708   line-width = 17.5\cm
1709 %   bottom-margin = 1.5\cm
1710   top-margin = 0.7\cm
1711   ragged-right = ##f
1712   ragged-last = ##f
1713   ragged-bottom = ##f
1714   ragged-last-bottom = ##f
1716 \layout {
1717   \context {
1718     \ChoirStaff
1719     % If only one non-empty staff in a system exists, still print the backet
1720     \override SystemStartBracket #'collapse-height = #1
1721     \consists "Instrument_name_engraver"
1722     \consists "Keep_alive_together_engraver"
1723   }
1724   \context {
1725     \StaffGroup
1726     % If only one non-empty staff in a system exists, still print the backet
1727     \override SystemStartBracket #'collapse-height = #1
1728     \consists "Instrument_name_engraver"
1729   }
1730   \context {
1731     \GrandStaff
1732     \override SystemStartBracket #'collapse-height = #1
1733     \consists "Instrument_name_engraver"
1734   }
1735   \context {
1736     \FiguredBass
1737     \override VerticalAxisGroup #'padding = #0
1738   }
1739   \context {
1740     \Score
1741     % Force multi-measure rests to be written as one span
1742     \override MultiMeasureRest #'expand-limit = #3
1743     skipBars = ##t
1744     autoBeaming = ##f
1745     \override CombineTextScript #'avoid-slur = #'outside
1746     \override DynamicTextSpanner #'style = #'none
1747     \override InstrumentSwitch #'font-size = #-1
1749     % Rest collision
1750     \override RestCollision #'positioning-done = #merge-rests-on-positioning
1751     % Auto-Accidentals: Use modern-cautionary style...
1752     extraNatural = ##f
1753     % Accidental rules (the rule giving the most accidentals wins!)
1754     % -) Reset accidentals at each barline -> accs not in key sig will always be printed
1755     % -) Same octave accidentals are remembered for two measures -> cancellation
1756     % -) other octave accidentals are remembered for next measure -> cancellation
1757     autoAccidentals = #`(Staff  ,(make-accidental-rule 'same-octave 0)
1758                                 ,(make-accidental-rule 'any-octave 0)
1759                                 ,(make-accidental-rule 'any-octave 1)
1760                                 ,(make-accidental-rule 'same-octave 2))
1761     % No auto-cautionaries, we always use autoAccidentals!
1762 %     autoCautionaries = #`(Staff ,(make-accidental-rule 'any-octave 0)
1763 %                                 ,(make-accidental-rule 'same-octave 1))
1764     printKeyCancellation = ##t
1765     quotedEventTypes = #'(StreamEvent)
1766     quotedCueEventTypes = #'(
1767       rhythmic-event
1768       tie-event
1769       beam-event
1770       tuplet-span-event
1771       tremolo-event
1772       glissando-event
1773       harmonic-event
1774       repeat-tie-event
1775       articulation-event
1776       slur-event
1777       trill-span-event
1778       tremolo-span-event
1779     )
1780     implicitBassFigures = #'(0 100)
1781     doubleRepeatType = #":|.|:"
1783   }
1784   \context {
1785     \Staff
1786     \RemoveEmptyStaves
1787   }
1791 ts = #(make-music 'TextScriptEvent 'text "t.s." 'direction UP )
1792 tt = #(make-music 'TextScriptEvent 'text "Tutti" 'direction UP )
1793 solo = -\tweak #'whiteout ##t #(make-music 'TextScriptEvent 'text "Solo" 'direction UP )
1794 tutti = #(make-music 'TextScriptEvent 'text "Tutti" 'direction UP )
1795 bracketts = #(make-music 'TextScriptEvent 'text "[t.s.]" 'direction UP )
1796 brackettt = #(make-music 'TextScriptEvent 'text "[Tutti]" 'direction UP )
1797 bracketsolo = #(make-music 'TextScriptEvent 'text "[Solo]" 'direction UP )
1799 sottovoce = #(make-music 'TextScriptEvent 'text "sotto voce" 'direction UP )
1801 dashedSlur = -\tweak #'dash-definition #'((0 1 0.4 0.75))(
1802 dashedTie = -\tweak #'dash-definition #'((0 1 0.4 0.75))~
1804 divisi = #(define-music-function (parser location vc1 vc2) (ly:music? ly:music?)
1806   << { \voiceOne $vc1 \oneVoice} \context Voice = "divisi2" { \voiceTwo $vc2 } >>
1810 #(define twoVoice divisi)
1812 #(define-public (bracket-stencils grob)
1813   (let ((lp (grob-interpret-markup grob (markup #:fontsize 3.5 #:translate (cons -0.3 -0.5) "[")))
1814         (rp (grob-interpret-markup grob (markup #:fontsize 3.5 #:translate (cons -0.3 -0.5) "]"))))
1815     (list lp rp)))
1817 bracketify = #(define-music-function (parser loc arg) (ly:music?)
1818    (_i "Tag @var{arg} to be parenthesized.")
1820   \tweak ParenthesesItem #'stencils #bracket-stencils \parenthesize $arg
1825 #(define-public (parentheses-item::calc-parenthesis-left-stencils grob)
1826   (let* ((font (ly:grob-default-font grob)))
1827     (list (ly:font-get-glyph font "accidentals.leftparen") empty-stencil)))
1829 #(define-public (parentheses-item::calc-parenthesis-right-stencils grob)
1830   (let* ((font (ly:grob-default-font grob)))
1831     (list empty-stencil (ly:font-get-glyph font "accidentals.rightparen"))))
1833 parenthesizeLeft = #(define-music-function (parser loc arg) (ly:music?)
1835   -\tweak ParenthesesItem #'stencils #parentheses-item::calc-parenthesis-left-stencils
1836   -\parenthesize $arg 
1838 parenthesizeRight = #(define-music-function (parser loc arg) (ly:music?)
1840   -\tweak ParenthesesItem #'stencils #parentheses-item::calc-parenthesis-right-stencils
1841   -\parenthesize $arg 
1845 #(define-markup-command (hat layout props arg) (markup?)
1846   "Draw a hat above the given string @var{arg}."
1847   (interpret-markup layout props (markup #:combine #:raise 1.5 "^" arg)))
1851 smallFlageolet =
1852 #(let ((m (make-music 'ArticulationEvent
1853                       'articulation-type "flageolet")))
1854    (ly:music-set-property! m 'tweaks
1855      (acons 'font-size -2
1856        (ly:music-property m 'tweaks)))
1857   m)
1860 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1861 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1862 %%%%%   LICENSE TEXTS
1863 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1864 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1866 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" }}
1867 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" }}
1868 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" }}
1869 LicenseNoRestrictions = \markup{\line {Die Ausgabe darf kopiert und ohne Einschränkungen aufgeführt werden. / May be copied and performed without restriction.}}
1873 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1874 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1875 %%%%%   VARIOUS
1876 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1877 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1879 startUnremovableSection = \set Staff.keepAliveInterfaces =
1880  #'(rhythmic-grob-interface
1881     rest-interface
1882     lyric-interface
1883     percent-repeat-item-interface
1884     percent-repeat-interface
1885     stanza-number-interface)
1887 endUnremovableSection = \unset Staff.keepAliveInterfaces
1890 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1891 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1892 %%%%%   EDITORIAL ANNOTATIONS
1893 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1894 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1896 #(define-public (editorial-bracket-stencil stil padding widen)
1897 "Add brackets for editorial annoations around STIL, producing a new stencil."
1898 (let* ((axis Y)
1899        (other-axis (lambda (a) (remainder (+ a 1) 2)))
1900        (ext (interval-widen (ly:stencil-extent stil axis) widen))
1901        (thick 0.15)
1902        (protrusion 0.3)
1903        (lb (ly:bracket axis ext thick protrusion))
1904        (rb (ly:bracket axis ext thick (- protrusion))))
1905   (set! stil (ly:stencil-combine-at-edge stil (other-axis axis) 1 rb padding))
1906   (set! stil
1907     (ly:stencil-combine-at-edge lb (other-axis axis) 1 stil padding))
1908   stil))
1910 editorialHairpin = \once \override Hairpin     #'stencil = #(lambda (grob) (editorial-bracket-stencil (ly:hairpin::print grob) 0.2 0.55))
1911 editorialDynamic = \once \override DynamicText #'stencil = #(lambda (grob) (editorial-bracket-stencil (ly:text-interface::print grob) 0.2 0.55))
1912 editorialMarkup =  \once \override TextScript  #'stencil = #(lambda (grob) (editorial-bracket-stencil (ly:text-interface::print grob) 0.2 0.55))
1914 videStart = \mark \markup \halign #-2.3 \concat { \hspace #4.5 \musicglyph #"scripts.coda" \left-align { vi- } }
1915 videEnd = \notemode {
1916         \once \override Score.RehearsalMark #'break-visibility = #begin-of-line-invisible
1917         \mark \markup \concat{ \right-align { -de } \hspace #1.5 \musicglyph #"scripts.coda" \hspace #4.2 }
1922 \layout {
1923         \context {\Staff
1924                 soloText = #"I"
1925                 soloIIText = #"II"
1926                 aDueText = #"a2"
1927         }
1930 \paper {
1931 %   annotate-spacing = ##t
1932   ragged-bottom = ##f
1933   ragged-last = ##f
1934   ragged-last-bottom = ##f
1936   top-markup-spacing #'minimum-distance = #5
1937 %   top-markup-spacing #'basic-distance = #4
1938 %   top-markup-spacing #'padding = #2
1939   top-markup-spacing #'stretchability = #15
1941   top-system-spacing #'minimum-distance = #0
1942 %   top-system-spacing #'basic-distance = #3
1943   top-system-spacing #'padding = #2
1944   top-system-spacing #'stretchability = #13
1945   
1946   markup-system-spacing #'minimum-distance = #5
1947 %   markup-system-spacing #'basic-distance = #4
1948   markup-system-spacing #'padding = #3
1949   markup-system-spacing #'stretchability = #25
1950   
1951   system-system-spacing #'minimum-distance = #0
1952 %   system-system-spacing #'basic-distance = #5
1953   system-system-spacing #'padding = #2
1954   system-system-spacing #'stretchability = #15
1955   
1956   last-bottom-spacing #'basic-distance = #3
1957 %   last-bottom-spacing #'basic-distance = #7
1958   last-bottom-spacing #'padding = #4
1959   last-bottom-spacing #'stretchability = #14
1961 %   score-markup-spacing #'basic-distance = #5
1962 %   score-markup-spacing #'stretchability = #15
1964 %   markup-markup-spacing #'basic-distance = #5
1965 %   markup-markup-spacing #'stretchability = #30
1968 \layout {
1969   \context { \PianoStaff
1970     \override StaffGrouper #'staff-staff-spacing #'stretchability = #1.5
1971   }
1972   \context { \StaffGroup
1973     \override StaffGrouper #'staff-staff-spacing #'stretchability = #2.5
1974     \override SystemStartBracket #'collapse-height = #1
1975   }
1976   \context { \GrandStaff
1977     \override StaffGrouper #'staff-staff-spacing #'stretchability = #3
1978     \override StaffGrouper #'staffgroup-staff-spacing #'stretchability = #3
1979    }
1980   \context { \ChoirStaff
1981     \override StaffGrouper #'staff-staff-spacing #'stretchability = #1
1982   }
1983   \context { \Staff
1984     \override StaffGrouper #'staff-staff-spacing #'stretchability = #4.9
1985   }
1986   \context { \Score
1987     \override StaffGrouper #'staff-staff-spacing #'stretchability = #5
1988   }
1993 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1994 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1995 %%%%%   WORKAROUNDS!
1996 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1997 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1999 % _ does not work as a direction modifier in figured bass
2000 tsdown = #(make-music 'TextScriptEvent 'text "t.s." 'direction DOWN )