-(use-modules (ice-9 regex))
+(use-modules (ice-9 regex)
+ (srfi srfi-1))
+
+
+;; should make module?
+
"
That is much cleaner: building the document, and dumping it to output
is then separated.
+
+ foo = \score { ... }
+
+ #(as-xml foo)
+
+ <score>
+ <music></music>
+ <paperoutput>
+ </paperoutput>
+ </score>
+
+
+
"
(define (dump-duration d port)
(display (open-tag 'duration
- `((log . ,(duration-log d))
- (dots . ,(duration-dot-count d))
- (numer . ,(car (duration-factor d)))
- (denom . ,(cdr (duration-factor d)))
+ `((log . ,(ly:duration-log d))
+ (dots . ,(ly:duration-dot-count d))
+ (numer . ,(car (ly:duration-factor d)))
+ (denom . ,(cdr (ly:duration-factor d)))
)
'() ) port)
(display (close-tag 'duration) port))
(define (dump-pitch p port)
(display (open-tag 'pitch
- `((octave . ,(pitch-octave p))
- (notename . ,(pitch-notename p))
- (alteration . ,(pitch-alteration p))
+ `((octave . ,(ly:pitch-octave p))
+ (notename . ,(ly:pitch-notename p))
+ (alteration . ,(ly:pitch-alteration p))
)
'() ) port)
(display (close-tag 'pitch) port))
(regexp-substitute/global #f re string 'pre to 'post))
(define (re-sub-alist string alist)
- (re-sub (caar alist) (cdar alist)
- (if (pair? (cdr alist))
- (re-sub-alist string (cdr alist))
- string)))
+ (if (null? alist)
+ string
+ (re-sub (caar alist) (cdar alist)
+ (re-sub-alist string (cdr alist)))))
+
+(define xml-entities-alist
+ '(("\"" . """)
+ ("<" . "<")
+ (">" . ">")
+ ("'" . "'")
+ ("&" . "&")))
(define (open-tag tag attrs exceptions)
(define (candidate? x)
"\n "
(symbol->string sym)
"=\""
-
(let ((s (call-with-output-string (lambda (port) (display val port)))))
- (re-sub-alist s '(("\"" . """)
- ("<" . "<")
- (">" . ">")
- ("'" . "'")
- ("&" . "&"))))
-
+ (re-sub-alist s xml-entities-alist))
"\""
)))
(string-append
"<" (symbol->string tag)
(apply string-append
- (map dump-attr (filter-list candidate? attrs)))
-
+ (map dump-attr (filter candidate? attrs)))
">\n")
)
(define (music-to-xml-helper music port)
(let*
(
- (name (ly-get-mus-property music 'name))
- (e (ly-get-mus-property music 'element))
- (es (ly-get-mus-property music 'elements))
- (mprops (ly-get-mutable-properties music))
- (p (ly-get-mus-property music 'pitch))
- (d (ly-get-mus-property music 'duration))
+ (name (ly:get-mus-property music 'name))
+ (e (ly:get-mus-property music 'element))
+ (es (ly:get-mus-property music 'elements))
+ (mprops (ly:get-mutable-properties music))
+ (p (ly:get-mus-property music 'pitch))
+ (d (ly:get-mus-property music 'duration))
(ignore-props '(origin elements duration pitch element))
)
+ ;; As almost everything is music; <SequentialMusic> is
+ ;; probably better than <music type="SequentialMusic">?
+
(display (open-tag 'music (cons `(type . ,name) mprops) ignore-props)
port)
- (if (duration? d)
+ (if (ly:duration? d)
(dump-duration d port))
- (if (pitch? p)
+ (if (ly:pitch? p)
(dump-pitch p port))
(if (pair? es)
- (begin
- (map (lambda (x) (music-to-xml-helper x port)) es)))
- (if (music? e)
+ (map (lambda (x) (music-to-xml-helper x port)) es)
+ )
+
+ (if (ly:music? e)
(begin
(music-to-xml-helper e port)))
(display (close-tag 'music) port)
- ))
-
-
+ ))
+
(define-public (music-to-xml music port)
"Dump XML-ish stuff to PORT."
- (display (dtd-header) port)
+
+ ;; dtd contains # -- This confuses tex during make web.
+ ;;
+ ;; (display (dtd-header) port)
+
(display (open-tag 'music '((type . score)) '()) port)
(music-to-xml-helper music port)
(display (close-tag 'music) port))