Nitpick: ly:spanner-bound grob name slur -> spanner.
[lilypond.git] / scm / define-music-types.scm
blobc454cfd3a61a07b1ae33dea76393f3237cf3f15c
1 ;;;; define-music-types.scm --
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;;
5 ;;;; (c) 1998--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 ;;;;                 Jan Nieuwenhuizen <janneke@gnu.org>
8 ;; TODO: should link back into user manual.
10 (define (mm-rest-child-list music)
11   "Generate events for multimeasure rests,
12 to be used by the sequential-iterator"
13   (let ((location (ly:music-property music 'origin))
14         (duration (ly:music-property music 'duration)))
15     (list (make-music 'BarCheck
16                       'origin location)
17           (make-event-chord (cons (make-music 'MultiMeasureRestEvent
18                                               'origin location
19                                               'duration duration)
20                                   (ly:music-property music 'articulations)))
21           (make-music 'BarCheck
22                       'origin location))))
24 (define-public music-descriptions
25   `(
26     (AbsoluteDynamicEvent
27      . ((description . "Create a dynamic mark.
29 Syntax: @var{note}@code{\\x}, where @code{\\x} is a dynamic mark like
30 @code{\\ppp} or @code{\\sfz}.  A complete list is in file
31 @file{ly/@/dynamic-scripts-init.ly}.")
32         (types . (general-music event dynamic-event absolute-dynamic-event))
33         ))
35     (AnnotateOutputEvent
36      . ((description . "Print an annotation of an output element.")
37         (types . (general-music event annotate-output-event))
38         ))
40     (ApplyContext
41      . ((description . "Call the argument with the current context during
42 interpreting phase.")
43         (types . (general-music apply-context))
44         (iterator-ctor . ,ly:apply-context-iterator::constructor)
45         ))
47     (ApplyOutputEvent
48      . ((description . "Call the argument with all current grobs during
49 interpreting phase.
51 Syntax: @code{\\applyOutput #'@var{context} @var{func}}
53 Arguments to @var{func} are 1.@tie{}the grob, 2.@tie{}the originating
54 context, and 3.@tie{}the context where @var{func} is called.")
55         (types . (general-music event apply-output-event))
56         ))
58     (ArpeggioEvent
59      . ((description . "Make an arpeggio on this note.
61 Syntax: @var{note}@code{-\\arpeggio}")
62         (types . (general-music arpeggio-event event))
63         ))
65     ;; todo: use articulation-event for slur as well.
66     ;; separate non articulation scripts
67     (ArticulationEvent
68      . ((description . "Add an articulation marking to a note.
70 Syntax: @var{note}@code{x}@code{y}, where @code{x} is a direction
71 (@code{^} for up or @code{_} for down), or LilyPond's choice
72 (no direction specified)), and where @code{y} is an articulation
73 (such as @code{-.}, @code{->}, @code{\\tenuto}, @code{\\downbow}).
74 See the Notation Reference for details.")
75         (types . (general-music event articulation-event script-event))
76         ))
78     (AutoChangeMusic
79      . ((description . "Used for making voices that switch between
80 piano staves automatically.")
81         (iterator-ctor . ,ly:auto-change-iterator::constructor)
82         (start-callback . ,ly:music-wrapper::start-callback)
83         (length-callback . ,ly:music-wrapper::length-callback)
84         (types . (general-music music-wrapper-music auto-change-instruction))
85         ))
87     (BarCheck
88      . ((description . "Check whether this music coincides with
89 the start of the measure.")
90         (types . (general-music bar-check))
91         (iterator-ctor . ,ly:bar-check-iterator::constructor)
92         ))
94     (BassFigureEvent
95      . ((description . "Print a bass-figure text.")
96         (types . (general-music event rhythmic-event bass-figure-event))
97         ))
99     (BeamEvent
100      . ((description . "Start or stop a beam.
102 Syntax for manual control: @code{c8-[ c c-] c8}")
103         (types . (general-music event beam-event span-event))
104         ))
106     (BeamForbidEvent
107      . ((description . "Specify that a note may not auto-beamed.")
108         (types . (general-music event beam-forbid-event))
109         ))
111     (BendAfterEvent
112      . ((description . "A drop/fall/doit jazz articulation.")
113         (types . (general-music bend-after-event event))))
115     (BreathingEvent
116      . ((description . "Create a @q{breath mark} or @q{comma}.
118 Syntax: @var{note}@code{\\breathe}")
120         (types . (general-music event breathing-event))
121         ))
123     (ContextChange
124      . ((description . "Change staves in Piano staff.
126 Syntax: @code{\\change Staff = @var{new-id}}")
127         (iterator-ctor . ,ly:change-iterator::constructor)
128         (types . (general-music translator-change-instruction))
129         ))
131     (ClusterNoteEvent
132      . ((description . "A note that is part of a cluster.")
133         ;; not a note-event, to ensure that Note_engraver doesn't eat it.
134         (types . (general-music cluster-note-event melodic-event
135                   rhythmic-event event))
136         ))
138     (ContextSpeccedMusic
139      . ((description . "Interpret the argument music within a
140 specific context.")
141         (iterator-ctor . ,ly:context-specced-music-iterator::constructor)
142         (length-callback . ,ly:music-wrapper::length-callback)
143         (start-callback . ,ly:music-wrapper::start-callback)
144         (types . (context-specification general-music music-wrapper-music))
145         ))
147     (CrescendoEvent
148      . ((description . "Begin or end a crescendo.
150 Syntax: @var{note}@code{\\cr} @dots{} @var{note}@code{\\rc}
152 You can also use @code{\\<}, @code{\\!}, @code{\\cresc}, and
153 @code{\\endcresc}.  See the Notation Reference for details.")
154         (types . (general-music span-event span-dynamic-event crescendo-event
155                   event))
156         ))
158     (DecrescendoEvent
159      . ((description . "See @ref{CrescendoEvent}.")
160         (types . (general-music span-event span-dynamic-event decrescendo-event
161                   event))
162         ))
164     (ExtenderEvent
165      . ((description . "Extend lyrics.")
166         (types . (general-music extender-event event))
167         ))
169     (Event
170      . ((description . "Atomic music event.")
171         (types . (general-music event))
172         ))
174     (EventChord
175      . ((description . "Internally used to group a set of events.")
176         (iterator-ctor . ,ly:event-chord-iterator::constructor)
177         (length-callback . ,ly:music-sequence::maximum-length-callback)
178         (to-relative-callback .
179          ,ly:music-sequence::event-chord-relative-callback)
180         (types . (general-music event-chord simultaneous-music))
181         ))
183     (FingeringEvent
184      . ((description . "Specify what finger to use for this note.")
185         (types . (general-music fingering-event event))
186         ))
188     (GlissandoEvent
189      . ((description . "Start a glissando on this note.")
190         (types . (general-music glissando-event event))
191         ))
193     (GraceMusic
194      . ((description . "Interpret the argument as grace notes.")
195         (start-callback . ,ly:grace-music::start-callback)
196         (length . ,ZERO-MOMENT)
197         (iterator-ctor . ,ly:grace-iterator::constructor)
198         (types . (grace-music music-wrapper-music general-music))
199         ))
201     (HarmonicEvent
202      . ((description . "Mark a note as harmonic.")
203         (types . (general-music event harmonic-event))
204         ))
206     (HyphenEvent
207      . ((description . "A hyphen between lyric syllables.")
208         (types . (general-music hyphen-event event))
209         ))
211     (KeyChangeEvent
212      . ((description . "Change the key signature.
214 Syntax: @code{\\key} @var{name} @var{scale}")
215         (to-relative-callback . ,(lambda (x p) p))
216         (types . (general-music key-change-event event))
217         ))
219     (LabelEvent
220      . ((description . "Place a bookmarking label.")
221         (types . (general-music label-event event))
222         ))
224     (LaissezVibrerEvent
225      . ((description . "Don't damp this chord.
227 Syntax: @var{note}@code{\\laissezVibrer}")
228         (types . (general-music event laissez-vibrer-event))
229         ))
231     (LigatureEvent
232      . ((description . "Start or end a ligature.")
233         (span-type . ligature)
234         (types . (general-music span-event ligature-event event))
235         ))
237     (LineBreakEvent
238      . ((description . "Allow, forbid or force a line break.")
239         (types . (general-music line-break-event break-event event))
240         ))
242     (LyricCombineMusic
243      . ((description . "Align lyrics to the start of notes.
245 Syntax: @code{\\lyricsto} @var{voicename} @var{lyrics}")
246         (length . ,ZERO-MOMENT)
247         (types . (general-music lyric-combine-music))
248         (iterator-ctor . ,ly:lyric-combine-music-iterator::constructor)
249         ))
251     (LyricEvent
252      . ((description . "A lyric syllable.  Must be entered in lyrics mode,
253 i.e., @code{\\lyrics @{ twinkle4 twinkle4 @} }.")
254         (types . (general-music rhythmic-event lyric-event event))
255         ))
257     (MarkEvent
258      . ((description . "Insert a rehearsal mark.
260 Syntax: @code{\\mark} @var{marker}
262 Example: @code{\\mark \"A\"}")
263         (types . (general-music mark-event event))
264         ))
266     (MultiMeasureRestEvent
267      . ((description . "Used internally by @code{MultiMeasureRestMusic}
268 to signal rests.")
269         (types . (general-music event rhythmic-event
270                   multi-measure-rest-event))
271         ))
273     (MultiMeasureRestMusic
274      . ((description . "Rests that may be compressed into Multi rests.
276 Syntax: @code{R2.*4} for 4 measures in 3/4 time.")
277         (iterator-ctor . ,ly:sequential-iterator::constructor)
278         (elements-callback . ,mm-rest-child-list)
279         (types . (general-music multi-measure-rest))
280         ))
282     (MultiMeasureTextEvent
283      . ((description . "Texts on multi measure rests.
285 Syntax: @code{R-\\markup @{ \\roman \"bla\" @}}
287 Note the explicit font switch.")
288         (types . (general-music event multi-measure-text-event))
289         ))
291     (Music
292      . ((description . "Generic type for music expressions.")
293         (types . (general-music))
294         ))
296     (NoteEvent
297      . ((description . "A note.")
298         (types . (general-music event note-event rhythmic-event
299                   melodic-event))
300         ))
302     (NoteGroupingEvent
303      . ((description . "Start or stop grouping brackets.")
304         (types . (general-music event note-grouping-event))
305         ))
307     (OverrideProperty
308      . ((description . "Extend the definition of a graphical object.
310 Syntax: @code{\\override} [ @var{context} @code{.} ]
311 @var{object} @var{property} @code{=} @var{value}")
312         (types . (general-music layout-instruction-event
313                   override-property-event))
314         (iterator-ctor . ,ly:push-property-iterator::constructor)
315         ))
317     (PageBreakEvent
318      . ((description . "Allow, forbid or force a page break.")
319         (types . (general-music break-event page-break-event event))
320         ))
322     (PageTurnEvent
323      . ((description . "Allow, forbid or force a page turn.")
324         (types . (general-music break-event page-turn-event event))
325         ))
327     (PartCombineMusic
328      . ((description . "Combine two parts on a staff, either merged or
329 as separate voices.")
330         (length-callback . ,ly:music-sequence::maximum-length-callback)
331         (start-callback . ,ly:music-sequence::minimum-start-callback)
332         (types . (general-music part-combine-music))
333         (iterator-ctor . ,ly:part-combine-iterator::constructor)
334         ))
336     (PercentEvent
337      . ((description . "Used internally to signal percent repeats.")
338         (types . (general-music event percent-event rhythmic-event))
339         ))
341     (PercentRepeatedMusic
342      . ((description . "Repeats encoded by percents.")
343         (iterator-ctor . ,ly:percent-repeat-iterator::constructor)
344         (start-callback .  ,ly:repeated-music::first-start)
345         (length-callback . ,ly:repeated-music::unfolded-music-length)
346         (types . (general-music repeated-music percent-repeated-music))
347         ))
349     (PesOrFlexaEvent
350      . ((description . "Within a ligature, mark the previous and the
351 following note to form a pes (if melody goes up) or a flexa (if melody
352 goes down).")
353         (types . (general-music pes-or-flexa-event event))
354         ))
356     (PhrasingSlurEvent
357      . ((description . "Start or end phrasing slur.
359 Syntax: @var{note}@code{\\(} and @var{note}@code{\\)}")
360         (types . (general-music span-event event phrasing-slur-event))
361         ))
363     (PropertySet
364      . ((description . "Set a context property.
366 Syntax: @code{\\property @var{context}.@var{prop} = @var{scheme-val}}")
367         (types . (layout-instruction-event general-music))
368         (iterator-ctor . ,ly:property-iterator::constructor)
369         ))
371     (PropertyUnset
372      . ((description . "Remove the definition of a context
373 @code{\\property}.")
374         (types . (layout-instruction-event general-music))
375         (iterator-ctor . ,ly:property-unset-iterator::constructor)
376         ))
378     (QuoteMusic
379      . ((description . "Quote preprocessed snippets of music.")
380         (iterator-ctor . ,ly:music-wrapper-iterator::constructor)
381         (length-callback . ,ly:music-wrapper::length-callback)
382         (start-callback . ,ly:music-wrapper::start-callback)
383         (types . (general-music music-wrapper-music))
384         ))
386     (RelativeOctaveCheck
387      . ((description . "Check if a pitch is in the correct octave.")
388         (to-relative-callback . ,ly:relative-octave-check::relative-callback)
389         (types . (general-music relative-octave-check))
390         ))
392     (RelativeOctaveMusic
393      . ((description . "Music that was entered in relative octave notation.")
394         (to-relative-callback . ,ly:relative-octave-music::relative-callback)
395         (iterator-ctor . ,ly:music-wrapper-iterator::constructor)
396         (length-callback . ,ly:music-wrapper::length-callback)
397         (start-callback . ,ly:music-wrapper::start-callback)
398         (types . (music-wrapper-music general-music relative-octave-music))
399         ))
401     (RepeatTieEvent
402      . ((description . "Ties for starting a second volta bracket.")
403         (types . (general-music event repeat-tie-event))
404         ))
406     (RepeatedMusic
407      . ((description . "Repeat music in different ways.")
408         (types . (general-music repeated-music))
409         ))
411     (RestEvent
412      . ((description . "A Rest.
414 Syntax: @code{r4} for a quarter rest.")
415         (types . (general-music event rhythmic-event rest-event))
416         ))
418     (RevertProperty
419      . ((description . "The opposite of @ref{OverrideProperty}: remove a
420 previously added property from a graphical object definition.")
421         (types . (general-music layout-instruction-event))
422         (iterator-ctor . ,ly:pop-property-iterator::constructor)
423         ))
425     (ScriptEvent
426      . ((description . "Add an articulation mark to a note.")
427         (types . (general-music event))
428         ))
430     (SequentialMusic
431      . ((description . "Music expressions concatenated.
433 Syntax: @code{\\sequential @{ @dots{} @}} or simply @code{@{ @dots{} @}}")
434         (length-callback . ,ly:music-sequence::cumulative-length-callback)
435         (start-callback . ,ly:music-sequence::first-start-callback)
436         (elements-callback . ,(lambda (m) (ly:music-property m 'elements)))
437         (iterator-ctor . ,ly:sequential-iterator::constructor)
438         (types . (general-music sequential-music))
439         ))
441     (SimultaneousMusic
442      . ((description . "Music playing together.
444 Syntax: @code{\\simultaneous @{ @dots{} @}} or @code{<< @dots{} >>}")
445         (iterator-ctor . ,ly:simultaneous-music-iterator::constructor)
446         (start-callback . ,ly:music-sequence::minimum-start-callback)
447         (length-callback . ,ly:music-sequence::maximum-length-callback)
448         (to-relative-callback .
449          ,ly:music-sequence::simultaneous-relative-callback)
450         (types . (general-music simultaneous-music))
451         ))
453     (SkipEvent
454      . ((description . "Filler that takes up duration, but does not
455 print anything.
457 Syntax: @code{s4} for a skip equivalent to a quarter rest.")
458         (types . (general-music event rhythmic-event skip-event))
459         ))
461     (SkipMusic
462      . ((description . "Filler that takes up duration, does not
463 print anything, and also does not create staves or voices implicitly.
465 Syntax: @code{\\skip} @var{duration}")
466         (length-callback . ,ly:music-duration-length)
467         (iterator-ctor . ,ly:simple-music-iterator::constructor)
468         (types . (general-music event rhythmic-event skip-event))
469         ))
471     (SlurEvent
472      . ((description . "Start or end slur.
474 Syntax: @var{note}@code{(} and @var{note}@code{)}")
475         (types . (general-music span-event event slur-event))
476         ))
478     (SoloOneEvent
479      . ((description . "Print @q{Solo@tie{}1}.")
480         (part-combine-status . solo1)
481         (types . (general-music event part-combine-event solo-one-event))
482         ))
484     (SoloTwoEvent
485      . ((description . "Print @q{Solo@tie{}2}.")
486         (part-combine-status . solo2)
487         (types . (general-music event part-combine-event solo-two-event))
488         ))
490     (SostenutoEvent
491      . ((description . "Depress or release sostenuto pedal.")
492         (types . (general-music event pedal-event sostenuto-event))
493         ))
495     (SpacingSectionEvent
496      . ((description . "Start a new spacing section.")
497         (types . (general-music event spacing-section-event))))
499     (SpanEvent
500      . ((description . "Event for anything that is started at a
501 different time than stopped.")
502         (types . (general-music event))
503         ))
505     (StaffSpanEvent
506      . ((description . "Start or stop a staff symbol.")
507         (types . (general-music event span-event staff-span-event))
508      ))
510     (StringNumberEvent
511      . ((description . "Specify on which string to play this note.
513 Syntax: @code{\\@var{number}}")
514         (types . (general-music string-number-event event))
515         ))
517     (StrokeFingerEvent
518      . ((description . "Specify with which finger to pluck a string.
520 Syntax: @code{\\rightHandFinger @var{text}}")
521         (types . (general-music stroke-finger-event event))
522         ))
524     (SustainEvent
525      . ((description . "Depress or release sustain pedal.")
526         (types . (general-music event pedal-event sustain-event))
527         ))
529     (TextScriptEvent
530      . ((description . "Print text.")
531         (types . (general-music script-event text-script-event event))
532         ))
534     (TextSpanEvent
535      . ((description . "Start a text spanner, e.g., 8va.....|")
536         (types . (general-music span-event event text-span-event))
537         ))
539     (TieEvent
540      . ((description . "A tie.
542 Syntax: @var{note}@code{-~}")
543         (types . (general-music tie-event event))
544         ))
546     (TimeScaledMusic
547      . ((description . "Multiply durations, as in tuplets.
549 Syntax: @code{\\times @var{fraction} @var{music}}, e.g.
550 @code{\\times 2/3 @{ @dots{} @}} for triplets.")
551         (length-callback . ,ly:music-wrapper::length-callback)
552         (start-callback . ,ly:music-wrapper::start-callback)
553         (iterator-ctor . ,ly:time-scaled-music-iterator::constructor)
554         (types . (time-scaled-music music-wrapper-music general-music))
555         ))
557     (TransposedMusic
558      . ((description . "Music that has been transposed.")
559         (iterator-ctor . ,ly:music-wrapper-iterator::constructor)
560         (start-callback . ,ly:music-wrapper::start-callback)
561         (length-callback . ,ly:music-wrapper::length-callback)
562         (to-relative-callback .
563          ,ly:relative-octave-music::no-relative-callback)
564         (types . (music-wrapper-music general-music transposed-music))
565         ))
567     (TremoloEvent
568      . ((description . "Unmeasured tremolo.")
569         (types . (general-music event tremolo-event))
570         ))
572     (TremoloRepeatedMusic
573      . ((description . "Repeated notes denoted by tremolo beams.")
574         (iterator-ctor . ,ly:chord-tremolo-iterator::constructor)
575         (start-callback .  ,ly:repeated-music::first-start)
576         ;; the length of the repeat is handled by shifting the note logs
577         (length-callback . ,ly:repeated-music::folded-music-length)
578         (types . (general-music repeated-music tremolo-repeated-music))
579         ))
581     (TremoloSpanEvent
582      . ((description . "Tremolo over two stems")
583         (types . (general-music event span-event tremolo-span-event))
584         ))
586     (TrillSpanEvent
587      . ((description . "Start a trill spanner tr~~~")
588         (types . (general-music span-event event trill-span-event))
589         ))
591     (TupletSpanEvent
592      . ((description . "Used internally to signal where tuplet
593 brackets start and stop.")
594         (types . (tuplet-span-event span-event event general-music))
595        ))
597     (UnaCordaEvent
598      . ((description . "Depress or release una-corda pedal.")
599         (types . (general-music event pedal-event una-corda-event))
600         ))
602     (UnfoldedRepeatedMusic
603      . ((description . "Repeated music which is fully written
604 (and played) out.")
605         (iterator-ctor . ,ly:unfolded-repeat-iterator::constructor)
606         (start-callback .  ,ly:repeated-music::first-start)
607         (types . (general-music repeated-music unfolded-repeated-music))
608         (length-callback . ,ly:repeated-music::unfolded-music-length)
609         ))
611     (UnisonoEvent
612      . ((description . "Print @q{a@tie{}2}.")
613         (part-combine-status . unisono)
614         (types . (general-music event part-combine-event unisono-event))))
616     (UnrelativableMusic
617      . ((description . "Music that cannot be converted from relative
618 to absolute notation.  For example, transposed music.")
619         (to-relative-callback . ,ly:relative-octave-music::no-relative-callback)
620         (iterator-ctor . ,ly:music-wrapper-iterator::constructor)
621         (length-callback . ,ly:music-wrapper::length-callback)
622         (types . (music-wrapper-music general-music unrelativable-music))
623         ))
625     (VoiceSeparator
626      . ((description . "Separate polyphonic voices in simultaneous music.
628 Syntax: @code{\\\\}")
629         (types . (separator general-music))
630         ))
632     (VoltaRepeatedMusic
633      . ((description . "Repeats with alternatives placed sequentially.")
634         (iterator-ctor . ,ly:volta-repeat-iterator::constructor)
635         (start-callback .  ,ly:repeated-music::first-start)
636         (length-callback . ,ly:repeated-music::volta-music-length)
637         (types . (general-music repeated-music volta-repeated-music))
638         ))
639     ))
641 (set! music-descriptions
642       (sort music-descriptions alist<?))
644 (define-public music-name-to-property-table (make-vector 59 '()))
646 ;; init hash table,
647 ;; transport description to an object property.
648 (set!
649  music-descriptions
650  (map (lambda (x)
651         (set-object-property! (car x)
652                               'music-description
653                               (cdr (assq 'description (cdr x))))
654         (let ((lst (cdr x)))
655           (set! lst (assoc-set! lst 'name (car x)))
656           (set! lst (assq-remove! lst 'description))
657           (hashq-set! music-name-to-property-table (car x) lst)
658           (cons (car x) lst)))
659       music-descriptions))
661 (define-safe-public (make-music name . music-properties)
662   "Create a music object of given name, and set its properties
663 according to @code{music-properties}, a list of alternating property symbols
664 and values. E.g:
665   (make-music 'OverrideProperty
666               'symbol 'Stem
667               'grob-property 'thickness
668               'grob-value (* 2 1.5))"
669   (if (not (symbol? name))
670       (ly:error (_ "symbol expected: ~S") name))
671   (let ((props (hashq-ref music-name-to-property-table name '())))
672     (if (not (pair? props))
673         (ly:error (_ "cannot find music object: ~S") name))
674     (let ((m (ly:make-music props)))
675       (define (set-props mus-props)
676         (if (and (not (null? mus-props))
677                  (not (null? (cdr mus-props))))
678             (begin
679               (set! (ly:music-property m (car mus-props)) (cadr mus-props))
680               (set-props (cddr mus-props)))))
681       (set-props music-properties)
682       m)))
684 (define-public (make-repeated-music name)
685   (let* ((handle (assoc name '(("volta" . VoltaRepeatedMusic)
686                                ("unfold" . UnfoldedRepeatedMusic)
687                                ("percent" . PercentRepeatedMusic)
688                                ("tremolo" . TremoloRepeatedMusic))))
689          (music-name (if (pair? handle)
690                          (cdr handle)
691                          (begin
692                            (ly:warning (_ "unknown repeat type `~S'") name)
693                            (ly:warning (_ "See define-music-types.scm for supported repeats"))
694                            'VoltaRepeatedMusic))))
695     (make-music music-name)))