Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
YeonV committed Oct 5, 2024
1 parent fd67105 commit 5267d6c
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions src/components/Midi/MidiListener.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,37 +215,40 @@ const MIDIListener = () => {
handleMidiInput(input)
})
}
if (output) {
Object.entries(midiMapping[0]).forEach(([key, value]) => {
const buttonNumber = value.buttonNumber
if (value.command !== 'scene' && value.command && value.command !== 'none' && buttonNumber !== -1) {
if (output) {
try {
output.send([parseInt(`0x${value.typeCommand}`) || 0x90, buttonNumber, parseInt(value.colorCommand || commandColor, 16) || 99])
} catch (error) {
console.error('Error sending MIDI message:', error)
}
}
} else if (value.command === 'scene') {
if (output && buttonNumber !== -1) {
try {
output.send([parseInt(`0x${value.typeSceneInactive}`) || 0x90, buttonNumber, parseInt(value.colorSceneInactive || midiSceneInactiveColor, 16) || 60])
} catch (error) {
console.error('Error sending MIDI message:', error)
}
}
}
})
}
}
}
})
}

enableWebMidi()

const output = WebMidi.getOutputByName(midiOutput)

Object.entries(midiMapping[0]).forEach(([key, value]) => {
const buttonNumber = value.buttonNumber
if (value.command !== 'scene' && value.command && value.command !== 'none' && buttonNumber !== -1) {
if (output) {
try {
output.send([parseInt(`0x${value.typeCommand}`) || 0x90, buttonNumber, parseInt(value.colorCommand || commandColor, 16) || 99])
} catch (error) {
console.error('Error sending MIDI message:', error)
}
}
} else if (value.command === 'scene') {
if (output && buttonNumber !== -1) {
try {
output.send([parseInt(`0x${value.typeSceneInactive}`) || 0x90, buttonNumber, parseInt(value.colorSceneInactive || midiSceneInactiveColor, 16) || 60])
} catch (error) {
console.error('Error sending MIDI message:', error)
}
}
}
})


const handleWebsockets = (event: any) => {
const output = WebMidi.getOutputByName(midiOutput)
try {
if (event.type === 'scene_activated') {
const { scene_id } = event.detail
Expand Down

0 comments on commit 5267d6c

Please sign in to comment.