//It appears that when WebMidi sends a noteon message to itself,
//the octave in the listened for note is 2 octaves below
//the octave that was sent.
//Code to reproduce:
//eval the commented out last line to send C3.
var wmin, wmout //WebMidiInput and WebMidiOutput ports
WebMidi = require("webmidi")
WebMidi.enable(function(err) {
if (err) {out("WebMidi couldn't be enabled: " + err)}
else {
out(WebMidi.inputs)
out(WebMidi.outputs)
wmin = WebMidi.inputs[0]
wmout = WebMidi.outputs[0] //use same output as the output so you can "hear" what's "played"
wmin.addListener('noteon', "all",
function(event){
debugger
console.log(event.note.octave)})
}})
// webMidi: C3 == 60 == middle C. GarageBand also plays 60 as middle C
// wmout.playNote("C3", 1, {duration: 2000})
/*setting up a Mac or PC to be able to do this without a hardware midi controller
is difficult. Here's how:
To get a MIDI app on your computer to talk to
another MIDI app on your computer,
you must set up a "Virtual Port".
On Mac 10.12 (Sierra)
Launch Applications/Utilities/Audio Midi Setup.app
Choose menubar/Window/Show Midi Studio
In the dialog box that comes up, double click "IAC Driver".
In the new dialog box that comes up,
click on the port "Bus 1" to select it.
Above that, check "Device is online"
Click the "Apply" button.
For creating virtual ports on windows:
http://www.tobias-erichsen.de/software/loopmidi.html
looks promising.
Eval the below to enable webmidi and create an input and output.
Eval the last line (playNote call) to send a note from WebMidi, through
the "Bus 1" port, and back to WebMidi.
You should see in the output pane:
"Got MIDI event: Input, IAC Driver Bus 1, channel:1, type: noteon, C1, vel: 0.5039370078740157"
To hear this on a "software synthesizer" you have to
get it to listen to midi
output on the appropriate device, on the appropriate channel.
One such software synthesizer is in GarageBand,
which is now free for Mac and Windows.
On Mac, In your Applications folder
you should see GarageBand.app (comes with the OS)
Double click on it. This will cause its full contents
to download and takes 15 minutes or so (its very large).
Once this is complete, launch it if it isn't already up.
On Windows, see https://garagebandforwindowspc.org/ for a more
complex installation, but looks promising.
With GB launched, double click on "Keyboard Collection"
Back in DDE, Eval the call to playNote and you should hear a sound.
Select a different instrument in GarageBand for a different sound.
Debugging Garage Band:
If no sound, EVAL playnote in DDE again. Sometimes the first one
just doesn't work.
If that doesn't work, check that sound is up on your computer.
(On Mac, hit the F12 key a few times.)
If that didn't help, verify that Garage Band can
make a sound by choosing its menu bar/Show Keyboard
Then click on the piano keys and you should hear a sound.
If that didn't help, check GB's "Master Slider"
(unlabeled horizontal slider in the upper right of GB main window.)
If that didn't help, check the midi connections in
Garage Band: menu bar/GarageBand/Preferences.
Select "Audio/Midi"
In the bottom of the dialog you should see
"Midi Status: X MIDI inputs detected."
(if X == 0, try clicking the "Reset Midi Drivers" button.)
Even though GB has a soft keyboard, it can't send out Midi.
You can download http://vmpk.sourceforge.net/
for a virtual midi controller,
for Mac/Windows/Linux. It has no synthesizers in it.
In the VMPK menu bar, choose "MIDI Connections".
For "MIDI OUT Driver", choose "CoreMIDI".
For "Output MIDI Connection" Choose "IAC Driver Bus 1"
(the default on the Mac, it will be something else on Windows.)
Click the OK button.
Choose VMPK menu bar/Tools/Note Input/Comuter Keyboard,
and also in the same sub menu, "Mouse".
Now click on the keyboard or hit a key (like "q")
and you should see "Got Midi event..." in DDE.
You should also hear the note played in Garage Band.
VMPK has a nice feature for labeling the keys on its
piano keyboard: Choose menu bar/View/Note names
Unfortunately this labels Middle C as C4, whereas
WebMidi uses Middle C as C3. Octave nomenclature is
inconsistent in conventional music as well as MIDI.
*/