Wherein we ramble on about 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. On Windows,
invoking Probe MIDI System..
when no devices are connected produces
this output in the Log Panel:
A similar result is obtained on MacOS but under the API guise
OS-X CoreMIDI
.
Now, ofter pluging in a MIDI keyboard and Digital Music Interface device we see this on Windows:
You can also probe MIDI from the Hz command line. as follows:
% Hz --midi:probe
When invoked in this manner, Hz exits after emitting a probe-summary to the std output channel.
Each time devices are connected or perhaps even if your computer is
restarted the results of the probe may change. Importantly, the
MusicAPI MidiIn
constructor accepts a port number or a port object
to identify your device and this correspondance may change with the
changing conditions on your computer. If your MIDI port numbers are
ntermittent 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();