Implement slashed grace notes (no slur)
[orchestrallily.git] / orchestrallily.ily
bloba691004c9c69b12a3850e835421d437b79ae82f8
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   ("Continuo" "ParallelVoicesStaff" ("BCFb" "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"))
147   ("VocalScore" "SimultaneousMusic" ("ChoralScore" "Piano"))
148   ("Particell"  "SimultaneousMusic" ("ChoralScore" "Continuo"))
150 ; Full scores: Orchestral score and long score including organ
151   ("ChStrQ" "SimultaneousMusic" ("Str" "Ch" "VceB"))
154 #(define (oly:set_score_structure struct)
155   (if (list? struct)
156     (set! oly:orchestral_score_structure struct)
157     (ly:warning (_ "oly:set_score_structure needs an association list as argument!"))
158   )
161 orchestralScoreStructure = #(define-music-function (parser location structure) (list?) 
162   (oly:set_score_structure structure)
163   (make-music 'Music 'void #t)
166 #(define oly:voice_types '())
168 #(define (oly:set_voice_types types)
169   (if (list? types)
170     (set! oly:voice_types types)
171     (ly:warning (_ "oly:set_voice_types needs an association list as argument!"))
172   )
175 orchestralVoiceTypes = #(define-music-function (parser location types) (list?)
176   (oly:set_voice_types types)
177   (make-music 'Music 'void #t)
181 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182 % Automatic staff and group generation
183 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185 % Retrieve all music definitions for the given 
186 #(define (oly:get_music_object piece instrument)
187   (namedPieceInstrObject piece instrument "Music")
189 #(define (oly:get_music_objects piece instruments)
190   (filter not-null? (map (lambda (i) (oly:get_music_object piece i)) instruments))
193 % Given a property name and the extensions, either generate the pair to set 
194 % the property or an empty list, if no pre-defined variable could be found
195 #(define (oly:generate_property_pair prop piece instr type)
196   (let* ((val (namedPieceInstrObject piece instr type)))
197     (if (not-null? val) (list 'assign prop val) '() )
198   )
200   
201 #(define (oly:staff_type type)
202   (cond 
203     ((string? type) (string->symbol type))
204     ((symbol? type) type)
205     (else 'Staff)
206   )
209 #(define (oly:extractPitch music)
210   (let* (
211          (elems  (if (ly:music? music) (ly:music-property music 'elements)))
212          (note   (if (pair? elems) (car elems)))
213          (pitch  (if (ly:music? note) (ly:music-property note 'pitch)))
214         )
215     (if (and (not-null? music) (not (ly:pitch? pitch))) 
216       (ly:warning "Unable to interpret as a pitch!")
217     )
218     pitch
219   )
222 #(define (oly:extractTranspositionPitch piece name)
223   (let* (
224          (trpFromPitch (oly:extractPitch (namedPieceInstrObject piece name "TransposeFrom")))
225          (trpToPitch   (oly:extractPitch (namedPieceInstrObject piece name "TransposeTo")))
226         )
227     (if (ly:pitch? trpFromPitch)
228       (if (ly:pitch? trpToPitch)
229         ; Both pitches
230         (ly:pitch-diff trpFromPitch trpToPitch)
231         (ly:pitch-diff trpFromPitch (ly:make-pitch 0 0 0))
232       )
233       (if (ly:pitch? trpToPitch)
234         (ly:pitch-diff (ly:make-pitch 0 0 0) trpToPitch)
235         #f
236       )
237     )
238   )
241 #(define (oly:musiccontent_for_voice parser piece name music additional)
242   (let* ((musiccontent additional))
243     
244     ; Append the settings, key and clef (if defined)
245     (map 
246       (lambda (type) 
247         (let* ((object (namedPieceInstrObject piece name type)))
248           (if (ly:music? object)
249             (set! musiccontent (append musiccontent (list (ly:music-deep-copy object))))
250             (if (not-null? object) (ly:warning (_ "Wrong type (no ly:music) for ~S for instrument ~S in piece ~S") type name piece))
251           )
252         )
253       )
254       ; TODO: Does the "Tempo" work here???
255       '("Settings" "Key" "Clef" "TimeSignature" ;"Tempo"
256       )
257     )
259     (if (ly:music? music)
260       (begin
261         (set! musiccontent (make-simultaneous-music (append musiccontent (list music))))
262         ;(ly:message "Generating staff for ~a" name)
263         (let* ((trpPitch (oly:extractTranspositionPitch piece name)))
264           (if (ly:pitch? trpPitch) 
265             (set! musiccontent (ly:music-transpose musiccontent trpPitch))
266           )
267         )
268         musiccontent
269       )
270       ; For empty music, return empty 
271       '()
272     )
273   )
275 #(define (oly:voice_handler_internal parser piece name type music)
276   (let* (
277          (lyrics   (namedPieceInstrObject piece name "Lyrics"))
278          (additional '())
279         )
280     
281     (if (ly:music? lyrics)
282       (set! additional (list dynamicUp))
283       (if (not-null? lyrics) (ly:warning (_ "Wrong type (no lyrics) for lyrics for instrument ~S in piece ~S") name piece))
284     )
286     (if (ly:music? music)
287       (let* ((musiccontent (oly:musiccontent_for_voice parser piece name music additional))
288              (voicename  (oly:generate_object_name piece name "Voice" ))
289              (voicetype  (oly:staff_type type))
290              (voice      (context-spec-music musiccontent voicetype voicename))
291              (staffcont  (list voice))
292             )
293         ; If we have lyrics, create a lyrics context containing LyricCombineMusic 
294         ; and add that as second element to the staff's elements list...
295         (if (ly:music? lyrics)
296           (let* (
297                  (lyricsname (oly:generate_object_name piece name "Lyrics" ))
298                  (lyricscont (make-music 'LyricCombineMusic 'element lyrics 'associated-context voicename))
299                 )
300             (set! staffcont (append staffcont 
301               (list (context-spec-music lyricscont 'Lyrics lyricsname))))
302           )
303         )
304         staffcont
305       )
306       ; For empty music, return empty 
307       '()
308     )
309   )
312 #(define (oly:voice_handler parser piece name type)
313   (let* ((music (oly:get_music_object piece name))
314         )
315     (oly:voice_handler_internal parser piece name type music)
316   )
320 #(define (oly:staff_handler_internal parser piece name type voices)
321   (if (not-null? voices)
322     (let* (
323            (staffname  (oly:generate_staff_name piece name))
324            (stafftype  (oly:staff_type type))
325            (staff      (make-simultaneous-music voices))
326            (propops    (oly:staff_handler_properties piece name))
327           )
328       (case stafftype
329         ((SimultaneousMusic ParallelMusic) #f)
330         (else (set! staff (context-spec-music staff stafftype staffname)))
331       )
332       (if (not-null? propops)
333         (set! (ly:music-property staff 'property-operations) propops)
334       )
335       staff
336     )
337     ; For empty music, return empty 
338     '()
339   )
342 #(define (oly:staff_handler parser piece name type children)
343   (let* ((c (if (not-null? children) children (list name)))
344          (voices (apply append (map (lambda (v) (oly:create_voice parser piece v)) c)) ) 
345         )
346     (if (not-null? voices)
347       (oly:staff_handler_internal parser piece name type voices)
348       '()
349     )
350   )
352   
353 #(define (oly:parallel_voices_staff_handler parser piece name type children) 
354   (let* (
355          (voices (map (lambda (i) (oly:create_voice parser piece i)) children))
356          ; get the list of non-empty voices and flatten it!
357          (nonemptyvoices (apply append (filter not-null? voices)))
358         )
359     (if (not-null? nonemptyvoices)
360       (oly:staff_handler_internal parser piece name "Staff" nonemptyvoices)
361       '()
362     )
363   )
366 #(define (oly:part_combined_staff_handler parser piece name type children) 
367   (let* ((rawmusic (map (lambda (c) (oly:musiccontent_for_voice parser piece name (oly:get_music_object piece c) '())) children))
368          (music (filter not-null? rawmusic)))
369   (cond
370       ((and (pair? music) (ly:music? (car music)) (not-null? (cdr music)) (ly:music? (cadr music)))
371           ;(ly:message "Part-combine with two music expressions")
372           (oly:staff_handler_internal parser piece name "Staff" (list (make-part-combine-music parser music))))
373       ((null? music) 
374           (ly:warning "Part-combine without any music expressions")
375           '())
376       ; exactly one is a music expression, simply use that by joining 
377       ((list? music) 
378           (ly:message "Part-combine with only one music expressions")
379           (oly:staff_handler_internal parser piece name "Staff" (list (apply append music))))
380       (else 
381           ;(ly:message "make_part_combined_staff: ~S ~S ~a" piece instr instruments) 
382           '() )
383     )
384   )
387 % Generate the properties for the staff for piece and instr. Typically, these
388 % are the instrument name and the short instrument name (if defined).
389 % return a (possibly empty) list of all assignments.
390 #(define (oly:staff_handler_properties piece instr)
391   (let* (
392          (mapping '( 
393               (instrumentName . "InstrumentName") 
394               (shortInstrumentName . "ShortInstrumentName")
395               (midiInstrument . "MidiInstrument")
396             ))
397          (assignments (map 
398              (lambda (pr) 
399                  (oly:generate_property_pair (car pr) piece instr (cdr pr))
400              )
401              mapping))
402          (props (filter not-null? assignments))
403         )
404     props
405   )
407   
408 % Figured bass is a special case, as it can be voice- or staff-type. When
409 % given as a staff type, simply call the voice handler, instead
411 #(define (oly:figured_bass_staff_handler parser piece name type children)
412   (let* ((c (if (not-null? children) children (list name)))
413          (voice  (oly:voice_handler parser piece (car c) type)))
414     (if (pair? voice) (car voice) ())
415   )
417   
419 #(define (oly:staff_group_handler parser piece name type children)
420   (let* (
421          (staves (map (lambda (i) (oly:create_staff_or_group parser piece i)) children))
422          (nonemptystaves (filter not-null? staves))
423         )
424     (if (not-null? nonemptystaves)
425       (let* (
426              (musicexpr (if (= 1 (length nonemptystaves)) 
427                           (car nonemptystaves) 
428                           (make-simultaneous-music nonemptystaves)))
429              (groupname (oly:generate_staff_name piece name))
430              (grouptype (oly:staff_type type))
431              (group     musicexpr)
432              (propops   (oly:staff_handler_properties piece name))
433             )
434         (case grouptype
435           ((SimultaneousMusic ParallelMusic) #f)
436           (else (set! group (context-spec-music group grouptype groupname)))
437         )
438         (set! (ly:music-property group 'property-operations) propops)
439         group
440       )
441       ; Return empty list if no staves are generated
442       '()
443     )
444   )
447 #(define (oly:create_voice parser piece name)
448   (let* ( (voice (namedPieceInstrObject piece name "Voice"))
449           (type (assoc-ref oly:voice_types name)) )
450     (if (not-null? voice)
451       ; Explicit voice variable, use that
452       voice
453       
454       (if (not type)
455         ; No entry in structure found => simple voice
456         (oly:voice_handler parser piece name "Voice")
457         ; Entry found in structure => use the handler for the given type
458         (let* (
459                (voicetype (car type))
460                (handler (assoc-ref oly:voice_handlers voicetype))
461               )
462           (if handler
463             ((primitive-eval handler) parser piece name voicetype)
464             (begin
465               (ly:warning "No handler found for voice type ~a, using default voice handler" voicetype)
466               (oly:voice_handler parser piece name voicetype)
467             )
468           )
469         )
470       )
471     )
472   )
475 #(define (oly:create_staff_or_group parser piece name)
476   (let* ( (staff (namedPieceInstrObject piece name "Staff"))
477           (type_from_structure (assoc-ref oly:orchestral_score_structure name)) )
478     ;(if (not-null? staff)
479     ;  (ly:message "Found staff variable for instrument ~a in piece ~a"  instr piece)
480     ;  (ly:message "Staff variable for instrument ~a in piece ~a NOT FOUND"  instr piece)
481     ;)
482     (if (not-null? staff)
483       ; Explicit staff variable, use that
484       staff
485       
486       (if (not (list? type_from_structure)) 
487         ; No entry in structure found => simple staff
488         (oly:staff_handler parser piece name "Staff" '())
489         
490         ; Entry found in structure => use the handler for the given type
491         (let* ((type (car type_from_structure))
492                (handler (assoc-ref oly:staff_handlers type))
493                (children (cadr type_from_structure))
494               )
495           (if handler
496             ((primitive-eval handler) parser piece name type children)
497             (begin
498               (ly:warning "No handler found for staff type ~a, using default staff handler" type)
499               (oly:staff_handler parser piece name type children)
500             )
501           )
502         )
503       )
504     )
505   )
508 #(define oly:staff_handlers
509   (list
510     ; staff group types
511     '("GrandStaff" . oly:staff_group_handler )
512     '("PianoStaff" . oly:staff_group_handler )
513     '("ChoirStaff" . oly:staff_group_handler )
514     '("StaffGroup" . oly:staff_group_handler )
515     '("InnerChoirStaff" . oly:staff_group_handler )
516     '("InnerStaffGroup" . oly:staff_group_handler )
517     '("ParallelMusic" . oly:staff_group_handler )
518     '("SimultaneousMusic" . oly:staff_group_handler )
519     ; staff types
520     '("Staff" . oly:staff_handler )
521     '("DrumStaff" . oly:staff_handler )
522     '("RhythmicStaff" . oly:staff_handler )
523     '("TabStaff" . oly:staff_handler )
524     '("GregorianTranscriptionStaff" . oly:staff_handler )
525     '("MensuralStaff" . oly:staff_handler )
526     '("VaticanaStaff" . oly:staff_handler )
527     ; staves with multiple voices
528     '("PartCombinedStaff" . oly:part_combined_staff_handler )
529     '("ParallelVoicesStaff" . oly:parallel_voices_staff_handler )
530     ; special cases: Figured bass can be staff or voice type!
531     '("FiguredBass" . oly:figured_bass_staff_handler )
532   )
535 #(define oly:voice_handlers
536   (list
537     ; voice types
538     '("Voice" . oly:voice_handler )
539     '("CueVoice" . oly:voice_handler )
540     '("DrumVoice" . oly:voice_handler )
541     '("FiguredBass" . oly:voice_handler )
542     '("GregorianTranscriptionVoice" . oly:voice_handler )
543     '("NoteNames" . oly:voice_handler )
544     '("TabVoice" . oly:voice_handler )
545     '("VaticanaVoice" . oly:voice_handler )
546     ;'("Dynamics" . oly:dynamics_handler )
547   )
551 #(define (oly:register_staff_type_handler type func)
552 ;  (ly:message "Registering staff handler ~a for type ~a" func type)
553   (set! oly:staff_handlers (assoc-set! oly:staff_handlers type func))
556 #(define (oly:register_voice_type_handler type func)
557 ;  (ly:message "Registering voice type handler ~a for type ~a" func type)
558   (set! oly:voice_handlers (assoc-set! oly:voice_handlers type func))
561 % handlers for deprecated API
562 #(oly:register_staff_type_handler 'StaffGroup 'oly:staff_group_handler)
563 #(oly:register_staff_type_handler 'GrandStaff 'oly:staff_group_handler)
564 #(oly:register_staff_type_handler 'PianoStaff 'oly:staff_group_handler)
565 #(oly:register_staff_type_handler 'ChoirStaff 'oly:staff_group_handler)
566 #(oly:register_staff_type_handler 'Staff 'oly:staff_handler )
567 #(oly:register_staff_type_handler 'ParallelMusic 'oly:staff_group_handler)
568 #(oly:register_staff_type_handler 'SimultaneousMusic 'oly:staff_group_handler)
569 #(oly:register_staff_type_handler #t 'oly:part_combined_staff_handler )
570 #(oly:register_staff_type_handler #f 'oly:parallel_voices_staff_handler )
572     
574 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
575 % Automatic score generation
576 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
578 % \setUseBook ##t/##f sets a flag to determine whether the calls to createScore
579 % are from within a book block or not
580 % #(define oly:score_handler collect-scores-for-book)
581 #(define oly:score_handler toplevel-score-handler)
582 #(define oly:music_handler toplevel-music-handler)
583 #(define oly:text_handler toplevel-text-handler)
585 setUseBook = #(define-music-function (parser location usebook) (boolean?) 
586   (if usebook
587     (begin
588       (set! oly:score_handler book-score-handler)
589       (set! oly:music_handler book-music-handler)
590       (set! oly:text_handler book-text-handler)
591     )
592     (begin
593       (set! oly:score_handler toplevel-score-handler)
594       (set! oly:music_handler toplevel-music-handler)
595       (set! oly:text_handler toplevel-text-handler)
596     )
597   )
598   (make-music 'Music 'void #t)
602 % Two functions to handle midi-blocks: Either don't set one, or set an empty 
603 % one so that MIDI is generated
604 #(define (oly:set_no_midi_block score) '())
605 #(define (oly:set_midi_block score) 
606   (let* ((midiblock (if (defined? '$defaultmidi) 
607                         (ly:output-def-clone $defaultmidi) 
608                         (ly:make-output-def))))
609     (ly:output-def-set-variable! midiblock 'is-midi #t)
610     (ly:score-add-output-def! score midiblock)
611   )
614 % \setCreateMidi ##t/##f sets a flag to determine wheter MIDI output should
615 % be generated
616 #(define oly:apply_score_midi oly:set_no_midi_block)
617 setCreateMIDI = #(define-music-function (parser location createmidi) (boolean?)
618   (if createmidi
619     (set! oly:apply_score_midi oly:set_midi_block)
620     (set! oly:apply_score_midi oly:set_no_midi_block)
621   )
622   (make-music 'Music 'void #t)
626 % Two functions to handle layout-blocks: Either don't set one, or set an empty 
627 % one so that a PDF is generated
628 #(define (oly:set_no_layout_block score) '())
629 #(define (oly:set_layout_block score) 
630   (let* ((layoutblock (if (defined? '$defaultlayout) 
631                         (ly:output-def-clone $defaultlayout) 
632                         (ly:make-output-def))))
633     (ly:output-def-set-variable! layoutblock 'is-layout #t)
634     (ly:score-add-output-def! score layoutblock)
635   )
638 % \setCreatePDF ##t/##f sets a flag to determine wheter PDF output should
639 % be generated
640 #(define oly:apply_score_layout oly:set_no_layout_block)
641 setCreatePDF = #(define-music-function (parser location createlayout) (boolean?)
642   (if createlayout
643     (set! oly:apply_score_layout oly:set_layout_block)
644     (set! oly:apply_score_layout oly:set_no_layout_block)
645   )
646   (make-music 'Music 'void #t)
650 % Set the piece title in a new header block.
651 #(define (oly:set_piece_header score piecename)
652   (if (not-null? piecename)
653     (let* ((header (make-module)))
654       (module-define! header 'piece piecename)
655       (ly:score-set-header! score header)
656     )
657   )
661 % post-filter functions. By default, no filtering is done. However,
662 % for the *NoCues* function, the cue notes should be killed
663 identity = #(define-music-function (parser location music) (ly:music?) music)
664 cuefilter = #(define-music-function (parser location music) (ly:music?)
665   ((ly:music-function-extract removeWithTag) parser location 'cued ((ly:music-function-extract killCues) parser location music))
669 #(define (oly:create-toc-file layout pages)
670   (let* ((label-table (ly:output-def-lookup layout 'label-page-table)))
671     (if (not (null? label-table))
672       (let* ((format-line (lambda (toc-item)
673              (let* ((label (car toc-item))
674                     (text  (caddr toc-item))
675                     (label-page (and (list? label-table) 
676                                      (assoc label label-table)))
677                     (page (and label-page (cdr label-page))))
678                (format #f "~a, section, 1, {~a}, ~a" page text label))))
679              (formatted-toc-items (map format-line (toc-items)))
680              (whole-string (string-join formatted-toc-items ",\n"))
681              (output-name (ly:parser-output-name parser))
682              (outfilename (format "~a.toc" output-name))
683              (outfile (open-output-file outfilename)))
684         (if (output-port? outfile)
685             (display whole-string outfile)
686             (ly:warning (_ "Unable to open output file ~a for the TOC information") outfilename))
687         (close-output-port outfile)))))
690 #(define-public (oly:add-toc-item parser markup-symbol text)
691   (oly:music_handler parser (add-toc-item! markup-symbol text)))
694 #(define (oly:add-score parser score piecename)
695   (if (not-null? piecename)
696     (oly:add-toc-item parser 'tocItemMarkup piecename))
697   (oly:score_handler parser score)
699 % The helper function to build a score.
700 #(define (oly:createScoreHelper parser location piece children func)
701   (let* (
702          (staves    (oly:staff_group_handler parser piece "" "SimultaneousMusic" children))
703          (music     (if (not-null? staves)
704                         ((ly:music-function-extract func) parser location staves)
705                         '()
706                     ))
707          (score     '())
708          (piecename (namedPieceInstrObject piece (car children) "PieceName"))
709          (piecenametacet (namedPieceInstrObject piece (car children) "PieceNameTacet"))
710          (header    '())
711         )
712     (if (null? music)
713       ; No staves, print tacet
714       (begin 
715         (if (not-null? piecenametacet) (set! piecename piecenametacet))
716         (if (not-null? piecename)
717           (oly:add-score parser (list (oly:piece-title-markup piecename)) piecename)
718           (ly:warning (_ "No music and no score title found for part ~a and instrument ~a") piece children)
719         )
720       )
721       ; we have staves, apply the piecename to the score and add layout/midi blocks if needed
722       (begin
723         (set! score (scorify-music music parser))
724         (oly:set_piece_header score piecename)
725         (oly:apply_score_midi score)
726         (oly:apply_score_layout score)
727         ; Schedule the score for typesetting
728         (oly:add-score parser score piecename)
729       )
730     )
731   )
732   ; This is a void function, the score has been schedulled for typesetting already
733   (make-music 'Music 'void #t)
736 createScore = #(define-music-function (parser location piece children) (string? list?)
737   (oly:createScoreHelper parser location piece children identity)
739 createNoCuesScore = #(define-music-function (parser location piece children) (string? list?)
740   (oly:createScoreHelper parser location piece children cuefilter)
743 createHeadline = #(define-music-function (parser location headline) (string?)
744   (oly:add-toc-item parser 'tocItemMarkup headline)
745   (oly:score_handler parser (list (oly:piece-title-markup headline)))
746   (make-music 'Music 'void #t)
751 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
752 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
753 %%%%%   CUE NOTES
754 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
755 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
757 newInstrument = #(define-music-function (parser location instr) (string?)
759   \set Voice.instrumentCueName = #$(string-join (list "+" instr))
762 cueText = #(define-music-function (parser location instr) (string?)
764   \set Voice.instrumentCueName = $instr
768 % generate a cue music section with instrument names
769 % Parameters: \namedCueDuring NameOfQuote CueDirection CueInstrument OriginalInstrument music
770 %                 -) NameOfQuote CueDirection music are the parameters for \cueDuring
771 %                 -) CueInstrument and OriginalInstrument are the displayed instrument names
772 % typical call:
773 % \namedCueDuring #"vIQuote" #UP #"V.I" #"Sop." { R1*3 }
774 %      This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
775 %      the beginning of the cue notes and "Sop." at the end
776 namedCueDuring = #(define-music-function (parser location cuevoice direction instrcue instr cuemusic) (string? number? string? string? ly:music?)
777    #{
778      \cueDuring #$cuevoice #$direction { \tag #'cued \cueText #$instrcue $cuemusic \tag #'cued \cueText #$instr }
779 %      \tag #'uncued $cuemusic
780    #}
782 namedTransposedCueDuring = #(define-music-function (parser location cuevoice direction instrcue instr trans cuemusic) (string? number? string? string? ly:music? ly:music?)
783    #{
784      \transposedCueDuring #$cuevoice #$direction $trans { \tag #'cued \cueText #$instrcue $cuemusic \tag #'cued \cueText #$instr }
785 %      \tag #'uncued $cuemusic
786    #}
789 % set the cue instrument name and clef
790 setClefCue = #(define-music-function (parser location instr clef) 
791                                                      (string? ly:music?)
792    #{
793      \once \override Staff.Clef #'font-size = #-3 $clef
794      \set Voice.instrumentCueName = $instr
795    #} )
797 % generate a cue music section with instrument names and clef changes
798 % Parameters: \cleffedCueDuring NameOfQuote CueDirection CueInstrument CueClef OriginalInstrument OriginalClef music
799 %                 -) NameOfQuote CueDirection music are the parameters for \cueDuring
800 %                 -) CueInstrument and OriginalInstrument are the displayed instrument names
801 %                 -) CueClef and OriginalClef are the clefs for the the cue notes and the clef of the containing voice
802 % typical call:
803 % \cleffedCueDuring #"vIQuote" #UP #"V.I" #"treble" #"Basso" #"bass" { R1*3 }
804 %      This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
805 %      the beginning of the cue notes and "Basso" at the end. The clef is changed to treble at the 
806 %      beginning of the cue notes and reset to bass at the end
807 cleffedCueDuring = #(define-music-function (parser location cuevoice direction instrcue clefcue instr clefinstr cuemusic) 
808                                                         (string? number? string? ly:music? string? ly:music? ly:music?)
809    #{
810      \cueDuring #$cuevoice #$direction { \tag #'cued \setClefCue #$instrcue $clefcue $cuemusic \tag #'cued \setClefCue #$instr $clefinstr }
811 %      \tag #'uncued $cuemusic
812    #}
818 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
819 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
820 %%%%%   DYNAMICS
821 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
822 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
825 dynamicsX = #(define-music-function (parser location offset) (number?)
827     \once \override DynamicText #'X-offset = $offset
828     \once \override DynamicLineSpanner #'Y-offset = #0
831 % Move the dynamic sign inside the staff to a fixed staff-relative position 
832 % posY (where 0 means vertically starts at the middle staff line)
833 dynamicsAllInside = #(define-music-function (parser location offsetX posY)
834 (number? number?)
836   % Invalid y-extent -> hidden from skyline calculation and collisions
837   \once \override DynamicLineSpanner #'Y-extent = #(cons +0 -0.01)
838   % move by X offset and to fixed Y-position (use Y-offset of parent!)
839   \once \override DynamicText #'X-offset = $offsetX
840   \once \override DynamicText #'Y-offset =
841     $(lambda (grob)
842        (let* ((head (ly:grob-parent grob Y))
843               (offset (ly:grob-property head 'Y-offset)))
844          (- posY  offset (- 0.6))))
845   \once \override DynamicLineSpanner #'Y-offset = $posY
848 dynamicsUpInside = #(define-music-function (parser location offsetX) (number?)
849   ((ly:music-function-extract dynamicsAllInside) parser location offsetX 1.5)
852 dynamicsDownInside = #(define-music-function (parser location offsetX) (number?)
853   ((ly:music-function-extract dynamicsAllInside) parser location offsetX -3.5)
856 hairpinOffset = #(define-music-function (parser location posY) (number?)
858   \once \override DynamicLineSpanner #'Y-offset = $posY
859   \once \override DynamicLineSpanner #'Y-extent = #(cons +0 -0.01)
862 #(define ((line-break-offset before after) grob)
863   (let* ((orig (ly:grob-original grob))
864          ; All siblings if line-broken:
865          (siblings (if (ly:grob? orig) (ly:spanner-broken-into orig) '() )))
866     (if (>= (length siblings) 2)
867       ; We have been line-broken
868       (if (eq? (car (last-pair siblings)) grob)
869         ; Last sibling:
870         (ly:grob-set-property! grob 'Y-offset after)
871         ; Others get the before value:
872         (ly:grob-set-property! grob 'Y-offset before)
873       )
874     )
875   )
878 ffz = #(make-dynamic-script "ffz")
879 pf = #(make-dynamic-script "pf")
880 sempp = #(make-dynamic-script (markup #:line( #:with-dimensions '(0 . 0) 
881 '(0 . 0) #:right-align #:normal-text #:italic "sempre" #:dynamic "pp")))
882 parenf = #(make-dynamic-script (markup #:line(#:normal-text #:italic #:fontsize 2 "(" #:dynamic "f" #:normal-text #:italic #:fontsize 2 ")" )))
883 parenp = #(make-dynamic-script (markup #:line(#:normal-text #:italic #:fontsize 2 "(" #:dynamic "p" #:normal-text #:italic #:fontsize 2 ")" )))
884 pdolce = #(make-dynamic-script (markup #:line(#:dynamic "p" #:with-dimensions '(0 . 0) '(0 . 0) #:normal-text #:italic "dolce"  )))
888 cresc = #(make-music 'CrescendoEvent 'span-direction START 'crescendoSpanner 'text 'crescendoText "cresc.")
889 endcresc =  #(make-span-event 'CrescendoEvent STOP)
890 dim = #(make-music 'DecrescendoEvent 'span-direction START 'decrescendoSpanner 'text 'decrescendoText "dim.")
891 enddim =  #(make-span-event 'DecrescendoEvent STOP)
892 decresc = #(make-music 'DecrescendoEvent 'span-direction START 'decrescendoSpanner 'text 'decrescendoText "decresc.")
893 enddecresc =  #(make-span-event 'DecrescendoEvent STOP)
895 setCresc = {}
896 setDecresc = {}
897 setDim = {}
899 newOrOldClef = #(define-music-function (parser location new old ) (string? string?)
900     (if (ly:get-option 'old-clefs) #{ \clef $old #} #{ \clef $new #}) 
905 %%% Thanks to "Gilles THIBAULT" <gilles.thibault@free.fr>, there is a way
906 %   to remove also the fermata from R1-\fermataMarkup: By filtering the music
907 %   and removing the corresponding events.
908 %   Documented as an LSR snippet: http://lsr.dsi.unimi.it/LSR/Item?id=372
909 #(define (filterOneEventsMarkup event)
910 ( let ( (eventname (ly:music-property  event 'name)) )
911  (not
912   (or     ;; add here event name you do NOT want
913    (eq? eventname 'MultiMeasureTextEvent)
914    (eq? eventname 'AbsoluteDynamicEvent)
915    (eq? eventname 'TextScriptEvent)
916    (eq? eventname 'ArticulationEvent)
917    (eq? eventname 'CrescendoEvent)
918    (eq? eventname 'DecrescendoEvent)
919   )
923 filterArticulations = #(define-music-function (parser location music) (ly:music?)
924   Â (music-filter filterOneEventsMarkup music)
931 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
932 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
933 %%%%%   Tempo markings
934 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
935 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
939 rit = \markup {\italic "rit."}
940 pocorit = \markup {\italic "poco rit."}
941 ppmosso = \markup {\italic "poco più mosso"}
942 dolce = \markup {\italic "dolce."}
943 pizz = \markup {\italic "pizz."}
944 arco = \markup {\italic "arco"}
945 perd = \markup {\italic "perdend."}
950 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
951 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
952 %%%%%   REST COMBINATION
953 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
954 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
958 %% REST COMBINING, TAKEN FROM http://lsr.dsi.unimi.it/LSR/Item?id=336
960 %% Usage:
961 %%   \new Staff \with {
962 %%     \override RestCollision #'positioning-done = #merge-rests-on-positioning
963 %%   } << \somevoice \\ \othervoice >>
964 %% or (globally):
965 %%   \layout {
966 %%     \context {
967 %%       \Staff
968 %%       \override RestCollision #'positioning-done = #merge-rests-on-positioning
969 %%     }
970 %%   } 
972 %% Limitations:
973 %% - only handles two voices
974 %% - does not handle multi-measure/whole-measure rests
976 #(define (rest-score r)
977   (let ((score 0)
978   (yoff (ly:grob-property-data r 'Y-offset))
979   (sp (ly:grob-property-data r 'staff-position)))
980     (if (number? yoff)
981   (set! score (+ score 2))
982   (if (eq? yoff 'calculation-in-progress)
983       (set! score (- score 3))))
984     (and (number? sp)
985    (<= 0 2 sp)
986    (set! score (+ score 2))
987    (set! score (- score (abs (- 1 sp)))))
988     score))
990 #(define (merge-rests-on-positioning grob)
991   (let* ((can-merge #f)
992    (elts (ly:grob-object grob 'elements))
993    (num-elts (and (ly:grob-array? elts)
994       (ly:grob-array-length elts)))
995    (two-voice? (= num-elts 2)))
996     (if two-voice?
997   (let* ((v1-grob (ly:grob-array-ref elts 0))
998          (v2-grob (ly:grob-array-ref elts 1))
999          (v1-rest (ly:grob-object v1-grob 'rest))
1000          (v2-rest (ly:grob-object v2-grob 'rest)))
1001     (and
1002      (ly:grob? v1-rest)
1003      (ly:grob? v2-rest)          
1004      (let* ((v1-duration-log (ly:grob-property v1-rest 'duration-log))
1005       (v2-duration-log (ly:grob-property v2-rest 'duration-log))
1006       (v1-dot (ly:grob-object v1-rest 'dot))
1007       (v2-dot (ly:grob-object v2-rest 'dot))
1008       (v1-dot-count (and (ly:grob? v1-dot)
1009              (ly:grob-property v1-dot 'dot-count -1)))
1010       (v2-dot-count (and (ly:grob? v2-dot)
1011              (ly:grob-property v2-dot 'dot-count -1))))
1012        (set! can-merge
1013        (and 
1014         (number? v1-duration-log)
1015         (number? v2-duration-log)
1016         (= v1-duration-log v2-duration-log)
1017         (eq? v1-dot-count v2-dot-count)))
1018        (if can-merge
1019      ;; keep the rest that looks best:
1020      (let* ((keep-v1? (>= (rest-score v1-rest)
1021               (rest-score v2-rest)))
1022       (rest-to-keep (if keep-v1? v1-rest v2-rest))
1023       (dot-to-kill (if keep-v1? v2-dot v1-dot)))
1024        ;; uncomment if you're curious of which rest was chosen:
1025        ;;(ly:grob-set-property! v1-rest 'color green)
1026        ;;(ly:grob-set-property! v2-rest 'color blue)
1027        (ly:grob-suicide! (if keep-v1? v2-rest v1-rest))
1028        (if (ly:grob? dot-to-kill)
1029            (ly:grob-suicide! dot-to-kill))
1030        (ly:grob-set-property! rest-to-keep 'direction 0)
1031        (ly:rest::y-offset-callback rest-to-keep)))))))
1032     (if can-merge
1033   #t
1034   (ly:rest-collision::calc-positioning-done grob))))
1040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1041 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1042 %%%%%   TABLE OF CONTENTS
1043 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1044 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1047 contentsTitle = "Inhalt / Contents"
1049 \paper {
1050   tocTitleMarkup = \markup \fill-line{ 
1051     \null 
1052     \column {
1053       \override #(cons 'line-width (* 7 cm)) 
1054       \line{ \fill-line {\piece-title {\contentsTitle} \null }}
1055       \hspace #1
1056     }
1057     \null 
1058   }
1059   tocItemMarkup = \markup \fill-line { 
1060     \null 
1061     \column {
1062       \override #(cons 'line-width (* 7 cm )) 
1063       \line { \fill-line{\fromproperty #'toc:text \fromproperty #'toc:page }}
1064     }
1065     \null
1066   }
1070 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1071 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1072 %%%%%   TITLE PAGE / HEADER
1073 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1074 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1076 #(define-markup-command (when-property layout props symbol markp) (symbol? markup?)
1077   (if (chain-assoc-get symbol props)
1078       (interpret-markup layout props markp)
1079       (ly:make-stencil '()  '(1 . -1) '(1 . -1))))
1081 #(define-markup-command (vspace layout props amount) (number?)
1082   "This produces a invisible object taking vertical space."
1083   (let ((amount (* amount 3.0)))
1084     (if (> amount 0)
1085         (ly:make-stencil "" (cons -1 1) (cons 0 amount))
1086         (ly:make-stencil "" (cons -1 1) (cons amount amount)))))
1090 titlePageMarkup = \markup \abs-fontsize #10 \when-property #'header:title \column {
1091     \vspace #4
1092     \fill-line { \fontsize #8 \fromproperty #'header:composer }
1093     \vspace #1
1094     \fill-line { \fontsize #8 \fromproperty #'header:poet }
1095     \vspace #4
1096     \fill-line { \fontsize #10 \bold \fromproperty #'header:titlepagetitle }
1097     \vspace #1
1098     \fontsize #2 \when-property #'header:titlepagesubtitle { 
1099       \fill-line { \fromproperty #'header:titlepagesubtitle }
1100       \vspace #1
1101     }
1102     \fill-line { \postscript #"-20 0 moveto 40 0 rlineto stroke" }
1103     \vspace #8
1104     \fill-line { \fontsize #5 \fromproperty #'header:ensemble }
1105     \vspace #0.02
1106     \fill-line { \fontsize #2 \fromproperty #'header:instruments }
1107     \vspace #9
1108     \fill-line { \fontsize #5 \fromproperty #'header:date }
1109     \vspace #1
1110     \fill-line { \fontsize #5 \fromproperty #'header:scoretype }
1111     \vspace #8
1112     \fontsize #2 \when-property #'header:enteredby { 
1113       \fill-line { "Herausgegeben von: / Edited by:"}
1114       \vspace #0.
1115       \fill-line { \fromproperty #'header:enteredby }
1116     }
1117     \fill-line {
1118       \when-property #'header:arrangement \column {
1119         \vspace #8
1120         \fill-line { \fontsize #3 \fromproperty #'header:arrangement }
1121       }
1122     }
1125 titleHeaderMarkup = \markup {
1126   \override #'(baseline-skip . 3.5)
1127   \column {
1128     \override #'(baseline-skip . 3.5)
1129     \column {
1130       \huge \larger \bold
1131       \fill-line {
1132         \larger \fromproperty #'header:title
1133       }
1134       \fill-line {
1135         \large \smaller \bold
1136         \larger \fromproperty #'header:subtitle
1137       }
1138       \fill-line {
1139         \smaller \bold
1140         \fromproperty #'header:subsubtitle
1141       }
1142       \fill-line {
1143         { \large \bold \fromproperty #'header:instrument }
1144       }
1145       \fill-line {
1146         \fromproperty #'header:poet
1147         \fromproperty #'header:composer
1148       }
1149       \fill-line {
1150         \fromproperty #'header:meter
1151         \fromproperty #'header:arranger
1152       }
1153     }
1154   }
1157 titleScoreMarkup = \markup \piece-title \fromproperty #'header:piece
1159 \paper {
1160   scoreTitleMarkup = \titleScoreMarkup
1161   bookTitleMarkup = \titleHeaderMarkup
1166 %%%%%%%%%%%%%% headers and footers %%%%%%%%%%%%%%%%%%%%%%%%%%
1168 #(define (first-score-page layout props arg)
1169   (let* ((label 'first-score-page)
1170          (table (ly:output-def-lookup layout 'label-page-table))
1171          (label-page (and (list? table) (assoc label table)))
1172          (page-number (and label-page (cdr label-page)))
1173         )
1174     (if (eq? (chain-assoc-get 'page:page-number props -1) page-number)
1175       (interpret-markup layout props arg)
1176       empty-stencil)))
1178 #(define no-header-table '())
1179 thisPageNoHeader = #(define-music-function (parser location) ()
1180   (let* ((label (gensym "header")))
1181     (set! no-header-table (cons label no-header-table))
1182     (make-music 'Music 
1183       'page-marker #t
1184       'page-label label)))
1187 % TODO: Use the no-header-table!
1188 #(define (is-header-page layout props arg)
1189   (let* ((page-number (chain-assoc-get 'page:page-number props -1))
1190         )
1191     ;(if (and (> page-number 2) (!= page-number 7))
1192     (if (> page-number 1)
1193       (interpret-markup layout props arg)
1194       empty-stencil)))
1196 #(define no-footer-table '())
1197 thisPageNoFooter = #(define-music-function (parser location) ()
1198   (let* ((label (gensym "footer")))
1199     (set! no-footer-table (cons label no-footer-table))
1200     (make-music 'Music 
1201       'page-marker #t
1202       'page-label label)))
1204 % TODO: Use the no-footer-table!
1205 #(define (is-footer-page layout props arg)
1206   (let* ((page-number (chain-assoc-get 'page:page-number props -1))
1207          (label 'first-score-page)
1208          (table (ly:output-def-lookup layout 'label-page-table))
1209          (label-page (and (list? table) (assoc label table)))
1210          ;(page-number (and label-page (cdr label-page)))
1211         )
1212     (if (and (> page-number 1))
1213       (interpret-markup layout props arg)
1214       empty-stencil)))
1217 #(define copyright-footer-table '())
1218 thisPageCopyrightFooter = #(define-music-function (parser location) ()
1219   (let* ((label (gensym "copyrightfooter")))
1220     (set! copyright-footer-table (cons label copyright-footer-table))
1221     (make-music 'Music 
1222       'page-marker #t
1223       'page-label label)))
1225 #(define copyright-pg 1)
1226 #(define (set-copyright-page page)
1227   (set! copyright-pg page)
1230 % TODO: Use the copyright-footer-table!
1231 #(define (copyright-page layout props arg)
1232     (if (= (chain-assoc-get 'page:page-number props -1) copyright-pg)
1233       (interpret-markup layout props arg)
1234       empty-stencil))
1237 \paper {
1238   oddHeaderMarkup = \markup \fill-line {
1239     %% force the header to take some space, otherwise the
1240     %% page layout becomes a complete mess.
1241     " "
1242     \on-the-fly #is-header-page \fromproperty #'header:title
1243     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1244   }
1245   evenHeaderMarkup = \markup \fill-line {
1246     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1247     \on-the-fly #is-header-page \fromproperty #'header:composer
1248     " "
1249   }
1251   oddFooterMarkup = \markup {
1252     \column {
1253       \fill-line {
1254         %% publisher header field only on title page.
1255         \on-the-fly #first-page \fromproperty #'header:publisher
1256       }
1257       \fill-line {
1258         %% copyright on the first real score page
1259         \on-the-fly #copyright-page \fromproperty #'header:copyright
1260         \on-the-fly #copyright-page \null
1261       }
1262       \fill-line {
1263         %% All other pages get the number of the edition centered
1264         \on-the-fly #is-footer-page \fromproperty #'header:scorenumber
1265       }
1266     }
1267   }
1281 % Interpret the given markup with the header fields added to the props. 
1282 % This way, one can re-use the same functions (using fromproperty 
1283 % #'header:field) in the header block and as top-level markup.
1285 % This function is originally copied from mark-up-title (file scm/titling.scm), 
1286 % which is lilypond's internal function to handle the title markups. I needed 
1287 % to replace the scopes and manually add the $defaultheader (which is internally 
1288 % done in paper-book.cc before calling mark-up-title. Also, I don't extract the 
1289 % markup from the header block, but use the given markup.
1291 % I'm not sure if I really need the page properties in props, too... But I 
1292 % suppose it does not hurt, either.
1293 #(define-markup-command (markupWithHeader layout props markup) (markup?)
1294   "Interpret the given markup with the header fields added to the props. 
1295    This way, one can re-use the same functions (using fromproperty 
1296    #'header:field) in the header block and as top-level markup."
1297   (let* (
1298       ; TODO: If we are inside a score, add the score's local header block, too!
1299       ; Currently, I only use the global header block, stored in $defaultheader
1300       (scopes (list $defaultheader))
1301       (alists (map ly:module->alist scopes))
1302   
1303       (prefixed-alist
1304         (map (lambda (alist)
1305           (map (lambda (entry)
1306             (cons
1307               (string->symbol (string-append "header:" (symbol->string (car entry))))
1308               (cdr entry)))
1309             alist))
1310           alists))
1311       (props (append prefixed-alist
1312               props
1313               (layout-extract-page-properties layout)))
1314     )
1315     (interpret-markup layout props markup)
1316   )
1324 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1325 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1326 %%%%%   Equally spacing multiple columns (e.g. for translations)
1327 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1330 % Credits: Nicolas Sceaux on the lilypond-user mailinglist
1331 #(define-markup-command (columns layout props args) (markup-list?)
1332    (let ((line-width (/ (chain-assoc-get 'line-width props
1333                          (ly:output-def-lookup layout 'line-width))
1334                         (max (length args) 1))))
1335      (interpret-markup layout props
1336        (make-line-markup (map (lambda (line)
1337                                 (markup #:pad-to-box `(0 . ,line-width) '(0 . 0)
1338                                   #:override `(line-width . ,line-width)
1339                                   line))
1340                                args)))))
1344 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1345 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1346 %%%%%   SCORE (HEADER / LAYOUT) SETTINGS
1347 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1348 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1351 startSlashedGraceMusic =  {
1352   \override Stem  #'stroke-style = #"grace"
1355 stopSlashedGraceMusic =  {
1356   \revert Stem #'stroke-style
1359 slashedGrace =
1360 #(def-grace-function startSlashedGraceMusic stopSlashedGraceMusic
1361    (_i "Create slashed graces (slashes through stems, but no slur)from the following music expression"))
1364 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1365 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1366 %%%%%   SCORE (HEADER / LAYOUT) SETTINGS
1367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1368 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1370 \paper {
1371 %   left-margin = 2\cm
1372 %   right-margin = 2\cm
1373 %   line-width = 17\cm
1374 %   bottom-margin = 1\cm
1375 %   top-margin = 1\cm
1376 %   after-title-space = 0.5\cm
1377   ragged-right = ##f
1378   ragged-last = ##f
1379   ragged-bottom = ##f
1380   ragged-last-bottom = ##f
1382 \layout {
1383   \context {
1384     \ChoirStaff 
1385     % If only one non-empty staff in a system exists, still print the backet
1386     \override SystemStartBracket #'collapse-height = #1
1387     \consists "Instrument_name_engraver"
1388   }
1389   \context {
1390     \StaffGroup
1391     % If only one non-empty staff in a system exists, still print the backet
1392     \override SystemStartBracket #'collapse-height = #1
1393     \consists "Instrument_name_engraver"
1394   }
1395   \context {
1396     \GrandStaff
1397     \override SystemStartBracket #'collapse-height = #1
1398     \consists "Instrument_name_engraver"
1399   }
1400   \context {
1401     \PianoStaff
1402 %     \override VerticalAxisGroup #'keep-fixed-while-stretching = ##t
1403   }
1404   \context {
1405     \FiguredBass
1406 %     \override VerticalAxisGroup #'keep-fixed-while-stretching = ##t
1407     \override VerticalAxisGroup #'minimum-Y-extent  = #'(0 . 1)
1408     \override VerticalAxisGroup #'padding = #0
1409   }
1410   \context {
1411     \Score
1412     % Force multi-measure rests to be written as one span
1413     \override MultiMeasureRest #'expand-limit = #3
1414     skipBars = ##t
1415     autoBeaming = ##f
1416 %     hairpinToBarline = ##f
1417     \override BarNumber #'break-visibility = #end-of-line-invisible
1418     \override BarNumber #'self-alignment-X = #0
1419     \override CombineTextScript #'avoid-slur = #'outside
1420     barNumberVisibility = #(every-nth-bar-number-visible 5)
1421     \override DynamicTextSpanner #'dash-period = #-1.0
1422     \override InstrumentSwitch #'font-size = #-1
1424     % Rest collision
1425     \override RestCollision #'positioning-done = #merge-rests-on-positioning
1426     % Auto-Accidentals: Use modern-cautionary style...
1427     extraNatural = ##f
1428     autoAccidentals = #`(Staff  ,(make-accidental-rule 'same-octave 0))
1429     autoCautionaries = #`(Staff ,(make-accidental-rule 'any-octave 0)
1430                                 ,(make-accidental-rule 'same-octave 1))
1431     printKeyCancellation = ##t
1432   }
1433   \context {
1434     \RemoveEmptyStaffContext 
1435   }
1436   \context {
1437     \Lyrics
1438     \override VerticalAxisGroup #'minimum-Y-extent = #'(0.5 . 0.5)
1439   }
1440   \context {
1441     \Staff
1442     \override VerticalAxisGroup #'minimum-Y-extent = #'(-1. . 3)
1443     quotedEventTypes = #'(StreamEvent)
1444     ignoreFiguredBassRest = ##f
1445     implicitBassFigures = #'(100)
1446   }
1451 \layout {
1452   \context {
1453     \type "Engraver_group"
1454     \name Dynamics
1455     % So that \cresc works, for example.
1456     \alias Voice
1457     \consists "Output_property_engraver"
1458     
1459     \override VerticalAxisGroup #'minimum-Y-extent = #'(-1 . 1)
1460     pedalSustainStrings = #'("Ped." "*Ped." "*")
1461     pedalUnaCordaStrings = #'("una corda" "" "tre corde")
1462     
1463     \consists "Piano_pedal_engraver"
1464     \consists "Script_engraver"
1465     \consists "Dynamic_engraver"
1466     \consists "Text_engraver"
1467     
1468     \override TextScript #'font-size = #2
1469     \override TextScript #'font-shape = #'italic
1470     \override DynamicText #'extra-offset = #'(0 . 2.5)
1471     \override Hairpin #'extra-offset = #'(0 . 2.5)
1472     
1473     \consists "Skip_event_swallow_translator"
1474     
1475     \consists "Axis_group_engraver"
1476   }
1477   \context {
1478     \PianoStaff
1479     \accepts Dynamics
1480 %     \override VerticalAlignment #'forced-distance = #7
1481   }
1486 solo = ^\markup{"Solo"}
1487 tutti = ^\markup{"Tutti"}