Skip to content

Instantly share code, notes, and snippets.

@dndrks
Last active Apr 5, 2021
Embed
What would you like to do?
multimap example
my_faderbank = midi.connect(2) -- swap 2 for whichever port your device is on
function init()
-- just going to initialize some dummy parameters
amp = controlspec.AMP
params:add_control("amplitude","amplitude",amp)
pan = controlspec.PAN
params:add_control("panning","panning",pan)
del = controlspec.DELAY
params:add_control("delay_time","delay time",del)
end
my_faderbank.event = function(data)
local d = midi.to_msg(data)
-- print(d.cc,d.val) -- uncomment this line to see the raw values
if d.cc == 32 then -- swap 32 for whichever cc you want to route
multi_map("amplitude",d.val) -- i just need to make sure each of these names match the parameter's
multi_map("panning",d.val) -- same here.
multi_map("delay_time",d.val) -- same here.
end
end
-- the plumbing!
function multi_map(p,val)
params:set(p,map_range(p,val))
end
function map_range(p,val)
return util.linlin(1,127,get_range(p)[1],get_range(p)[2],val)
end
function get_range(p)
local id = params.lookup[p]
local name = params:lookup_param(id)
local t = params:t(id)
if t == params.tCONTROL then
return {params.params[id].controlspec.minval,params.params[id].controlspec.maxval}
elseif t == params.tNUMBER or t == params.tOPTION or t == params.tBINARY then
return name:get_range()
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment