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)
17 ;; Maps event-class to a list of ancestors (inclusive)
18 ;; TODO: use resizable hash
19 (define ancestor-lookup (make-hash-table 1))
21 ;; Each class will be defined as
22 ;; (class parent grandparent .. )
23 ;; so that (eq? (cdr class) parent) holds.
28 (hashq-set! ancestor-lookup type (cons type (hashq-ref ancestor-lookup (cdr rel) '())))) ;; `(define ,type (cons ',type ,(cdr rel)))))
32 ;; TODO: Allow entering more complex classes, by taking unions.
33 (define-public (ly:make-event-class leaf)
34 (hashq-ref ancestor-lookup leaf))
35 ;; (primitive-eval leaf))
37 (defmacro-public make-stream-event (expr)
38 (Stream_event::undump (primitive-eval (list 'quasiquote expr))))
42 ;; Special case for lists reduces stack consumption.
43 ((list? e) (map simplify e))
44 ((pair? e) (cons (simplify (car e))
47 (list 'unquote `(make-stream-event ,(simplify (Stream_event::dump e)))))
49 (list 'unquote (music->make-music e)))
51 (list 'unquote `(ly:make-moment
52 ,(ly:moment-main-numerator e)
53 ,(ly:moment-main-denominator e)
54 . ,(if (eq? 0 (ly:moment-grace-numerator e))
56 (list (ly:moment-grace-numerator e)
57 (ly:moment-grace-denominator e))))))
59 (list 'unquote `(ly:make-duration
61 ,(ly:duration-dot-count e)
62 ,(car (ly:duration-factor e))
63 ,(cdr (ly:duration-factor e)))))
65 (list 'unquote `(ly:make-pitch
67 ,(ly:pitch-notename e)
68 ,(ly:pitch-alteration e))))
69 ((ly:input-location? e)
70 (list 'unquote '(ly:dummy-input-location)))
73 (define-public (ly:simplify-scheme e)
74 (list 'quasiquote (simplify e))
77 ; used by lily/dispatcher.cc
78 (define-public (car< a b) (< (car a) (car b)))