Pierre THIERRY writes: [cc lilypond-devel]
> If memory serves, so far we have US$200, C$100 and €200. If I were to > work alone on this bounty, that would allow me to allocate > approximately 20hrs, which should clearly be enough to write a nice > XML exporting in some schema mimicking Lilypond's representation, and > probably also the XSLT transformation to MusicXML (I'm not sure how > much time figuring it and then debugging it will take, it has been > ages since I played with XSLT). To fix this bug, what we need is a very clear bug report to know when we can close it. Actually, we require that for all bugs, so #665 should never have been entered into the bug database like this. What I would like to see attached to #665 is at least one .ly with corresponding .xml with bonusses attached. Possibly it's best to delay #665 and split it up into several different issues (and attached bounties), each with it's own .ly -- and starting with a most simple one. It's only about an hour of work (see below) to convert a simple and prepared .ly score to musicxml, see below. Jan
>From 8dd82d867fcf9b7b9a554016de02109ab6486a0c Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen <jann...@gnu.org> Date: Wed, 24 Aug 2011 15:46:34 +0200 Subject: [PATCH 1/3] [MusicXML]: Hello world xslt stylesheet for MusicXML output. --- xml/GNUmakefile | 2 ++ xml/test-1.xml | 28 ++++++++++++++++++++++++++++ xml/to-xml.html | 17 +++++++++++++++++ xml/xml.ly | 16 ++++++++++++++++ xml/xml.xml | 38 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 101 insertions(+), 0 deletions(-) create mode 100644 xml/GNUmakefile create mode 100644 xml/test-1.xml create mode 100644 xml/to-xml.html create mode 100644 xml/xml.ly create mode 100644 xml/xml.xml diff --git a/xml/GNUmakefile b/xml/GNUmakefile new file mode 100644 index 0000000..83d803c --- /dev/null +++ b/xml/GNUmakefile @@ -0,0 +1,2 @@ +test: + xsltproc to-xml.html test-1.xml \ No newline at end of file diff --git a/xml/test-1.xml b/xml/test-1.xml new file mode 100644 index 0000000..3c33cc8 --- /dev/null +++ b/xml/test-1.xml @@ -0,0 +1,28 @@ +<music> +<NoteEvent> +<pitch + octave="1" + notename="0" + alteration="0"> +</pitch> +<duration + log="2" + dots="0" + numer="1" + denom="1"> +</duration> +</NoteEvent> +<NoteEvent> +<pitch + octave="2" + notename="1" + alteration="0"> +</pitch> +<duration + log="2" + dots="0" + numer="1" + denom="1"> +</duration> +</NoteEvent> +</music> \ No newline at end of file diff --git a/xml/to-xml.html b/xml/to-xml.html new file mode 100644 index 0000000..f1da85a --- /dev/null +++ b/xml/to-xml.html @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> + + <xsl:template match="/"> + <xml> + <score-partwise> + <xsl:for-each select="music"> + <xsl:for-each select="NoteEvent"> + <pitch><xsl:value-of select="pitch"/> + <octave><xsl:value-of select="pitch"/></octave> + </pitch> + </xsl:for-each> + </xsl:for-each> + </score-partwise> + </xml> + </xsl:template> +</xsl:stylesheet> diff --git a/xml/xml.ly b/xml/xml.ly new file mode 100644 index 0000000..2ade547 --- /dev/null +++ b/xml/xml.ly @@ -0,0 +1,16 @@ +\version "2.14.0" + +testMusic = { << c''4 \\ g'4 >> } + +#(use-modules (scm to-xml)) + +#(ly:progress "\nXML:\n\n~A\n" (call-with-output-string (lambda (p) (music-to-xml testMusic p)))) + + +\header { + texidoc = + "The input representation is generic, and may be translated to XML. " +} + + +{ \testMusic } diff --git a/xml/xml.xml b/xml/xml.xml new file mode 100644 index 0000000..12ca68a --- /dev/null +++ b/xml/xml.xml @@ -0,0 +1,38 @@ +<music + type="score"> +<SequentialMusic> +<SimultaneousMusic> +<EventChord> +<NoteEvent> +<pitch + octave="1" + notename="0" + alteration="0"> +</pitch> +<duration + log="2" + dots="0" + numer="1" + denom="1"> +</duration> +</NoteEvent> +</EventChord> +<VoiceSeparator> +</VoiceSeparator> +<EventChord> +<NoteEvent> +<pitch + octave="0" + notename="4" + alteration="0"> +</pitch> +<duration + log="2" + dots="0" + numer="1" + denom="1"> +</duration> +</NoteEvent> +</EventChord> +</SimultaneousMusic> +</SequentialMusic></music> -- 1.7.4.1
>From ec8bf2adb089f4c1c38462afc1e8ec3fb0e33a60 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen <jann...@gnu.org> Date: Wed, 24 Aug 2011 15:58:33 +0200 Subject: [PATCH 2/3] [MusicXML]: use apply-templates. --- xml/to-xml.html | 35 ++++++++++++++++++++++++++++------- 1 files changed, 28 insertions(+), 7 deletions(-) diff --git a/xml/to-xml.html b/xml/to-xml.html index f1da85a..3768641 100644 --- a/xml/to-xml.html +++ b/xml/to-xml.html @@ -4,14 +4,35 @@ <xsl:template match="/"> <xml> <score-partwise> - <xsl:for-each select="music"> - <xsl:for-each select="NoteEvent"> - <pitch><xsl:value-of select="pitch"/> - <octave><xsl:value-of select="pitch"/></octave> - </pitch> - </xsl:for-each> - </xsl:for-each> + <xsl:apply-templates/> </score-partwise> </xml> </xsl:template> + + + <xsl:template match="EventChord"> + <xsl:apply-templates/> + </xsl:template> + + <xsl:template match="NoteEvent"> + <xsl:apply-templates/> + </xsl:template> + + <xsl:template match="SequentialMusic"> + <xsl:apply-templates/> + </xsl:template> + + <xsl:template match="SimultaneousMusic"> + <xsl:apply-templates/> + </xsl:template> + + <xsl:template match="pitch"> + <pitch><xsl:value-of select="pitch"/> + <octave><xsl:value-of select="pitch"/></octave> + </pitch> + </xsl:template> + + <xsl:template match="duration"> + </xsl:template> + </xsl:stylesheet> -- 1.7.4.1
>From e44e345fc6cc718a5ea7560caf1245db7e8f3745 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen <jann...@gnu.org> Date: Wed, 24 Aug 2011 22:48:27 +0200 Subject: [PATCH 3/3] [MusicXML]: convert simple .ly to working .mxml --- xml/GNUmakefile | 22 +++++++++++++++- xml/lyxml-to-mxml.xsl | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ xml/test-1.ly | 14 +++++++++++ xml/test-1.xml | 28 ---------------------- xml/to-xml.html | 38 ------------------------------ xml/xml.xml | 38 ------------------------------ 6 files changed, 96 insertions(+), 106 deletions(-) create mode 100644 xml/lyxml-to-mxml.xsl create mode 100644 xml/test-1.ly delete mode 100644 xml/test-1.xml delete mode 100644 xml/to-xml.html delete mode 100644 xml/xml.xml diff --git a/xml/GNUmakefile b/xml/GNUmakefile index 83d803c..565baad 100644 --- a/xml/GNUmakefile +++ b/xml/GNUmakefile @@ -1,2 +1,20 @@ -test: - xsltproc to-xml.html test-1.xml \ No newline at end of file +test: test-1.mxml.pdf + +LILYPOND=../out/bin/lilypond +MUSICXML2LY=../out/bin/musicxml2ly +XSLT2=saxonb-xslt -ext:on + +%.mxml.ly: %.mxml + $(MUSICXML2LY) --output=$@ $< + +%.mxml.pdf: %.mxml.ly + $(LILYPOND) $< + +%.lyxml: %.ly + $(LILYPOND) $< > $@ + +%.mxml: %.lyxml lyxml-to-mxml.xsl + $(XSLT2) $< lyxml-to-mxml.xsl > $@ + +clean: + rm -f *.lyxml *.mxml *.xml *.pdf *.*.* diff --git a/xml/lyxml-to-mxml.xsl b/xml/lyxml-to-mxml.xsl new file mode 100644 index 0000000..a9c341d --- /dev/null +++ b/xml/lyxml-to-mxml.xsl @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:Math="http://www.math.org/" + xmlns:xs="http://www.w3.org/2001/XMLSchema"> + + <xsl:template match="/"> + <score-partwise> + <part-list> + <score-part id="P1"> + <part-name>P1</part-name> + </score-part> + </part-list> + <part id="P1"> + <measure number="1"> + <xsl:apply-templates/> + </measure> + </part> + </score-partwise> + </xsl:template> + + <xsl:template match="EventChord"> + <xsl:apply-templates/> + </xsl:template> + + <xsl:template match="NoteEvent"> + <note> + <xsl:apply-templates/> + </note> + </xsl:template> + + <xsl:template match="SequentialMusic"> + <xsl:apply-templates/> + </xsl:template> + + <xsl:template match="SimultaneousMusic"> + <xsl:apply-templates/> + </xsl:template> + + <xsl:template match="pitch"> + <pitch> + <step><xsl:value-of select="codepoints-to-string (xs:integer (65 + ((number (@notename) + 2) mod 7)))"/></step> + <octave><xsl:value-of select="sum (4, @octave)"/></octave> + </pitch> + </xsl:template> + + <xsl:template match="duration"> + <duration>1</duration> + <!-- + <duration><xsl:value-of select="8 div Math:pow (2, @log)" + xmlns:Math="java:java.lang.Math"/></duration> + !--> + <type> + <xsl:choose> + <xsl:when test="@log = 0">whole</xsl:when> + <xsl:when test="@log = 1">halve</xsl:when> + <xsl:when test="@log = 2">quarter</xsl:when> + <xsl:when test="@log = 3">eighth</xsl:when> + </xsl:choose> + </type> + </xsl:template> + +</xsl:stylesheet> diff --git a/xml/test-1.ly b/xml/test-1.ly new file mode 100644 index 0000000..7e12a3c --- /dev/null +++ b/xml/test-1.ly @@ -0,0 +1,14 @@ +\version "2.14.0" + +\header { + texidoc = + "The input representation is generic, and may be translated to XML. " +} + +testMusic = { c' d' e'8 f g a b} + +#(use-modules (scm to-xml)) + +#(display (call-with-output-string (lambda (p) (music-to-xml testMusic p)))) + +{ \testMusic } diff --git a/xml/test-1.xml b/xml/test-1.xml deleted file mode 100644 index 3c33cc8..0000000 --- a/xml/test-1.xml +++ /dev/null @@ -1,28 +0,0 @@ -<music> -<NoteEvent> -<pitch - octave="1" - notename="0" - alteration="0"> -</pitch> -<duration - log="2" - dots="0" - numer="1" - denom="1"> -</duration> -</NoteEvent> -<NoteEvent> -<pitch - octave="2" - notename="1" - alteration="0"> -</pitch> -<duration - log="2" - dots="0" - numer="1" - denom="1"> -</duration> -</NoteEvent> -</music> \ No newline at end of file diff --git a/xml/to-xml.html b/xml/to-xml.html deleted file mode 100644 index 3768641..0000000 --- a/xml/to-xml.html +++ /dev/null @@ -1,38 +0,0 @@ -<?xml version="1.0" encoding="ISO-8859-1"?> -<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> - - <xsl:template match="/"> - <xml> - <score-partwise> - <xsl:apply-templates/> - </score-partwise> - </xml> - </xsl:template> - - - <xsl:template match="EventChord"> - <xsl:apply-templates/> - </xsl:template> - - <xsl:template match="NoteEvent"> - <xsl:apply-templates/> - </xsl:template> - - <xsl:template match="SequentialMusic"> - <xsl:apply-templates/> - </xsl:template> - - <xsl:template match="SimultaneousMusic"> - <xsl:apply-templates/> - </xsl:template> - - <xsl:template match="pitch"> - <pitch><xsl:value-of select="pitch"/> - <octave><xsl:value-of select="pitch"/></octave> - </pitch> - </xsl:template> - - <xsl:template match="duration"> - </xsl:template> - -</xsl:stylesheet> diff --git a/xml/xml.xml b/xml/xml.xml deleted file mode 100644 index 12ca68a..0000000 --- a/xml/xml.xml +++ /dev/null @@ -1,38 +0,0 @@ -<music - type="score"> -<SequentialMusic> -<SimultaneousMusic> -<EventChord> -<NoteEvent> -<pitch - octave="1" - notename="0" - alteration="0"> -</pitch> -<duration - log="2" - dots="0" - numer="1" - denom="1"> -</duration> -</NoteEvent> -</EventChord> -<VoiceSeparator> -</VoiceSeparator> -<EventChord> -<NoteEvent> -<pitch - octave="0" - notename="4" - alteration="0"> -</pitch> -<duration - log="2" - dots="0" - numer="1" - denom="1"> -</duration> -</NoteEvent> -</EventChord> -</SimultaneousMusic> -</SequentialMusic></music> -- 1.7.4.1
-- Jan Nieuwenhuizen <jann...@gnu.org> | GNU LilyPond http://lilypond.org Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.nl
_______________________________________________ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user