Fix compilation, BC instrument names, organ in full score
[orchestrallily.git] / orchestrallily.ily
blob862013ea2dfa108c6dfec086aa126a9ebe716801
1 \version "2.11.41"
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: GPL v3.0, http://www.gnu.org/licenses/gpl.html
13 % Version History:
14 % 0.01 (2008-03-02): Initial Version
15 % 0.02 (2008-03-06): Added basic MIDI support (*MidiInstrument and \setCreateMIDI)
16 % 0.03 (2008-07-xx): General staff/voice types, title pages, etc.
17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19 #(use-modules (ice-9 match))
22 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24 %%%%%   SCORE STRUCTURE AND AUTOMATIC GENERATION
25 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 % Helper functions
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 % Helper function to filter all non-null entries
36 #(define (not-null? x) (not (null? x)))
38 % Helper function to extract a given variable, built from [Piece][Instrument]Identifier
39 #(define (namedPieceInstrObject piece instr name)
40   (let* (
41          (fullname  (string->symbol (string-append piece instr name)))
42          (instrname (string->symbol (string-append instr name)))
43          (piecename (string->symbol (string-append piece name)))
44         )
45     (cond
46       ((defined? fullname) (primitive-eval fullname))
47       ((defined? instrname) (primitive-eval instrname))
48       ((defined? piecename) (primitive-eval piecename))
49       (else '())
50     )
51   )
54 %% Print text as a justified paragraph, taken from the lilypond Notation Reference
55 #(define-markup-list-command (paragraph layout props args) (markup-list?)
56    (let ((indent (chain-assoc-get 'par-indent props 2)))
57      (interpret-markup-list layout props
58        (make-justified-lines-markup-list (cons (make-hspace-markup indent)
59                                                args)))))
61 conditionalBreak = #(define-music-function (parser location) ()
62    #{ \tag #'instrumental-score \pageBreak #}
65 #(define (oly:piece-title-markup title) (markup #:column (#:line (#:fontsize #'3 #:bold title))) )
67 #(define-markup-command (piece-title layout props title) (markup?)
68      (interpret-markup layout props (oly:piece-title-markup title))
71 #(define (oly:generate_object_name piece instr obj )
72   (if (and (string? piece) (string? instr) (string? obj))
73     (string-append piece instr obj)
74     #f
75   )
77 #(define (oly:generate_staff_name piece instr) (oly:generate_object_name piece instr "St"))
79 #(define (set-context-property context property value)
80   (set! (ly:music-property context property) value)
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 % Score structure and voice types
86 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 #(define oly:orchestral_score_structure '(
89 ; Part-combined staves for full score
90   ("Fl" "PartCombinedStaff" ("FlI" "FlII"))
91   ("Ob" "PartCombinedStaff" ("ObI" "ObII"))
92   ("Cl" "PartCombinedStaff" ("ClI" "ClII"))
93   ("Fag" "PartCombinedStaff" ("FagI" "FagII"))
94   ("Wd" "StaffGroup" ("Fl" "Ob" "Cl" "Fag" "CFag"))
96   ("Cor" "PartCombinedStaff" ("CorI" "CorII"))
97   ("Trb" "PartCombinedStaff" ("TrbI" "TrbII"))
98   ("Tbe" "PartCombinedStaff" ("TbeI" "TbeII"))
99   ("Br" "StaffGroup" ("Cor" "Trb" "Tbe" "Tba"))
101 ; long score; no part-combined staves, but GrandStaves instead
102   ("FlLong" "GrandStaff" ("FlI" "FlII"))
103   ("ObLong" "GrandStaff" ("ObI" "ObII"))
104   ("ClLong" "GrandStaff" ("ClI" "ClII"))
105   ("FagLong" "GrandStaff" ("FagI" "FagII"))
106   ("WdLong" "StaffGroup" ("FlLong" "ObLong" "ClLong" "FagLong" "CFag"))
108   ("CorLong" "GrandStaff" ("CorI" "CorII"))
109   ("TrbLong" "GrandStaff" ("TrbI" "TrbII"))
110   ("TbeLong" "GrandStaff" ("TbeI" "TbeII" "TbeIII"))
111   ("BrLong" "StaffGroup" ("CorLong" "TrbLong" "TbeLong" "Tba"))
113 ; Percussion
114   ("Perc" "StaffGroup" ("Tim"))
116 ; Strings, they are the same in long and short full score  
117   ("V" "GrandStaff" ("VI" "VII"))
118   ("Str" "StaffGroup" ("V" "Va"))
119   ("VceB" "StaffGroup" ("Vc" "Cb" "VcB"))
120   ("FullStr" "StaffGroup" ("V" "Va" "Vc" "Cb" "VcB"))
122 ; Choral score
123   ("Solo" "SimultaneousMusic" ("SSolo" "ASolo" "TSolo" "BSolo"))
124   ("Ch" "ChoirStaff" ("S" "A" "T" "B"))
125   ("ChoralScore" "SimultaneousMusic" ("Ch"))
126   ("SoloScore" "SimultaneousMusic" ("Solo"))
127   ("SoloChoirScore" "SimultaneousMusic" ("Solo" "Ch"))
129 ; Organ score (inkl. Figured bass)
130   ("BCFb" "FiguredBass" ())
131   ("FiguredBass" "FiguredBass" ())
132   ;("Organ" "SimultaneousMusic" ("BCFb" "O"))
133   ("Organ" "ParallelVoicesStaff" ("BCFb" "BC" "FiguredBass"))
134   ;("BC" "ParallelVoicesStaff" ("BCFb" "O" "BC" "FiguredBass"))
135   
136   ("O" "PianoStaff" ("OI" "OII"))
137   ("OI" "ParallelVoicesStaff" ("OIa" "OIb"))
138   ("OII" "ParallelVoicesStaff" ("OIIa" "OIIb"))
140 ; Full Scores
141   ("FullScore" "SimultaneousMusic" ("Wd" "Br" "Perc" "Str" "SoloChoirScore" "Organ" "O" "BC" "VceB"))
142   ("LongScore" "SimultaneousMusic" ("WdLong" "BrLong" "Perc" "Str" "SoloChoirScore" "Organ" "O" "BC" "VceB"))
144 ; Piano reduction
145   ;("Piano" "SimultaneousMusic" ("Organ"))
146   ("OrganScore" "SimultaneousMusic" ("ChoralScore" "O" "BC"))
147   ("VocalScore" "SimultaneousMusic" ("ChoralScore" "O" "Organ" "Piano"))
149 ; Full scores: Orchestral score and long score including organ
150   ("ChStrQ" "SimultaneousMusic" ("Str" "Ch" "VceB"))
153 #(define (oly:set_score_structure struct)
154   (if (list? struct)
155     (set! oly:orchestral_score_structure struct)
156     (ly:warning (_ "oly:set_score_structure needs an association list as argument!"))
157   )
160 orchestralScoreStructure = #(define-music-function (parser location structure) (list?) 
161   (oly:set_score_structure structure)
162   (make-music 'Music 'void #t)
165 #(define oly:voice_types '())
167 #(define (oly:set_voice_types types)
168   (if (list? types)
169     (set! oly:voice_types types)
170     (ly:warning (_ "oly:set_voice_types needs an association list as argument!"))
171   )
174 orchestralVoiceTypes = #(define-music-function (parser location types) (list?)
175   (oly:set_voice_types types)
176   (make-music 'Music 'void #t)
180 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 % Automatic staff and group generation
182 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184 % Retrieve all music definitions for the given 
185 #(define (oly:get_music_object piece instrument)
186   (namedPieceInstrObject piece instrument "Music")
188 #(define (oly:get_music_objects piece instruments)
189   (filter not-null? (map (lambda (i) (oly:get_music_object piece i)) instruments))
192 % Given a property name and the extensions, either generate the pair to set 
193 % the property or an empty list, if no pre-defined variable could be found
194 #(define (oly:generate_property_pair prop piece instr type)
195   (let* ((val (namedPieceInstrObject piece instr type)))
196     (if (not-null? val) (list 'assign prop val) '() )
197   )
199   
200 #(define (oly:staff_type type)
201   (cond 
202     ((string? type) (string->symbol type))
203     ((symbol? type) type)
204     (else 'Staff)
205   )
208 #(define (oly:extractPitch music)
209   (let* (
210          (elems  (if (ly:music? music) (ly:music-property music 'elements)))
211          (note   (if (pair? elems) (car elems)))
212          (pitch  (if (ly:music? note) (ly:music-property note 'pitch)))
213         )
214     (if (and (not-null? music) (not (ly:pitch? pitch))) 
215       (ly:warning "Unable to interpret as a pitch!")
216     )
217     pitch
218   )
221 #(define (oly:extractTranspositionPitch piece name)
222   (let* (
223          (trpFromPitch (oly:extractPitch (namedPieceInstrObject piece name "TransposeFrom")))
224          (trpToPitch   (oly:extractPitch (namedPieceInstrObject piece name "TransposeTo")))
225         )
226     (if (ly:pitch? trpFromPitch)
227       (if (ly:pitch? trpToPitch)
228         ; Both pitches
229         (ly:pitch-diff trpFromPitch trpToPitch)
230         (ly:pitch-diff trpFromPitch (ly:make-pitch 0 0 0))
231       )
232       (if (ly:pitch? trpToPitch)
233         (ly:pitch-diff (ly:make-pitch 0 0 0) trpToPitch)
234         #f
235       )
236     )
237   )
240 #(define (oly:musiccontent_for_voice parser piece name music additional)
241   (let* ((musiccontent additional))
242     
243     ; Append the settings, key and clef (if defined)
244     (map 
245       (lambda (type) 
246         (let* ((object (namedPieceInstrObject piece name type)))
247           (if (ly:music? object)
248             (set! musiccontent (append musiccontent (list (ly:music-deep-copy object))))
249             (if (not-null? object) (ly:warning (_ "Wrong type (no ly:music) for ~S for instrument ~S in piece ~S") type name piece))
250           )
251         )
252       )
253       ; TODO: Does the "Tempo" work here???
254       '("Settings" "Key" "Clef" "TimeSignature" ;"Tempo"
255       )
256     )
258     (if (ly:music? music)
259       (begin
260         (set! musiccontent (make-simultaneous-music (append musiccontent (list music))))
261         ;(ly:message "Generating staff for ~a" name)
262         (let* ((trpPitch (oly:extractTranspositionPitch piece name)))
263           (if (ly:pitch? trpPitch) 
264             (set! musiccontent (ly:music-transpose musiccontent trpPitch))
265           )
266         )
267         musiccontent
268       )
269       ; For empty music, return empty 
270       '()
271     )
272   )
274 #(define (oly:voice_handler_internal parser piece name type music)
275   (let* (
276          (lyrics   (namedPieceInstrObject piece name "Lyrics"))
277          (additional '())
278         )
279     
280     (if (ly:music? lyrics)
281       (set! additional (list dynamicUp))
282       (if (not-null? lyrics) (ly:warning (_ "Wrong type (no lyrics) for lyrics for instrument ~S in piece ~S") name piece))
283     )
285     (if (ly:music? music)
286       (let* ((musiccontent (oly:musiccontent_for_voice parser piece name music additional))
287              (voicename  (oly:generate_object_name piece name "Voice" ))
288              (voicetype  (oly:staff_type type))
289              (voice      (context-spec-music musiccontent voicetype voicename))
290              (staffcont  (list voice))
291             )
292         ; If we have lyrics, create a lyrics context containing LyricCombineMusic 
293         ; and add that as second element to the staff's elements list...
294         (if (ly:music? lyrics)
295           (let* (
296                  (lyricsname (oly:generate_object_name piece name "Lyrics" ))
297                  (lyricscont (make-music 'LyricCombineMusic 'element lyrics 'associated-context voicename))
298                 )
299             (set! staffcont (append staffcont 
300               (list (context-spec-music lyricscont 'Lyrics lyricsname))))
301           )
302         )
303         staffcont
304       )
305       ; For empty music, return empty 
306       '()
307     )
308   )
311 #(define (oly:voice_handler parser piece name type)
312   (let* ((music (oly:get_music_object piece name))
313         )
314     (oly:voice_handler_internal parser piece name type music)
315   )
319 #(define (oly:staff_handler_internal parser piece name type voices)
320   (if (not-null? voices)
321     (let* (
322            (staffname  (oly:generate_staff_name piece name))
323            (stafftype  (oly:staff_type type))
324            (staff      (make-simultaneous-music voices))
325            (propops    (oly:staff_handler_properties piece name))
326           )
327       (case stafftype
328         ((SimultaneousMusic ParallelMusic) #f)
329         (else (set! staff (context-spec-music staff stafftype staffname)))
330       )
331       (if (not-null? propops)
332         (set! (ly:music-property staff 'property-operations) propops)
333       )
334       staff
335     )
336     ; For empty music, return empty 
337     '()
338   )
341 #(define (oly:staff_handler parser piece name type children)
342   (let* ((c (if (not-null? children) children (list name)))
343          (voices (apply append (map (lambda (v) (oly:create_voice parser piece v)) c)) ) 
344         )
345     (if (not-null? voices)
346       (oly:staff_handler_internal parser piece name type voices)
347       '()
348     )
349   )
351   
352 #(define (oly:parallel_voices_staff_handler parser piece name type children) 
353   (let* (
354          (voices (map (lambda (i) (oly:create_voice parser piece i)) children))
355          ; get the list of non-empty voices and flatten it!
356          (nonemptyvoices (apply append (filter not-null? voices)))
357         )
358     (if (not-null? nonemptyvoices)
359       (oly:staff_handler_internal parser piece name "Staff" nonemptyvoices)
360       '()
361     )
362   )
365 #(define (oly:part_combined_staff_handler parser piece name type children) 
366   (let* ((rawmusic (map (lambda (c) (oly:musiccontent_for_voice parser piece name (oly:get_music_object piece c) '())) children))
367          (music (filter not-null? rawmusic)))
368   (cond
369       ((and (pair? music) (ly:music? (car music)) (not-null? (cdr music)) (ly:music? (cadr music)))
370           ;(ly:message "Part-combine with two music expressions")
371           (oly:staff_handler_internal parser piece name "Staff" (list (make-part-combine-music parser music))))
372       ((null? music) 
373           (ly:warning "Part-combine without any music expressions")
374           '())
375       ; exactly one is a music expression, simply use that by joining 
376       ((list? music) 
377           (ly:message "Part-combine with only one music expressions")
378           (oly:staff_handler_internal parser piece name "Staff" (list (apply append music))))
379       (else 
380           ;(ly:message "make_part_combined_staff: ~S ~S ~a" piece instr instruments) 
381           '() )
382     )
383   )
386 % Generate the properties for the staff for piece and instr. Typically, these
387 % are the instrument name and the short instrument name (if defined).
388 % return a (possibly empty) list of all assignments.
389 #(define (oly:staff_handler_properties piece instr)
390   (let* (
391          (mapping '( 
392               (instrumentName . "InstrumentName") 
393               (shortInstrumentName . "ShortInstrumentName")
394               (midiInstrument . "MidiInstrument")
395             ))
396          (assignments (map 
397              (lambda (pr) 
398                  (oly:generate_property_pair (car pr) piece instr (cdr pr))
399              )
400              mapping))
401          (props (filter not-null? assignments))
402         )
403     props
404   )
406   
407 % Figured bass is a special case, as it can be voice- or staff-type. When
408 % given as a staff type, simply call the voice handler, instead
410 #(define (oly:figured_bass_staff_handler parser piece name type children)
411   (let* ((c (if (not-null? children) children (list name)))
412          (voice  (oly:voice_handler parser piece (car c) type)))
413     (if (pair? voice) (car voice) ())
414   )
416   
418 #(define (oly:staff_group_handler parser piece name type children)
419   (let* (
420          (staves (map (lambda (i) (oly:create_staff_or_group parser piece i)) children))
421          (nonemptystaves (filter not-null? staves))
422         )
423     (if (not-null? nonemptystaves)
424       (let* (
425              (musicexpr (if (= 1 (length nonemptystaves)) 
426                           (car nonemptystaves) 
427                           (make-simultaneous-music nonemptystaves)))
428              (groupname (oly:generate_staff_name piece name))
429              (grouptype (oly:staff_type type))
430              (group     musicexpr)
431              (propops   (oly:staff_handler_properties piece name))
432             )
433         (case grouptype
434           ((SimultaneousMusic ParallelMusic) #f)
435           (else (set! group (context-spec-music group grouptype groupname)))
436         )
437         (set! (ly:music-property group 'property-operations) propops)
438         group
439       )
440       ; Return empty list if no staves are generated
441       '()
442     )
443   )
446 #(define (oly:create_voice parser piece name)
447   (let* ( (voice (namedPieceInstrObject piece name "Voice"))
448           (type (assoc-ref oly:voice_types name)) )
449     (if (not-null? voice)
450       ; Explicit voice variable, use that
451       voice
452       
453       (if (not type)
454         ; No entry in structure found => simple voice
455         (oly:voice_handler parser piece name "Voice")
456         ; Entry found in structure => use the handler for the given type
457         (let* (
458                (voicetype (car type))
459                (handler (assoc-ref oly:voice_handlers voicetype))
460               )
461           (if handler
462             ((primitive-eval handler) parser piece name voicetype)
463             (begin
464               (ly:warning "No handler found for voice type ~a, using default voice handler" voicetype)
465               (oly:voice_handler parser piece name voicetype)
466             )
467           )
468         )
469       )
470     )
471   )
474 #(define (oly:create_staff_or_group parser piece name)
475   (let* ( (staff (namedPieceInstrObject piece name "Staff"))
476           (type_from_structure (assoc-ref oly:orchestral_score_structure name)) )
477     ;(if (not-null? staff)
478     ;  (ly:message "Found staff variable for instrument ~a in piece ~a"  instr piece)
479     ;  (ly:message "Staff variable for instrument ~a in piece ~a NOT FOUND"  instr piece)
480     ;)
481     (if (not-null? staff)
482       ; Explicit staff variable, use that
483       staff
484       
485       (if (not (list? type_from_structure)) 
486         ; No entry in structure found => simple staff
487         (oly:staff_handler parser piece name "Staff" '())
488         
489         ; Entry found in structure => use the handler for the given type
490         (let* ((type (car type_from_structure))
491                (handler (assoc-ref oly:staff_handlers type))
492                (children (cadr type_from_structure))
493               )
494           (if handler
495             ((primitive-eval handler) parser piece name type children)
496             (begin
497               (ly:warning "No handler found for staff type ~a, using default staff handler" type)
498               (oly:staff_handler parser piece name type children)
499             )
500           )
501         )
502       )
503     )
504   )
507 #(define oly:staff_handlers
508   (list
509     ; staff group types
510     '("GrandStaff" . oly:staff_group_handler )
511     '("PianoStaff" . oly:staff_group_handler )
512     '("ChoirStaff" . oly:staff_group_handler )
513     '("StaffGroup" . oly:staff_group_handler )
514     '("InnerChoirStaff" . oly:staff_group_handler )
515     '("InnerStaffGroup" . oly:staff_group_handler )
516     '("ParallelMusic" . oly:staff_group_handler )
517     '("SimultaneousMusic" . oly:staff_group_handler )
518     ; staff types
519     '("Staff" . oly:staff_handler )
520     '("DrumStaff" . oly:staff_handler )
521     '("RhythmicStaff" . oly:staff_handler )
522     '("TabStaff" . oly:staff_handler )
523     '("GregorianTranscriptionStaff" . oly:staff_handler )
524     '("MensuralStaff" . oly:staff_handler )
525     '("VaticanaStaff" . oly:staff_handler )
526     ; staves with multiple voices
527     '("PartCombinedStaff" . oly:part_combined_staff_handler )
528     '("ParallelVoicesStaff" . oly:parallel_voices_staff_handler )
529     ; special cases: Figured bass can be staff or voice type!
530     '("FiguredBass" . oly:figured_bass_staff_handler )
531   )
534 #(define oly:voice_handlers
535   (list
536     ; voice types
537     '("Voice" . oly:voice_handler )
538     '("CueVoice" . oly:voice_handler )
539     '("DrumVoice" . oly:voice_handler )
540     '("FiguredBass" . oly:voice_handler )
541     '("GregorianTranscriptionVoice" . oly:voice_handler )
542     '("NoteNames" . oly:voice_handler )
543     '("TabVoice" . oly:voice_handler )
544     '("VaticanaVoice" . oly:voice_handler )
545     ;'("Dynamics" . oly:dynamics_handler )
546   )
550 #(define (oly:register_staff_type_handler type func)
551 ;  (ly:message "Registering staff handler ~a for type ~a" func type)
552   (set! oly:staff_handlers (assoc-set! oly:staff_handlers type func))
555 #(define (oly:register_voice_type_handler type func)
556 ;  (ly:message "Registering voice type handler ~a for type ~a" func type)
557   (set! oly:voice_handlers (assoc-set! oly:voice_handlers type func))
560 % handlers for deprecated API
561 #(oly:register_staff_type_handler 'StaffGroup 'oly:staff_group_handler)
562 #(oly:register_staff_type_handler 'GrandStaff 'oly:staff_group_handler)
563 #(oly:register_staff_type_handler 'PianoStaff 'oly:staff_group_handler)
564 #(oly:register_staff_type_handler 'ChoirStaff 'oly:staff_group_handler)
565 #(oly:register_staff_type_handler 'Staff 'oly:staff_handler )
566 #(oly:register_staff_type_handler 'ParallelMusic 'oly:staff_group_handler)
567 #(oly:register_staff_type_handler 'SimultaneousMusic 'oly:staff_group_handler)
568 #(oly:register_staff_type_handler #t 'oly:part_combined_staff_handler )
569 #(oly:register_staff_type_handler #f 'oly:parallel_voices_staff_handler )
571     
573 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
574 % Automatic score generation
575 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
577 % \setUseBook ##t/##f sets a flag to determine whether the calls to createScore
578 % are from within a book block or not
579 % #(define oly:score_handler collect-scores-for-book)
580 #(define oly:score_handler toplevel-score-handler)
581 #(define oly:music_handler toplevel-music-handler)
582 #(define oly:text_handler toplevel-text-handler)
584 setUseBook = #(define-music-function (parser location usebook) (boolean?) 
585   (if usebook
586     (begin
587       (set! oly:score_handler book-score-handler)
588       (set! oly:music_handler book-music-handler)
589       (set! oly:text_handler book-text-handler)
590     )
591     (begin
592       (set! oly:score_handler toplevel-score-handler)
593       (set! oly:music_handler toplevel-music-handler)
594       (set! oly:text_handler toplevel-text-handler)
595     )
596   )
597   (make-music 'Music 'void #t)
601 % Two functions to handle midi-blocks: Either don't set one, or set an empty 
602 % one so that MIDI is generated
603 #(define (oly:set_no_midi_block score) '())
604 #(define (oly:set_midi_block score) 
605   (let* ((midiblock (if (defined? '$defaultmidi) 
606                         (ly:output-def-clone $defaultmidi) 
607                         (ly:make-output-def))))
608     (ly:output-def-set-variable! midiblock 'is-midi #t)
609     (ly:score-add-output-def! score midiblock)
610   )
613 % \setCreateMidi ##t/##f sets a flag to determine wheter MIDI output should
614 % be generated
615 #(define oly:apply_score_midi oly:set_no_midi_block)
616 setCreateMIDI = #(define-music-function (parser location createmidi) (boolean?)
617   (if createmidi
618     (set! oly:apply_score_midi oly:set_midi_block)
619     (set! oly:apply_score_midi oly:set_no_midi_block)
620   )
621   (make-music 'Music 'void #t)
625 % Two functions to handle layout-blocks: Either don't set one, or set an empty 
626 % one so that a PDF is generated
627 #(define (oly:set_no_layout_block score) '())
628 #(define (oly:set_layout_block score) 
629   (let* ((layoutblock (if (defined? '$defaultlayout) 
630                         (ly:output-def-clone $defaultlayout) 
631                         (ly:make-output-def))))
632     (ly:output-def-set-variable! layoutblock 'is-layout #t)
633     (ly:score-add-output-def! score layoutblock)
634   )
637 % \setCreatePDF ##t/##f sets a flag to determine wheter PDF output should
638 % be generated
639 #(define oly:apply_score_layout oly:set_no_layout_block)
640 setCreatePDF = #(define-music-function (parser location createlayout) (boolean?)
641   (if createlayout
642     (set! oly:apply_score_layout oly:set_layout_block)
643     (set! oly:apply_score_layout oly:set_no_layout_block)
644   )
645   (make-music 'Music 'void #t)
649 % Set the piece title in a new header block.
650 #(define (oly:set_piece_header score piecename)
651   (if (not-null? piecename)
652     (let* ((header (make-module)))
653       (module-define! header 'piece piecename)
654       (ly:score-set-header! score header)
655     )
656   )
660 % post-filter functions. By default, no filtering is done. However,
661 % for the *NoCues* function, the cue notes should be killed
662 identity = #(define-music-function (parser location music) (ly:music?) music)
663 cuefilter = #(define-music-function (parser location music) (ly:music?)
664   ((ly:music-function-extract removeWithTag) parser location 'cued ((ly:music-function-extract killCues) parser location music))
668 #(define (oly:create-toc-file layout pages)
669   (let* ((label-table (ly:output-def-lookup layout 'label-page-table)))
670     (if (not (null? label-table))
671       (let* ((format-line (lambda (toc-item)
672              (let* ((label (car toc-item))
673                     (text  (caddr toc-item))
674                     (label-page (and (list? label-table) 
675                                      (assoc label label-table)))
676                     (page (and label-page (cdr label-page))))
677                (format #f "~a, section, 1, {~a}, ~a" page text label))))
678              (formatted-toc-items (map format-line (toc-items)))
679              (whole-string (string-join formatted-toc-items ",\n"))
680              (output-name (ly:parser-output-name parser))
681              (outfilename (format "~a.toc" output-name))
682              (outfile (open-output-file outfilename)))
683         (if (output-port? outfile)
684             (display whole-string outfile)
685             (ly:warning (_ "Unable to open output file ~a for the TOC information") outfilename))
686         (close-output-port outfile)))))
689 #(define-public (oly:add-toc-item parser markup-symbol text)
690   (oly:music_handler parser (add-toc-item! markup-symbol text)))
693 #(define (oly:add-score parser score piecename)
694   (if (not-null? piecename)
695     (oly:add-toc-item parser 'tocItemMarkup piecename))
696   (oly:score_handler parser score)
698 % The helper function to build a score.
699 #(define (oly:createScoreHelper parser location piece children func)
700   (let* (
701          (staves    (oly:staff_group_handler parser piece "" "SimultaneousMusic" children))
702          (music     (if (not-null? staves)
703                         ((ly:music-function-extract func) parser location staves)
704                         '()
705                     ))
706          (score     '())
707          (piecename (namedPieceInstrObject piece (car children) "PieceName"))
708          (piecenametacet (namedPieceInstrObject piece (car children) "PieceNameTacet"))
709          (header    '())
710         )
711     (if (null? music)
712       ; No staves, print tacet
713       (begin 
714         (if (not-null? piecenametacet) (set! piecename piecenametacet))
715         (if (not-null? piecename)
716           (oly:add-score parser (list (oly:piece-title-markup piecename)) piecename)
717           (ly:warning (_ "No music and no score title found for part ~a and instrument ~a") piece children)
718         )
719       )
720       ; we have staves, apply the piecename to the score and add layout/midi blocks if needed
721       (begin
722         (set! score (scorify-music music parser))
723         (oly:set_piece_header score piecename)
724         (oly:apply_score_midi score)
725         (oly:apply_score_layout score)
726         ; Schedule the score for typesetting
727         (oly:add-score parser score piecename)
728       )
729     )
730   )
731   ; This is a void function, the score has been schedulled for typesetting already
732   (make-music 'Music 'void #t)
735 createScore = #(define-music-function (parser location piece children) (string? list?)
736   (oly:createScoreHelper parser location piece children identity)
738 createNoCuesScore = #(define-music-function (parser location piece children) (string? list?)
739   (oly:createScoreHelper parser location piece children cuefilter)
742 createHeadline = #(define-music-function (parser location headline) (string?)
743   (oly:add-toc-item parser 'tocItemMarkup headline)
744   (oly:score_handler parser (list (oly:piece-title-markup headline)))
745   (make-music 'Music 'void #t)
750 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
751 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
752 %%%%%   CUE NOTES
753 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
754 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
756 newInstrument = #(define-music-function (parser location instr) (string?)
758   \set Voice.instrumentCueName = #$(string-join (list "+" instr))
761 cueText = #(define-music-function (parser location instr) (string?)
763   \set Voice.instrumentCueName = $instr
767 % generate a cue music section with instrument names
768 % Parameters: \namedCueDuring NameOfQuote CueDirection CueInstrument OriginalInstrument music
769 %                 -) NameOfQuote CueDirection music are the parameters for \cueDuring
770 %                 -) CueInstrument and OriginalInstrument are the displayed instrument names
771 % typical call:
772 % \namedCueDuring #"vIQuote" #UP #"V.I" #"Sop." { R1*3 }
773 %      This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
774 %      the beginning of the cue notes and "Sop." at the end
775 namedCueDuring = #(define-music-function (parser location cuevoice direction instrcue instr cuemusic) (string? number? string? string? ly:music?)
776    #{
777      \cueDuring #$cuevoice #$direction { \tag #'cued \cueText #$instrcue $cuemusic \tag #'cued \cueText #$instr }
778 %      \tag #'uncued $cuemusic
779    #}
781 namedTransposedCueDuring = #(define-music-function (parser location cuevoice direction instrcue instr trans cuemusic) (string? number? string? string? ly:music? ly:music?)
782    #{
783      \transposedCueDuring #$cuevoice #$direction $trans { \tag #'cued \cueText #$instrcue $cuemusic \tag #'cued \cueText #$instr }
784 %      \tag #'uncued $cuemusic
785    #}
788 % set the cue instrument name and clef
789 setClefCue = #(define-music-function (parser location instr clef) 
790                                                      (string? ly:music?)
791    #{
792      \once \override Staff.Clef #'font-size = #-3 $clef
793      \set Voice.instrumentCueName = $instr
794    #} )
796 % generate a cue music section with instrument names and clef changes
797 % Parameters: \cleffedCueDuring NameOfQuote CueDirection CueInstrument CueClef OriginalInstrument OriginalClef music
798 %                 -) NameOfQuote CueDirection music are the parameters for \cueDuring
799 %                 -) CueInstrument and OriginalInstrument are the displayed instrument names
800 %                 -) CueClef and OriginalClef are the clefs for the the cue notes and the clef of the containing voice
801 % typical call:
802 % \cleffedCueDuring #"vIQuote" #UP #"V.I" #"treble" #"Basso" #"bass" { R1*3 }
803 %      This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
804 %      the beginning of the cue notes and "Basso" at the end. The clef is changed to treble at the 
805 %      beginning of the cue notes and reset to bass at the end
806 cleffedCueDuring = #(define-music-function (parser location cuevoice direction instrcue clefcue instr clefinstr cuemusic) 
807                                                         (string? number? string? ly:music? string? ly:music? ly:music?)
808    #{
809      \cueDuring #$cuevoice #$direction { \tag #'cued \setClefCue #$instrcue $clefcue $cuemusic \tag #'cued \setClefCue #$instr $clefinstr }
810 %      \tag #'uncued $cuemusic
811    #}
817 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
818 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
819 %%%%%   DYNAMICS
820 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
821 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
824 dynamicsX = #(define-music-function (parser location offset) (number?)
826     \once \override DynamicText #'X-offset = $offset
827     \once \override DynamicLineSpanner #'Y-offset = #0
830 % Move the dynamic sign inside the staff to a fixed staff-relative position 
831 % posY (where 0 means vertically starts at the middle staff line)
832 dynamicsAllInside = #(define-music-function (parser location offsetX posY)
833 (number? number?)
835   % Invalid y-extent -> hidden from skyline calculation and collisions
836   \once \override DynamicLineSpanner #'Y-extent = #(cons +0 -0.01)
837   % move by X offset and to fixed Y-position (use Y-offset of parent!)
838   \once \override DynamicText #'X-offset = $offsetX
839   \once \override DynamicText #'Y-offset =
840     $(lambda (grob)
841        (let* ((head (ly:grob-parent grob Y))
842               (offset (ly:grob-property head 'Y-offset)))
843          (- posY  offset (- 0.6))))
844   \once \override DynamicLineSpanner #'Y-offset = $posY
847 dynamicsUpInside = #(define-music-function (parser location offsetX) (number?)
848   ((ly:music-function-extract dynamicsAllInside) parser location offsetX 1.5)
851 dynamicsDownInside = #(define-music-function (parser location offsetX) (number?)
852   ((ly:music-function-extract dynamicsAllInside) parser location offsetX -3.5)
855 hairpinOffset = #(define-music-function (parser location posY) (number?)
857   \once \override DynamicLineSpanner #'Y-offset = $posY
858   \once \override DynamicLineSpanner #'Y-extent = #(cons +0 -0.01)
861 #(define ((line-break-offset before after) grob)
862   (let* ((orig (ly:grob-original grob))
863          ; All siblings if line-broken:
864          (siblings (if (ly:grob? orig) (ly:spanner-broken-into orig) '() )))
865     (if (>= (length siblings) 2)
866       ; We have been line-broken
867       (if (eq? (car (last-pair siblings)) grob)
868         ; Last sibling:
869         (ly:grob-set-property! grob 'Y-offset after)
870         ; Others get the before value:
871         (ly:grob-set-property! grob 'Y-offset before)
872       )
873     )
874   )
877 ffz = #(make-dynamic-script "ffz")
878 pf = #(make-dynamic-script "pf")
879 sempp = #(make-dynamic-script (markup #:line( #:with-dimensions '(0 . 0) 
880 '(0 . 0) #:right-align #:normal-text #:italic "sempre" #:dynamic "pp")))
881 parenf = #(make-dynamic-script (markup #:line(#:normal-text #:italic #:fontsize 2 "(" #:dynamic "f" #:normal-text #:italic #:fontsize 2 ")" )))
882 parenp = #(make-dynamic-script (markup #:line(#:normal-text #:italic #:fontsize 2 "(" #:dynamic "p" #:normal-text #:italic #:fontsize 2 ")" )))
883 pdolce = #(make-dynamic-script (markup #:line(#:dynamic "p" #:with-dimensions '(0 . 0) '(0 . 0) #:normal-text #:italic "dolce"  )))
887 cresc = #(make-music 'CrescendoEvent 'span-direction START 'crescendoSpanner 'text 'crescendoText "cresc.")
888 endcresc =  #(make-span-event 'CrescendoEvent STOP)
889 dim = #(make-music 'DecrescendoEvent 'span-direction START 'decrescendoSpanner 'text 'decrescendoText "dim.")
890 enddim =  #(make-span-event 'DecrescendoEvent STOP)
891 decresc = #(make-music 'DecrescendoEvent 'span-direction START 'decrescendoSpanner 'text 'decrescendoText "decresc.")
892 enddecresc =  #(make-span-event 'DecrescendoEvent STOP)
894 setCresc = {}
895 setDecresc = {}
896 setDim = {}
898 newOrOldClef = #(define-music-function (parser location new old ) (string? string?)
899     (if (ly:get-option 'old-clefs) #{ \clef $old #} #{ \clef $new #}) 
904 %%% Thanks to "Gilles THIBAULT" <gilles.thibault@free.fr>, there is a way
905 %   to remove also the fermata from R1-\fermataMarkup: By filtering the music
906 %   and removing the corresponding events.
907 %   Documented as an LSR snippet: http://lsr.dsi.unimi.it/LSR/Item?id=372
908 #(define (filterOneEventsMarkup event)
909 ( let ( (eventname (ly:music-property  event 'name)) )
910  (not
911   (or     ;; add here event name you do NOT want
912    (eq? eventname 'MultiMeasureTextEvent)
913    (eq? eventname 'AbsoluteDynamicEvent)
914    (eq? eventname 'TextScriptEvent)
915    (eq? eventname 'ArticulationEvent)
916    (eq? eventname 'CrescendoEvent)
917    (eq? eventname 'DecrescendoEvent)
918   )
922 filterArticulations = #(define-music-function (parser location music) (ly:music?)
923   Â (music-filter filterOneEventsMarkup music)
930 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
931 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
932 %%%%%   Tempo markings
933 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
934 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
938 rit = \markup {\italic "rit."}
939 pocorit = \markup {\italic "poco rit."}
940 ppmosso = \markup {\italic "poco più mosso"}
941 dolce = \markup {\italic "dolce."}
942 pizz = \markup {\italic "pizz."}
943 arco = \markup {\italic "arco"}
944 perd = \markup {\italic "perdend."}
949 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
950 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
951 %%%%%   REST COMBINATION
952 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
953 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
957 %% REST COMBINING, TAKEN FROM http://lsr.dsi.unimi.it/LSR/Item?id=336
959 %% Usage:
960 %%   \new Staff \with {
961 %%     \override RestCollision #'positioning-done = #merge-rests-on-positioning
962 %%   } << \somevoice \\ \othervoice >>
963 %% or (globally):
964 %%   \layout {
965 %%     \context {
966 %%       \Staff
967 %%       \override RestCollision #'positioning-done = #merge-rests-on-positioning
968 %%     }
969 %%   } 
971 %% Limitations:
972 %% - only handles two voices
973 %% - does not handle multi-measure/whole-measure rests
975 #(define (rest-score r)
976   (let ((score 0)
977   (yoff (ly:grob-property-data r 'Y-offset))
978   (sp (ly:grob-property-data r 'staff-position)))
979     (if (number? yoff)
980   (set! score (+ score 2))
981   (if (eq? yoff 'calculation-in-progress)
982       (set! score (- score 3))))
983     (and (number? sp)
984    (<= 0 2 sp)
985    (set! score (+ score 2))
986    (set! score (- score (abs (- 1 sp)))))
987     score))
989 #(define (merge-rests-on-positioning grob)
990   (let* ((can-merge #f)
991    (elts (ly:grob-object grob 'elements))
992    (num-elts (and (ly:grob-array? elts)
993       (ly:grob-array-length elts)))
994    (two-voice? (= num-elts 2)))
995     (if two-voice?
996   (let* ((v1-grob (ly:grob-array-ref elts 0))
997          (v2-grob (ly:grob-array-ref elts 1))
998          (v1-rest (ly:grob-object v1-grob 'rest))
999          (v2-rest (ly:grob-object v2-grob 'rest)))
1000     (and
1001      (ly:grob? v1-rest)
1002      (ly:grob? v2-rest)          
1003      (let* ((v1-duration-log (ly:grob-property v1-rest 'duration-log))
1004       (v2-duration-log (ly:grob-property v2-rest 'duration-log))
1005       (v1-dot (ly:grob-object v1-rest 'dot))
1006       (v2-dot (ly:grob-object v2-rest 'dot))
1007       (v1-dot-count (and (ly:grob? v1-dot)
1008              (ly:grob-property v1-dot 'dot-count -1)))
1009       (v2-dot-count (and (ly:grob? v2-dot)
1010              (ly:grob-property v2-dot 'dot-count -1))))
1011        (set! can-merge
1012        (and 
1013         (number? v1-duration-log)
1014         (number? v2-duration-log)
1015         (= v1-duration-log v2-duration-log)
1016         (eq? v1-dot-count v2-dot-count)))
1017        (if can-merge
1018      ;; keep the rest that looks best:
1019      (let* ((keep-v1? (>= (rest-score v1-rest)
1020               (rest-score v2-rest)))
1021       (rest-to-keep (if keep-v1? v1-rest v2-rest))
1022       (dot-to-kill (if keep-v1? v2-dot v1-dot)))
1023        ;; uncomment if you're curious of which rest was chosen:
1024        ;;(ly:grob-set-property! v1-rest 'color green)
1025        ;;(ly:grob-set-property! v2-rest 'color blue)
1026        (ly:grob-suicide! (if keep-v1? v2-rest v1-rest))
1027        (if (ly:grob? dot-to-kill)
1028            (ly:grob-suicide! dot-to-kill))
1029        (ly:grob-set-property! rest-to-keep 'direction 0)
1030        (ly:rest::y-offset-callback rest-to-keep)))))))
1031     (if can-merge
1032   #t
1033   (ly:rest-collision::calc-positioning-done grob))))
1039 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1041 %%%%%   TABLE OF CONTENTS
1042 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1043 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1046 contentsTitle = "Inhalt / Contents"
1048 \paper {
1049   tocTitleMarkup = \markup \fill-line{ 
1050     \null 
1051     \column {
1052       \override #(cons 'line-width (* 7 cm)) 
1053       \line{ \fill-line {\piece-title {\contentsTitle} \null }}
1054       \hspace #1
1055     }
1056     \null 
1057   }
1058   tocItemMarkup = \markup \fill-line { 
1059     \null 
1060     \column {
1061       \override #(cons 'line-width (* 7 cm )) 
1062       \line { \fill-line{\fromproperty #'toc:text \fromproperty #'toc:page }}
1063     }
1064     \null
1065   }
1069 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1070 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1071 %%%%%   TITLE PAGE / HEADER
1072 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1073 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1075 #(define-markup-command (when-property layout props symbol markp) (symbol? markup?)
1076   (if (chain-assoc-get symbol props)
1077       (interpret-markup layout props markp)
1078       (ly:make-stencil '()  '(1 . -1) '(1 . -1))))
1080 #(define-markup-command (vspace layout props amount) (number?)
1081   "This produces a invisible object taking vertical space."
1082   (let ((amount (* amount 3.0)))
1083     (if (> amount 0)
1084         (ly:make-stencil "" (cons -1 1) (cons 0 amount))
1085         (ly:make-stencil "" (cons -1 1) (cons amount amount)))))
1089 titlePageMarkup = \markup \abs-fontsize #10 \when-property #'header:title \column {
1090     \vspace #4
1091     \fill-line { \fontsize #8 \fromproperty #'header:composer }
1092     \vspace #1
1093     \fill-line { \fontsize #8 \fromproperty #'header:poet }
1094     \vspace #4
1095     \fill-line { \fontsize #10 \bold \fromproperty #'header:titlepagetitle }
1096     \vspace #1
1097     \fontsize #2 \when-property #'header:titlepagesubtitle { 
1098       \fill-line { \fromproperty #'header:titlepagesubtitle }
1099       \vspace #1
1100     }
1101     \fill-line { \postscript #"-20 0 moveto 40 0 rlineto stroke" }
1102     \vspace #8
1103     \fill-line { \fontsize #5 \fromproperty #'header:ensemble }
1104     \vspace #0.02
1105     \fill-line { \fontsize #2 \fromproperty #'header:instruments }
1106     \vspace #9
1107     \fill-line { \fontsize #5 \fromproperty #'header:date }
1108     \vspace #1
1109     \fill-line { \fontsize #5 \fromproperty #'header:scoretype }
1110     \vspace #8
1111     \fontsize #2 \when-property #'header:enteredby { 
1112       \fill-line { "Herausgegeben von: / Edited by:"}
1113       \vspace #0.
1114       \fill-line { \fromproperty #'header:enteredby }
1115     }
1116     \fill-line {
1117       \when-property #'header:arrangement \column {
1118         \vspace #8
1119         \fill-line { \fontsize #3 \fromproperty #'header:arrangement }
1120       }
1121     }
1124 titleHeaderMarkup = \markup {
1125   \override #'(baseline-skip . 3.5)
1126   \column {
1127     \override #'(baseline-skip . 3.5)
1128     \column {
1129       \huge \larger \bold
1130       \fill-line {
1131         \larger \fromproperty #'header:title
1132       }
1133       \fill-line {
1134         \large \smaller \bold
1135         \larger \fromproperty #'header:subtitle
1136       }
1137       \fill-line {
1138         \smaller \bold
1139         \fromproperty #'header:subsubtitle
1140       }
1141       \fill-line {
1142         { \large \bold \fromproperty #'header:instrument }
1143       }
1144       \fill-line {
1145         \fromproperty #'header:poet
1146         \fromproperty #'header:composer
1147       }
1148       \fill-line {
1149         \fromproperty #'header:meter
1150         \fromproperty #'header:arranger
1151       }
1152     }
1153   }
1156 titleScoreMarkup = \markup \piece-title \fromproperty #'header:piece
1158 \paper {
1159   scoreTitleMarkup = \titleScoreMarkup
1160   bookTitleMarkup = \titleHeaderMarkup
1165 %%%%%%%%%%%%%% headers and footers %%%%%%%%%%%%%%%%%%%%%%%%%%
1167 #(define (first-score-page layout props arg)
1168   (let* ((label 'first-score-page)
1169          (table (ly:output-def-lookup layout 'label-page-table))
1170          (label-page (and (list? table) (assoc label table)))
1171          (page-number (and label-page (cdr label-page)))
1172         )
1173     (if (eq? (chain-assoc-get 'page:page-number props -1) page-number)
1174       (interpret-markup layout props arg)
1175       empty-stencil)))
1177 #(define no-header-table '())
1178 thisPageNoHeader = #(define-music-function (parser location) ()
1179   (let* ((label (gensym "header")))
1180     (set! no-header-table (cons label no-header-table))
1181     (make-music 'Music 
1182       'page-marker #t
1183       'page-label label)))
1186 % TODO: Use the no-header-table!
1187 #(define (is-header-page layout props arg)
1188   (let* ((page-number (chain-assoc-get 'page:page-number props -1))
1189         )
1190     ;(if (and (> page-number 2) (!= page-number 7))
1191     (if (> page-number 1)
1192       (interpret-markup layout props arg)
1193       empty-stencil)))
1195 #(define no-footer-table '())
1196 thisPageNoFooter = #(define-music-function (parser location) ()
1197   (let* ((label (gensym "footer")))
1198     (set! no-footer-table (cons label no-footer-table))
1199     (make-music 'Music 
1200       'page-marker #t
1201       'page-label label)))
1203 % TODO: Use the no-footer-table!
1204 #(define (is-footer-page layout props arg)
1205   (let* ((page-number (chain-assoc-get 'page:page-number props -1))
1206          (label 'first-score-page)
1207          (table (ly:output-def-lookup layout 'label-page-table))
1208          (label-page (and (list? table) (assoc label table)))
1209          ;(page-number (and label-page (cdr label-page)))
1210         )
1211     (if (and (> page-number 1))
1212       (interpret-markup layout props arg)
1213       empty-stencil)))
1216 #(define copyright-footer-table '())
1217 thisPageCopyrightFooter = #(define-music-function (parser location) ()
1218   (let* ((label (gensym "copyrightfooter")))
1219     (set! copyright-footer-table (cons label copyright-footer-table))
1220     (make-music 'Music 
1221       'page-marker #t
1222       'page-label label)))
1224 #(define copyright-pg 1)
1225 #(define (set-copyright-page page)
1226   (set! copyright-pg page)
1229 % TODO: Use the copyright-footer-table!
1230 #(define (copyright-page layout props arg)
1231     (if (= (chain-assoc-get 'page:page-number props -1) copyright-pg)
1232       (interpret-markup layout props arg)
1233       empty-stencil))
1236 \paper {
1237   oddHeaderMarkup = \markup \fill-line {
1238     %% force the header to take some space, otherwise the
1239     %% page layout becomes a complete mess.
1240     " "
1241     \on-the-fly #is-header-page \fromproperty #'header:title
1242     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1243   }
1244   evenHeaderMarkup = \markup \fill-line {
1245     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1246     \on-the-fly #is-header-page \fromproperty #'header:composer
1247     " "
1248   }
1250   oddFooterMarkup = \markup {
1251     \column {
1252       \fill-line {
1253         %% publisher header field only on title page.
1254         \on-the-fly #first-page \fromproperty #'header:publisher
1255       }
1256       \fill-line {
1257         %% copyright on the first real score page
1258         \on-the-fly #copyright-page \fromproperty #'header:copyright
1259         \on-the-fly #copyright-page \null
1260       }
1261       \fill-line {
1262         %% All other pages get the number of the edition centered
1263         \on-the-fly #is-footer-page \fromproperty #'header:scorenumber
1264       }
1265     }
1266   }
1280 % Interpret the given markup with the header fields added to the props. 
1281 % This way, one can re-use the same functions (using fromproperty 
1282 % #'header:field) in the header block and as top-level markup.
1284 % This function is originally copied from mark-up-title (file scm/titling.scm), 
1285 % which is lilypond's internal function to handle the title markups. I needed 
1286 % to replace the scopes and manually add the $defaultheader (which is internally 
1287 % done in paper-book.cc before calling mark-up-title. Also, I don't extract the 
1288 % markup from the header block, but use the given markup.
1290 % I'm not sure if I really need the page properties in props, too... But I 
1291 % suppose it does not hurt, either.
1292 #(define-markup-command (markupWithHeader layout props markup) (markup?)
1293   "Interpret the given markup with the header fields added to the props. 
1294    This way, one can re-use the same functions (using fromproperty 
1295    #'header:field) in the header block and as top-level markup."
1296   (let* (
1297       ; TODO: If we are inside a score, add the score's local header block, too!
1298       ; Currently, I only use the global header block, stored in $defaultheader
1299       (scopes (list $defaultheader))
1300       (alists (map ly:module->alist scopes))
1301   
1302       (prefixed-alist
1303         (map (lambda (alist)
1304           (map (lambda (entry)
1305             (cons
1306               (string->symbol (string-append "header:" (symbol->string (car entry))))
1307               (cdr entry)))
1308             alist))
1309           alists))
1310       (props (append prefixed-alist
1311               props
1312               (layout-extract-page-properties layout)))
1313     )
1314     (interpret-markup layout props markup)
1315   )
1323 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1324 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1325 %%%%%   Equally spacing multiple columns (e.g. for translations)
1326 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1327 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1329 % Credits: Nicolas Sceaux on the lilypond-user mailinglist
1330 #(define-markup-command (columns layout props args) (markup-list?)
1331    (let ((line-width (/ (chain-assoc-get 'line-width props
1332                          (ly:output-def-lookup layout 'line-width))
1333                         (max (length args) 1))))
1334      (interpret-markup layout props
1335        (make-line-markup (map (lambda (line)
1336                                 (markup #:pad-to-box `(0 . ,line-width) '(0 . 0)
1337                                   #:override `(line-width . ,line-width)
1338                                   line))
1339                                args)))))
1345 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1346 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1347 %%%%%   SCORE (HEADER / LAYOUT) SETTINGS
1348 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1349 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1351 \paper {
1352 %   left-margin = 2\cm
1353 %   right-margin = 2\cm
1354 %   line-width = 17\cm
1355 %   bottom-margin = 1\cm
1356 %   top-margin = 1\cm
1357 %   after-title-space = 0.5\cm
1358   ragged-right = ##f
1359   ragged-last = ##f
1360   ragged-bottom = ##f
1361   ragged-last-bottom = ##f
1363 \layout {
1364   \context {
1365     \ChoirStaff 
1366     % If only one non-empty staff in a system exists, still print the backet
1367     \override SystemStartBracket #'collapse-height = #1
1368     \consists "Instrument_name_engraver"
1369   }
1370   \context {
1371     \StaffGroup
1372     % If only one non-empty staff in a system exists, still print the backet
1373     \override SystemStartBracket #'collapse-height = #1
1374     \consists "Instrument_name_engraver"
1375   }
1376   \context {
1377     \GrandStaff
1378     \override SystemStartBracket #'collapse-height = #1
1379     \consists "Instrument_name_engraver"
1380   }
1381   \context {
1382     \PianoStaff
1383 %     \override VerticalAxisGroup #'keep-fixed-while-stretching = ##t
1384   }
1385   \context {
1386     \FiguredBass
1387 %     \override VerticalAxisGroup #'keep-fixed-while-stretching = ##t
1388     \override VerticalAxisGroup #'minimum-Y-extent  = #'(0 . 1)
1389     \override VerticalAxisGroup #'padding = #0
1390   }
1391   \context {
1392     \Score
1393     % Force multi-measure rests to be written as one span
1394     \override MultiMeasureRest #'expand-limit = #3
1395     skipBars = ##t
1396     autoBeaming = ##f
1397 %     hairpinToBarline = ##f
1398     \override BarNumber #'break-visibility = #end-of-line-invisible
1399     \override BarNumber #'self-alignment-X = #0
1400     \override CombineTextScript #'avoid-slur = #'outside
1401     barNumberVisibility = #(every-nth-bar-number-visible 5)
1402     \override DynamicTextSpanner #'dash-period = #-1.0
1403     \override InstrumentSwitch #'font-size = #-1
1405     % Rest collision
1406     \override RestCollision #'positioning-done = #merge-rests-on-positioning
1407     % Auto-Accidentals: Use modern-cautionary style...
1408     extraNatural = ##f
1409     autoAccidentals = #`(Staff  ,(make-accidental-rule 'same-octave 0))
1410     autoCautionaries = #`(Staff ,(make-accidental-rule 'any-octave 0)
1411                                 ,(make-accidental-rule 'same-octave 1))
1412     printKeyCancellation = ##t
1413   }
1414   \context {
1415     \RemoveEmptyStaffContext 
1416   }
1417   \context {
1418     \Lyrics
1419     \override VerticalAxisGroup #'minimum-Y-extent = #'(0.5 . 0.5)
1420   }
1421   \context {
1422     \Staff
1423     \override VerticalAxisGroup #'minimum-Y-extent = #'(-1. . 3)
1424     quotedEventTypes = #'(StreamEvent)
1425   }
1430 \layout {
1431   \context {
1432     \type "Engraver_group"
1433     \name Dynamics
1434     % So that \cresc works, for example.
1435     \alias Voice
1436     \consists "Output_property_engraver"
1437     
1438     \override VerticalAxisGroup #'minimum-Y-extent = #'(-1 . 1)
1439     pedalSustainStrings = #'("Ped." "*Ped." "*")
1440     pedalUnaCordaStrings = #'("una corda" "" "tre corde")
1441     
1442     \consists "Piano_pedal_engraver"
1443     \consists "Script_engraver"
1444     \consists "Dynamic_engraver"
1445     \consists "Text_engraver"
1446     
1447     \override TextScript #'font-size = #2
1448     \override TextScript #'font-shape = #'italic
1449     \override DynamicText #'extra-offset = #'(0 . 2.5)
1450     \override Hairpin #'extra-offset = #'(0 . 2.5)
1451     
1452     \consists "Skip_event_swallow_translator"
1453     
1454     \consists "Axis_group_engraver"
1455   }
1456   \context {
1457     \PianoStaff
1458     \accepts Dynamics
1459 %     \override VerticalAlignment #'forced-distance = #7
1460   }