Mapping linux input events to OSC
In linux every input device registers under /dev/input/eventX and sends events in 16 byte blocks. these data chunks contain a timestamp the event type, the event code and a value depending on the event type the semantic of value changes. for a event type 1 (key event) value 1 means pressed and value 0 mean released.
here is a little ruby program that reacts to key press events and sends osc messages. which could trigger drum sounds, start play back, ...
key press events are not only sent by keyboards but also by mice, joystics, gamepads, a DDR mat, a buzz buzzer, ...
the code example is used to map keys of my PS3 Controller to drum sounds.
require 'osc';
c = OSC::UDPSocket.new
hh = OSC::Message.new('/drum', 's', "hh" )
bd = OSC::Message.new('/drum', 's', "bd" )
sn = OSC::Message.new('/drum', 's', "sn" )
File.open("/dev/input/event7") do |f|
while true
event = f.read(16).unpack("llSSl")
time = event[0] + event[1] / 1000000.0
type = event[2]
code = event[3]
value = event[4]
puts "Ti: #{time} T: #{type} C: #{code} V: #{value} " if type == 1
c.send( bd, 0, 'localhost', 3334 ) if type == 1 && code == 298 && value == 1
c.send( sn, 0, 'localhost', 3334 ) if type == 1 && code == 293 && value == 1
c.send( hh, 0, 'localhost', 3334 ) if type == 1 && code == 303 && value == 1
end
end
The code was inspired by 2 articles i found recently the first one is about how to use a DDR-mat to trigger Drum Sounds and the second one shows how to read the accelerometer data from a openmonoko phone
read more ...ruby osc seqencer version2
i updated my osc sequencer in ruby. now it doesn't just send osc events but also react to it. i made a small processing sketch that sends osc play,pause,stop events for each track in the sequencer. i also refactored the ruby code a bit, to use classes. next steps i plan are to separate the sequencer code from the sequences and allow sequences to be added or deleted at runtime via osc messages.
the code isn't very reusable now, so i still considere this more as a prove of concept, but i like the idea of separating the frontend and the backend via osc events and having sequences that can run independently.
that should enable some nice osc controlled audio/video installations.
write me a comment or mail if you have some ideas for improvement or if you use the code in one of your projects
read more ...processing ical-flowers-2.0
I made a new version of the ical flowers sketch i wrote in dezember. This time it doesn't only show a flower for every event in my calender, it also shows
- the current weather (using the rubyweather library)
- the current temperature outside
- the min/max temperature outside
- the current temperature inside ( using my arduino i2c thermometer sketch)
- the sky color changes depending on the current time
the system consists of a ruby-proxy, an arduino sketch and a processing sketch.
the ruby proxy starts a web-server on port 2000. It fetches the current weather using the rubyweather gem, fetches the events from the configured caldav calenders, and fetches the current temperature from the arduino using ruby-serial
the arduino sketch is basicaly the same as in this blog post. the only change is that the arduino only sends the temperature when the host sends a 'C' over the serial line
the processing sketch finally fetches the data via http from the proxy and displays it ( using my icap4p library. the screen is updated every 1/2 hour using the method described here
the code can be downloaded here
it's published under the LGPL
have fun :-)
read more ...ruby symbols vs string vs constant
on saturday i was asked by a ruby-newbie (sorry - i had to write it :-) ) whats the difference between a symbol, a string and a constant in ruby. even tough there are realy, realy many articles about ruby symbols ( a google search for "ruby symbols" results in 1,340,000 hits - so this is the 1,340,001 aricle covering the topic) there is obviously still some confusion out there. So i try my own definition here.
read more ...Ruby Caldav Library 0.2
I have made a new version of my ruby caldav lib.
version 0.2 is a bugfix release, there are no new features but i removed some essential typos
read more ...osc sequencer in ruby
I wrote a simple osc sequencer in ruby using rosc. The script triggers the drum-kit and the bass i implemented last week.
the pattern may also be of different length. This allows very interesting polyrythmic loops.
require 'osc'
Host = 'localhost'
Port = 3334
c = OSC::UDPSocket.new
hh = OSC::Message.new('/drum', 's', "hh" )
bd = OSC::Message.new('/drum', 's', "bd" )
sn = OSC::Message.new('/drum', 's', "sn" )
ba = OSC::Message.new('/bass', 'i', 64 )
#c.send sn, 0, Host, Port
bpm = 120
step = 1.0/8;
s = bpm * step / 60.0 ;
snd = [ bd, sn, hh ]
pattern = [
[1, 0, 0, 1, 0, 1, 0, 0 ],
[0, 0, 1, 0, 0, 0, 1, 1 ],
[1, 1, 1, 1, 1, 1, 1, 1 ]
]
bass = [
40, 40, 0, 40, 40, 0, 43, 0,
40, 40, 0, 40, 40, 0, 38, 0 ]
count = 0;
while(true)
(0..2).each { |i|
c.send(snd[i], 0, Host, Port) if pattern[i][count % pattern[i].length] == 1
}
ba.args = [bass[ count % bass.length]]
c.send( ba, 0, Host, Port ) if bass[ count % bass.length ] != 0
sleep s
count+=1
end
read more ...typo on debian
Yesterday i have installed typo on a debian box. First i installed ruby, rails, mongrel, rake and gem - and when i wanted to install typo it told me that it didnt like my rails version :-/
so i installed rails 2.0.2 and then typo. After installing the blog, and configuring apache (i haaaaaaate mod_proxy rewrites in apache - i cant tell you how much!) typo thrwe some exceptions every time i wanted to write an article.
hrmpf
after googleling for some time, i found out that rails 2.0.2 isnt working with ruby 1.8.7. Instructions how to downgrade ruby can be found here and instructions how to keep debian from upgrading it again can be found here
read more ...Ruby Caldav Library
I have a DAViCal running and i wanted to write a simple jabber bot that reminds me when i have forgotten to enter my timesheet data. So i have hacked together a simple ruby library to access the caldav protocol. More info and sourcecode is available on the project page
read more ...Nagios Glitzerlampe
I made a new project page for my nagios visualisation system written in ruby.
read more ...stinky emails
Last week a college came up with the theory, that nobody would have mails lying around in his inbox, if they would start to stink after a while. To check this, i came up with the "email-stinky-o-mat" i already have hacked together a small ruby script that calculates the "stinkycount" for a mailbox.
require 'net/imap'
require 'date'
imap = Net::IMAP.new('mailhost')
imap.login( 'user', 'password')
imap.select( "INBOX" )
stinkycount = 0
imap.search(["BEFORE", "#{(Date.today()-20).strftime( "%d-%b-%Y" )}" ]).each do |message_id|
stinkycount += 1
end
puts "#{stinkycount} stinking messages found"
this count can now be sent to a microcontroller (an arduino for example) which starts a fan, that is standing next to a reservior containing someting stinky - et voila (imagine drum roll here) - emails start to stink after 20 days :-)
read more ...