info Here we address issues associated with connecting Hz with your MIDI devices and files.
If you have MIDI devices connected to your computer, you can use them to trigger events within your Hz soundscapes and compositions.
The MusicAPI provides two classes to generate events from devices and MIDI files. You can find some simple examples here.
To interactively query Hz's understanding of your systems's MIDI devices, use the settings menu.
Each time devices are connected or perhaps even if your computer is
restarted, the results of the MIDI probe may change. Importantly, the
MusicAPI MidiIn constructor accepts a port number or a device name
to identify your device and this correspondance may change with the
changing conditions on your computer. If your MIDI port numbers are
intermittent on your system, you can issue Midi.Probe and inspect its
results for the device port associated with device name prior
to MidiIn construction.
Here's an example that uses the input device on port 0.
let port = 0;
let midiInput = new MidiIn(port);
let ok = await midiInput.Open();
console.log("midiInput.open returned " + ok);
for(let i=0;i<30;i++)
{
let data = await midiInput.Recv(); // "blocks" until activity
console.log(`${i}: ${data}`);
}
console.log("midiInput.close");
midiInput.Close();