X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scm%2Fto-xml.scm;h=a552c1f8465304f645cf1158af784bec9255f4e5;hb=4d88ff7f4887a48096b4718c278c04d04ea7e1f9;hp=d88649315a50786d31656d9fe11c449501b63e9b;hpb=12186b6828aee7aa298076d684835d629b757f2a;p=lilypond.git diff --git a/scm/to-xml.scm b/scm/to-xml.scm index d88649315a..a552c1f846 100644 --- a/scm/to-xml.scm +++ b/scm/to-xml.scm @@ -1,12 +1,26 @@ -;;;; to-xml.scm -- dump parse tree as xml +;;;; This file is part of LilyPond, the GNU music typesetter. ;;;; -;;;; source file of the GNU LilyPond music typesetter -;;;; -;;;; (c) 2003--2004 Han-Wen Nienhuys +;;;; Copyright (C) 2003--2010 Han-Wen Nienhuys ;;;; Jan Nieuwenhuizen +;;;; +;;;; LilyPond is free software: you can redistribute it and/or modify +;;;; it under the terms of the GNU General Public License as published by +;;;; the Free Software Foundation, either version 3 of the License, or +;;;; (at your option) any later version. +;;;; +;;;; LilyPond is distributed in the hope that it will be useful, +;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;;; GNU General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU General Public License +;;;; along with LilyPond. If not, see . + +(define-module (scm to-xml)) (use-modules (ice-9 regex) (srfi srfi-1) + (lily) (oop goops)) " @@ -24,8 +38,8 @@ is then separated. - - + + " @@ -47,25 +61,19 @@ is then separated. (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 @@ -92,31 +100,18 @@ is then separated. (numer . ,(car (ly:duration-factor d))) (denom . ,(cdr (ly:duration-factor d)))))) -(define (musicxml-pitch->xml-node p) - (make - #:name 'pitch - #:children - (list - (make - #:name 'step - #:value (list-ref '("C" "D" "E" "F" "G" "A" "B") - (ly:pitch-notename p))) - (make - #:name 'octave - #:value (number->string (ly:pitch-octave p)))))) - (define (pitch->xml-node p) (make #: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))) @@ -141,8 +136,8 @@ is then separated. ]> ")) - - + + ;; as computed from input/trip.ly, by ;; http://www.pault.com/pault/dtdgenerator/ @@ -193,7 +188,7 @@ is then separated. (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)) @@ -216,20 +211,16 @@ is then separated. (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) @@ -242,7 +233,7 @@ is then separated. (define-public (music-to-xml music port) "Dump XML-ish stuff to PORT." - ;; dtd contains # -- This confuses tex during make web. + ;; dtd contains # -- This confuses tex during make doc. ;; ;; (display (dtd-header) port) @@ -253,11 +244,10 @@ is then separated. (define-public (music-to-musicxml music port) "Dump MusicXML-ish stuff to PORT." - ;; dtd contains # -- This confuses tex during make web. + ;; dtd contains # -- This confuses tex during make doc. ;; ;; (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)