Skip to content

Commit

Permalink
Fix connection splice()
Browse files Browse the repository at this point in the history
  • Loading branch information
Brackets-Coder committed Oct 30, 2024
1 parent c9645ee commit 9014297
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions extensions/MasterMath/midi.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,23 @@
function onSuccess(midiAccess) {
midiAccess.onstatechange = (event) => {
if (event.port.state == "connected") {
midiInputDevices.push([
`[id: "${event.port.id}"` + ` name: "${event.port.name}"]`,
]);
midiInputDevices.push(
`[id: "${event.port.id}" name: "${event.port.name}"]`
);
midiDeviceInfo.push([event.port.id, event.port.name]);
} else if (event.port.state == "disconnected") {
midiInputDevices.splice(
[`[id: "${event.port.id}"` + ` name: "${event.port.name}"]`],
1
// Find and remove from midiInputDevices
const inputIndex = midiInputDevices.findIndex(
(item) =>
item === `[id: "${event.port.id}" name: "${event.port.name}"]`
);
if (inputIndex !== -1) midiInputDevices.splice(inputIndex, 1);

// Find and remove from midiDeviceInfo
const infoIndex = midiDeviceInfo.findIndex(
(item) => item[0] === event.port.id
);
midiDeviceInfo.splice([event.port.id, event.port.name]);
if (infoIndex !== -1) midiDeviceInfo.splice(infoIndex, 1);
}
};

Expand Down

0 comments on commit 9014297

Please sign in to comment.