monome / norns

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

Add rows and cols to grid.vport #552

Closed okyeron closed 6 years ago

okyeron commented 6 years ago

Suggestion - modify grid.lua to store the number of rows and cols available in the vport object.

The following seems to work (on a quick test)

Grid.vport = {}
for i=1,4 do
  Grid.vport[i] = {
    name = "none",
    callbacks = {},
    index = 0,
    led = function() end,
    all = function() end,
    refresh = function() end,
    cols = 0,
    rows = 0,
    attached = false
  }
end

and

 function Grid.new(id, serial, name, dev)
  local g = setmetatable({}, Grid)
  g.id = id
  g.serial = serial
  name = name .. " " .. serial
  while tab.contains(Grid.list,name) do
    name = name .. "+"
  end
  g.name = name
  g.dev = dev -- opaque pointer
  g.key = nil -- key event callback
  g.remove = nil -- device unplug callback
  g.rows = grid_rows(dev)
  g.cols = grid_cols(dev)
  g.ports = {} -- list of virtual ports this device is attached to

  -- autofill next postiion
  local connected = {}
  for i=1,4 do 
    table.insert(connected, Grid.vport[i].name) 
    table.insert(connected, Grid.vport[i].cols) 
    table.insert(connected, Grid.vport[i].rows) 
  end
  if not tab.contains(connected, name) then
    for i=1,4 do
      if Grid.vport[i].name == "none" then
        Grid.vport[i].name = name
        Grid.vport[i].cols = grid_cols(dev)
        Grid.vport[i].rows = grid_rows(dev)
        break
      end
    end
  end

  return g
end
tehn commented 6 years ago

want to submit a PR? this idea seems good

okyeron commented 6 years ago

https://github.com/monome/norns/pull/553