ABC and MusicXML

Abc and MusicXML - a starter page

I've been doing some reading and experimenting, on MusicXML and its possible value to ABC users - and, it seems to have some intriguing possibilities. So I thought I'd round up a few demonstrations and links, to see if I can interest any other people in this stuff. Aimed primarily at ABC users because that's where I come from.

MusicXML is "music written in text" in the same sort of way that ABC is - people who use ABC may find that MusicXML would fit conveniently into the way they do things - but with a set of strengths and weaknesses that seem to complement those of ABC very neatly. Briefly, I doubt if many ABC users would want to write a tune out in MusicXML, it's incredibly verbose, repetitive, boring. Spells everything out in longwinded detail ... yes, it's easy for machines; to copy from one system to another, to operate on, to turn into some other format. Which is why it's proposed as a transfer format between other representations.

It also seems that the software for us to take advantage of some of these possibilities is closer than I had thought. Reading suggests, for example that "modern mainstream" browsers are XML-aware, and in particular are capable of applying XSLT 1.0 transformations to MusicXML files (my Mozilla 1.0 can do this, I don't have any details wrt other browsers). Also, standalone XML/XSLT processors appear to be fairly commonly available (?), to do the same thing with more flexibility. The general scheme is to use a xml-xslt processor / suitable browser to apply a "stylesheet" to, in our case, a file written in MusicXML. This stylesheet causes the processor to pick information out of the file and output it, either in possibly-transformed xml, or equally-possibly in another format altogether. Like ABC, for example.

So try these links and see what happens.

These files above are music coded in MusicXML. If your browser shows you their contents as ABC, that's "success". I can store a tune on a website as xml, and you can access it as ABC. Otherwise I guess you see the MusicXML text, in which case you might want to look for a standalone XML XSLT 1.0 processor, which should give you the same results, and more, if you download the xml files, and a stylesheet, and try this at home. Even if the browser displays ABC, I think it will probably save to disk as xml.

There are 2 stylesheets that I know of, to generate ABC from MusicXML. The single tunes above (the first 3 links) were done using something really really crude that I hacked together within my first day of trying to write this stuff. It's not pretty, and only works on very simple and carefully selected input, but I'm impressed that I can parse a data file, written in a language that I barely understand even superficially, using an unknown processing language, and get so far so quickly. This is a scheme where it really is easy to pick information out of a file. If you can translate ABC to MusicXML, there are all sorts of processing, information-gathering, etc, that become much easier than trying to parse an ABC file and doing them there. If you can translate it back into ABC after, it might help, of course ... which is why I think I should put my stylesheet, crude hack though it is, under the GPL in the hope that maybe it's improvable and could grow up to be a valuable resource. I call it abc.xsl and here is a link to it for anyone that's interested.

One thing my stylesheet can't do yet is to handle "opus" files, which are part of the MusicXML spec for "collections" of related "works". However, there are other stylesheets which can handle these. The final file in the list above, "File Four", is a file containing pointers to the 3 single-tune files above it. This is rendered using a different sylesheet, xml2abc, which I found on John Lynch's ABC/MusicXML page page, along with the noteReport stylesheet used below and also a Windows command-line abc->musicxml converter. A Linux port of this last is available courtesy of Dave Holland (the sylesheets, of course are system independent, they don't need porting. This is a write-once-run-anywhere one-size-fits-all scheme).

And if the examples above worked for you, try this. This is the same collection file as before, but processed using a different sytlesheet (noteReport.xsl), which counts the notes contained in the tunes it points to and outputs some statistics, marked up as HTML.

Another thing John Lynch's xml2abc.xls stylesheet can do is ... the Gutenberg Project Chamber Music Archive offers some material in MusicXML. Beethoven String Quartets, for instance. Among other things, these offerings contain 4 separate xml files holding the parts for each separate instrument. These can be converted into ABC that is only a few irritating glitches, a handful of keystrokes in your favourite text editor, away from being acceptable to abcm2ps. I have seen ABC files that were harder to import than this. They were created in Windows Finale. Transfer format, indeed. This almost works, already.

The MusicXML 1.0 tutorial is another useful link.