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