Midi messages in Lua
Lua scripts can now receive midi messages (set with the lua_pushmidi function of LuaScript). These messages appear as a table with the following capacities:
msg.channel -- midi channel
msg.type -- msg type, see below
-- 'NoteOn', 'NoteOff'
msg.note -- note value as number
msg.velocity -- note velocity
-- 'Ctrl'
msg.ctrl -- ctrl change number
msg.value -- ctrl value
-- Clock related: , 'Start', 'Stop', '.' (clock tick), 'Continue'
-- Other: '?'
New MidiIn object
(the Midi object has been renamed to “MidiOut”)
The new midi in object receives midi events from other sources (use MidiIn.list to get sources list). Outputs are:
OUTLET(MidiIn,all) // 1
OUTLET(MidiIn,notes) // 2
OUTLET(MidiIn,ctrl) // 3
OUTLET(MidiIn,clock) // 4
OUTLET(MidiIn,tick) // 5
The ‘clock’ outlet can be used to start/stop and sync a beat machine. For example:
mii = MidiIn(0)
mii.4 => l
l = Lua(load:"beatmachine.lua")
l => miout
miout = MidiOut(0)
The lua script receives 24 ticks per quarter note (“noire”).
quantize input
This is a simple example to quantize midi input with rubyk:
mii = MidiIn() # midi input (virtual port)
mii.2 => 2.v # send notes to 'set_value' port of Value (no bang)
v = Value()
mii.5 => b # send ticks to 'bang'
b = Bang()
b => v # send 'bang' to Value object outputs midi notes
v => mio # send notes to midi out
mio = MidiOut() # midi output (virtual port)