halvves / webmonome

we've moved to sourcehut! this is just a mirror of: https://sr.ht/~merl/webmonome/
https://www.npmjs.com/package/webmonome/v/alpha
MIT License
11 stars 1 forks source link

Higher level LED methods? #6

Open domchristie opened 2 years ago

domchristie commented 2 years ago

The monome protocol specifies that messages for LED rows, columns, and maps target a "quad", i.e. an 8x8 segment with an x/y offset. The webmonome API reflects this, but I'm wondering if we could add some higher level methods to make it easier to set LED states in one call.

For example, in mlr, a single LED tracks the sample's play position. In JavaScript we might track this with an array of 16 items:

let row = [0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0]

To convey is to a device, we have to split the array into two chunks of 8, then call gridLedRow twice with offsets:

let chunks = chunk(row, 8) // [[0,0,0,0,0,0,0,0],[0,0,0,0,0,1,0,0]]
chunks.forEach((chunk, i) => monome.gridLedRow(i * 8, rowNumber, chunk))

I'm wondering if a nicer API might be:

monome.gridLedRow(rowNumber, row)

(and perhaps rename the current methods to gridLedRowQuad, or something?

domchristie commented 2 years ago

(and perhaps rename the current methods to gridLedRowQuad, or something?

or rather just allow both signature types:

monome.gridLedRow(xOffset, yOffset, states) // up to 8 leds
monome.gridLedRow(yOffset, states) // up to 16 leds
halvves commented 2 years ago

Sorry I never responded to this issue. Part of me me really wants to keep webmonome simple and ~1:1 with monome protocol, but I definitely like the idea of maybe making row/col/map more flexible. We can maybe keep the api as is, and make some assumptions if the "states" array is different lengths: 8 vs 16 etc. If the states array is longer we can just assume the the intent is to extend further down/right. gridLedMap might be a bit trickier, maybe optional dataWidth/dataHeight params and otherwise assume extending the map in width?