Allow black text on colored title pages (enable for chamber music by default)
[orchestrallily.git] / orchestrallily.ily
blobc10fd48ce99ba2b7820e8947f102fc6e5dbfaf8a
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 % GLOBAL OPTIONS
24 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26 % Use relative include pathes!
27 #(ly:set-option 'relative-includes #t)
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 %%%%%   SCORE STRUCTURE AND AUTOMATIC GENERATION
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 % Helper functions
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 % Helper function to filter all non-null entries
44 #(define (not-null? x) (not (null? x)))
46 % Helper function to extract a given variable, built from [Piece][Instrument]Identifier
47 #(define (namedPieceInstrObject piece instr name)
48   (let* (
49          (fullname  (string->symbol (string-append piece instr name)))
50          (instrname (string->symbol (string-append instr name)))
51          (piecename (string->symbol (string-append piece name)))
52          (fallback  (string->symbol name))
53         )
54     (cond
55       ((defined? fullname) (primitive-eval fullname))
56       ((defined? instrname) (primitive-eval instrname))
57       ((defined? piecename) (primitive-eval piecename))
58       ((defined? fallback) (primitive-eval fallback))
59       (else '())
60     )
61   )
64 %% Print text as a justified paragraph, taken from the lilypond Notation Reference
65 #(define-markup-list-command (paragraph layout props args) (markup-list?)
66    (let ((indent (chain-assoc-get 'par-indent props 2)))
67      (interpret-markup-list layout props
68        (make-justified-lines-markup-list (cons (make-hspace-markup indent)
69                                                args)))))
71 conditionalBreak = #(define-music-function (parser location) ()
72    #{ \tag #'instrumental-score \pageBreak #}
75 #(define (oly:piece-title-markup title) (markup #:column (#:line (#:fontsize #'3 #:bold title))) )
77 #(define-markup-command (piece-title layout props title) (markup?)
78      (interpret-markup layout props (oly:piece-title-markup title))
81 #(define (oly:generate_object_name piece instr obj )
82   (if (and (string? piece) (string? instr) (string? obj))
83     (string-append piece instr obj)
84     #f
85   )
87 #(define (oly:generate_staff_name piece instr) (oly:generate_object_name piece instr "St"))
89 #(define (set-context-property context property value)
90   (set! (ly:music-property context property) value)
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95 % Score structure and voice types
96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98 #(define oly:LiedScoreStructure '(
99   ("SoloScore" "SimultaneousMusic" ("Singstimme"))
100   ("Pfe" "PianoStaff" ("PfeI" "PfeII"))
101   ;("PfeI" "ParallelVoicesStaff" ("OIa" "OIb"))
102   ;("PfeII" "ParallelVoicesStaff" ("OIIa" "OIIb"))
103   ("FullScore" "SimultaneousMusic" ("Singstimme" "Pfe"))
104   ("VocalScore" "SimultaneousMusic" ("Singstimme" "Pfe"))
107 #(define oly:fullOrchestraScoreStructure '(
108 ; Part-combined staves for full score
109   ("Fl" "PartCombinedStaff" ("FlI" "FlII"))
110   ("Ob" "PartCombinedStaff" ("ObI" "ObII"))
111   ("Cl" "PartCombinedStaff" ("ClI" "ClII"))
112   ("Fag" "PartCombinedStaff" ("FagI" "FagII"))
113   ("Wd" "StaffGroup" ("Fl" "Ob" "Cl" "Fag" "CFag"))
115   ("Cor" "PartCombinedStaff" ("CorI" "CorII"))
116   ("Trb" "PartCombinedStaff" ("TrbI" "TrbII"))
117   ("Tbe" "PartCombinedStaff" ("TbeI" "TbeII"))
118   ("Br" "StaffGroup" ("Cor" "Trb" "Tbe" "Tba"))
120 ; long score; no part-combined staves, but GrandStaves instead
121   ("FlLong" "GrandStaff" ("FlI" "FlII"))
122   ("ObLong" "GrandStaff" ("ObI" "ObII"))
123   ("ClLong" "GrandStaff" ("ClI" "ClII"))
124   ("FagLong" "GrandStaff" ("FagI" "FagII"))
125   ("WdLong" "StaffGroup" ("FlLong" "ObLong" "ClLong" "FagLong" "CFag"))
127   ("CorLong" "GrandStaff" ("CorI" "CorII"))
128   ("TrbLong" "GrandStaff" ("TrbI" "TrbII"))
129   ("TbeLong" "GrandStaff" ("TbeI" "TbeII" "TbeIII"))
130   ("BrLong" "StaffGroup" ("CorLong" "TrbLong" "TbeLong" "Tba"))
132 ; Percussion
133   ("Perc" "StaffGroup" ("Tim"))
135 ; Strings, they are the same in long and short full score
136   ("VV" "GrandStaff" ("VI" "VII"))
137   ("Str" "StaffGroup" ("VV" "Va"))
138   ("VceB" "StaffGroup" ("Vc" "Cb" "VcB"))
139   ("FullStr" "StaffGroup" ("VV" "Va" "Vc" "Cb" "VcB"))
141 ; Choral score
142   ("Solo" "SimultaneousMusic" ("SSolo" "ASolo" "TSolo" "BSolo"))
143   ("Ch" "ChoirStaff" ("S" "A" "T" "B"))
144   ("ChoralScore" "SimultaneousMusic" ("Ch"))
145   ("SoloScore" "SimultaneousMusic" ("Solo"))
146   ("SoloChoirScore" "SimultaneousMusic" ("Solo" "Ch"))
148 ; Organ score (inkl. Figured bass)
149   ("BCFb" "FiguredBass" ())
150   ("FiguredBass" "FiguredBass" ())
151   ;("Organ" "SimultaneousMusic" ("BCFb" "O"))
152   ("Continuo" "ParallelVoicesStaff" ("BCFb" "BC" "FiguredBass"))
153   ("RealizedContinuo" "PianoStaff" ("BCRealization" "Continuo"))
154   ("BassGroup" "StaffGroup" ("Continuo"))
156   ("P" "PianoStaff" ("PI" "PII"))
157   ("O" "PianoStaff" ("OI" "OII"))
158   ("OI" "ParallelVoicesStaff" ("OIa" "OIb"))
159   ("OII" "ParallelVoicesStaff" ("OIIa" "OIIb"))
160   ("Organ" "SimultaneousMusic" ("OGroup" "RealizedContinuo"))
161   ;("BassGroup" "ParallelVoicesStaff" ("Organ" "O" "BC" "VceB"))
163 ; Full Scores
164   ("FullScore" "SimultaneousMusic" ("Wd" "Br" "Perc" "Str" "SoloChoirScore" "O" "Continuo"))
165   ("LongScore" "SimultaneousMusic" ("WdLong" "BrLong" "Perc" "Str" "SoloChoirScore" "O" "Continuo"))
166   ("OriginalScore" "SimultaneousMusic" ("BrLong" "WdLong" "Perc" "Str" "SoloChoirScore" "O" "BassGroup"))
168 ; Piano reduction
169   ;("Piano" "SimultaneousMusic" ("Organ"))
170   ("OrganScore" "SimultaneousMusic" ("ChoralScore" "O"))
171   ("VocalScore" "SimultaneousMusic" ("ChoralScore" "P"))
172   ("Particell"  "SimultaneousMusic" ("ChoralScore" "BassGroup"))
174 ; Full scores: Orchestral score and long score including organ
175   ("ChStrQ" "SimultaneousMusic" ("Str" "Ch" "VceB"))
177 #(define oly:orchestral_score_structure oly:fullOrchestraScoreStructure)
179 #(define (oly:set_score_structure struct)
180   (if (list? struct)
181     (set! oly:orchestral_score_structure struct)
182     (ly:warning (_ "oly:set_score_structure needs an association list as argument!"))
183   )
186 #(define (oly:modify_score_structure entry)
187   (if (list? entry)
188     (set! oly:orchestral_score_structure (assoc-set! oly:orchestral_score_structure  (car entry) (cdr entry)))
189     (ly:warning (_ "oly:modify_score_structure expects a list (\"key\" \"type\" '(children)) as argument!"))))
191 #(define (oly:remove_from_score_structure entry)
192   (if (list? entry)
193     (map oly:remove_from_score_structure entry)
194     (set! oly:orchestral_score_structure (assoc-remove! oly:orchestral_score_structure  entry))))
196 orchestralScoreStructure = #(define-music-function (parser location structure) (list?)
197   (oly:set_score_structure structure)
198   (make-music 'Music 'void #t)
201 #(define oly:voice_types '())
203 #(define (oly:set_voice_types types)
204   (if (list? types)
205     (set! oly:voice_types types)
206     (ly:warning (_ "oly:set_voice_types needs an association list as argument!"))
207   )
210 orchestralVoiceTypes = #(define-music-function (parser location types) (list?)
211   (oly:set_voice_types types)
212   (make-music 'Music 'void #t)
216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217 % Automatic staff and group generation
218 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
220 % Retrieve all music definitions for the given
221 #(define (oly:get_music_object piece instrument)
222   (namedPieceInstrObject piece instrument "Music")
224 #(define (oly:get_music_objects piece instruments)
225   (filter not-null? (map (lambda (i) (oly:get_music_object piece i)) instruments))
228 % Given a property name and the extensions, either generate the pair to set
229 % the property or an empty list, if no pre-defined variable could be found
230 #(define (oly:generate_property_pair prop piece instr type)
231   (let* ((val (namedPieceInstrObject piece instr type)))
232     (if (not-null? val) (list 'assign prop val) '() )
233   )
236 #(define (oly:staff_type type)
237   (cond
238     ((string? type) (string->symbol type))
239     ((symbol? type) type)
240     (else 'Staff)
241   )
244 #(define (oly:extractPitch music)
245   (let* (
246          (elems  (if (ly:music? music) (ly:music-property music 'elements)))
247          (note   (if (pair? elems) (car elems)))
248          (pitch  (if (ly:music? note) (ly:music-property note 'pitch)))
249         )
250     (if (and (not-null? music) (not (ly:pitch? pitch)))
251       (ly:warning "Unable to interpret as a pitch!")
252     )
253     pitch
254   )
257 #(define (oly:extractTranspositionPitch piece name)
258   (let* (
259          (trpFromPitch (oly:extractPitch (namedPieceInstrObject piece name "TransposeFrom")))
260          (trpToPitch   (oly:extractPitch (namedPieceInstrObject piece name "TransposeTo")))
261         )
262     (if (ly:pitch? trpFromPitch)
263       (if (ly:pitch? trpToPitch)
264         ; Both pitches
265         (ly:pitch-diff trpFromPitch trpToPitch)
266         (ly:pitch-diff trpFromPitch (ly:make-pitch 0 0 0))
267       )
268       (if (ly:pitch? trpToPitch)
269         (ly:pitch-diff (ly:make-pitch 0 0 0) trpToPitch)
270         #f
271       )
272     )
273   )
276 #(define (oly:musiccontent_for_voice parser piece name music additional)
277   (let* ((musiccontent additional))
279     ; Append the settings, key and clef (if defined)
280     (map
281       (lambda (type)
282         (let* ((object (namedPieceInstrObject piece name type)))
283           (if (ly:music? object)
284             (set! musiccontent (append musiccontent (list (ly:music-deep-copy object))))
285             (if (not-null? object) (ly:warning (_ "Wrong type (no ly:music) for ~S for instrument ~S in piece ~S") type name piece))
286           )
287         )
288       )
289       ; TODO: Does the "Tempo" work here???
290       '("Settings" "Key" "Clef" "TimeSignature" "ExtraSettings";"Tempo"
291       )
292     )
294     (if (ly:music? music)
295       (begin
296         (set! musiccontent (make-simultaneous-music (append musiccontent (list music))))
297         ;(ly:message "Generating staff for ~a" name)
298         (let* ((trpPitch (oly:extractTranspositionPitch piece name)))
299           (if (ly:pitch? trpPitch)
300             (set! musiccontent (ly:music-transpose musiccontent trpPitch))
301           )
302         )
303         musiccontent
304       )
305       ; For empty music, return empty
306       '()
307     )
308   )
311 #(define (oly:lyrics_create_single_context parser piece name voicename lyricsid)
312   ; If we have lyrics, create a lyrics context containing LyricCombineMusic
313   ; and add that as second element to the staff's elements list...
314   (let* ((id (string-append "Lyrics" lyricsid))
315          (lyrics (namedPieceInstrObject piece name id)))
316     (if (ly:music? lyrics)
317       (context-spec-music (make-music 'LyricCombineMusic
318                                       'element lyrics
319                                       'associated-context voicename)
320                           'Lyrics (oly:generate_object_name piece name id))
321       '())
322   )
325 #(define (oly:lyrics_create_contexts parser piece name voicename)
326   (filter not-null?
327     (map (lambda (str)
328                  (oly:lyrics_create_single_context parser piece name voicename str))
329          (list "" "I" "II" "III"  "IV" "V" "VI"))))
331 #(define (oly:voice_handler_internal parser piece name type music)
332   (if (ly:music? music)
333     (let* (
334            (voicename    (oly:generate_object_name piece name "Voice" ))
335            (lyrics       (oly:lyrics_create_contexts parser piece name voicename))
336            (additional   (if (not-null? lyrics) (list dynamicUp) '()))
337            (musiccontent (oly:musiccontent_for_voice parser piece name music additional))
338            (voicetype    (oly:staff_type type))
339            (voice        (context-spec-music musiccontent voicetype voicename))
340           )
341       (cons voice lyrics)
342     )
343     ; For empty music, return empty
344     '()
345   )
348 #(define (oly:voice_handler parser piece name type)
349   (oly:voice_handler_internal parser piece name type (oly:get_music_object piece name)))
351 #(define (oly:staff_handler_internal parser piece name type voices)
352   (if (not-null? voices)
353     (let* (
354            (staffname  (oly:generate_staff_name piece name))
355            (stafftype  (oly:staff_type type))
356            (staff      (make-simultaneous-music voices))
357            (propops    (oly:staff_handler_properties piece name))
358           )
359       (case stafftype
360         ((SimultaneousMusic ParallelMusic) #f)
361         (else (set! staff (context-spec-music staff stafftype staffname)))
362       )
363       (if (not-null? propops)
364         (set! (ly:music-property staff 'property-operations) propops)
365       )
366       staff
367     )
368     ; For empty music, return empty
369     '()
370   )
373 #(define (oly:staff_handler parser piece name type children)
374   (let* ((c (if (not-null? children) children (list name)))
375          (voices (apply append (map (lambda (v) (oly:create_voice parser piece v)) c)) )
376         )
377     (if (not-null? voices)
378       (oly:staff_handler_internal parser piece name type voices)
379       '()
380     )
381   )
384 #(define (oly:devnull_handler parser piece name type children)
385   (oly:voice_handler parser piece name type)
388 #(define (oly:parallel_voices_staff_handler parser piece name type children)
389   (let* (
390          (voices (map (lambda (i) (oly:create_voice parser piece i)) children))
391          ; get the list of non-empty voices and flatten it!
392          (nonemptyvoices (apply append (filter not-null? voices)))
393         )
394     (if (not-null? nonemptyvoices)
395       (oly:staff_handler_internal parser piece name "Staff" nonemptyvoices)
396       '()
397     )
398   )
401 #(define (oly:part_combined_staff_handler parser piece name type children)
402   (let* ((rawmusic (map (lambda (c) (oly:musiccontent_for_voice parser piece name (oly:get_music_object piece c) '())) children))
403          (music (filter not-null? rawmusic)))
404   (cond
405       ((and (pair? music) (ly:music? (car music)) (not-null? (cdr music)) (ly:music? (cadr music)))
406           ;(ly:message "Part-combine with two music expressions")
407           (oly:staff_handler_internal parser piece name "Staff" (list (make-part-combine-music parser music))))
408       ((null? music)
409           ;;(ly:warning "Part-combine without any music expressions")
410           '())
411       ; exactly one is a music expression, simply use that by joining
412       ((list? music)
413           ;;(ly:message "Part-combine with only one music expressions")
414           (oly:staff_handler_internal parser piece name "Staff" (list (apply append music))))
415       (else
416           ;(ly:message "make_part_combined_staff: ~S ~S ~a" piece instr instruments)
417           '() )
418     )
419   )
422 % Generate the properties for the staff for piece and instr. Typically, these
423 % are the instrument name and the short instrument name (if defined).
424 % return a (possibly empty) list of all assignments.
425 #(define (oly:staff_handler_properties piece instr)
426   (let* (
427          (mapping '(
428               (instrumentName . "InstrumentName")
429               (shortInstrumentName . "ShortInstrumentName")
430               (midiInstrument . "MidiInstrument")
431             ))
432          (assignments (map
433              (lambda (pr)
434                  (oly:generate_property_pair (car pr) piece instr (cdr pr))
435              )
436              mapping))
437          (props (filter not-null? assignments))
438         )
439     props
440   )
443 % Figured bass is a special case, as it can be voice- or staff-type. When
444 % given as a staff type, simply call the voice handler, instead
446 #(define (oly:figured_bass_staff_handler parser piece name type children)
447   (let* ((c (if (not-null? children) children (list name)))
448          (voice  (oly:voice_handler parser piece (car c) type)))
449     (if (pair? voice) (car voice) ())
450   )
453 #(define (flatten lst)
454   (define (f remaining result)
455     (cond
456       ((null? remaining) result)
457       ((pair? (car remaining)) (f (cdr remaining) (f (car remaining) result)))
458       (else (f (cdr remaining) (cons (car remaining) result)))))
459   (reverse! (f lst '())))
461 #(define (oly:staff_group_handler parser piece name type children)
462   (let* (
463          (staves (flatten (map (lambda (i) (oly:create_staff_or_group parser piece i)) children)))
464          (nonemptystaves (filter not-null? staves))
465         )
466     (if (not-null? nonemptystaves)
467       (let* (
468              (musicexpr (if (= 1 (length nonemptystaves))
469                           (car nonemptystaves)
470                           (make-simultaneous-music nonemptystaves)))
471              (groupname (oly:generate_staff_name piece name))
472              (grouptype (oly:staff_type type))
473              (group     musicexpr)
474              (propops   (oly:staff_handler_properties piece name))
475             )
476         (case grouptype
477           ((SimultaneousMusic ParallelMusic) #f)
478           (else (set! group (context-spec-music group grouptype groupname)))
479         )
480         (if (pair? propops)
481           (set! (ly:music-property group 'property-operations) propops))
482         group
483       )
484       ; Return empty list if no staves are generated
485       '()
486     )
487   )
490 #(define (oly:create_voice parser piece name)
491   (let* ( (voice (namedPieceInstrObject piece name "Voice"))
492           (type (assoc-ref oly:voice_types name)) )
493     (if (not-null? voice)
494       ; Explicit voice variable, use that
495       voice
497       (if (not type)
498         ; No entry in structure found => simple voice
499         (oly:voice_handler parser piece name "Voice")
500         ; Entry found in structure => use the handler for the given type
501         (let* (
502                (voicetype (car type))
503                (handler (assoc-ref oly:voice_handlers voicetype))
504               )
505           (if handler
506             ((primitive-eval handler) parser piece name voicetype)
507             (begin
508               (ly:warning "No handler found for voice type ~a, using default voice handler" voicetype)
509               (oly:voice_handler parser piece name voicetype)
510             )
511           )
512         )
513       )
514     )
515   )
518 #(define (oly:create_staff_or_group parser piece name)
519   (let* ( (staff (namedPieceInstrObject piece name "Staff"))
520           (type_from_structure (assoc-ref oly:orchestral_score_structure name)) )
521     ;(if (not-null? staff)
522     ;  (ly:message "Found staff variable for instrument ~a in piece ~a"  instr piece)
523     ;  (ly:message "Staff variable for instrument ~a in piece ~a NOT FOUND"  instr piece)
524     ;)
525     (if (not-null? staff)
526       ; Explicit staff variable, use that
527       staff
529       (if (not (list? type_from_structure))
530         ; No entry in structure found => simple staff
531         (oly:staff_handler parser piece name "Staff" '())
533         ; Entry found in structure => use the handler for the given type
534         (let* ((type (car type_from_structure))
535                (handler (assoc-ref oly:staff_handlers type))
536                (children (cadr type_from_structure))
537               )
538           (if handler
539             ((primitive-eval handler) parser piece name type children)
540             (begin
541               (ly:warning "No handler found for staff type ~a, using default staff handler" type)
542               (oly:staff_handler parser piece name type children)
543             )
544           )
545         )
546       )
547     )
548   )
551 #(define (oly:dynamics_handler parser piece name type children)
552   (oly:voice_handler parser piece name type)
556 #(define oly:staff_handlers
557   (list
558     ; staff group types
559     '("GrandStaff" . oly:staff_group_handler )
560     '("PianoStaff" . oly:staff_group_handler )
561     '("ChoirStaff" . oly:staff_group_handler )
562     '("StaffGroup" . oly:staff_group_handler )
563     '("InnerChoirStaff" . oly:staff_group_handler )
564     '("InnerStaffGroup" . oly:staff_group_handler )
565     '("ParallelMusic" . oly:staff_group_handler )
566     '("SimultaneousMusic" . oly:staff_group_handler )
567     ; staff types
568     '("Staff" . oly:staff_handler )
569     '("DrumStaff" . oly:staff_handler )
570     '("RhythmicStaff" . oly:staff_handler )
571     '("TabStaff" . oly:staff_handler )
572     '("GregorianTranscriptionStaff" . oly:staff_handler )
573     '("MensuralStaff" . oly:staff_handler )
574     '("VaticanaStaff" . oly:staff_handler )
575     ; staves with multiple voices
576     '("PartCombinedStaff" . oly:part_combined_staff_handler )
577     '("ParallelVoicesStaff" . oly:parallel_voices_staff_handler )
578     ; special cases: Figured bass can be staff or voice type!
579     '("FiguredBass" . oly:figured_bass_staff_handler )
580     ; Devnull is like a staff, only that it doesn't craete output
581     '("Devnull" . oly:devnull_handler )
582     '("Dynamics" . oly:dynamics_handler )
583   )
586 #(define oly:voice_handlers
587   (list
588     ; voice types
589     '("Voice" . oly:voice_handler )
590     '("CueVoice" . oly:voice_handler )
591     '("DrumVoice" . oly:voice_handler )
592     '("FiguredBass" . oly:voice_handler )
593     '("GregorianTranscriptionVoice" . oly:voice_handler )
594     '("NoteNames" . oly:voice_handler )
595     '("TabVoice" . oly:voice_handler )
596     '("VaticanaVoice" . oly:voice_handler )
597   )
601 #(define (oly:register_staff_type_handler type func)
602 ;  (ly:message "Registering staff handler ~a for type ~a" func type)
603   (set! oly:staff_handlers (assoc-set! oly:staff_handlers type func))
606 #(define (oly:register_voice_type_handler type func)
607 ;  (ly:message "Registering voice type handler ~a for type ~a" func type)
608   (set! oly:voice_handlers (assoc-set! oly:voice_handlers type func))
611 % handlers for deprecated API
612 #(oly:register_staff_type_handler 'StaffGroup 'oly:staff_group_handler)
613 #(oly:register_staff_type_handler 'GrandStaff 'oly:staff_group_handler)
614 #(oly:register_staff_type_handler 'PianoStaff 'oly:staff_group_handler)
615 #(oly:register_staff_type_handler 'ChoirStaff 'oly:staff_group_handler)
616 #(oly:register_staff_type_handler 'Staff 'oly:staff_handler )
617 #(oly:register_staff_type_handler 'ParallelMusic 'oly:staff_group_handler)
618 #(oly:register_staff_type_handler 'SimultaneousMusic 'oly:staff_group_handler)
619 #(oly:register_staff_type_handler #t 'oly:part_combined_staff_handler )
620 #(oly:register_staff_type_handler #f 'oly:parallel_voices_staff_handler )
624 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
625 % Automatic score generation
626 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
628 #(define oly:score_handler add-score)
629 #(define oly:music_handler add-music)
630 #(define oly:text_handler add-text)
631 % ~~~~~~~~~~~~~~~~~~
633 % TODO: deprecate
634 setUseBook = #(define-music-function (parser location usebook) (boolean?)
635   (ly:warning "\\setUseBook has been deprecated! Books are now automatically handled without any hacks")
636   (make-music 'Music 'void #t)
640 % Two functions to handle midi-blocks: Either don't set one, or set an empty
641 % one so that MIDI is generated
642 #(define (oly:set_no_midi_block score) '())
643 #(define (oly:set_midi_block score)
644   (let* ((midiblock (if (defined? '$defaultmidi)
645                         (ly:output-def-clone $defaultmidi)
646                         (ly:make-output-def))))
647     (ly:output-def-set-variable! midiblock 'is-midi #t)
648     (ly:score-add-output-def! score midiblock)
649   )
652 % \setCreateMidi ##t/##f sets a flag to determine wheter MIDI output should
653 % be generated
654 #(define oly:apply_score_midi oly:set_no_midi_block)
655 setCreateMIDI = #(define-music-function (parser location createmidi) (boolean?)
656   (if createmidi
657     (set! oly:apply_score_midi oly:set_midi_block)
658     (set! oly:apply_score_midi oly:set_no_midi_block)
659   )
660   (make-music 'Music 'void #t)
664 % Two functions to handle layout-blocks: Either don't set one, or set an empty
665 % one so that a PDF is generated
666 #(define (oly:set_no_layout_block score) '())
667 #(define (oly:set_layout_block score)
668   (let* ((layoutblock (if (defined? '$defaultlayout)
669                         (ly:output-def-clone $defaultlayout)
670                         (ly:make-output-def))))
671     (ly:output-def-set-variable! layoutblock 'is-layout #t)
672     (ly:score-add-output-def! score layoutblock)
673   )
676 % \setCreatePDF ##t/##f sets a flag to determine wheter PDF output should
677 % be generated
678 #(define oly:apply_score_layout oly:set_no_layout_block)
679 setCreatePDF = #(define-music-function (parser location createlayout) (boolean?)
680   (if createlayout
681     (set! oly:apply_score_layout oly:set_layout_block)
682     (set! oly:apply_score_layout oly:set_no_layout_block)
683   )
684   (make-music 'Music 'void #t)
688 % Set the piece title in a new header block.
689 #(define (oly:set_piece_header score piecename)
690   (if (not-null? piecename)
691     (let* ((header (make-module)))
692       (module-define! header 'piece piecename)
693       (ly:score-set-header! score header)
694     )
695   )
699 % post-filter functions. By default, no filtering is done. However,
700 % for the *NoCues* function, the cue notes should be killed
701 identity = #(define-music-function (parser location music) (ly:music?) music)
702 cuefilter = #(define-music-function (parser location music) (ly:music?)
703   ((ly:music-function-extract removeWithTag) parser location 'cued ((ly:music-function-extract killCues) parser location music))
707 #(define (oly:create-toc-file layout pages)
708   (let* ((label-table (ly:output-def-lookup layout 'label-page-table)))
709     (if (not (null? label-table))
710       (let* ((format-line (lambda (toc-item)
711              (let* ((label (car toc-item))
712                     (text  (caddr toc-item))
713                     (label-page (and (list? label-table)
714                                      (assoc label label-table)))
715                     (page (and label-page (cdr label-page))))
716                (format #f "~a, section, 1, {~a}, ~a" page text label))))
717              (formatted-toc-items (map format-line (toc-items)))
718              (whole-string (string-join formatted-toc-items ",\n"))
719              (output-name (ly:parser-output-name parser))
720              (outfilename (format "~a.toc" output-name))
721              (outfile (open-output-file outfilename)))
722         (if (output-port? outfile)
723             (display whole-string outfile)
724             (ly:warning (_ "Unable to open output file ~a for the TOC information") outfilename))
725         (close-output-port outfile)))))
728 #(define-public (oly:add-toc-item parser markup-symbol text)
729   (oly:music_handler parser (add-toc-item! markup-symbol text)))
732 #(define (oly:add-score parser score piecename)
733   (if (not-null? piecename)
734     (oly:add-toc-item parser 'tocItemMarkup piecename))
735   (oly:score_handler parser score)
737 % The helper function to build a score.
738 #(define (oly:createScoreHelper parser location piece children func)
739   (let* (
740          (staves    (oly:staff_group_handler parser piece "" "SimultaneousMusic" children))
741          (music     (if (not-null? staves)
742                         ((ly:music-function-extract func) parser location staves)
743                         '()
744                     ))
745          (score     '())
746          (piecename (namedPieceInstrObject piece (car children) "PieceName"))
747          (piecenametacet (namedPieceInstrObject piece (car children) "PieceNameTacet"))
748          (header    '())
749         )
750     (if (null? music)
751       ; No staves, print tacet
752       (begin
753         (if (not-null? piecenametacet) (set! piecename piecenametacet))
754         (if (not-null? piecename)
755           (oly:add-score parser (list (oly:piece-title-markup piecename)) piecename)
756           (ly:warning (_ "No music and no score title found for part ~a and instrument ~a") piece children)
757         )
758       )
759       ; we have staves, apply the piecename to the score and add layout/midi blocks if needed
760       (begin
761         (set! score (scorify-music music parser))
762         (oly:set_piece_header score piecename)
763         (oly:apply_score_midi score)
764         (oly:apply_score_layout score)
765         ; Schedule the score for typesetting
766         (oly:add-score parser score piecename)
767       )
768     )
769   )
770   ; This is a void function, the score has been schedulled for typesetting already
771   (make-music 'Music 'void #t)
774 createScore = #(define-music-function (parser location piece children) (string? list?)
775   (oly:createScoreHelper parser location piece children identity)
777 createNoCuesScore = #(define-music-function (parser location piece children) (string? list?)
778   (oly:createScoreHelper parser location piece children cuefilter)
781 createHeadline = #(define-music-function (parser location headline) (string?)
782   (oly:add-toc-item parser 'tocItemMarkup headline)
783   (oly:score_handler parser (list (oly:piece-title-markup headline)))
784   (make-music 'Music 'void #t)
789 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
790 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
791 %%%%%   CUE NOTES
792 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
793 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
795 newInstrument = #(define-music-function (parser location instr) (string?)
797   \set Voice.instrumentCueName = #$(string-join (list "+" instr))
800 cueText = #(define-music-function (parser location instr) (string?)
802   \set Voice.instrumentCueName = $instr
806 clearCueText = #(define-music-function (parser location) ()
808   \unset Voice.instrumentCueName
812 insertCueText = #(define-music-function (parser location instr) (string?)
813   (if (string-null? instr)
814     #{ \tag #'cued \clearCueText #}
815     #{ \tag #'cued \cueText #$instr #}
818 % generate a cue music section with instrument names
819 % Parameters: \namedCueDuring NameOfQuote CueDirection CueInstrument OriginalInstrument music
820 %                 -) NameOfQuote CueDirection music are the parameters for \cueDuring
821 %                 -) CueInstrument and OriginalInstrument are the displayed instrument names
822 % typical call:
823 % \namedCueDuring #"vIQuote" #UP #"V.I" #"Sop." { R1*3 }
824 %      This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
825 %      the beginning of the cue notes and "Sop." at the end
826 namedCueDuring = #(define-music-function (parser location cuevoice direction instrcue instr cuemusic) (string? number? string? string? ly:music?)
828   \cueDuring #$cuevoice #$direction {
829     \insertCueText #$instrcue
830     $cuemusic
831     \insertCueText #$instr
832   }
835 namedTransposedCueDuring = #(define-music-function (parser location cuevoice direction instrcue instr trans cuemusic) (string? number? string? string? ly:music? ly:music?)
836    #{
837      \transposedCueDuring #$cuevoice #$direction $trans {
838        \insertCueText #$instrcue
839        $cuemusic
840        \insertCueText #$instr
841      }
842    #}
845 % set the cue instrument name and clef
846 setClefCue = #(define-music-function (parser location instr clef)
847                                                      (string? ly:music?)
848    #{
849      \once \override Staff.Clef #'font-size = #-3 $clef
850      \insertCueText $instr
851    #} )
853 % generate a cue music section with instrument names and clef changes
854 % Parameters: \cleffedCueDuring NameOfQuote CueDirection CueInstrument CueClef OriginalInstrument OriginalClef music
855 %                 -) NameOfQuote CueDirection music are the parameters for \cueDuring
856 %                 -) CueInstrument and OriginalInstrument are the displayed instrument names
857 %                 -) CueClef and OriginalClef are the clefs for the the cue notes and the clef of the containing voice
858 % typical call:
859 % \cleffedCueDuring #"vIQuote" #UP #"V.I" #"treble" #"Basso" #"bass" { R1*3 }
860 %      This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
861 %      the beginning of the cue notes and "Basso" at the end. The clef is changed to treble at the
862 %      beginning of the cue notes and reset to bass at the end
863 cleffedCueDuring = #(define-music-function (parser location cuevoice direction instrcue clefcue instr clefinstr cuemusic)
864                                                         (string? number? string? ly:music? string? ly:music? ly:music?)
865    #{
866      \cueDuring #$cuevoice #$direction {
867        \tag #'cued \setClefCue #$instrcue $clefcue
868        $cuemusic
869        \tag #'cued \setClefCue #$instr $clefinstr
870      }
871    #}
877 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
878 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
879 %%%%%   DYNAMICS
880 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
881 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
884 dynamicsX = #(define-music-function (parser location offset) (number?)
886     \once \override DynamicText #'X-offset = $offset
887     \once \override DynamicLineSpanner #'Y-offset = #0
890 % Move the dynamic sign inside the staff to a fixed staff-relative position
891 % posY (where 0 means vertically starts at the middle staff line)
892 dynamicsAllInside = #(define-music-function (parser location offsetX posY)
893 (number? number?)
895   % Invalid y-extent -> hidden from skyline calculation and collisions
896 %   \once \override DynamicLineSpanner #'Y-extent = #(cons +0 -0.01)
897   \once \override DynamicLineSpanner #'Y-extent = $(lambda (grob)
898     (let* ((ext (ly:axis-group-interface::height grob))
899            (dir (ly:grob-property grob 'direction)))
900       (if (eq? dir UP)
901             (cons (- (cdr ext) 0.1) (cdr ext))
902             (cons (car ext)         (+ (car ext) 0.1)))))
903   % move by X offset and to fixed Y-position (use Y-offset of parent!)
904   \once \override DynamicText #'X-offset = $offsetX
905   \once \override DynamicText #'Y-offset =
906     $(lambda (grob)
907        (let* ((head (ly:grob-parent grob Y))
908               (offset (ly:grob-property head 'Y-offset)))
909          (- posY  offset (- 0.6))))
910   \once \override DynamicLineSpanner #'Y-offset = $posY
913 dynamicsUpInside = #(define-music-function (parser location offsetX) (number?)
914   ((ly:music-function-extract dynamicsAllInside) parser location offsetX 1.5)
917 dynamicsDownInside = #(define-music-function (parser location offsetX) (number?)
918   ((ly:music-function-extract dynamicsAllInside) parser location offsetX -3.5)
921 hairpinOffset = #(define-music-function (parser location posY) (number?)
923   \once \override DynamicLineSpanner #'Y-offset = $posY
924   \once \override DynamicLineSpanner #'Y-extent = #(cons +0 -0.01)
927 #(define ((line-break-offset before after) grob)
928   (let* ((orig (ly:grob-original grob))
929          ; All siblings if line-broken:
930          (siblings (if (ly:grob? orig) (ly:spanner-broken-into orig) '() )))
931     (if (>= (length siblings) 2)
932       ; We have been line-broken
933       (if (eq? (car (last-pair siblings)) grob)
934         ; Last sibling:
935         (ly:grob-set-property! grob 'Y-offset after)
936         ; Others get the before value:
937         (ly:grob-set-property! grob 'Y-offset before)
938       )
939     )
940   )
943 ffz = #(make-dynamic-script "ffz")
944 pf = #(make-dynamic-script "pf")
945 sempp = #(make-dynamic-script (markup #:line( #:with-dimensions '(0 . 0)
946 '(0 . 0) #:right-align #:normal-text #:italic "sempre" #:dynamic "pp")))
947 parenf = #(make-dynamic-script (markup #:line(#:normal-text #:italic #:fontsize 2 "(" #:dynamic "f" #:normal-text #:italic #:fontsize 2 ")" )))
948 parenp = #(make-dynamic-script (markup #:line(#:normal-text #:italic #:fontsize 2 "(" #:dynamic "p" #:normal-text #:italic #:fontsize 2 ")" )))
949 pdolce = #(make-dynamic-script (markup #:line(#:dynamic "p" #:with-dimensions '(0 . 0) '(0 . 0) #:normal-text #:italic "dolce"  )))
950 sfpdolce = #(make-dynamic-script (markup #:line(#:dynamic "sfp" #:with-dimensions '(0 . 0) '(0 . 0) #:normal-text #:italic "dolce"  )))
951 bracketf = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 3 "[" #:dynamic "f" #:hspace 0.1 #:normal-text #:fontsize 3 "]"))))
952 bracketmf = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 3 "[" #:dynamic "mf" #:hspace 0.1 #:normal-text #:fontsize 3 "]"))))
953 bracketmp = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 2 "[" #:hspace 0.2 #:dynamic "mp" #:normal-text #:fontsize 2 "]"))))
954 bracketp = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 2 "[" #:hspace 0.2 #:dynamic "p" #:normal-text #:fontsize 2 "]"))))
958 % cresc = #(make-music 'CrescendoEvent 'span-direction START 'crescendoSpanner 'text 'crescendoText "cresc.")
959 % endcresc =  #(make-span-event 'CrescendoEvent STOP)
960 % dim = #(make-music 'DecrescendoEvent 'span-direction START 'decrescendoSpanner 'text 'decrescendoText "dim.")
961 % enddim =  #(make-span-event 'DecrescendoEvent STOP)
962 % decresc = #(make-music 'DecrescendoEvent 'span-direction START 'decrescendoSpanner 'text 'decrescendoText "decresc.")
963 % enddecresc =  #(make-span-event 'DecrescendoEvent STOP)
965 % setCresc = {}
966 % setDecresc = {}
967 % setDim = {}
968 cresc = #(make-music 'CrescendoEvent 'span-direction START
969                      'span-type 'text 'span-text "cresc.")
970 dim = #(make-music 'DecrescendoEvent 'span-direction START
971                    'span-type 'text 'span-text "dim.")
972 decresc = #(make-music 'DecrescendoEvent 'span-direction START
973                        'span-type 'text 'span-text "decresc.")
975 newOrOldClef = #(define-music-function (parser location new old ) (string? string?)
976     (if (ly:get-option 'old-clefs) #{ \clef $old #} #{ \clef $new #})
981 %%% Thanks to "Gilles THIBAULT" <gilles.thibault@free.fr>, there is a way
982 %   to remove also the fermata from R1-\fermataMarkup: By filtering the music
983 %   and removing the corresponding events.
984 %   Documented as an LSR snippet: http://lsr.dsi.unimi.it/LSR/Item?id=372
985 #(define (filterOneEventsMarkup event)
986 ( let ( (eventname (ly:music-property  event 'name)) )
987  (not
988   (or     ;; add here event name you do NOT want
989    (eq? eventname 'MultiMeasureTextEvent)
990    (eq? eventname 'AbsoluteDynamicEvent)
991    (eq? eventname 'TextScriptEvent)
992    (eq? eventname 'ArticulationEvent)
993    (eq? eventname 'CrescendoEvent)
994    (eq? eventname 'DecrescendoEvent)
995   )
999 filterArticulations = #(define-music-function (parser location music) (ly:music?)
1000    (music-filter filterOneEventsMarkup music)
1007 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1008 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1009 %%%%%   Tempo markings
1010 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1011 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1015 rit = \markup {\italic "rit."}
1016 pocorit = \markup {\italic "poco rit."}
1017 ppmosso = \markup {\italic "poco più mosso"}
1018 dolce = \markup {\italic "dolce"}
1019 pizz = \markup {\italic "pizz."}
1020 arco = \markup {\italic "arco"}
1021 perd = \markup {\italic "perdend."}
1026 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1027 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1028 %%%%%   REST COMBINATION
1029 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1030 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1034 %% REST COMBINING, TAKEN FROM http://lsr.dsi.unimi.it/LSR/Item?id=336
1036 %% Usage:
1037 %%   \new Staff \with {
1038 %%     \override RestCollision #'positioning-done = #merge-rests-on-positioning
1039 %%   } << \somevoice \\ \othervoice >>
1040 %% or (globally):
1041 %%   \layout {
1042 %%     \context {
1043 %%       \Staff
1044 %%       \override RestCollision #'positioning-done = #merge-rests-on-positioning
1045 %%     }
1046 %%   }
1048 %% Limitations:
1049 %% - only handles two voices
1050 %% - does not handle multi-measure/whole-measure rests
1052 #(define (rest-score r)
1053   (let ((score 0)
1054   (yoff (ly:grob-property-data r 'Y-offset))
1055   (sp (ly:grob-property-data r 'staff-position)))
1056     (if (number? yoff)
1057   (set! score (+ score 2))
1058   (if (eq? yoff 'calculation-in-progress)
1059       (set! score (- score 3))))
1060     (and (number? sp)
1061    (<= 0 2 sp)
1062    (set! score (+ score 2))
1063    (set! score (- score (abs (- 1 sp)))))
1064     score))
1066 #(define (merge-rests-on-positioning grob)
1067   (let* ((can-merge #f)
1068    (elts (ly:grob-object grob 'elements))
1069    (num-elts (and (ly:grob-array? elts)
1070       (ly:grob-array-length elts)))
1071    (two-voice? (= num-elts 2)))
1072     (if two-voice?
1073   (let* ((v1-grob (ly:grob-array-ref elts 0))
1074          (v2-grob (ly:grob-array-ref elts 1))
1075          (v1-rest (ly:grob-object v1-grob 'rest))
1076          (v2-rest (ly:grob-object v2-grob 'rest)))
1077     (and
1078      (ly:grob? v1-rest)
1079      (ly:grob? v2-rest)
1080      (let* ((v1-duration-log (ly:grob-property v1-rest 'duration-log))
1081       (v2-duration-log (ly:grob-property v2-rest 'duration-log))
1082       (v1-dot (ly:grob-object v1-rest 'dot))
1083       (v2-dot (ly:grob-object v2-rest 'dot))
1084       (v1-dot-count (and (ly:grob? v1-dot)
1085              (ly:grob-property v1-dot 'dot-count -1)))
1086       (v2-dot-count (and (ly:grob? v2-dot)
1087              (ly:grob-property v2-dot 'dot-count -1))))
1088        (set! can-merge
1089        (and
1090         (number? v1-duration-log)
1091         (number? v2-duration-log)
1092         (= v1-duration-log v2-duration-log)
1093         (eq? v1-dot-count v2-dot-count)))
1094        (if can-merge
1095      ;; keep the rest that looks best:
1096      (let* ((keep-v1? (>= (rest-score v1-rest)
1097               (rest-score v2-rest)))
1098       (rest-to-keep (if keep-v1? v1-rest v2-rest))
1099       (dot-to-kill (if keep-v1? v2-dot v1-dot)))
1100        ;; uncomment if you're curious of which rest was chosen:
1101        ;;(ly:grob-set-property! v1-rest 'color green)
1102        ;;(ly:grob-set-property! v2-rest 'color blue)
1103        (ly:grob-suicide! (if keep-v1? v2-rest v1-rest))
1104        (if (ly:grob? dot-to-kill)
1105            (ly:grob-suicide! dot-to-kill))
1106        (ly:grob-set-property! rest-to-keep 'direction 0)
1107        (ly:rest::y-offset-callback rest-to-keep)))))))
1108     (if can-merge
1109   #t
1110   (ly:rest-collision::calc-positioning-done grob))))
1116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1118 %%%%%   TABLE OF CONTENTS
1119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1123 contentsTitle = "Inhalt / Contents"
1125 \paper {
1126   tocTitleMarkup = \markup \fill-line{
1127     \null
1128     \column {
1129       \override #(cons 'line-width (* 7 cm))
1130       \line{ \fill-line {\piece-title {\contentsTitle} \null }}
1131       \hspace #1
1132     }
1133     \null
1134   }
1135   tocItemMarkup = \markup \fill-line {
1136     \null
1137     \column {
1138       \override #(cons 'line-width (* 7 cm ))
1139       \line { \fill-line{\fromproperty #'toc:text \fromproperty #'toc:page }}
1140     }
1141     \null
1142   }
1146 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1147 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1148 %%%%%   TITLE PAGE / HEADER
1149 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1150 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1152 #(define-markup-command (when-property layout props symbol markp) (symbol? markup?)
1153   (if (chain-assoc-get symbol props)
1154       (interpret-markup layout props markp)
1155       (ly:make-stencil '()  '(1 . -1) '(1 . -1))))
1157 #(define-markup-command (vspace layout props amount) (number?)
1158   "This produces a invisible object taking vertical space."
1159   (let ((amount (* amount 3.0)))
1160     (if (> amount 0)
1161         (ly:make-stencil "" (cons -1 1) (cons 0 amount))
1162         (ly:make-stencil "" (cons -1 1) (cons amount amount)))))
1166 titlePageMarkup = \markup \abs-fontsize #10 \when-property #'header:title \column {
1167     \vspace #4
1168     \fill-line { \fontsize #8 \fromproperty #'header:composer }
1169     \vspace #1
1170     \fill-line { \fontsize #8 \fromproperty #'header:poet }
1171     \vspace #4
1172     \fill-line { \fontsize #10 \bold \fromproperty #'header:titlepagetitle }
1173     \vspace #1
1174     \fontsize #2 \when-property #'header:titlepagesubtitle {
1175       \fill-line { \fromproperty #'header:titlepagesubtitle }
1176       \vspace #1
1177     }
1178     \fill-line { \postscript #"-20 0 moveto 40 0 rlineto stroke" }
1179     \vspace #8
1180     \fill-line { \fontsize #5 \fromproperty #'header:ensemble }
1181     \vspace #0.02
1182     \fill-line { \fontsize #2 \fromproperty #'header:instruments }
1183     \vspace #9
1184     \fill-line { \fontsize #5 \fromproperty #'header:date }
1185     \vspace #1
1186     \fill-line { \fontsize #5 \fromproperty #'header:scoretype }
1187     \vspace #8
1188     \fontsize #2 \when-property #'header:enteredby {
1189       \fill-line { "Herausgegeben von: / Edited by:"}
1190       \vspace #0.
1191       \fill-line { \fromproperty #'header:enteredby }
1192     }
1193     \fill-line {
1194       \when-property #'header:arrangement \column {
1195         \vspace #8
1196         \fill-line { \fontsize #3 \fromproperty #'header:arrangement }
1197       }
1198     }
1201 titleHeaderMarkup = \markup {
1202   \override #'(baseline-skip . 3.5)
1203   \column {
1204     \fill-line {
1205       \fromproperty #'header:logo
1206       \center-column {
1207         \huge \larger \bold \larger \fromproperty #'header:title
1208         \large \smaller \bold \larger \fromproperty #'header:subtitle
1209         \smaller \bold \fromproperty #'header:subsubtitle
1210       }
1211       \bold \when-property #'header:instrument \rounded-box \fromproperty #'header:instrument
1212     }
1213     \fill-line {
1214       \with-dimensions #'( 0 . 0) #'( 0 . 1 ) \null
1215     }
1217 %     \fill-line {
1218 %       { \large \bold \fromproperty #'header:instrument }
1219 %     }
1220     \fill-line {
1221       \fromproperty #'header:poet
1222       \fromproperty #'header:composer
1223     }
1224     \fill-line {
1225       \fromproperty #'header:meter
1226       \fromproperty #'header:arranger
1227     }
1228   }
1231 titleScoreMarkup = \markup \piece-title \fromproperty #'header:piece
1233 \paper {
1234   scoreTitleMarkup = \titleScoreMarkup
1235   bookTitleMarkup = \titleHeaderMarkup
1240 %%%%%%%%%%%%%% headers and footers %%%%%%%%%%%%%%%%%%%%%%%%%%
1242 #(define (first-score-page layout props arg)
1243   (let* ((label 'first-score-page)
1244          (table (ly:output-def-lookup layout 'label-page-table))
1245          (label-page (and (list? table) (assoc label table)))
1246          (page-number (and label-page (cdr label-page)))
1247         )
1248     (if (eq? (chain-assoc-get 'page:page-number props -1) page-number)
1249       (interpret-markup layout props arg)
1250       empty-stencil)))
1252 #(define no-header-table '())
1253 thisPageNoHeader = #(define-music-function (parser location) ()
1254   (let* ((label (gensym "header")))
1255     (set! no-header-table (cons label no-header-table))
1256     (make-music 'Music
1257       'page-marker #t
1258       'page-label label)))
1261 % TODO: Use the no-header-table!
1262 #(define (is-header-page layout props arg)
1263   (let* ((page-number (chain-assoc-get 'page:page-number props -1))
1264         )
1265     ;(if (and (> page-number 2) (!= page-number 7))
1266     (if (> page-number 1)
1267       (interpret-markup layout props arg)
1268       empty-stencil)))
1270 #(define no-footer-table '())
1271 thisPageNoFooter = #(define-music-function (parser location) ()
1272   (let* ((label (gensym "footer")))
1273     (set! no-footer-table (cons label no-footer-table))
1274     (make-music 'Music
1275       'page-marker #t
1276       'page-label label)))
1278 % TODO: Use the no-footer-table!
1279 #(define (is-footer-page layout props arg)
1280   (let* ((page-number (chain-assoc-get 'page:page-number props -1))
1281          (label 'first-score-page)
1282          (table (ly:output-def-lookup layout 'label-page-table))
1283          (label-page (and (list? table) (assoc label table)))
1284          ;(page-number (and label-page (cdr label-page)))
1285         )
1286     (if (and (> page-number 1))
1287       (interpret-markup layout props arg)
1288       empty-stencil)))
1291 #(define copyright-footer-table '())
1292 thisPageCopyrightFooter = #(define-music-function (parser location) ()
1293   (let* ((label (gensym "copyrightfooter")))
1294     (set! copyright-footer-table (cons label copyright-footer-table))
1295     (make-music 'Music
1296       'page-marker #t
1297       'page-label label)))
1299 #(define copyright-pg 1)
1300 #(define (set-copyright-page page)
1301   (set! copyright-pg page)
1304 % TODO: Use the copyright-footer-table!
1305 #(define (copyright-page layout props arg)
1306     (if (= (chain-assoc-get 'page:page-number props -1) copyright-pg)
1307       (interpret-markup layout props arg)
1308       empty-stencil))
1311 \paper {
1312   oddHeaderMarkup = \markup \fill-line {
1313     %% force the header to take some space, otherwise the
1314     %% page layout becomes a complete mess.
1315     " "
1316     \on-the-fly #is-header-page \fromproperty #'header:title
1317     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1318   }
1319   evenHeaderMarkup = \markup \fill-line {
1320     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1321     \on-the-fly #is-header-page \fromproperty #'header:composer
1322     " "
1323   }
1325   oddFooterMarkup = \markup {
1326     \column {
1327       \fill-line {
1328         %% publisher header field only on title page.
1329         \on-the-fly #first-page \fromproperty #'header:publisher
1330       }
1331       \fill-line {
1332         %% copyright on the first real score page
1333         \on-the-fly #copyright-page \fromproperty #'header:copyright
1334         \on-the-fly #copyright-page \null
1335       }
1336       \fill-line {
1337         %% All other pages get the number of the edition centered
1338         \on-the-fly #is-footer-page \fromproperty #'header:scorenumber
1339       }
1340     }
1341   }
1355 % Interpret the given markup with the header fields added to the props.
1356 % This way, one can re-use the same functions (using fromproperty
1357 % #'header:field) in the header block and as top-level markup.
1359 % This function is originally copied from mark-up-title (file scm/titling.scm),
1360 % which is lilypond's internal function to handle the title markups. I needed
1361 % to replace the scopes and manually add the $defaultheader (which is internally
1362 % done in paper-book.cc before calling mark-up-title. Also, I don't extract the
1363 % markup from the header block, but use the given markup.
1365 % I'm not sure if I really need the page properties in props, too... But I
1366 % suppose it does not hurt, either.
1367 #(define-markup-command (markupWithHeader layout props markup) (markup?)
1368   "Interpret the given markup with the header fields added to the props.
1369    This way, one can re-use the same functions (using fromproperty
1370    #'header:field) in the header block and as top-level markup."
1371   (let* (
1372       ; TODO: If we are inside a score, add the score's local header block, too!
1373       ; Currently, I only use the global header block, stored in $defaultheader
1374       (scopes (list $defaultheader))
1375       (alists (map ly:module->alist scopes))
1377       (prefixed-alist
1378         (map (lambda (alist)
1379           (map (lambda (entry)
1380             (cons
1381               (string->symbol (string-append "header:" (symbol->string (car entry))))
1382               (cdr entry)))
1383             alist))
1384           alists))
1385       (props (append prefixed-alist
1386               props
1387               (layout-extract-page-properties layout)))
1388     )
1389     (interpret-markup layout props markup)
1390   )
1398 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1399 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1400 %%%%%   Equally spacing multiple columns (e.g. for translations)
1401 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1402 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1404 % Credits: Nicolas Sceaux on the lilypond-user mailinglist
1405 #(define-markup-command (columns layout props args) (markup-list?)
1406    (let ((line-width (/ (chain-assoc-get 'line-width props
1407                          (ly:output-def-lookup layout 'line-width))
1408                         (max (length args) 1))))
1409      (interpret-markup layout props
1410        (make-line-markup (map (lambda (line)
1411                                 (markup #:pad-to-box `(0 . ,line-width) '(0 . 0)
1412                                   #:override `(line-width . ,line-width)
1413                                   line))
1414                                args)))))
1418 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1419 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1420 %%%%%   SCORE (HEADER / LAYOUT) SETTINGS
1421 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1422 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1425 startSlashedGraceMusic =  {
1426   \override Stem  #'stroke-style = #"grace"
1429 stopSlashedGraceMusic =  {
1430   \revert Stem #'stroke-style
1433 slashedGrace =
1434 #(def-grace-function startSlashedGraceMusic stopSlashedGraceMusic
1435    (_i "Create slashed graces (slashes through stems, but no slur)from the following music expression"))
1438 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1439 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1440 %%%%%   SCORE (HEADER / LAYOUT) SETTINGS
1441 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1442 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1444 \paper {
1445   left-margin = 2\cm
1446   right-margin = 1.5\cm
1447   line-width = 17.5\cm
1448 %   bottom-margin = 1.5\cm
1449   top-margin = 1.2\cm
1450 %   after-title-space = 0.5\cm
1451   ragged-right = ##f
1452   ragged-last = ##f
1453   ragged-bottom = ##f
1454   ragged-last-bottom = ##f
1456 \layout {
1457   \context {
1458     \ChoirStaff
1459     % If only one non-empty staff in a system exists, still print the backet
1460     \override SystemStartBracket #'collapse-height = #1
1461     \consists "Instrument_name_engraver"
1462   }
1463   \context {
1464     \StaffGroup
1465     % If only one non-empty staff in a system exists, still print the backet
1466     \override SystemStartBracket #'collapse-height = #1
1467     \consists "Instrument_name_engraver"
1468   }
1469   \context {
1470     \GrandStaff
1471     \override SystemStartBracket #'collapse-height = #1
1472     \consists "Instrument_name_engraver"
1473   }
1474   \context {
1475     \FiguredBass
1476 %     \override VerticalAxisGroup #'keep-fixed-while-stretching = ##t
1477     \override VerticalAxisGroup #'minimum-Y-extent  = #'(0 . 1)
1478     \override VerticalAxisGroup #'padding = #0
1479   }
1480   \context {
1481     \Score
1482     % Force multi-measure rests to be written as one span
1483     \override MultiMeasureRest #'expand-limit = #3
1484     skipBars = ##t
1485     autoBeaming = ##f
1486 %     hairpinToBarline = ##f
1487 %     \override BarNumber #'break-visibility = #end-of-line-invisible
1488 %     \override BarNumber #'self-alignment-X = #0
1489 %     barNumberVisibility = #(every-nth-bar-number-visible 5)
1490     \override CombineTextScript #'avoid-slur = #'outside
1491     \override DynamicTextSpanner #'dash-period = #-1.0
1492     \override InstrumentSwitch #'font-size = #-1
1494     % Rest collision
1495     \override RestCollision #'positioning-done = #merge-rests-on-positioning
1496     % Auto-Accidentals: Use modern-cautionary style...
1497     extraNatural = ##f
1498     autoAccidentals = #`(Staff  ,(make-accidental-rule 'same-octave 0)
1499                                 ,(make-accidental-rule 'any-octave 0)
1500                                 ,(make-accidental-rule 'same-octave 1))
1501 %     autoCautionaries = #`(Staff ,(make-accidental-rule 'any-octave 0)
1502 %                                 ,(make-accidental-rule 'same-octave 1))
1503     printKeyCancellation = ##t
1504     quotedEventTypes = #'(StreamEvent)
1505     implicitBassFigures = #'(0 100)
1506   }
1507   \context {
1508     \RemoveEmptyStaffContext
1509   }
1510   \context {
1511     \Staff
1512     ignoreFiguredBassRest = ##f
1513   }
1517 ts = ^\markup{"t.s."}
1518 tt = ^\markup{"Tutti"}
1519 solo = ^\markup{"Solo"}
1520 tutti = ^\markup{"Tutti"}
1521 bracketts = ^\markup{"[Solo]"}
1522 brackettt = ^\markup{"[Tutti]"}
1523 bracketsolo = ^\markup{"[Solo]"}
1525 dashedSlur = -\tweak #'dash-definition #'((0 1 0.4 0.75))(
1526 dashedTie = -\tweak #'dash-definition #'((0 1 0.4 0.75))~
1528 divisi = #(define-music-function (parser location vc1 vc2) (ly:music? ly:music?)
1530   << { \voiceOne $vc1 \oneVoice} \new Voice = "divisi2" { \voiceTwo $vc2 } >>
1534 #(define twoVoice divisi)
1536 #(define-public (bracket-stencils grob)
1537   (let ((lp (grob-interpret-markup grob (markup #:fontsize 3.5 #:translate (cons -0.3 -0.5) "[")))
1538         (rp (grob-interpret-markup grob (markup #:fontsize 3.5 #:translate (cons -0.3 -0.5) "]"))))
1539     (list lp rp)))
1541 bracketify = #(define-music-function (parser loc arg) (ly:music?)
1542    (_i "Tag @var{arg} to be parenthesized.")
1544   \once \override ParenthesesItem #'stencils = #bracket-stencils
1545   \parenthesize $arg
1550 #(define-markup-command (hat layout props arg) (markup?)
1551   "Draw a hat above the given string @var{arg}."
1552   (interpret-markup layout props (markup #:combine #:raise 1.5 "^" arg)))
1556 smallFlageolet =
1557 #(let ((m (make-music 'ArticulationEvent
1558                       'articulation-type "flageolet")))
1559    (ly:music-set-property! m 'tweaks
1560      (acons 'font-size -2
1561        (ly:music-property m 'tweaks)))
1562   m)
1565 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1566 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1567 %%%%%   LICENSE TEXTS
1568 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1569 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1571 LicenseCCBY = \markup {Lizensiert unter / Licensed under: Creative Commons BY \with-url #"http://creativecommons.org/licenses/by/3.0/at/" {\translate #'(0 . -0.7) \epsfile #Y #3 #"orchestrallily/cc-by.eps" }}
1572 LicenseCCBYNC = \markup {Lizensiert unter / Licensed under: Creative Commons BY-NC \with-url #"http://creativecommons.org/licenses/by-nc/3.0/at/" {\translate #'(0 . -0.7) \epsfile #Y #3 #"orchestrallily/cc-by-nc.eps" }}
1573 LicenseNoRestrictions = \markup{\line {Die Ausgabe darf kopiert und ohne Einschränkungen aufgeführt werden. / May be copied and performed without restriction.}}
1575 \include "sceaux_clef-key.ily"
1578 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1579 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1580 %%%%%   VARIOUS
1581 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1582 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1584 startUnremovableSection = \set Staff.keepAliveInterfaces =
1585  #'(rhythmic-grob-interface
1586     rest-interface
1587     lyric-interface
1588     percent-repeat-item-interface
1589     percent-repeat-interface
1590     stanza-number-interface)
1592 endUnremovableSection = \unset Staff.keepAliveInterfaces
1595 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1596 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1597 %%%%%   EDITORIAL ANNOTATIONS
1598 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1599 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1601 #(define-public (editorial-bracket-stencil stil padding widen)
1602 "Add brackets for editorial annoations around STIL, producing a new stencil."
1603 (let* ((axis Y)
1604        (other-axis (lambda (a) (remainder (+ a 1) 2)))
1605        (ext (interval-widen (ly:stencil-extent stil axis) widen))
1606        (thick 0.15)
1607        (protrusion 0.3)
1608        (lb (ly:bracket axis ext thick protrusion))
1609        (rb (ly:bracket axis ext thick (- protrusion))))
1610   (set! stil (ly:stencil-combine-at-edge stil (other-axis axis) 1 rb padding))
1611   (set! stil
1612     (ly:stencil-combine-at-edge lb (other-axis axis) 1 stil padding))
1613   stil))
1615 editorialHairpin = \once \override Hairpin     #'stencil = #(lambda (grob) (editorial-bracket-stencil (ly:hairpin::print grob) 0.2 0.55))
1616 editorialDynamic = \once \override DynamicText #'stencil = #(lambda (grob) (editorial-bracket-stencil (ly:text-interface::print grob) 0.2 0.55))
1617 editorialMarkup =  \once \override TextScript  #'stencil = #(lambda (grob) (editorial-bracket-stencil (ly:text-interface::print grob) 0.2 0.55))