Skip to content

Commit

Permalink
split websocket handler
Browse files Browse the repository at this point in the history
  • Loading branch information
YeonV committed Oct 5, 2024
1 parent ecefee9 commit fd67105
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions src/components/Midi/MidiListener.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const MIDIListener = () => {
const setMidiInput = useStore((state) => state.setMidiInput)
const setMidiOutput = useStore((state) => state.setMidiOutput)
const midiInput = useStore((state) => state.midiInput)
const commandColor = useStore((state) => state.midiColors.commandColor)
const midiOutput = useStore((state) => state.midiOutput)
const midiMapping = useStore((state) => state.midiMapping)
const midiEvent = useStore((state) => state.midiEvent)
Expand Down Expand Up @@ -193,7 +194,7 @@ const MIDIListener = () => {
if (value.command && value.command !== 'scene' && value.command !== 'none') {
if (output) {
try {
output.send([0x90, buttonNumber, parseInt(value.colorCommand, 16) || 99])
output.send([0x90, buttonNumber, parseInt(value.colorCommand || commandColor, 16) || 99])
} catch (error) {
console.error('Error sending MIDI message:', error)
}
Expand Down Expand Up @@ -221,32 +222,30 @@ const MIDIListener = () => {

enableWebMidi()



const handleWebsockets = (event: any) => {
const output = WebMidi.getOutputByName(midiOutput)
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, 16) || 99])
} catch (error) {
console.error('Error sending MIDI message:', error)
}
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)
}
}
} 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) => {
try {
if (event.type === 'scene_activated') {
const { scene_id } = event.detail
Expand Down

0 comments on commit fd67105

Please sign in to comment.