Skip to content

Commit

Permalink
fix: Fix for broken CC Toggle Button
Browse files Browse the repository at this point in the history
  • Loading branch information
TimSusa committed Oct 16, 2019
1 parent 9948cda commit 8b8f429
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions packages/midi-bricks/src/reducers/slider-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,20 @@ export const sliders = {

[ActionTypeSliderList.HANDLE_SLIDER_CHANGE](state, action) {
const { i, val } = action.payload
let sliderList = state.sliderList
const sliderList = state.sliderList
const idx = sliderList.findIndex((item) => item.i === i)
const tmp = sliderList[idx]

const idx = sliderList.findIndex(item => item.i === i)

const tmp = sliderList[idx]
const { type, onVal, offVal } = tmp || {}

// Set noteOn/noteOff stemming from CC VAl
if ([BUTTON_CC, BUTTON_TOGGLE_CC].includes(type)) {
if (val === onVal || val === offVal) {
sliderList = toggleNotesInState(state.sliderList, i)
}
}
// Handle multi CC
const { midiCC, midiChannel, driverName, label } = tmp || {}
// At first send MIDI
const { midiCC, midiChannel, driverName, label, isNoteOn } = tmp || {}
sendControlChanges({ midiCC, midiChannel, driverName, val, label })

// Now, do view state changes
return createNextState(state, (draftState) => {
// For CC Buttons we toggle the NoteOn state at each trigger
if ([BUTTON_CC, BUTTON_TOGGLE_CC].includes(tmp.type)) {
draftState.sliderList[idx].isNoteOn = !isNoteOn
}
draftState.sliderList[idx].val = val
return draftState
})
Expand Down Expand Up @@ -938,11 +935,13 @@ function transformAddState(state, action) {
function toggleNotesInState(list, i) {
return list.map((item) => {
if (item.i === i) {
return {
const res = {
...item,
isNoteOn: !item.isNoteOn,
val: !item.isNoteOn ? item.onVal : item.offVal
val: item.isNoteOn ? item.onVal : item.offVal
}
console.log('togglenotesinsstat', res.isNoteOn)
return res
} else {
return item
}
Expand Down

0 comments on commit 8b8f429

Please sign in to comment.