quarterTone.lua

QuarterTone script

--------------------------------------------------------------------------------
--! @example quarterTone.lua
--! QuarterTone script
--------------------------------------------------------------------------------
-- setSize(600,80)
notes = {"C","C#","D","D#","E","F","F#","G","G#","A","A#","B"}
notenames={}
for i=1,128 do
notenames[i] = notes[(1+(i-1)%12)] .. (math.floor(i/12) - 2)
end
Root = Menu("root", notenames)
Root.value = 60+1
function onNote(e)
local root = Root.value-1
local note = e.note
local velocity = e.velocity
local detune = 0
if (e.note-root)%2 == 0 then -- no detune
note = root + math.floor((e.note-root)/2)
else
if e.note > root then
note = math.floor((e.note-root)/2) + root + 1
detune = -0.5 -- minus 50 cents
elseif e.note < root then
note = math.floor((e.note-root)/2) + root - 1
detune = 0.50 -- plus 50 cents
end
end
local id = playNote(note, velocity)
if detune ~= 0 then
changeTune(id, detune)
end
end
function onRelease(e)
-- release is automatic
end