Monday, November 15, 2010

Jarre's 'Laser Harp' Sound for Propellerheads Reason

Those of you familiar with the music of Jean Michel Jarre will probably have heard, and possibly seen, his Laser Harp. It's a crazy instrument played by passing the hands through laser beams. The Laser Harp has been a feature at many of his concerts over the years and while it's mostly for show, I've always loved the sound, which is generated by an Elka Synthex synthesizer.

I set about recreating the Laser Harp sound in Propellerheads Reason, using Reason's Thor synthesizer and a few supporting effects. I'm very happy with the results and thought I'd share them.

If you have Reason Version 4 or higher, you can download a copy of the Reason patch here. If you can improve upon it, then please let me know.

Have fun.

Wednesday, November 03, 2010

Mac OS X Java Update breakage.

I just knew I shouldn't have let Mac OS X apply the recent Java update. Just a couple of days after the update I had reason to upgrade the rjb ('Ruby Java Bridge') gem. The upgrade process exploded in my face with the following error:

checking for jni.h... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

The problem appears to be missing Java supporting sources that the most recent Java update removed. Luckily, I found the solution over at the nicely named Kick me in the nuts blog. For your convenience here are the magic incantations:

Step 1: Go to http://connect.apple.com and download and download Java for Mac OS X 10.6 Update 3 Developer Package. You'll need a registered Apple Developer account, but it's free.

Step 2: Install it.

Step 3: Open a Terminal.app window and type:

sudo -s
cd /System/Library/Frameworks/JavaVM.framework/Home
ln -s /Library/Java/JavaVirtualMachines/1.6.0_22-b04-307.jdk/Contents/Home/src.jar .
ln -s /Library/Java/JavaVirtualMachines/1.6.0_22-b04-307.jdk/Contents/Home/docs.jar .

After the above, developer calm should be restored.

Sunday, October 31, 2010

Using StormMQs Messaging Cloud with Ruby

A little while back I was asked by Ross Cooney of StormMQ to write a Ruby client for their enterprise class managed message queueing service. It was a fun little project. The client code is open source and is hosted on GitHub and we've also published it as a gem for easy installation. What follows is a tutorial explaining how to get up and running with StormMQ's service using the Ruby client.

The first thing you'll need is an account with StormMQ, so head on over to their site and register. Registration is free, non-binding and gives you access to the free cloud based message queue service.

Next you'll need to install the Ruby client. The easiest way to do this is via the gem. Open a command line and type:


gem install stormmq-client


This will install the client and its dependencies on your system.

For this tutorial we're going to write some simple code to publish a test message to a queue and then read it back. Since message queues are most often used to build loosely coupled systems that communicate asynchronously via one of more queues, we'll separate the publisher and consumer of the test message by writing each as an independent script.

Let's start with the publisher. Launch your favourite text editor, or IDE, paste in the following code and save it as 'publish.rb':


#!/usr/bin/env ruby

# Before we can call the client we need to require it!
require 'rubygems'
require 'stormmq/amqp'

# For convenience we'll create a hash of the required connection options.
client_options = {
:user => 'my_username',
:pass => 'a_very_looooooong_password',
:company => 'my_username',
:system => 'my_username',
:environment => 'development'
}

# Connect to the AMQP service using the options configured above.
# Note, the run() method creates the connection and executes
# the code in the block. When the block terminates, the connection
# is closed.
StormMQ::AMQPClient.run(client_options) do |client|

# Declare a queue on the exchange
queue = client.queue('test1')

# Publish (submit) our test message to the new queue.
queue.publish('Hello World!')
end


The above code will open a connection to StormMQ's service, using your account details (you did use your account details, right?). It will then declare a queue called 'test1', publish the traditional 'Hello World' to the queue and close the connection.

Run it from the command line with

ruby publish.rb


That's all well and good, but let's see if we can re-connect to the queue and read the message from it. Returning to the text editor or IDE, open a new file and paste in the following:


#!/usr/bin/env ruby

require 'rubygems'
require 'stormmq/amqp'

# Use the same settings as before
client_options = {
:user => 'my_username',
:pass => 'a_very_looooooong_password',
:company => 'my_username',
:system => 'my_username',
:environment => 'development'
}

StormMQ::AMQPClient.run(client_options) do |client|
queue = client.queue('test1')

# Read the message from the queue and display it.
puts queue.pop[:payload]
end


Save the new file as 'subscribe.rb' and run it as follows:


ruby subscribe.rb


All going well, this should print 'Hello World!' on screen. Congratulations! You've just written your first code to talk to an enterprise class message queuing system.

The Ruby client is actually a thin wrapper around the Bunny library, which is an AMQP compliant ruby client. My contribution provides the extra bits needed to support StormMQ's virtual host configuration. My client is also a REST client for StormMQ's configuration system to allow customers to manage their systems. We'll take a look at the REST component of the client in a future blog post.