Start of generating TeX files in generate_oly_structure.py
[orchestrallily.git] / orchestrallily.ily
blobfaa35387eab09acb470802161ba2585153b2195c
1 \version "2.11.41"
3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 % OrchestralLily
5 % ==============
6 % Desciption:  Lilypond package to make writing large orchestral scores easier.
7 % Documentation: http://wiki.kainhofer.com/lilypond/orchestrallily
8 % Version: 0.02, 2008-03-06
9 % Author: Reinhold Kainhofer, reinhold@kainhofer.com
10 % Copyright: (C) 2008 by Reinhold Kainhofer
11 % License: GPL v3.0, http://www.gnu.org/licenses/gpl.html
13 % Version History:
14 % 0.01 (2008-03-02): Initial Version
15 % 0.02 (2008-03-06): Added basic MIDI support (*MidiInstrument and \setCreateMIDI)
16 % 0.03 (2008-07-xx): General staff/voice types, title pages, etc.
17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19 #(use-modules (ice-9 match))
22 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24 %%%%%   SCORE STRUCTURE AND AUTOMATIC GENERATION
25 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 % Helper functions
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 % Helper function to filter all non-null entries
36 #(define (not-null? x) (not (null? x)))
38 % Helper function to extract a given variable, built from [Piece][Instrument]Identifier
39 #(define (namedPieceInstrObject piece instr name)
40   (let* (
41          (fullname  (string->symbol (string-append piece instr name)))
42          (instrname (string->symbol (string-append instr name)))
43          (piecename (string->symbol (string-append piece name)))
44         )
45     (cond
46       ((defined? fullname) (primitive-eval fullname))
47       ((defined? instrname) (primitive-eval instrname))
48       ((defined? piecename) (primitive-eval piecename))
49       (else '())
50     )
51   )
54 %% Print text as a justified paragraph, taken from the lilypond Notation Reference
55 #(define-markup-list-command (paragraph layout props args) (markup-list?)
56    (let ((indent (chain-assoc-get 'par-indent props 2)))
57      (interpret-markup-list layout props
58        (make-justified-lines-markup-list (cons (make-hspace-markup indent)
59                                                args)))))
61 conditionalBreak = #(define-music-function (parser location) ()
62    #{ \tag #'instrumental-score \pageBreak #}
65 #(define (oly:piece-title-markup title) (markup #:column (#:line (#:fontsize #'3 #:bold title))) )
67 #(define-markup-command (piece-title layout props title) (markup?)
68      (interpret-markup layout props (oly:piece-title-markup title))
71 #(define (oly:generate_object_name piece instr obj )
72   (if (and (string? piece) (string? instr) (string? obj))
73     (string-append piece instr obj)
74     #f
75   )
77 #(define (oly:generate_staff_name piece instr) (oly:generate_object_name piece instr "St"))
79 #(define (set-context-property context property value)
80   (set! (ly:music-property context property) value)
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 % Score structure and voice types
86 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 #(define oly:orchestral_score_structure '(
89 ; Part-combined staves for full score
90   ("Fl" "PartCombinedStaff" ("FlI" "FlII"))
91   ("Ob" "PartCombinedStaff" ("ObI" "ObII"))
92   ("Cl" "PartCombinedStaff" ("ClI" "ClII"))
93   ("Fag" "PartCombinedStaff" ("FagI" "FagII"))
94   ("Wd" "StaffGroup" ("Fl" "Ob" "Cl" "Fag" "CFag"))
96   ("Cor" "PartCombinedStaff" ("CorI" "CorII"))
97   ("Trb" "PartCombinedStaff" ("TrbI" "TrbII"))
98   ("Tbe" "PartCombinedStaff" ("TbeI" "TbeII"))
99   ("Br" "StaffGroup" ("Cor" "Trb" "Tbe" "Tba"))
101 ; long score; no part-combined staves, but GrandStaves instead
102   ("FlLong" "GrandStaff" ("FlI" "FlII"))
103   ("ObLong" "GrandStaff" ("ObI" "ObII"))
104   ("ClLong" "GrandStaff" ("ClI" "ClII"))
105   ("FagLong" "GrandStaff" ("FagI" "FagII"))
106   ("WdLong" "StaffGroup" ("FlLong" "ObLong" "ClLong" "FagLong" "CFag"))
108   ("CorLong" "GrandStaff" ("CorI" "CorII"))
109   ("TrbLong" "GrandStaff" ("TrbI" "TrbII"))
110   ("TbeLong" "GrandStaff" ("TbeI" "TbeII" "TbeIII"))
111   ("BrLong" "StaffGroup" ("CorLong" "TrbLong" "TbeLong" "Tba"))
113 ; Percussion
114   ("Perc" "StaffGroup" ("Tim"))
116 ; Strings, they are the same in long and short full score  
117   ("V" "GrandStaff" ("VI" "VII"))
118   ("Str" "StaffGroup" ("V" "Va"))
119   ("VceB" "StaffGroup" ("Vc" "Cb" "VcB"))
120   ("FullStr" "StaffGroup" ("V" "Va" "Vc" "Cb" "VcB"))
122 ; Choral score
123   ("Solo" "SimultaneousMusic" ("SSolo" "ASolo" "TSolo" "BSolo"))
124   ("Ch" "ChoirStaff" ("S" "A" "T" "B"))
125   ("ChoirScore" "SimultaneousMusic" ("Ch"))
126   ("SoloScore" "SimultaneousMusic" ("Solo"))
127   ("SoloChoirScore" "SimultaneousMusic" ("Solo" "Ch"))
129 ; Organ score (inkl. Figured bass)
130   ("OFb" "FiguredBass" ())
131   ("FiguredBass" "FiguredBass" ())
132   ;("Organ" "SimultaneousMusic" ("OFb" "O"))
133   ("BC" "ParallelVoicesStaff" ("OFb" "O" "FiguredBass"))
134   
135   ("O" "PianoStaff" ("OI" "OII"))
136   ("OI" "ParallelVoicesStaff" ("OIa" "OIb"))
137   ("OII" "ParallelVoicesStaff" ("OIIa" "OIIb"))
139 ; Full Scores
140   ("FullScore" "SimultaneousMusic" ("Wd" "Br" "Perc" "Str" "ChoirScore" "Organ" "O" "BC" "VceB"))
141   ("LongScore" "SimultaneousMusic" ("WdLong" "BrLong" "Perc" "Str" "ChoirScore" "Organ" "O" "BC" "VceB"))
143 ; Piano reduction
144   ;("Piano" "SimultaneousMusic" ("Organ"))
145   ("OrganScore" "SimultaneousMusic" ("ChoirScore" "O" "BC"))
146   ("PianoScore" "SimultaneousMusic" ("ChoirScore" "O" "Piano"))
148 ; Full scores: Orchestral score and long score including organ
149   ("ChStrQ" "SimultaneousMusic" ("Str" "Ch" "VceB"))
152 #(define (oly:set_score_structure struct)
153   (if (list? struct)
154     (set! oly:orchestral_score_structure struct)
155     (ly:warning (_ "oly:set_score_structure needs an association list as argument!"))
156   )
159 orchestralScoreStructure = #(define-music-function (parser location structure) (list?) 
160   (oly:set_score_structure structure)
161   (make-music 'Music 'void #t)
164 #(define oly:voice_types '())
166 #(define (oly:set_voice_types types)
167   (if (list? types)
168     (set! oly:voice_types types)
169     (ly:warning (_ "oly:set_voice_types needs an association list as argument!"))
170   )
173 orchestralVoiceTypes = #(define-music-function (parser location types) (list?)
174   (oly:set_voice_types types)
175   (make-music 'Music 'void #t)
179 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180 % Automatic staff and group generation
181 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183 % Retrieve all music definitions for the given 
184 #(define (oly:get_music_object piece instrument)
185   (namedPieceInstrObject piece instrument "Music")
187 #(define (oly:get_music_objects piece instruments)
188   (filter not-null? (map (lambda (i) (oly:get_music_object piece i)) instruments))
191 % Given a property name and the extensions, either generate the pair to set 
192 % the property or an empty list, if no pre-defined variable could be found
193 #(define (oly:generate_property_pair prop piece instr type)
194   (let* ((val (namedPieceInstrObject piece instr type)))
195     (if (not-null? val) (list 'assign prop val) '() )
196   )
198   
199 #(define (oly:staff_type type)
200   (cond 
201     ((string? type) (string->symbol type))
202     ((symbol? type) type)
203     (else 'Staff)
204   )
207 #(define (oly:extractPitch music)
208   (let* (
209          (elems  (if (ly:music? music) (ly:music-property music 'elements)))
210          (note   (if (pair? elems) (car elems)))
211          (pitch  (if (ly:music? note) (ly:music-property note 'pitch)))
212         )
213     (if (and (not-null? music) (not (ly:pitch? pitch))) 
214       (ly:warning "Unable to interpret as a pitch!")
215     )
216     pitch
217   )
220 #(define (oly:extractTranspositionPitch piece name)
221   (let* (
222          (trpFromPitch (oly:extractPitch (namedPieceInstrObject piece name "TransposeFrom")))
223          (trpToPitch   (oly:extractPitch (namedPieceInstrObject piece name "TransposeTo")))
224         )
225     (if (ly:pitch? trpFromPitch)
226       (if (ly:pitch? trpToPitch)
227         ; Both pitches
228         (ly:pitch-diff trpFromPitch trpToPitch)
229         (ly:pitch-diff trpFromPitch (ly:make-pitch 0 0 0))
230       )
231       (if (ly:pitch? trpToPitch)
232         (ly:pitch-diff (ly:make-pitch 0 0 0) trpToPitch)
233         #f
234       )
235     )
236   )
239 #(define (oly:musiccontent_for_voice parser piece name music additional)
240   (let* ((musiccontent additional))
241     
242     ; Append the settings, key and clef (if defined)
243     (map 
244       (lambda (type) 
245         (let* ((object (namedPieceInstrObject piece name type)))
246           (if (ly:music? object)
247             (set! musiccontent (append musiccontent (list (ly:music-deep-copy object))))
248             (if (not-null? object) (ly:warning (_ "Wrong type (no ly:music) for ~S for instrument ~S in piece ~S") type name piece))
249           )
250         )
251       )
252       ; TODO: Does the "Tempo" work here???
253       '("Settings" "Key" "Clef" "TimeSignature" ;"Tempo"
254       )
255     )
257     (if (ly:music? music)
258       (begin
259         (set! musiccontent (make-simultaneous-music (append musiccontent (list music))))
260         ;(ly:message "Generating staff for ~a" name)
261         (let* ((trpPitch (oly:extractTranspositionPitch piece name)))
262           (if (ly:pitch? trpPitch) 
263             (set! musiccontent (ly:music-transpose musiccontent trpPitch))
264           )
265         )
266         musiccontent
267       )
268       ; For empty music, return empty 
269       '()
270     )
271   )
273 #(define (oly:voice_handler_internal parser piece name type music)
274   (let* (
275          (lyrics   (namedPieceInstrObject piece name "Lyrics"))
276          (additional '())
277         )
278     
279     (if (ly:music? lyrics)
280       (set! additional (list dynamicUp))
281       (if (not-null? lyrics) (ly:warning (_ "Wrong type (no lyrics) for lyrics for instrument ~S in piece ~S") name piece))
282     )
284     (if (ly:music? music)
285       (let* ((musiccontent (oly:musiccontent_for_voice parser piece name music additional))
286              (voicename  (oly:generate_object_name piece name "Voice" ))
287              (voicetype  (oly:staff_type type))
288              (voice      (context-spec-music musiccontent voicetype voicename))
289              (staffcont  (list voice))
290             )
291         ; If we have lyrics, create a lyrics context containing LyricCombineMusic 
292         ; and add that as second element to the staff's elements list...
293         (if (ly:music? lyrics)
294           (let* (
295                  (lyricsname (oly:generate_object_name piece name "Lyrics" ))
296                  (lyricscont (make-music 'LyricCombineMusic 'element lyrics 'associated-context voicename))
297                 )
298             (set! staffcont (append staffcont 
299               (list (context-spec-music lyricscont 'Lyrics lyricsname))))
300           )
301         )
302         staffcont
303       )
304       ; For empty music, return empty 
305       '()
306     )
307   )
310 #(define (oly:voice_handler parser piece name type)
311   (let* ((music (oly:get_music_object piece name))
312         )
313     (oly:voice_handler_internal parser piece name type music)
314   )
318 #(define (oly:staff_handler_internal parser piece name type voices)
319   (if (not-null? voices)
320     (let* (
321            (staffname  (oly:generate_staff_name piece name))
322            (stafftype  (oly:staff_type type))
323            (staff      (make-simultaneous-music voices))
324            (propops    (oly:staff_handler_properties piece name))
325           )
326       (case stafftype
327         ((SimultaneousMusic ParallelMusic) #f)
328         (else (set! staff (context-spec-music staff stafftype staffname)))
329       )
330       (if (not-null? propops)
331         (set! (ly:music-property staff 'property-operations) propops)
332       )
333       staff
334     )
335     ; For empty music, return empty 
336     '()
337   )
340 #(define (oly:staff_handler parser piece name type children)
341   (let* ((c (if (not-null? children) children (list name)))
342          (voices (apply append (map (lambda (v) (oly:create_voice parser piece v)) c)) ) 
343         )
344     (if (not-null? voices)
345       (oly:staff_handler_internal parser piece name type voices)
346       '()
347     )
348   )
350   
351 #(define (oly:parallel_voices_staff_handler parser piece name type children) 
352   (let* (
353          (voices (map (lambda (i) (oly:create_voice parser piece i)) children))
354          ; get the list of non-empty voices and flatten it!
355          (nonemptyvoices (apply append (filter not-null? voices)))
356         )
357     (if (not-null? nonemptyvoices)
358       (oly:staff_handler_internal parser piece name "Staff" nonemptyvoices)
359       '()
360     )
361   )
364 #(define (oly:part_combined_staff_handler parser piece name type children) 
365   (let* ((rawmusic (map (lambda (c) (oly:musiccontent_for_voice parser piece name (oly:get_music_object piece c) '())) children))
366          (music (filter not-null? rawmusic)))
367   (cond
368       ((and (pair? music) (ly:music? (car music)) (not-null? (cdr music)) (ly:music? (cadr music)))
369           ;(ly:message "Part-combine with two music expressions")
370           (oly:staff_handler_internal parser piece name "Staff" (list (make-part-combine-music parser music))))
371       ((null? music) 
372           (ly:warning "Part-combine without any music expressions")
373           '())
374       ; exactly one is a music expression, simply use that by joining 
375       ((list? music) 
376           (ly:message "Part-combine with only one music expressions")
377           (oly:staff_handler_internal parser piece name "Staff" (list (apply append music))))
378       (else 
379           ;(ly:message "make_part_combined_staff: ~S ~S ~a" piece instr instruments) 
380           '() )
381     )
382   )
385 % Generate the properties for the staff for piece and instr. Typically, these
386 % are the instrument name and the short instrument name (if defined).
387 % return a (possibly empty) list of all assignments.
388 #(define (oly:staff_handler_properties piece instr)
389   (let* (
390          (mapping '( 
391               (instrumentName . "InstrumentName") 
392               (shortInstrumentName . "ShortInstrumentName")
393               (midiInstrument . "MidiInstrument")
394             ))
395          (assignments (map 
396              (lambda (pr) 
397                  (oly:generate_property_pair (car pr) piece instr (cdr pr))
398              )
399              mapping))
400          (props (filter not-null? assignments))
401         )
402     props
403   )
405   
406 % Figured bass is a special case, as it can be voice- or staff-type. When
407 % given as a staff type, simply call the voice handler, instead
409 #(define (oly:figured_bass_staff_handler parser piece name type children)
410   (let* ((c (if (not-null? children) children (list name)))
411          (voice  (oly:voice_handler parser piece (car c) type)))
412     (if (pair? voice) (car voice) ())
413   )
415   
417 #(define (oly:staff_group_handler parser piece name type children)
418   (let* (
419          (staves (map (lambda (i) (oly:create_staff_or_group parser piece i)) children))
420          (nonemptystaves (filter not-null? staves))
421         )
422     (if (not-null? nonemptystaves)
423       (let* (
424              (musicexpr (if (= 1 (length nonemptystaves)) 
425                           (car nonemptystaves) 
426                           (make-simultaneous-music nonemptystaves)))
427              (groupname (oly:generate_staff_name piece name))
428              (grouptype (oly:staff_type type))
429              (group     musicexpr)
430              (propops   (oly:staff_handler_properties piece name))
431             )
432         (case grouptype
433           ((SimultaneousMusic ParallelMusic) #f)
434           (else (set! group (context-spec-music group grouptype groupname)))
435         )
436         (set! (ly:music-property group 'property-operations) propops)
437         group
438       )
439       ; Return empty list if no staves are generated
440       '()
441     )
442   )
445 #(define (oly:create_voice parser piece name)
446   (let* ( (voice (namedPieceInstrObject piece name "Voice"))
447           (type (assoc-ref oly:voice_types name)) )
448     (if (not-null? voice)
449       ; Explicit voice variable, use that
450       voice
451       
452       (if (not type)
453         ; No entry in structure found => simple voice
454         (oly:voice_handler parser piece name "Voice")
455         ; Entry found in structure => use the handler for the given type
456         (let* (
457                (voicetype (car type))
458                (handler (assoc-ref oly:voice_handlers voicetype))
459               )
460           (if handler
461             ((primitive-eval handler) parser piece name voicetype)
462             (begin
463               (ly:warning "No handler found for voice type ~a, using default voice handler" voicetype)
464               (oly:voice_handler parser piece name voicetype)
465             )
466           )
467         )
468       )
469     )
470   )
473 #(define (oly:create_staff_or_group parser piece name)
474   (let* ( (staff (namedPieceInstrObject piece name "Staff"))
475           (type_from_structure (assoc-ref oly:orchestral_score_structure name)) )
476     ;(if (not-null? staff)
477     ;  (ly:message "Found staff variable for instrument ~a in piece ~a"  instr piece)
478     ;  (ly:message "Staff variable for instrument ~a in piece ~a NOT FOUND"  instr piece)
479     ;)
480     (if (not-null? staff)
481       ; Explicit staff variable, use that
482       staff
483       
484       (if (not (list? type_from_structure)) 
485         ; No entry in structure found => simple staff
486         (oly:staff_handler parser piece name "Staff" '())
487         
488         ; Entry found in structure => use the handler for the given type
489         (let* ((type (car type_from_structure))
490                (handler (assoc-ref oly:staff_handlers type))
491                (children (cadr type_from_structure))
492               )
493           (if handler
494             ((primitive-eval handler) parser piece name type children)
495             (begin
496               (ly:warning "No handler found for staff type ~a, using default staff handler" type)
497               (oly:staff_handler parser piece name type children)
498             )
499           )
500         )
501       )
502     )
503   )
506 #(define oly:staff_handlers
507   (list
508     ; staff group types
509     '("GrandStaff" . oly:staff_group_handler )
510     '("PianoStaff" . oly:staff_group_handler )
511     '("ChoirStaff" . oly:staff_group_handler )
512     '("StaffGroup" . oly:staff_group_handler )
513     '("InnerChoirStaff" . oly:staff_group_handler )
514     '("InnerStaffGroup" . oly:staff_group_handler )
515     '("ParallelMusic" . oly:staff_group_handler )
516     '("SimultaneousMusic" . oly:staff_group_handler )
517     ; staff types
518     '("Staff" . oly:staff_handler )
519     '("DrumStaff" . oly:staff_handler )
520     '("RhythmicStaff" . oly:staff_handler )
521     '("TabStaff" . oly:staff_handler )
522     '("GregorianTranscriptionStaff" . oly:staff_handler )
523     '("MensuralStaff" . oly:staff_handler )
524     '("VaticanaStaff" . oly:staff_handler )
525     ; staves with multiple voices
526     '("PartCombinedStaff" . oly:part_combined_staff_handler )
527     '("ParallelVoicesStaff" . oly:parallel_voices_staff_handler )
528     ; special cases: Figured bass can be staff or voice type!
529     '("FiguredBass" . oly:figured_bass_staff_handler )
530   )
533 #(define oly:voice_handlers
534   (list
535     ; voice types
536     '("Voice" . oly:voice_handler )
537     '("CueVoice" . oly:voice_handler )
538     '("DrumVoice" . oly:voice_handler )
539     '("FiguredBass" . oly:voice_handler )
540     '("GregorianTranscriptionVoice" . oly:voice_handler )
541     '("NoteNames" . oly:voice_handler )
542     '("TabVoice" . oly:voice_handler )
543     '("VaticanaVoice" . oly:voice_handler )
544     ;'("Dynamics" . oly:dynamics_handler )
545   )
549 #(define (oly:register_staff_type_handler type func)
550 ;  (ly:message "Registering staff handler ~a for type ~a" func type)
551   (set! oly:staff_handlers (assoc-set! oly:staff_handlers type func))
554 #(define (oly:register_voice_type_handler type func)
555 ;  (ly:message "Registering voice type handler ~a for type ~a" func type)
556   (set! oly:voice_handlers (assoc-set! oly:voice_handlers type func))
559 % handlers for deprecated API
560 #(oly:register_staff_type_handler 'StaffGroup 'oly:staff_group_handler)
561 #(oly:register_staff_type_handler 'GrandStaff 'oly:staff_group_handler)
562 #(oly:register_staff_type_handler 'PianoStaff 'oly:staff_group_handler)
563 #(oly:register_staff_type_handler 'ChoirStaff 'oly:staff_group_handler)
564 #(oly:register_staff_type_handler 'Staff 'oly:staff_handler )
565 #(oly:register_staff_type_handler 'ParallelMusic 'oly:staff_group_handler)
566 #(oly:register_staff_type_handler 'SimultaneousMusic 'oly:staff_group_handler)
567 #(oly:register_staff_type_handler #t 'oly:part_combined_staff_handler )
568 #(oly:register_staff_type_handler #f 'oly:parallel_voices_staff_handler )
570     
572 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
573 % Automatic score generation
574 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
576 % \setUseBook ##t/##f sets a flag to determine whether the calls to createScore
577 % are from within a book block or not
578 % #(define oly:score_handler collect-scores-for-book)
579 #(define oly:score_handler toplevel-score-handler)
580 #(define oly:music_handler toplevel-music-handler)
581 #(define oly:text_handler toplevel-text-handler)
583 setUseBook = #(define-music-function (parser location usebook) (boolean?) 
584   (if usebook
585     (begin
586       (set! oly:score_handler book-score-handler)
587       (set! oly:music_handler book-music-handler)
588       (set! oly:text_handler book-text-handler)
589     )
590     (begin
591       (set! oly:score_handler toplevel-score-handler)
592       (set! oly:music_handler toplevel-music-handler)
593       (set! oly:text_handler toplevel-text-handler)
594     )
595   )
596   (make-music 'Music 'void #t)
600 % Two functions to handle midi-blocks: Either don't set one, or set an empty 
601 % one so that MIDI is generated
602 #(define (oly:set_no_midi_block score) '())
603 #(define (oly:set_midi_block score) 
604   (let* ((midiblock (if (defined? '$defaultmidi) 
605                         (ly:output-def-clone $defaultmidi) 
606                         (ly:make-output-def))))
607     (ly:output-def-set-variable! midiblock 'is-midi #t)
608     (ly:score-add-output-def! score midiblock)
609   )
612 % \setCreateMidi ##t/##f sets a flag to determine wheter MIDI output should
613 % be generated
614 #(define oly:apply_score_midi oly:set_no_midi_block)
615 setCreateMIDI = #(define-music-function (parser location createmidi) (boolean?)
616   (if createmidi
617     (set! oly:apply_score_midi oly:set_midi_block)
618     (set! oly:apply_score_midi oly:set_no_midi_block)
619   )
620   (make-music 'Music 'void #t)
624 % Two functions to handle layout-blocks: Either don't set one, or set an empty 
625 % one so that a PDF is generated
626 #(define (oly:set_no_layout_block score) '())
627 #(define (oly:set_layout_block score) 
628   (let* ((layoutblock (if (defined? '$defaultlayout) 
629                         (ly:output-def-clone $defaultlayout) 
630                         (ly:make-output-def))))
631     (ly:output-def-set-variable! layoutblock 'is-layout #t)
632     (ly:score-add-output-def! score layoutblock)
633   )
636 % \setCreatePDF ##t/##f sets a flag to determine wheter PDF output should
637 % be generated
638 #(define oly:apply_score_layout oly:set_no_layout_block)
639 setCreatePDF = #(define-music-function (parser location createlayout) (boolean?)
640   (if createlayout
641     (set! oly:apply_score_layout oly:set_layout_block)
642     (set! oly:apply_score_layout oly:set_no_layout_block)
643   )
644   (make-music 'Music 'void #t)
648 % Set the piece title in a new header block.
649 #(define (oly:set_piece_header score piecename)
650   (if (not-null? piecename)
651     (let* ((header (make-module)))
652       (module-define! header 'piece piecename)
653       (ly:score-set-header! score header)
654     )
655   )
659 % post-filter functions. By default, no filtering is done. However,
660 % for the *NoCues* function, the cue notes should be killed
661 identity = #(define-music-function (parser location music) (ly:music?) music)
662 cuefilter = #(define-music-function (parser location music) (ly:music?)
663   ((ly:music-function-extract removeWithTag) parser location 'cued ((ly:music-function-extract killCues) parser location music))
667 #(define (oly:create-toc-file layout pages)
668   (let* ((label-table (ly:output-def-lookup layout 'label-page-table)))
669     (if (not (null? label-table))
670       (let* ((format-line (lambda (toc-item)
671              (let* ((label (car toc-item))
672                     (text  (caddr toc-item))
673                     (label-page (and (list? label-table) 
674                                      (assoc label label-table)))
675                     (page (and label-page (cdr label-page))))
676                (format #f "~a, section, 1, {~a}, ~a" page text label))))
677              (formatted-toc-items (map format-line (toc-items)))
678              (whole-string (string-join formatted-toc-items ",\n"))
679              (output-name (ly:parser-output-name parser))
680              (outfilename (format "~a.toc" output-name))
681              (outfile (open-output-file outfilename)))
682         (if (output-port? outfile)
683             (display whole-string outfile)
684             (ly:warning (_ "Unable to open output file ~a for the TOC information") outfilename))
685         (close-output-port outfile)))))
688 #(define-public (oly:add-toc-item parser markup-symbol text)
689   (oly:music_handler parser (add-toc-item! markup-symbol text)))
692 #(define (oly:add-score parser score piecename)
693   (if (not-null? piecename)
694     (oly:add-toc-item parser 'tocItemMarkup piecename))
695   (oly:score_handler parser score)
697 % The helper function to build a score.
698 #(define (oly:createScoreHelper parser location piece children func)
699   (let* (
700          (staves    (oly:staff_group_handler parser piece "" "SimultaneousMusic" children))
701          (music     (if (not-null? staves)
702                         ((ly:music-function-extract func) parser location staves)
703                         '()
704                     ))
705          (score     '())
706          (piecename (namedPieceInstrObject piece (car children) "PieceName"))
707          (piecenametacet (namedPieceInstrObject piece (car children) "PieceNameTacet"))
708          (header    '())
709         )
710     (if (null? music)
711       ; No staves, print tacet
712       (begin 
713         (if (not-null? piecenametacet) (set! piecename piecenametacet))
714         (if (not-null? piecename)
715           (oly:add-score parser (list (oly:piece-title-markup piecename)) piecename)
716           (ly:warning (_ "No music and no score title found for part ~a and instrument ~a") piece children)
717         )
718       )
719       ; we have staves, apply the piecename to the score and add layout/midi blocks if needed
720       (begin
721         (set! score (scorify-music music parser))
722         (oly:set_piece_header score piecename)
723         (oly:apply_score_midi score)
724         (oly:apply_score_layout score)
725         ; Schedule the score for typesetting
726         (oly:add-score parser score piecename)
727       )
728     )
729   )
730   ; This is a void function, the score has been schedulled for typesetting already
731   (make-music 'Music 'void #t)
734 createScore = #(define-music-function (parser location piece children) (string? list?)
735   (oly:createScoreHelper parser location piece children identity)
737 createNoCuesScore = #(define-music-function (parser location piece children) (string? list?)
738   (oly:createScoreHelper parser location piece children cuefilter)
741 createHeadline = #(define-music-function (parser location headline) (string?)
742   (oly:add-toc-item parser 'tocItemMarkup headline)
743   (oly:score_handler parser (list (oly:piece-title-markup headline)))
744   (make-music 'Music 'void #t)
749 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
750 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
751 %%%%%   CUE NOTES
752 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
753 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
755 newInstrument = #(define-music-function (parser location instr) (string?)
757   \set Voice.instrumentCueName = #$(string-join (list "+" instr))
760 cueText = #(define-music-function (parser location instr) (string?)
762   \set Voice.instrumentCueName = $instr
766 % generate a cue music section with instrument names
767 % Parameters: \namedCueDuring NameOfQuote CueDirection CueInstrument OriginalInstrument music
768 %                 -) NameOfQuote CueDirection music are the parameters for \cueDuring
769 %                 -) CueInstrument and OriginalInstrument are the displayed instrument names
770 % typical call:
771 % \namedCueDuring #"vIQuote" #UP #"V.I" #"Sop." { R1*3 }
772 %      This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
773 %      the beginning of the cue notes and "Sop." at the end
774 namedCueDuring = #(define-music-function (parser location cuevoice direction instrcue instr cuemusic) (string? number? string? string? ly:music?)
775    #{
776      \cueDuring #$cuevoice #$direction { \tag #'cued \cueText #$instrcue $cuemusic \tag #'cued \cueText #$instr }
777 %      \tag #'uncued $cuemusic
778    #}
780 namedTransposedCueDuring = #(define-music-function (parser location cuevoice direction instrcue instr trans cuemusic) (string? number? string? string? ly:music? ly:music?)
781    #{
782      \transposedCueDuring #$cuevoice #$direction $trans { \tag #'cued \cueText #$instrcue $cuemusic \tag #'cued \cueText #$instr }
783 %      \tag #'uncued $cuemusic
784    #}
787 % set the cue instrument name and clef
788 setClefCue = #(define-music-function (parser location instr clef) 
789                                                      (string? ly:music?)
790    #{
791      \once \override Staff.Clef #'font-size = #-3 $clef
792      \set Voice.instrumentCueName = $instr
793    #} )
795 % generate a cue music section with instrument names and clef changes
796 % Parameters: \cleffedCueDuring NameOfQuote CueDirection CueInstrument CueClef OriginalInstrument OriginalClef music
797 %                 -) NameOfQuote CueDirection music are the parameters for \cueDuring
798 %                 -) CueInstrument and OriginalInstrument are the displayed instrument names
799 %                 -) CueClef and OriginalClef are the clefs for the the cue notes and the clef of the containing voice
800 % typical call:
801 % \cleffedCueDuring #"vIQuote" #UP #"V.I" #"treble" #"Basso" #"bass" { R1*3 }
802 %      This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
803 %      the beginning of the cue notes and "Basso" at the end. The clef is changed to treble at the 
804 %      beginning of the cue notes and reset to bass at the end
805 cleffedCueDuring = #(define-music-function (parser location cuevoice direction instrcue clefcue instr clefinstr cuemusic) 
806                                                         (string? number? string? ly:music? string? ly:music? ly:music?)
807    #{
808      \cueDuring #$cuevoice #$direction { \tag #'cued \setClefCue #$instrcue $clefcue $cuemusic \tag #'cued \setClefCue #$instr $clefinstr }
809 %      \tag #'uncued $cuemusic
810    #}
816 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
817 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
818 %%%%%   DYNAMICS
819 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
820 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
823 dynamicsX = #(define-music-function (parser location offset) (number?)
825     \once \override DynamicText #'X-offset = $offset
826     \once \override DynamicLineSpanner #'Y-offset = #0
829 % Move the dynamic sign inside the staff to a fixed staff-relative position 
830 % posY (where 0 means vertically starts at the middle staff line)
831 dynamicsAllInside = #(define-music-function (parser location offsetX posY)
832 (number? number?)
834   % Invalid y-extent -> hidden from skyline calculation and collisions
835   \once \override DynamicLineSpanner #'Y-extent = #(cons +0 -0.01)
836   % move by X offset and to fixed Y-position (use Y-offset of parent!)
837   \once \override DynamicText #'X-offset = $offsetX
838   \once \override DynamicText #'Y-offset =
839     $(lambda (grob)
840        (let* ((head (ly:grob-parent grob Y))
841               (offset (ly:grob-property head 'Y-offset)))
842          (- posY  offset (- 0.6))))
843   \once \override DynamicLineSpanner #'Y-offset = $posY
846 dynamicsUpInside = #(define-music-function (parser location offsetX) (number?)
847   ((ly:music-function-extract dynamicsAllInside) parser location offsetX 1.5)
850 dynamicsDownInside = #(define-music-function (parser location offsetX) (number?)
851   ((ly:music-function-extract dynamicsAllInside) parser location offsetX -3.5)
854 hairpinOffset = #(define-music-function (parser location posY) (number?)
856   \once \override DynamicLineSpanner #'Y-offset = $posY
857   \once \override DynamicLineSpanner #'Y-extent = #(cons +0 -0.01)
860 #(define ((line-break-offset before after) grob)
861   (let* ((orig (ly:grob-original grob))
862          ; All siblings if line-broken:
863          (siblings (if (ly:grob? orig) (ly:spanner-broken-into orig) '() )))
864     (if (>= (length siblings) 2)
865       ; We have been line-broken
866       (if (eq? (car (last-pair siblings)) grob)
867         ; Last sibling:
868         (ly:grob-set-property! grob 'Y-offset after)
869         ; Others get the before value:
870         (ly:grob-set-property! grob 'Y-offset before)
871       )
872     )
873   )
876 ffz = #(make-dynamic-script "ffz")
877 pf = #(make-dynamic-script "pf")
878 sempp = #(make-dynamic-script (markup #:line( #:with-dimensions '(0 . 0) 
879 '(0 . 0) #:right-align #:normal-text #:italic "sempre" #:dynamic "pp")))
880 parenf = #(make-dynamic-script (markup #:line(#:normal-text #:italic #:fontsize 2 "(" #:dynamic "f" #:normal-text #:italic #:fontsize 2 ")" )))
881 parenp = #(make-dynamic-script (markup #:line(#:normal-text #:italic #:fontsize 2 "(" #:dynamic "p" #:normal-text #:italic #:fontsize 2 ")" )))
882 pdolce = #(make-dynamic-script (markup #:line(#:dynamic "p" #:with-dimensions '(0 . 0) '(0 . 0) #:normal-text #:italic "dolce"  )))
886 cresc = #(make-music 'CrescendoEvent 'span-direction START 'crescendoSpanner 'text 'crescendoText "cresc.")
887 endcresc =  #(make-span-event 'CrescendoEvent STOP)
888 dim = #(make-music 'DecrescendoEvent 'span-direction START 'decrescendoSpanner 'text 'decrescendoText "dim.")
889 enddim =  #(make-span-event 'DecrescendoEvent STOP)
890 decresc = #(make-music 'DecrescendoEvent 'span-direction START 'decrescendoSpanner 'text 'decrescendoText "decresc.")
891 enddecresc =  #(make-span-event 'DecrescendoEvent STOP)
893 setCresc = {}
894 setDecresc = {}
895 setDim = {}
897 newOrOldClef = #(define-music-function (parser location new old ) (string? string?)
898     (if (ly:get-option 'old-clefs) #{ \clef $old #} #{ \clef $new #}) 
903 %%% Thanks to "Gilles THIBAULT" <gilles.thibault@free.fr>, there is a way
904 %   to remove also the fermata from R1-\fermataMarkup: By filtering the music
905 %   and removing the corresponding events.
906 %   Documented as an LSR snippet: http://lsr.dsi.unimi.it/LSR/Item?id=372
907 #(define (filterOneEventsMarkup event)
908 ( let ( (eventname (ly:music-property  event 'name)) )
909  (not
910   (or     ;; add here event name you do NOT want
911    (eq? eventname 'MultiMeasureTextEvent)
912    (eq? eventname 'AbsoluteDynamicEvent)
913    (eq? eventname 'TextScriptEvent)
914    (eq? eventname 'ArticulationEvent)
915    (eq? eventname 'CrescendoEvent)
916    (eq? eventname 'DecrescendoEvent)
917   )
921 filterArticulations = #(define-music-function (parser location music) (ly:music?)
922   Â (music-filter filterOneEventsMarkup music)
935 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
936 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
937 %%%%%   REST COMBINATION
938 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
939 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
943 %% REST COMBINING, TAKEN FROM http://lsr.dsi.unimi.it/LSR/Item?id=336
945 %% Usage:
946 %%   \new Staff \with {
947 %%     \override RestCollision #'positioning-done = #merge-rests-on-positioning
948 %%   } << \somevoice \\ \othervoice >>
949 %% or (globally):
950 %%   \layout {
951 %%     \context {
952 %%       \Staff
953 %%       \override RestCollision #'positioning-done = #merge-rests-on-positioning
954 %%     }
955 %%   } 
957 %% Limitations:
958 %% - only handles two voices
959 %% - does not handle multi-measure/whole-measure rests
961 #(define (rest-score r)
962   (let ((score 0)
963   (yoff (ly:grob-property-data r 'Y-offset))
964   (sp (ly:grob-property-data r 'staff-position)))
965     (if (number? yoff)
966   (set! score (+ score 2))
967   (if (eq? yoff 'calculation-in-progress)
968       (set! score (- score 3))))
969     (and (number? sp)
970    (<= 0 2 sp)
971    (set! score (+ score 2))
972    (set! score (- score (abs (- 1 sp)))))
973     score))
975 #(define (merge-rests-on-positioning grob)
976   (let* ((can-merge #f)
977    (elts (ly:grob-object grob 'elements))
978    (num-elts (and (ly:grob-array? elts)
979       (ly:grob-array-length elts)))
980    (two-voice? (= num-elts 2)))
981     (if two-voice?
982   (let* ((v1-grob (ly:grob-array-ref elts 0))
983          (v2-grob (ly:grob-array-ref elts 1))
984          (v1-rest (ly:grob-object v1-grob 'rest))
985          (v2-rest (ly:grob-object v2-grob 'rest)))
986     (and
987      (ly:grob? v1-rest)
988      (ly:grob? v2-rest)          
989      (let* ((v1-duration-log (ly:grob-property v1-rest 'duration-log))
990       (v2-duration-log (ly:grob-property v2-rest 'duration-log))
991       (v1-dot (ly:grob-object v1-rest 'dot))
992       (v2-dot (ly:grob-object v2-rest 'dot))
993       (v1-dot-count (and (ly:grob? v1-dot)
994              (ly:grob-property v1-dot 'dot-count -1)))
995       (v2-dot-count (and (ly:grob? v2-dot)
996              (ly:grob-property v2-dot 'dot-count -1))))
997        (set! can-merge
998        (and 
999         (number? v1-duration-log)
1000         (number? v2-duration-log)
1001         (= v1-duration-log v2-duration-log)
1002         (eq? v1-dot-count v2-dot-count)))
1003        (if can-merge
1004      ;; keep the rest that looks best:
1005      (let* ((keep-v1? (>= (rest-score v1-rest)
1006               (rest-score v2-rest)))
1007       (rest-to-keep (if keep-v1? v1-rest v2-rest))
1008       (dot-to-kill (if keep-v1? v2-dot v1-dot)))
1009        ;; uncomment if you're curious of which rest was chosen:
1010        ;;(ly:grob-set-property! v1-rest 'color green)
1011        ;;(ly:grob-set-property! v2-rest 'color blue)
1012        (ly:grob-suicide! (if keep-v1? v2-rest v1-rest))
1013        (if (ly:grob? dot-to-kill)
1014            (ly:grob-suicide! dot-to-kill))
1015        (ly:grob-set-property! rest-to-keep 'direction 0)
1016        (ly:rest::y-offset-callback rest-to-keep)))))))
1017     (if can-merge
1018   #t
1019   (ly:rest-collision::calc-positioning-done grob))))
1025 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1026 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1027 %%%%%   TABLE OF CONTENTS
1028 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1029 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1032 contentsTitle = "Inhalt / Contents"
1034 \paper {
1035   tocTitleMarkup = \markup \fill-line{ 
1036     \null 
1037     \column {
1038       \override #(cons 'line-width (* 7 cm)) 
1039       \line{ \fill-line {\piece-title {\contentsTitle} \null }}
1040       \hspace #1
1041     }
1042     \null 
1043   }
1044   tocItemMarkup = \markup \fill-line { 
1045     \null 
1046     \column {
1047       \override #(cons 'line-width (* 7 cm )) 
1048       \line { \fill-line{\fromproperty #'toc:text \fromproperty #'toc:page }}
1049     }
1050     \null
1051   }
1055 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1056 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1057 %%%%%   TITLE PAGE / HEADER
1058 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1059 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1061 #(define-markup-command (when-property layout props symbol markp) (symbol? markup?)
1062   (if (chain-assoc-get symbol props)
1063       (interpret-markup layout props markp)
1064       (ly:make-stencil '()  '(1 . -1) '(1 . -1))))
1066 #(define-markup-command (vspace layout props amount) (number?)
1067   "This produces a invisible object taking vertical space."
1068   (let ((amount (* amount 3.0)))
1069     (if (> amount 0)
1070         (ly:make-stencil "" (cons -1 1) (cons 0 amount))
1071         (ly:make-stencil "" (cons -1 1) (cons amount amount)))))
1075 titlePageMarkup = \markup \abs-fontsize #10 \when-property #'header:title \column {
1076     \vspace #4
1077     \fill-line { \fontsize #8 \fromproperty #'header:composer }
1078     \vspace #1
1079     \fill-line { \fontsize #8 \fromproperty #'header:poet }
1080     \vspace #4
1081     \fill-line { \fontsize #10 \bold \fromproperty #'header:titlepagetitle }
1082     \vspace #1
1083     \fontsize #2 \when-property #'header:titlepagesubtitle { 
1084       \fill-line { \fromproperty #'header:titlepagesubtitle }
1085       \vspace #1
1086     }
1087     \fill-line { \postscript #"-20 0 moveto 40 0 rlineto stroke" }
1088     \vspace #8
1089     \fill-line { \fontsize #5 \fromproperty #'header:ensemble }
1090     \vspace #0.02
1091     \fill-line { \fontsize #2 \fromproperty #'header:instruments }
1092     \vspace #9
1093     \fill-line { \fontsize #5 \fromproperty #'header:date }
1094     \vspace #1
1095     \fill-line { \fontsize #5 \fromproperty #'header:scoretype }
1096     \vspace #8
1097     \fontsize #2 \when-property #'header:enteredby { 
1098       \fill-line { "Herausgegeben von: / Edited by:"}
1099       \vspace #0.
1100       \fill-line { \fromproperty #'header:enteredby }
1101     }
1102     \fill-line {
1103       \when-property #'header:arrangement \column {
1104         \vspace #8
1105         \fill-line { \fontsize #3 \fromproperty #'header:arrangement }
1106       }
1107     }
1110 titleHeaderMarkup = \markup {
1111   \override #'(baseline-skip . 3.5)
1112   \column {
1113     \override #'(baseline-skip . 3.5)
1114     \column {
1115       \huge \larger \bold
1116       \fill-line {
1117         \larger \fromproperty #'header:title
1118       }
1119       \fill-line {
1120         \large \smaller \bold
1121         \larger \fromproperty #'header:subtitle
1122       }
1123       \fill-line {
1124         \smaller \bold
1125         \fromproperty #'header:subsubtitle
1126       }
1127       \fill-line {
1128         { \large \bold \fromproperty #'header:instrument }
1129       }
1130       \fill-line {
1131         \fromproperty #'header:poet
1132         \fromproperty #'header:composer
1133       }
1134       \fill-line {
1135         \fromproperty #'header:meter
1136         \fromproperty #'header:arranger
1137       }
1138     }
1139   }
1142 titleScoreMarkup = \markup \piece-title \fromproperty #'header:piece
1144 \paper {
1145   scoreTitleMarkup = \titleScoreMarkup
1146   bookTitleMarkup = \titleHeaderMarkup
1151 %%%%%%%%%%%%%% headers and footers %%%%%%%%%%%%%%%%%%%%%%%%%%
1153 #(define (first-score-page layout props arg)
1154   (let* ((label 'first-score-page)
1155          (table (ly:output-def-lookup layout 'label-page-table))
1156          (label-page (and (list? table) (assoc label table)))
1157          (page-number (and label-page (cdr label-page)))
1158         )
1159     (if (eq? (chain-assoc-get 'page:page-number props -1) page-number)
1160       (interpret-markup layout props arg)
1161       empty-stencil)))
1163 #(define no-header-table '())
1164 thisPageNoHeader = #(define-music-function (parser location) ()
1165   (let* ((label (gensym "header")))
1166     (set! no-header-table (cons label no-header-table))
1167     (make-music 'Music 
1168       'page-marker #t
1169       'page-label label)))
1172 % TODO: Use the no-header-table!
1173 #(define (is-header-page layout props arg)
1174   (let* ((page-number (chain-assoc-get 'page:page-number props -1))
1175         )
1176     ;(if (and (> page-number 2) (!= page-number 7))
1177     (if (> page-number 1)
1178       (interpret-markup layout props arg)
1179       empty-stencil)))
1181 #(define no-footer-table '())
1182 thisPageNoFooter = #(define-music-function (parser location) ()
1183   (let* ((label (gensym "footer")))
1184     (set! no-footer-table (cons label no-footer-table))
1185     (make-music 'Music 
1186       'page-marker #t
1187       'page-label label)))
1189 % TODO: Use the no-footer-table!
1190 #(define (is-footer-page layout props arg)
1191   (let* ((page-number (chain-assoc-get 'page:page-number props -1))
1192          (label 'first-score-page)
1193          (table (ly:output-def-lookup layout 'label-page-table))
1194          (label-page (and (list? table) (assoc label table)))
1195          ;(page-number (and label-page (cdr label-page)))
1196         )
1197     (if (and (> page-number 1))
1198       (interpret-markup layout props arg)
1199       empty-stencil)))
1202 #(define copyright-footer-table '())
1203 thisPageCopyrightFooter = #(define-music-function (parser location) ()
1204   (let* ((label (gensym "copyrightfooter")))
1205     (set! copyright-footer-table (cons label copyright-footer-table))
1206     (make-music 'Music 
1207       'page-marker #t
1208       'page-label label)))
1210 #(define copyright-pg 1)
1211 #(define (set-copyright-page page)
1212   (set! copyright-pg page)
1215 % TODO: Use the copyright-footer-table!
1216 #(define (copyright-page layout props arg)
1217     (if (= (chain-assoc-get 'page:page-number props -1) copyright-pg)
1218       (interpret-markup layout props arg)
1219       empty-stencil))
1222 \paper {
1223   oddHeaderMarkup = \markup \fill-line {
1224     %% force the header to take some space, otherwise the
1225     %% page layout becomes a complete mess.
1226     " "
1227     \on-the-fly #is-header-page \fromproperty #'header:title
1228     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1229   }
1230   evenHeaderMarkup = \markup \fill-line {
1231     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1232     \on-the-fly #is-header-page \fromproperty #'header:composer
1233     " "
1234   }
1236   oddFooterMarkup = \markup {
1237     \column {
1238       \fill-line {
1239         %% publisher header field only on title page.
1240         \on-the-fly #first-page \fromproperty #'header:publisher
1241       }
1242       \fill-line {
1243         %% copyright on the first real score page
1244         \on-the-fly #copyright-page \fromproperty #'header:copyright
1245         \on-the-fly #copyright-page \null
1246       }
1247       \fill-line {
1248         %% All other pages get the number of the edition centered
1249         \on-the-fly #is-footer-page \fromproperty #'header:scorenumber
1250       }
1251     }
1252   }
1266 % Interpret the given markup with the header fields added to the props. 
1267 % This way, one can re-use the same functions (using fromproperty 
1268 % #'header:field) in the header block and as top-level markup.
1270 % This function is originally copied from mark-up-title (file scm/titling.scm), 
1271 % which is lilypond's internal function to handle the title markups. I needed 
1272 % to replace the scopes and manually add the $defaultheader (which is internally 
1273 % done in paper-book.cc before calling mark-up-title. Also, I don't extract the 
1274 % markup from the header block, but use the given markup.
1276 % I'm not sure if I really need the page properties in props, too... But I 
1277 % suppose it does not hurt, either.
1278 #(define-markup-command (markupWithHeader layout props markup) (markup?)
1279   "Interpret the given markup with the header fields added to the props. 
1280    This way, one can re-use the same functions (using fromproperty 
1281    #'header:field) in the header block and as top-level markup."
1282   (let* (
1283       ; TODO: If we are inside a score, add the score's local header block, too!
1284       ; Currently, I only use the global header block, stored in $defaultheader
1285       (scopes (list $defaultheader))
1286       (alists (map ly:module->alist scopes))
1287   
1288       (prefixed-alist
1289         (map (lambda (alist)
1290           (map (lambda (entry)
1291             (cons
1292               (string->symbol (string-append "header:" (symbol->string (car entry))))
1293               (cdr entry)))
1294             alist))
1295           alists))
1296       (props (append prefixed-alist
1297               props
1298               (layout-extract-page-properties layout)))
1299     )
1300     (interpret-markup layout props markup)
1301   )
1309 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1310 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1311 %%%%%   Equally spacing multiple columns (e.g. for translations)
1312 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1313 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1315 % Credits: Nicolas Sceaux on the lilypond-user mailinglist
1316 #(define-markup-command (columns layout props args) (markup-list?)
1317    (let ((line-width (/ (chain-assoc-get 'line-width props
1318                          (ly:output-def-lookup layout 'line-width))
1319                         (max (length args) 1))))
1320      (interpret-markup layout props
1321        (make-line-markup (map (lambda (line)
1322                                 (markup #:pad-to-box `(0 . ,line-width) '(0 . 0)
1323                                   #:override `(line-width . ,line-width)
1324                                   line))
1325                                args)))))
1331 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1332 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1333 %%%%%   SCORE (HEADER / LAYOUT) SETTINGS
1334 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1335 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1337 \paper {
1338 %   left-margin = 2\cm
1339 %   right-margin = 2\cm
1340 %   line-width = 17\cm
1341 %   bottom-margin = 1\cm
1342 %   top-margin = 1\cm
1343 %   after-title-space = 0.5\cm
1344   ragged-right = ##f
1345   ragged-last = ##f
1346   ragged-bottom = ##f
1347   ragged-last-bottom = ##f
1349 \layout {
1350   \context {
1351     \ChoirStaff 
1352     % If only one non-empty staff in a system exists, still print the backet
1353     \override SystemStartBracket #'collapse-height = #1
1354     \consists "Instrument_name_engraver"
1355   }
1356   \context {
1357     \StaffGroup
1358     % If only one non-empty staff in a system exists, still print the backet
1359     \override SystemStartBracket #'collapse-height = #1
1360     \consists "Instrument_name_engraver"
1361   }
1362   \context {
1363     \GrandStaff
1364     \override SystemStartBracket #'collapse-height = #1
1365     \consists "Instrument_name_engraver"
1366   }
1367   \context {
1368     \PianoStaff
1369 %     \override VerticalAxisGroup #'keep-fixed-while-stretching = ##t
1370   }
1371   \context {
1372     \FiguredBass
1373 %     \override VerticalAxisGroup #'keep-fixed-while-stretching = ##t
1374     \override VerticalAxisGroup #'minimum-Y-extent  = #'(0 . 1)
1375     \override VerticalAxisGroup #'padding = #0
1376   }
1377   \context {
1378     \Score
1379     % Force multi-measure rests to be written as one span
1380     \override MultiMeasureRest #'expand-limit = #3
1381     skipBars = ##t
1382     autoBeaming = ##f
1383 %     hairpinToBarline = ##f
1384     \override BarNumber #'break-visibility = #end-of-line-invisible
1385     \override CombineTextScript #'avoid-slur = #'outside
1386     barNumberVisibility = #(every-nth-bar-number-visible 5)
1387     \override DynamicTextSpanner #'dash-period = #-1.0
1388     \override InstrumentSwitch #'font-size = #-1
1390     % Rest collision
1391     \override RestCollision #'positioning-done = #merge-rests-on-positioning
1392     % Auto-Accidentals: Use modern-cautionary style...
1393     extraNatural = ##f
1394     autoAccidentals = #`(Staff  ,(make-accidental-rule 'same-octave 0))
1395     autoCautionaries = #`(Staff ,(make-accidental-rule 'any-octave 0)
1396                                 ,(make-accidental-rule 'same-octave 1))
1397     printKeyCancellation = ##t
1398   }
1399   \context {
1400     \RemoveEmptyStaffContext 
1401   }
1402   \context {
1403     \Lyrics
1404     \override VerticalAxisGroup #'minimum-Y-extent = #'(0.5 . 0.5)
1405   }
1410 \layout {
1411   \context {
1412     \type "Engraver_group"
1413     \name Dynamics
1414     % So that \cresc works, for example.
1415     \alias Voice
1416     \consists "Output_property_engraver"
1417     
1418     \override VerticalAxisGroup #'minimum-Y-extent = #'(-1 . 1)
1419     pedalSustainStrings = #'("Ped." "*Ped." "*")
1420     pedalUnaCordaStrings = #'("una corda" "" "tre corde")
1421     
1422     \consists "Piano_pedal_engraver"
1423     \consists "Script_engraver"
1424     \consists "Dynamic_engraver"
1425     \consists "Text_engraver"
1426     
1427     \override TextScript #'font-size = #2
1428     \override TextScript #'font-shape = #'italic
1429     \override DynamicText #'extra-offset = #'(0 . 2.5)
1430     \override Hairpin #'extra-offset = #'(0 . 2.5)
1431     
1432     \consists "Skip_event_swallow_translator"
1433     
1434     \consists "Axis_group_engraver"
1435   }
1436   \context {
1437     \PianoStaff
1438     \accepts Dynamics
1439 %     \override VerticalAlignment #'forced-distance = #7
1440   }