Last active
November 3, 2020 08:33
-
-
Save dndrks/817cd450ab432c79c97507c1a1a0a1f6 to your computer and use it in GitHub Desktop.
example midi matrix
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
box = {} -- a table of boxes | |
msg = | |
{ | |
["cc"] = {"cc","val","ch"} | |
, ["note_on"] = {"note","vel","ch"} | |
, ["note_off"] = {"note","vel","ch"} | |
, ["key_pressure"] = {"note","val","ch"} | |
, ["pitchbend"] = {"val","ch",nil} | |
, ["channel_pressure"] = {"val","ch",nil} | |
} | |
for source = 1,4 do -- I have four boxes (four USB MIDI ports) | |
box[source] = midi.connect(source) -- box 1 == whatever's connected to port 1, etc | |
box[source].connected = {false,false,false,false} -- all boxes are disconnected | |
box[source].event = function(data) -- what to do when a box sends MIDI into norns: | |
-- print("box "..source..":") -- uncomment this line to print which box, if you want | |
local received = midi.to_msg(data) -- capture the message... | |
-- tab.print(received) -- uncomment this line to print the message, if you want | |
for destination = 1,4 do -- for each of the potential inter-box destinations: | |
if box[source].connected[destination] then -- if the source is connected to a destination... | |
local msg_1 = received[msg[received.type][1]] -- shorten message 1... | |
local msg_2 = received[msg[received.type][2]] -- shorten message 2... | |
local msg_3 = received[msg[received.type][3]] -- shorten message 3... | |
-- send the source's messages to the destination box: | |
box[destination][received.type](box[destination],msg_1,msg_2,msg_3) | |
-- ^^ nb: I removed syntactic sugar from self:functionName() ^^ | |
end | |
end | |
end | |
end | |
function manage(src,dest,state) -- easier way to manage states: | |
box[src].connected[dest] = state | |
--`manage(2,1,true)` sets box 2 as source and box 1 as destination | |
--`manage(2,1,false)` breaks the sending connection between box 2 and box 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment