Generating MIDI with abcjs

It’s been a while since I worked on the MIDI part of abcjs, and it shows! When Greg first developed it, he put in a widget that would use QuickTime. Pretty clever at the time. But that doesn’t work anywhere any more, so I removed it. I have some plans for generating MIDI right on the web page, but that will have to wait until the next version.

For this version I concentrated on making the MIDI generation better.

I refactored the generation to use three passes: 1) identify the parts of the abcjs object that affect sound and put them in chronological order, 2) Turn those conceptual events into specific events, 3) generate MIDI. That made it much easier to add features: all of the “artistic” stuff is in the second step.

The two main features I added were guitar chord generation and grace notes. Both of those required some artistic license.

I tried to find a rule of thumb for how long a grace note is, but there really isn’t one. It depends on the style of music whether the grace note is before the beat or on the beat. The length of a grace note is variable. It is unclear whether it should be a fraction of a beat or a fixed amount of time, independent of the tempo. I just picked something that seemed to work for me.

For guitar chords, in general I wanted to do a boom-chick pattern, but that depended on where the chords were specified in time. This can be vague and differs for different meters. So if boom-chick didn’t work, I played the full chord on the beat. If a chord appears between beats, I pulled it back to the previous beat. This seems to have worked passably for the sample tunes I tried. It’s just that the specification is not very exact, so there’s no way of telling for some of the border cases.

In any case, the result was surprisingly good on some tunes! There is room for improvement and there are many decorations, MIDI commands, and rhythm designations to support to keep me busy for the next version.

And, when it comes down to it, MIDI is never going to sound “good”. The purpose of MIDI is as a proof-reader of the music you create. It’s just hard to stop refining it once I get going.

Money Lost: