X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scm%2Fdefine-event-classes.scm;h=30f48999adcb17661af1a52130d99598903974ed;hb=7dcae7597fae14ce5c4e2e7d50c2709d162b7332;hp=3d8b1b14261d4879e756c1e9cc9af244d013760f;hpb=862601226f319d2395794fe1175e7f17485b8e19;p=lilypond.git diff --git a/scm/define-event-classes.scm b/scm/define-event-classes.scm index 3d8b1b1426..30f48999ad 100644 --- a/scm/define-event-classes.scm +++ b/scm/define-event-classes.scm @@ -7,18 +7,42 @@ (use-modules (srfi srfi-1)) -;; Event class hierarchy. Each line is on the form ((List of children) . Parent) +;; Event class hierarchy. Each line is on the form (Parent . (List of children)) (define event-classes - '(((StreamEvent) . '()) - ((RemoveContext ChangeParent Override Revert UnsetProperty SetProperty - MusicEvent CreateContext Prepare OneTimeStep Finish) . StreamEvent) - ((Announcement) . '()) - ((AnnounceNewContext) . Announcement) + '((() . (StreamEvent)) + (StreamEvent . + (RemoveContext ChangeParent Override Revert UnsetProperty + SetProperty music-event OldMusicEvent CreateContext Prepare + OneTimeStep Finish)) + (music-event . (arpeggio-event breathing-event extender-event span-event + rhythmic-event dynamic-event break-event percent-event + key-change-event string-number-event tie-event part-combine-event + beam-forbid-event script-event + tremolo-event bend-after-event fingering-event glissando-event + harmonic-event hyphen-event laissez-vibrer-event mark-event + multi-measure-text-event note-grouping-event + pes-or-flexa-event repeat-tie-event spacing-section-event + layout-instruction-event)) + (layout-instruction-event . (apply-output-event)) + (script-event . (articulation-event text-script-event)) + (part-combine-event . (solo1-event solo2-event unisono-event)) + (break-event . (line-break-event page-break-event page-turn-event)) + (dynamic-event . (absolute-dynamic-event)) + (span-event . (span-dynamic-event beam-event ligature-event + pedal-event phrasing-slur-event slur-event staff-span-event + text-span-event trill-span-event tremolo-span-event + tuplet-span-event)) + (span-dynamic-event . (decrescendo-event crescendo-event)) + (pedal-event . (sostenuto-event sustain-event una-corda-event)) + (rhythmic-event . (lyric-event melodic-event multi-measure-rest-event + rest-event skip-event bass-figure-event)) + (melodic-event . (cluster-note-event note-event)) + (() . (Announcement)) + (Announcement . (AnnounceNewContext)) )) ;; Maps event-class to a list of ancestors (inclusive) -;; TODO: use resizable hash -(define ancestor-lookup (make-hash-table 1)) +(define ancestor-lookup (make-hash-table 11)) ;; Each class will be defined as ;; (class parent grandparent .. ) @@ -27,14 +51,72 @@ (lambda (rel) (for-each (lambda (type) - (hashq-set! ancestor-lookup type (cons type (hashq-ref ancestor-lookup (cdr rel) '())))) ;; `(define ,type (cons ',type ,(cdr rel))))) - (car rel))) + (hashq-set! ancestor-lookup type + (cons type (hashq-ref ancestor-lookup (car rel) '())))) + (cdr rel))) event-classes) ;; TODO: Allow entering more complex classes, by taking unions. (define-public (ly:make-event-class leaf) (hashq-ref ancestor-lookup leaf)) -;; (primitive-eval leaf)) + +;; does this exist in guile already? +(define (map-tree f t) + (cond + ((list? t) + (map (lambda (x) (map-tree f x)) t)) + ((pair? t) + (cons (map-tree f (car t)) (map-tree f (cdr t)))) + (else (f t)))) + +;; expand each non-leaf subtree to (root . children), recursively +(define (expand-event-tree root) + (let ((children (assq root event-classes))) + (if children + (cons root (map expand-event-tree (cdr children))) + root))) + +;; All leaf event classes that no translator listens to +;; directly. Avoids printing a warning. +(define unlistened-music-event-classes + '(harmonic-event line-break-event page-break-event page-turn-event + solo1-event solo2-event skip-event unisono-event)) + +;; produce neater representation of music event tree. +;; TODO: switch to this representation for the event-classes list? +(define music-event-tree (expand-event-tree 'music-event)) +(define (sort-tree t) + (define (stringify el) + (if (symbol? el) + (symbol->string el) + (symbol->string (first el)))) + (if (list? t) + (sort (map (lambda (el) + (if (list? el) + (cons (car el) (sort-tree (cdr el))) + el)) + t) + (lambda (a b) (string