MIDI File Export... Not So Fast!

So I have looked a bit more into bringing MIDI file export to Sputter. This could be very useful, making it possible to use Sputter as an on-the-go drafting tool.

This summer I have been reading up on and implementing code for the MIDI file format. This has gone really well. By this point it is a quite old and simple format, so writing the code for it was quite easy.

The harder part, as it now seems, is translating Sputter’s playback logic into MIDI events. At first I thought this would be trivial, just iterating through the notes and generate MIDI events as appropriate.

Then I realized that there would be situations like this:

Screenshot showing repeated pattern with non-retriggered note

If you look closely, you’ll see that this group is repeated twice:

Group repeats twice

And if you look closely at the beginning of the note, you will see that retrigger is disabled:

Retrigger disabled

This means that the note is to be played continously for two bars, and the resulting MIDI file should end up like this:

MIDI file with continuous note for two bars

Not with two notes on two seperate bars:

MIDI file with two seperate notes

And not with only one note for one bar:

MIDI file with two seperate notes

Since Sputter does not try to be or resemble a traditional MIDI editor the “naive approach” mentioned before would result in one of these two outputs. This would not sound the same as what you would hear if you played back the track in Sputter.

So in order to generate the MIDI note events properly, the song has to be played through virtually using Sputter’s logic. Since the playback logic currently expects there to be an audio backend involved, these two components need to be better seperated so they can be used individually.

As the technically inclined have probably already spotted, this means more refactoring! However, as opposed to last time, this should not be as extensive or take so long.

It should not be too long before some progress has been made, I will post updates with regards to this.