Scripting MIDI CC sends

Hi all,

I’m trying to send out some midi cc commands to my midi interface. It should be as simple as “midi:cc(cc,val,ch)” according to the docs but I keep getting this error:




/home/we/norns/lua/core/midi.lua:85: bad argument #1 to ‘midi_send’ (userdata expected, got nil)

stack traceback:

[C]: in field ‘midi_send’

/home/we/norns/lua/core/midi.lua:85: in function ‘core/midi.send’

/home/we/norns/lua/core/midi.lua:112: in function ‘core/’

(…tail calls…)

I’ve had a peek around to see if I can find anyone implementing midi cc in their scripts but it doesn’t seem to be very common.

I know it’s probably a quick fix to do with syntax, the same way “ParamSet:” can be used as “params:” :man_shrugging:

hey hey!

if you’re executing this from the REPL (or if you haven’t yet assigned a variable as midi.connect(x), where x is the port you want to address), you’ll need to address the specific port where your device is located.


you can navigate to DEVICES > MIDI and see which port your MIDI device is connected to:

(here, my AKM320 MIDI device is connected to port 1)

knowing the device’s port is super important – norns needs to be told where to direct midi messages, so we’ll use a device’s port assignment to help specify.

you can also query the ports from maiden's REPL
tab.print(midi.vports) -- execute this, which returns:
1	table: 0x3cbb78
2	table: 0x3bf688
3	table: 0x3c0678
4	table: 0x3c0650
tab.print(midi.vports[1]) -- execute this, which returns:
note_off	function: 0x3a79c0
key_pressure	function: 0x3a78c8
start	function: 0x3a73c8
channel_pressure	function: 0x3a77a8
pitchbend	function: 0x3a75e0
note_on	function: 0x3a7ae0
send	function: 0x3a77f8
cc	function: 0x3a7760
clock	function: 0x3a7330
stop	function: 0x3a76b0
program_change	function: 0x3a7548
name	AKM320
song_select	function: 0x3a7498
song_position	function: 0x3a71b0
continue	function: 0x3a7590

the easiest way to keep track of the little boxes is to assign the destination port to a variable in your script, eg. device1 = midi.connect(1), to alias the device connected to port 1 as device1. this is a little more readable than midi.vports[1]

either way, once we know which port the device is connected to, we can…

send midi cc

you were spot on, you need to use :cc(cc,val,ch) to send a cc message, but the first part needs to be more specific since we need to provide a port destination for that cc message.

if you don’t assign the device port to a variable, you’ll address devices using the raw port assignment:


if you do assign the device port to a variable, then you can just use that variable:


hope this helps! please lmk if there’s any ambiguity! i just posted a video walkthrough of some midi hacking, which covers these setup steps. cc is a function of the midi library, same as note_on, so the same approach applies: *norns walkthrough*: hacking a script to add MIDI output


Thats so funny I opened The “Hacking a script to add MIDI output” in a new tab as you replied to my question!

This helps a lot! I’m now successfully sending CC commands :slight_smile:

1 Like