addArticulation function to add articulation to multiple notes
[orchestrallily.git] / orchestrallily.ily
blobb783854ac904913a5b687cc61bf7652783f2cd3a
1 \version "2.15.19"
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: Dual-licensed under either:
12 %      -) GPL v3.0, http://www.gnu.org/licenses/gpl.html
13 %      -) Creative Commons BY-NC 3.0, http://creativecommons.org/licenses/by-nc/3.0/at/
15 % Version History:
16 % 0.01 (2008-03-02): Initial Version
17 % 0.02 (2008-03-06): Added basic MIDI support (*MidiInstrument and \setCreateMIDI)
18 % 0.03 (2008-07-xx): General staff/voice types, title pages, etc.
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21 #(use-modules (ice-9 match))
24 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25 % GLOBAL OPTIONS
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28 % Use relative include pathes!
29 #(ly:set-option 'relative-includes #t)
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34 %%%%%   SCORE STRUCTURE AND AUTOMATIC GENERATION
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 % Helper functions
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 % Helper function to filter all non-null entries
46 #(define (not-null? x) (not (null? x)))
48 % Helper function to extract a given variable, built from [Piece][Instrument]Identifier
49 #(define (namedPieceInstrObject piece instr name)
50   (let* (
51          (fullname  (string->symbol (string-append piece instr name)))
52          (instrname (string->symbol (string-append instr name)))
53          (piecename (string->symbol (string-append piece name)))
54          (fallback  (string->symbol name))
55         )
56     (cond
57       ((defined? fullname) (primitive-eval fullname))
58       ((defined? instrname) (primitive-eval instrname))
59       ((defined? piecename) (primitive-eval piecename))
60       ((defined? fallback) (primitive-eval fallback))
61       (else '())
62     )
63   )
66 %% Print text as a justified paragraph, taken from the lilypond Notation Reference
67 #(define-markup-list-command (paragraph layout props args) (markup-list?)
68    (let ((indent (chain-assoc-get 'par-indent props 2)))
69      (interpret-markup-list layout props
70        (make-justified-lines-markup-list (cons (make-hspace-markup indent)
71                                                args)))))
73 conditionalBreak = #(define-music-function (parser location) ()
74    #{ \tag #'instrumental-score \pageBreak #}
77 #(define (oly:piece-title-markup title) (markup #:column (#:line (#:fontsize #'3 #:bold title))) )
79 #(define-markup-command (piece-title layout props title) (markup?)
80      (interpret-markup layout props (oly:piece-title-markup title))
83 #(define (oly:generate_object_name piece instr obj )
84   (if (and (string? piece) (string? instr) (string? obj))
85     (string-append piece instr obj)
86     #f
87   )
89 #(define (oly:generate_staff_name piece instr) (oly:generate_object_name piece instr "St"))
91 #(define (set-context-property context property value)
92   (set! (ly:music-property context property) value)
96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97 % Score structure and voice types
98 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100 #(define oly:LiedScoreStructure '(
101   ("SoloScore" "SimultaneousMusic" ("Singstimme"))
102   ("Pfe" "PianoStaff" ("PfeI" "PfeII"))
103   ;("PfeI" "ParallelVoicesStaff" ("OIa" "OIb"))
104   ;("PfeII" "ParallelVoicesStaff" ("OIIa" "OIIb"))
105   ("FullScore" "SimultaneousMusic" ("Singstimme" "Pfe"))
106   ("VocalScore" "SimultaneousMusic" ("Singstimme" "Pfe"))
109 #(define oly:StringEnsembleScoreStructure '(
110   ("FullScore" "StaffGroup" ("VI" "VII" "Va" "Vc" "Cb" "VcB"))
113 #(define oly:fullOrchestraScoreStructure '(
114 ; Part-combined staves for full score
115   ("Fl" "PartCombinedStaff" ("FlI" "FlII"))
116   ("Ob" "PartCombinedStaff" ("ObI" "ObII"))
117   ("Cl" "PartCombinedStaff" ("ClI" "ClII"))
118   ("Fag" "PartCombinedStaff" ("FagI" "FagII"))
119   ("Wd" "StaffGroup" ("Fl" "Ob" "Cl" "Fag" "CFag"))
121   ("Cor" "PartCombinedStaff" ("CorI" "CorII"))
122   ("Tbe" "PartCombinedStaff" ("TbeI" "TbeII"))
123   ("Clni" "PartCombinedStaff" ("ClnoI" "ClnoII"))
124   ("Trb" "PartCombinedStaff" ("TrbI" "TrbII"))
125   ("Br" "StaffGroup" ("Cor" "Tbe" "Clni" "Trb" "Tba"))
127 ; long score; no part-combined staves, but GrandStaves instead
128   ("FlLong" "GrandStaff" ("FlI" "FlII"))
129   ("ObLong" "GrandStaff" ("ObI" "ObII"))
130   ("ClLong" "GrandStaff" ("ClI" "ClII"))
131   ("FagLong" "GrandStaff" ("FagI" "FagII"))
132   ("WdLong" "StaffGroup" ("FlLong" "ObLong" "ClLong" "FagLong" "CFag"))
134   ("CorLong" "GrandStaff" ("CorI" "CorII"))
135   ("TbeLong" "GrandStaff" ("TbeI" "TbeII"))
136   ("ClniLong" "GrandStaff" ("ClnoI" "ClnoII" "ClnoIII"))
137   ("TrbLong" "GrandStaff" ("TrbI" "TrbII" "TrbIII"))
138   ("BrLong" "StaffGroup" ("CorLong" "TbeLong" "ClniLong" "TrbLong" "Tba"))
140 ; Percussion
141   ("Perc" "StaffGroup" ("Tim"))
143 ; Strings, they are the same in long and short full score
144   ("VV" "GrandStaff" ("VI" "VII"))
145   ("Str" "StaffGroup" ("VV" "Va"))
146   ("VceB" "StaffGroup" ("Vc" "Cb" "VcB"))
147   ("FullStr" "StaffGroup" ("VV" "Va" "Vc" "Cb" "VcB"))
149 ; Choral score
150   ("Solo" "SimultaneousMusic" ("SSolo" "ASolo" "TSolo" "BSolo"))
151   ("Ch" "ChoirStaff" ("S" "A" "T" "B"))
152   ("ChoralScore" "SimultaneousMusic" ("Ch"))
153   ("SoloScore" "SimultaneousMusic" ("Solo"))
154   ("SoloChoirScore" "SimultaneousMusic" ("Solo" "Ch"))
156 ; Organ score (inkl. Figured bass)
157   ("BCFb" "FiguredBass" ())
158   ("FiguredBass" "FiguredBass" ())
159   ;("Organ" "SimultaneousMusic" ("BCFb" "O"))
160   ("Continuo" "ParallelVoicesStaff" ("BCFb" "BC" "FiguredBass"))
161   ("RealizedContinuo" "PianoStaff" ("BCRealization" "Continuo"))
163   ("P" "PianoStaff" ("PI" "PII"))
164   ("O" "PianoStaff" ("OI" "OII"))
165   ("OI" "ParallelVoicesStaff" ("OIa" "OIb"))
166   ("OII" "ParallelVoicesStaff" ("OIIa" "OIIb"))
168   ;("Organ" "SimultaneousMusic" ("OGroup" "RealizedContinuo"))
169   ;("BassGroup" "ParallelVoicesStaff" ("Organ" "O" "BC" "VceB"))
170   ("BassGroup" "StaffGroup" ("O" "RealizedContinuo" "Vc" "Cb" "VcB"))
172 ; Full Scores
173   ("FullScore" "SimultaneousMusic" ("Wd" "Br" "Perc" "Str" "SoloChoirScore" "BassGroup"))
174   ("LongScore" "SimultaneousMusic" ("WdLong" "BrLong" "Perc" "Str" "SoloChoirScore" "BassGroup"))
175   ("OriginalScore" "SimultaneousMusic" ("BrLong" "WdLong" "Perc" "Str" "SoloChoirScore" "BassGroup"))
177 ; Piano reduction
178   ;("Piano" "SimultaneousMusic" ("Organ"))
179   ("OrganScore" "SimultaneousMusic" ("SoloChoirScore" "O"))
180   ("VocalScore" "SimultaneousMusic" ("SoloChoirScore" "P"))
181   ("Particell"  "SimultaneousMusic" ("ChoralScore" "BassGroup"))
183 ; Full scores: Orchestral score and long score including organ
184   ("ChStrQ" "SimultaneousMusic" ("Str" "Ch" "VceB"))
186 #(define oly:orchestral_score_structure oly:fullOrchestraScoreStructure)
188 #(define (oly:set_score_structure struct)
189   (if (list? struct)
190     (set! oly:orchestral_score_structure struct)
191     (ly:warning (_ "oly:set_score_structure needs an association list as argument!"))
192   )
195 #(define (oly:modify_score_structure entry)
196   (if (list? entry)
197     (set! oly:orchestral_score_structure (assoc-set! oly:orchestral_score_structure  (car entry) (cdr entry)))
198     (ly:warning (_ "oly:modify_score_structure expects a list (\"key\" \"type\" '(children)) as argument!"))))
200 #(define (oly:remove_from_score_structure entry)
201   (if (list? entry)
202     (map oly:remove_from_score_structure entry)
203     (set! oly:orchestral_score_structure (assoc-remove! oly:orchestral_score_structure  entry))))
205 orchestralScoreStructure = #(define-music-function (parser location structure) (list?)
206   (oly:set_score_structure structure)
207   (make-music 'Music 'void #t)
210 #(define oly:voice_types '())
212 #(define (oly:set_voice_types types)
213   (if (list? types)
214     (set! oly:voice_types types)
215     (ly:warning (_ "oly:set_voice_types needs an association list as argument!"))
216   )
219 orchestralVoiceTypes = #(define-music-function (parser location types) (list?)
220   (oly:set_voice_types types)
221   (make-music 'Music 'void #t)
225 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226 % Automatic staff and group generation
227 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
229 % Retrieve all music definitions for the given
230 #(define (oly:get_music_object piece instrument)
231   (namedPieceInstrObject piece instrument "Music")
233 #(define (oly:get_music_objects piece instruments)
234   (filter not-null? (map (lambda (i) (oly:get_music_object piece i)) instruments))
237 % Given a property name and the extensions, either generate the pair to set
238 % the property or an empty list, if no pre-defined variable could be found
239 #(define (oly:generate_property_pair prop piece instr type)
240   (let* ((val (namedPieceInstrObject piece instr type)))
241     (if (not-null? val) (list 'assign prop val) '() )
242   )
245 #(define (oly:staff_type type)
246   (cond
247     ((string? type) (string->symbol type))
248     ((symbol? type) type)
249     (else 'Staff)
250   )
253 % extract the pitch from the music (can also be a raw pitch object!)
254 #(define (oly:extractPitch music)
255   (let* (
256          (elems  (if (ly:music? music) (ly:music-property music 'elements)))
257          (note   (if (pair? elems) (car elems)))
258          (mpitch (if (ly:music? note) (ly:music-property note 'pitch)))
259          (pitch  (if (ly:pitch? music) music mpitch))
260         )
261     (if (and (not-null? music) (not (ly:pitch? pitch)))
262       (ly:warning "Unable to interpret as a pitch!")
263     )
264     pitch
265   )
268 #(define (oly:extractTranspositionPitch piece name)
269   (let* (
270          (trpFromPitch (oly:extractPitch (namedPieceInstrObject piece name "TransposeFrom")))
271          (trpToPitch   (oly:extractPitch (namedPieceInstrObject piece name "TransposeTo")))
272         )
273     (if (ly:pitch? trpFromPitch)
274       (if (ly:pitch? trpToPitch)
275         ; Both pitches
276         (ly:pitch-diff trpFromPitch trpToPitch)
277         (ly:pitch-diff trpFromPitch (ly:make-pitch 0 0 0))
278       )
279       (if (ly:pitch? trpToPitch)
280         (ly:pitch-diff (ly:make-pitch 0 0 0) trpToPitch)
281         #f
282       )
283     )
284   )
288 %%=====================================================================
289 %% Extract context modifications for given objects
290 %%---------------------------------------------------------------------
293 % TODO: join these property extractors to avoid code duplication
295 % Generate the properties for the lyrics for piece and instr.
296 % Also check whether we have a modifications object to fech mods from.
297 % return a (possibly empty) list of all assignments.
298 #(define (oly:lyrics_handler_properties piece name lyricsid)
299   (let* (
300          (mods (namedPieceInstrObject piece name (string-append lyricsid "Modifications")))
301          (mod-list (if (not-null? mods) (ly:get-context-mods mods) '()))
302          (mapping '(
303              ;(instrumentName . "InstrumentName")
304              ;(shortInstrumentName . "ShortInstrumentName")
305              ;(midiInstrument . "MidiInstrument")
306             ))
307          (assignments (map
308              (lambda (pr)
309                  (oly:generate_property_pair (car pr) piece name (cdr pr))
310              )
311              mapping))
312          (olyprops (filter not-null? assignments))
313          (props (append mod-list olyprops))
314         )
315     props
316   )
319 % Generate the properties for the voice for piece and instr.
320 % Also check whether we have a modifications object to fech mods from.
321 % return a (possibly empty) list of all assignments.
322 #(define (oly:voice_handler_properties piece name)
323   (let* (
324          (mods (namedPieceInstrObject piece name "VoiceModifications"))
325          (mod-list (if (not-null? mods) (ly:get-context-mods mods) '()))
326          (mapping '(
327              ;(instrumentName . "InstrumentName")
328              ;(shortInstrumentName . "ShortInstrumentName")
329              ;(midiInstrument . "MidiInstrument")
330             ))
331          (assignments (map
332              (lambda (pr)
333                  (oly:generate_property_pair (car pr) piece name (cdr pr))
334              )
335              mapping))
336          (olyprops (filter not-null? assignments))
337          (props (append mod-list olyprops))
338         )
339     props
340   )
343 % Generate the properties for the staff for piece and instr. Typically, these
344 % are the instrument name and the short instrument name (if defined).
345 % Also check whether we have a modifications object to fech mods from.
346 % return a (possibly empty) list of all assignments.
347 #(define (oly:staff_handler_properties piece instr)
348   (let* (
349          (mods (namedPieceInstrObject piece instr "StaffModifications"))
350          (mod-list (if (not-null? mods) (ly:get-context-mods mods) '()))
351          (mapping '(
352               (instrumentName . "InstrumentName")
353               (shortInstrumentName . "ShortInstrumentName")
354               (midiInstrument . "MidiInstrument")
355             ))
356          (assignments (map
357              (lambda (pr)
358                  (oly:generate_property_pair (car pr) piece instr (cdr pr))
359              )
360              mapping))
361          (olyprops (filter not-null? assignments))
362          (props (append mod-list olyprops))
363         )
364     props
365   )
371 %%=====================================================================
372 %% Extract contents for voices
373 %%---------------------------------------------------------------------
375 #(define (oly:musiccontent_for_voice parser piece name music additional)
376   (let* ((musiccontent additional))
378     ; Append the settings, key and clef (if defined)
379     (map
380       (lambda (type)
381         (let* ((object (namedPieceInstrObject piece name type)))
382           (if (ly:music? object)
383             (set! musiccontent (append musiccontent (list (ly:music-deep-copy object))))
384             (if (not-null? object) (ly:warning (_ "Wrong type (no ly:music) for ~S for instrument ~S in piece ~S") type name piece))
385           )
386         )
387       )
388       ; TODO: Does the "Tempo" work here???
389       '("Settings" "Key" "Clef" "TimeSignature" "ExtraSettings";"Tempo"
390       )
391     )
393     (if (ly:music? music)
394       (begin
395         (set! musiccontent (make-simultaneous-music (append musiccontent (list music))))
396         ;(ly:message "Generating staff for ~a" name)
397         (let* ((trpPitch (oly:extractTranspositionPitch piece name)))
398           (if (ly:pitch? trpPitch)
399             (set! musiccontent (ly:music-transpose musiccontent trpPitch))
400           )
401         )
402         musiccontent
403       )
404       ; For empty music, return empty
405       '()
406     )
407   )
412 %%=====================================================================
413 %% create Lyrics
414 %%---------------------------------------------------------------------
417 #(define (oly:lyrics_create_single_context parser piece name voicename lyricsid)
418   ; If we have lyrics, create a lyrics context containing LyricCombineMusic
419   ; and add that as second element to the staff's elements list...
420   ; Also add possibly configured LyricsModifications
421   (let* ((id (string-append "Lyrics" lyricsid))
422          (lyricsmods (oly:lyrics_handler_properties piece name id))
423          (lyrics (namedPieceInstrObject piece name id))
424          (ctx (if (ly:music? lyrics)
425                   (context-spec-music (make-music 'LyricCombineMusic
426                                                   'element lyrics
427                                                   'associated-context voicename)
428                                       'Lyrics
429                                       (oly:generate_object_name piece name id))
430                   '())))
431     (if (and (not-null? lyricsmods) (not-null? ctx))
432       (set! (ly:music-property ctx 'property-operations) lyricsmods)
433     )
434     ctx
435   )
438 #(define (oly:lyrics_create_contexts parser piece name voicename)
439   (filter not-null?
440     (map (lambda (str)
441                  (oly:lyrics_create_single_context parser piece name voicename str))
442          (list "" "I" "II" "III"  "IV" "V" "VI"))))
445 %%=====================================================================
446 %% Voice handling
447 %%---------------------------------------------------------------------
450 #(define (oly:voice_handler_internal parser piece name type music)
451   (if (ly:music? music)
452     (let* (
453            (voicename    (oly:generate_object_name piece name "Voice" ))
454            (lyrics       (oly:lyrics_create_contexts parser piece name voicename))
455            (additional   (if (not-null? lyrics) (list dynamicUp) '()))
456            (musiccontent (oly:musiccontent_for_voice parser piece name music additional))
457            (voicetype    (oly:staff_type type))
458            (voice        (context-spec-music musiccontent voicetype voicename))
459            (voiceprops   (oly:voice_handler_properties piece name))
460           )
461       (if (not-null? voiceprops)
462         (set! (ly:music-property voice 'property-operations) voiceprops)
463       )
464       (cons voice lyrics)
465     )
466     ; For empty music, return empty
467     '()
468   )
471 #(define (oly:voice_handler parser piece name type)
472   (oly:voice_handler_internal parser piece name type (oly:get_music_object piece name)))
475 %%=====================================================================
476 %% Staff/Group handling
477 %%---------------------------------------------------------------------
480 #(define (oly:staff_handler_internal parser piece name type voices)
481   (if (not-null? voices)
482     (let* (
483            (staffname  (oly:generate_staff_name piece name))
484            (stafftype  (oly:staff_type type))
485            (staff      (make-simultaneous-music voices))
486            (propops    (oly:staff_handler_properties piece name))
487           )
488       (case stafftype
489         ((SimultaneousMusic ParallelMusic) #f)
490         (else (set! staff (context-spec-music staff stafftype staffname)))
491       )
492       (if (not-null? propops)
493         (set! (ly:music-property staff 'property-operations) propops)
494       )
495       staff
496     )
497     ; For empty music, return empty
498     '()
499   )
502 #(define (oly:staff_handler parser piece name type children)
503   (let* ((c (if (not-null? children) children (list name)))
504          (voices (apply append (map (lambda (v) (oly:create_voice parser piece v)) c)) )
505         )
506     (if (not-null? voices)
507       (oly:staff_handler_internal parser piece name type voices)
508       '()
509     )
510   )
513 #(define (oly:devnull_handler parser piece name type children)
514   (oly:voice_handler parser piece name type)
517 #(define (oly:parallel_voices_staff_handler parser piece name type children)
518   (let* (
519          (voices (map (lambda (i) (oly:create_voice parser piece i)) children))
520          ; get the list of non-empty voices and flatten it!
521          (nonemptyvoices (apply append (filter not-null? voices)))
522         )
523     (if (not-null? nonemptyvoices)
524       (oly:staff_handler_internal parser piece name "Staff" nonemptyvoices)
525       '()
526     )
527   )
530 #(define (oly:remove-with-tag tag music)
531   (if (ly:music? music)
532       (music-filter
533         (lambda (m)
534           (let* ((tags (ly:music-property m 'tags))
535                  (res (memq tag tags)))
536             (not res)))
537         music)
538       music))
540 % Remove all music tagged a not-part-combine
541 #(define (oly:remove-non-part-combine-events music)
542   (oly:remove-with-tag 'non-partcombine music))
544 #(define (oly:part_combined_staff_handler parser piece name type children)
545   (let* ((rawmusic (map (lambda (c) (oly:musiccontent_for_voice parser piece name (oly:get_music_object piece c) '())) children))
546          (filteredmusic (map (lambda (m) (oly:remove-non-part-combine-events m)) rawmusic))
547          (music (filter not-null? filteredmusic)))
548   (cond
549       ((and (pair? music) (ly:music? (car music)) (not-null? (cdr music)) (ly:music? (cadr music)))
550           ;(ly:message "Part-combine with two music expressions")
551           (oly:staff_handler_internal parser piece name "Staff" (list (make-part-combine-music parser music #f))))
552       ((null? music)
553           ;;(ly:warning "Part-combine without any music expressions")
554           '())
555       ; exactly one is a music expression, simply use that by joining
556       ((list? music)
557           ;;(ly:message "Part-combine with only one music expressions")
558           (oly:staff_handler_internal parser piece name "Staff" (list (apply append music))))
559       (else
560           ;(ly:message "make_part_combined_staff: ~S ~S ~a" piece instr instruments)
561           '() )
562     )
563   )
566 % Figured bass is a special case, as it can be voice- or staff-type. When
567 % given as a staff type, simply call the voice handler, instead
569 #(define (oly:figured_bass_staff_handler parser piece name type children)
570   (let* ((c (if (not-null? children) children (list name)))
571          (voice  (oly:voice_handler parser piece (car c) type)))
572     (if (pair? voice) (car voice) ())
573   )
576 #(define (flatten lst)
577   (define (f remaining result)
578     (cond
579       ((null? remaining) result)
580       ((pair? (car remaining)) (f (cdr remaining) (f (car remaining) result)))
581       (else (f (cdr remaining) (cons (car remaining) result)))))
582   (reverse! (f lst '())))
584 #(define (oly:staff_group_handler parser piece name type children)
585   (let* (
586          (staves (flatten (map (lambda (i) (oly:create_staff_or_group parser piece i)) children)))
587          (nonemptystaves (filter not-null? staves))
588         )
589     (if (not-null? nonemptystaves)
590       (let* (
591              (musicexpr (if (= 1 (length nonemptystaves))
592                           (car nonemptystaves)
593                           (make-simultaneous-music nonemptystaves)))
594              (groupname (oly:generate_staff_name piece name))
595              (grouptype (oly:staff_type type))
596              (group     musicexpr)
597              (propops   (oly:staff_handler_properties piece name))
598             )
599         (case grouptype
600           ((SimultaneousMusic ParallelMusic) #f)
601           (else (set! group (context-spec-music group grouptype groupname)))
602         )
603         (if (pair? propops)
604           (set! (ly:music-property group 'property-operations) propops))
605         group
606       )
607       ; Return empty list if no staves are generated
608       '()
609     )
610   )
613 #(define (oly:create_voice parser piece name)
614   (let* ( (voice (namedPieceInstrObject piece name "Voice"))
615           (type (assoc-ref oly:voice_types name)) )
616     (if (not-null? voice)
617       ; Explicit voice variable, use that
618       voice
620       (if (not type)
621         ; No entry in structure found => simple voice
622         (oly:voice_handler parser piece name "Voice")
623         ; Entry found in structure => use the handler for the given type
624         (let* (
625                (voicetype (car type))
626                (handler (assoc-ref oly:voice_handlers voicetype))
627               )
628           (if handler
629             ((primitive-eval handler) parser piece name voicetype)
630             (begin
631               (ly:warning "No handler found for voice type ~a, using default voice handler" voicetype)
632               (oly:voice_handler parser piece name voicetype)
633             )
634           )
635         )
636       )
637     )
638   )
641 #(define (oly:create_staff_or_group parser piece name)
642   (let* ( (staff (namedPieceInstrObject piece name "Staff"))
643           (type_from_structure (assoc-ref oly:orchestral_score_structure name)) )
644     ;(if (not-null? staff)
645     ;  (ly:message "Found staff variable for instrument ~a in piece ~a"  instr piece)
646     ;  (ly:message "Staff variable for instrument ~a in piece ~a NOT FOUND"  instr piece)
647     ;)
648     (if (not-null? staff)
649       ; Explicit staff variable, use that
650       staff
652       (if (not (list? type_from_structure))
653         ; No entry in structure found => simple staff
654         (oly:staff_handler parser piece name "Staff" '())
656         ; Entry found in structure => use the handler for the given type
657         (let* ((type (car type_from_structure))
658                (handler (assoc-ref oly:staff_handlers type))
659                (children (cadr type_from_structure))
660               )
661           (if handler
662             ((primitive-eval handler) parser piece name type children)
663             (begin
664               (ly:warning "No handler found for staff type ~a, using default staff handler" type)
665               (oly:staff_handler parser piece name type children)
666             )
667           )
668         )
669       )
670     )
671   )
674 #(define (oly:dynamics_handler parser piece name type children)
675   (oly:voice_handler parser piece name type)
679 %%=====================================================================
680 %% Handler definitions
681 %%---------------------------------------------------------------------
683 #(define oly:staff_handlers
684   (list
685     ; staff group types
686     '("GrandStaff" . oly:staff_group_handler )
687     '("PianoStaff" . oly:staff_group_handler )
688     '("ChoirStaff" . oly:staff_group_handler )
689     '("StaffGroup" . oly:staff_group_handler )
690     '("ParallelMusic" . oly:staff_group_handler )
691     '("SimultaneousMusic" . oly:staff_group_handler )
692     ; staff types
693     '("Staff" . oly:staff_handler )
694     '("DrumStaff" . oly:staff_handler )
695     '("RhythmicStaff" . oly:staff_handler )
696     '("TabStaff" . oly:staff_handler )
697     '("GregorianTranscriptionStaff" . oly:staff_handler )
698     '("MensuralStaff" . oly:staff_handler )
699     '("VaticanaStaff" . oly:staff_handler )
700     ; staves with multiple voices
701     '("PartCombinedStaff" . oly:part_combined_staff_handler )
702     '("ParallelVoicesStaff" . oly:parallel_voices_staff_handler )
703     ; special cases: Figured bass can be staff or voice type!
704     '("FiguredBass" . oly:figured_bass_staff_handler )
705     ; Devnull is like a staff, only that it doesn't craete output
706     '("Devnull" . oly:devnull_handler )
707     '("Dynamics" . oly:dynamics_handler )
708   )
711 #(define oly:voice_handlers
712   (list
713     ; voice types
714     '("Voice" . oly:voice_handler )
715     '("CueVoice" . oly:voice_handler )
716     '("DrumVoice" . oly:voice_handler )
717     '("FiguredBass" . oly:voice_handler )
718     '("GregorianTranscriptionVoice" . oly:voice_handler )
719     '("NoteNames" . oly:voice_handler )
720     '("TabVoice" . oly:voice_handler )
721     '("VaticanaVoice" . oly:voice_handler )
722   )
726 #(define (oly:register_staff_type_handler type func)
727 ;  (ly:message "Registering staff handler ~a for type ~a" func type)
728   (set! oly:staff_handlers (assoc-set! oly:staff_handlers type func))
731 #(define (oly:register_voice_type_handler type func)
732 ;  (ly:message "Registering voice type handler ~a for type ~a" func type)
733   (set! oly:voice_handlers (assoc-set! oly:voice_handlers type func))
736 % handlers for deprecated API
737 #(oly:register_staff_type_handler 'StaffGroup 'oly:staff_group_handler)
738 #(oly:register_staff_type_handler 'GrandStaff 'oly:staff_group_handler)
739 #(oly:register_staff_type_handler 'PianoStaff 'oly:staff_group_handler)
740 #(oly:register_staff_type_handler 'ChoirStaff 'oly:staff_group_handler)
741 #(oly:register_staff_type_handler 'Staff 'oly:staff_handler )
742 #(oly:register_staff_type_handler 'ParallelMusic 'oly:staff_group_handler)
743 #(oly:register_staff_type_handler 'SimultaneousMusic 'oly:staff_group_handler)
744 #(oly:register_staff_type_handler #t 'oly:part_combined_staff_handler )
745 #(oly:register_staff_type_handler #f 'oly:parallel_voices_staff_handler )
749 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
750 % Automatic score generation
751 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
753 #(define oly:score_handler add-score)
754 #(define oly:music_handler add-music)
755 #(define oly:text_handler add-text)
758 % TODO: deprecate
759 setUseBook = #(define-music-function (parser location usebook) (boolean?)
760   (ly:warning "\\setUseBook has been deprecated! Books are now automatically handled without any hacks")
761   (make-music 'Music 'void #t)
765 % Two functions to handle midi-blocks: Either don't set one, or set an empty
766 % one so that MIDI is generated
767 #(define (oly:set_no_midi_block score) '())
768 #(define (oly:set_midi_block score)
769   (let* ((midiblock (if (defined? '$defaultmidi)
770                         (ly:output-def-clone $defaultmidi)
771                         (ly:make-output-def))))
772     (ly:output-def-set-variable! midiblock 'is-midi #t)
773     (ly:score-add-output-def! score midiblock)
774   )
777 % \setCreateMidi ##t/##f sets a flag to determine wheter MIDI output should
778 % be generated
779 #(define oly:apply_score_midi oly:set_no_midi_block)
780 setCreateMIDI = #(define-music-function (parser location createmidi) (boolean?)
781   (if createmidi
782     (set! oly:apply_score_midi oly:set_midi_block)
783     (set! oly:apply_score_midi oly:set_no_midi_block)
784   )
785   (make-music 'Music 'void #t)
789 % Two functions to handle layout-blocks: Either don't set one, or set an empty
790 % one so that a PDF is generated
791 #(define (oly:set_no_layout_block score) '())
792 #(define (oly:set_layout_block score)
793   (let* ((layoutblock (if (defined? '$defaultlayout)
794                         (ly:output-def-clone $defaultlayout)
795                         (ly:make-output-def))))
796     (ly:output-def-set-variable! layoutblock 'is-layout #t)
797     (ly:score-add-output-def! score layoutblock)
798   )
801 % \setCreatePDF ##t/##f sets a flag to determine wheter PDF output should
802 % be generated
803 #(define oly:apply_score_layout oly:set_no_layout_block)
804 setCreatePDF = #(define-music-function (parser location createlayout) (boolean?)
805   (if createlayout
806     (set! oly:apply_score_layout oly:set_layout_block)
807     (set! oly:apply_score_layout oly:set_no_layout_block)
808   )
809   (make-music 'Music 'void #t)
813 % Set the piece title in a new header block.
814 #(define (oly:set_piece_header score piecename)
815   (if (not-null? piecename)
816     (let* ((header (make-module)))
817       (module-define! header 'piece piecename)
818       (ly:score-set-header! score header)
819     )
820   )
824 % post-filter functions. By default, no filtering is done. However,
825 % for the *NoCues* function, the cue notes should be killed
826 keepcuefilter = #(define-music-function (parser location music) (ly:music?)
827   ((ly:music-function-extract removeWithTag) parser location 'non-cued music))
828 removecuefilter = #(define-music-function (parser location music) (ly:music?)
829   ((ly:music-function-extract removeWithTag) parser location 'cued ((ly:music-function-extract killCues) parser location music)))
832 #(define (oly:create-toc-file layout pages)
833   (let* ((label-table (ly:output-def-lookup layout 'label-page-table))
834          ;; The page numbers are pages counts in the pdf file, not visible page number!
835          ;; So we have to offset them if the first page is not page #1
836          (first-page-offset (1- (ly:output-def-lookup layout 'first-page-number))))
837     (if (not (null? label-table))
838       (let* ((format-line (lambda (toc-item)
839              (let* ((label (car toc-item))
840                     (text  (caddr toc-item))
841                     (label-page (and (list? label-table)
842                                      (assoc label label-table)))
843                     (page (and label-page (cdr label-page))))
844                (format #f "~a, section, 1, {~a}, ~a" (- page first-page-offset) text label))))
845              (formatted-toc-items (map format-line (toc-items)))
846              (whole-string (string-join formatted-toc-items ",\n"))
847              (output-name (ly:parser-output-name parser))
848              (outfilename (format "~a.toc" output-name))
849              (outfile (open-output-file outfilename)))
850         (if (output-port? outfile)
851             (display whole-string outfile)
852             (ly:warning (_ "Unable to open output file ~a for the TOC information") outfilename))
853         (close-output-port outfile)))))
856 #(define-public (oly:add-toc-item parser markup-symbol text)
857   (oly:music_handler parser (add-toc-item! markup-symbol text)))
860 #(define (oly:add-score parser score piecename)
861   (if (not-null? piecename)
862     (oly:add-toc-item parser 'tocItemMarkup piecename))
863   (oly:score_handler parser score)
865 % The helper function to build a score.
866 #(define (oly:createScoreHelper parser location piece children func)
867   (let* (
868          (staves    (oly:staff_group_handler parser piece "" "SimultaneousMusic" children))
869          (music     (if (not-null? staves)
870                         ((ly:music-function-extract func) parser location staves)
871                         '()
872                     ))
873          (score     '())
874          (piecename (namedPieceInstrObject piece (car children) "PieceName"))
875          (piecenametacet (namedPieceInstrObject piece (car children) "PieceNameTacet"))
876          (header    '())
877         )
878     (if (null? music)
879       ; No staves, print tacet
880       (begin
881         (if (not-null? piecenametacet) (set! piecename piecenametacet))
882         (if (not-null? piecename)
883           (oly:add-score parser (list (oly:piece-title-markup piecename)) piecename)
884           (ly:warning (_ "No music and no score title found for part ~a and instrument ~a") piece children)
885         )
886       )
887       ; we have staves, apply the piecename to the score and add layout/midi blocks if needed
888       (begin
889         (set! score (scorify-music music parser))
890         (oly:set_piece_header score piecename)
891         (oly:apply_score_midi score)
892         (oly:apply_score_layout score)
893         ; Schedule the score for typesetting
894         (oly:add-score parser score piecename)
895       )
896     )
897   )
898   ; This is a void function, the score has been schedulled for typesetting already
899   (make-music 'Music 'void #t)
902 createVoice = #(define-music-function (parser location piece name) (string? string?)
903   (let* ((vc (oly:create_voice parser piece name)))
904     (make-music 'SimultaneousMusic
905                 'elements vc)))
907 createStaff = #(define-music-function (parser location piece name) (string? string?)
908   (oly:create_staff_or_group parser piece name))
909 createStaffForContents = #(define-music-function (parser location piece name contents) (string? string? ly:music?)
910   (let* ((tstruct (assoc-ref oly:orchestral_score_structure name))
911          (type (if (list? tstruct) (car tstruct) "Staff")))
912     (oly:staff_handler_internal parser piece name type (list contents))))
915 createScore = #(define-music-function (parser location piece children) (string? list?)
916   (oly:createScoreHelper parser location piece children keepcuefilter)
918 createNoCuesScore = #(define-music-function (parser location piece children) (string? list?)
919   (oly:createScoreHelper parser location piece children removecuefilter)
922 createHeadline = #(define-music-function (parser location headline) (string?)
923   (oly:add-toc-item parser 'tocItemMarkup headline)
924   (oly:score_handler parser (list (oly:piece-title-markup headline)))
925   (make-music 'Music 'void #t)
930 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
931 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
932 %%%%%   CUE NOTES
933 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
934 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
936 newInstrument = #(define-music-function (parser location instr) (string?)
938   \set Voice.instrumentCueName = #(string-join (list "+" instr))
941 cueText = #(define-music-function (parser location instr) (string?)
943   \set Voice.instrumentCueName = $instr
946 cueMarkup = #(define-music-function (parser location instr) (markup?)
948   \set Voice.instrumentCueName = $instr
952 clearCueText = #(define-music-function (parser location) ()
954   \unset Voice.instrumentCueName
958 insertCueText = #(define-music-function (parser location instr) (string?)
959   (if (string-null? instr)
960     #{ \tag #'cued \clearCueText #}
961     #{ \tag #'cued \cueText #instr #}
964 % generate a cue music section with instrument names
965 % Parameters: \namedCueDuring NameOfQuote CueDirection CueInstrument OriginalInstrument music
966 %                 -) NameOfQuote CueDirection music are the parameters for \cueDuring
967 %                 -) CueInstrument and OriginalInstrument are the displayed instrument names
968 % typical call:
969 % \namedCueDuring #"vIQuote" #UP #"V.I" #"Sop." { R1*3 }
970 %      This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
971 %      the beginning of the cue notes and "Sop." at the end
972 namedCueDuring = #(define-music-function (parser location cuevoice direction instrcue instr cuemusic) (string? number? string? string? ly:music?)
974   \cueDuring #cuevoice #direction {
975     \insertCueText #instrcue
976     $cuemusic
977     \insertCueText #instr
978   }
981 namedTransposedCueDuring = #(define-music-function (parser location cuevoice direction instrcue instr trans cuemusic) (string? number? string? string? ly:music? ly:music?)
982    #{
983      \transposedCueDuring #cuevoice #direction #trans {
984        \insertCueText #instrcue
985        #cuemusic
986        \insertCueText #instr
987      }
988    #}
991 % set the cue instrument name and clef
992 setClefCue = #(define-music-function (parser location instr clef)
993                                                      (string? ly:music?)
994    #{
995      \once \override Staff.Clef #'font-size = #-3 #clef
996      \insertCueText #instr
997    #} )
999 % generate a cue music section with instrument names and clef changes
1000 % Parameters: \cleffedCueDuring NameOfQuote CueDirection CueInstrument CueClef OriginalInstrument OriginalClef music
1001 %                 -) NameOfQuote CueDirection music are the parameters for \cueDuring
1002 %                 -) CueInstrument and OriginalInstrument are the displayed instrument names
1003 %                 -) CueClef and OriginalClef are the clefs for the the cue notes and the clef of the containing voice
1004 % typical call:
1005 % \cleffedCueDuring #"vIQuote" #UP #"V.I" #"treble" #"Basso" #"bass" { R1*3 }
1006 %      This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
1007 %      the beginning of the cue notes and "Basso" at the end. The clef is changed to treble at the
1008 %      beginning of the cue notes and reset to bass at the end
1009 cleffedCueDuring = #(define-music-function (parser location cuevoice direction instrcue clefcue instr clefinstr cuemusic)
1010                                                         (string? number? string? ly:music? string? ly:music? ly:music?)
1011    #{
1012      \cueDuring #cuevoice #direction {
1013        \tag #'cued \setClefCue #instrcue #clefcue
1014        #cuemusic
1015        \tag #'cued \setClefCue #instr #clefinstr
1016      }
1017    #}
1019 % generate a cue music section with instrument names and clef changes
1020 % Parameters: \namedCueDuringClef NameOfQuote CueDirection CueInstrument CueClef OriginalInstrument music
1021 %                 -) NameOfQuote CueDirection music are the parameters for \cueDuring
1022 %                 -) CueInstrument and OriginalInstrument are the displayed instrument names
1023 %                 -) CueClef is the clef for the the cue notes
1024 % typical call:
1025 % \namedCueDuringClef #"vIQuote" #UP #"V.I" #"treble" #"Basso" { R1*3 }
1026 %      This adds the notes from vIQuote (defined via \addQuote) to three measures, prints "V.I" at
1027 %      the beginning of the cue notes and "Basso" at the end. The clef is changed to treble at the
1028 %      beginning of the cue notes and reset to bass at the end
1029 namedCueDuringWithClef = #(define-music-function (parser location cuevoice direction instrcue clefcue instr cuemusic)
1030                                              (string? number? string? string? string? ly:music?)
1031    #{
1032      \cueDuringWithClef #cuevoice #direction #clefcue {
1033        \insertCueText #instrcue
1034        #cuemusic
1035        \insertCueText #instr
1036      }
1037    #}
1042 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1043 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1044 %%%%%   DYNAMICS
1045 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1046 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1049 dynamicsX = #(define-music-function (parser location offset) (number?)
1051     \once \override DynamicText #'X-offset = $offset
1052     \once \override DynamicLineSpanner #'Y-offset = #0
1055 % Move the dynamic sign inside the staff to a fixed staff-relative position
1056 % posY (where 0 means vertically starts at the middle staff line)
1057 dynamicsAllInside = #(define-music-function (parser location offsetX posY)
1058 (number? number?)
1060   % Invalid y-extent -> hidden from skyline calculation and collisions
1061 %   \once \override DynamicLineSpanner #'Y-extent = #(cons +0 -0.01)
1062   \once \override DynamicLineSpanner #'Y-extent = $(lambda (grob)
1063     (let* ((ext (ly:axis-group-interface::height grob))
1064            (dir (ly:grob-property grob 'direction)))
1065       (if (eq? dir UP)
1066             (cons (- (cdr ext) 0.1) (cdr ext))
1067             (cons (car ext)         (+ (car ext) 0.1)))))
1068   % move by X offset and to fixed Y-position (use Y-offset of parent!)
1069   \once \override DynamicText #'X-offset = $offsetX
1070   \once \override DynamicText #'Y-offset =
1071     $(lambda (grob)
1072        (let* ((head (ly:grob-parent grob Y))
1073               (offset (ly:grob-property head 'Y-offset)))
1074          (- posY  offset (- 0.6))))
1075   \once \override DynamicLineSpanner #'Y-offset = $posY
1078 dynamicsUpInside = #(define-music-function (parser location offsetX) (number?)
1079   ((ly:music-function-extract dynamicsAllInside) parser location offsetX 1.5)
1082 dynamicsDownInside = #(define-music-function (parser location offsetX) (number?)
1083   ((ly:music-function-extract dynamicsAllInside) parser location offsetX -3.5)
1086 hairpinOffset = #(define-music-function (parser location posY) (number?)
1088   \once \override DynamicLineSpanner #'Y-offset = $posY
1089   \once \override DynamicLineSpanner #'Y-extent = #(cons +0 -0.01)
1092 #(define ((line-break-offset before after) grob)
1093   (let* ((orig (ly:grob-original grob))
1094          ; All siblings if line-broken:
1095          (siblings (if (ly:grob? orig) (ly:spanner-broken-into orig) '() )))
1096     (if (>= (length siblings) 2)
1097       ; We have been line-broken
1098       (if (eq? (car (last-pair siblings)) grob)
1099         ; Last sibling:
1100         (ly:grob-set-property! grob 'Y-offset after)
1101         ; Others get the before value:
1102         (ly:grob-set-property! grob 'Y-offset before)
1103       )
1104     )
1105   )
1108 ffz = #(make-dynamic-script "ffz")
1109 pf = #(make-dynamic-script "pf")
1110 sempp = #(make-dynamic-script (markup #:line( #:with-dimensions '(0 . 0)
1111 '(0 . 0) #:right-align #:normal-text #:italic "sempre" #:dynamic "pp")))
1112 parenf = #(make-dynamic-script (markup #:line(#:normal-text #:italic #:fontsize 2 "(" #:dynamic "f" #:normal-text #:italic #:fontsize 2 ")")))
1113 parenp = #(make-dynamic-script (markup #:line(#:normal-text #:italic #:fontsize 2 "(" #:dynamic "p" #:normal-text #:italic #:fontsize 2 ")")))
1114 pdolce = #(make-dynamic-script (markup #:line(#:dynamic "p" #:with-dimensions '(0 . 0) '(0 . 0) #:normal-text #:italic "dolce")))
1115 ppdolce = #(make-dynamic-script (markup #:line(#:dynamic "pp" #:with-dimensions '(0 . 0) '(0 . 0) #:normal-text #:italic "dolce")))
1116 dolce = #(make-dynamic-script (markup #:line(#:normal-text #:italic "dolce")))
1117 sfpdolce = #(make-dynamic-script (markup #:line(#:dynamic "sfp" #:with-dimensions '(0 . 0) '(0 . 0) #:normal-text #:italic "dolce"  )))
1118 bracketf = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 3 "[" #:dynamic "f" #:hspace 0.1 #:normal-text #:fontsize 3 "]"))))
1119 bracketmf = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 3 "[" #:dynamic "mf" #:hspace 0.1 #:normal-text #:fontsize 3 "]"))))
1120 bracketmp = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 2 "[" #:hspace 0.2 #:dynamic "mp" #:normal-text #:fontsize 2 "]"))))
1121 bracketp = #(make-dynamic-script (markup #:line(#:concat(#:normal-text #:fontsize 2 "[" #:hspace 0.2 #:dynamic "p" #:normal-text #:fontsize 2 "]"))))
1123 whiteoutp = #(make-dynamic-script (markup #:whiteout #:pad-markup 0.5 #:dynamic "p"))
1124 whiteoutf = #(make-dynamic-script (markup #:whiteout #:pad-markup 0.5 #:dynamic "f"))
1125 whiteoutff = #(make-dynamic-script (markup #:whiteout #:pad-markup 0.5 #:dynamic "ff"))
1128 cresc = #(make-music 'CrescendoEvent 'span-direction START
1129                      'span-type 'text 'span-text "cresc.")
1130 dim = #(make-music 'DecrescendoEvent 'span-direction START
1131                    'span-type 'text 'span-text "dim.")
1132 decresc = #(make-music 'DecrescendoEvent 'span-direction START
1133                        'span-type 'text 'span-text "decresc.")
1137 %%% Thanks to "Gilles THIBAULT" <gilles.thibault@free.fr>, there is a way
1138 %   to remove also the fermata from R1-\fermataMarkup: By filtering the music
1139 %   and removing the corresponding events.
1140 %   Documented as an LSR snippet: http://lsr.dsi.unimi.it/LSR/Item?id=372
1141 #(define (filterOneEventsMarkup event)
1142 ( let ( (eventname (ly:music-property  event 'name)) )
1143  (not
1144   (or     ;; add here event name you do NOT want
1145    (eq? eventname 'MultiMeasureTextEvent)
1146    (eq? eventname 'AbsoluteDynamicEvent)
1147    (eq? eventname 'TextScriptEvent)
1148    (eq? eventname 'ArticulationEvent)
1149    (eq? eventname 'CrescendoEvent)
1150    (eq? eventname 'DecrescendoEvent)
1151   )
1155 filterArticulations = #(define-music-function (parser location music) (ly:music?)
1156   (music-filter filterOneEventsMarkup music)
1161 %%% Add the same articulation to a longer sequence of notes:
1162 #(define (make-script x)
1163    (make-music 'ArticulationEvent
1164                'articulation-type x))
1166 #(define (add-articulation music art)
1167    (map-some-music
1168      (lambda (m)
1169        (cond ((music-is-of-type? m 'event-chord)
1170                 (set! (ly:music-property m 'elements)
1171                         (append (ly:music-property m 'elements)
1172                           (list (make-script art))))
1173                 m)
1174              ((music-is-of-type? m 'note-event)
1175                 (set! (ly:music-property m 'articulations)
1176                         (append (ly:music-property m 'articulations)
1177                           (list (make-script art))))
1178                 m)
1179              (else #f)))
1180       music))
1182 addArticulation = #(define-music-function (parser location type music) 
1183                                           (string? ly:music? )
1184                 (add-articulation music type))
1189 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1190 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1191 %%%%%   Tempo markings
1192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1193 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1197 rit = \markup {\italic "rit."}
1198 atempo = \markup {\italic "a tempo"}
1199 pocorit = \markup {\italic "poco rit."}
1200 ppmosso = \markup {\italic "poco più mosso"}
1201 pizz = \markup {\italic "pizz."}
1202 arco = \markup {\italic "arco"}
1203 perd = \markup {\italic "perdend."}
1208 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1209 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1210 %%%%%   REST COMBINATION
1211 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1212 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1216 %% REST COMBINING, TAKEN FROM http://lsr.dsi.unimi.it/LSR/Item?id=336
1218 %% Usage:
1219 %%   \new Staff \with {
1220 %%     \override RestCollision #'positioning-done = #merge-rests-on-positioning
1221 %%   } << \somevoice \\ \othervoice >>
1222 %% or (globally):
1223 %%   \layout {
1224 %%     \context {
1225 %%       \Staff
1226 %%       \override RestCollision #'positioning-done = #merge-rests-on-positioning
1227 %%     }
1228 %%   }
1230 %% Limitations:
1231 %% - only handles two voices
1232 %% - does not handle multi-measure/whole-measure rests
1234 #(define (rest-score r)
1235   (let ((score 0)
1236   (yoff (ly:grob-property-data r 'Y-offset))
1237   (sp (ly:grob-property-data r 'staff-position)))
1238     (if (number? yoff)
1239   (set! score (+ score 2))
1240   (if (eq? yoff 'calculation-in-progress)
1241       (set! score (- score 3))))
1242     (and (number? sp)
1243    (<= 0 2 sp)
1244    (set! score (+ score 2))
1245    (set! score (- score (abs (- 1 sp)))))
1246     score))
1248 #(define (merge-rests-on-positioning grob)
1249   (let* ((can-merge #f)
1250    (elts (ly:grob-object grob 'elements))
1251    (num-elts (and (ly:grob-array? elts)
1252       (ly:grob-array-length elts)))
1253    (two-voice? (= num-elts 2)))
1254     (if two-voice?
1255   (let* ((v1-grob (ly:grob-array-ref elts 0))
1256          (v2-grob (ly:grob-array-ref elts 1))
1257          (v1-rest (ly:grob-object v1-grob 'rest))
1258          (v2-rest (ly:grob-object v2-grob 'rest)))
1259     (and
1260      (ly:grob? v1-rest)
1261      (ly:grob? v2-rest)
1262      (let* ((v1-duration-log (ly:grob-property v1-rest 'duration-log))
1263       (v2-duration-log (ly:grob-property v2-rest 'duration-log))
1264       (v1-dot (ly:grob-object v1-rest 'dot))
1265       (v2-dot (ly:grob-object v2-rest 'dot))
1266       (v1-dot-count (and (ly:grob? v1-dot)
1267              (ly:grob-property v1-dot 'dot-count -1)))
1268       (v2-dot-count (and (ly:grob? v2-dot)
1269              (ly:grob-property v2-dot 'dot-count -1))))
1270        (set! can-merge
1271        (and
1272         (number? v1-duration-log)
1273         (number? v2-duration-log)
1274         (= v1-duration-log v2-duration-log)
1275         (eq? v1-dot-count v2-dot-count)))
1276        (if can-merge
1277      ;; keep the rest that looks best:
1278      (let* ((keep-v1? (>= (rest-score v1-rest)
1279               (rest-score v2-rest)))
1280       (rest-to-keep (if keep-v1? v1-rest v2-rest))
1281       (dot-to-kill (if keep-v1? v2-dot v1-dot)))
1282        ;; uncomment if you're curious of which rest was chosen:
1283        ;;(ly:grob-set-property! v1-rest 'color green)
1284        ;;(ly:grob-set-property! v2-rest 'color blue)
1285        (ly:grob-suicide! (if keep-v1? v2-rest v1-rest))
1286        (if (ly:grob? dot-to-kill)
1287            (ly:grob-suicide! dot-to-kill))
1288        (ly:grob-set-property! rest-to-keep 'direction 0)
1289        (ly:rest::y-offset-callback rest-to-keep)))))))
1290     (if can-merge
1291   #t
1292   (ly:rest-collision::calc-positioning-done grob))))
1298 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1300 %%%%%   TABLE OF CONTENTS
1301 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1302 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1305 contentsTitle = "Inhalt / Contents"
1307 \paper {
1308   tocTitleMarkup = \markup \fill-line{
1309     \null
1310     \column {
1311       \override #(cons 'line-width (* 7 cm))
1312       \line{ \fill-line {\piece-title {\contentsTitle} \null }}
1313       \hspace #1
1314     }
1315     \null
1316   }
1317   tocItemMarkup = \markup \fill-line {
1318     \null
1319     \column {
1320       \override #(cons 'line-width (* 7 cm ))
1321       \line { \fill-line{\fromproperty #'toc:text \fromproperty #'toc:page }}
1322     }
1323     \null
1324   }
1328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1329 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1330 %%%%%   TITLE PAGE / HEADER
1331 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1332 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1334 #(define-markup-command (when-property layout props symbol markp) (symbol? markup?)
1335   (if (chain-assoc-get symbol props)
1336       (interpret-markup layout props markp)
1337       (ly:make-stencil '()  '(1 . -1) '(1 . -1))))
1339 #(define-markup-command (vspace layout props amount) (number?)
1340   "This produces a invisible object taking vertical space."
1341   (let ((amount (* amount 3.0)))
1342     (if (> amount 0)
1343         (ly:make-stencil "" (cons -1 1) (cons 0 amount))
1344         (ly:make-stencil "" (cons -1 1) (cons amount amount)))))
1348 titlePageMarkup = \markup \abs-fontsize #10 \when-property #'header:title \column {
1349     \vspace #4
1350     \fill-line { \fontsize #8 \fromproperty #'header:composer }
1351     \vspace #1
1352     \fill-line { \fontsize #8 \fromproperty #'header:poet }
1353     \vspace #4
1354     \fill-line { \fontsize #10 \bold \fromproperty #'header:titlepagetitle }
1355     \vspace #1
1356     \fontsize #2 \when-property #'header:titlepagesubtitle {
1357       \fill-line { \fromproperty #'header:titlepagesubtitle }
1358       \vspace #1
1359     }
1360     \fill-line { \postscript #"-20 0 moveto 40 0 rlineto stroke" }
1361     \vspace #8
1362     \fill-line { \fontsize #5 \fromproperty #'header:ensemble }
1363     \vspace #0.02
1364     \fill-line { \fontsize #2 \fromproperty #'header:instruments }
1365     \vspace #9
1366     \fill-line { \fontsize #5 \fromproperty #'header:date }
1367     \vspace #1
1368     \fill-line { \fontsize #5 \fromproperty #'header:scoretype }
1369     \vspace #1
1370     \when-property #'header:instrument {
1371       \fill-line { \bold \fontsize #6 \rounded-box \fromproperty #'header:instrument }
1372     }
1373     \vspace #7
1374     \fontsize #2 \when-property #'header:enteredby \override #'(baseline-skip . 3.75) \left-align\center-column {
1375       \fill-line { "Herausgegeben von: / Edited by:"}
1376       \vspace #0.
1377       \fill-line { \fromproperty #'header:enteredby }
1378     }
1379     \fill-line {
1380       \when-property #'header:arrangement \column {
1381         \vspace #8
1382         \fill-line { \fontsize #3 \fromproperty #'header:arrangement }
1383       }
1384     }
1385   \vspace #6
1386   \fill-line { \fromproperty #'header:copyright }
1389 titleHeaderMarkup = \markup {
1390   \override #'(baseline-skip . 3.5)
1391   \column {
1392     \fill-line {
1393       \fromproperty #'header:logo
1394       \override #'(baseline-skip . 4.5) \center-column {
1395         \bold \abs-fontsize #18 \fromproperty #'header:title
1396         \bold \abs-fontsize #12 \fromproperty #'header:subtitle
1397         \abs-fontsize #11 \fromproperty #'header:subsubtitle
1398       }
1399       \bold \abs-fontsize #11 \when-property #'header:instrument \rounded-box \fromproperty #'header:instrument
1400     }
1401     \fill-line {
1402       \with-dimensions #'( 0 . 0) #'( 0 . 1 ) \null
1403     }
1405     \fill-line {
1406             \abs-fontsize #10 \fromproperty #'header:poet
1407             \abs-fontsize #10 \fromproperty #'header:composer
1408     }
1409     \fill-line {
1410             \abs-fontsize #10 \fromproperty #'header:meter
1411             \abs-fontsize #10 \fromproperty #'header:arranger
1412     }
1413   }
1415 date = #(strftime "%d-%m-%Y" (localtime (current-time)))
1416 \header {
1417   logo = \date
1421 titleScoreMarkup = \markup \piece-title \fromproperty #'header:piece
1423 \paper {
1424   scoreTitleMarkup = \titleScoreMarkup
1425   bookTitleMarkup = \titleHeaderMarkup
1430 %%%%%%%%%%%%%% headers and footers %%%%%%%%%%%%%%%%%%%%%%%%%%
1432 #(define (first-score-page layout props arg)
1433   (let* ((label 'first-score-page)
1434          (table (ly:output-def-lookup layout 'label-page-table))
1435          (label-page (and (list? table) (assoc label table)))
1436          (page-number (and label-page (cdr label-page)))
1437         )
1438     (if (eq? (chain-assoc-get 'page:page-number props -1) page-number)
1439       (interpret-markup layout props arg)
1440       empty-stencil)))
1442 #(define no-header-table '(1))
1443 addNoHeaderPage = #(define-music-function (parser location nr) (number?)
1444   (set! no-header-table (cons nr no-header-table))
1445   (make-music 'Music 'void #t))
1446 setNoHeaderPages = #(define-music-function (parser location pages) (list?)
1447   (set! no-header-table pages)
1448   (make-music 'Music 'void #t))
1450 #(define (is-header-page layout props arg)
1451   (let* ((page-number (chain-assoc-get 'page:page-number props -1)))
1452     (if (not (member page-number no-header-table))
1453       (interpret-markup layout props arg)
1454       empty-stencil)))
1456 #(define no-footer-table '(1))
1457 addNoFooterPage = #(define-music-function (parser location nr) (number?)
1458   (set! no-footer-table (cons nr no-footer-table))
1459   (make-music 'Music 'void #t))
1460 setNoFooterPages = #(define-music-function (parser location pages) (list?)
1461   (set! no-footer-table pages)
1462   (make-music 'Music 'void #t))
1464 #(define (is-footer-page layout props arg)
1465   (let* ((page-number (chain-assoc-get 'page:page-number props -1)))
1466     (if (not (member page-number no-footer-table))
1467       (interpret-markup layout props arg)
1468       empty-stencil)))
1470 #(define copyright-pages-table '(1))
1471 addCopyrightPage = #(define-music-function (parser location nr) (number?)
1472   (set! copyright-pages-table (cons nr copyright-pages-table))
1473   (make-music 'Music 'void #t))
1474 setCopyrightPages = #(define-music-function (parser location pages) (list?)
1475   (set! copyright-pages-table pages)
1476   (make-music 'Music 'void #t))
1478 #(define (is-copyright-page layout props arg)
1479   (let* ((page-number (chain-assoc-get 'page:page-number props -1)))
1480     (if (member page-number copyright-pages-table)
1481       (interpret-markup layout props arg)
1482       empty-stencil)))
1486 \paper {
1487   olyStdOddHeaderMarkup = \markup \fill-line {
1488     %% force the header to take some space, otherwise the
1489     %% page layout becomes a complete mess.
1490     " "
1491     \on-the-fly #is-header-page \fromproperty #'header:title
1492     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1493   }
1494   olyStdEvenHeaderMarkup = \markup \fill-line {
1495     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1496     \on-the-fly #is-header-page \fromproperty #'header:composer
1497     " "
1498   }
1499   olyInstrumentOddHeaderMarkup = \markup \fill-line {
1500     " "
1501     \on-the-fly #is-header-page \concat { \fromproperty #'header:instrument }
1502     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1503   }
1504   olyInstrumentEvenHeaderMarkup = \markup \fill-line {
1505     \on-the-fly #is-header-page \fromproperty #'page:page-number-string
1506     \on-the-fly #is-header-page \concat { \fromproperty #'header:composer ": " \fromproperty #'header:title }
1507     " "
1508   }
1509   oddHeaderMarkup = \olyStdOddHeaderMarkup
1510   evenHeaderMarkup = \olyStdEvenHeaderMarkup
1512   olyStdOddFooterMarkup = \markup {
1513     \column {
1514       \fill-line {
1515         %% publisher header field only on title page.
1516         \on-the-fly #first-page \fromproperty #'header:publisher
1517       }
1518       \fill-line {
1519         %% copyright on the first real score page
1520         \on-the-fly #is-copyright-page \fromproperty #'header:copyright
1521         \on-the-fly #is-copyright-page \null
1522       }
1523       \fill-line {
1524         %% All other pages get the number of the edition centered
1525         \on-the-fly #is-footer-page \fromproperty #'header:scorenumber
1526       }
1527     }
1528   }
1529   olyInstrumentOddFooterMarkup = \markup {
1530     \column {
1531       \fill-line {
1532         %% copyright on the first real score page
1533         \on-the-fly #is-copyright-page \fromproperty #'header:copyright
1534         \on-the-fly #is-copyright-page \null
1535       }
1536       \fill-line {
1537         %% All other pages get the number of the edition centered
1538         \on-the-fly #is-footer-page \fromproperty #'header:scorenumber
1539       }
1540     }
1541   }
1542   oddFooterMarkup = \olyStdOddFooterMarkup
1555 % Interpret the given markup with the header fields added to the props.
1556 % This way, one can re-use the same functions (using fromproperty
1557 % #'header:field) in the header block and as top-level markup.
1559 % This function is originally copied from mark-up-title (file scm/titling.scm),
1560 % which is lilypond's internal function to handle the title markups. I needed
1561 % to replace the scopes and manually add the $defaultheader (which is internally
1562 % done in paper-book.cc before calling mark-up-title. Also, I don't extract the
1563 % markup from the header block, but use the given markup.
1565 % I'm not sure if I really need the page properties in props, too... But I
1566 % suppose it does not hurt, either.
1567 #(define-markup-command (markupWithHeader layout props markup) (markup?)
1568   "Interpret the given markup with the header fields added to the props.
1569    This way, one can re-use the same functions (using fromproperty
1570    #'header:field) in the header block and as top-level markup."
1571   (let* (
1572       ; TODO: If we are inside a score, add the score's local header block, too!
1573       ; Currently, I only use the global header block, stored in $defaultheader
1574       (scopes (list $defaultheader))
1575       (alists (map ly:module->alist scopes))
1577       (prefixed-alist
1578         (map (lambda (alist)
1579           (map (lambda (entry)
1580             (cons
1581               (string->symbol (string-append "header:" (symbol->string (car entry))))
1582               (cdr entry)))
1583             alist))
1584           alists))
1585       (props (append prefixed-alist
1586               props
1587               (layout-extract-page-properties layout)))
1588     )
1589     (interpret-markup layout props markup)
1590   )
1598 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1599 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1600 %%%%%   Equally spacing multiple columns (e.g. for translations)
1601 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1602 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1604 % Credits: Nicolas Sceaux on the lilypond-user mailinglist
1605 #(define-markup-command (columns layout props args) (markup-list?)
1606    (let ((line-width (/ (chain-assoc-get 'line-width props
1607                          (ly:output-def-lookup layout 'line-width))
1608                         (max (length args) 1))))
1609      (interpret-markup layout props
1610        (make-line-markup (map (lambda (line)
1611                                 (markup #:pad-to-box `(0 . ,line-width) '(0 . 0)
1612                                   #:override `(line-width . ,line-width)
1613                                   line))
1614                                args)))))
1618 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1619 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1620 %%%%%   SCORE (HEADER / LAYOUT) SETTINGS
1621 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1622 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1625 startSlashedGraceMusic =  {
1626   \override Flag #'stroke-style = #"grace"
1629 stopSlashedGraceMusic =  {
1630   \revert Flag #'stroke-style
1633 slashedGrace =
1634 #(def-grace-function startSlashedGraceMusic stopSlashedGraceMusic
1635    (_i "Create slashed graces (slashes through stems, but no slur)from the following music expression"))
1638 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1639 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1640 %%%%%   SCORE (HEADER / LAYOUT) SETTINGS
1641 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1642 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1644 \paper {
1645   footnote-separator-markup = \markup { \fill-line { \override #`(span-factor . 1/4) { \draw-hline } \null }}
1647   left-margin = 2\cm
1648   right-margin = 1.5\cm
1649   line-width = 17.5\cm
1650 %   bottom-margin = 1.5\cm
1651   top-margin = 0.7\cm
1652   ragged-right = ##f
1653   ragged-last = ##f
1654   ragged-bottom = ##f
1655   ragged-last-bottom = ##f
1657 \layout {
1658   \context {
1659     \ChoirStaff
1660     % If only one non-empty staff in a system exists, still print the backet
1661     \override SystemStartBracket #'collapse-height = #1
1662     \consists "Instrument_name_engraver"
1663     \consists "Keep_alive_together_engraver"
1664   }
1665   \context {
1666     \StaffGroup
1667     % If only one non-empty staff in a system exists, still print the backet
1668     \override SystemStartBracket #'collapse-height = #1
1669     \consists "Instrument_name_engraver"
1670   }
1671   \context {
1672     \GrandStaff
1673     \override SystemStartBracket #'collapse-height = #1
1674     \consists "Instrument_name_engraver"
1675   }
1676   \context {
1677     \FiguredBass
1678     \override VerticalAxisGroup #'padding = #0
1679   }
1680   \context {
1681     \Score
1682     % Force multi-measure rests to be written as one span
1683     \override MultiMeasureRest #'expand-limit = #3
1684     skipBars = ##t
1685     autoBeaming = ##f
1686     \override CombineTextScript #'avoid-slur = #'outside
1687     \override DynamicTextSpanner #'style = #'none
1688     \override InstrumentSwitch #'font-size = #-1
1690     % Rest collision
1691     \override RestCollision #'positioning-done = #merge-rests-on-positioning
1692     % Auto-Accidentals: Use modern-cautionary style...
1693     extraNatural = ##f
1694     % Accidental rules (the rule giving the most accidentals wins!)
1695     % -) Reset accidentals at each barline -> accs not in key sig will always be printed
1696     % -) Same octave accidentals are remembered for two measures -> cancellation
1697     % -) other octave accidentals are remembered for next measure -> cancellation
1698     autoAccidentals = #`(Staff  ,(make-accidental-rule 'same-octave 0)
1699                                 ,(make-accidental-rule 'any-octave 0)
1700                                 ,(make-accidental-rule 'any-octave 1)
1701                                 ,(make-accidental-rule 'same-octave 2))
1702     % No auto-cautionaries, we always use autoAccidentals!
1703 %     autoCautionaries = #`(Staff ,(make-accidental-rule 'any-octave 0)
1704 %                                 ,(make-accidental-rule 'same-octave 1))
1705     printKeyCancellation = ##t
1706     quotedEventTypes = #'(StreamEvent)
1707     quotedCueEventTypes = #'(
1708       rhythmic-event
1709       tie-event
1710       beam-event
1711       tuplet-span-event
1712       tremolo-event
1713       glissando-event
1714       harmonic-event
1715       repeat-tie-event
1716       articulation-event
1717       slur-event
1718       trill-span-event
1719       tremolo-span-event
1720     )
1721     implicitBassFigures = #'(0 100)
1722   }
1723   \context {
1724     \Staff
1725     \RemoveEmptyStaves
1726   }
1730 ts = #(make-music 'TextScriptEvent 'text "t.s." 'direction UP )
1731 tt = #(make-music 'TextScriptEvent 'text "Tutti" 'direction UP )
1732 solo = #(make-music 'TextScriptEvent 'text "Solo" 'direction UP )
1733 tutti = #(make-music 'TextScriptEvent 'text "Tutti" 'direction UP )
1734 bracketts = #(make-music 'TextScriptEvent 'text "[t.s.]" 'direction UP )
1735 brackettt = #(make-music 'TextScriptEvent 'text "[Tutti]" 'direction UP )
1736 bracketsolo = #(make-music 'TextScriptEvent 'text "[Solo]" 'direction UP )
1738 sottovoce = #(make-music 'TextScriptEvent 'text "sotto voce" 'direction UP )
1740 dashedSlur = -\tweak #'dash-definition #'((0 1 0.4 0.75))(
1741 dashedTie = -\tweak #'dash-definition #'((0 1 0.4 0.75))~
1743 divisi = #(define-music-function (parser location vc1 vc2) (ly:music? ly:music?)
1745   << { \voiceOne $vc1 \oneVoice} \context Voice = "divisi2" { \voiceTwo $vc2 } >>
1749 #(define twoVoice divisi)
1751 #(define-public (bracket-stencils grob)
1752   (let ((lp (grob-interpret-markup grob (markup #:fontsize 3.5 #:translate (cons -0.3 -0.5) "[")))
1753         (rp (grob-interpret-markup grob (markup #:fontsize 3.5 #:translate (cons -0.3 -0.5) "]"))))
1754     (list lp rp)))
1756 bracketify = #(define-music-function (parser loc arg) (ly:music?)
1757    (_i "Tag @var{arg} to be parenthesized.")
1759   \once \override ParenthesesItem #'stencils = #bracket-stencils
1760   \parenthesize $arg
1765 #(define-markup-command (hat layout props arg) (markup?)
1766   "Draw a hat above the given string @var{arg}."
1767   (interpret-markup layout props (markup #:combine #:raise 1.5 "^" arg)))
1771 smallFlageolet =
1772 #(let ((m (make-music 'ArticulationEvent
1773                       'articulation-type "flageolet")))
1774    (ly:music-set-property! m 'tweaks
1775      (acons 'font-size -2
1776        (ly:music-property m 'tweaks)))
1777   m)
1780 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1781 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1782 %%%%%   LICENSE TEXTS
1783 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1784 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1786 LicenseCCBYPlain = \markup {Creative Commons BY \with-url #"http://creativecommons.org/licenses/by/3.0/at/" {\translate #'(0 . -0.7) \epsfile #Y #3 #"orchestrallily/cc-by.eps" }}
1787 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" }}
1788 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" }}
1789 LicenseNoRestrictions = \markup{\line {Die Ausgabe darf kopiert und ohne Einschränkungen aufgeführt werden. / May be copied and performed without restriction.}}
1791 \include "sceaux_clef-key.ily"
1794 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1795 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1796 %%%%%   VARIOUS
1797 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1798 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1800 startUnremovableSection = \set Staff.keepAliveInterfaces =
1801  #'(rhythmic-grob-interface
1802     rest-interface
1803     lyric-interface
1804     percent-repeat-item-interface
1805     percent-repeat-interface
1806     stanza-number-interface)
1808 endUnremovableSection = \unset Staff.keepAliveInterfaces
1811 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1812 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1813 %%%%%   EDITORIAL ANNOTATIONS
1814 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1815 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1817 #(define-public (editorial-bracket-stencil stil padding widen)
1818 "Add brackets for editorial annoations around STIL, producing a new stencil."
1819 (let* ((axis Y)
1820        (other-axis (lambda (a) (remainder (+ a 1) 2)))
1821        (ext (interval-widen (ly:stencil-extent stil axis) widen))
1822        (thick 0.15)
1823        (protrusion 0.3)
1824        (lb (ly:bracket axis ext thick protrusion))
1825        (rb (ly:bracket axis ext thick (- protrusion))))
1826   (set! stil (ly:stencil-combine-at-edge stil (other-axis axis) 1 rb padding))
1827   (set! stil
1828     (ly:stencil-combine-at-edge lb (other-axis axis) 1 stil padding))
1829   stil))
1831 editorialHairpin = \once \override Hairpin     #'stencil = #(lambda (grob) (editorial-bracket-stencil (ly:hairpin::print grob) 0.2 0.55))
1832 editorialDynamic = \once \override DynamicText #'stencil = #(lambda (grob) (editorial-bracket-stencil (ly:text-interface::print grob) 0.2 0.55))
1833 editorialMarkup =  \once \override TextScript  #'stencil = #(lambda (grob) (editorial-bracket-stencil (ly:text-interface::print grob) 0.2 0.55))
1835 % videStart = \mark \markup { \hspace #1 \musicglyph #"scripts.coda"  \with-dimensions #'(0 . 0) #'(0 . 0) \left-align { vi-} }
1836 videStart = \mark \markup \halign #-2.3 \concat { \hspace #4.5 \musicglyph #"scripts.coda" \left-align { vi- } }
1837 % videEnd = \notemode {
1838 %   \once \override Score.RehearsalMark #'break-visibility = #begin-of-line-invisible
1839 %   \mark \markup \concat{ \with-dimensions #'(0 . 0) #'(0 . 0) \right-align { -de } \hspace #1 \musicglyph #"scripts.coda" }
1841 videEnd = \notemode {
1842         \once \override Score.RehearsalMark #'break-visibility = #begin-of-line-invisible
1843         \mark \markup \concat{ \right-align { -de } \hspace #1.5 \musicglyph #"scripts.coda" \hspace #4.2 }
1848 \layout {
1849         \context {\Staff
1850                 soloText = #"I"
1851                 soloIIText = #"II"
1852                 aDueText = #"a2"
1853         }
1856 \paper {
1857 %   annotate-spacing = ##t
1858   ragged-bottom = ##f
1859   ragged-last = ##f
1860   ragged-last-bottom = ##f
1862   top-markup-spacing #'minimum-distance = #5
1863 %   top-markup-spacing #'basic-distance = #4
1864 %   top-markup-spacing #'padding = #2
1865   top-markup-spacing #'stretchability = #15
1867   top-system-spacing #'minimum-distance = #0
1868 %   top-system-spacing #'basic-distance = #3
1869   top-system-spacing #'padding = #2
1870   top-system-spacing #'stretchability = #13
1871   
1872   markup-system-spacing #'minimum-distance = #5
1873 %   markup-system-spacing #'basic-distance = #4
1874   markup-system-spacing #'padding = #3
1875   markup-system-spacing #'stretchability = #25
1876   
1877   system-system-spacing #'minimum-distance = #0
1878 %   system-system-spacing #'basic-distance = #5
1879   system-system-spacing #'padding = #2
1880   system-system-spacing #'stretchability = #15
1881   
1882   last-bottom-spacing #'basic-distance = #3
1883 %   last-bottom-spacing #'basic-distance = #7
1884   last-bottom-spacing #'padding = #4
1885   last-bottom-spacing #'stretchability = #14
1887 %   score-markup-spacing #'basic-distance = #5
1888 %   score-markup-spacing #'stretchability = #15
1890 %   markup-markup-spacing #'basic-distance = #5
1891 %   markup-markup-spacing #'stretchability = #30
1894 \layout {
1895   \context { \PianoStaff
1896     \override StaffGrouper #'staff-staff-spacing #'stretchability = #1.5
1897   }
1898   \context { \StaffGroup
1899     \override StaffGrouper #'staff-staff-spacing #'stretchability = #2.5
1900     \override SystemStartBracket #'collapse-height = #1
1901   }
1902   \context { \GrandStaff
1903     \override StaffGrouper #'staff-staff-spacing #'stretchability = #3
1904     \override StaffGrouper #'staffgroup-staff-spacing #'stretchability = #3
1905    }
1906   \context { \ChoirStaff
1907     \override StaffGrouper #'staff-staff-spacing #'stretchability = #1
1908   }
1909   \context { \Staff
1910     \override StaffGrouper #'staff-staff-spacing #'stretchability = #4.9
1911   }
1912   \context { \Score
1913     \override StaffGrouper #'staff-staff-spacing #'stretchability = #5
1914   }
1919 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1920 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1921 %%%%%   WORKAROUNDS!
1922 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1923 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1925 % _ does not work as a direction modifier in figured bass
1926 tsdown = #(make-music 'TextScriptEvent 'text "t.s." 'direction DOWN )