The MIDI block currently provides components to generate XMidi from a MIDI file, and to serialize XMidi back to a MIDI file. XMidi is an XML format that was developed several years ago by Peter Loeb (see http://www.palserv.com/XMidi/ for more information about the original code).
There are also simple XSLT stylesheets to perform transposition and inversion.
Future plans include:
- Create more difficult transformers of the XMidi, e.g. retrograde etc.
- Create some XMidi to SVG transformers so that graphical (e.g. Western musical notation, or Schenkerian analysis perhaps!) representations of MIDI files can be rapidly generated.
The MIDI format itself provides very little presentation information thus limiting the scope of my second aim, but this block could well provide the catalyst for developments that encompass other XML formats for music (such as MusicXML, NIFF XML, MusicML, or perhaps a new markup for music).
Usage
To use the X!MidiGenerator you must declare it as usual in your sitemap's <map:components> section thus:
{{{<map:components>
<map:generators ...>
<map:generator name="xmidi" src="org.apache.cocoon.generation.XMidiGenerator"
logger="midi.sitemap.generator"/>
</map:generators>
<map:serializers ...>
<map:serializer name="xmidi" src="org.apache.cocoon.serializer.XMidiSerializer"
logger="midi.sitemap.serializer"/>
</map:serializers>
- ..
</map:components>}}}
To use the X!MidiGenerator in your own pipelines just specify the location of the MIDI file in the src attribute of the <map:generate> element. To serialize the XMidi back to MIDI just use the serializer in the normal way. The following pipeline generates a SAX stream representation in XMidi, and then serializes it back to MIDI: a round trip. I'll leave it to you to create the transformations that make this useful!
{{{<map:match pattern="prelude.xmi">
<map:generate type="xmidi" src="midi/prelude.mid"/> <map:serialize type="xmidi"/>
</map:match>}}}
Sample XMidi
{{{<?xml version="1.0" standalone="yes"?> <XMidi VERSION="1.2">
<MThd LENGTH="6" TYPE="MThd">
<FORMAT>0</FORMAT> <TRACKS>1</TRACKS> <PPNQ>0078</PPNQ>
</MThd> <MTrk LENGTH="3415" TYPE="MTrk">
<DELTA DTIME="00000000">
<STATUS SLEN="23" SNAM="non-MIDI - Sequence/Track Name" SNMT="03" SVAL="FF">
<EDATA>5072E96C756465206EB031206C6976726520312057544B</EDATA>
</STATUS>
</DELTA> <DELTA DTIME="00000000">
<STATUS SLEN="4" SNAM="non-MIDI - Copyright" SNMT="02" SVAL="FF">
<EDATA>6E6F6E65</EDATA>
</STATUS>
</DELTA>
- ..
<DELTA DTIME="00000091">
<STATUS SLEN="2" SNAM="Note On" SVAL="90">
<CHANNEL NUMBER="0" TYPE="9">
<NOTE_ON NAME="C" PITCH="60" REGISTER="0" VELOCITY="38" />
</CHANNEL>
</STATUS>
</DELTA> <DELTA DTIME="00000033">
<CHANNEL NUMBER="0" TYPE="9">
<NOTE_ON NAME="E" PITCH="64" REGISTER="0" VELOCITY="34" />
</CHANNEL>
</DELTA>
- ..
<DELTA DTIME="00000000">
<STATUS SLEN="0" SNAM="non-MIDI - End of Track" SNMT="2F" SVAL="FF">
<EDATA>No data</EDATA>
</STATUS>
</DELTA>
</MTrk>
</XMidi>}}}