Skip to content

Commit

Permalink
try to fix midi issues
Browse files Browse the repository at this point in the history
  • Loading branch information
YeonV committed Oct 4, 2024
1 parent 096d33b commit 8cf6a79
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/components/Gamepad/Assign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ const Assign = ({
...mapping,
[padIndex]: {
...mapping[padIndex],
[index]: { command: e.target.value }
[index]: {
...mapping[padIndex]?.[index],
command: e.target.value
}
}
})
}
Expand Down
8 changes: 4 additions & 4 deletions src/components/Midi/MidiListener.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ const MIDIListener = () => {

Object.entries(midiMapping[0]).forEach(([key, value]) => {
const buttonNumber = value.buttonNumber
if (value.command !== 'scene' && value.command && value.command !== 'none') {
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])
Expand All @@ -233,7 +233,7 @@ const MIDIListener = () => {
}
}
} else if (value.command === 'scene') {
if (output) {
if (output && buttonNumber !== -1) {
try {
output.send([parseInt(`0x${value.typeSceneInactive}`) || 0x90, buttonNumber, parseInt(value.colorSceneInactive, 16) || 60])
} catch (error) {
Expand All @@ -250,15 +250,15 @@ const MIDIListener = () => {
const scene = scenes[key]
const buttonNumber = parseInt(scene.scene_midiactivate.split('buttonNumber: ')[1], 10)
if (key === scene_id) {
if (output) {
if (output && buttonNumber !== -1) {
if (!Number.isNaN(buttonNumber)) {
output.send([parseInt(`0x${midiMapping[0][buttonNumber]?.typeSceneActive}`) || 0x90, buttonNumber, parseInt(midiMapping[0][buttonNumber]?.colorSceneActive || '1E', 16)])
}
} else {
console.error('No MIDI output devices found')
}
} else {
if (output) {
if (output && buttonNumber !== -1) {
if (!Number.isNaN(buttonNumber)) {
output.send([parseInt(`0x${midiMapping[0][buttonNumber]?.typeSceneInactive}`) || 0x90, buttonNumber, parseInt(midiMapping[0][buttonNumber]?.colorSceneInactive || '3C', 16)])
}
Expand Down

0 comments on commit 8cf6a79

Please sign in to comment.