Fix solo names messup
[orchestrallily.git] / orchestrallily.ily
blob154df4f472d7449f8985a17bf7e1ac2be669aaaa
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))
1241 #(define-markup-command (pad-y layout props amount arg)
1242   (number? markup?)
1243   #:category align
1244   (let* ((m (interpret-markup layout props arg))
1245          (x (ly:stencil-extent m X))
1246          (y (ly:stencil-extent m Y)))
1247     (ly:make-stencil (ly:stencil-expr m) x 
1248                      (interval-widen y amount))))
1251 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1252 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1253 %%%%%   Tempo markings
1254 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1255 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1259 rit = \markup {\whiteout \italic "rit."}
1260 parenrit = \markup {\whiteout \italic "(rit.)"}
1261 atempo = \markup {\whiteout \italic "a tempo"}
1262 pocorit = \markup {\whiteout \italic "poco rit."}
1263 ppmosso = \markup {\whiteout \italic "poco più mosso"}
1264 pizz = \markup {\whiteout \italic "pizz."}
1265 arco = \markup {\whiteout \italic "arco"}
1266 colarco = \markup {\whiteout \italic "Col' arco"}
1267 perd = \markup {\whiteout \italic "perdend."}
1272 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1273 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1274 %%%%%   REST COMBINATION
1275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1276 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1280 %% REST COMBINING, TAKEN FROM http://lsr.dsi.unimi.it/LSR/Item?id=336
1282 %% Usage:
1283 %%   \new Staff \with {
1284 %%     \override RestCollision #'positioning-done = #merge-rests-on-positioning
1285 %%   } << \somevoice \\ \othervoice >>
1286 %% or (globally):
1287 %%   \layout {
1288 %%     \context {
1289 %%       \Staff
1290 %%       \override RestCollision #'positioning-done = #merge-rests-on-positioning
1291 %%     }
1292 %%   }
1294 %% Limitations:
1295 %% - only handles two voices
1296 %% - does not handle multi-measure/whole-measure rests
1298 #(define (rest-score r)
1299   (let ((score 0)
1300   (yoff (ly:grob-property-data r 'Y-offset))
1301   (sp (ly:grob-property-data r 'staff-position)))
1302     (if (number? yoff)
1303   (set! score (+ score 2))
1304   (if (eq? yoff 'calculation-in-progress)
1305       (set! score (- score 3))))
1306     (and (number? sp)
1307    (<= 0 2 sp)
1308    (set! score (+ score 2))
1309    (set! score (- score (abs (- 1 sp)))))
1310     score))
1312 #(define (merge-rests-on-positioning grob)
1313   (let* ((can-merge #f)
1314    (elts (ly:grob-object grob 'elements))
1315    (num-elts (and (ly:grob-array? elts)
1316       (ly:grob-array-length elts)))
1317    (two-voice? (= num-elts 2)))
1318     (if two-voice?
1319   (let* ((v1-grob (ly:grob-array-ref elts 0))
1320          (v2-grob (ly:grob-array-ref elts 1))
1321          (v1-rest (ly:grob-object v1-grob 'rest))
1322          (v2-rest (ly:grob-object v2-grob 'rest)))
1323     (and
1324      (ly:grob? v1-rest)
1325      (ly:grob? v2-rest)
1326      (let* ((v1-duration-log (ly:grob-property v1-rest 'duration-log))
1327       (v2-duration-log (ly:grob-property v2-rest 'duration-log))
1328       (v1-dot (ly:grob-object v1-rest 'dot))
1329       (v2-dot (ly:grob-object v2-rest 'dot))
1330       (v1-dot-count (and (ly:grob? v1-dot)
1331              (ly:grob-property v1-dot 'dot-count -1)))
1332       (v2-dot-count (and (ly:grob? v2-dot)
1333              (ly:grob-property v2-dot 'dot-count -1))))
1334        (set! can-merge
1335        (and
1336         (number? v1-duration-log)
1337         (number? v2-duration-log)
1338         (= v1-duration-log v2-duration-log)
1339         (eq? v1-dot-count v2-dot-count)))
1340        (if can-merge
1341      ;; keep the rest that looks best:
1342      (let* ((keep-v1? (>= (rest-score v1-rest)
1343               (rest-score v2-rest)))
1344       (rest-to-keep (if keep-v1? v1-rest v2-rest))
1345       (dot-to-kill (if keep-v1? v2-dot v1-dot)))
1346        ;; uncomment if you're curious of which rest was chosen:
1347        ;;(ly:grob-set-property! v1-rest 'color green)
1348        ;;(ly:grob-set-property! v2-rest 'color blue)
1349        (ly:grob-suicide! (if keep-v1? v2-rest v1-rest))
1350        (if (ly:grob? dot-to-kill)
1351            (ly:grob-suicide! dot-to-kill))
1352        (ly:grob-set-property! rest-to-keep 'direction 0)
1353        (ly:rest::y-offset-callback rest-to-keep)))))))
1354     (if can-merge
1355   #t
1356   (ly:rest-collision::calc-positioning-done grob))))
1362 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1363 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1364 %%%%%   TABLE OF CONTENTS
1365 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1366 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1369 contentsTitle = "Inhalt / Contents"
1371 \paper {
1372   tocTitleMarkup = \markup \fill-line{
1373     \null
1374     \column {
1375       \override #(cons 'line-width (* 7 cm))
1376       \line{ \fill-line {\piece-title {\contentsTitle} \null }}
1377       \hspace #1
1378     }
1379     \null
1380   }
1381   tocItemMarkup = \markup \fill-line {
1382     \null
1383     \column {
1384       \override #(cons 'line-width (* 7 cm ))
1385       \line { \fill-line{\fromproperty #'toc:text \fromproperty #'toc:page }}
1386     }
1387     \null
1388   }
1392 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1393 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1394 %%%%%   TITLE PAGE / HEADER
1395 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1396 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1398 #(define-markup-command (when-property layout props symbol markp) (symbol? markup?)
1399   (if (chain-assoc-get symbol props)
1400       (interpret-markup layout props markp)
1401       (ly:make-stencil '()  '(1 . -1) '(1 . -1))))
1403 #(define-markup-command (vspace layout props amount) (number?)
1404   "This produces a invisible object taking vertical space."
1405   (let ((amount (* amount 3.0)))
1406     (if (> amount 0)
1407         (ly:make-stencil "" (cons -1 1) (cons 0 amount))
1408         (ly:make-stencil "" (cons -1 1) (cons amount amount)))))
1412 titlePageMarkup = \markup \abs-fontsize #10 \when-property #'header:title \column {
1413     \vspace #4
1414     \fill-line { \fontsize #8 \fromproperty #'header:composer }
1415     \vspace #1
1416     \fill-line { \fontsize #8 \fromproperty #'header:poet }
1417     \vspace #4
1418     \fill-line { \fontsize #10 \bold \fromproperty #'header:titlepagetitle }
1419     \vspace #1
1420     \fontsize #2 \when-property #'header:titlepagesubtitle {
1421       \fill-line { \fromproperty #'header:titlepagesubtitle }
1422       \vspace #1
1423     }
1424     \fill-line { \postscript #"-20 0 moveto 40 0 rlineto stroke" }
1425     \vspace #8
1426     \fill-line { \fontsize #5 \fromproperty #'header:ensemble }
1427     \vspace #0.02
1428     \fill-line { \fontsize #2 \fromproperty #'header:instruments }
1429     \vspace #9
1430     \fill-line { \fontsize #5 \fromproperty #'header:date }
1431     \vspace #1
1432     \fill-line { \fontsize #5 \fromproperty #'header:scoretype }
1433     \vspace #1
1434     \when-property #'header:instrument {
1435       \fill-line { \bold \fontsize #6 \rounded-box \fromproperty #'header:instrument }
1436     }
1437     \vspace #7
1438     \fontsize #2 \when-property #'header:enteredby \override #'(baseline-skip . 3.75) \left-align\center-column {
1439       \fill-line { "Herausgegeben von: / Edited by:"}
1440       \vspace #0.
1441       \fill-line { \fromproperty #'header:enteredby }
1442     }
1443     \fill-line {
1444       \when-property #'header:arrangement \column {
1445         \vspace #8
1446         \fill-line { \fontsize #3 \fromproperty #'header:arrangement }
1447       }
1448     }
1449   \vspace #6
1450   \fill-line { \fromproperty #'header:copyright }
1453 titleHeaderMarkup = \markup {
1454   \override #'(baseline-skip . 3.5)
1455   \column {
1456     \fill-line {
1457       \fromproperty #'header:logo
1458       \override #'(baseline-skip . 4.5) \center-column {
1459         \bold \abs-fontsize #18 \fromproperty #'header:title
1460         \bold \abs-fontsize #12 \fromproperty #'header:subtitle
1461         \abs-fontsize #11 \fromproperty #'header:subsubtitle
1462       }
1463       \bold \abs-fontsize #11 \when-property #'header:instrument \rounded-box \fromproperty #'header:instrument
1464     }
1465     \fill-line {
1466       \with-dimensions #'( 0 . 0) #'( 0 . 1 ) \null
1467     }
1469     \fill-line {
1470             \abs-fontsize #10 \fromproperty #'header:poet
1471             \abs-fontsize #10 \fromproperty #'header:composer
1472     }
1473     \fill-line {
1474             \abs-fontsize #10 \fromproperty #'header:meter
1475             \abs-fontsize #10 \fromproperty #'header:arranger
1476     }
1477   }
1479 date = #(strftime "%d-%m-%Y" (localtime (current-time)))
1480 \header {
1481   logo = \date
1482   scorenumber = \markup \concat { \fromproperty #'header:scorenumberbase "-" \fromproperty #'header:instrumentnr }
1483   pdftitle = \markup \line {\concat{\fromproperty #'header:shortcomposer ":"} \concat {\fromproperty #'header:title ","} \fromproperty #'header:instrument \fromproperty #'header:scoretype }
1487 titleScoreMarkup = \markup \piece-title \fromproperty #'header:piece
1489 \paper {
1490   scoreTitleMarkup = \titleScoreMarkup
1491   bookTitleMarkup = \titleHeaderMarkup
1496 %%%%%%%%%%%%%% headers and footers %%%%%%%%%%%%%%%%%%%%%%%%%%
1498 #(define (first-score-page layout props arg)
1499   (let* ((label 'first-score-page)
1500          (table (ly:output-def-lookup layout 'label-page-table))
1501          (label-page (and (list? table) (assoc label table)))
1502          (page-number (and label-page (cdr label-page)))
1503         )
1504     (if (eq? (chain-assoc-get 'page:page-number props -1) page-number)
1505       (interpret-markup layout props arg)
1506       empty-stencil)))
1508 #(define no-header-table '(1))
1509 addNoHeaderPage = #(define-music-function (parser location nr) (number?)
1510   (set! no-header-table (cons nr no-header-table))
1511   (make-music 'Music 'void #t))
1512 setNoHeaderPages = #(define-music-function (parser location pages) (list?)
1513   (set! no-header-table pages)
1514   (make-music 'Music 'void #t))
1516 #(define (is-header-page layout props arg)
1517   (let* ((page-number (chain-assoc-get 'page:page-number props -1)))
1518     (if (not (member page-number no-header-table))
1519       (interpret-markup layout props arg)
1520       empty-stencil)))
1522 #(define no-footer-table '(1))
1523 addNoFooterPage = #(define-music-function (parser location nr) (number?)
1524   (set! no-footer-table (cons nr no-footer-table))
1525   (make-music 'Music 'void #t))
1526 setNoFooterPages = #(define-music-function (parser location pages) (list?)
1527   (set! no-footer-table pages)
1528   (make-music 'Music 'void #t))
1530 #(define (is-footer-page layout props arg)
1531   (let* ((page-number (chain-assoc-get 'page:page-number props -1)))
1532     (if (not (member page-number no-footer-table))
1533       (interpret-markup layout props arg)
1534       empty-stencil)))
1536 #(define copyright-pages-table '(1))
1537 addCopyrightPage = #(define-music-function (parser location nr) (number?)
1538   (set! copyright-pages-table (cons nr copyright-pages-table))
1539   (make-music 'Music 'void #t))
1540 setCopyrightPages = #(define-music-function (parser location pages) (list?)
1541   (set! copyright-pages-table pages)
1542   (make-music 'Music 'void #t))
1544 #(define (is-copyright-page layout props arg)
1545   (let* ((page-number (chain-assoc-get 'page:page-number props -1)))
1546     (if (member page-number copyright-pages-table)
1547       (interpret-markup layout props arg)
1548       empty-stencil)))
1552 \paper {
1553   olyStdOddHeaderMarkup = \markup \fill-line {
1554     %% force the header to take some space, otherwise the
1555     %% page layout becomes a complete mess.
1556     " "
1557     \on-the-fly #is-header-page \fromproperty #'header:title
1558     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1559   }
1560   olyStdEvenHeaderMarkup = \markup \fill-line {
1561     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1562     \on-the-fly #is-header-page \fromproperty #'header:composer
1563     " "
1564   }
1565   olyInstrumentOddHeaderMarkup = \markup \fill-line {
1566     " "
1567     \on-the-fly #is-header-page \concat { \fromproperty #'header:instrument }
1568     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1569   }
1570   olyInstrumentEvenHeaderMarkup = \markup \fill-line {
1571     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1572     \on-the-fly #is-header-page \concat { \fromproperty #'header:shortcomposer ": " \fromproperty #'header:title }
1573     " "
1574   }
1575   oddHeaderMarkup = \olyStdOddHeaderMarkup
1576   evenHeaderMarkup = \olyStdEvenHeaderMarkup
1578   olyStdOddFooterMarkup = \markup {
1579     \column {
1580       \fill-line {
1581         %% publisher header field only on title page.
1582         \on-the-fly #first-page \fromproperty #'header:publisher
1583       }
1584       \fill-line {
1585         %% copyright on the first real score page
1586         \on-the-fly #is-copyright-page \fromproperty #'header:copyright
1587         \on-the-fly #is-copyright-page \null
1588       }
1589       \fill-line {
1590         %% All other pages get the number of the edition centered
1591         \on-the-fly #is-footer-page \fromproperty #'header:scorenumber
1592       }
1593     }
1594   }
1595   olyInstrumentOddFooterMarkup = \markup {
1596     \column {
1597       \fill-line {
1598         %% copyright on the first real score page
1599         \on-the-fly #is-copyright-page \fromproperty #'header:copyright
1600         \on-the-fly #is-copyright-page \null
1601       }
1602       \fill-line {
1603         %% All other pages get the number of the edition centered
1604         \on-the-fly #is-footer-page \fromproperty #'header:scorenumber
1605       }
1606     }
1607   }
1608   oddFooterMarkup = \olyStdOddFooterMarkup
1609   evenFooterMarkup = \olyStdOddFooterMarkup
1622 % Interpret the given markup with the header fields added to the props.
1623 % This way, one can re-use the same functions (using fromproperty
1624 % #'header:field) in the header block and as top-level markup.
1626 % This function is originally copied from mark-up-title (file scm/titling.scm),
1627 % which is lilypond's internal function to handle the title markups. I needed
1628 % to replace the scopes and manually add the $defaultheader (which is internally
1629 % done in paper-book.cc before calling mark-up-title. Also, I don't extract the
1630 % markup from the header block, but use the given markup.
1632 % I'm not sure if I really need the page properties in props, too... But I
1633 % suppose it does not hurt, either.
1634 #(define-markup-command (markupWithHeader layout props markup) (markup?)
1635   "Interpret the given markup with the header fields added to the props.
1636    This way, one can re-use the same functions (using fromproperty
1637    #'header:field) in the header block and as top-level markup."
1638   (let* (
1639       ; TODO: If we are inside a score, add the score's local header block, too!
1640       ; Currently, I only use the global header block, stored in $defaultheader
1641       (scopes (list $defaultheader))
1642       (alists (map ly:module->alist scopes))
1644       (prefixed-alist
1645         (map (lambda (alist)
1646           (map (lambda (entry)
1647             (cons
1648               (string->symbol (string-append "header:" (symbol->string (car entry))))
1649               (cdr entry)))
1650             alist))
1651           alists))
1652       (props (append prefixed-alist
1653               props
1654               (layout-extract-page-properties layout)))
1655     )
1656     (interpret-markup layout props markup)
1657   )
1665 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1666 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1667 %%%%%   Equally spacing multiple columns (e.g. for translations)
1668 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1669 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1671 % Credits: Nicolas Sceaux on the lilypond-user mailinglist
1672 #(define-markup-command (columns layout props args) (markup-list?)
1673    (let ((line-width (/ (chain-assoc-get 'line-width props
1674                          (ly:output-def-lookup layout 'line-width))
1675                         (max (length args) 1))))
1676      (interpret-markup layout props
1677        (make-line-markup (map (lambda (line)
1678                                 (markup #:pad-to-box `(0 . ,line-width) '(0 . 0)
1679                                   #:override `(line-width . ,line-width)
1680                                   line))
1681                                args)))))
1685 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1686 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1687 %%%%%   SCORE (HEADER / LAYOUT) SETTINGS
1688 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1689 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1692 startSlashedGraceMusic =  {
1693   \override Flag #'stroke-style = #"grace"
1696 stopSlashedGraceMusic =  {
1697   \revert Flag #'stroke-style
1700 slashedGrace =
1701 #(def-grace-function startSlashedGraceMusic stopSlashedGraceMusic
1702    (_i "Create slashed graces (slashes through stems, but no slur)from the following music expression"))
1705 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1706 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1707 %%%%%   SCORE (HEADER / LAYOUT) SETTINGS
1708 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1709 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1711 \paper {
1712   footnote-separator-markup = \markup { \fill-line { \override #`(span-factor . 1/4) { \draw-hline } \null }}
1714   left-margin = 1.75\cm
1715   right-margin = 1.75\cm
1716   line-width = 17.5\cm
1717 %   bottom-margin = 1.5\cm
1718   top-margin = 0.7\cm
1719   ragged-right = ##f
1720   ragged-last = ##f
1721   ragged-bottom = ##f
1722   ragged-last-bottom = ##f
1724 \layout {
1725   \context {
1726     \ChoirStaff
1727     % If only one non-empty staff in a system exists, still print the backet
1728     \override SystemStartBracket #'collapse-height = #1
1729     \consists "Instrument_name_engraver"
1730     \consists "Keep_alive_together_engraver"
1731   }
1732   \context {
1733     \StaffGroup
1734     % If only one non-empty staff in a system exists, still print the backet
1735     \override SystemStartBracket #'collapse-height = #1
1736     \consists "Instrument_name_engraver"
1737   }
1738   \context {
1739     \GrandStaff
1740     \override SystemStartBracket #'collapse-height = #1
1741     \consists "Instrument_name_engraver"
1742   }
1743   \context {
1744     \FiguredBass
1745     \override VerticalAxisGroup #'padding = #0
1746   }
1747   \context {
1748     \Score
1749     % Force multi-measure rests to be written as one span
1750     \override MultiMeasureRest #'expand-limit = #3
1751     skipBars = ##t
1752     autoBeaming = ##f
1753     \override CombineTextScript #'avoid-slur = #'outside
1754     \override DynamicTextSpanner #'style = #'none
1755     \override InstrumentSwitch #'font-size = #-1
1757     % Rest collision
1758     \override RestCollision #'positioning-done = #merge-rests-on-positioning
1759     % Auto-Accidentals: Use modern-cautionary style...
1760     extraNatural = ##f
1761     % Accidental rules (the rule giving the most accidentals wins!)
1762     % -) Reset accidentals at each barline -> accs not in key sig will always be printed
1763     % -) Same octave accidentals are remembered for two measures -> cancellation
1764     % -) other octave accidentals are remembered for next measure -> cancellation
1765     autoAccidentals = #`(Staff  ,(make-accidental-rule 'same-octave 0)
1766                                 ,(make-accidental-rule 'any-octave 0)
1767                                 ,(make-accidental-rule 'any-octave 1)
1768                                 ,(make-accidental-rule 'same-octave 2))
1769     % No auto-cautionaries, we always use autoAccidentals!
1770 %     autoCautionaries = #`(Staff ,(make-accidental-rule 'any-octave 0)
1771 %                                 ,(make-accidental-rule 'same-octave 1))
1772     printKeyCancellation = ##t
1773     quotedEventTypes = #'(StreamEvent)
1774     quotedCueEventTypes = #'(
1775       rhythmic-event
1776       tie-event
1777       beam-event
1778       tuplet-span-event
1779       tremolo-event
1780       glissando-event
1781       harmonic-event
1782       repeat-tie-event
1783       articulation-event
1784       slur-event
1785       trill-span-event
1786       tremolo-span-event
1787     )
1788     implicitBassFigures = #'(0 100)
1789     doubleRepeatType = #":|.|:"
1791   }
1792   \context {
1793     \Staff
1794     \RemoveEmptyStaves
1795   }
1799 ts = #(make-music 'TextScriptEvent 'text "t.s." 'direction UP )
1800 tt = #(make-music 'TextScriptEvent 'text "Tutti" 'direction UP )
1801 solo = -\tweak #'whiteout ##t #(make-music 'TextScriptEvent 'text "Solo" 'direction UP )
1802 tutti = #(make-music 'TextScriptEvent 'text "Tutti" 'direction UP )
1803 bracketts = #(make-music 'TextScriptEvent 'text "[t.s.]" 'direction UP )
1804 brackettt = #(make-music 'TextScriptEvent 'text "[Tutti]" 'direction UP )
1805 bracketsolo = #(make-music 'TextScriptEvent 'text "[Solo]" 'direction UP )
1807 sottovoce = #(make-music 'TextScriptEvent 'text "sotto voce" 'direction UP )
1809 dashedSlur = -\tweak #'dash-definition #'((0 1 0.4 0.75))(
1810 dashedTie = -\tweak #'dash-definition #'((0 1 0.4 0.75))~
1812 divisi = #(define-music-function (parser location vc1 vc2) (ly:music? ly:music?)
1814   << { \voiceOne $vc1 \oneVoice} \context Voice = "divisi2" { \voiceTwo $vc2 } >>
1818 #(define twoVoice divisi)
1820 #(define-public (bracket-stencils grob)
1821   (let ((lp (grob-interpret-markup grob (markup #:fontsize 3.5 #:translate (cons -0.3 -0.5) "[")))
1822         (rp (grob-interpret-markup grob (markup #:fontsize 3.5 #:translate (cons -0.3 -0.5) "]"))))
1823     (list lp rp)))
1825 bracketify = #(define-music-function (parser loc arg) (ly:music?)
1826    (_i "Tag @var{arg} to be parenthesized.")
1828   \tweak ParenthesesItem #'stencils #bracket-stencils \parenthesize $arg
1833 #(define-public (parentheses-item::calc-parenthesis-left-stencils grob)
1834   (let* ((font (ly:grob-default-font grob)))
1835     (list (ly:font-get-glyph font "accidentals.leftparen") empty-stencil)))
1837 #(define-public (parentheses-item::calc-parenthesis-right-stencils grob)
1838   (let* ((font (ly:grob-default-font grob)))
1839     (list empty-stencil (ly:font-get-glyph font "accidentals.rightparen"))))
1841 parenthesizeLeft = #(define-music-function (parser loc arg) (ly:music?)
1843   -\tweak ParenthesesItem #'stencils #parentheses-item::calc-parenthesis-left-stencils
1844   -\parenthesize $arg 
1846 parenthesizeRight = #(define-music-function (parser loc arg) (ly:music?)
1848   -\tweak ParenthesesItem #'stencils #parentheses-item::calc-parenthesis-right-stencils
1849   -\parenthesize $arg 
1853 #(define-markup-command (hat layout props arg) (markup?)
1854   "Draw a hat above the given string @var{arg}."
1855   (interpret-markup layout props (markup #:combine #:raise 1.5 "^" arg)))
1859 smallFlageolet =
1860 #(let ((m (make-music 'ArticulationEvent
1861                       'articulation-type "flageolet")))
1862    (ly:music-set-property! m 'tweaks
1863      (acons 'font-size -2
1864        (ly:music-property m 'tweaks)))
1865   m)
1868 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1869 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1870 %%%%%   LICENSE TEXTS
1871 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1872 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1874 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" }}
1875 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" }}
1876 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" }}
1877 LicenseNoRestrictions = \markup{\line {Die Ausgabe darf kopiert und ohne Einschränkungen aufgeführt werden. / May be copied and performed without restriction.}}
1881 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1882 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1883 %%%%%   VARIOUS
1884 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1885 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1887 startUnremovableSection = \set Staff.keepAliveInterfaces =
1888  #'(rhythmic-grob-interface
1889     rest-interface
1890     lyric-interface
1891     percent-repeat-item-interface
1892     percent-repeat-interface
1893     stanza-number-interface)
1895 endUnremovableSection = \unset Staff.keepAliveInterfaces
1898 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1899 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1900 %%%%%   EDITORIAL ANNOTATIONS
1901 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1902 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1904 #(define-public (editorial-bracket-stencil stil padding widen)
1905 "Add brackets for editorial annoations around STIL, producing a new stencil."
1906 (let* ((axis Y)
1907        (other-axis (lambda (a) (remainder (+ a 1) 2)))
1908        (ext (interval-widen (ly:stencil-extent stil axis) widen))
1909        (thick 0.15)
1910        (protrusion 0.3)
1911        (lb (ly:bracket axis ext thick protrusion))
1912        (rb (ly:bracket axis ext thick (- protrusion))))
1913   (set! stil (ly:stencil-combine-at-edge stil (other-axis axis) 1 rb padding))
1914   (set! stil
1915     (ly:stencil-combine-at-edge lb (other-axis axis) 1 stil padding))
1916   stil))
1918 editorialHairpin = \once \override Hairpin     #'stencil = #(lambda (grob) (editorial-bracket-stencil (ly:hairpin::print grob) 0.2 0.55))
1919 editorialDynamic = \once \override DynamicText #'stencil = #(lambda (grob) (editorial-bracket-stencil (ly:text-interface::print grob) 0.2 0.55))
1920 editorialMarkup =  \once \override TextScript  #'stencil = #(lambda (grob) (editorial-bracket-stencil (ly:text-interface::print grob) 0.2 0.55))
1922 videStart = \mark \markup \halign #-2.3 \concat { \hspace #4.5 \musicglyph #"scripts.coda" \left-align { vi- } }
1923 videEnd = \notemode {
1924         \once \override Score.RehearsalMark #'break-visibility = #begin-of-line-invisible
1925         \mark \markup \concat{ \right-align { -de } \hspace #1.5 \musicglyph #"scripts.coda" \hspace #4.2 }
1930 \layout {
1931         \context {\Staff
1932                 soloText = #"I"
1933                 soloIIText = #"II"
1934                 aDueText = #"a2"
1935         }
1938 \paper {
1939 %   annotate-spacing = ##t
1940   ragged-bottom = ##f
1941   ragged-last = ##f
1942   ragged-last-bottom = ##f
1944   top-markup-spacing #'minimum-distance = #5
1945 %   top-markup-spacing #'basic-distance = #4
1946 %   top-markup-spacing #'padding = #2
1947   top-markup-spacing #'stretchability = #15
1949   top-system-spacing #'minimum-distance = #0
1950 %   top-system-spacing #'basic-distance = #3
1951   top-system-spacing #'padding = #2
1952   top-system-spacing #'stretchability = #13
1953   
1954   markup-system-spacing #'minimum-distance = #5
1955 %   markup-system-spacing #'basic-distance = #4
1956   markup-system-spacing #'padding = #3
1957   markup-system-spacing #'stretchability = #25
1958   
1959   system-system-spacing #'minimum-distance = #0
1960 %   system-system-spacing #'basic-distance = #5
1961   system-system-spacing #'padding = #2
1962   system-system-spacing #'stretchability = #15
1963   
1964   last-bottom-spacing #'basic-distance = #3
1965 %   last-bottom-spacing #'basic-distance = #7
1966   last-bottom-spacing #'padding = #4
1967   last-bottom-spacing #'stretchability = #14
1969 %   score-markup-spacing #'basic-distance = #5
1970 %   score-markup-spacing #'stretchability = #15
1972 %   markup-markup-spacing #'basic-distance = #5
1973 %   markup-markup-spacing #'stretchability = #30
1976 \layout {
1977   \context { \PianoStaff
1978     \override StaffGrouper #'staff-staff-spacing #'stretchability = #1.5
1979   }
1980   \context { \StaffGroup
1981     \override StaffGrouper #'staff-staff-spacing #'stretchability = #2.5
1982     \override SystemStartBracket #'collapse-height = #1
1983   }
1984   \context { \GrandStaff
1985     \override StaffGrouper #'staff-staff-spacing #'stretchability = #3
1986     \override StaffGrouper #'staffgroup-staff-spacing #'stretchability = #3
1987    }
1988   \context { \ChoirStaff
1989     \override StaffGrouper #'staff-staff-spacing #'stretchability = #1
1990   }
1991   \context { \Staff
1992     \override StaffGrouper #'staff-staff-spacing #'stretchability = #4.9
1993   }
1994   \context { \Score
1995     \override StaffGrouper #'staff-staff-spacing #'stretchability = #5
1996   }
2001 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2003 %%%%%   WORKAROUNDS!
2004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2005 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2007 % _ does not work as a direction modifier in figured bass
2008 tsdown = #(make-music 'TextScriptEvent 'text "t.s." 'direction DOWN )