Skip to content

Commit

Permalink
auto support launchpad s
Browse files Browse the repository at this point in the history
  • Loading branch information
YeonV committed Oct 5, 2024
1 parent a2cafac commit ecefee9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/components/Midi/MidiListener.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useRef, useState } from 'react'
import { WebMidi, Input } from 'webmidi'
import useStore from '../../store/useStore'
import { getUiBtnNo } from '../../store/ui/storeMidi'

// function setAllButtonsToBlack(output: WebMidi.MIDIOutput) {
// for (let i = 0 i < 81 i++) {
Expand Down Expand Up @@ -41,6 +42,7 @@ const MIDIListener = () => {
const midiOutput = useStore((state) => state.midiOutput)
const midiMapping = useStore((state) => state.midiMapping)
const midiEvent = useStore((state) => state.midiEvent)
const lpType = useStore((state) => state.lpType)
const global_brightness = useStore((state) => state.config.global_brightness)
const glBrightness = useRef(global_brightness)

Expand Down Expand Up @@ -299,11 +301,12 @@ const MIDIListener = () => {
scene.scene_midiactivate.split('buttonNumber: ')[1],
10
)
const uiButtonNumber = lpType === 'LPX' ? buttonNumber : getUiBtnNo(buttonNumber) || -1
// console.log('Button Number:', buttonNumber)
mapping[0] = {
...mapping[0],
[buttonNumber]: {
...mapping[0][buttonNumber],
[uiButtonNumber]: {
...mapping[0][uiButtonNumber],
command: 'scene',
payload: { scene: key },
buttonNumber: buttonNumber
Expand Down
11 changes: 10 additions & 1 deletion src/store/ui/storeMidi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,16 @@ export const LpMapping = {
]
}


export function getUiBtnNo(inputInt: number): number | null {
for (let i = 0; i < LpMapping.LaunchpadS.length; i++) {
for (let j = 0; j < LpMapping.LaunchpadS[i].length; j++) {
if (LpMapping.LaunchpadS[i][j] === inputInt) {
return LpMapping.LaunchpadX[i][j];
}
}
}
return null;
}
const storeMidi = (set: any) => ({
lpType: 'LPX' as 'LPX' | 'LPS',
setLpType: (type: 'LPX' | 'LPS') =>
Expand Down

0 comments on commit ecefee9

Please sign in to comment.