Norns: tutorial

@sno Fwiw I have a simple midi clock example using 2.0 syntax here

But many of the older scripts (from Norns 1.x) use the beatclock library which handles clock a bit more abstractly.

2 Likes

thanks for sharing @okyeron! I’m very new to this kind of language so the tutorials help a lot :slight_smile:

1 Like

shouldn’t this be 1.0 / 15

for 15 fps? (since metro time is in seconds, as an interval?)

shouldn’t this be 1.0 / 15

Yes! Absolutely, I’ve corrected the sources and thread.

@tehn Do you know if grid.attached() works right now? I can’t seem to be able to check if the device is connected without an error.

i’ll check that. it should and if it doesn’t it’ll be an easy fix.

quick comment on:

the language is a little misleading as the code already lives on the norns, hence isn’t “send to it”, rather the play button is just a command shortcut for script.run(...) (that’s not the exact command) to just tell the menu system to execute the script that maiden is looking at. maybe just “run the script” instead of “send it to the device” ?

At the moment, grid.attached() throws:

9_grid.lua:24: attempt to call a nil value (field 'attached')

Which I would like to communicate wether the grid is connected or not, to the user.

I will update with run the script across the tutorial.

i don’t know of this method?

core lib just fires remove callback, which the script can use

so you could add this

local g = grid.connect()
g.attached = true
g.remove = function()
  g.attached = false
end

(caveat: haven’t tested lately, don’t have grid ATM)

It’s here and there across the examples and docs. I think it really should exist as part of the library if it has been removed since the studies were made.

i don’t see it? in the linked study i do see the method for midi devices. (only.)

that said, i don’t see the method in the midi module either. so yea… agreed.

1 Like

For some reason I expected this to exist within grid and arc, as well as with keys, I would love to have a callback on changed too. Like if you connect/disconnect a grid, I would love to catch that event, and update the interface.

i just showed that above (for a specific device)

you can also catch the global callback when any grid is added / removed:

grid.add = function(g) ... end
grid.remove = function(g) ... end

(g argument is an instance of Grid.)

you’ll notice this pattern in a few places:

grid module has static methods.add, .remove, these are designed to be overridden by scripts.

norns.grid has the “system-level” callbacks - don’t touch these.

Right, I understand :slight_smile: I even saw them in the docs, but the add and remove names threw me off, I was expecting either on_remove, or removed — And, on_connect, or connected

1 Like

Note - attached used to exist in 1.0

see this PR

I threw up a Github issue about it. Not sure if it got removed as part of the vport updates, or for some other reason.

1 Like

yeah sorry - i dunno, have never touched the midi or vport stuff

i agree, those would be clearer names. i’ve no objection to changing them and i’m not aware of any scripts using this feature at the moment

1 Like

Since I don’t think the on_ naming convention is very common in the monome ecosystem, I would suggest:

Wishlist

  • .attached(), returns true or false if it’s added. This should be is_attached really.
  • .removed(), fires when removed.
  • .added(), fires when added.

Current Issues

  • When disconnecting the grid, the .remove callback is fired twice.
  • .add callback is never fired if the grid is already connected. Is there a way to tell if a grid is connected on the start of an application? .connect() doesn’t throw any error if there’s no grid to connect to.

ah, i remember something like that. thought it was fixed? can’t find the GH issue.

i think it should return nil?

Even tho the grid is not connected, for .connect(), I get:

all	function: 0x31da28
name	monome 128 m1000454
refresh	function: 0x328018
add	function: 0x354590
rotation	function: 0x325eb0
cols	16
rows	8
remove	function: 0x3c2d48
led	function: 0x346688

ok, mea culpa, thanks for investigating.

i shouldn’t make any more statments without being able to verify them - which i can’t do, i’m travelling without a grid for several weeks.

1 Like

That’s alright :slight_smile: Thank you so much for your time and energy to help me. I think I can find something that works somewhat-reliably with what you’ve showed me, and I will update as new tools become available.

1 Like

You can check my_grid.device (after connecting) to see if a grid is still there.

2 Likes