Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #27 from McOmghall/master
Browse files Browse the repository at this point in the history
Added MIDI parsing functionality to example
  • Loading branch information
danigb authored Jun 30, 2016
2 parents 8ce8ae1 + d538aae commit eab0ae2
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,30 @@
time += 0.2;
});
});

// You can also use MIDI inputs, if you have connected ones
function onMIDISuccess (midi) {
if (!inst.processMidiMessage) {
console.log('Loaded soundfont-player doesnt have parsing MIDI ability')
return
}
midi.inputs.forEach(function (port, channelKey) {
port.onmidimessage = inst.processMidiMessage
console.log('You can play MIDI events on your input %j', port)
})
}
function onMIDIFailure (error) {
console.log('Error while loading MIDI API %j', error)
}
function renewMIDIAccess () {
if (window.navigator && typeof window.navigator.requestMIDIAccess === 'function') {
console.log('Adding MIDI connection')
window.navigator.requestMIDIAccess().then(onMIDISuccess, onMIDIFailure)
} else {
console.log('MIDI API not available')
}
}
renewMIDIAccess()

var xhr = new XMLHttpRequest();
xhr.open("GET", "./assets/musyngkite.json");
Expand All @@ -66,6 +90,7 @@
inst.onready(function() {
console.log("Instrument " + name + " ready.");
btn.removeAttribute("disabled");
renewMIDIAccess()
});
});
label.appendChild(radio);
Expand Down

0 comments on commit eab0ae2

Please sign in to comment.