MIDIator v0.3.0 released!
November 23rd, 2008
I’ve just released MIDIator v0.3.0. This release brings some new features that I’m told are exciting :)
- CC, Aftertouch, Channel Aftertouch, and Pitch Bend messages, contributed by Jeremy Voorhis.
- A driver for OSX that talks directly to the system’s synthesizer… no more routing nonsense required! Contributed by Adam Murray with help from Jeremy Voorhis.
Note that at least for the short-term, the CoreMIDI driver will remain the default for OSX. That means that #autodetect_driver will pick the CoreMIDI driver on OSX. If you want to use Adam’s driver, you must call #use, like so:
1 2 |
@midi = MIDIator::Interface.new @midi.use :dls_synth |
At some point in the future, both direct-to-synth and indirect MIDI message modes will be supported on all three platforms. I’ll also be adding a nicer way to specify which mode you want, so you don’t have to distribute code with hard-coded drivers.
You can install or update MIDIator from RubyForge:
$ sudo gem install midiator
Plz to enjoy!
The New(ish) Bleything.net
November 16th, 2008
While I’m completely sure that nobody ever goes to bleything.net, I have nevertheless put far more time than is necessary or reasonable into it over the past couple of weeks.
Inspired by my former LiveJournal coworker David Recordon, I added “recent activity” updates to bleything.net. It now shows you my recent tweets (with @s filtered out), my recent FireEagle updates, and GitHub activity.
There’s more coming, but I’ll save that for when I actually release it. I’m still working on the relaunch of this blog, but I’ve gotten sidetracked in javascript wankery. Once everything’s done and the dust has settled, I’ll be doing a series on all the code I wrote for this round of site updates… there’s some fun stuff involved.
As a preview, here’s a snippet of the script that fetches updates from GitHub:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
when /CommitEvent/ update_hash[ :type ] = 'GitHubCommit' update_hash[ :commit_id ] = update.links.first.href.split( '/' ).last update_hash[ :target ] = update.title.txt.match( /\w+\/\w+/ )[0] update_hash[ :text ] = Hpricot( update.content ).at( '//p[2]' ).inner_html.strip when /DeleteEvent/ update_hash[ :type ] = 'GitHubDelete' update_hash[ :target ] = update.title.txt.match( /\w+$/ )[0] when /ForkEvent/ update_hash[ :type ] = 'GitHubFork' update_hash[ :target ] = update.title.txt.match( /\w+\/\w+/ )[0] when /FollowEvent/ username = update.title.txt.match( /\w+$/ )[0] profile_page = Hpricot( open("http://github.com/#{username}") ) realname = profile_page.at( "span#profile_name" ).inner_html.strip update_hash[ :type ] = 'GitHubFollow' update_hash[ :target ] = username update_hash[ :text ] = realname when /WatchEvent/ update_hash[ :type ] = 'GitHubWatch' update_hash[ :target ] = Hpricot( update.content ).at( '//a' ).inner_html.strip |
Look for more soon!
Bad News for RubyConf
November 2nd, 2008
As he mentioned over here, Giles won’t be joining me and Yossef for our RubyConf presentation (Two Turntables and a Git Repo, if you’d forgotten).
If you were looking forward to seeing the man himself talking about his extremely popular project Archaeopteryx, I’m afraid you’re out of luck. I’ve never seen him speak about it, so I’m pretty disappointed.
Our presentation is still going to happen, and while I’ll be touching on Archaeopteryx briefly, it certainly won’t be the same. I am confident, however, that what Yossef and I have in store will be worth your time. See you in a few days!
You got MIDIator in my Archaeopteryx!
October 28th, 2008
As you are no doubt aware, mad scientist Giles Bowkett’s has a rad drum machine/crazy MIDI thing called Archaeopteryx. A common complaint with Archaeopteryx (hereafter “arkx”) is that it only runs on OSX.
The cool thing is that Giles used Topher Cyll’s code from Practical Ruby Projects. You may recall that I recently published a little library called MIDIator that also uses Topher’s code to provide easy access to MIDI on the major operating systems.
I’ve never really said this in public, but the real reason I wrote MIDIator in the first place was to become e-famous by making arkx work on Windows and Linux. So, it is with extreme hope for e-fame pleasure that I have pushed my branch of arkx that converts it to use MIDIator for MIDI interaction.
You can find the branch over here on GitHub. Please to enjoy.
Cropping and Pinning Images With CSS
October 26th, 2008
It feels really good to figure out a tricky CSS problem on your own without consulting the googles. This is a brief story about how I did that very thing while working on the forthcoming Great Bleything.net Refresh of ‘08™.
As you can see in the image below, the template I’m using wasn’t expecting to have an image in the left-hand column, so when I put one there, weird stuff happened when the browser was smaller than about 1100px:

