Hi @artfwo
am making progress - have got a virtual grid talking to two physical grids and almost running the hello app.
The guts of the connection is done in the SpanningSerialOsc class like this:
def on_device_added(self, id, type, port):
if id == "m40h-001":
asyncio.async(self.connect_physical_grid(1, port))
if id == "m40h-002":
asyncio.async(self.connect_physical_grid(2, port))
async def connect_physical_grid(self, grid_reference, grid_port):
transport, physical_grid = await self.loop.create_datagram_endpoint(monome.Grid, local_addr=('127.0.0.1', 0), remote_addr=('127.0.0.1', grid_port))
if grid_reference == 1:
self.physical_grid1 = physical_grid
self.physical_grid1.connect()
if grid_reference == 2:
self.physical_grid2 = physical_grid
self.physical_grid2.connect()
self.grid = VirtualGridWrapper(self.physical_grid1, self.physical_grid2)
self.autoconnect_app.attach(self.grid)
So far I can correctly address leds with led_set from 0 to 16. The VirtualGridWrapper led_set method handles the translation of position to the underlying physical grid (if x < 8, send it to grid1, else send it to grid2).
One challenge is correctly apply an offset to an incoming grid_key message, as with the code above I don’t know which grid the key press is coming from.
I’ve kludged my way around this by creating another version of monome.Grid called OffsetGrid which modifies the __on_grid_key message to apply the offset. All the other code is the same. This way the correct grid_key coordinate gets passed up to the VirtualGrid without any other wrangling at that level.
Copying the whole Grid class seems like a terrible hack right now, as all I want to do is override the __on_grid_key handler, but I don’t really know how to register that correctly. I got a bunch of errors when I tried to have a subclass with constructor which registered all the parent handler except for the __on_grid_key method, so I ended up just copying the whole grid class, which does work.
If you have any suggestions for how to make this more elegant, I’d be interested. Perhaps I should just get the code for the spanned Hello example as tidy and possible and then send it across - might be easier than discussing here…
In any case, thanks again - overall this is looking much cleaner than the previous spanning solution I had pulled together. I’m hoping that this means I can even make use of things like Pages on top of the spanned Virtual Grid, which may make my sequencer app much easier to manage.
But for now, one step at a time 