Rapport hebdomadaire 10

MusicXML2SVG: première intégration des technologies Java, XML, XSLT, et SVG.


Mots-clés:

Java, XML, XSLT, et SVG.
 
 

Bibliographie:

CR-SVG-20001102.pdf: SVG 1.0 Specification, W3C Candidate Recommandation 2000
The Java Programming Language Third Edition; Ken Arnold, James Gosling, David Holmes, ed. Sun Microsystem 2000
Unleashed XML; Michael Morrison, ed. Sams Publishing 2000
XML Langage et applications, Alain Michard, Eyrolles 3e tirage 1999
 

Sites internet:

Java Image Coding:
http://www.geocities.com/marcoschmidt.geo/java-image-coding.html

Transforming XML into SVG:
http://www-106.ibm.com/developerworks/education/transforming-xml/xmltosvg/index.html
Doug Tidwell: Cyber Evangelist, developerWorks XML Team

SVG Adobe's Tutorial:
http://www.adobe.com/svg/basics/getstarted.html
 
 

Développement de MusicXML2SVG:


Ce premier développement a nécessité l'apprentissage de nombreuses technologies: des langages dont Java, XML, et XSL, des concepts tels les DOM ou les DTM, des normes particulières dont MusicXML et SVG, et des librairies en cours de développement dont Xerces et Xalan.
Le fonctionnement reste pourtant simple en apparence: un programme Java charge un processeur Xalan, puis lui demande d'appliquer sur un fichier XML une feuille de style XSLT, et de retourner le résultat dans un fichier quelconque, ici ce sera un fichier SVG.
Ce code fonctionne, mais la feuille de style se limite pour l'instant à détecter une partition MusicXML (part-wise) pour générer une portée en SVG. Il reste une semaine pour développer l'ensemble du code, notamment pour modéliser un ensemble de règles de paramétrage typographique. Cela risque de poser certains problèmes techniques au niveau de localisation des calculs, soit dans le programme Java, soit dans la feuille de style, ou encore au niveau de la gestion des polices musicales, qui doivent être True Type 1, ce qui n'est pas le cas.

Suivent une exécution, puis l'ensemble du code:

[barkati@ceres musicxml2svg]$ java MusicXML2SVG
************* The result is in mutshortshort.svg *************
 
 

MusicXML2SVG.java:

/*
  Ce code est inspiré du fichier d'exemple SimpleTransform.java d'Apache.
 */

import org.xml.sax.SAXException;
import org.apache.xalan.xslt.XSLTProcessorFactory;
import org.apache.xalan.xslt.XSLTInputSource;
import org.apache.xalan.xslt.XSLTResultTarget;
import org.apache.xalan.xslt.XSLTProcessor;

/**
 * Simple sample code to show how to run the XSL processor
 * from the API.
 */
public class MusicXML2SVG
{
 public static void main(String[] args)
    throws java.io.IOException,
           java.net.MalformedURLException,
           org.xml.sax.SAXException
 {
    // Have the XSLTProcessorFactory obtain a interface to a
    // new XSLTProcessor object.
    XSLTProcessor processor = XSLTProcessorFactory.getProcessor();

    // Have the XSLTProcessor processor object transform "birds.xml" to
    // System.out, using the XSLT instructions found in "birds.xsl".
    processor.process(new XSLTInputSource("mutshortshort.xml"),
                      new XSLTInputSource("mutshortshort.xsl"),
                      new XSLTResultTarget("mutshortshort.svg"));
   System.out.println("************* The result is in mutshortshort.svg *************");
 }
}
 

mutshortshort.svg:

<?xml version="1.0" encoding="ISO-8859-1"?>
<svg contentStyleType="text/css" contentScriptType="text/ecmascript" zoomAndPan="magnify" preserveAspectRatio="xMidYMid meet" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 600" height="600" width="800">
    <line style="stroke-width:1; stroke:black" y2="150" x2="950" y1="150" x1="50"/>
    <line style="stroke-width:1; stroke:black" y2="200" x2="950" y1="200" x1="50"/>
    <line style="stroke-width:1; stroke:black" y2="250" x2="950" y1="250" x1="50"/>
    <line style="stroke-width:1; stroke:black" y2="300" x2="950" y1="300" x1="50"/>
    <line style="stroke-width:1; stroke:black" y2="350" x2="950" y1="350" x1="50"/>
</svg>
 

mutshortshort.xsl:

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20001102//EN"
 "http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="xml" indent="yes"/>

<xsl:template match="score-partwise">
<svg width="800" height="600" viewBox="0 0 1000 600">
<line x1="50" y1="150" x2="950" y2="150" style="stroke-width:1; stroke:black" />
<line x1="50" y1="200" x2="950" y2="200" style="stroke-width:1; stroke:black" />
<line x1="50" y1="250" x2="950" y2="250" style="stroke-width:1; stroke:black" />
<line x1="50" y1="300" x2="950" y2="300" style="stroke-width:1; stroke:black" />
<line x1="50" y1="350" x2="950" y2="350" style="stroke-width:1; stroke:black" />
</svg>
</xsl:template>
</xsl:stylesheet>
 

mutshortshort.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE score-partwise PUBLIC
  "-//Recordare//DTD MusicXML Partwise//EN"
 "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise>
 <work>
  <work-number>D. 911</work-number>
  <work-title>Winterreise</work-title>
 </work>
 <movement-number>22</movement-number>
 <movement-title>Mut</movement-title>
 <identification>
  <creator type="composer">Franz Schubert</creator>
  <creator type="poet">Wilhelm Müller</creator>
  <rights>Electronic edition Copyright © 2001 Recordare. All rights reserved.</rights>
  <encoding>
   <encoding-date>2001-01-12</encoding-date>
   <encoder>Michael Good</encoder>
   <software>Finale 2001c for Windows</software>
   <encoding-description>MusicXML 0.1b example</encoding-description>
  </encoding>
  <source>Based on Dover reprint of Breitkopf &amp; Härtel edition of 1895. Original A-minor version; later transposed to G minor.</source>
 </identification>
 <part-list>
  <score-part id="P1">
   <part-name>Singstimme.</part-name>
  </score-part>
 </part-list>
 <part id="P1">
  <measure number="1">
   <attributes>
    <divisions>4</divisions>
    <key>
     <fifths>0</fifths>
     <mode>minor</mode>
    </key>
    <time>
     <beats>2</beats>
     <beat-type>4</beat-type>
    </time>
    <clef>
     <sign>G</sign>
     <line>2</line>
    </clef>
   </attributes>
   <direction>
    <direction-type>
     <words xml:lang="de">Ziemlich geschwind, kräftig</words>
    </direction-type>
   </direction>
   <note>
    <rest/>
    <duration>8</duration>
    <type>half</type>
   </note>
   <barline>
    <bar-style>light-heavy</bar-style>
   </barline>
  </measure>
 </part>
</score-partwise>