Add dashed tie
[orchestrallily.git] / orchestrallily.ily
blob6ceaa063daa1489a3098f0e701c53a3a7fd282ee
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:LiedScoreStructure '(
89   ("SoloScore" "SimultaneousMusic" ("Singstimme"))
90   ("Pfe" "PianoStaff" ("PfeI" "PfeII"))
91   ;("PfeI" "ParallelVoicesStaff" ("OIa" "OIb"))
92   ;("PfeII" "ParallelVoicesStaff" ("OIIa" "OIIb"))
93   ("FullScore" "SimultaneousMusic" ("Singstimme" "Pfe"))
94   ("VocalScore" "SimultaneousMusic" ("Singstimme" "Pfe"))
97 #(define oly:fullOrchestraScoreStructure '(
98 ; Part-combined staves for full score
99   ("Fl" "PartCombinedStaff" ("FlI" "FlII"))
100   ("Ob" "PartCombinedStaff" ("ObI" "ObII"))
101   ("Cl" "PartCombinedStaff" ("ClI" "ClII"))
102   ("Fag" "PartCombinedStaff" ("FagI" "FagII"))
103   ("Wd" "StaffGroup" ("Fl" "Ob" "Cl" "Fag" "CFag"))
105   ("Cor" "PartCombinedStaff" ("CorI" "CorII"))
106   ("Trb" "PartCombinedStaff" ("TrbI" "TrbII"))
107   ("Tbe" "PartCombinedStaff" ("TbeI" "TbeII"))
108   ("Br" "StaffGroup" ("Cor" "Trb" "Tbe" "Tba"))
110 ; long score; no part-combined staves, but GrandStaves instead
111   ("FlLong" "GrandStaff" ("FlI" "FlII"))
112   ("ObLong" "GrandStaff" ("ObI" "ObII"))
113   ("ClLong" "GrandStaff" ("ClI" "ClII"))
114   ("FagLong" "GrandStaff" ("FagI" "FagII"))
115   ("WdLong" "StaffGroup" ("FlLong" "ObLong" "ClLong" "FagLong" "CFag"))
117   ("CorLong" "GrandStaff" ("CorI" "CorII"))
118   ("TrbLong" "GrandStaff" ("TrbI" "TrbII"))
119   ("TbeLong" "GrandStaff" ("TbeI" "TbeII" "TbeIII"))
120   ("BrLong" "StaffGroup" ("CorLong" "TrbLong" "TbeLong" "Tba"))
122 ; Percussion
123   ("Perc" "StaffGroup" ("Tim"))
125 ; Strings, they are the same in long and short full score  
126   ("V" "GrandStaff" ("VI" "VII"))
127   ("Str" "StaffGroup" ("V" "Va"))
128   ("VceB" "StaffGroup" ("Vc" "Cb" "VcB"))
129   ("FullStr" "StaffGroup" ("V" "Va" "Vc" "Cb" "VcB"))
131 ; Choral score
132   ("Solo" "SimultaneousMusic" ("SSolo" "ASolo" "TSolo" "BSolo"))
133   ("Ch" "ChoirStaff" ("S" "A" "T" "B"))
134   ("ChoralScore" "SimultaneousMusic" ("Ch"))
135   ("SoloScore" "SimultaneousMusic" ("Solo"))
136   ("SoloChoirScore" "SimultaneousMusic" ("Solo" "Ch"))
138 ; Organ score (inkl. Figured bass)
139   ("BCFb" "FiguredBass" ())
140   ("FiguredBass" "FiguredBass" ())
141   ;("Organ" "SimultaneousMusic" ("BCFb" "O"))
142   ("Organ" "ParallelVoicesStaff" ("BCFb" "BC" "FiguredBass"))
143   ("Continuo" "ParallelVoicesStaff" ("BCFb" "BC" "FiguredBass"))
144   
145   ("O" "PianoStaff" ("OI" "OII"))
146   ("OI" "ParallelVoicesStaff" ("OIa" "OIb"))
147   ("OII" "ParallelVoicesStaff" ("OIIa" "OIIb"))
148   ;("BassGroup" "ParallelVoicesStaff" ("Organ" "O" "BC" "VceB"))
149   ("BassGroup" "StaffGroup" ("O" "Continuo"))
151 ; Full Scores
152   ("FullScore" "SimultaneousMusic" ("Wd" "Br" "Perc" "Str" "SoloChoirScore" "BassGroup"))
153   ("LongScore" "SimultaneousMusic" ("WdLong" "BrLong" "Perc" "Str" "SoloChoirScore" "BassGroup"))
155 ; Piano reduction
156   ;("Piano" "SimultaneousMusic" ("Organ"))
157   ("OrganScore" "SimultaneousMusic" ("ChoralScore" "O"))
158   ("VocalScore" "SimultaneousMusic" ("ChoralScore" "Piano"))
159   ("Particell"  "SimultaneousMusic" ("ChoralScore" "Continuo"))
161 ; Full scores: Orchestral score and long score including organ
162   ("ChStrQ" "SimultaneousMusic" ("Str" "Ch" "VceB"))
164 #(define oly:orchestral_score_structure oly:fullOrchestraScoreStructure)
166 #(define (oly:set_score_structure struct)
167   (if (list? struct)
168     (set! oly:orchestral_score_structure struct)
169     (ly:warning (_ "oly:set_score_structure needs an association list as argument!"))
170   )
173 #(define (oly:modify_score_structure entry)
174   (if (list? entry)
175     (set! oly:orchestral_score_structure (assoc-set! oly:orchestral_score_structure  (car entry) (cdr entry)))
176     (ly:warning (_ "oly:modify_score_structure expects a list (\"key\" \"type\" '(children)) as argument!"))))
178 #(define (oly:remove_from_score_structure entry)
179   (if (list? entry)
180     (map oly:remove_from_score_structure entry)
181     (set! oly:orchestral_score_structure (assoc-remove! oly:orchestral_score_structure  entry))))
183 orchestralScoreStructure = #(define-music-function (parser location structure) (list?) 
184   (oly:set_score_structure structure)
185   (make-music 'Music 'void #t)
188 #(define oly:voice_types '())
190 #(define (oly:set_voice_types types)
191   (if (list? types)
192     (set! oly:voice_types types)
193     (ly:warning (_ "oly:set_voice_types needs an association list as argument!"))
194   )
197 orchestralVoiceTypes = #(define-music-function (parser location types) (list?)
198   (oly:set_voice_types types)
199   (make-music 'Music 'void #t)
203 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
204 % Automatic staff and group generation
205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
207 % Retrieve all music definitions for the given 
208 #(define (oly:get_music_object piece instrument)
209   (namedPieceInstrObject piece instrument "Music")
211 #(define (oly:get_music_objects piece instruments)
212   (filter not-null? (map (lambda (i) (oly:get_music_object piece i)) instruments))
215 % Given a property name and the extensions, either generate the pair to set 
216 % the property or an empty list, if no pre-defined variable could be found
217 #(define (oly:generate_property_pair prop piece instr type)
218   (let* ((val (namedPieceInstrObject piece instr type)))
219     (if (not-null? val) (list 'assign prop val) '() )
220   )
222   
223 #(define (oly:staff_type type)
224   (cond 
225     ((string? type) (string->symbol type))
226     ((symbol? type) type)
227     (else 'Staff)
228   )
231 #(define (oly:extractPitch music)
232   (let* (
233          (elems  (if (ly:music? music) (ly:music-property music 'elements)))
234          (note   (if (pair? elems) (car elems)))
235          (pitch  (if (ly:music? note) (ly:music-property note 'pitch)))
236         )
237     (if (and (not-null? music) (not (ly:pitch? pitch))) 
238       (ly:warning "Unable to interpret as a pitch!")
239     )
240     pitch
241   )
244 #(define (oly:extractTranspositionPitch piece name)
245   (let* (
246          (trpFromPitch (oly:extractPitch (namedPieceInstrObject piece name "TransposeFrom")))
247          (trpToPitch   (oly:extractPitch (namedPieceInstrObject piece name "TransposeTo")))
248         )
249     (if (ly:pitch? trpFromPitch)
250       (if (ly:pitch? trpToPitch)
251         ; Both pitches
252         (ly:pitch-diff trpFromPitch trpToPitch)
253         (ly:pitch-diff trpFromPitch (ly:make-pitch 0 0 0))
254       )
255       (if (ly:pitch? trpToPitch)
256         (ly:pitch-diff (ly:make-pitch 0 0 0) trpToPitch)
257         #f
258       )
259     )
260   )
263 #(define (oly:musiccontent_for_voice parser piece name music additional)
264   (let* ((musiccontent additional))
265     
266     ; Append the settings, key and clef (if defined)
267     (map 
268       (lambda (type) 
269         (let* ((object (namedPieceInstrObject piece name type)))
270           (if (ly:music? object)
271             (set! musiccontent (append musiccontent (list (ly:music-deep-copy object))))
272             (if (not-null? object) (ly:warning (_ "Wrong type (no ly:music) for ~S for instrument ~S in piece ~S") type name piece))
273           )
274         )
275       )
276       ; TODO: Does the "Tempo" work here???
277       '("Settings" "Key" "Clef" "TimeSignature" ;"Tempo"
278       )
279     )
281     (if (ly:music? music)
282       (begin
283         (set! musiccontent (make-simultaneous-music (append musiccontent (list music))))
284         ;(ly:message "Generating staff for ~a" name)
285         (let* ((trpPitch (oly:extractTranspositionPitch piece name)))
286           (if (ly:pitch? trpPitch) 
287             (set! musiccontent (ly:music-transpose musiccontent trpPitch))
288           )
289         )
290         musiccontent
291       )
292       ; For empty music, return empty 
293       '()
294     )
295   )
297 #(define (oly:voice_handler_internal parser piece name type music)
298   (let* (
299          (lyrics   (namedPieceInstrObject piece name "Lyrics"))
300          (additional '())
301         )
302     
303     (if (ly:music? lyrics)
304       (set! additional (list dynamicUp))
305       (if (not-null? lyrics) (ly:warning (_ "Wrong type (no lyrics) for lyrics for instrument ~S in piece ~S") name piece))
306     )
308     (if (ly:music? music)
309       (let* ((musiccontent (oly:musiccontent_for_voice parser piece name music additional))
310              (voicename  (oly:generate_object_name piece name "Voice" ))
311              (voicetype  (oly:staff_type type))
312              (voice      (context-spec-music musiccontent voicetype voicename))
313              (staffcont  (list voice))
314             )
315         ; If we have lyrics, create a lyrics context containing LyricCombineMusic 
316         ; and add that as second element to the staff's elements list...
317         (if (ly:music? lyrics)
318           (let* (
319                  (lyricsname (oly:generate_object_name piece name "Lyrics" ))
320                  (lyricscont (make-music 'LyricCombineMusic 'element lyrics 'associated-context voicename))
321                 )
322             (set! staffcont (append staffcont 
323               (list (context-spec-music lyricscont 'Lyrics lyricsname))))
324           )
325         )
326         staffcont
327       )
328       ; For empty music, return empty 
329       '()
330     )
331   )
334 #(define (oly:voice_handler parser piece name type)
335   (let* ((music (oly:get_music_object piece name))
336         )
337     (oly:voice_handler_internal parser piece name type music)
338   )
342 #(define (oly:staff_handler_internal parser piece name type voices)
343   (if (not-null? voices)
344     (let* (
345            (staffname  (oly:generate_staff_name piece name))
346            (stafftype  (oly:staff_type type))
347            (staff      (make-simultaneous-music voices))
348            (propops    (oly:staff_handler_properties piece name))
349           )
350       (case stafftype
351         ((SimultaneousMusic ParallelMusic) #f)
352         (else (set! staff (context-spec-music staff stafftype staffname)))
353       )
354       (if (not-null? propops)
355         (set! (ly:music-property staff 'property-operations) propops)
356       )
357       staff
358     )
359     ; For empty music, return empty 
360     '()
361   )
364 #(define (oly:staff_handler parser piece name type children)
365   (let* ((c (if (not-null? children) children (list name)))
366          (voices (apply append (map (lambda (v) (oly:create_voice parser piece v)) c)) ) 
367         )
368     (if (not-null? voices)
369       (oly:staff_handler_internal parser piece name type voices)
370       '()
371     )
372   )
374   
375 #(define (oly:parallel_voices_staff_handler parser piece name type children) 
376   (let* (
377          (voices (map (lambda (i) (oly:create_voice parser piece i)) children))
378          ; get the list of non-empty voices and flatten it!
379          (nonemptyvoices (apply append (filter not-null? voices)))
380         )
381     (if (not-null? nonemptyvoices)
382       (oly:staff_handler_internal parser piece name "Staff" nonemptyvoices)
383       '()
384     )
385   )
388 #(define (oly:part_combined_staff_handler parser piece name type children) 
389   (let* ((rawmusic (map (lambda (c) (oly:musiccontent_for_voice parser piece name (oly:get_music_object piece c) '())) children))
390          (music (filter not-null? rawmusic)))
391   (cond
392       ((and (pair? music) (ly:music? (car music)) (not-null? (cdr music)) (ly:music? (cadr music)))
393           ;(ly:message "Part-combine with two music expressions")
394           (oly:staff_handler_internal parser piece name "Staff" (list (make-part-combine-music parser music))))
395       ((null? music) 
396           (ly:warning "Part-combine without any music expressions")
397           '())
398       ; exactly one is a music expression, simply use that by joining 
399       ((list? music) 
400           (ly:message "Part-combine with only one music expressions")
401           (oly:staff_handler_internal parser piece name "Staff" (list (apply append music))))
402       (else 
403           ;(ly:message "make_part_combined_staff: ~S ~S ~a" piece instr instruments) 
404           '() )
405     )
406   )
409 % Generate the properties for the staff for piece and instr. Typically, these
410 % are the instrument name and the short instrument name (if defined).
411 % return a (possibly empty) list of all assignments.
412 #(define (oly:staff_handler_properties piece instr)
413   (let* (
414          (mapping '( 
415               (instrumentName . "InstrumentName") 
416               (shortInstrumentName . "ShortInstrumentName")
417               (midiInstrument . "MidiInstrument")
418             ))
419          (assignments (map 
420              (lambda (pr) 
421                  (oly:generate_property_pair (car pr) piece instr (cdr pr))
422              )
423              mapping))
424          (props (filter not-null? assignments))
425         )
426     props
427   )
429   
430 % Figured bass is a special case, as it can be voice- or staff-type. When
431 % given as a staff type, simply call the voice handler, instead
433 #(define (oly:figured_bass_staff_handler parser piece name type children)
434   (let* ((c (if (not-null? children) children (list name)))
435          (voice  (oly:voice_handler parser piece (car c) type)))
436     (if (pair? voice) (car voice) ())
437   )
439   
441 #(define (oly:staff_group_handler parser piece name type children)
442   (let* (
443          (staves (map (lambda (i) (oly:create_staff_or_group parser piece i)) children))
444          (nonemptystaves (filter not-null? staves))
445         )
446     (if (not-null? nonemptystaves)
447       (let* (
448              (musicexpr (if (= 1 (length nonemptystaves)) 
449                           (car nonemptystaves) 
450                           (make-simultaneous-music nonemptystaves)))
451              (groupname (oly:generate_staff_name piece name))
452              (grouptype (oly:staff_type type))
453              (group     musicexpr)
454              (propops   (oly:staff_handler_properties piece name))
455             )
456         (case grouptype
457           ((SimultaneousMusic ParallelMusic) #f)
458           (else (set! group (context-spec-music group grouptype groupname)))
459         )
460         (if (pair? propops)
461           (set! (ly:music-property group 'property-operations) propops))
462         group
463       )
464       ; Return empty list if no staves are generated
465       '()
466     )
467   )
470 #(define (oly:create_voice parser piece name)
471   (let* ( (voice (namedPieceInstrObject piece name "Voice"))
472           (type (assoc-ref oly:voice_types name)) )
473     (if (not-null? voice)
474       ; Explicit voice variable, use that
475       voice
476       
477       (if (not type)
478         ; No entry in structure found => simple voice
479         (oly:voice_handler parser piece name "Voice")
480         ; Entry found in structure => use the handler for the given type
481         (let* (
482                (voicetype (car type))
483                (handler (assoc-ref oly:voice_handlers voicetype))
484               )
485           (if handler
486             ((primitive-eval handler) parser piece name voicetype)
487             (begin
488               (ly:warning "No handler found for voice type ~a, using default voice handler" voicetype)
489               (oly:voice_handler parser piece name voicetype)
490             )
491           )
492         )
493       )
494     )
495   )
498 #(define (oly:create_staff_or_group parser piece name)
499   (let* ( (staff (namedPieceInstrObject piece name "Staff"))
500           (type_from_structure (assoc-ref oly:orchestral_score_structure name)) )
501     ;(if (not-null? staff)
502     ;  (ly:message "Found staff variable for instrument ~a in piece ~a"  instr piece)
503     ;  (ly:message "Staff variable for instrument ~a in piece ~a NOT FOUND"  instr piece)
504     ;)
505     (if (not-null? staff)
506       ; Explicit staff variable, use that
507       staff
508       
509       (if (not (list? type_from_structure)) 
510         ; No entry in structure found => simple staff
511         (oly:staff_handler parser piece name "Staff" '())
512         
513         ; Entry found in structure => use the handler for the given type
514         (let* ((type (car type_from_structure))
515                (handler (assoc-ref oly:staff_handlers type))
516                (children (cadr type_from_structure))
517               )
518           (if handler
519             ((primitive-eval handler) parser piece name type children)
520             (begin
521               (ly:warning "No handler found for staff type ~a, using default staff handler" type)
522               (oly:staff_handler parser piece name type children)
523             )
524           )
525         )
526       )
527     )
528   )
531 #(define oly:staff_handlers
532   (list
533     ; staff group types
534     '("GrandStaff" . oly:staff_group_handler )
535     '("PianoStaff" . oly:staff_group_handler )
536     '("ChoirStaff" . oly:staff_group_handler )
537     '("StaffGroup" . oly:staff_group_handler )
538     '("InnerChoirStaff" . oly:staff_group_handler )
539     '("InnerStaffGroup" . oly:staff_group_handler )
540     '("ParallelMusic" . oly:staff_group_handler )
541     '("SimultaneousMusic" . oly:staff_group_handler )
542     ; staff types
543     '("Staff" . oly:staff_handler )
544     '("DrumStaff" . oly:staff_handler )
545     '("RhythmicStaff" . oly:staff_handler )
546     '("TabStaff" . oly:staff_handler )
547     '("GregorianTranscriptionStaff" . oly:staff_handler )
548     '("MensuralStaff" . oly:staff_handler )
549     '("VaticanaStaff" . oly:staff_handler )
550     ; staves with multiple voices
551     '("PartCombinedStaff" . oly:part_combined_staff_handler )
552     '("ParallelVoicesStaff" . oly:parallel_voices_staff_handler )
553     ; special cases: Figured bass can be staff or voice type!
554     '("FiguredBass" . oly:figured_bass_staff_handler )
555   )
558 #(define oly:voice_handlers
559   (list
560     ; voice types
561     '("Voice" . oly:voice_handler )
562     '("CueVoice" . oly:voice_handler )
563     '("DrumVoice" . oly:voice_handler )
564     '("FiguredBass" . oly:voice_handler )
565     '("GregorianTranscriptionVoice" . oly:voice_handler )
566     '("NoteNames" . oly:voice_handler )
567     '("TabVoice" . oly:voice_handler )
568     '("VaticanaVoice" . oly:voice_handler )
569     ;'("Dynamics" . oly:dynamics_handler )
570   )
574 #(define (oly:register_staff_type_handler type func)
575 ;  (ly:message "Registering staff handler ~a for type ~a" func type)
576   (set! oly:staff_handlers (assoc-set! oly:staff_handlers type func))
579 #(define (oly:register_voice_type_handler type func)
580 ;  (ly:message "Registering voice type handler ~a for type ~a" func type)
581   (set! oly:voice_handlers (assoc-set! oly:voice_handlers type func))
584 % handlers for deprecated API
585 #(oly:register_staff_type_handler 'StaffGroup 'oly:staff_group_handler)
586 #(oly:register_staff_type_handler 'GrandStaff 'oly:staff_group_handler)
587 #(oly:register_staff_type_handler 'PianoStaff 'oly:staff_group_handler)
588 #(oly:register_staff_type_handler 'ChoirStaff 'oly:staff_group_handler)
589 #(oly:register_staff_type_handler 'Staff 'oly:staff_handler )
590 #(oly:register_staff_type_handler 'ParallelMusic 'oly:staff_group_handler)
591 #(oly:register_staff_type_handler 'SimultaneousMusic 'oly:staff_group_handler)
592 #(oly:register_staff_type_handler #t 'oly:part_combined_staff_handler )
593 #(oly:register_staff_type_handler #f 'oly:parallel_voices_staff_handler )
595     
597 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
598 % Automatic score generation
599 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
601 % \setUseBook ##t/##f sets a flag to determine whether the calls to createScore
602 % are from within a book block or not
603 % #(define oly:score_handler collect-scores-for-book)
604 #(define oly:score_handler toplevel-score-handler)
605 #(define oly:music_handler toplevel-music-handler)
606 #(define oly:text_handler toplevel-text-handler)
608 setUseBook = #(define-music-function (parser location usebook) (boolean?) 
609   (if usebook
610     (begin
611       (set! oly:score_handler book-score-handler)
612       (set! oly:music_handler book-music-handler)
613       (set! oly:text_handler book-text-handler)
614     )
615     (begin
616       (set! oly:score_handler toplevel-score-handler)
617       (set! oly:music_handler toplevel-music-handler)
618       (set! oly:text_handler toplevel-text-handler)
619     )
620   )
621   (make-music 'Music 'void #t)
625 % Two functions to handle midi-blocks: Either don't set one, or set an empty 
626 % one so that MIDI is generated
627 #(define (oly:set_no_midi_block score) '())
628 #(define (oly:set_midi_block score) 
629   (let* ((midiblock (if (defined? '$defaultmidi) 
630                         (ly:output-def-clone $defaultmidi) 
631                         (ly:make-output-def))))
632     (ly:output-def-set-variable! midiblock 'is-midi #t)
633     (ly:score-add-output-def! score midiblock)
634   )
637 % \setCreateMidi ##t/##f sets a flag to determine wheter MIDI output should
638 % be generated
639 #(define oly:apply_score_midi oly:set_no_midi_block)
640 setCreateMIDI = #(define-music-function (parser location createmidi) (boolean?)
641   (if createmidi
642     (set! oly:apply_score_midi oly:set_midi_block)
643     (set! oly:apply_score_midi oly:set_no_midi_block)
644   )
645   (make-music 'Music 'void #t)
649 % Two functions to handle layout-blocks: Either don't set one, or set an empty 
650 % one so that a PDF is generated
651 #(define (oly:set_no_layout_block score) '())
652 #(define (oly:set_layout_block score) 
653   (let* ((layoutblock (if (defined? '$defaultlayout) 
654                         (ly:output-def-clone $defaultlayout) 
655                         (ly:make-output-def))))
656     (ly:output-def-set-variable! layoutblock 'is-layout #t)
657     (ly:score-add-output-def! score layoutblock)
658   )
661 % \setCreatePDF ##t/##f sets a flag to determine wheter PDF output should
662 % be generated
663 #(define oly:apply_score_layout oly:set_no_layout_block)
664 setCreatePDF = #(define-music-function (parser location createlayout) (boolean?)
665   (if createlayout
666     (set! oly:apply_score_layout oly:set_layout_block)
667     (set! oly:apply_score_layout oly:set_no_layout_block)
668   )
669   (make-music 'Music 'void #t)
673 % Set the piece title in a new header block.
674 #(define (oly:set_piece_header score piecename)
675   (if (not-null? piecename)
676     (let* ((header (make-module)))
677       (module-define! header 'piece piecename)
678       (ly:score-set-header! score header)
679     )
680   )
684 % post-filter functions. By default, no filtering is done. However,
685 % for the *NoCues* function, the cue notes should be killed
686 identity = #(define-music-function (parser location music) (ly:music?) music)
687 cuefilter = #(define-music-function (parser location music) (ly:music?)
688   ((ly:music-function-extract removeWithTag) parser location 'cued ((ly:music-function-extract killCues) parser location music))
692 #(define (oly:create-toc-file layout pages)
693   (let* ((label-table (ly:output-def-lookup layout 'label-page-table)))
694     (if (not (null? label-table))
695       (let* ((format-line (lambda (toc-item)
696              (let* ((label (car toc-item))
697                     (text  (caddr toc-item))
698                     (label-page (and (list? label-table) 
699                                      (assoc label label-table)))
700                     (page (and label-page (cdr label-page))))
701                (format #f "~a, section, 1, {~a}, ~a" page text label))))
702              (formatted-toc-items (map format-line (toc-items)))
703              (whole-string (string-join formatted-toc-items ",\n"))
704              (output-name (ly:parser-output-name parser))
705              (outfilename (format "~a.toc" output-name))
706              (outfile (open-output-file outfilename)))
707         (if (output-port? outfile)
708             (display whole-string outfile)
709             (ly:warning (_ "Unable to open output file ~a for the TOC information") outfilename))
710         (close-output-port outfile)))))
713 #(define-public (oly:add-toc-item parser markup-symbol text)
714   (oly:music_handler parser (add-toc-item! markup-symbol text)))
717 #(define (oly:add-score parser score piecename)
718   (if (not-null? piecename)
719     (oly:add-toc-item parser 'tocItemMarkup piecename))
720   (oly:score_handler parser score)
722 % The helper function to build a score.
723 #(define (oly:createScoreHelper parser location piece children func)
724   (let* (
725          (staves    (oly:staff_group_handler parser piece "" "SimultaneousMusic" children))
726          (music     (if (not-null? staves)
727                         ((ly:music-function-extract func) parser location staves)
728                         '()
729                     ))
730          (score     '())
731          (piecename (namedPieceInstrObject piece (car children) "PieceName"))
732          (piecenametacet (namedPieceInstrObject piece (car children) "PieceNameTacet"))
733          (header    '())
734         )
735     (if (null? music)
736       ; No staves, print tacet
737       (begin 
738         (if (not-null? piecenametacet) (set! piecename piecenametacet))
739         (if (not-null? piecename)
740           (oly:add-score parser (list (oly:piece-title-markup piecename)) piecename)
741           (ly:warning (_ "No music and no score title found for part ~a and instrument ~a") piece children)
742         )
743       )
744       ; we have staves, apply the piecename to the score and add layout/midi blocks if needed
745       (begin
746         (set! score (scorify-music music parser))
747         (oly:set_piece_header score piecename)
748         (oly:apply_score_midi score)
749         (oly:apply_score_layout score)
750         ; Schedule the score for typesetting
751         (oly:add-score parser score piecename)
752       )
753     )
754   )
755   ; This is a void function, the score has been schedulled for typesetting already
756   (make-music 'Music 'void #t)
759 createScore = #(define-music-function (parser location piece children) (string? list?)
760   (oly:createScoreHelper parser location piece children identity)
762 createNoCuesScore = #(define-music-function (parser location piece children) (string? list?)
763   (oly:createScoreHelper parser location piece children cuefilter)
766 createHeadline = #(define-music-function (parser location headline) (string?)
767   (oly:add-toc-item parser 'tocItemMarkup headline)
768   (oly:score_handler parser (list (oly:piece-title-markup headline)))
769   (make-music 'Music 'void #t)
774 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
775 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
776 %%%%%   CUE NOTES
777 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
778 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
780 newInstrument = #(define-music-function (parser location instr) (string?)
782   \set Voice.instrumentCueName = #$(string-join (list "+" instr))
785 cueText = #(define-music-function (parser location instr) (string?)
787   \set Voice.instrumentCueName = $instr
791 % generate a cue music section with instrument names
792 % Parameters: \namedCueDuring NameOfQuote CueDirection CueInstrument OriginalInstrument music
793 %                 -) NameOfQuote CueDirection music are the parameters for \cueDuring
794 %                 -) CueInstrument and OriginalInstrument are the displayed instrument names
795 % typical call:
796 % \namedCueDuring #"vIQuote" #UP #"V.I" #"Sop." { R1*3 }
797 %      This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
798 %      the beginning of the cue notes and "Sop." at the end
799 namedCueDuring = #(define-music-function (parser location cuevoice direction instrcue instr cuemusic) (string? number? string? string? ly:music?)
800    #{
801      \cueDuring #$cuevoice #$direction { \tag #'cued \cueText #$instrcue $cuemusic \tag #'cued \cueText #$instr }
802 %      \tag #'uncued $cuemusic
803    #}
805 namedTransposedCueDuring = #(define-music-function (parser location cuevoice direction instrcue instr trans cuemusic) (string? number? string? string? ly:music? ly:music?)
806    #{
807      \transposedCueDuring #$cuevoice #$direction $trans { \tag #'cued \cueText #$instrcue $cuemusic \tag #'cued \cueText #$instr }
808 %      \tag #'uncued $cuemusic
809    #}
812 % set the cue instrument name and clef
813 setClefCue = #(define-music-function (parser location instr clef) 
814                                                      (string? ly:music?)
815    #{
816      \once \override Staff.Clef #'font-size = #-3 $clef
817      \set Voice.instrumentCueName = $instr
818    #} )
820 % generate a cue music section with instrument names and clef changes
821 % Parameters: \cleffedCueDuring NameOfQuote CueDirection CueInstrument CueClef OriginalInstrument OriginalClef music
822 %                 -) NameOfQuote CueDirection music are the parameters for \cueDuring
823 %                 -) CueInstrument and OriginalInstrument are the displayed instrument names
824 %                 -) CueClef and OriginalClef are the clefs for the the cue notes and the clef of the containing voice
825 % typical call:
826 % \cleffedCueDuring #"vIQuote" #UP #"V.I" #"treble" #"Basso" #"bass" { R1*3 }
827 %      This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
828 %      the beginning of the cue notes and "Basso" at the end. The clef is changed to treble at the 
829 %      beginning of the cue notes and reset to bass at the end
830 cleffedCueDuring = #(define-music-function (parser location cuevoice direction instrcue clefcue instr clefinstr cuemusic) 
831                                                         (string? number? string? ly:music? string? ly:music? ly:music?)
832    #{
833      \cueDuring #$cuevoice #$direction { \tag #'cued \setClefCue #$instrcue $clefcue $cuemusic \tag #'cued \setClefCue #$instr $clefinstr }
834 %      \tag #'uncued $cuemusic
835    #}
841 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
842 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
843 %%%%%   DYNAMICS
844 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
845 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
848 dynamicsX = #(define-music-function (parser location offset) (number?)
850     \once \override DynamicText #'X-offset = $offset
851     \once \override DynamicLineSpanner #'Y-offset = #0
854 % Move the dynamic sign inside the staff to a fixed staff-relative position 
855 % posY (where 0 means vertically starts at the middle staff line)
856 dynamicsAllInside = #(define-music-function (parser location offsetX posY)
857 (number? number?)
859   % Invalid y-extent -> hidden from skyline calculation and collisions
860   \once \override DynamicLineSpanner #'Y-extent = #(cons +0 -0.01)
861   % move by X offset and to fixed Y-position (use Y-offset of parent!)
862   \once \override DynamicText #'X-offset = $offsetX
863   \once \override DynamicText #'Y-offset =
864     $(lambda (grob)
865        (let* ((head (ly:grob-parent grob Y))
866               (offset (ly:grob-property head 'Y-offset)))
867          (- posY  offset (- 0.6))))
868   \once \override DynamicLineSpanner #'Y-offset = $posY
871 dynamicsUpInside = #(define-music-function (parser location offsetX) (number?)
872   ((ly:music-function-extract dynamicsAllInside) parser location offsetX 1.5)
875 dynamicsDownInside = #(define-music-function (parser location offsetX) (number?)
876   ((ly:music-function-extract dynamicsAllInside) parser location offsetX -3.5)
879 hairpinOffset = #(define-music-function (parser location posY) (number?)
881   \once \override DynamicLineSpanner #'Y-offset = $posY
882   \once \override DynamicLineSpanner #'Y-extent = #(cons +0 -0.01)
885 #(define ((line-break-offset before after) grob)
886   (let* ((orig (ly:grob-original grob))
887          ; All siblings if line-broken:
888          (siblings (if (ly:grob? orig) (ly:spanner-broken-into orig) '() )))
889     (if (>= (length siblings) 2)
890       ; We have been line-broken
891       (if (eq? (car (last-pair siblings)) grob)
892         ; Last sibling:
893         (ly:grob-set-property! grob 'Y-offset after)
894         ; Others get the before value:
895         (ly:grob-set-property! grob 'Y-offset before)
896       )
897     )
898   )
901 ffz = #(make-dynamic-script "ffz")
902 pf = #(make-dynamic-script "pf")
903 sempp = #(make-dynamic-script (markup #:line( #:with-dimensions '(0 . 0) 
904 '(0 . 0) #:right-align #:normal-text #:italic "sempre" #:dynamic "pp")))
905 parenf = #(make-dynamic-script (markup #:line(#:normal-text #:italic #:fontsize 2 "(" #:dynamic "f" #:normal-text #:italic #:fontsize 2 ")" )))
906 parenp = #(make-dynamic-script (markup #:line(#:normal-text #:italic #:fontsize 2 "(" #:dynamic "p" #:normal-text #:italic #:fontsize 2 ")" )))
907 pdolce = #(make-dynamic-script (markup #:line(#:dynamic "p" #:with-dimensions '(0 . 0) '(0 . 0) #:normal-text #:italic "dolce"  )))
908 bracketf = #(make-dynamic-script (markup #:line(#:concat(#:normal-text "[" #:dynamic "f" #:normal-text "]"))))
909 bracketp = #(make-dynamic-script (markup #:line(#:concat(#:normal-text "[" #:dynamic "p" #:normal-text "]"))))
913 % cresc = #(make-music 'CrescendoEvent 'span-direction START 'crescendoSpanner 'text 'crescendoText "cresc.")
914 % endcresc =  #(make-span-event 'CrescendoEvent STOP)
915 % dim = #(make-music 'DecrescendoEvent 'span-direction START 'decrescendoSpanner 'text 'decrescendoText "dim.")
916 % enddim =  #(make-span-event 'DecrescendoEvent STOP)
917 % decresc = #(make-music 'DecrescendoEvent 'span-direction START 'decrescendoSpanner 'text 'decrescendoText "decresc.")
918 % enddecresc =  #(make-span-event 'DecrescendoEvent STOP)
920 % setCresc = {}
921 % setDecresc = {}
922 % setDim = {}
924 newOrOldClef = #(define-music-function (parser location new old ) (string? string?)
925     (if (ly:get-option 'old-clefs) #{ \clef $old #} #{ \clef $new #}) 
930 %%% Thanks to "Gilles THIBAULT" <gilles.thibault@free.fr>, there is a way
931 %   to remove also the fermata from R1-\fermataMarkup: By filtering the music
932 %   and removing the corresponding events.
933 %   Documented as an LSR snippet: http://lsr.dsi.unimi.it/LSR/Item?id=372
934 #(define (filterOneEventsMarkup event)
935 ( let ( (eventname (ly:music-property  event 'name)) )
936  (not
937   (or     ;; add here event name you do NOT want
938    (eq? eventname 'MultiMeasureTextEvent)
939    (eq? eventname 'AbsoluteDynamicEvent)
940    (eq? eventname 'TextScriptEvent)
941    (eq? eventname 'ArticulationEvent)
942    (eq? eventname 'CrescendoEvent)
943    (eq? eventname 'DecrescendoEvent)
944   )
948 filterArticulations = #(define-music-function (parser location music) (ly:music?)
949   Â (music-filter filterOneEventsMarkup music)
956 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
957 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
958 %%%%%   Tempo markings
959 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
960 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
964 rit = \markup {\italic "rit."}
965 pocorit = \markup {\italic "poco rit."}
966 ppmosso = \markup {\italic "poco più mosso"}
967 dolce = \markup {\italic "dolce."}
968 pizz = \markup {\italic "pizz."}
969 arco = \markup {\italic "arco"}
970 perd = \markup {\italic "perdend."}
975 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
976 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
977 %%%%%   REST COMBINATION
978 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
979 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
983 %% REST COMBINING, TAKEN FROM http://lsr.dsi.unimi.it/LSR/Item?id=336
985 %% Usage:
986 %%   \new Staff \with {
987 %%     \override RestCollision #'positioning-done = #merge-rests-on-positioning
988 %%   } << \somevoice \\ \othervoice >>
989 %% or (globally):
990 %%   \layout {
991 %%     \context {
992 %%       \Staff
993 %%       \override RestCollision #'positioning-done = #merge-rests-on-positioning
994 %%     }
995 %%   } 
997 %% Limitations:
998 %% - only handles two voices
999 %% - does not handle multi-measure/whole-measure rests
1001 #(define (rest-score r)
1002   (let ((score 0)
1003   (yoff (ly:grob-property-data r 'Y-offset))
1004   (sp (ly:grob-property-data r 'staff-position)))
1005     (if (number? yoff)
1006   (set! score (+ score 2))
1007   (if (eq? yoff 'calculation-in-progress)
1008       (set! score (- score 3))))
1009     (and (number? sp)
1010    (<= 0 2 sp)
1011    (set! score (+ score 2))
1012    (set! score (- score (abs (- 1 sp)))))
1013     score))
1015 #(define (merge-rests-on-positioning grob)
1016   (let* ((can-merge #f)
1017    (elts (ly:grob-object grob 'elements))
1018    (num-elts (and (ly:grob-array? elts)
1019       (ly:grob-array-length elts)))
1020    (two-voice? (= num-elts 2)))
1021     (if two-voice?
1022   (let* ((v1-grob (ly:grob-array-ref elts 0))
1023          (v2-grob (ly:grob-array-ref elts 1))
1024          (v1-rest (ly:grob-object v1-grob 'rest))
1025          (v2-rest (ly:grob-object v2-grob 'rest)))
1026     (and
1027      (ly:grob? v1-rest)
1028      (ly:grob? v2-rest)          
1029      (let* ((v1-duration-log (ly:grob-property v1-rest 'duration-log))
1030       (v2-duration-log (ly:grob-property v2-rest 'duration-log))
1031       (v1-dot (ly:grob-object v1-rest 'dot))
1032       (v2-dot (ly:grob-object v2-rest 'dot))
1033       (v1-dot-count (and (ly:grob? v1-dot)
1034              (ly:grob-property v1-dot 'dot-count -1)))
1035       (v2-dot-count (and (ly:grob? v2-dot)
1036              (ly:grob-property v2-dot 'dot-count -1))))
1037        (set! can-merge
1038        (and 
1039         (number? v1-duration-log)
1040         (number? v2-duration-log)
1041         (= v1-duration-log v2-duration-log)
1042         (eq? v1-dot-count v2-dot-count)))
1043        (if can-merge
1044      ;; keep the rest that looks best:
1045      (let* ((keep-v1? (>= (rest-score v1-rest)
1046               (rest-score v2-rest)))
1047       (rest-to-keep (if keep-v1? v1-rest v2-rest))
1048       (dot-to-kill (if keep-v1? v2-dot v1-dot)))
1049        ;; uncomment if you're curious of which rest was chosen:
1050        ;;(ly:grob-set-property! v1-rest 'color green)
1051        ;;(ly:grob-set-property! v2-rest 'color blue)
1052        (ly:grob-suicide! (if keep-v1? v2-rest v1-rest))
1053        (if (ly:grob? dot-to-kill)
1054            (ly:grob-suicide! dot-to-kill))
1055        (ly:grob-set-property! rest-to-keep 'direction 0)
1056        (ly:rest::y-offset-callback rest-to-keep)))))))
1057     (if can-merge
1058   #t
1059   (ly:rest-collision::calc-positioning-done grob))))
1065 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1066 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1067 %%%%%   TABLE OF CONTENTS
1068 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1069 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1072 contentsTitle = "Inhalt / Contents"
1074 \paper {
1075   tocTitleMarkup = \markup \fill-line{ 
1076     \null 
1077     \column {
1078       \override #(cons 'line-width (* 7 cm)) 
1079       \line{ \fill-line {\piece-title {\contentsTitle} \null }}
1080       \hspace #1
1081     }
1082     \null 
1083   }
1084   tocItemMarkup = \markup \fill-line { 
1085     \null 
1086     \column {
1087       \override #(cons 'line-width (* 7 cm )) 
1088       \line { \fill-line{\fromproperty #'toc:text \fromproperty #'toc:page }}
1089     }
1090     \null
1091   }
1095 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1096 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1097 %%%%%   TITLE PAGE / HEADER
1098 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1099 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1101 #(define-markup-command (when-property layout props symbol markp) (symbol? markup?)
1102   (if (chain-assoc-get symbol props)
1103       (interpret-markup layout props markp)
1104       (ly:make-stencil '()  '(1 . -1) '(1 . -1))))
1106 #(define-markup-command (vspace layout props amount) (number?)
1107   "This produces a invisible object taking vertical space."
1108   (let ((amount (* amount 3.0)))
1109     (if (> amount 0)
1110         (ly:make-stencil "" (cons -1 1) (cons 0 amount))
1111         (ly:make-stencil "" (cons -1 1) (cons amount amount)))))
1115 titlePageMarkup = \markup \abs-fontsize #10 \when-property #'header:title \column {
1116     \vspace #4
1117     \fill-line { \fontsize #8 \fromproperty #'header:composer }
1118     \vspace #1
1119     \fill-line { \fontsize #8 \fromproperty #'header:poet }
1120     \vspace #4
1121     \fill-line { \fontsize #10 \bold \fromproperty #'header:titlepagetitle }
1122     \vspace #1
1123     \fontsize #2 \when-property #'header:titlepagesubtitle { 
1124       \fill-line { \fromproperty #'header:titlepagesubtitle }
1125       \vspace #1
1126     }
1127     \fill-line { \postscript #"-20 0 moveto 40 0 rlineto stroke" }
1128     \vspace #8
1129     \fill-line { \fontsize #5 \fromproperty #'header:ensemble }
1130     \vspace #0.02
1131     \fill-line { \fontsize #2 \fromproperty #'header:instruments }
1132     \vspace #9
1133     \fill-line { \fontsize #5 \fromproperty #'header:date }
1134     \vspace #1
1135     \fill-line { \fontsize #5 \fromproperty #'header:scoretype }
1136     \vspace #8
1137     \fontsize #2 \when-property #'header:enteredby { 
1138       \fill-line { "Herausgegeben von: / Edited by:"}
1139       \vspace #0.
1140       \fill-line { \fromproperty #'header:enteredby }
1141     }
1142     \fill-line {
1143       \when-property #'header:arrangement \column {
1144         \vspace #8
1145         \fill-line { \fontsize #3 \fromproperty #'header:arrangement }
1146       }
1147     }
1150 titleHeaderMarkup = \markup {
1151   \override #'(baseline-skip . 3.5)
1152   \column {
1153     \override #'(baseline-skip . 3.5)
1154     \column {
1155       \huge \larger \bold
1156       \fill-line {
1157         \larger \fromproperty #'header:title
1158       }
1159       \fill-line {
1160         \large \smaller \bold
1161         \larger \fromproperty #'header:subtitle
1162       }
1163       \fill-line {
1164         \smaller \bold
1165         \fromproperty #'header:subsubtitle
1166       }
1167       \fill-line {
1168         { \large \bold \fromproperty #'header:instrument }
1169       }
1170       \fill-line {
1171         \fromproperty #'header:poet
1172         \fromproperty #'header:composer
1173       }
1174       \fill-line {
1175         \fromproperty #'header:meter
1176         \fromproperty #'header:arranger
1177       }
1178     }
1179   }
1182 titleScoreMarkup = \markup \piece-title \fromproperty #'header:piece
1184 \paper {
1185   scoreTitleMarkup = \titleScoreMarkup
1186   bookTitleMarkup = \titleHeaderMarkup
1191 %%%%%%%%%%%%%% headers and footers %%%%%%%%%%%%%%%%%%%%%%%%%%
1193 #(define (first-score-page layout props arg)
1194   (let* ((label 'first-score-page)
1195          (table (ly:output-def-lookup layout 'label-page-table))
1196          (label-page (and (list? table) (assoc label table)))
1197          (page-number (and label-page (cdr label-page)))
1198         )
1199     (if (eq? (chain-assoc-get 'page:page-number props -1) page-number)
1200       (interpret-markup layout props arg)
1201       empty-stencil)))
1203 #(define no-header-table '())
1204 thisPageNoHeader = #(define-music-function (parser location) ()
1205   (let* ((label (gensym "header")))
1206     (set! no-header-table (cons label no-header-table))
1207     (make-music 'Music 
1208       'page-marker #t
1209       'page-label label)))
1212 % TODO: Use the no-header-table!
1213 #(define (is-header-page layout props arg)
1214   (let* ((page-number (chain-assoc-get 'page:page-number props -1))
1215         )
1216     ;(if (and (> page-number 2) (!= page-number 7))
1217     (if (> page-number 1)
1218       (interpret-markup layout props arg)
1219       empty-stencil)))
1221 #(define no-footer-table '())
1222 thisPageNoFooter = #(define-music-function (parser location) ()
1223   (let* ((label (gensym "footer")))
1224     (set! no-footer-table (cons label no-footer-table))
1225     (make-music 'Music 
1226       'page-marker #t
1227       'page-label label)))
1229 % TODO: Use the no-footer-table!
1230 #(define (is-footer-page layout props arg)
1231   (let* ((page-number (chain-assoc-get 'page:page-number props -1))
1232          (label 'first-score-page)
1233          (table (ly:output-def-lookup layout 'label-page-table))
1234          (label-page (and (list? table) (assoc label table)))
1235          ;(page-number (and label-page (cdr label-page)))
1236         )
1237     (if (and (> page-number 1))
1238       (interpret-markup layout props arg)
1239       empty-stencil)))
1242 #(define copyright-footer-table '())
1243 thisPageCopyrightFooter = #(define-music-function (parser location) ()
1244   (let* ((label (gensym "copyrightfooter")))
1245     (set! copyright-footer-table (cons label copyright-footer-table))
1246     (make-music 'Music 
1247       'page-marker #t
1248       'page-label label)))
1250 #(define copyright-pg 1)
1251 #(define (set-copyright-page page)
1252   (set! copyright-pg page)
1255 % TODO: Use the copyright-footer-table!
1256 #(define (copyright-page layout props arg)
1257     (if (= (chain-assoc-get 'page:page-number props -1) copyright-pg)
1258       (interpret-markup layout props arg)
1259       empty-stencil))
1262 \paper {
1263   oddHeaderMarkup = \markup \fill-line {
1264     %% force the header to take some space, otherwise the
1265     %% page layout becomes a complete mess.
1266     " "
1267     \on-the-fly #is-header-page \fromproperty #'header:title
1268     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1269   }
1270   evenHeaderMarkup = \markup \fill-line {
1271     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1272     \on-the-fly #is-header-page \fromproperty #'header:composer
1273     " "
1274   }
1276   oddFooterMarkup = \markup {
1277     \column {
1278       \fill-line {
1279         %% publisher header field only on title page.
1280         \on-the-fly #first-page \fromproperty #'header:publisher
1281       }
1282       \fill-line {
1283         %% copyright on the first real score page
1284         \on-the-fly #copyright-page \fromproperty #'header:copyright
1285         \on-the-fly #copyright-page \null
1286       }
1287       \fill-line {
1288         %% All other pages get the number of the edition centered
1289         \on-the-fly #is-footer-page \fromproperty #'header:scorenumber
1290       }
1291     }
1292   }
1306 % Interpret the given markup with the header fields added to the props. 
1307 % This way, one can re-use the same functions (using fromproperty 
1308 % #'header:field) in the header block and as top-level markup.
1310 % This function is originally copied from mark-up-title (file scm/titling.scm), 
1311 % which is lilypond's internal function to handle the title markups. I needed 
1312 % to replace the scopes and manually add the $defaultheader (which is internally 
1313 % done in paper-book.cc before calling mark-up-title. Also, I don't extract the 
1314 % markup from the header block, but use the given markup.
1316 % I'm not sure if I really need the page properties in props, too... But I 
1317 % suppose it does not hurt, either.
1318 #(define-markup-command (markupWithHeader layout props markup) (markup?)
1319   "Interpret the given markup with the header fields added to the props. 
1320    This way, one can re-use the same functions (using fromproperty 
1321    #'header:field) in the header block and as top-level markup."
1322   (let* (
1323       ; TODO: If we are inside a score, add the score's local header block, too!
1324       ; Currently, I only use the global header block, stored in $defaultheader
1325       (scopes (list $defaultheader))
1326       (alists (map ly:module->alist scopes))
1327   
1328       (prefixed-alist
1329         (map (lambda (alist)
1330           (map (lambda (entry)
1331             (cons
1332               (string->symbol (string-append "header:" (symbol->string (car entry))))
1333               (cdr entry)))
1334             alist))
1335           alists))
1336       (props (append prefixed-alist
1337               props
1338               (layout-extract-page-properties layout)))
1339     )
1340     (interpret-markup layout props markup)
1341   )
1349 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1350 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1351 %%%%%   Equally spacing multiple columns (e.g. for translations)
1352 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1353 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1355 % Credits: Nicolas Sceaux on the lilypond-user mailinglist
1356 #(define-markup-command (columns layout props args) (markup-list?)
1357    (let ((line-width (/ (chain-assoc-get 'line-width props
1358                          (ly:output-def-lookup layout 'line-width))
1359                         (max (length args) 1))))
1360      (interpret-markup layout props
1361        (make-line-markup (map (lambda (line)
1362                                 (markup #:pad-to-box `(0 . ,line-width) '(0 . 0)
1363                                   #:override `(line-width . ,line-width)
1364                                   line))
1365                                args)))))
1369 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1370 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1371 %%%%%   SCORE (HEADER / LAYOUT) SETTINGS
1372 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1373 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1376 startSlashedGraceMusic =  {
1377   \override Stem  #'stroke-style = #"grace"
1380 stopSlashedGraceMusic =  {
1381   \revert Stem #'stroke-style
1384 slashedGrace =
1385 #(def-grace-function startSlashedGraceMusic stopSlashedGraceMusic
1386    (_i "Create slashed graces (slashes through stems, but no slur)from the following music expression"))
1389 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1390 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1391 %%%%%   SCORE (HEADER / LAYOUT) SETTINGS
1392 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1393 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1395 \paper {
1396   left-margin = 2\cm
1397   right-margin = 1.5\cm
1398   line-width = 17.5\cm
1399 %   bottom-margin = 1.5\cm
1400 %   top-margin = 1.5\cm
1401 %   after-title-space = 0.5\cm
1402   ragged-right = ##f
1403   ragged-last = ##f
1404   ragged-bottom = ##f
1405   ragged-last-bottom = ##f
1407 \layout {
1408   \context {
1409     \ChoirStaff 
1410     % If only one non-empty staff in a system exists, still print the backet
1411     \override SystemStartBracket #'collapse-height = #1
1412     \consists "Instrument_name_engraver"
1413   }
1414   \context {
1415     \StaffGroup
1416     % If only one non-empty staff in a system exists, still print the backet
1417     \override SystemStartBracket #'collapse-height = #1
1418     \consists "Instrument_name_engraver"
1419   }
1420   \context {
1421     \GrandStaff
1422     \override SystemStartBracket #'collapse-height = #1
1423     \consists "Instrument_name_engraver"
1424   }
1425   \context {
1426     \PianoStaff
1427 %     \override VerticalAxisGroup #'keep-fixed-while-stretching = ##t
1428   }
1429   \context {
1430     \FiguredBass
1431 %     \override VerticalAxisGroup #'keep-fixed-while-stretching = ##t
1432     \override VerticalAxisGroup #'minimum-Y-extent  = #'(0 . 1)
1433     \override VerticalAxisGroup #'padding = #0
1434   }
1435   \context {
1436     \Score
1437     % Force multi-measure rests to be written as one span
1438     \override MultiMeasureRest #'expand-limit = #3
1439     skipBars = ##t
1440     autoBeaming = ##f
1441 %     hairpinToBarline = ##f
1442     \override BarNumber #'break-visibility = #end-of-line-invisible
1443     \override BarNumber #'self-alignment-X = #0
1444     \override CombineTextScript #'avoid-slur = #'outside
1445     barNumberVisibility = #(every-nth-bar-number-visible 5)
1446     \override DynamicTextSpanner #'dash-period = #-1.0
1447     \override InstrumentSwitch #'font-size = #-1
1449     % Rest collision
1450     \override RestCollision #'positioning-done = #merge-rests-on-positioning
1451     % Auto-Accidentals: Use modern-cautionary style...
1452     extraNatural = ##f
1453     autoAccidentals = #`(Staff  ,(make-accidental-rule 'same-octave 0)
1454                                 ,(make-accidental-rule 'any-octave 0)
1455                                 ,(make-accidental-rule 'same-octave 1))
1456 %     autoCautionaries = #`(Staff ,(make-accidental-rule 'any-octave 0)
1457 %                                 ,(make-accidental-rule 'same-octave 1))
1458     printKeyCancellation = ##t
1459   }
1460   \context {
1461     \RemoveEmptyStaffContext 
1462   }
1463   \context {
1464     \Lyrics
1465     \override VerticalAxisGroup #'minimum-Y-extent = #'(0.5 . 0.5)
1466   }
1467   \context {
1468     \Staff
1469     \override VerticalAxisGroup #'minimum-Y-extent = #'(-1. . 3)
1470     quotedEventTypes = #'(StreamEvent)
1471     ignoreFiguredBassRest = ##f
1472     implicitBassFigures = #'(0 100)
1473   }
1478 \layout {
1479   \context {
1480     \type "Engraver_group"
1481     \name Dynamics
1482     % So that \cresc works, for example.
1483     \alias Voice
1484     \consists "Output_property_engraver"
1485     
1486     \override VerticalAxisGroup #'minimum-Y-extent = #'(-1 . 1)
1487     pedalSustainStrings = #'("Ped." "*Ped." "*")
1488     pedalUnaCordaStrings = #'("una corda" "" "tre corde")
1489     
1490     \consists "Piano_pedal_engraver"
1491     \consists "Script_engraver"
1492     \consists "Dynamic_engraver"
1493     \consists "Text_engraver"
1494     
1495     \override TextScript #'font-size = #2
1496     \override TextScript #'font-shape = #'italic
1497     \override DynamicText #'extra-offset = #'(0 . 2.5)
1498     \override Hairpin #'extra-offset = #'(0 . 2.5)
1499     
1500     \consists "Skip_event_swallow_translator"
1501     
1502     \consists "Axis_group_engraver"
1503   }
1504   \context {
1505     \PianoStaff
1506     \accepts Dynamics
1507 %     \override VerticalAlignment #'forced-distance = #7
1508   }
1512 ts = ^\markup{"t.s."}
1513 tt = ^\markup{"Tutti"}
1514 solo = ^\markup{"Solo"}
1515 tutti = ^\markup{"Tutti"}
1517 dashedSlur = -\tweak #'dash-definition #'((0 1 0.4 0.75))(
1518 dashedTie = -\tweak #'dash-definition #'((0 1 0.4 0.75))~
1520 divisi = #(define-music-function (parser location vc1 vc2) (ly:music? ly:music?)
1522   << { \voiceOne $vc1 \oneVoice} \new Voice = "divisi2" { \voiceTwo $vc2 } >>
1526 #(define-public (bracket-stencils grob)
1527   (let ((lp (grob-interpret-markup grob (markup #:fontsize 3.5 #:translate (cons -0.3 -0.5) "[")))
1528         (rp (grob-interpret-markup grob (markup #:fontsize 3.5 #:translate (cons -0.3 -0.5) "]"))))
1529     (list lp rp)))
1531 bracketify = #(define-music-function (parser loc arg) (ly:music?)
1532    (_i "Tag @var{arg} to be parenthesized.")
1534   \once \override ParenthesesItem #'stencils = #bracket-stencils
1535   \parenthesize $arg
1540 #(define-markup-command (hat layout props arg) (markup?)
1541   "Draw a hat above the given string @var{arg}."
1542   (interpret-markup layout props (markup #:combine #:raise 1.0 "^" arg)))