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.
thanks! I realized now that this was mentioned in the first study!!
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.
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):
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.
…and an example of one of the many functions which handles a C-level event by calling a function in Lua:
OK - I got myself working with midi.send(dev,data) I had to define a variable for the device in midi.add(dev) and include that in my midi.send (the nil value was because I wasn’t picking up a value for dev)
Question: Where do these “status” codes for midi events come from?
norns.midi.event = function(id, data)
status = data
data1 = data
data2 = data
if status == 144 then
elseif status == 128 then
The earthsea script (snippet above) has a note-off code of 128, but my midi controller sends note-off as 144 with velocity 0 (same code as note-on)
Just a quick word of warning. If anyone comes across scripts in dust which assign values to anything in the norns module (like this snippet does) please flag it - as it is most likely the wrong way to do something. The norns module contains the low level glue where C-level hardware drivers are exposed to lua - changing things in the norns module will likely cause other scripts to break.
In the case of midi the proper way to define event handlers is shown in earthsea, specifically:
…looking at the dust repo I see that the hello_gong script is still using the (now internal) midi api (which we need to fix).