exports.identity = (v) -> v
exports.identity.inverse = exports.identity
exports.momentary = (v) -> if v > 0 then 1 else 0
exports.momentary.inverse = (v) -> if v > 0 then 1 else 0
exports.binary = (v, oldv) -> if v > 0 then not oldv else null
exports.binary.inverse = (v) -> if v > 0 then 1 else 0
exports.linear = (v, min, max) -> min + v * (max - min)
exports.linear.inverse = (v, min, max) -> (v - min) / (max - min)
exports.centered = (v, min, center, max) ->
if v < .5
then linear v*2, min, center
else linear (v-.5)*2, center, max
exports.centered.inverse = (v, min, center, max) ->
if v < center
then 0.5 * linear.inverse v, min, center
else 0.5 + 0.5 * linear.inverse v, center, max
exports.transform = (f, args...) ->
result = (ev, oldv) -> f ev.value / 127.0, args..., oldv
result.inverse = (v) -> 127 * f.inverse(v, args...)
result
exports.transformI = (f, args...) ->
result = (ev, oldv) -> f ev.value, args..., oldv
result.inverse = (v) -> f.inverse(v, args...)
result
exports.transformB = (f, args...) ->
result = (ev, oldv) -> f ev.pressed / 127.0, args..., oldv
result.inverse = (v) -> 127 * f.inverse(v, args...)
result
exports.identityT = identityT = exports.transformI exports.identity
exports.momentaryT = momentaryT = exports.transformB exports.momentary
exports.binaryT = binaryT = exports.transformB exports.binary
exports.linearT = linearT = -> exports.transform exports.linear, arguments...
exports.centeredT = centeredT = -> exports.transform exports.centered, arguments...
exports.defaultT = defaultT = linearT 0.0, 1.0