simple ruby script to convert serial to midi


i've created simple script others might find useful.. grabs serial data coming arduino , converts midi commands using midiator gem.. first stab , implies have data coming across wire this

note,duration,velocity

code: [select]

require 'rubygems'
require 'midiator'

# don't ask...
# http://www.ruby-forum.com/topic/123503
kernel::require "serialport.so"

#params serial port
port_str = "/dev/tty.usbserial-a6006esl"  #may different you
baud_rate = 9600
data_bits = 8
stop_bits = 1
parity = serialport::none
sp = serialport.new(port_str, baud_rate, data_bits, stop_bits, parity)

midi = midiator::interface.new
midi.autodetect_driver


puts "begin"
begin
 loop do
   resp = sp.gets
   break if resp.nil?
   
   puts "got midi message: #{resp}"
   
   note, duration, velocity = resp.split(",").collect{|x| x.to_i }
   
   #duration = duration / 100
   
   midi.play note,
             duration / 100,
             1,
             velocity
 end
ensure
 puts "cleaning up!"
 # bad things happen if don't this
 sp.close
end



Arduino Forum > Forum 2005-2010 (read only) > Software > Interfacing > simple ruby script to convert serial to midi


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums