(grid) Code examples

I’m looking for code examples for handling multi-page sequences (longer than 16 steps). Ex: ala Octatrack’s 64 steps being accessible thru 4 pages.

Any language is OK, except Max (haven’t gone down that hole yet). Have been through tehn’s Supercollider example and have looked through some of the norns scripts.

Specifically, I’m looking for how one would handle the multiple pages.

Thanks.

if you’re scripting on norns, mlr has a reasonable approach to multi-page. but you’ll have to dig through a lot of code to find the relevant bits…

1 Like

Thanks. I don’t mind digging.

1 Like

that said, i’d like to assemble a next-level grid study that shows multi-page interaction, along with some other tricks like alt-keys/multi-touch selection, animation, etc. if there are specific requests about specific fancy grid interaction, let me know

7 Likes

I don’t feel you need to get fancy, brian. Things like:

  • handling more than a 16 step, 8 pitch sequence
  • setting up a page for ‘controls’, ie: lfo, synth param settings, and others.

Just a ‘next level’ study.

btw: I looked thru mlr code and found the functions for handling pages. Now just need to backtrack through. It would help if I had a single clue as what mlr does. (It’s not you, it’s me.)

Hi, any chance that there will be examples in Javascript as well?

1 Like

We definitly need fancy! The only thing to justify the price on this thing IS with fancy. I want to see parameters for fx: envelopes, modulations, behaviors, and directonal flow patterning. You know, genuine flavor worth our thousand muffuggun dollars!

1 Like

Any update on this? I’m happy to help out, I’m not great with code but design interfaces for a living.

Hi,

can anyone point me to a code example of how to use a push button as a toggle? Though I need to write it in Ruby, Javascript would be fine.

After some googling I found an example for Arduino but I was not yet able to transfer this to a scenario involving a (Monome) grid. So I do hope with a working example from some grid application I can go on.

PS.: I would be very interested in the announced advanced grid code examples. Any news about that?

In pseudocode,
init toggle_state = 0
//detect key press on top left pad
if x == 0 and y == 0 and s==1 then
if toggle_state == 0 then
toggle_state = 1
do things like lighting led(0,0)
else
toggle_state = 0
do things like turning led(0,0) off
endif
endif

2 Likes

A neat way to toggle a variable between 0 and 1 is

x = 1 - x
4 Likes

Hi, thanks for that. Not to difficult :wink:

My confusion came from the fact that right now I am working with a virtual grid made with Open Stage Control (so long as I don’t own a real one). The default push buttons also return a release event (well, that’s what a push button does, right) and your example is based on just one push event. Am I right? (I can simulate that with Open Stage Control with the option ‘no release’)

Also,

x = not x

Or does Lua not treat 1==true?

in lua logic operations return true or false

so

not x

(edit below for correctness! thanks @zebra)

will return false for anything except when x equals false or nil

(though this is a nice trick in c/etc)

yes, in my example the toggle “happens” when a button is pushed.
If you want it to happen when a button is released, test for s == 0.
The grid sends the coordinates of buttons with a 1 when they are pushed, and with a 0 when they are released. This page documents the OSC messages that can be used to communicate with the grid via serialosc.

1 Like

[a pedant approaches]

you mean: not x will return false except when x equals false or nil.

IOW: in lua, all values that are not explicitly false or nil evaluate to true in conditionals and boolean operations. this includes 0, which is a huge gotcha.

Lua 5.3.3  Copyright (C) 1994-2016 Lua.org, PUC-Rio
> function tog() x = not x; print(x) end
> x = true
> tog()
false       ---- cool
> tog() 
true        ---- cool
> x = 1
> tog()
false       --- ok...
> tog()
true
> x = 0
> tog()
false      --- wtf!!
> if 0 then print('wtf') else print('cool') end
wtf

anyways, the moral is: in lua, don’t do logic on numbers (meaningless results) or arithmetic on booleans (throws error.) but you can use the conjunction operator and as a ternary operator:

x = (x>0) and 0 or 1

toggles x between 0 and 1. (but will bork if x is a boolean.)

2 Likes

Yeah, I had a suspicion that Lua was like early JavaScript.
I did some Lua on ESP8266 a few years back, and remember distinctly not enjoying it.

Off topic, but I’d be quite interested if there are any archived discussions around the choice of Lua as default language for Norns. I searched a while back, but didn’t find anything, so any pointers would be appreciated.

thank you for fixing my typos and clarifying :slight_smile:

cond and x or y

works as a ternary if except when the condition is true and x is false or nil, in which case it returns y. i’m still learning lua and this was one of the things that tripped me. for a language that seems to be designed for improved readability it’s strange they wouldn’t just include a proper ternary if op.

1 Like

Hi,

after finally having succeeded in getting my Adafruit Unztrument to work with node-serialoscd I can now dive into programming for the grid. (I plan to buy a original Monome soon but need to lay aside some more money). I am working with Sonic Pi so my programming language will Ruby for the moment. Being a less experienced programmer I did some exercises with Open Stage Control as controller (e. g. lmq where not only the name is somehow inspired by mlr and a Live Looper application). My plan is to develop my own set of grid applications and use these in combination with live coding - even if they are not as sophisticated as already existing applications (like those running on norns e. g.) because I know that it is a rewarding process not only to make the music but also (at least partly) build your own instrument.

As I would like to primarily use the Monome as controller/squencer I am looking for general concepts, ressources and examples for (more or less advanced) grid programming (which I will have to translate to Ruby as far as possible). This posting kind of provides a starter for what I am interested in.

As I am a beginner, it is not that easy to be specific (as the specific problems come with more knowledge and experience) but I will give an example of what I am currently coping with:

From what I have already done and tested I conclude that using the bitmask operations (map/row/col) is neccessary to achieve a decent performance; is that correct? Are there any systematic approaches to that?

To make it more tangible: I e. g. want to implement a volume control for my Live Looper application using 7 leds to mimic a (low resolution) volume switch with 7 steps (let’s say x = 1 and y = 1 to 7); if I press 1/4 I want 1/1, 1/1, 1/2, 1/3 and 1/4 to light up as well as translate the pressed led coordinates/number to a certain volumee and send the appropriate osc message. I will have to group these leds, make them into toggles and implement that while toggling one led the group members will be light up in the correct way. From what I have seen there are already solutions to do such things. Are these documented somewhere? Are there ressources (apart from the grid studies I have already studied as far as they apply to what I want to do) I should have a look at?

There are of course quite a few other things where I have a rough idea how to do that, but I am guessing others have already done this and I could learn from it amongst these e. g. paging (ctrl and alt buttons to switch the whole grid to functionally separated layers).

Thanks a lot if you have any hints or ideas for me how to go on (in a more systematic and not so much only try-and-error-way).