Closed markwheeler closed 5 years ago
@markwheeler after pondering on this for some time, i think that managing callbacks lies out of scope for connect()
and could be done explicitly instead, e.g:
function grid_handler() ... end
grid1 = grid.connect(1)
grid1.key = grid_handler
...
grid2 = grid.connect(2)
grid2.key = grid_handler
grid1.key = nil
or even connect to all 4 ports during initialization and manage callbacks internally if required.
otherwise, it makes it difficult for scripts, that want simultaneous access to multiple devices of the same class, to keep existing callbacks when we call connect()
.
OK cool. So for switching grids am I correct in that this would be the way to do it without creating new grid tables?
-- Connect
my_grid = grid.connect(1)
my_grid.key = grid_handler
...
-- Reconnect
my_grid.key = nil
my_grid = grid.connect(2)
my_grid.key = grid_handler
Yes, or keep the devices in a table that you create during initialization.
Cool thanks!
Use case: Allow the user to switch MIDI or grid input from a script param. In norns v1 there was a
reconnect()
function.Currently in 2.0, calling
midi.connect(value)
keeps previous callbacks. Ideally there'd be a simple way to switch device and have the existing callback function start receiving from the new device while the old one is cleaned up.Unsure if this applies to arc or HID also.