+(define (duration->xml-node d)
+ (make <xml-node>
+ #:name 'duration
+ ;; #:value (number->string (ash 1 (ly:duration-log d)))))
+ #:attributes `((log . ,(ly:duration-log d))
+ (dots . ,(ly:duration-dot-count d))
+ (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:music-mutable-properties music))
+ (d (ly:music-property music 'duration))
+ (p (ly:music-property music 'pitch))
+ (ignore-props '(origin elements duration pitch element)))
+
+ (make <xml-node>
+ #:name name
+ #:children
+ (apply
+ append
+ (if (ly:pitch? p) (list (pitch->xml-node p)) '())
+ (if (ly:duration? d) (list (duration->xml-node d)) '())
+ (if (pair? es) (map music->xml-node es) '())
+ (if (ly:music? e) (list (music->xml-node e)) '())
+ '()))))