monome / norns

norns is many sound instruments.
http://monome.org
GNU General Public License v3.0
631 stars 145 forks source link

What happened to attached for devices? #843

Closed okyeron closed 5 years ago

okyeron commented 5 years ago

Some time back in 1.0 grid and midi devices could be checked if attached - Study 4 specifically uses this.

Now I'm searching all the code and can't find it at all.

What happened here? Did this get tossed for some other better way to determine if a device is connected?

artfwo commented 5 years ago

Yes, I think I removed that property when cleaning up vport library, you can use vport.device ~= nil instead.

neauoire commented 5 years ago

Could I ask for it to be added back? Not a big fan of vport.device ~= nil as replacement.

artfwo commented 5 years ago

That would be a flag which does nothing but being a duplicate of vport.device ~= nil, a potential source of problems if we forget to update it. You can use vport.device as a shortcut, which will evaluate to true, if the device is attached.

neauoire commented 5 years ago

Maybe I'm not exactly sure how to use it then, first time I hear of vport. I just want to check if the grid is connected to the norns. It's currently connected:

g = grid.connect()
g.key = on_grid_key
g.add = on_grid_add
g.remove = on_grid_remove

print(vport) # nil
print(g.vport) # nil
print(grid.vport) # nil
print(norns.vport) # nil
artfwo commented 5 years ago

Right, grid.connect(x) returns a vport instance, see https://github.com/monome/norns/blob/master/lua/core/grid.lua#L107

Currently scripts only deal with vports (assigned in devices menu), and we connect to them using grid.connect. A vport instance keeps a reference to the physical device, in your example above that would be g.device.

Hope this helps!

neauoire commented 5 years ago

That's actually excellent, sorry for my confusion earlier.