]> git.donarmstrong.com Git - lilypond.git/blob - scm/define-event-classes.scm
Fix some bugs in the dynamic engraver and PostScript backend
[lilypond.git] / scm / define-event-classes.scm
1 ;;;; stream-event-classes.scm -- define the tree of stream-event classes.
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;;
5 ;;;; (c) 2005-2006 Erik Sandberg <mandolaerik@gmail.com>
6
7
8 (use-modules (srfi srfi-1))
9
10 ;; Event class hierarchy. Each line is on the form ((List of children) . Parent)
11 (define event-classes
12   '(((StreamEvent) . '())
13     ((RemoveContext ChangeParent Override Revert UnsetProperty SetProperty 
14       MusicEvent CreateContext Prepare OneTimeStep Finish) . StreamEvent)
15     ))
16
17 ;; Maps event-class to a list of ancestors (inclusive)
18 ;; TODO: use resizable hash
19 (define ancestor-lookup (make-hash-table 1))
20
21 ;; Each class will be defined as
22 ;; (class parent grandparent .. )
23 ;; so that (eq? (cdr class) parent) holds.
24 (for-each
25  (lambda (rel)
26    (for-each
27     (lambda (type)
28       (hashq-set! ancestor-lookup type (cons type (hashq-ref ancestor-lookup (cdr rel) '())))) ;; `(define ,type (cons ',type ,(cdr rel)))))
29     (car rel)))
30  event-classes)
31
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))
36
37 (defmacro-public make-stream-event (expr)
38   (Stream_event::undump (primitive-eval (list 'quasiquote expr))))
39
40 (define* (simplify e)
41   (cond
42    ;; Special case for lists reduces stack consumption.
43    ((list? e) (map simplify e))
44    ((pair? e) (cons (simplify (car e))
45                     (simplify (cdr e))))
46    ((ly:stream-event? e)
47     (list 'unquote `(make-stream-event ,(simplify (Stream_event::dump e)))))
48    ((ly:music? e)
49     (list 'unquote (music->make-music e)))
50    ((ly:moment? 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))
55                             '()
56                             (list (ly:moment-grace-numerator e)
57                                   (ly:moment-grace-denominator e))))))
58    ((ly:duration? e)
59     (list 'unquote `(ly:make-duration
60                      ,(ly:duration-log e)
61                      ,(ly:duration-dot-count e)
62                      ,(car (ly:duration-factor e))
63                      ,(cdr (ly:duration-factor e)))))
64    ((ly:pitch? e)
65     (list 'unquote `(ly:make-pitch
66                      ,(ly:pitch-octave e)
67                      ,(ly:pitch-notename e)
68                      ,(ly:pitch-alteration e))))
69    ((ly:input-location? e)
70     (list 'unquote '(ly:dummy-input-location)))
71    (#t e)))
72
73 (define-public (ly:simplify-scheme e)
74   (list 'quasiquote (simplify e))
75 )
76
77 ; used by lily/dispatcher.cc
78 (define-public (car< a b) (< (car a) (car b)))