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 ba882e1 commit a8dbe7d
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions src/components/Midi/MidiListener.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,33 +223,36 @@ const MIDIListener = () => {

enableWebMidi()




const handleWebsockets = (event: any) => {
const initLeds = () => {
const output = WebMidi.getOutputByName(midiOutput)
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)
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)
} 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)
}
}
}
}
})
})
}
}
initLeds()

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

0 comments on commit a8dbe7d

Please sign in to comment.