Of course, expecting that people’s browsers are wider than that is kinda crazy, so instead of ignoring the problem, I fixed it. On some advice from Matt Lyon, I tried to figure out how to make the image crop itself when the window got too small to contain it.
As you see it in the image above, it’s actually inside an unordered list, because that’s how
the template came and I just dropped in my content. I initially tried making the li
relatively positioned and overflow: hidden, and the img absolutely positioned, but that
resulted in the image going right up to the edge of the grey box instead of leaving a border
around it.
Realizing that the unordered list thing was kind of insane markup anyway, I switched to using
a div. I tried the same positioning trick with no luck. At some point in my fiddling I even
got the image to disappear altogether when overflow: hidden was on the div. I slowly came
to realize that I was going to need more than one div.
That led me to the solution, which is reproduced below for your enjoyment:
1 2 3 4 5 6 7 8 |
<div id="headshot"> <div class="image"> <img src="/images/headshot.png" /> </div> <h3>Ben Bleything, Bit Poet</h3> </div> |
... and the relevant CSS:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
div#headshot {
background: #555;
padding: 10px;
}
div#headshot div.image {
position: relative;
height: 211px;
overflow: hidden;
}
div#headshot div.image img {
position: absolute;
right: 0;
}
|
If you’re not familiar with this technique, allow me to explain a touch. First, the outer
div acts as a container for all the goodness to come. We set its background color and give
it some padding so we have the nice border around the image.
Next, we have the div that will contain the image. This is what gives us the ability to
crop the image, as well as the ability to “pin” it to the right-hand side (since in the shot
I’m on the right). By setting position: relative on the inner div, we gain the ability to
absolutely position elements inside it. Note that the terminology is kinda strange here,
since what we ultimately accomplish is having the absolutely-positioned elements be relative
to the relatively-positioned element.
We also set overflow: hidden, which makes anything that would normally be outside the div
disappear. Finally, we set an explicit height (which matches the height of the image).
Without the height attribute, the div wouldn’t take up any space. I’m not entirely sure I
understand the reasoning for this, but I believe that absolutely positioned elements are
removed from the flow so they don’t cause their containing elements to resize. Similar things
happen when you float elements.
Finally, we absolutely position the img tag inside the inner div, and pin it to the
right-hand side. The cumulative effect is that at full width, you see the entire image. As
you shrink the page, the left column will eventually start to shrink too. When it does, the
left-hand side of the image will start to “overflow” the left-hand side of the containing
div, but thanks to overflow: hidden, it just disappears, leaving our nice border in
place.
Cool, right? I really do love this stuff. Stay tuned, I should be rolling out the new design soonish.
RubyConf Interview
October 21st, 2008
I mentioned this in the MIDIator post, but just in case you skipped that, I’ll be speaking at RubyConf in a couple of weeks. I’m giving a presentation with Giles Bowkett and Yossef Mendelssohn called Two Turntables and a Git Repo. It’s gonna be rad. Miss it and DIE.
Chad Fowler has posted a small interview with me on his blag. You should go read it.
Announcing MIDIator
October 20th, 2008
I was just looking at my FeedBurner statistics and noticed that my feed readership has gone up by approximately 100 in the past year. Then I looked at my blog and realized I hadn’t posted anything Ruby-related in 2008. Then I remembered that I’m a Ruby programmer and decided to release some software for the express purpose of blogging an announcement.
Okay, not really. Well. The last part is mostly a lie. I guess. On to the point.
Background
Earlier this year a small publishing concern called Apress (that you may have heard of!) published a most interesting book. It was Practical Ruby Projects, by the lovely and talented Topher Cyll. There’s a link on his page if you want to get it.
Practical Ruby Projects is the book that I have always wanted to write. I would have called it Stupid Ruby Tricks myself, but that’s neither here nor there. The subtitle is “Ideas for the Eclectic Programmer”, and that really gives you an idea of the flavor of what’s inside.
The second chapter is entitled “Making Music with Ruby”, and is a gentle introduction into writing code that can play music. The chapter is based around building an app that can play songs written in simple notation. One of the really awesome things that Topher did, though, was to supply code to interface with the MIDI subsystems on Windows, Linux, and OSX.
Around this same time, Giles Bowkett’s sweet project Archaeopteryx was starting to take off. Giles had also taken both code and inspiration from Practical Ruby Projects, but he had only grabbed the OSX parts. That’s fine, I thought, because I’m on a mac and it works for me.
Then, people started complaining. Not really complaining, but definitely whinging about wanting to play with Archaeopteryx but being stuck on inferior platforms. There was also an issue with the fact that Giles demos Archaeopteryx hooked up to Reason, and Reason costs like $500. You don’t have to use Reason, though, as Shay Arnett so deftly demonstrated at the Hoedown. I have more to say about this, but you’re going to have to wait for RubyConf.
Aaaaaanyway, I decided that I was going to take Topher’s code and bundle it up for you, the masses, to consume. This was made possible in large part by Apress’s total awesomeness in releasing all the code from Practical Ruby Projects under the MIT license. I took his code, refactored it a little bit, wrote some specs and examples, and published it as MIDIator.
How Can
First, install as normal:
$ sudo gem install midiator
Next, do this:
1 2 3 4 5 6 |
require 'rubygems' require 'midiator' midi = MIDIator::Interface.new midi.autodetect_driver midi.play( 84, 0.5 ) |
Thanks to Tobi Reif for pointing out the error in the above example!
You should hear a half-second of middle C. Now, to be fair, I’m leaving out all the information about how to get a working MIDI setup on your machine. I’ll be blogging about that later, though, so if you don’t know how just keep your eyes peeled.
Where Can I…
You can get MIDIator at GitHub or RubyForge, or install it via gems as shown above.
Future blog posts about MIDIator will be tagged, so you can use this link to get all the news that’s fit to blag.
You can read the RDoc at RubyForge.
Stay Tuned!
There’s more coming. In the next few days I’ll be showing you how to get MIDI working on your system. Then I’ll be speaking at RubyConf with Giles and Yossef Mendelssohn. I’ll definitely post some stuff related to my talk around the conference, but you’re going to have to wait for the really fun stuff.
Back on the air!
July 28th, 2008
Hello blogsville!
I think I’ve got things back up and running after an extended vacation from a working Mephisto. We’ll see how it goes.
Controlling a BlinkM from Max/MSP
March 23rd, 2008
A fellow BlinkM enthusiast over at the ThingM GetSatisfaction board asked whether it was possible to control a BlinkM on an Arduino from Max/MSP. I’ve been playing with Max/MSP in conjunction with my newly-completed Monome 40h kit, so I decided to take a stab at it. Here’s the comment I posted on GetSatisfaction:
Turns out it’s actually really, really easy!
Add a swatch. Send its left outlet to a “prepend 1 0 4 0 99”, and send prepend’s outlet to a serial object. For me, my Arduino showed up as port b (send “print” to serial to get a list in the max window), so I set up the serial with “serial b 19200”.
Program BlinkMCommunicator onto the Arduino, drop the BlinkM in the normal position, and you’re set. It’s so easy!
I expanded upon that simple patch and came up with this one, that includes sliders and a menu to select which port to talk to. The menu is not of my design; it was yoinked from Arduino2Max from the Arduino Playground.
Look for more Max/MSP fun soon. I’m really digging this environment.
Monome OSC Proxy in Processing
March 8th, 2008
(I can hear you all going “wtf does that subject line mean”... bear with me)
I recently picked up a monome 40h kit. Assembly was a breeze, but I ordered LEDs from China and they’re not here yet. I’m super anxious to start using my new toy, but it’s hard to tell what’s going on unless you can see the button pads light up.
So what is the enterprising hacker to do? Fake it? OKAY!
I’ve been hacking around with OSC lately… it’s a really cool, extremely flexible network protocol for device control and the like. Read more about it right here on the wikipedia. One of the cool things about the Monome setup is that while the physical device communicates using a serial protocol over USB, the applications communicate via OSC.
Anyway, blah de blah. What I did was use the oscP5 library to intercept the messages between the Monome router and applications. I update the grid based on those messages, and then pass them on to the destination recipient. It works surprisingly well! Here’s a screenshot of the sketch in use, running the flin application:

