Adds ability for user to select MIDI channel
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
aarbit 2024-07-28 22:56:23 -05:00
parent fb09365579
commit a485d78e6f
2 changed files with 16 additions and 2 deletions

View File

@ -4,5 +4,4 @@ A quick preset selector for the Oberheim Matrix 1000
# TODO # TODO
* Add support for channel selection
* Save last configuration and patch selection in local browser cache * Save last configuration and patch selection in local browser cache

View File

@ -9,6 +9,7 @@ function App() {
const [patchNumber, setPatchNumber] = useState(0) const [patchNumber, setPatchNumber] = useState(0)
const [midiDeviceMap, setMidiDeviceMap] = useState<Map<string, Output>>(new Map()) const [midiDeviceMap, setMidiDeviceMap] = useState<Map<string, Output>>(new Map())
const [selectedMidiDevice, setSelectedMidiDevice] = useState<string>() const [selectedMidiDevice, setSelectedMidiDevice] = useState<string>()
const [selectedMidiChannel, setSelectedMidiChannel] = useState<number>(1)
function connect() { function connect() {
WebMidi.enable() WebMidi.enable()
@ -55,7 +56,7 @@ function App() {
function sendPatchNumber() { function sendPatchNumber() {
if(selectedMidiDevice) { if(selectedMidiDevice) {
let outputDevice = midiDeviceMap.get(selectedMidiDevice) let outputDevice = midiDeviceMap.get(selectedMidiDevice)
let midiChannel = 2 let midiChannel = selectedMidiChannel
if(outputDevice) { if(outputDevice) {
outputDevice.sendControlChange(1, 127, {channels: midiChannel}) outputDevice.sendControlChange(1, 127, {channels: midiChannel})
pause(50) pause(50)
@ -93,13 +94,27 @@ function App() {
return options return options
} }
function midiChannelOptions() {
let channelList = makeList(16).map((num) => {
return <option value={num+1} key={'channelkey'+(num+1)}>{num+1}</option>
})
channelList.unshift(<option key={"channelnochoice"}>--</option>)
return channelList
}
function handleMidiDeviceSelect(e: ChangeEvent<HTMLSelectElement>) { function handleMidiDeviceSelect(e: ChangeEvent<HTMLSelectElement>) {
setSelectedMidiDevice(e.target.value) setSelectedMidiDevice(e.target.value)
} }
function handleMidiChannelSelect(e: ChangeEvent<HTMLSelectElement>) {
setSelectedMidiChannel(parseInt(e.target.value))
}
return ( return (
<> <>
<select onChange={handleMidiDeviceSelect}>{midiDeviceOptions()}</select> <select onChange={handleMidiDeviceSelect}>{midiDeviceOptions()}</select>
<select onChange={handleMidiChannelSelect}>{midiChannelOptions()}</select>
<div> <div>
PATCH: PATCH:
</div> </div>