Norns: scripting



cheeky comment: bring your norns to work!

non-cheekily, I’d appreciate this being somewhere online as well. Though I’ve definitely made a recent habit of tucking norns in my bag and booting it up in free moments :sunglasses:

edit: perhaps this is already somewhere accessible in one of the github repos? but I’ve not found it yet

@tehn thanks for the response, I got it working using the metro method, but the util.time() seems like a really handy thing to check out!


getting the docs live online somewhere is on my list, thanks for the reminder!


You could actually download the norns master to your computer and read the docs offline, I believe.


How to recognize key up events on norns?

If I want to trigger an action when key 3 on norns is released, I think this

if n==3 and z==1 then
   if n==3 and z==0 then ACTION end

is one way to find out if key 3 goes up again. I wonder if there is an alternative way to do this, like a dedicated “key 3 up” event? Thanks in advance!


when z=0 the key is up


I just do

 if n == 3 and z == 0 then


controlspec questions:

  1. Is there a way to use a controlspec outside the confines of a param setup? I’d like to set up a controlspec for use against a standard variable, and do the equivalent of a params:delta call. You know, convenience…

  2. What is the syntax for creating a controlspec that has enumerated values: “fwd”, “bwd”, “updn”? I thought I saw it somewhere, then I didn’t… Or is it just that params can have options, but not controls (where I might just have to use indices)?

Trying to wrap my head around this - but having a ton of fun doing it!



yeah, something like this should work (untested)…

local ControlSpec = require 'controlspec'
local Control = require 'params/control'

local mycontrol ="mycontrolname",, 20000, 'exp', 0, 10000, "Hz"))

Option may be a better alternative if you need to use delta() for enumerated values.

local Option = require 'params/option'

local myoption ="myoptionname", {"fwd", "bwd", "updn"})

(again, untested as I’m not at my device, but something like above should do)

(also FYI note that i tend to Capitalize OOP classes in Lua such as ControlSpec, Control and Option. this is not required, and you will see in many scripts that classes are not capitalized)


@jah - this was some brilliant help, and also pointed me to the ol’ repo, were digging into params/* provided a lot of fruit!




And my little norns piece (#1!)

You can get it here:


Need more help now:

I’m trying to implement a more robust MIDI implementation, but I’m falling off track with the Midi.add and Midi.remove functions. I see in midi.lua that, when a device is added, it checks to see if Midi.add exists; if so, it calls it. In my code, I can override this as so:

local Midi = require 'midi'

Midi.add = function(dev)
  print("ddg adding " ..

but if I try to override the remove function, like this:

Midi.remove = function(dev)
  print("ddg removing " ..

I get an error:

ddg removing mio
lua: /home/we/dust/scripts/ddg/midi_override.lua:16: attempt to index a nil value (local 'dev')
stack traceback:
	/home/we/dust/scripts/ddg/midi_override.lua:16: in function 'midi.remove'
	/home/we/norns/lua/midi.lua:68: in function </home/we/norns/lua/midi.lua:62>

This is a little weird, because it seems to actually work (it says the name of the thing it is removing, using my unique ‘ddg’ syntax…), but then croaks on that same line. This error implies that it is calling the device-specific remove() - which has no arguments - rather than the class-level remove() - which provides the device. How do I override the class function instead?

Any ideas would be greatly appreciated!



What does work is to do this:

function Midi.remove(dev)
  if (dev) then
    print("ddg removing " ..

But I’m not sure why this remove is being called for both the class-level and device-level remove function. Is it because, in the function, the d.remove should actually be set to an empty function so it doesn’t ripple down to the class?



apologies, you’re diving into this just before we’re about to release a big update, followed by a midi/grid study.

see here for the major details:


Ah, a great read. :popcorn::cup_with_straw::chocolate_bar:

Looking forward to it!



How could I approach making a single pixel, circle around a given point at x radius n times per second? Sort of lacking in my trigonemtric functions knowledge.

EDIT: currently on the right track… Will update when I find success.

EDIT#2: success

have a look

function init()
r = 10
a = 2
x = 64 + (r * math.cos(a))
y = 32 + (r * math.sin(a))

function enc(n,d)
  if n == 3 then
    r = r + d/2
    x = 64 + (r * math.cos(a))
    y = 32 + (r * math.sin(a))
  if n == 2 then
    a = a + d/36
    x = 64 + (r * math.cos(a))
    y = 32 + (r * math.sin(a))

function redraw()

Now I can get started on a patch I’ve been thinking about for a while!


When I am away from norns (God forbid!), what is a recommended editor to continue working on Lua scripts for norns on macOS?


Atom is pretty flexible and looks nice.


I personally like Sublime Text, but nearly all decent text editors will be fine. Atom is a good and free choice.

edit: Plus, they have their own Teletype - what’s not to like? :smiley:


BBEdit is fantastic. It’s commercial software, but has a free/lite mode after a 30-day evaluation.


I use Atom and love it - it can be as non-invasive as you need!