Created
December 20, 2014 23:20
-
-
Save eric-wood/8ef56a782e05034b6117 to your computer and use it in GitHub Desktop.
Read the first 5 MIDI notes presented, play 'em back
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'unimidi' | |
input = UniMIDI::Input.use(:first) | |
output = UniMIDI::Output.use(:first) | |
puts "-" * 100 | |
puts "Start playing some notes plz" | |
puts "-" * 100 | |
data = [] | |
NUM_NOTES = 5 | |
loop do | |
break if data.size >= NUM_NOTES | |
note = input.gets.first | |
# only add "note on" data | |
data << note if note[:data][0] == 0x90 | |
end | |
puts "cool, thanks for the notes" | |
# strip out the other details | |
notes = data.map { |i| i[:data] } | |
sequencer = Thread.new do | |
Thread.current[:delay] = 0.1 | |
Thread.current[:notes] ||= [] | |
loop do | |
Thread.current[:notes].each do |note| | |
output.puts(0x90, note[1], note[2]) | |
sleep(Thread.current[:delay]) | |
output.puts(0x80, note[1], note[2]) | |
end | |
end | |
end | |
sequencer[:notes] = notes | |
gets | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment