0

I am trying to write a simple parser to read MusicXML and play it back. I am using JFugue 5.0.3. The library simply hangs in the middle half the time.

My code:-

 public void play() throws ParserConfigurationException, ParsingException, IOException {
        MusicXmlParser_J parser_j = new MusicXmlParser_J();
        StaccatoParserListener listener = new StaccatoParserListener();
        parser_j.addParserListener(listener);
        parser_j.parse(musicXMLFile);
        Player player = new Player();
        final Pattern musicXMLPattern = listener.getPattern();
        player.play(musicXMLPattern);
}

This code fails after attempting to build MusicXML file with a useless error message:-

attempting to build file
Oops something went wrong. The error isConnection timed out

and it works sometimes and when it does it works like a charm and within milliseconds. What is JFugue trying to download stuff over the network? A little debugging revealed it works by downloading

Few questions to the people who work on this :-

  1. Why doesn't this code work with MusicXMLParserListener class? This class fails with an arbitrary null pointer exception because it expects Staccato parser to be defined. Why? And what is the deal with two different listeners for MusicXML - MusicXMLParserListener_J and MusicXMLParserListener_R? Don't expose broken stuff to consumers please.

  2. I had read that JFugue supports MusicXML and I expected this to work without an issue.

Are there examples of JFugue working with MusicXML?

David Koelle
  • 20,726
  • 23
  • 93
  • 130
Arunav Sanyal
  • 1,708
  • 1
  • 16
  • 36

1 Answers1

1

The two different parsers you see are a result of MusicXML capability in JFugue 5.0+ not being fully completed yet (which is mentioned on the JFugue download page). These were two implementations contributed by two developers in the open source community. Based on your issue, I have just updated the JFugue distribution: I moved one of the parsers out, and renamed the other one simply MusicXmlParser.

It turns out that the other parser, MusicXmlParser_R, is the better of the two. Of course, no user would have had any idea about that. My apologies for exposing an incomplete capability. For the record, "Oops, something went wrong" is not a JFugue error message, but "attempting to build file" was in MusicXmlParser_J, which is now out of the code.

The following code, which is from test/org.jfugue.musicxml, demonstrates the use of MusicXmlParser.

MusicXmlParser musicXmlParser = new MusicXmlParser();
StaccatoParserListener spl = new StaccatoParserListener();
musicXmlParser.addParserListener(spl);
musicXmlParser.parse(new File("src/test/resources/HelloWorldMusicXml.xml")); 

Please note that there is no implementation of MusicXmlParserListener for JFugue 5.0 at the moment. I have updated the download page to make this clear.

The MusicXML capabilities within JFugue are entirely community-contributed.

David Koelle
  • 20,726
  • 23
  • 93
  • 130
  • I kind of figured whats going on. JFugue tries to perform a schema validation and downloads the DTD specification from a high load site. It works half the time because JFugue assumes network IO and that breaks. I will try it out without an internet connection to confirm this. – Arunav Sanyal Sep 14 '15 at 18:13
  • Yep I was right https://github.com/avh4/jfugue/blob/master/jfugue/src/org/jfugue/MusicXmlRenderer.java. In here method getMusicXMLDom() is present which tries to copy DTD info from "http://www.musicxml.org/dtds/partwise.dtd". I am pretty certain this is done in quite a few places. – Arunav Sanyal Sep 14 '15 at 18:38
  • Good finding this! Please keep in mind that this is not an official source for JFugue. The current version and most up-to-date source code (including an updated MusicXmlParser) is available at JFugue.org – David Koelle Sep 14 '15 at 20:29