midi note to CC for params mod: add to `dust/code/note_to_params_cc/lib`
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
-- midi note to cc mod (study only, not supported code!) | |
local mod = require 'core/mods' -- this provides the mod its functionality | |
local note_to_cc_mod = {} | |
local mod_midi_devs = {} | |
function note_to_cc_mod.init() | |
for i = 1,16 do | |
mod_midi_devs[i] = midi.connect(i) | |
end | |
end | |
function note_to_cc_mod.init_devices() | |
local pre_existing_events = {} | |
for i = 1,16 do | |
if midi.vports[i].event then -- if a script already defines midi events, we want to retain it! | |
pre_existing_events[i] = midi.vports[i].event | |
end | |
mod_midi_devs[i].event = function(data) | |
if pre_existing_events[i] ~= nil then -- if the script defines an event | |
pre_existing_events[i](data) -- execute the script-defined event as part of the mod's event | |
end | |
if midi.to_msg(data).type == "note_on" then | |
local ch_val = (data[1]-144)+176 | |
norns.menu_midi_event({ch_val,data[2],data[3]},i) -- if you want velocity to determine value... | |
-- norns.menu_midi_event({ch_val,data[2],127},i) -- or, if you want "note on" to set param to max, use this | |
elseif midi.to_msg(data).type == "note_off" then | |
local ch_val = (data[1]-128)+176 | |
-- norns.menu_midi_event({ch_val,data[2],0},i) -- if you want "note off" to set param to 0, uncomment | |
-- otherwise, we'll just use "note on" events | |
end | |
end | |
end | |
end | |
mod.hook.register("script_pre_init", "surface note data as cc", function() | |
local script_init = init | |
function init() | |
script_init() | |
note_to_cc_mod.init() | |
note_to_cc_mod.init_devices() | |
end | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment