1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 1998--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
4 ;;;; Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; LilyPond is free software: you can redistribute it and/or modify
7 ;;;; it under the terms of the GNU General Public License as published by
8 ;;;; the Free Software Foundation, either version 3 of the License, or
9 ;;;; (at your option) any later version.
11 ;;;; LilyPond is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;;; GNU General Public License for more details.
16 ;;;; You should have received a copy of the GNU General Public License
17 ;;;; along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
19 ;; TODO: should link back into user manual.
21 (define (mm-rest-child-list music)
22 "Generate events for multimeasure rests,
23 to be used by the sequential-iterator"
24 (let ((location (ly:music-property music 'origin))
25 (duration (ly:music-property music 'duration)))
26 (list (make-music 'BarCheck
28 (make-event-chord (cons (make-music 'MultiMeasureRestEvent
31 (ly:music-property music 'articulations)))
35 (define (make-ottava-set music)
36 "Set context properties for an ottava bracket."
37 (let ((octavation (ly:music-property music 'ottava-number)))
39 (list (context-spec-music
42 (let ((offset (* -7 octavation))
43 (string (assoc-get octavation '((2 . "15ma")
48 (set! (ly:context-property context 'middleCOffset) offset)
49 (set! (ly:context-property context 'ottavation) string)
50 (ly:set-middle-C! context))))
53 (define-public music-descriptions
56 . ((description . "Create a dynamic mark.
58 Syntax: @var{note}@code{\\x}, where @code{\\x} is a dynamic mark like
59 @code{\\ppp} or @code{\\sfz}. A complete list is in file
60 @file{ly/@/dynamic-scripts-init.ly}.")
61 (types . (general-music event dynamic-event absolute-dynamic-event))
65 . ((description . "Print an annotation of an output element.")
66 (types . (general-music event annotate-output-event))
70 . ((description . "Call the argument with the current context during
72 (types . (general-music apply-context))
73 (iterator-ctor . ,ly:apply-context-iterator::constructor)
77 . ((description . "Call the argument with all current grobs during
80 Syntax: @code{\\applyOutput #'@var{context} @var{func}}
82 Arguments to @var{func} are 1.@tie{}the grob, 2.@tie{}the originating
83 context, and 3.@tie{}the context where @var{func} is called.")
84 (types . (general-music event apply-output-event))
88 . ((description . "Make an arpeggio on this note.
90 Syntax: @var{note}@code{-\\arpeggio}")
91 (types . (general-music arpeggio-event event))
94 ;; todo: use articulation-event for slur as well.
95 ;; separate non articulation scripts
97 . ((description . "Add an articulation marking to a note.
99 Syntax: @var{note}@code{x}@code{y}, where @code{x} is a direction
100 (@code{^} for up or @code{_} for down), or LilyPond's choice
101 (no direction specified), and where @code{y} is an articulation
102 (such as @code{-.}, @code{->}, @code{\\tenuto}, @code{\\downbow}).
103 See the Notation Reference for details.")
104 (types . (general-music event articulation-event script-event))
108 . ((description . "Used for making voices that switch between
109 piano staves automatically.")
110 (iterator-ctor . ,ly:auto-change-iterator::constructor)
111 (start-callback . ,ly:music-wrapper::start-callback)
112 (length-callback . ,ly:music-wrapper::length-callback)
113 (types . (general-music music-wrapper-music auto-change-instruction))
117 . ((description . "Check whether this music coincides with
118 the start of the measure.")
119 (types . (general-music bar-check))
120 (iterator-ctor . ,ly:bar-check-iterator::constructor)
124 . ((description . "Print a bass-figure text.")
125 (types . (general-music event rhythmic-event bass-figure-event))
129 . ((description . "Start or stop a beam.
131 Syntax for manual control: @code{c8-[ c c-] c8}")
132 (types . (general-music event beam-event span-event))
136 . ((description . "Specify that a note may not auto-beamed.")
137 (types . (general-music event beam-forbid-event))
140 (BreakDynamicSpanEvent
141 . ((description . "End an alignment spanner for dynamics here.")
142 (types . (general-music break-span-event break-dynamic-span-event event))
146 . ((description . "A drop/fall/doit jazz articulation.")
147 (types . (general-music bend-after-event event))))
150 . ((description . "Create a @q{breath mark} or @q{comma}.
152 Syntax: @var{note}@code{\\breathe}")
154 (types . (general-music event breathing-event))
158 . ((description . "A note that is part of a cluster.")
159 ;; not a note-event, to ensure that Note_heads_engraver doesn't eat it.
160 (types . (general-music cluster-note-event melodic-event
161 rhythmic-event event))
164 (CompletizeExtenderEvent
165 . ((description . "Used internally to signal the end of a lyrics block to
166 ensure extenders are completed correctly when a @code{Lyrics} context ends
167 before its associated @code{Voice} context.")
168 (types . (general-music completize-extender-event event))
172 . ((description . "Change staves in Piano staff.
174 Syntax: @code{\\change Staff = @var{new-id}}")
175 (iterator-ctor . ,ly:change-iterator::constructor)
176 (types . (general-music translator-change-instruction))
180 . ((description . "Interpret the argument music within a
182 (iterator-ctor . ,ly:context-specced-music-iterator::constructor)
183 (length-callback . ,ly:music-wrapper::length-callback)
184 (start-callback . ,ly:music-wrapper::start-callback)
185 (types . (context-specification general-music music-wrapper-music))
189 . ((description . "Begin or end a crescendo.
191 Syntax: @var{note}@code{\\<} @dots{} @var{note}@code{\\!}
193 An alternative syntax is @var{note}@code{\\cr} @dots{}
194 @var{note}@code{\\endcr}.")
195 (types . (general-music span-event span-dynamic-event crescendo-event
200 . ((description . "Begin or end a decrescendo.
202 Syntax: @var{note}@code{\\>} @dots{} @var{note}@code{\\!}
204 An alternative syntax is @var{note}@code{\\decr} @dots{}
205 @var{note}@code{\\enddecr}.")
206 (types . (general-music span-event span-dynamic-event decrescendo-event
211 . ((description . "Begin or end an episema.")
212 (types . (general-music span-event event episema-event))
216 . ((description . "Atomic music event.")
217 (types . (general-music event))
221 . ((description . "Internally used to group a set of events.")
222 (iterator-ctor . ,ly:event-chord-iterator::constructor)
223 (length-callback . ,ly:music-sequence::maximum-length-callback)
224 (to-relative-callback .
225 ,ly:music-sequence::event-chord-relative-callback)
226 (types . (general-music event-chord simultaneous-music))
230 . ((description . "Extend lyrics.")
231 (types . (general-music extender-event event))
235 . ((description . "Specify what finger to use for this note.")
236 (types . (general-music fingering-event event))
240 . ((description . "Start a glissando on this note.")
241 (types . (general-music glissando-event event))
245 . ((description . "Interpret the argument as grace notes.")
246 (start-callback . ,ly:grace-music::start-callback)
247 (length . ,ZERO-MOMENT)
248 (iterator-ctor . ,ly:grace-iterator::constructor)
249 (types . (grace-music music-wrapper-music general-music))
253 . ((description . "Mark a note as harmonic.")
254 (types . (general-music event harmonic-event))
258 . ((description . "A hyphen between lyric syllables.")
259 (types . (general-music hyphen-event event))
263 . ((description . "Change the key signature.
265 Syntax: @code{\\key} @var{name} @var{scale}")
266 (to-relative-callback . ,(lambda (x p) p))
267 (types . (general-music key-change-event event))
271 . ((description . "Place a bookmarking label.")
272 (types . (general-music label-event event))
276 . ((description . "Don't damp this chord.
278 Syntax: @var{note}@code{\\laissezVibrer}")
279 (types . (general-music event laissez-vibrer-event))
283 . ((description . "Start or end a ligature.")
284 (types . (general-music span-event ligature-event event))
288 . ((description . "Allow, forbid or force a line break.")
289 (types . (general-music line-break-event break-event event))
293 . ((description . "Align lyrics to the start of notes.
295 Syntax: @code{\\lyricsto} @var{voicename} @var{lyrics}")
296 (length . ,ZERO-MOMENT)
297 (types . (general-music lyric-combine-music))
298 (iterator-ctor . ,ly:lyric-combine-music-iterator::constructor)
302 . ((description . "A lyric syllable. Must be entered in lyrics mode,
303 i.e., @code{\\lyrics @{ twinkle4 twinkle4 @} }.")
304 (types . (general-music rhythmic-event lyric-event event))
308 . ((description . "Insert a rehearsal mark.
310 Syntax: @code{\\mark} @var{marker}
312 Example: @code{\\mark \"A\"}")
313 (types . (general-music mark-event event))
316 (MultiMeasureRestEvent
317 . ((description . "Used internally by @code{MultiMeasureRestMusic}
319 (types . (general-music event rhythmic-event
320 multi-measure-rest-event))
323 (MultiMeasureRestMusic
324 . ((description . "Rests that may be compressed into Multi rests.
326 Syntax: @code{R2.*4} for 4 measures in 3/4 time.")
327 (iterator-ctor . ,ly:sequential-iterator::constructor)
328 (elements-callback . ,mm-rest-child-list)
329 (types . (general-music multi-measure-rest))
332 (MultiMeasureTextEvent
333 . ((description . "Texts on multi measure rests.
335 Syntax: @code{R-\\markup @{ \\roman \"bla\" @}}
337 Note the explicit font switch.")
338 (types . (general-music event multi-measure-text-event))
342 . ((description . "Generic type for music expressions.")
343 (types . (general-music))
347 . ((description . "A note.")
348 (types . (general-music event note-event rhythmic-event
353 . ((description . "Start or stop grouping brackets.")
354 (types . (general-music event note-grouping-event))
358 . ((description . "Start or stop an ottava bracket.")
359 (iterator-ctor . ,ly:sequential-iterator::constructor)
360 (elements-callback . ,make-ottava-set)
361 (types . (general-music ottava-music))
365 . ((description . "Extend the definition of a graphical object.
367 Syntax: @code{\\override} [ @var{context} @code{.} ]
368 @var{object} @var{property} @code{=} @var{value}")
369 (types . (general-music layout-instruction-event
370 override-property-event))
371 (iterator-ctor . ,ly:push-property-iterator::constructor)
375 . ((description . "Allow, forbid or force a page break.")
376 (types . (general-music break-event page-break-event event))
380 . ((description . "Allow, forbid or force a page turn.")
381 (types . (general-music break-event page-turn-event event))
385 . ((description . "Combine two parts on a staff, either merged or
386 as separate voices.")
387 (length-callback . ,ly:music-sequence::maximum-length-callback)
388 (start-callback . ,ly:music-sequence::minimum-start-callback)
389 (types . (general-music part-combine-music))
390 (iterator-ctor . ,ly:part-combine-iterator::constructor)
394 . ((description . "Used internally to signal percent repeats.")
395 (types . (general-music event percent-event rhythmic-event))
398 (PercentRepeatedMusic
399 . ((description . "Repeats encoded by percents.")
400 (iterator-ctor . ,ly:percent-repeat-iterator::constructor)
401 (start-callback . ,ly:repeated-music::first-start)
402 (length-callback . ,ly:repeated-music::unfolded-music-length)
403 (types . (general-music repeated-music percent-repeated-music))
407 . ((description . "Within a ligature, mark the previous and the
408 following note to form a pes (if melody goes up) or a flexa (if melody
410 (types . (general-music pes-or-flexa-event event))
414 . ((description . "Start or end phrasing slur.
416 Syntax: @var{note}@code{\\(} and @var{note}@code{\\)}")
417 (types . (general-music span-event event phrasing-slur-event))
421 . ((description . "Set a context property.
423 Syntax: @code{\\set @var{context}.@var{prop} = @var{scheme-val}}")
424 (types . (layout-instruction-event general-music))
425 (iterator-ctor . ,ly:property-iterator::constructor)
429 . ((description . "Restore the default setting for a context
430 property. See @ref{PropertySet}.
432 Syntax: @code{\\unset @var{context}.@var{prop}}")
433 (types . (layout-instruction-event general-music))
434 (iterator-ctor . ,ly:property-unset-iterator::constructor)
438 . ((description . "Quote preprocessed snippets of music.")
439 (iterator-ctor . ,ly:music-wrapper-iterator::constructor)
440 (length-callback . ,ly:music-wrapper::length-callback)
441 (start-callback . ,ly:music-wrapper::start-callback)
442 (types . (general-music music-wrapper-music))
446 . ((description . "Check if a pitch is in the correct octave.")
447 (to-relative-callback . ,ly:relative-octave-check::relative-callback)
448 (types . (general-music relative-octave-check))
452 . ((description . "Music that was entered in relative octave notation.")
453 (to-relative-callback . ,ly:relative-octave-music::relative-callback)
454 (iterator-ctor . ,ly:music-wrapper-iterator::constructor)
455 (length-callback . ,ly:music-wrapper::length-callback)
456 (start-callback . ,ly:music-wrapper::start-callback)
457 (types . (music-wrapper-music general-music relative-octave-music))
461 . ((description . "A chord repetition")
462 (to-relative-callback . ,ly:music-sequence::repeated-chord-relative-callback)
463 (iterator-ctor . ,ly:music-wrapper-iterator::constructor)
464 (start-callback . ,ly:music-wrapper::start-callback)
465 (length-callback . ,ly:music-wrapper::length-callback)
466 (types . (general-music music-wrapper-music))
470 . ((description . "Repeat music in different ways.")
471 (types . (general-music repeated-music))
475 . ((description . "Ties for starting a second volta bracket.")
476 (types . (general-music event repeat-tie-event))
480 . ((description . "A Rest.
482 Syntax: @code{r4} for a quarter rest.")
483 (types . (general-music event rhythmic-event rest-event))
487 . ((description . "The opposite of @ref{OverrideProperty}: remove a
488 previously added property from a graphical object definition.")
489 (types . (general-music layout-instruction-event))
490 (iterator-ctor . ,ly:pop-property-iterator::constructor)
494 . ((description . "Add an articulation mark to a note.")
495 (types . (general-music event))
499 . ((description . "Music expressions concatenated.
501 Syntax: @code{\\sequential @{ @dots{} @}} or simply @code{@{ @dots{} @}}")
502 (length-callback . ,ly:music-sequence::cumulative-length-callback)
503 (start-callback . ,ly:music-sequence::first-start-callback)
504 (elements-callback . ,(lambda (m) (ly:music-property m 'elements)))
505 (iterator-ctor . ,ly:sequential-iterator::constructor)
506 (types . (general-music sequential-music))
510 . ((description . "Music playing together.
512 Syntax: @code{\\simultaneous @{ @dots{} @}} or @code{<< @dots{} >>}")
513 (iterator-ctor . ,ly:simultaneous-music-iterator::constructor)
514 (start-callback . ,ly:music-sequence::minimum-start-callback)
515 (length-callback . ,ly:music-sequence::maximum-length-callback)
516 (to-relative-callback .
517 ,ly:music-sequence::simultaneous-relative-callback)
518 (types . (general-music simultaneous-music))
522 . ((description . "Filler that takes up duration, but does not
525 Syntax: @code{s4} for a skip equivalent to a quarter rest.")
526 (types . (general-music event rhythmic-event skip-event))
530 . ((description . "Filler that takes up duration, does not
531 print anything, and also does not create staves or voices implicitly.
533 Syntax: @code{\\skip} @var{duration}")
534 (length-callback . ,ly:music-duration-length)
535 (iterator-ctor . ,ly:simple-music-iterator::constructor)
536 (types . (general-music event rhythmic-event skip-event))
540 . ((description . "Start or end slur.
542 Syntax: @var{note}@code{(} and @var{note}@code{)}")
543 (types . (general-music span-event event slur-event))
547 . ((description . "Print @q{Solo@tie{}1}.")
548 (part-combine-status . solo1)
549 (types . (general-music event part-combine-event solo-one-event))
553 . ((description . "Print @q{Solo@tie{}2}.")
554 (part-combine-status . solo2)
555 (types . (general-music event part-combine-event solo-two-event))
559 . ((description . "Depress or release sostenuto pedal.")
560 (types . (general-music event pedal-event sostenuto-event))
564 . ((description . "Start a new spacing section.")
565 (types . (general-music event spacing-section-event))))
568 . ((description . "Event for anything that is started at a
569 different time than stopped.")
570 (types . (general-music event))
574 . ((description . "Start or stop a staff symbol.")
575 (types . (general-music event span-event staff-span-event))
579 . ((description . "Specify on which string to play this note.
581 Syntax: @code{\\@var{number}}")
582 (types . (general-music string-number-event event))
586 . ((description . "Specify with which finger to pluck a string.
588 Syntax: @code{\\rightHandFinger @var{text}}")
589 (types . (general-music stroke-finger-event event))
593 . ((description . "Depress or release sustain pedal.")
594 (types . (general-music event pedal-event sustain-event))
598 . ((description . "Print text.")
599 (types . (general-music script-event text-script-event event))
603 . ((description . "Start a text spanner, for example, an
605 (types . (general-music span-event event text-span-event))
609 . ((description . "A tie.
611 Syntax: @var{note}@code{-~}")
612 (types . (general-music tie-event event))
616 . ((description . "Multiply durations, as in tuplets.
618 Syntax: @code{\\times @var{fraction} @var{music}}, e.g.,
619 @code{\\times 2/3 @{ @dots{} @}} for triplets.")
620 (length-callback . ,ly:music-wrapper::length-callback)
621 (start-callback . ,ly:music-wrapper::start-callback)
622 (iterator-ctor . ,ly:tuplet-iterator::constructor)
623 (types . (time-scaled-music music-wrapper-music general-music))
627 . ((description . "Music that has been transposed.")
628 (iterator-ctor . ,ly:music-wrapper-iterator::constructor)
629 (start-callback . ,ly:music-wrapper::start-callback)
630 (length-callback . ,ly:music-wrapper::length-callback)
631 (to-relative-callback .
632 ,ly:relative-octave-music::no-relative-callback)
633 (types . (music-wrapper-music general-music transposed-music))
637 . ((description . "Unmeasured tremolo.")
638 (types . (general-music event tremolo-event))
641 (TremoloRepeatedMusic
642 . ((description . "Repeated notes denoted by tremolo beams.")
643 (iterator-ctor . ,ly:chord-tremolo-iterator::constructor)
644 (start-callback . ,ly:repeated-music::first-start)
645 ;; the length of the repeat is handled by shifting the note logs
646 (length-callback . ,ly:repeated-music::folded-music-length)
647 (types . (general-music repeated-music tremolo-repeated-music))
651 . ((description . "Tremolo over two stems.")
652 (types . (general-music event span-event tremolo-span-event))
656 . ((description . "Start a trill spanner.")
657 (types . (general-music span-event event trill-span-event))
661 . ((description . "Used internally to signal where tuplet
662 brackets start and stop.")
663 (types . (tuplet-span-event span-event event general-music))
667 . ((description . "Depress or release una-corda pedal.")
668 (types . (general-music event pedal-event una-corda-event))
671 (UnfoldedRepeatedMusic
672 . ((description . "Repeated music which is fully written
674 (iterator-ctor . ,ly:unfolded-repeat-iterator::constructor)
675 (start-callback . ,ly:repeated-music::first-start)
676 (types . (general-music repeated-music unfolded-repeated-music))
677 (length-callback . ,ly:repeated-music::unfolded-music-length)
681 . ((description . "Print @q{a@tie{}2}.")
682 (part-combine-status . unisono)
683 (types . (general-music event part-combine-event unisono-event))))
686 . ((description . "Music that cannot be converted from relative
687 to absolute notation. For example, transposed music.")
688 (to-relative-callback . ,ly:relative-octave-music::no-relative-callback)
689 (iterator-ctor . ,ly:music-wrapper-iterator::constructor)
690 (length-callback . ,ly:music-wrapper::length-callback)
691 (types . (music-wrapper-music general-music unrelativable-music))
695 . ((description . "Separate polyphonic voices in simultaneous music.
697 Syntax: @code{\\\\}")
698 (types . (separator general-music))
702 . ((description . "Repeats with alternatives placed sequentially.")
703 (iterator-ctor . ,ly:volta-repeat-iterator::constructor)
704 (start-callback . ,ly:repeated-music::first-start)
705 (length-callback . ,ly:repeated-music::volta-music-length)
706 (types . (general-music repeated-music volta-repeated-music))
710 (set! music-descriptions
711 (sort music-descriptions alist<?))
713 (define-public music-name-to-property-table (make-vector 59 '()))
716 ;; transport description to an object property.
720 (set-object-property! (car x)
722 (cdr (assq 'description (cdr x))))
724 (set! lst (assoc-set! lst 'name (car x)))
725 (set! lst (assq-remove! lst 'description))
726 (hashq-set! music-name-to-property-table (car x) lst)
730 (define-safe-public (make-music name . music-properties)
731 "Create a music object of given name, and set its properties
732 according to @code{music-properties}, a list of alternating property symbols
734 (make-music 'OverrideProperty
736 'grob-property 'thickness
737 'grob-value (* 2 1.5))"
738 (if (not (symbol? name))
739 (ly:error (_ "symbol expected: ~S") name))
740 (let ((props (hashq-ref music-name-to-property-table name '())))
741 (if (not (pair? props))
742 (ly:error (_ "cannot find music object: ~S") name))
743 (let ((m (ly:make-music props)))
744 (define (set-props mus-props)
745 (if (and (not (null? mus-props))
746 (not (null? (cdr mus-props))))
748 (set! (ly:music-property m (car mus-props)) (cadr mus-props))
749 (set-props (cddr mus-props)))))
750 (set-props music-properties)
753 (define-public (make-repeated-music name)
754 (let* ((repeated-music (assoc-get name '(("volta" . VoltaRepeatedMusic)
755 ("unfold" . UnfoldedRepeatedMusic)
756 ("percent" . PercentRepeatedMusic)
757 ("tremolo" . TremoloRepeatedMusic))))
758 (repeated-music-name (if repeated-music
761 (ly:warning (_ "unknown repeat type `~S'") name)
762 (ly:warning (_ "See define-music-types.scm for supported repeats"))
763 'VoltaRepeatedMusic))))
764 (make-music repeated-music-name)))