Skip to content

Instantly share code, notes, and snippets.

@cfdrake
Created January 29, 2021 22:55
Show Gist options
  • Save cfdrake/9c2b4994a8471b54e149c00ecbc7a88e to your computer and use it in GitHub Desktop.
Save cfdrake/9c2b4994a8471b54e149c00ecbc7a88e to your computer and use it in GitHub Desktop.
-- mouse
-- by @cfd90
MusicUtil = require "musicutil"
hs = require('awake/lib/halfsecond')
engine.name = "PolyPerc"
last_x = 4
last_y = 4
offset = 0
movement = 2
spread = 4
notes = MusicUtil.generate_scale_of_length(60, 1, 128)
function init()
print(tab.print(notes))
g = grid.connect()
g.key = grid_key
redraw_grid()
params:add_separator()
cs_AMP = controlspec.new(0,1,'lin',0,0.5,'')
params:add{type="control",id="amp",controlspec=cs_AMP,
action=function(x) engine.amp(x) end}
cs_PW = controlspec.new(0,100,'lin',0,50,'%')
params:add{type="control",id="pw",controlspec=cs_PW,
action=function(x) engine.pw(x/100) end}
cs_REL = controlspec.new(0.1,3.2,'lin',0,1.2,'s')
params:add{type="control",id="release",controlspec=cs_REL,
action=function(x) engine.release(x) end}
cs_CUT = controlspec.new(50,5000,'exp',0,800,'hz')
params:add{type="control",id="cutoff",controlspec=cs_CUT,
action=function(x) engine.cutoff(x) end}
cs_GAIN = controlspec.new(0,4,'lin',0,1,'')
params:add{type="control",id="gain",controlspec=cs_GAIN,
action=function(x) engine.gain(x) end}
cs_PAN = controlspec.new(-1,1, 'lin',0,0,'')
params:add{type="control",id="pan",controlspec=cs_PAN,
action=function(x) engine.pan(x) end}
hs.init()
end
function grid_key(x, y, z)
if z == 0 then
return
end
if last_x ~= x then
print("Updating x to " .. x)
last_x = x
trigger_x(x)
end
if last_y ~= y then
print("Updating y to " .. y)
last_y = y
trigger_y(y)
end
redraw_grid()
end
function redraw_grid()
g:all(0)
g:led(last_x, last_y, 15)
g:refresh()
end
function trigger_x(x)
engine.hz(MusicUtil.note_num_to_freq(notes[offset + x*movement - spread]))
engine.hz(MusicUtil.note_num_to_freq(notes[offset + x*movement]))
engine.hz(MusicUtil.note_num_to_freq(notes[offset + x*movement + spread]))
end
function trigger_y(y)
engine.hz(MusicUtil.note_num_to_freq(notes[offset + y*movement]))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment