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