1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 2005--2012 Erik Sandberg <mandolaerik@gmail.com>
5 ;;;; LilyPond is free software: you can redistribute it and/or modify
6 ;;;; it under the terms of the GNU General Public License as published by
7 ;;;; the Free Software Foundation, either version 3 of the License, or
8 ;;;; (at your option) any later version.
10 ;;;; LilyPond is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;;;; GNU General Public License for more details.
15 ;;;; You should have received a copy of the GNU General Public License
16 ;;;; along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
19 (use-modules (srfi srfi-1))
21 ;; Event class hierarchy. Each line is on the form (Parent . (List of children))
23 '((() . (StreamEvent))
25 (RemoveContext ChangeParent Override Revert UnsetProperty
26 SetProperty music-event OldMusicEvent CreateContext Prepare
28 (music-event . (annotate-output-event footnote-event
29 arpeggio-event breathing-event extender-event span-event
30 rhythmic-event dynamic-event break-event label-event percent-event
31 key-change-event string-number-event stroke-finger-event tie-event
32 part-combine-event part-combine-force-event
33 beam-forbid-event script-event tempo-change-event
34 tremolo-event bend-after-event fingering-event glissando-event
35 harmonic-event hyphen-event laissez-vibrer-event mark-event
36 multi-measure-text-event note-grouping-event
37 pes-or-flexa-event repeat-tie-event spacing-section-event
38 layout-instruction-event completize-extender-event break-span-event
41 (layout-instruction-event . (apply-output-event))
42 (script-event . (articulation-event text-script-event))
43 (part-combine-event . (solo-one-event solo-two-event unisono-event))
44 (break-event . (line-break-event page-break-event page-turn-event))
45 (dynamic-event . (absolute-dynamic-event))
46 (span-event . (span-dynamic-event beam-event episema-event ligature-event
47 pedal-event phrasing-slur-event slur-event staff-span-event
48 text-span-event trill-span-event tremolo-span-event
50 (span-dynamic-event . (decrescendo-event crescendo-event))
51 (break-span-event . (break-dynamic-span-event))
52 (pedal-event . (sostenuto-event sustain-event una-corda-event))
53 (rhythmic-event . (lyric-event melodic-event multi-measure-rest-event
54 double-percent-event percent-event
55 repeat-slash-event rest-event
56 skip-event bass-figure-event))
57 (melodic-event . (cluster-note-event note-event))
59 (Announcement . (AnnounceNewContext))
62 (define-public (event-class-cons class parent classlist)
63 (let ((lineage (assq parent classlist)))
66 (if (not (null? parent))
67 (ly:warning (_ "unknown parent class `~a'") parent))
70 (acons class lineage classlist)
71 (fold (lambda (elt alist)
72 (acons elt lineage alist))
75 ;; Each class will be defined as
76 ;; (class parent grandparent .. )
77 ;; so that (eq? (cdr class) parent) holds.
79 (define-public (ly:in-event-class? ev cl)
80 "Does event @var{ev} belong to event class @var{cl}?"
81 (memq cl (ly:event-property ev 'class)))
83 (define-public all-event-classes
84 (fold (lambda (elt classlist)
85 (event-class-cons (cdr elt) (car elt) classlist))
88 ;; does this exist in guile already?
89 (define (map-tree f t)
92 (map (lambda (x) (map-tree f x)) t))
94 (cons (map-tree f (car t)) (map-tree f (cdr t))))
97 ;; expand each non-leaf subtree to (root . children), recursively
98 (define (expand-event-tree root)
99 (let ((children (assq root event-classes)))
101 (cons root (map expand-event-tree (cdr children)))
104 ;; produce neater representation of music event tree.
105 ;; TODO: switch to this representation for the event-classes list?
106 (define music-event-tree (expand-event-tree 'music-event))
107 (define (sort-tree t)
108 (define (stringify el)
111 (symbol->string (first el))))
113 (sort (map (lambda (el)
115 (cons (car el) (sort-tree (cdr el)))
118 (lambda (a b) (string<? (stringify a) (stringify b))))
121 ;;(use-modules (ice-9 pretty-print))
122 ;;(pretty-print (cons (car music-event-tree) (sort-tree (cdr music-event-tree))))
124 (defmacro-public make-stream-event (expr)
125 (Stream_event::undump (primitive-eval (list 'quasiquote expr))))
127 (define* (simplify e)
129 ;; Special case for lists reduces stack consumption.
130 ((list? e) (map simplify e))
131 ((pair? e) (cons (simplify (car e))
133 ((ly:stream-event? e)
134 (list 'unquote (list 'make-stream-event (simplify (Stream_event::dump e)))))
136 (list 'unquote (music->make-music e)))
138 (list 'unquote `(ly:make-moment
139 ,(ly:moment-main-numerator e)
140 ,(ly:moment-main-denominator e)
141 . ,(if (eq? 0 (ly:moment-grace-numerator e))
143 (list (ly:moment-grace-numerator e)
144 (ly:moment-grace-denominator e))))))
146 (list 'unquote `(ly:make-duration
148 ,(ly:duration-dot-count e)
149 ,(car (ly:duration-factor e))
150 ,(cdr (ly:duration-factor e)))))
152 (list 'unquote `(ly:make-pitch
154 ,(ly:pitch-notename e)
155 ,(ly:pitch-alteration e))))
156 ((ly:input-location? e)
157 (list 'unquote '(ly:dummy-input-location)))
160 (define-public (ly:simplify-scheme e)
161 (list 'quasiquote (simplify e)))