Playing midi files with more than 16 tracks on multiple ports
tevey opened this issue · 6 comments
Hi,
I have a midi file with 32 tracks that i want to play using this library.
Using this code:
const JZZ = require('jzz');
const fs = require('fs');
require('jzz-midi-smf')(JZZ);
const filename = 'END.MID';
const midiout = JZZ().openMidiOut(3);
const data = fs.readFileSync(filename, 'binary');
const smf = new JZZ.MIDI.SMF(data);
const player = smf.player();
player.connect(midiout);
player.play();
only the first 16 tracks are played, which is expected since one midi port only can handle 16 tracks.
Is there any way i can open 2 out ports and play track 1-16 in port1 and track 17-32 in port2?
Thanks!
Do you mean 32 MIDI channels?
Yes, it's possible to route MIDI messages to multiple ports, but it will need a little scripting.
Please attach your file, I'll have a look at it.
A simple solution would look like this:
// instead of player.connect(midiout)
player connect(function(msg) {
(msg.track > 16 ? midiout2 : midiout1).send(msg);
});
It can be further refined to handle the ff21
metaevents from the file and automatically decide to which port to send the track data.
Thanks, will give this a try. And read up on ff21.
Here is a good reference: https://www.midi.org/specifications/file-format-specifications/standard-midi-files
Search for meta events.
Thanks for the help!