The trouble with having gone with MOD as my music format of choice nearly ten years ago is that almost immediately when I started, it became obsolete and every other popular music package sprang up using MIDI-based formats. Even though you would think that music formats couldn't be all that different from each other, I haven't yet found a MOD to MIDI convertor that does what I need it to (Modplug's own MIDI import and export is particularly awful), which is a problem when I put up tablatures of my songs because I have to convert them all by hand. Often this results in being able to improve on some parts of the original that I might not have got quite right the first time, or introduce a couple of new ideas, but it's the sort of thing that's very programmatic for the most part.
So I invoked my philosophy that the good thing about computers is that you have the tools to automate repetitive tasks on them already at your disposal, and decided that I could at least attempt to get it to lay the groundwork itself and rewrite the drum parts in MIDI for me. So the idea for a new Java project was born in the form of DrumWriter, and the basic plan was simple - find something that could read MOD files, find something that could write MIDI files, and then nail them together into a sort of musical chimera.
Reading a MODMy first target came in the form of a library called
JMOD that seemed incredibly difficult to get hold of even though it came up on a search - the best link I found was to that beta version of it. Almost immediately I came across one of the disadvantages of unfinished open source software, that being that it was unfinished - I spent a while wondering what I was doing wrong while loading my .IT song files until I went in to check exactly what it was doing on loading them, which was to make up 64 completely blank tracks and then return them without so much as looking at the actual structure of the file. I didn't have a way around this because adding that would have required a knowledge of the IT file format, which is what I was using someone else's library to avoid - instead, it's not too much of a bother to use Modplug to save them as the very similar XM files (which JMOD can actually read and not just pretend to) before using them.
The second problem was that the format of the samples within the file wasn't what JMOD was expecting - I'm not sure if this is an oddity of Modplug compared to the original Impulse Tracker or not, but it made it just throw an exception on trying to load them. This was a bigger problem, and I ended up just completely removing all attempts to load any samples from the code and recompiling JMOD into my own patched version, seeing as it was just the song layout that was important to me and I wouldn't actually be using it to play back the file. After those two fairly major obstacles were out the way, I could load in a finished MOD file and run through it to recognize when individual drum samples were played, constructing an internal sort of piano-roll arrangement.
Writing a MIDThe second half of the exercise required taking the drum pattern that I'd gathered in the MOD and then writing it out to a MIDI file. My first choice for this was Java's own MIDI library in javax.sound, but I quickly learned that this was not intended for humans to understand - adding notes to a file involves constructing a MIDI message byte by byte and then inserting it manually into a sequence, which isn't the most intuitive of ways to work. (Despite their simple sound, MIDIs are very complex and hold a lot of information - MODs are solid and wonderfully logically laid out by comparison.) After searching for an alternative I quickly came up with
JFugue.
JFugue uses a rather unusual string notation that isn't at all far removed from ZZT's idea of a music format, a set of characters that together represent notes and durations (though it also has to worry about instrument, channel, and so on). As you can see from
the examples, it even provides special methods for writing percussion tracks, inventing the concept of layers to get around some awkwardness that MIDI usually has with this. It's a free library, but gets you by putting a price on the manual for it, so I just muddled through with the Javadoc of it to help me through. And after some hammering, I got it to generate a set of rhythm strings based on the drum patterns I had from the first step (one for each type of drum), convert those to a combined music string using the relevant drum instruments, and export the whole thing to a MIDI file (a step that took me much longer than you'd expect, because it's curiously a method of the Player class and I couldn't find it for ages.)
The combination of the twoThere was one last oddness that I had to get past, and that was in the import into Guitar Pro 5, which uses its own format but can import MIDI (making the entire chain IT → XM → JMOD → DrumWriter → JFugue → MID → GP5). For some reason, the MIDIs generated by my program come out far too fast when imported - and not just in tempo, it was that the notes are treated as hemidemisemiquavers when they should be rather a lot longer. I got around this by simply making the conversion step with JFugue output notes with the duration of crotchets when they should be semiquavers (therefore four times their intended length), which works when imported, though I'm not sure why.

This is part of the result of running it on a song that I'd converted to tab myself previously - the one that I did by hand is the lower score, and the upper score has the same piece of music converted by this new drum writer. As far as the notes played go, they're aurally identical - you can see a slight difference at the end because the drum writer only ever treats anything as a semiquaver (I think Guitar Pro combines long stretches of rests itself), but this doesn't make a difference to the sound because percussion instruments don't have a concept of how long they're played for, and I only ever made them longer in the original version to make the score more readable.
Another problem with its readability is the way that the events on the tab layout below the stave are scrunched up together, without having a line for each drum like I laid them out when I did it myself. This isn't a huge issue because I shouldn't need to edit them a whole lot - it's something that would be nice to correct, but I can't see a way of doing it, because representing drums as a tab is a feature of Guitar Pro 5 that I can't directly save when I output a MIDI, and it seems to just put the drums in numerical order from the top down on every beat.
The other large detail missing is the dynamics, which are generally handled a little differently in MIDI compared to MOD, but I might be able to just convert them over note by note (GP5 does it this way as well - the more faded a note is on the score, the quieter it is).
Since last night I've also completely misnamed it by extending it to handle melodic instruments in a basic fashion as well -
this is the result of running it on a song that I have in progress at the moment, with just the drums, bass and harpsichord parts turned on. For something automatically generated from a completely different format it's pretty convincing.