├── .gitattributes ├── README.md ├── grid128_arc4.touchosc ├── lib ├── oscarc.lua └── oscgrid.lua ├── load.lua ├── load_arc.lua ├── load_grid.lua └── unload.lua /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # oscgrid 2 | touchosc emulation for monome grid 3 | 4 | ## This is super hacky - use at your own risk 5 | 6 | Edit the IP address of your touchosc device at the top of the load script 7 | 8 | Remember to run the unload script after you're done using 9 | 10 | ## TouchOSC 11 | 12 | see https://hexler.net/software/touchosc for information about using TouchOSC. 13 | 14 | Full TouchOSC documentation is here: https://hexler.net/docs/touchosc 15 | 16 | You will need to be able to load a template 17 | and configure IP addresses for an OSC connection 18 | -------------------------------------------------------------------------------- /grid128_arc4.touchosc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okyeron/oscgrid/7bf831bfee1e4e2a8c1859e9aa809e03fcdea4d6/grid128_arc4.touchosc -------------------------------------------------------------------------------- /lib/oscarc.lua: -------------------------------------------------------------------------------- 1 | local vport = require 'vport' 2 | 3 | local oscarc = {} 4 | oscarc.__index = oscarc 5 | 6 | local oscsourceip = "10.0.1.11" 7 | local oscsourceport = 9000 8 | 9 | oscarc.devices = {} 10 | oscarc.vports = {} 11 | 12 | oscarc.oscdest = {oscsourceip,oscsourceport} 13 | 14 | oscarc.arcLEDarray = {} -- create the matrix 15 | for i=1,4 do -- ring 16 | oscarc.arcLEDarray[i] = {} -- create a new row 17 | for j=1,64 do -- leds 18 | oscarc.arcLEDarray[i][j] = 0 19 | end 20 | end 21 | 22 | 23 | for i=1,4 do 24 | oscarc.vports[i] = { 25 | name = "none", 26 | device = nil, 27 | 28 | delta = nil, 29 | key = nil, 30 | 31 | led = vport.wrap_method('led'), 32 | all = vport.wrap_method('all'), 33 | refresh = vport.wrap_method('refresh'), 34 | segment = vport.wrap_method('segment'), 35 | } 36 | end 37 | 38 | 39 | function oscarc.new(id, serial, name) 40 | local device = setmetatable({}, oscarc) 41 | 42 | device.id = id 43 | device.serial = serial 44 | device.name = name.." "..serial 45 | device.dev = {} 46 | device.delta = nil -- delta event callback 47 | device.key = nil -- key event callback 48 | device.remove = nil -- device unpludevice callback 49 | device.port = nil 50 | 51 | -- autofill next postiion 52 | local connected = {} 53 | for i=1,4 do 54 | table.insert(connected, arc.vports[i].name) 55 | end 56 | if not tab.contains(connected, device.name) then 57 | for i=1,4 do 58 | if arc.vports[i].name == "none" then 59 | arc.vports[i].name = device.name 60 | break 61 | end 62 | end 63 | end 64 | return device 65 | end 66 | 67 | --- set state of single LED on this arc device. 68 | -- @tparam integer ring : ring index (1-based!) 69 | -- @tparam integer x : led index (1-based!) 70 | -- @tparam integer val : LED brightness in [0, 15] 71 | function oscarc:led(ring, x, val) 72 | oscarc.arcLEDarray[ring][x] = util.clamp(val,0,15) 73 | --osc.send(oscarc.oscdest, "/ring/led ".. ring .. " " .. x, {val}) 74 | --arc_set_led(self.dev, ring, x, val) 75 | end 76 | 77 | --- set state of all LEDs on this arc device. 78 | -- @tparam integer val : LED brightness in [0, 15] 79 | function oscarc:all(val) 80 | for i = 1,4 do -- ring 81 | for j = 1,64 do -- leds 82 | oscarc.arcLEDarray[i][j] = val 83 | --osc.send(oscarc.oscdest, "/ring/led ".. i .. " " .. j, {val}) 84 | end 85 | end 86 | --arc_all_led(self.dev, val) 87 | end 88 | 89 | --- update any dirty quads on this arc device. 90 | function oscarc:refresh() 91 | for i = 1,4 do -- ring 92 | for j = 1,64 do -- leds 93 | osc.send(oscarc.oscdest, "/ring/led ".. i .. " " .. j, {oscarc.arcLEDarray[i][j]}) 94 | end 95 | end 96 | 97 | --monome_refresh(self.dev) 98 | end 99 | 100 | --- static callback when any arc device is added; 101 | -- user scripts can redefine 102 | -- @static 103 | -- @param dev : an arc table 104 | function oscarc.add(dev) 105 | print("arc added:", dev.id, dev.name, dev.serial) 106 | end 107 | 108 | --- static callback when any arc device is removed; 109 | -- user scripts can redefine 110 | -- @static 111 | -- @param dev : an arc table 112 | function oscarc.remove(dev) end 113 | 114 | 115 | --- create an anti-aliased point to point arc 116 | -- segment/range on a sepcific LED ring. 117 | -- each point can be a decimal, LEDs will fade for in between values. 118 | -- @tparam integer ring : ring index (1-based) 119 | -- @tparam number from : from angle in radians 120 | -- @tparam number to : to angle in radians 121 | -- @tparam integer level : LED brightness in [0, 15] 122 | function oscarc:segment(ring, from, to, level) 123 | local tau = math.pi * 2 124 | 125 | local function overlap(a, b, c, d) 126 | if a > b then 127 | return overlap(a, tau, c, d) + overlap(0, b, c, d) 128 | elseif c > d then 129 | return overlap(a, b, c, tau) + overlap(a, b, 0, d) 130 | else 131 | return math.max(0, math.min(b, d) - math.max(a, c)) 132 | end 133 | end 134 | 135 | local function overlap_segments(a, b, c, d) 136 | a = a % tau 137 | b = b % tau 138 | c = c % tau 139 | d = d % tau 140 | 141 | return overlap(a, b, c, d) 142 | end 143 | 144 | local m = {} 145 | local sl = tau / 64 146 | 147 | for i=1, 64 do 148 | local sa = tau / 64 * (i - 1) 149 | local sb = tau / 64 * i 150 | 151 | local o = overlap_segments(from, to, sa, sb) 152 | m[i] = util.round(o / sl * level) 153 | self:led(ring, i, m[i]) 154 | end 155 | end 156 | 157 | 158 | 159 | local t = 0 160 | local dt = 1 161 | local newdelta = 0 162 | 163 | oscarc.osc_in = function(path, args, from, ar_id) 164 | local k 165 | local pathxy = {} 166 | for k in string.gmatch(path, "%S+") do 167 | table.insert(pathxy,k) 168 | end 169 | --print (path) 170 | oscpath = pathxy[1] 171 | if oscpath == "/arc/enc" then 172 | n = math.floor(pathxy[2]) 173 | delta = math.floor(args[1]) 174 | 175 | -- collect fast deltas for quick spins 176 | local t1 = util.time() 177 | dt = t1 - t 178 | t = t1 179 | newdelta = newdelta + delta 180 | if dt > .025 then 181 | oscarc.arc.delta(ar_id, n, newdelta) 182 | --print (newdelta) 183 | newdelta = 0 184 | end 185 | --oscarc.draw(n .. ' ' .. delta) 186 | end 187 | end 188 | 189 | oscarc.arc = {} 190 | 191 | oscarc.arc.delta = function(id, n, delta) 192 | local device = arc.devices[id] 193 | 194 | if device ~= nil then 195 | if device.delta then 196 | device.delta(n, delta) 197 | _norns.arc.delta(id, n, delta) 198 | end 199 | 200 | if device.port then 201 | if oscarc.vports[device.port].delta then 202 | oscarc.vports[device.port].delta(n, delta) 203 | end 204 | end 205 | else 206 | error('no entry for arc '..id) 207 | end 208 | end 209 | 210 | 211 | oscarc.arc.key = function(id, n, s) 212 | local device = Arc.devices[id] 213 | 214 | if device ~= nil then 215 | if device.key then 216 | device.key(n, s) 217 | _norns.arc.key(id, n, s) 218 | end 219 | 220 | if device.port then 221 | if Arc.vports[device.port].key then 222 | Arc.vports[device.port].key(n, s) 223 | end 224 | end 225 | else 226 | error('no entry for arc '..id) 227 | end 228 | end 229 | 230 | 231 | function oscarc.connect(n) 232 | local n = n or 1 233 | return arc.vports[n] 234 | 235 | end 236 | --- clear handlers 237 | function oscarc.cleanup() 238 | for i=1,4 do 239 | arc.vports[i].delta = nil 240 | arc.vports[i].key = nil 241 | end 242 | 243 | for _, dev in pairs(arc.devices) do 244 | dev:all(0) 245 | dev:refresh() 246 | dev.delta = nil 247 | dev.key = nil 248 | end 249 | end 250 | 251 | function oscarc.update_devices() 252 | -- reset vports for existing devices 253 | --oscarc.list = {} 254 | for _, device in pairs(arc.devices) do 255 | device.port = nil 256 | end 257 | 258 | -- connect available devices to vports 259 | for i=1,4 do 260 | arc.vports[i].device = nil 261 | 262 | for _, device in pairs(arc.devices) do 263 | if device.name == arc.vports[i].name then 264 | arc.vports[i].device = device 265 | device.port = i 266 | end 267 | end 268 | end 269 | end 270 | 271 | 272 | -- arc add 273 | oscarc.arc.add = function(id, serial, name) 274 | local g = oscarc.new(id, serial, name) 275 | arc.devices[id] = g 276 | oscarc.update_devices() 277 | if oscarc.add ~= nil then oscarc.add(g) end 278 | end 279 | 280 | oscarc.arc.remove = function(id) 281 | if arc.devices[id] then 282 | if arc.remove ~= nil then 283 | arc.remove(arc.devices[id]) 284 | end 285 | if arc.devices[id].remove then 286 | arc.devices[id].remove() 287 | end 288 | end 289 | arc.devices[id] = nil 290 | arc.update_devices() 291 | end 292 | 293 | 294 | oscarc.draw = function(text) 295 | screen.clear() 296 | screen.move (10,10) 297 | screen.text(text) 298 | screen.stroke() 299 | screen.update() 300 | end 301 | 302 | 303 | return oscarc -------------------------------------------------------------------------------- /lib/oscgrid.lua: -------------------------------------------------------------------------------- 1 | local vport = require 'vport' 2 | 3 | local oscgrid = {} 4 | oscgrid.__index = oscgrid 5 | 6 | local oscsourceip = "10.0.1.11" 7 | local oscsourceport = 9000 8 | 9 | oscgrid.LEDarray = {} -- create the matrix 10 | for i=1,16 do 11 | oscgrid.LEDarray[i] = {} -- create a new row 12 | for j=1,8 do 13 | oscgrid.LEDarray[i][j] = 0 14 | end 15 | end 16 | --tab.print (oscgrid.LEDarray) 17 | --print ('ledarray 16 16', oscgrid.LEDarray[16][16]) 18 | 19 | 20 | oscgrid.devices = {} 21 | oscgrid.vports = {} 22 | oscgrid.gridkey = {} 23 | 24 | oscgrid.oscdest = {oscsourceip,oscsourceport} 25 | 26 | for i=1,4 do 27 | oscgrid.vports[i] = { 28 | name = "none", 29 | device = nil, 30 | 31 | key = nil, 32 | 33 | led = vport.wrap_method('led'), 34 | all = vport.wrap_method('all'), 35 | refresh = vport.wrap_method('refresh'), 36 | rotation = vport.wrap_method('rotation'), 37 | 38 | cols = 0, 39 | rows = 0, 40 | } 41 | end 42 | 43 | function oscgrid.new(id, serial, name, dev) 44 | local g = setmetatable({}, oscgrid) 45 | 46 | g.id = id 47 | g.serial = serial 48 | g.name = name.." "..serial 49 | g.dev = dev 50 | g.key = nil -- key event callback 51 | g.remove = nil -- device unplug callback 52 | g.rows = 8 53 | g.cols = 16 54 | g.port = nil 55 | 56 | 57 | -- autofill next postiion 58 | local connected = {} 59 | for i=1,4 do 60 | table.insert(connected, grid.vports[i].name) 61 | end 62 | if not tab.contains(connected, g.name) then 63 | for i=1,4 do 64 | if grid.vports[i].name == "none" then 65 | grid.vports[i].name = g.name 66 | --print (g.name, i); 67 | --tab.print(oscgrid.vports[i]) 68 | break 69 | end 70 | end 71 | end 72 | return g 73 | end 74 | 75 | -- set grid rotation. 76 | -- @tparam integer val : rotation 0,90,180,270 as [0, 3] 77 | function oscgrid:rotation(val) 78 | --_norns.grid_set_rotation(self.dev, val) 79 | end 80 | 81 | --- set state of single LED on this grid device. 82 | -- @tparam integer x : column index (1-based!) 83 | -- @tparam integer y : row index (1-based!) 84 | -- @tparam integer val : LED brightness in [0, 15] 85 | function oscgrid:led(x, y, val) 86 | -- this should load up array and then refresh sends the values 87 | --osc.send(oscgrid.oscdest, "/grid/led ".. x .. " " .. y, {val}) 88 | --grid_set_led(self.dev, x, y, val) 89 | if (x > 0 and x < 17) and (y > 0 and y < 9) then 90 | oscgrid.LEDarray[x][y] = util.clamp(val,0,15) 91 | end 92 | --print("led",self.LEDarray[x][y]) 93 | end 94 | 95 | --- set state of all LEDs on this grid device. 96 | -- @tparam integer val : LED brightness in [0, 15] 97 | function oscgrid:all(val) 98 | for i = 1,16 do -- should maybe use g.cols 99 | for j = 1,8 do -- should maybe use g.rows 100 | oscgrid.LEDarray[i][j] = val 101 | --osc.send(oscgrid.oscdest, "/grid/led ".. i .. " " .. j, {val}) 102 | end 103 | end 104 | --grid_all_led(self.dev, val) 105 | end 106 | 107 | --- update any dirty quads on this grid device. 108 | function oscgrid:refresh() 109 | for i = 1,16 do -- should maybe use g.cols 110 | for j = 1,8 do -- should maybe use g.rows 111 | osc.send(self.oscdest, "/grid/led ".. i .. " " .. j, {oscgrid.LEDarray[i][j]}) 112 | end 113 | end 114 | --monome_refresh(self.dev) 115 | end 116 | 117 | 118 | 119 | --- static callback when any grid device is added; 120 | -- user scripts can redefine 121 | -- @static 122 | -- @param dev : a Grid table 123 | function oscgrid.add(dev) 124 | print("grid added:", dev.id, dev.name, dev.serial) 125 | end 126 | 127 | --- static callback when any grid device is removed; 128 | -- user scripts can redefine 129 | -- @static 130 | -- @param dev : a Grid table 131 | function oscgrid.remove(dev) end 132 | 133 | 134 | oscgrid.osc_in = function(path, args, from, g_id) 135 | local k 136 | local pathxy = {} 137 | for k in string.gmatch(path, "%S+") do 138 | table.insert(pathxy,k) 139 | end 140 | --print (pathxy[1], pathxy[2], pathxy[3], math.floor(args[1]), g_id) 141 | oscpath = pathxy[1] 142 | if oscpath == "/grid/key" then 143 | x = math.floor(pathxy[2]) 144 | y = math.floor(pathxy[3]) 145 | s = math.floor(args[1]) 146 | oscgrid.gridkey = {x, y, s} 147 | oscgrid.grid.key(g_id, x, y, s) 148 | 149 | --osc.send(oscgrid.oscdest, "/grid/led ".. x .. " " .. y, {val}) 150 | --osc.send(oscgrid.oscdest, path, args) 151 | --oscgrid.draw(x .. ' ' .. y .. ' ' .. s) 152 | 153 | end 154 | end 155 | 156 | oscgrid.grid = {} 157 | 158 | oscgrid.grid.key = function(id, x, y, s) 159 | local g = grid.devices[id] 160 | --tab.print(g) 161 | if g ~= nil then 162 | --print (g.key) 163 | if g.key ~= nil then 164 | g.key(x, y, s) 165 | _norns.grid.key(id, x,y,s) 166 | --print (x, y, s) 167 | end 168 | 169 | if g.port then 170 | if oscgrid.vports[g.port].key then 171 | oscgrid.vports[g.port].key(x, y, s) 172 | print('oscgrid.vports',x,y,s) 173 | end 174 | end 175 | else 176 | error('no entry for grid '..id) 177 | end 178 | 179 | --print(id) 180 | --print(x,y,s) 181 | --norns.grid.key(id, x,y,s) 182 | end 183 | 184 | function oscgrid.connect(n) 185 | local n = n or 1 186 | return grid.vports[n] 187 | end 188 | 189 | --- clear handlers. 190 | function oscgrid.cleanup() 191 | for i=1,4 do 192 | grid.vports[i].key = nil 193 | end 194 | 195 | for _, dev in pairs(grid.devices) do 196 | dev:all(0) 197 | dev:refresh() 198 | dev.key = nil 199 | end 200 | end 201 | 202 | --- update devices. 203 | function oscgrid.update_devices() 204 | -- build list of available devices 205 | oscgrid.list = {} 206 | for _,device in pairs(grid.devices) do 207 | device.port = nil 208 | end 209 | 210 | -- connect available devices to vports 211 | for i=1,4 do 212 | grid.vports[i].device = nil 213 | grid.vports[i].rows = 0 214 | grid.vports[i].cols = 0 215 | 216 | for _,device in pairs(grid.devices) do 217 | if device.name == grid.vports[i].name then 218 | grid.vports[i].device = device 219 | grid.vports[i].rows = device.rows 220 | grid.vports[i].cols = device.cols 221 | device.port = i 222 | end 223 | end 224 | end 225 | end 226 | 227 | 228 | -- grid add 229 | oscgrid.grid.add = function(id, serial, name, dev) 230 | local g = oscgrid.new(id,serial,name, dev) 231 | grid.devices[id] = g 232 | oscgrid.update_devices() 233 | if oscgrid.add ~= nil then oscgrid.add(g) end 234 | end 235 | 236 | -- grid remove 237 | oscgrid.grid.remove = function(id) 238 | if grid.devices[id] then 239 | if grid.remove ~= nil then 240 | grid.remove(grid.devices[id]) 241 | end 242 | if grid.devices[id].remove then 243 | grid.devices[id].remove() 244 | end 245 | end 246 | grid.devices[id] = nil 247 | oscgrid.update_devices() 248 | end 249 | 250 | oscgrid.draw = function(text) 251 | screen.clear() 252 | screen.move (10,10) 253 | screen.text(text) 254 | screen.stroke() 255 | screen.update() 256 | end 257 | 258 | return oscgrid -------------------------------------------------------------------------------- /load.lua: -------------------------------------------------------------------------------- 1 | -- oscgrid/oscarc loader 2 | -- run this to load oscgrid and oscarc into memory 3 | 4 | -- you can also use this directly in another script 5 | -- replace grid.connect() with include('lib/oscgrid') 6 | -- and you're off to the races 7 | 8 | -- g = grid.connect() 9 | -- local g = include('lib/oscgrid') 10 | 11 | local touchoscsourceip = "10.0.1.11" 12 | local touchoscsourceport = 9000 13 | 14 | local grds = {} 15 | local g 16 | local grid_w 17 | local grid_h 18 | local ar 19 | 20 | 21 | function init() 22 | connect() 23 | get_grid_names() 24 | --tab.print(grds[1]) 25 | --tab.print(grid.vports[1].device) 26 | screen.aa(0) 27 | redraw() 28 | end 29 | 30 | function get_grid_names() 31 | -- Get a list of grid devices 32 | for id,device in pairs(grid.vports) do 33 | grds[id] = {name = device.name, id = device.id } 34 | --grds[id].id = device.id 35 | end 36 | end 37 | 38 | function connect() 39 | grid.update_devices() 40 | g = include('lib/oscgrid') 41 | local g_id = 2 42 | g.grid.add(g_id, "m12345", "oscgrid", {}) 43 | g.key = oscgrid_key 44 | grid_w = g.cols 45 | grid_h = g.rows 46 | --g:rotation(0) 47 | 48 | arc.update_devices() 49 | ar = include('lib/oscarc') 50 | local ar_id = 2 51 | ar.arc.add(ar_id, "m54321", "oscarc", {}) 52 | ar.delta = oscarc_delta 53 | 54 | g.oscdest = {touchoscsourceip,touchoscsourceport} 55 | ar.oscdest = {touchoscsourceip,touchoscsourceport} 56 | 57 | osc.event = function(path, args, from) 58 | g.osc_in(path, args, from, g_id) 59 | ar.osc_in(path, args, from, ar_id) 60 | end 61 | 62 | --print ("cols/rows", grid_w, grid_h) 63 | end 64 | 65 | 66 | function oscgrid_key(x, y, s) 67 | if s == 1 then 68 | --print('keyon') 69 | --g:led(x,y,15) 70 | --g:refresh() 71 | else 72 | --print('keyoff') 73 | --g:led(x,y,0) 74 | --g:refresh() 75 | end 76 | --print (x .. ' ' .. y .. ' ' .. s) 77 | end 78 | 79 | function oscarc_delta(n, delta) 80 | --print (n , delta) 81 | end 82 | 83 | 84 | function redraw() 85 | screen.clear() 86 | screen.level(15) 87 | screen.move (0,10) 88 | screen.text('oscgrid loaded') 89 | 90 | screen.update() 91 | end -------------------------------------------------------------------------------- /load_arc.lua: -------------------------------------------------------------------------------- 1 | -- oscgrid/oscarc loader 2 | -- run this to load oscgrid and oscarc into memory 3 | 4 | -- you can also use this directly in another script 5 | -- replace grid.connect() with include('lib/oscgrid') 6 | -- and you're off to the races 7 | 8 | -- ar = arc.connect() 9 | -- local ar = include('lib/oscarc') 10 | 11 | local touchoscsourceip = "10.0.1.11" 12 | local touchoscsourceport = 9000 13 | 14 | local ar 15 | 16 | function init() 17 | connect() 18 | 19 | screen.aa(0) 20 | redraw() 21 | end 22 | 23 | 24 | function connect() 25 | 26 | arc.update_devices() 27 | ar = include('lib/oscarc') 28 | local ar_id = 2 29 | ar.arc.add(ar_id, "m54321", "oscarc", {}) 30 | ar.delta = oscarc_delta 31 | 32 | ar.oscdest = {touchoscsourceip,touchoscsourceport} 33 | 34 | osc.event = ar.osc_in 35 | end 36 | 37 | function oscarc_delta(n, delta) 38 | --print (n , delta) 39 | 40 | end 41 | 42 | function redraw() 43 | screen.clear() 44 | screen.level(15) 45 | screen.move (0,10) 46 | screen.text('oscarc loaded') 47 | 48 | screen.update() 49 | end -------------------------------------------------------------------------------- /load_grid.lua: -------------------------------------------------------------------------------- 1 | -- oscgrid/oscarc loader 2 | -- run this to load oscgrid and oscarc into memory 3 | 4 | -- you can also use this directly in another script 5 | -- replace grid.connect() with include('lib/oscgrid') 6 | -- and you're off to the races 7 | 8 | -- g = grid.connect() 9 | -- local g = include('lib/oscgrid') 10 | 11 | local touchoscsourceip = "10.0.1.11" 12 | local touchoscsourceport = 9000 13 | 14 | 15 | local grds = {} 16 | local g 17 | local grid_w 18 | local grid_h 19 | 20 | function init() 21 | connect() 22 | get_grid_names() 23 | --tab.print(grds[1]) 24 | --tab.print(grid.vports[1].device) 25 | screen.aa(0) 26 | redraw() 27 | end 28 | 29 | function get_grid_names() 30 | -- Get a list of grid devices 31 | for id,device in pairs(grid.vports) do 32 | grds[id] = {name = device.name, id = device.id } 33 | --grds[id].id = device.id 34 | end 35 | end 36 | 37 | function connect() 38 | grid.update_devices() 39 | g = include('lib/oscgrid') 40 | local g_id = 2 41 | g.grid.add(g_id, "m12345", "oscgrid", {}) 42 | g.key = oscgrid_key 43 | grid_w = g.cols 44 | grid_h = g.rows 45 | --g:rotation(0) 46 | 47 | g.oscdest = {touchoscsourceip,touchoscsourceport} 48 | 49 | osc.event = function(path, args, from) 50 | g.osc_in(path, args, from, g_id) 51 | end 52 | 53 | --print ("cols/rows", grid_w, grid_h) 54 | end 55 | 56 | 57 | function oscgrid_key(x, y, s) 58 | if s == 1 then 59 | --print('keyon') 60 | --g:led(x,y,15) 61 | --g:refresh() 62 | 63 | else 64 | --print('keyoff') 65 | --g:led(x,y,0) 66 | --g:refresh() 67 | end 68 | --print (x .. ' ' .. y .. ' ' .. s) 69 | end 70 | 71 | 72 | function redraw() 73 | screen.clear() 74 | screen.level(15) 75 | screen.move (0,10) 76 | screen.text('oscgrid loaded') 77 | 78 | screen.update() 79 | end -------------------------------------------------------------------------------- /unload.lua: -------------------------------------------------------------------------------- 1 | -- oscgrid un-loader 2 | -- run this to unload oscgrid from memory 3 | 4 | 5 | local grds = {} 6 | local g 7 | local grid_w 8 | local grid_h 9 | 10 | function init() 11 | disconnect() 12 | get_grid_names() 13 | 14 | --tab.print(grds[1]) 15 | --tab.print(grid.vports[1].device) 16 | 17 | screen.aa(0) 18 | redraw() 19 | end 20 | 21 | function get_grid_names() 22 | -- Get a list of grid devices 23 | for id,device in pairs(grid.vports) do 24 | grds[id] = {name = device.name, id = device.id } 25 | --grds[id].id = device.id 26 | end 27 | end 28 | 29 | function disconnect() 30 | grid.update_devices() 31 | g = include('lib/oscgrid') 32 | 33 | g.grid.remove(2) 34 | g.cleanup() 35 | 36 | arc.update_devices() 37 | ar = include('lib/oscarc') 38 | ar.arc.remove(2) 39 | ar.cleanup() 40 | 41 | end 42 | 43 | function key(n,z) 44 | if n==2 and z==1 then 45 | redraw() 46 | end 47 | end 48 | 49 | 50 | function grid_key(x, y, s) 51 | if s == 1 then 52 | --print('keyon') 53 | --g:led(x,y,15) 54 | else 55 | --print('keyoff') 56 | --g:led(x,y,0) 57 | end 58 | --print (x .. ' ' .. y .. ' ' .. s) 59 | end 60 | 61 | 62 | function redraw() 63 | screen.clear() 64 | screen.level(15) 65 | screen.move (0,10) 66 | screen.text('oscgrid unloaded') 67 | 68 | screen.update() 69 | end --------------------------------------------------------------------------------