Skip to content

Commit

Permalink
fix: types for slider values
Browse files Browse the repository at this point in the history
  • Loading branch information
TimSusa committed Oct 6, 2019
1 parent aabeb08 commit 7c059ab
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 106 deletions.
83 changes: 43 additions & 40 deletions packages/midi-bricks/src/actions/init.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import WebMIDI from 'webmidi'
import { debounce } from 'lodash'
// import { debounce } from 'lodash'
import{debounce} from 'debounce'
import { Actions } from './slider-list'

const { initMidiAccessPending, midiMessageArrived, initFailed, initMidiAccessOk } = Actions
const {
initMidiAccessPending,
midiMessageArrived,
initFailed,
initMidiAccessOk
} = Actions

export function initApp(mode) {
return function(dispatch, getState) {
Expand All @@ -18,7 +24,7 @@ export function initApp(mode) {
}
const { inputs = [], outputs = [] } = WebMIDI
const {
sliders: { sliderList = [], pages={} },
sliders: { sliderList = [], pages = {} },
viewSettings: {
availableDrivers: { inputs: availableInputs } = {
inputs: {
Expand All @@ -40,7 +46,8 @@ export function initApp(mode) {
let ccArr = []

// Either only sliderlist
!pages && Array.isArray(sliderList) &&
!pages &&
Array.isArray(sliderList) &&
sliderList.forEach((entry) => {
const { driverNameInput = '', listenToCc = [] } = entry

Expand All @@ -54,21 +61,20 @@ export function initApp(mode) {
})

// Or pages
Object.values(pages).forEach(item => {
const {sliderList} = item
Object.values(pages).forEach((item) => {
const { sliderList } = item
Array.isArray(sliderList) &&
sliderList.forEach((entry) => {
const { driverNameInput = '', listenToCc = [] } = entry

if (name === driverNameInput) {
listenToCc.forEach((listen) => {
if (!ccArr.includes(listen)) {
ccArr.push(parseInt(listen, 10))
}
})
}
})
sliderList.forEach((entry) => {
const { driverNameInput = '', listenToCc = [] } = entry

if (name === driverNameInput) {
listenToCc.forEach((listen) => {
if (!ccArr.includes(listen)) {
ccArr.push(parseInt(listen, 10))
}
})
}
})
})
input.removeListener()
if (
Expand Down Expand Up @@ -102,29 +108,26 @@ export function initApp(mode) {
input.addListener(
'controlchange',
'all',
debounce(
({ value, channel, controller: { number } }) => {
const obj = {
isNoteOn: undefined,
val: value,
cC: number,
channel,
driver: name,

debounce(({ value, channel, controller: { number } }) => {
const obj = {
isNoteOn: undefined,
val: value,
cC: number,
channel,
driver: name
}
const myAction = (payload) => ({
type: 'MIDI_MESSAGE_ARRIVED',
payload,
meta: {
raf: true
}
const myAction = (payload) => ({
type: 'MIDI_MESSAGE_ARRIVED',
payload,
meta: {
raf: true
}
})
// dispatch(midiMessageArrived(obj))
})
// dispatch(midiMessageArrived(obj))

// Seems to perform in less time
dispatch(myAction(obj))
}
, 2)
// Seems to perform in less time
dispatch(myAction(obj))
}, 2)
)
}
if (
Expand Down Expand Up @@ -228,8 +231,8 @@ export function initApp(mode) {
})
if (hasContent(outputs) || hasContent(inputs)) {
const midiAccess = {
inputs: inputs.map(e => e.name),
outputs: outputs.map(e => e.name)
inputs: inputs.map((e) => e.name),
outputs: outputs.map((e) => e.name)
}
dispatch(initMidiAccessOk({ midiAccess }))
resolve(midiAccess)
Expand Down
Loading

0 comments on commit 7c059ab

Please sign in to comment.