Norns: scripting

I just came here to ask if anyone had worked on sending midi clock out! being able to sync up with my eurorack would be awesome.

Start and stop are very useful additions!


Got inspired by @burn last night to put my paltry Lua skills to the test and create a random Oblique Strategies generator - got it working!!

One syntax question, though: when using screen.text(), is it possible to insert a line break in the text you’re displaying? Some of those lines are quite long, and \n and \z didn’t do anything.

For context, I dumped a bunch of “strategies” to a table in Lua…

EDIT: Haven’t figured out the line break issue yet, but I did figure out how to implement a musical scale in my script and use the PolyPerc engine :slight_smile:


17 posts were merged into an existing topic: Norns: Development

This is so great! Please share if you wish.

1 Like

:slight_smile: Will do, once I clean the code up a bit (be forewarned, though - I’m sure the shared version will still be messy!) I’d also like to implement a counter displaying the index of the displayed strategy — just waiting on the second study to give me a nudge in the right direction for that.


mod note: moved conversation about globals to Norns: Development


a new low.


This sounds like an easy problem to solve, but I am having a bit of trouble.

Is there an easy way to make an int wrap around a range in lua? For instance, I want enc1 to increment/decrement a value, wrapping at its upper and lower bounds.
i.e. in a range of 1 - 8, 8 + 1 would be 1.

1 Like

modulo (%) is your friend.

for example: 9 % 8 = 1

1 Like

thanks! I realized now that this was mentioned in the first study!! :drooling_face:

edit: @ppqq, using my previous example of a range of 1-8. modulo seems to work perfectly for counting up, but when I count down I get some strangeness. crossing 0 seems to jump to 3 instead of the expected 8.

Mod of negative is confusing, search it if you like confusion.

Id just use a while loop

Thumbtyping …

while x > 8 do x = x - 8 end
while x < 1 do x = x + 8 end

bless this perfectly valid use of a norns.


just add the range when you’re counting down before you apply modulo. also you have to add a -1 correction and then add 1 after to shift it to 1…8 range instead of 0…7 (lua being 1-based is really… inconvenient):

increment: x = (x + 1 - 1) % 8 + 1
decrement: x = (x + 8 - 1 - 1) % 8 + 1

i’m showing full calculation to make it clear what’s happening but you can of course collapse it to:

x = x % 8 + 1
x = (x + 6) % 8 + 1


That worked like a charm! Thanks everyone!

1 Like

Not really understanding some nut-and-bolts stuff… not sure if it’s lua or just the way the scripting engine works here.

FWIW (as background) - I can muddle my way thru scripting with PHP, python, etc and coding basic stuff with Arduino

Where do functions like key(n,z) or enc(n,d) or something like gridkey(x,y,s) get executed or called? There’s not like a main loop here like with arduino, is there?

1 Like

I’m trying to wrap my head around the metro class. Any examples of executing a function using metro?emphasized text

matron does indeed have a main loop which is consuming events that come in via timers and other low level glue for monome devices, midi, hid devices, etc. The C level event handlers in turn execute callbacks defined in Lua.

Main loop:

…and an example of one of the many functions which handles a C-level event by calling a function in Lua:


As far as I understand, the script itself is the main loop. I think that function init() can start a loop if need be.

The encoder and key functions are always running as far as I know. I think osc.event functions can be placed anywhere. Or maybe within the init() function.

1 Like

soon after I posted above - I found the “norns” section in the docs - which is where those globals where hiding.

I’ve got osc events coming in ok - I just need to figure out how to make those be interpreted in the same way that grid events are (to emulate grid from TouchOSC).

to close the loop here (into the lua domain)

the above calls the lua function


which usually is found in the ‘appropriate’ lua class e.g. grid.lua
(its also seems to be in norns.lua, but im not sure why)