Fixes WebMidi use and possible undefined issue
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
aarbit 2024-07-28 16:39:40 -05:00
parent 6af9436544
commit 41f498d85d

View File

@ -13,20 +13,20 @@ function App() {
function connect() { function connect() {
WebMidi.enable() WebMidi.enable()
.then( .then(
(_: WebMidi) => midiReady(), (_) => midiReady(),
(err) => console.log('Something went wrong', err)); (err) => console.log('Something went wrong', err));
} }
function midiReady() { function midiReady() {
// react to device changes. // react to device changes.
//midi.addEventListener('statechange', (event) => initDevices(event.target)); //midi.addEventListener('statechange', (event) => initDevices(event.target));
initDevices(WebMidi); initDevices();
} }
function initDevices(midi: WebMidi) { function initDevices() {
//console.log(midi) //console.log(midi)
let midiOutputMap = new Map() let midiOutputMap = new Map()
midi.outputs.forEach((outputInfo: Output) => { WebMidi.outputs.forEach((outputInfo: Output) => {
console.log(outputInfo.id) console.log(outputInfo.id)
midiOutputMap.set(outputInfo.id, outputInfo) midiOutputMap.set(outputInfo.id, outputInfo)
}) })
@ -57,13 +57,15 @@ function App() {
if(selectedMidiDevice) { if(selectedMidiDevice) {
let outputDevice = midiDeviceMap.get(selectedMidiDevice) let outputDevice = midiDeviceMap.get(selectedMidiDevice)
let midiChannel = 2 let midiChannel = 2
outputDevice.sendControlChange(1, 127, {channels: midiChannel}) if(outputDevice) {
pause(50) outputDevice.sendControlChange(1, 127, {channels: midiChannel})
outputDevice.sendProgramChange(bankNumber, {channels: midiChannel}) pause(50)
pause(200) outputDevice.sendProgramChange(bankNumber, {channels: midiChannel})
outputDevice.sendControlChange(1, 0, {channels: midiChannel}) pause(200)
pause(50) outputDevice.sendControlChange(1, 0, {channels: midiChannel})
outputDevice.sendProgramChange(patchNumber, {channels: midiChannel}) pause(50)
outputDevice.sendProgramChange(patchNumber, {channels: midiChannel})
}
} }
} }