Git Product home page Git Product logo

osc-ruby's Introduction

An OSC client for Ruby

<img src=“https://travis-ci.com/aberant/osc-ruby.svg?branch=master” alt=“Build Status” />

opensoundcontrol.org/

Description

This OSC gem originally created by Tadayoshi Funaba has been updated for ruby 1.9 compatibility. I’ve made a point to make this code as expressive as possible and provide a test suite for confident hacking. It also should be flexible enough to support most crazy ideas.

Compatible with ruby 1.9, 2.* and jruby

Install

sudo gem install osc-ruby

for the EMServer, you will need EventMachine

sudo gem install eventmachine

Event Machine Basic example

require 'rubygems'
require 'osc-ruby'
require 'osc-ruby/em_server'

@server = OSC::EMServer.new( 3333 )
@client = OSC::Client.new( 'localhost', 3333 )

@server.add_method '/greeting' do | message |
  puts "#{message.ip_address}:#{message.ip_port} -- #{message.address} -- #{message.to_a}"
end

Thread.new do
  @server.run
end

@client.send( OSC::Message.new( "/greeting" , "hullo!" ))

sleep( 3 )

Credits

Originally created by…

Tadayoshi Funaba

www.funaba.org/en/

thx also to Toby Tripp, Brian McClain, Andreas Haller, James Hughes, Rapofran, and Daniel Dickison

osc-ruby's People

Contributors

aberant avatar brianmmcclain avatar danieldickison avatar kachick avatar kuma-giyomu avatar rapofran avatar samaaron avatar xavriley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

osc-ruby's Issues

osc-ruby socket error after a certian amount of messages

I have a script which sends osc messages to a server repeatedly, if i run it on jruby or using ruby-osc instead it functions but when i run it with standard ruby and osc-ruby (2.0.0 and 1.9.2 tested) it will give the following error after a few minutes. the socket information is the same each time and works for a while.
`connect': getaddrinfo: nodename nor servname provided, or not known (SocketError)

I've attached the send method for reference.
Can anyone shed any light?

def msg_send(message, channel, argu)
@client = Client.new("localhost", 10002)
@client.send Message.new("#{message}#{channel}", argu)
# puts "#{message}#{channel}", argu
end

Typo causes exception

Greetings and thanks for this lib. Please check the following line for a typo.

https://github.com/aberant/osc-ruby/blob/master/lib/osc-ruby/server.rb#L61

mesg should be message

/Users/guest/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/osc-ruby-1.1.4/lib/osc-ruby/server.rb:61:in `block in dispatch_message': undefined local variable or method `mesg' for #<OSC::Server:0x00007f9aa113a0e0> (NameError)
Did you mean?  message

The server still seems to work in my test app after the exception, but obviously something isn't going according to plan. See my code below. This only happens when the sleep is there, which I don't need, but I thought you'd want to know. Cheers.

EventMachine.run do
  server = Server.new $PORT

  puts "OSC server started on port #{$PORT}"

  server.add_method /.*/ do |message|       # this will match any address
    p "/.*/:       #{message.ip_address}:#{message.ip_port} -- #{message.address} -- #{message.to_a} }"
  end

  server.add_method %r{foo/.*} do |message| # this will match any /foo node
    p "%r{foo/.*}: #{message.ip_address}:#{message.ip_port} -- #{message.address} -- #{message.to_a} }"
  end

  server.add_method "/foo/bar" do |message| # this will just match /foo/bar address
    p "'/foo/bar': #{message.ip_address}:#{message.ip_port} -- #{message.address} -- #{message.to_a} }"
  end

  server.add_method "/exit" do |message|    # this will just match /exit address
    exit
  end

  Thread.new do
    server.run
  end

  sleep 1
  # hit Control + C to stop
  Signal.trap("INT")  { server.stop }
  Signal.trap("TERM") { server.stop }

  client = Client.new 'localhost', 8001
  client.send( OSC::Message.new( "/greeting" , "hullo!" ))

  client.send Message.new('/foo/bar', 1, 1.2, 'a string')
  client.send Message.new('/foo/bar/zar', 1, 1.2, 'a string')
  # client.send Bundle.new(Time.now + 2, Message.new('/exit'))

end

Route Part of a Namespace

Hi,

I'm doing some work with the osc-ruby library and it's been great so far, but I've run into a problem. Basically, I'd like to route part of a namespace and pass on what follows (similarly to how osc-route operates in Max/MSP). For example, if I'm monitoring the following namespace:

"/example/test/"

and I send the message:

"/example/test/my/namespace 5.0"

I'd like osc-ruby to pass on "/my/namespace 5.0"

Is there a simple way to do this?

Thanks,

Graham.

binding EMServer to localhost does not work when using devices that are not on the same ip

def run
EM::run { EM::open_datagram_socket "localhost", @PORT, Connection }
end

the above code caused me problems when trying to get TouchOSC on an iPad to comunicate with my Mac (Snow Leopard 10.6.3, ruby 1.8.7). A local client/server would work but nothing from the iPad was being received. iPad to other osc compatible apps does work.

changing the EMServer class to accept an address parameter (below) and then passing in my local ip (i.e. 192.168.1.100) got it all working but is not really ideal when using DHCP.

class EMServer

def initialize( address = "localhost", port = 3333 )
  @port = port
  @address = address
  setup_dispatcher
  @tuples = []
end

def run
  EM::run { EM::open_datagram_socket @address,  @port, Connection }
end

Thanks

updated gem?

Hey, just a gentle request to push out an update to this gem. I was trying to use the new ip_address info in the message, and wasted a bit of time trying to figure out why it was throwing an exception... only to find that those bits were missing from the rubygems version of the gem. :P
I've pulled it from github for the time being, so it's low priority.
Thanks!

Silently rescuing exception

It seems like osc-ruby is silently rescuing exception inside the message handlers.

If I raise an arbitrary exception inside a block passed to add_method the exception is silently handled somewhere. My most base example was to take the example code and add raise my own exception:

require 'rubygems'
require 'osc-ruby'
require 'osc-ruby/em_server'

@server = OSC::EMServer.new( 3333 )
@client = OSC::Client.new( 'localhost', 3333 )

@server.add_method '/greeting' do | message |
  puts "#{message.ip_address}:#{message.ip_port} -- #{message.address} -- #{message.to_a}"
  raise Exception.new "This is an exception"
end

Thread.new do
  @server.run
end

@client.send( OSC::Message.new( "/greeting" , "hullo!" ))

sleep( 3 )``` 

And I get nothing.

Sharing a socket for client and server

I have the following application scheme:
There is a OSC UDP server that has some properties. I connect to it and can subscribe to property changes by sending to "/xremote" periodically. The server will then send me updates on properties to the port I sent the subscription message from. So I need to receive from the same socket as I use for sending.

I use the following workaround:

@client = OSC::Client.new('10.1.2.3', 1234)
@server = OSC::EMServer.new(99999)
socket =  @client.instance_variable_get(:@so)

def @server.run(s)
  EM.error_handler{ |e|
    Thread.main.raise e
  }

  EM.run do
    EM::attach s, OSC::Connection
  end
end

It would be nice to have the possibility without a hack.

Numeric overrides collide with ActiveSupport

Hi, not sure if you're still maintaining this package. I wanted to try using this in a Rails project, but ended up with some errors in other packages because of the time method overrides. The return values from seconds, minutes, etc. are different than those from the same methods in ActiveSupport.

Is there a way to disable the class extension by any chance since all of those methods are already provided by Rails?

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.