Skip to content

Instantly share code, notes, and snippets.

@Dewb
Created October 6, 2023 20:58
Show Gist options
  • Save Dewb/163a67b8dc3a5ca3e8a1939be7bc6270 to your computer and use it in GitHub Desktop.
Save Dewb/163a67b8dc3a5ca3e8a1939be7bc6270 to your computer and use it in GitHub Desktop.
Script for use with VCV Rack ModScript to map a Launchpad X to a virtual monome grid64
-- Lua script for the ModScript module (https://github.com/Simon-L/ModScript)
-- to use a Launchpad X to control a virtual monome grid64 (https://dewb.github.io/monome-rack/modules/grids/)
config.frameDivider = 128
config.bufferSize = 8
grid = Module(0x12eff0454d674b)
leds = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
function process(block)
-- convert incoming MIDI note input to param changes
for i=1,block.midiInputSize do
msg = Message(block.midiInput[i])
if msg.type == NOTE_ON or msg.type == NOTE_OFF then
if msg.note >= 11 and msg.note <= 88 then
local y = math.floor((88 - msg.note)/10.0)
local x = (msg.note % 10) - 1
local n = (y * 8 + x) * 2 -- x2 because every button has two params
if n >= 0 and n < 128 then
-- launchpad X sends note offs as note on with velocity zero
if msg.type == NOTE_ON and msg.value > 0 then
grid:setParam(n, 1.0)
else
grid:setParam(n, 0.0)
end
end
end
end
end
-- send light changes out as MIDI messages
for x=0,7 do
for y=0,7 do
local n = y * 8 + x
local value = grid:getLight(n)
if leds[n] ~= value then
local color = math.floor(value * 7)
local note = 81 - (10 * y) + x
sendMidiMessage(NOTE_ON, note, color)
leds[n] = value
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment