aberant / osc-ruby

Open Sound Control Library for Ruby
MIT License
94 stars 16 forks source link

Route Part of a Namespace #3

Open sidechained opened 13 years ago

sidechained commented 13 years ago

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.

aberant commented 13 years ago

OSC::Message has an address method and OSC supports wildcards. i'm wondering if something like this wouldn't help you

@server.add_method "/example/test/*" do |message|
  new_address = message.address.gsub('/example/test', '')

  @client.send(OSC::Message.new(new_address, *message.to_a))
end

let me know if it doesn't help and i'd be more then glad to offer further assistance.

sidechained commented 13 years ago

Thanks, that's great and mostly solves my problem. I'm pretty new to Ruby, so had missed the address method. Guess I need to learn more about how to dig into libraries to see what they can do.

One problem that remains is that the wildcard will only route a single trailing namespace, so for example it will route "/example/test/this" but not "/example/test/this/that". In my case I need it to be able to pass anything, regardless of how many namespaces deep the trailing address is.

As far as I can see, I don't think this is supported directly by the OSC spec, but it is something that the osc-route object in Max handles very well. Any ideas on how I might accomplish this?

Graham.

On Fri, Jul 15, 2011 at 7:33 PM, aberant < reply@reply.github.com>wrote:

OSC::Message has an address method and OSC supports wildcards. i'm wondering if something like this wouldn't help you

@server.add_method "/example/test/*" do |message|
 new_address = message.address.gsub('/example/test', '')

 @client.send(OSC::Message.new(new_address, *message.to_a))
end

let me know if it doesn't help and i'd be more then glad to offer further assistance.

Reply to this email directly or view it on GitHub: https://github.com/aberant/osc-ruby/issues/3#issuecomment-1584034

aberant commented 13 years ago

Ah, i better understand what you are trying to do now. I've been thinking about implementing some routing features in the past and i think this is the push i need to implement them. "The simplest thing that could work" would probably be a new wildcard character. it would be something like "/example/test/**" that will match ALL sub containers of /example/test. you could then easily implement your own routing code for your needs. does that sound reasonable to you?

sidechained commented 13 years ago

It does make a lot of sense, although I'm in two minds at to whether the wildcard is even needed. Shouldn't the default behaviour be to discard the matching part of the address and pass on what follows? e.g.

Incoming message = /example/test/this/one 1

Namespace to match = /example/test

Result = /this/one 1

Having looked at the OSC 1.0 spec it doesn't really cover this kind of situation in detail, instead it just states:

A part of an OSC Address Pattern matches a part of an OSC Address if every consecutive character in the OSC Address Pattern matches the next consecutive substring of the OSC Address

So it mentions that they can match, but it does not define what should occur when they do. I guess the question is can you see any situations where partial matching would not be desirable, if so the I guess the double asterisk would be best.

If this makes sense, how long do you think it would take to implement? It would be really useful for the project I'm working on right now (deadline in two weeks!)

Thanks,

Graham.

On 17 Jul 2011, at 17:27, aberant < reply@reply.github.com> wrote:

Ah, i better understand what you are trying to do now. I've been thinking about implementing some routing features in the past and i think this is the push i need to implement them. "The simplest thing that could work" would probably be a new wildcard character. it would be something like "/example/test/**" that will match ALL sub containers of /example/test. you could then easily implement your own routing code for your needs. does that sound reasonable to you?

Reply to this email directly or view it on GitHub: https://github.com/aberant/osc-ruby/issues/3#issuecomment-1591778

aberant commented 13 years ago

I've got the double splat code up on this branch https://github.com/aberant/osc-ruby/tree/double_splat

pull it down and then "rake gem" it to create a gem for your project to use instead of the official one

this code gives you a \ matcher to match every sub container like

@server.add_method "/example/test/**" do |message|
  new_address = message.address.gsub('/example/test', '')

  @client.send(OSC::Message.new(new_address, *message.to_a))
end

i'd like to hold off creating a method for routing right now until i can get a better idea of the ways you would use it. please let me know if this helps.

sidechained commented 13 years ago

Thanks, that's great, I'll get a chance to try it out in the next couple of days.

Graham.

On 18 Jul 2011, at 18:34, aberant reply@reply.github.com wrote:

I've got the double splat code up on this branch https://github.com/aberant/osc-ruby/tree/double_splat

pull it down and then "rake gem" it to create a gem for your project to use instead of the official one

this code gives you a \ matcher to match every sub container like

@server.add_method "/example/test/**" do |message|
 new_address = message.address.gsub('/example/test', '')

 @client.send(OSC::Message.new(new_address, *message.to_a))
end

i'd like to hold off creating a method for routing right now until i can get a better idea of the ways you would use it. please let me know if this helps.

Reply to this email directly or view it on GitHub: https://github.com/aberant/osc-ruby/issues/3#issuecomment-1603490

sidechained commented 13 years ago

HI,

Just had chance to test this tonight after getting bogged down in installing Lion on my mac. Seems to be working well so far, so thanks! I think it would be useful to have a method which does the stripping off of the the OSC address for you, but for now it's not a problem to add that in. I'll keep you posted on when the new version of the project goes up on Github, that way you'll get a better idea of how I'm using it.

Graham,

On Tue, Jul 19, 2011 at 2:51 PM, Graham Booth graham.r.booth@gmail.comwrote:

Thanks, that's great, I'll get a chance to try it out in the next couple of days.

Graham.

On 18 Jul 2011, at 18:34, aberant <reply@reply.github.com

wrote:

I've got the double splat code up on this branch https://github.com/aberant/osc-ruby/tree/double_splat

pull it down and then "rake gem" it to create a gem for your project to use instead of the official one

this code gives you a \ matcher to match every sub container like

@server.add_method "/example/test/**" do |message|
 new_address = message.address.gsub('/example/test', '')

 @client.send(OSC::Message.new(new_address, *message.to_a))
end

i'd like to hold off creating a method for routing right now until i can get a better idea of the ways you would use it. please let me know if this helps.

Reply to this email directly or view it on GitHub: https://github.com/aberant/osc-ruby/issues/3#issuecomment-1603490

msonnabaum commented 12 years ago

Needed the double splat today to forward all osc messages to a non-osc server, and that branch worked great for me.

Would very much like to see it merged in!

aberant commented 12 years ago

i've been thinking about this and think i'll do it even tho it's not part of the OSC spec. maybe it will encourage them do include it in the spec. might take me a little bit to update the documentation

aberant commented 11 years ago

i've merged this to double splat branch into master, but it's not in the v1.0.0 gem. i want to update the docs and examples before i include it in the gem. if you use bundler, just point it at the github repo for now to get these features.

gem "osc-ruby", :git => "git://github.com/aberant/osc-ruby.git"