Sharing my personal patched version of Cranes that adds support for QWERTY keyboards as a template for others to follow…
cranes-kb.lua (26.7 KB)
usage
Place this in the dust/code/cranes folder. It will show up as cranes/cranes-kb in the script launcher. Connect a USB keyboard before running, and select it as device #1 in SYSTEM => DEVICES => HID menu.
Controls are as follows:
- (Modifies voice 1 by default, hold “Shift” while tapping a key to modify voice 2 instead)
- 1st Row: “1” through “-” selects pitch of loop (-4, -2, -1, -0.5, -0.25, 0, 0.25, 0.5, 1, 2, 4)
- 2nd Row: “Q” through “P” selects volume of loop, 0-1
- 3rd Row: “A” through “L” selects panning of loop, left to right
- Keep in mind that slew rates to pan/vol/etc. will animate changes smoothly
edit: have been retesting this script, you might need to boot up with the USB keyboard attached first!
tutorial
Here’s the TL; DR for how to add keyboard support to a script…
function init()
-- find the init() function in your script
-- this code is run when the script first launches
-- ...existing code here...
-- add this bit!
-- connects to the keyboard
-- tells keyboard to send all events to the "keyboard_event" bit of code
-- we'll need to add this next
keyb = hid.connect()
keyb.event = keyboard_event
end
Scroll to the bottom of the file, and add this bit of code:
function keyboard_event(typ, code, val)
-- code in here will run when a keyboard event occurs (press/release/etc)
-- typ can be ignored for us
-- code is an integer which identifies what key was pressed
-- val is the state of the key (1 indicates pressed down)
-- as an example of reacting to a keyboard event and altering script params...
-- this would add support for controlling loop 1's pitch from keys "1" and "2"
-- search around the script for "params" to see which params are available and what values they take on
-- check out the grid handling code, if it exists, to copy from
if code == hid.codes.KEY_1 and val == 1 then
-- code == hid.codes.KEY_1 indicates the "1" key
-- val == 1 indicates that key event type was "pressed"
-- we'll set rate to -1 (reverse, 1x speed)
params:set("speed_voice_1", -1)
elseif code == hid.codes.KEY_2 and val == 1 then
-- code == hid.codes.KEY_2 indicates the "2" key
-- val == 1 indicates that key event type was "pressed"
-- we'll set rate to 1 (forward, 1x speed)
params:set("speed_voice_1", 1)
end
-- as a tip I typically have this bit of code to print out keyboard input to maiden while developing
-- it helps for discovering what codes/vals are passed in when you physically interact w/the keyboard
print("code: " .. code .. ", val: " .. val)
end
Finally checkout this file for a listing of key codes that are available.
update: edited above to use hid.codes instead of hardcoding code values