-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add launch control xl support, and chunk mixer
- Loading branch information
Showing
11 changed files
with
744 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module.exports = scaleInterpolate | ||
|
||
function scaleInterpolate (currentValue, toValue, state) { | ||
var difference = absDifference(currentValue, toValue) | ||
if (difference != null && difference > 3 && (!state.lastSync || Date.now() - state.lastSync > 50)) { | ||
if (state.interpolatingFrom == null) { | ||
state.interpolatingFrom = toValue | ||
} | ||
if (absDifference(state.interpolatingFrom, currentValue) < difference) { | ||
if (currentValue <= 0) { | ||
toValue = 1 | ||
} else { | ||
toValue = toValue / state.interpolatingFrom * currentValue | ||
} | ||
} else { | ||
state.interpolatingFrom = toValue | ||
toValue = currentValue | ||
} | ||
state.lastSync = null | ||
} else { | ||
state.interpolatingFrom = null | ||
state.lastSync = Date.now() | ||
} | ||
|
||
return toValue | ||
} | ||
|
||
function absDifference (a, b) { | ||
if (a != null && b != null) { | ||
return Math.abs(a - b) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
var watch = require('observ/watch') | ||
|
||
module.exports = watchKnobs | ||
|
||
function watchKnobs (stream, keys, listener, defaultValue) { | ||
var currentStream = null | ||
var release = watch(stream, set) | ||
var currentValues = [] | ||
var broadcastedValues = [] | ||
var broadcastedAt = [] | ||
var lastChangeAt = [] | ||
var throttling = [] | ||
var timers = [] | ||
var minDelay = 10 | ||
|
||
return function () { | ||
release && release() | ||
currentStream && currentStream.removeListener('data', handler) | ||
} | ||
// scoped | ||
|
||
function handler (message) { | ||
var key = message[0] + '/' + message[1] | ||
var index = keys.indexOf(key) | ||
if (~index) { | ||
broadcast(index, message[2]) | ||
} | ||
} | ||
|
||
function broadcast (index, value) { | ||
currentValues[index] = value | ||
if (!throttling[index]) { | ||
if (Date.now() - lastChangeAt[index] > minDelay) { | ||
broadcastNow(index, value) | ||
} else { | ||
throttling[index] = true | ||
timers[index] = setInterval(function () { | ||
broadcastNow(index, currentValues[index]) | ||
}, minDelay) | ||
} | ||
} | ||
lastChangeAt[index] = Date.now() | ||
} | ||
|
||
function broadcastNow (index, value) { | ||
broadcastedAt[index] = Date.now() | ||
|
||
if (broadcastedValues[index] !== value) { | ||
broadcastedValues[index] = value | ||
listener(index, value) | ||
} | ||
|
||
if (throttling[index] && broadcastedAt[index] - lastChangeAt[index] > minDelay) { | ||
throttling[index] = false | ||
clearInterval(timers[index]) | ||
} | ||
} | ||
|
||
function set (newStream) { | ||
currentStream && currentStream.removeListener('data', handler) | ||
newStream && newStream.on('data', handler) | ||
currentStream = newStream | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
name: 'Launch Control XL', | ||
portMatch: /^Launch Control XL/, | ||
node: 'global/launch-control-xl', | ||
group: 'global-controllers', | ||
object: require('./object') | ||
} |
Oops, something went wrong.