Skip to content

Instantly share code, notes, and snippets.

@ypxk
Created October 1, 2018 20:58
Show Gist options
  • Save ypxk/93170e361fc5a508d38e9514a05bed4d to your computer and use it in GitHub Desktop.
Save ypxk/93170e361fc5a508d38e9514a05bed4d to your computer and use it in GitHub Desktop.
music = require 'mark_eats/musicutil'
chordsList = {}
timeSet = 0
timeDone = 0
--midi function
m = midi.connect()
m.event = function(data)
local d = midi.to_msg(data)
if d.type == "note_on" then
noteBuffer(d.note)
timeDone = util.time()
end
end
--note function
function noteBuffer(aNote)
timeSet = util.time()
for k, v in pairs (chordsList) do --ignore duplicate notes
if aNote == v then
return
end
end
if timeSet - timeDone < .5 then --set window for note input presses
table.insert(chordsList, aNote)
else -- clears table and starts new buffer
print('Initializing buffer')
for k, v in pairs(chordsList) do chordsList[k]=nil end
table.insert(chordsList, aNote)
end
capturedNotes = music.note_nums_to_names(chordsList)
print(#chordsList .. '-size buffer of notes ' )
for k, v in pairs(capturedNotes) do
print(v)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment