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