1 ;;;; stream-event-classes.scm -- define the tree of stream-event classes.
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2005-2006 Erik Sandberg <mandolaerik@gmail.com>
8 (use-modules (srfi srfi-1))
10 ;; Event class hierarchy. Each line is on the form ((List of children) . Parent)
12 '(((StreamEvent) . '())
13 ((RemoveContext ChangeParent Override Revert UnsetProperty SetProperty
14 MusicEvent CreateContext Prepare OneTimeStep Finish) . StreamEvent)
15 ((Announcement) . '())
16 ((AnnounceNewContext) . Announcement)
19 ;; Maps event-class to a list of ancestors (inclusive)
20 ;; TODO: use resizable hash
21 (define ancestor-lookup (make-hash-table 1))
23 ;; Each class will be defined as
24 ;; (class parent grandparent .. )
25 ;; so that (eq? (cdr class) parent) holds.
30 (hashq-set! ancestor-lookup type (cons type (hashq-ref ancestor-lookup (cdr rel) '())))) ;; `(define ,type (cons ',type ,(cdr rel)))))
34 ;; TODO: Allow entering more complex classes, by taking unions.
35 (define-public (ly:make-event-class leaf)
36 (hashq-ref ancestor-lookup leaf))
37 ;; (primitive-eval leaf))
39 (defmacro-public make-stream-event (expr)
40 (Stream_event::undump (primitive-eval (list 'quasiquote expr))))
44 ;; Special case for lists reduces stack consumption.
45 ((list? e) (map simplify e))
46 ((pair? e) (cons (simplify (car e))
49 (list 'unquote `(make-stream-event ,(simplify (Stream_event::dump e)))))
51 (list 'unquote (music->make-music e)))
53 (list 'unquote `(ly:make-moment
54 ,(ly:moment-main-numerator e)
55 ,(ly:moment-main-denominator e)
56 . ,(if (eq? 0 (ly:moment-grace-numerator e))
58 (list (ly:moment-grace-numerator e)
59 (ly:moment-grace-denominator e))))))
61 (list 'unquote `(ly:make-duration
63 ,(ly:duration-dot-count e)
64 ,(car (ly:duration-factor e))
65 ,(cdr (ly:duration-factor e)))))
67 (list 'unquote `(ly:make-pitch
69 ,(ly:pitch-notename e)
70 ,(ly:pitch-alteration e))))
71 ((ly:input-location? e)
72 (list 'unquote '(ly:dummy-input-location)))
75 (define-public (ly:simplify-scheme e)
76 (list 'quasiquote (simplify e))
79 ; used by lily/dispatcher.cc
80 (define-public (car< a b) (< (car a) (car b)))