Remember that input is happening on my real monome. The black disc is a button that I was pressing when I took the screenshot.
This is early software, and as such has problems and limitations. Here’s a copy/paste from the README:
Known Bugs / Issues / Didn’t Do Yet
- Only supports the 40h (and maybe the 64, I dunno)
- High CPU usage due to render strategy
- Doesn’t (yet) support rotation
- Doesn’t support input… probably won’t as I’m not intending to write an emulator, but we’ll see.
- Does not yet support the full OSC dictionary… coming soon?
- Sometimes cells will get “stuck” on during a transition until the next time that cell is updated.
So that’s about it. You can get it from my Subversion:
svn co http://svn.bleything.net/monome/Monome_Display_Proxy
Details about how to use it are in the README. Please email me if you have any troubles.
Wiimote And BlinkM Are love
February 1st, 2008
Long time no blog. Sorry. Tonight I’m going to write about something a little different than normal. There will be no Ruby in this post! Consider yourself warned.
It should be obvious from my recent posts that I dabble in the dark arts of hardware hacking. I recently found out about (and promptly ordered) a new little toy called a BlinkM. BlinkMs are basically smart LEDs… they’re an RGB LED with a small microcontroller that you can interact with over the I2C protocol.
Tod E. Kurt, one of the guys behind the BlinkM, posted some example code which included details on how to use the guts of a Nintendo Wii Nunchuck controller to fiddle with the BlinkM. I decided to take that one step further (or one step back, depending on your point of view) and hack together a similar control without requiring you to take your nunchuck apart.
My setup requires a lot of pieces. First, the Wii remote itself with a connected nunchuck. Next, the DarwiinOSC branch/fork of DarwiinRemote. OSC, for what it’s worth, is Open Sound Control is a networked sound control protocol, sort of like MIDI over the network. It allows devices to send all sorts of information in easy to digest packets.
I’m reading the OSC messages with Processing, the environment on which Arduino based their GUI. In turn, Processing is doing some math on the sensor readings and feeding them to an Arduino via a serial connection. That Arduino is controlling the BlinkM. Complicated? Eh, not as bad as it sounds!
The best way to understand what’s going on is to see it in action. Here’s a short video I created demonstrating the hack:
Some Technical Details
- I had a hell of a time figuring out the magic dance to get the BlinkM initialized and ready for commands. I ended up doing a gross hack which you’ll see in the code below, wherein I set the fade speed inside the update loop. Gross? Gross. For some reason, every time the BlinkM starts up, the fade speed resets to 0.
- I’m using the oscP5 library for Processing to read the OSC messages. OSC is a damn cool protocol! I wonder if there is Ruby code to read/write it…
- The translation of the (x,y) coordinates of the nunchuck’s joystick to displayable colors took some thinkin’. I absolutely suck at math so anything that I did right is purely by chance, heh. I ended up converting the rectangular coordinates to polar coordinates. This is convenient because the polar coordinates look like (r,θ), where r is the distance from the origin and θ is the angle from the origin axis. This maps pretty cleanly onto brightness and hue, respectively, and to make things even easier, the BlinkM can take an HSB-formatted color. I just set the saturation to full-bore and ran with it.
- The BlinkM examples from Tod that I previously mentioned include a sketch called BlinkMCommunicator, which sets up a simple serial <-> I2C translator in the Arduino. I used this to communicate between Processing and the BlinkM.
The Code
The code is available over here. Unfortunately my syntax highlighter doesn’t like Java, so you’ll have to cope with it being monochrome :)
RubyConf stuff
November 16th, 2007
Well. RubyConf was two weeks ago now and I still haven’t completely wrapped my head around it. It was a different experience this year than last (understanding that last year was my first RubyConf), and I’m not sure whether I liked it better. I would have preferred a single track, although I completely acknowledge the reasons why multitrack made sense… I just didn’t like having to make decisions between two talks I really wanted to see, which happened at pretty much every junction.
I particularly enjoyed Ryan Davis’s and Eric Hodel’s talks, which both more or less boiled down to them talking about the tactics they use to write more/better code. That’s the kind of thing I really like to hear about: the ways that other people boost their productivity and output quality. In this case, the people were experts, but it’s fun to hear from newbies too, as they almost always bring new perspective.
Another highlight was Laurent Sansonetti’s talk on how Apple loves Ruby. I can’t really explain how totally awesome this was. Apple really does love Ruby, and the stuff you can do in Leopard with Ruby is astounding. You’ll just have to watch the video.
Speaking of which, one totally awesome thing that may not be universally known is that Confreaks recorded (almost) every session and are publishing the videos on their website. It’s a lot of video to process so things are a little slow in coming, but eventually all of the conference videos will be here. They’ve already published all of the RejectConf presentations... you can see my 3 minutes on IRB history (now with more working) here. The code is available here.
I’ve also arranged to get the raw camera captures for my talk and I’ll be putting together a video of my presentation in a different format later. On that topic, the slides for my presentation are available at this link. They’re under the Creative Commons Attribution-Noncommercial-Share Alike 3.0... the video on Confreaks will be as well, which is slightly different than what their pages say. The non-commercial clause is the only exception.
Also as promised, below is a list of links to the stuff I talked about:
Serial Hardware
- Keyspan USA-19HS USB -> serial adapter — the best USB/serial adapter I’ve found. About $40.
- FTDI FT232R USB -> UART chip — These are only available in surface-mount packaging. You can get one on a breakout board from Sparkfun, if you need it by itself. See the Buy Some Gear section.
- FTDI TTL232R USB -> UART cables — these are USB cables with embedded FT232Rs, available in various configurations. Necessary if you’re using a Boarduino (see below) and handy to have around for other purposes as well.
X10 Home Automation
- x10-cm17a gem / project page
- CM17A FireCracker kit — The FireCracker control module, one appliance module, one transceiver/lamp module, and a remote. Note that these are much cheaper on eBay. See links in the Buy Some Gear section below.
BetaBrite LED sign
- betabrite gem / project page
- 213C-1 sign — this is the model of the sign I demonstrated
Arduino development boards
- Ruby Arduino Development / project page
- Boarduino — the small breadboard-compatible Arduino clone I demonstrated
- Simple Message System — an Arduino library that provides a simple ASCII messaging protocol. Look for Ruby bindings Real Soon Now™
- Prototyping Shield — Note that Sparkfun also sells a ProtoShield. Lady Ada’s is far superior.
- Arduino clones — There are a number of Arduino-compatible boards that are cheaper or have different design goals. I didn’t talk about these, but check out Freeduino and the Bare Bones Board
XBee Radios
- other xbee modules are pin-compatible, so pick the one that best suits your need, and remember that the Series 1 doesn’t fully support ZigBee
- Arduino xbee shield
Buy some gear!
- Keyspan USA-19HS — Froogle it or just hit up your local computer store. I got mine at CompUSA.
- FTDI FT232R — Available on a breakout board from Sparkfun, or from Digi-Key and Mouser as a bare part.
- FTDI TTL232R — Available in all configurations direct from FTDI, or in most configurations from Digi-Key and Mouser. If you’re doing a Boarduino, though, your best bet is Adafruit, because you can get a little price break if you get it bundled…
- X10 gear — eBay. Try this search for “x10 firecracker”.
- BetaBrite — Apparently they’re sold at Sam’s Club. We don’t have those in Oregon so I can’t confirm. I got mine from eBay. I use this search, which catches both “BetaBrite” and “Beta Brite”. You may be able to find other retailers too.
- Arduino — Lots of options here. Sparkfun is a good one, but I prefer Adafruit. I recommend the Starter Pack, which comes with an Arduino, ProtoShield kit, battery, wall wart, USB cable, and some goodies to play with.
- Boarduino — Adafruit. Be sure to tick the box to add the TTL232 cable if you need one. You’re going to have to solder this one… if you just don’t feel like it, email me and we can talk ;)
- Protoshield — Adafruit again. There’s also the Sparkfun one, but it’s more expensive and poorly designed (see the last paragraph in the description on Sparkfun to see what I mean)
- XBee modules — Digi-Key or Mouser. Maybe other places too, but they’re who I’ve used.
- XBee Shield — NKC Electronics, who sells on eBay as nkc_store. I’ve been very pleased with their service. NKC also sells some Arduino clones, for what it’s worth. Sparkfun sells exactly the same thing (albeit with an XBee module) for $80, which is highway robbery. Here’s the link, though, if you feel like throwing your money away :)
RubyConf 2007
October 8th, 2007
So the big (to me) announcement: I’ve been invited to speak at RubyConf 2007 next month! My presentation is called “Controlling Electronics with Ruby”, and you can read the proposal here. It’s going to be fun; I’ll be bringing along some hardware to demonstrate with :)
Also, for my own benefit I put together a calendar of the RubyConf sessions. It’s available here, feel free to grab it. You can probably subscribe to it using iCal or whatever, and if there are changes in the agenda, I’ll update it. It should contain timezones for everything, but I might have missed one or two, so please let me know if it’s wacky for you.
That’s all. See you in Charlotte!
Announcing LAIKA's Open Source Software
September 12th, 2007
On behalf of the entire LAIKA Information Technology department, it is my great pleasure to announce the release of a number of projects developed by the Information Systems group:
- Athenaeum — A “live” web view of the contents of a Delicious Library
- Growl Notifier — A plugin for CruiseControl.rb that sends build notifications to one or more Growl daemons.
- Linen — A framework for building command-line interfaces
- TextMate Bundle — Some of us use TextMate. This bundle includes some helpful commands and snippets that we wrote.
- ThingFish — A network-accessable datastore with extensible metadata
Please note that the ThingFish release is alpha quality, and much has changed between the current download and trunk. Watch for a new release Real Soon™
These projects were all developed to fit needs within our organization, but designed to be useful outside LAIKA as well. They’re released under the BSD license, and are therefore free to use, in every sense of the word.
Where To Get It
The primary source for LAIKA Open Source software is opensource.laika.com. This is a Trac instance, and is the main point of contact for all LAIKA open source projects. Check here first. File bugs here. Read documentation here :)
Downloads will also be hosted at RubyForge, so any of our projects that are available as gems will be installable via the normal gem mechanism. You can view our project page at laika.rubyforge.org and download our files at here.
About LAIKA
LAIKA is an animation studio based in Portland, Oregon (USA). We are currently working on two feature films and a large number of commercial projects. More information is available at laika.com
About LAIKA IS
LAIKA’s Information Systems group is a team of programmers, database administrators, and tech writers inside the Information Technology department. We make the shiny tools that help the rest of LAIKA do their jobs more easily, ease the sharing of information between groups, and solve mission-critical problems (like picking a place to go to lunch).
We believe in open source software. Many of the tools we use in-house are open source, and we feel strongly that we should give back whenever possible.
LAIKA’s IS department is:
- Ben Bleything
- Jeff Davis
- Michael Granger
- Steven J. Hall
- Jeremiah Jordan
- Myra Lavenue
- Mahlon E. Smith
- Anthony Roberts
- Kim Wallmark
How to Contact Us
If you’ve got problems with the code, please file appropriate bugs in our Trac instance. If you’ve got general questions or comments, please email opensource AT laika, dot com.
Announcing Shell-Style History for irb, the fixed edition!
July 30th, 2007
Astute readers will recall that during RubyConf last year, I posted about a little irb hack I’d written that allowed for shell-style history viewing and replay. There was a problem with it, however… replayed lines that made assignments didn’t work. So if you tried to replay
1 2 3 4 |
>> b = 5 => 5 >> b + 10 => 15 |
... you’d get …
NameError: undefined local variable or method `b' for main:Object
from (irb):1
... which sucks. This has now been fixed! Witness:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
>> b = 5 => 5 >> b + 10 => 15 >> exit superx ~...personal/toys/irbhistory > irb >> h [0937] b = 5 [0938] b + 10 [0939] h => nil >> h! 937,938 => 15 |
So that’s pretty cool, yeah? You can get the updated code here. It’s also in subversion, here.
Thanks to Giles Bowkett for pointing out a mis-feature that resulted in all evals returning nil, when you’d probably want them to return in the usual way. This is fixed now :)