Build OSC into Ruby objects
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
lib
test
LICENSE
README.rdoc
Rakefile

README.rdoc

OSC Access

A simple way to bind OSC directly to Ruby classes and objects.

Features

  • Works with MRI 1.9 and JRuby (in 1.9 mode)

  • Binding OSC events can be done by class or by instance

  • Network resources are invisible to the user even when shared or multiplexed

  • Shortcuts for common tasks associated with OSC such as translating numeric values from one range to another

  • Make OSC-accessible objects discoverable on a network using Zeroconf

Requirements

Requires eventmachine and osc-ruby. These should install automatically with the gem

For Zeroconf support, dnssd is required.

Installation

gem install osc-access

Usage

require "osc-access"

In this example when OSC messages for /1/fader1 are received, velocity= is called and another message is outputted confirming that the first message was received

class Instrument

  include OSCAccessible

  osc_receive("/1/fader1", :translate => { :remote => 0..1, :local => 0..127 }) do |instance, val|
    instance.velocity = val
    instance.osc_send("/receipt", "val set to #{val}")
  end

  def velocity=(val)
    puts "setting velocity to #{val}"
  end

end

i = Instrument.new
i.osc_start(:input_port => 8000, :output => { :host => "192.168.1.8", :port => 9000}).join

The :translate option means that the first OSC argument will be translated from a number between 0 to 1 to the analogous value between 0 and 127 before being passed to the code block.

Or, here is an example that produces the same object, but it's created by passing a Hash map to the instance:

map = {
  "/1/fader1" => { 
    :translate => { :remote => 0..1, :local => 0..127 }
    :action => Proc.new do |instance, val| 
      instance.pitch = val
      instance.osc_send("/receipt", "val set to #{val}")
    end
  }
}

class Instrument

  include OSCAccessible

  def pitch=(val)
    p "setting pitch to #{val}"
    ...
  end

end

i = Instrument.new
i.osc_start(:map => map, :input_port => 8000, :output => { :host => "192.168.1.8", :port => 9000}).join

Here’s a blog post that explains these examples in further depth and much more.

Other Documentation

License

Licensed under Apache 2.0, See the file LICENSE

Copyright ©2011 Ari Russo