Showing posts with label DSL. Show all posts
Showing posts with label DSL. Show all posts

Sunday, March 25, 2012

MicroOSC: a Ruby DSL for OSC

Being on my way to the west coast and out of arm's reach of the synths, I've had a few hours to switch gears and put together a quick Ruby gem, MicroOSC. It's a utility and DSL for dealing with OSC messaging.

gem install micro-osc

I applied the same principle to OSC that I applied to MIDI with MicroMIDI: distilling the simplest messenger interface that I could think of.

Unlike MIDI, OSC deals with generic user-defined messages. This eliminates the need for describing different concrete message types, something that added a lot complexity to MicroMIDI.

MicroOSC can function as a server, a client or both. In this example, I'll demonstrate them separately, having the two programs talk to each other over a local network.

Here is a server:

require "osc"

OSC.using(:input_port => 8000) do

  receive("/greeting") { |val| p "received #{val}" }

  p "Ready to receive OSC messages on port(s) #{input_ports.join(', ')}..."

  wait_for_input

end

Once you have this running, you should see "Ready to receive OSC messages..." in your Ruby console. Switch to another window and run this client program:

require "osc"

o = OSC.using(:output => { :host => "localhost", :port => 8000 })
o.out("/greeting", "hullo!")

After running it, flip back to your server program and see “received hullo!”, confirming that your two programs were in fact talking to each other!

Notice that in the second program I didn't use a Ruby block style. Doing it this way would generally be better for live coding, and probably some other scenarios as well.

That's it!

Look for another post with real-world examples, advanced techniques and combining with MicroMIDI soon.

http://github.com/arirusso/micro-osc

Wednesday, August 31, 2011

MicroMIDI: a Ruby DSL for MIDI

After a month of moving I'm finally getting back into some music projects. I've got some more flashy things in the works but first here is a Ruby DSL called MicroMIDI that brings all of the MIDI projects mentioned in this post together along with some new tricks in to a package a bit more suited for live coding and one-off scripts.

Being that it's an interface for four libraries, there's a lot of functionality. I break down each concept in the following posts:

http://github.com/arirusso/micromidi