Yes, I think i put it in the global scope,
local MusicUtil = require "musicutil"
local UI = require "ui"
local Graph = require "graph"
local EnvGraph = require "envgraph"
local Passersby = require "passersby/lib/passersby_engine"
local tab = require 'tabutil'
local pattern_time = require 'pattern_time'
local g = grid.connect()
local mode_transpose = 0
local root = { x=5, y=5 }
local trans = { x=5, y=5 }
local lit = {}
local screen_framerate = 15
local screen_refresh_metro
local ripple_repeat_rate = 1 / 0.3 / screen_framerate
local ripple_decay_rate = 1 / 0.5 / screen_framerate
local ripple_growth_rate = 1 / 0.02 / screen_framerate
local screen_notes = {}
local tn = include('tunnels/lib/tunnel')
local SCREEN_FRAMERATE = 15
local screen_refresh_metro
local screen_dirty = true
local midi_in_device
local active_notes = {}
local pages
local tabs
local tab_titles = {{"Wave", "FM"}, {"Env", "Reverb"}, {"LFO", "Targets"}, {"Fate"}, {"Tunnels"}}
local input_indicator_active = false
local wave_table = {}
local wave = {}
local wave_graph
local SUB_SAMPLING = 4
local fm1_dial
local fm2_dial
local env_graph
local env_status = {}
local env_status_metro
local spring_path = {}
local reverb_slider
local lfo_graph
local dice_throw_vel = 0
local dice_throw_progress = 0
local dice_thrown = false
local dice_need_update = false
local dice = {}
local drift_dial
local timbre = 0
local wave_shape = {actual = 0, modu = 0, dirty = true}
local wave_folds = {actual = 0, modu = 0, dirty = true}
local fm1_amount = {actual = 0, modu = 0, dirty = true}
local fm2_amount = {actual = 0, modu = 0, dirty = true}
local attack = {actual = 0, modu = 0, dirty = true}
local peak = {actual = 0, modu = 1, dirty = true}
local decay = {actual = 0, modu = 0, dirty = true}
local reverb_mix = {actual = 0, modu = 0, dirty = true}
local lfo_shape = {dirty = true}
local lfo_freq = {dirty = true}
local lfo_destinations = {dirty = true}
local drift = {actual = 0, dirty = true}
engine.name = "Passersby"
here’s the section that controls grid input and pattern
– GRID input
pat = pattern_time.new()
pat.process = grid_note_trans
local MAX_NUM_VOICES = 16
function g.key(x, y, z)
if x == 1 then
if z == 1 then
if y == 1 and pat.rec == 0 then
mode_transpose = 0
trans.x = 5
trans.y = 5
pat:stop()
engine.noteOffAll()
pat:clear()
pat:rec_start()
elseif y == 1 and pat.rec == 1 then
pat:rec_stop()
if pat.count > 0 then
root.x = pat.event[1].x
root.y = pat.event[1].y
trans.x = root.x
trans.y = root.y
pat:start()
end
elseif y == 2 and pat.play == 0 and pat.count > 0 then
if pat.rec == 1 then
pat:rec_stop()
end
pat:start()
elseif y == 2 and pat.play == 1 then
pat:stop()
engine.noteOffAll()
stop_all_screen_notes()
nvoices = 0
lit = {}
elseif y == 8 then
mode_transpose = 1 - mode_transpose
end
end
else
if mode_transpose == 0 then
local e = {}
e.id = x*8 + y
e.x = x
e.y = y
e.state = z
pat:watch(e)
grid_note(e)
else
trans.x = x
trans.y = y
end
end
gridredraw()
end
function grid_note(e)
local note = ((7-e.y)*5) + e.x
if e.state > 0 then
if nvoices < MAX_NUM_VOICES then
--engine.start(id, getHz(x, y-1))
--print("grid > "..id.." "..note)
engine.noteOn(e.id, getHzET(note), vel)
lit[e.id] = {}
lit[e.id].x = e.x
lit[e.id].y = e.y
nvoices = nvoices + 1
end
else
if lit[e.id] ~= nil then
engine.noteOff(e.id)
lit[e.id] = nil
nvoices = nvoices - 1
end
end
gridredraw()
end
function grid_note_trans(e)
local note = ((7-e.y+(root.y-trans.y))*5) + e.x + (trans.x-root.x)
if e.state > 0 then
if nvoices < MAX_NUM_VOICES then
--engine.start(id, getHz(x, y-1))
--print("grid > "..id.." "..note)
engine.noteOn(e.id, getHzET(note))
start_screen_note(note)
lit[e.id] = {}
lit[e.id].x = e.x + trans.x - root.x
lit[e.id].y = e.y + trans.y - root.y
nvoices = nvoices + 1
end
else
engine.noteOff(e.id)
stop_screen_note(note)
lit[e.id] = nil
nvoices = nvoices - 1
end
gridredraw()
end
function gridredraw()
g:all(0)
g:led(1,1,2 + pat.rec * 10)
g:led(1,2,2 + pat.play * 10)
g:led(1,8,2 + mode_transpose * 10)
if mode_transpose == 1 then g:led(trans.x, trans.y, 4) end
for i,e in pairs(lit) do
g:led(e.x, e.y,15)
end
g:refresh()
end
function note_on(note, vel)
if nvoices < MAX_NUM_VOICES then
--engine.start(id, getHz(x, y-1))
engine.start(note, getHzET(note))
start_screen_note(note)
nvoices = nvoices + 1
end
end
function note_off(note, vel)
engine.stop(note)
stop_screen_note(note)
nvoices = nvoices - 1
end
function midi_event(data)
if #data == 0 then return end
local msg = midi.to_msg(data)
-- Note off
if msg.type == "note_off" then
note_off(msg.note)
-- Note on
elseif msg.type == "note_on" then
note_on(msg.note, msg.vel / 127)
end
end
function cleanup()
stop_all_screen_notes()
pat:stop()
pat = nil
end