Creating an aplaymidi (and compatibles) >16 channel midi file

Just bought your first old school MIDI synthesizer and can't get it to work right? Having trouble getting DOSBox or SCUMMVM to work the way you want? Perhaps we can help. Do you have some neat tips you just want to share with the world? Or maybe you just need help convincing your computer to work. Either way, use this forum for all tech support related needs that somehow relate to MIDI and/or PC Gaming.

Moderator: Quest Studios Archive moderators

Post Reply
jaffa225man
Quest Studios Veteran
Quest Studios Veteran
Posts: 169
Joined: Mon Jul 13, 2015 6:26 pm
Location: Chippewa Falls, Wisconsin

Creating an aplaymidi (and compatibles) >16 channel midi file

Post by jaffa225man »

My objective was to create standard MIDI format files that play with greater than 16 channels in devices that support it.

First, I should say that I've considered writing a feature request for Rosegarden, but the more I think about it, the more I realize it may just create problems for the majority of its users. It does seem, though, that they could include a midi export option that would automatically insert "MIDI Port" Meta-Events based on each track's "Manage MIDI Devices" chosen output. Of course, "MIDI Port" Meta-Events are obsoleted in favor of "Device (Port) Name" Meta-Event's, but they're all that's supported by aplaymidi (and its derivatives) and are useful in that they're not hardcoded port names (i.e. "aplaymidi -p '28:0,28:1' smf-midi-file.mid" for a multi-Part sound module is just as valid as using multiple sound modules with "aplaymidi -p '28:0,32:0' smf-midi-file.mid". One concern would be alleviated if it's possible for "Device (Port) Name" Meta-Events to work with substrings (i.e. "Part A" instead of the whole "SC-8850 Part A") to work with other sound modules that have more "Parts" (Ports), but I can't test that as aplaymidi doesn't support it anyway. If substrings work, though, I would also consider writing a feature request for aplaymidi. See https://web.archive.org/web/20061112102 ... solete.htm for more info. Another (more practical?) possible feature request for Rosegarden, could be the ability to manually create Meta-Events using "Insert Event" in its "Event List Editor". That would function without introducing bugs.

Okay, here's my non-programmatic solution that you probably all can guess: just edit the exported SMF (format 1, multi-track) MIDI file with a hex editor.
1. Find the "MTrk"s throughout the file that pertain to channels you want to assign greater than 16.
2. For each, add 5 to the number contained in the 4 bytes directly following the "MTrk" in question (in hexadecimal) and store the sum in those same 4 bytes (in hexadecimal).
3. Also after each "MTrk" modified above, directly following the 4 bytes containing that changed sum, insert these 5 bytes: "00 FF 21 01 pp", where "pp" is 00, 01, 02, or 03 (which stands for Part A, Part B, Part C, or Part D... or really the port order specified to aplaymidi), so pp should be 01, 02, or 03, as 00 is the default port/Part normally used.

That works for me, and although it's dependent on an obsolete Meta-Event, it creates playable files (in GNU/Linux aplaymidi, etc.) without dealing with SysEx confusion and its checksums, or more complex/nonstandard software solutions (Rosegarden, CakeWalk, etc.).
Post Reply