;;;;
;;;; source file of the GNU LilyPond music typesetter
;;;;
-;;;; (c) 2003--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+;;;; (c) 2003--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
;;;; Jan Nieuwenhuizen <janneke@gnu.org>
+(define-module (scm to-xml))
+
(use-modules (ice-9 regex)
(srfi srfi-1)
+ (lily)
(oop goops))
"
<score>
<music></music>
- <paperoutput>
- </paperoutput>
+ <layoutoutput>
+ </layoutoutput>
</score>
"
(pitch . pitch)
(duration . duration)
(octave . octave)
- (step . step)
- ))
-
-(define (assoc-get-default key alist default)
- "Return value if KEY in ALIST, else DEFAULT."
- (let ((entry (assoc key alist)))
- (if entry (cdr entry) default)))
+ (step . step)))
(define (musicxml-node->string node)
- (let ((xml-name (assoc-get-default (node-name node) node-names #f)))
- (string-append
- (if xml-name (open-tag xml-name '() '()) "")
- (if (equal? (node-value node) "")
- (string-append
- (if xml-name "\n" "")
- (apply string-append (map musicxml-node->string (node-children node))))
- (node-value node))
- (if xml-name (close-tag xml-name) "")
- (if xml-name "\n" ""))))
+ (let ((xml-name (assoc-get (node-name node) node-names #f)))
+ (string-append
+ (if xml-name (open-tag xml-name '() '()) "")
+ (if (equal? (node-value node) "")
+ (string-append
+ (if xml-name "\n" "")
+ (apply string-append (map musicxml-node->string (node-children node))))
+ (node-value node))
+ (if xml-name (close-tag xml-name) "")
+ (if xml-name "\n" ""))))
(define (xml-node->string node)
(string-append
(numer . ,(car (ly:duration-factor d)))
(denom . ,(cdr (ly:duration-factor d))))))
-(define (musicxml-pitch->xml-node p)
- (make <xml-node>
- #:name 'pitch
- #:children
- (list
- (make <xml-node>
- #:name 'step
- #:value (list-ref '("C" "D" "E" "F" "G" "A" "B")
- (ly:pitch-notename p)))
- (make <xml-node>
- #:name 'octave
- #:value (number->string (ly:pitch-octave p))))))
-
(define (pitch->xml-node p)
(make <xml-node>
#:name 'pitch
#:attributes `((octave . ,(ly:pitch-octave p))
(notename . ,(ly:pitch-notename p))
(alteration . ,(ly:pitch-alteration p)))))
-
+
(define (music->xml-node music)
(let* ((name (ly:music-property music 'name))
(e (ly:music-property music 'element))
(es (ly:music-property music 'elements))
- (mprops (ly:get-mutable-properties music))
+ (mprops (ly:music-mutable-properties music))
(d (ly:music-property music 'duration))
(p (ly:music-property music 'pitch))
(ignore-props '(origin elements duration pitch element)))
]>
"))
-
-
+
+
;; as computed from input/trip.ly, by
;; http://www.pault.com/pault/dtdgenerator/
(define (assert x)
(if x
#t
- (error "assertion failed")))
+ (ly:error (_ "assertion failed: ~S") x)))
(define (re-sub re to string)
(regexp-substitute/global #f re string 'pre to 'post))
(not (memq (car x) exceptions)))
(define (dump-attr sym-val)
- (let*
- (
- (sym (car sym-val))
- (val (cdr sym-val))
- )
+ (let* ((sym (car sym-val))
+ (val (cdr sym-val)))
- (string-append
- "\n "
- (symbol->string sym)
- "=\""
- (let ((s (call-with-output-string (lambda (port) (display val port)))))
- (re-sub-alist s xml-entities-alist))
- "\""
- )))
+ (string-append
+ "\n "
+ (symbol->string sym)
+ "=\""
+ (let ((s (call-with-output-string (lambda (port) (display val port)))))
+ (re-sub-alist s xml-entities-alist))
+ "\"")))
(string-append
"<" (symbol->string tag)
;;
;; (display (dtd-header) port)
- (define pitch->xml-node musicxml-pitch->xml-node)
(define duration->xml-node musicxml-duration->xml-node)
(display (open-tag 'music '((type . score)) '()) port)