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