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
14 SetProperty MusicEvent OldMusicEvent CreateContext Prepare
15 OneTimeStep Finish) . StreamEvent)
16 ((arpeggio-event) . MusicEvent)
17 ((Announcement) . '())
18 ((AnnounceNewContext) . Announcement)
21 ;; Maps event-class to a list of ancestors (inclusive)
22 ;; TODO: use resizable hash
23 (define ancestor-lookup (make-hash-table 1))
25 ;; Each class will be defined as
26 ;; (class parent grandparent .. )
27 ;; so that (eq? (cdr class) parent) holds.
32 (hashq-set! ancestor-lookup type (cons type (hashq-ref ancestor-lookup (cdr rel) '())))) ;; `(define ,type (cons ',type ,(cdr rel)))))
36 ;; TODO: Allow entering more complex classes, by taking unions.
37 (define-public (ly:make-event-class leaf)
38 (hashq-ref ancestor-lookup leaf))
39 ;; (primitive-eval leaf))
41 (defmacro-public make-stream-event (expr)
42 (Stream_event::undump (primitive-eval (list 'quasiquote expr))))
46 ;; Special case for lists reduces stack consumption.
47 ((list? e) (map simplify e))
48 ((pair? e) (cons (simplify (car e))
51 (list 'unquote `(make-stream-event ,(simplify (Stream_event::dump e)))))
53 (list 'unquote (music->make-music e)))
55 (list 'unquote `(ly:make-moment
56 ,(ly:moment-main-numerator e)
57 ,(ly:moment-main-denominator e)
58 . ,(if (eq? 0 (ly:moment-grace-numerator e))
60 (list (ly:moment-grace-numerator e)
61 (ly:moment-grace-denominator e))))))
63 (list 'unquote `(ly:make-duration
65 ,(ly:duration-dot-count e)
66 ,(car (ly:duration-factor e))
67 ,(cdr (ly:duration-factor e)))))
69 (list 'unquote `(ly:make-pitch
71 ,(ly:pitch-notename e)
72 ,(ly:pitch-alteration e))))
73 ((ly:input-location? e)
74 (list 'unquote '(ly:dummy-input-location)))
77 (define-public (ly:simplify-scheme e)
78 (list 'quasiquote (simplify e))
81 ; used by lily/dispatcher.cc
82 (define-public (car< a b) (< (car a) (car b)))