kivy/oscpy

Feature request: catch none matching address

ptrdvds opened this issue · 8 comments

What really would be helpfull is the possibility to have a catch none matching address.
Something like:

@osc.address(None):
def catch_none_matching(values)
...

This way you can do advanced matching in the "catch_none_matching" function.

Just my two cents.
Regards, Peter

I was looking at the OSC 1.0 specification for a "default" semantic of some sort, but i don't seem to find it, so i guess it's up to us.

I think i would prefer

@osc.default()
def catch_none_matching(address, values)
    ...

But i'm not entirely sure if it's worth defining a new method for that.

Not being in the OSC 1.0 specification and deviate from it can be useful, maybe not for you but for the users of the library.

My use case:
I am writing a osc proxy that puts everything it receives from an osc sender in a message queue.
Then it is up to the subscriber to consume the message and do something with it.
The consumers can be any kind of device or program that reacts on a given message.
It would be tedious to write every address i possibly have to handle in the osc server code.

Thank you for your time and effort!

Cheers :)

That does make sense, i guess it's currently possible already by subclassing OSCThreadServer, and overriding _match_address, but i agree it's a bit hacky, i'll look into adding that.

Open questions:

  • Should it only be called when no other address matched, or for all messages?
  • currently the callback doesn't receive the address the message was sent to, so registering this default handler would need to be different in that regard.

Both of these could be options, but i'd rather not have too many options around, to keep the code simple, so input on that is welcome.

It should only be called when no other address matched.
This way we can handle an incoming address that is not matched in an appropriate manner.

I went for the simplest way, since it would be weird to have multiple default handler, so it's a simple attribute that is called if nothing else matched.

I also added a way for handlers to get the address that they were called from, since there can be parameters for this with advanced_matching.

Thank you, i will test it asap.

did you manage to test?

Hi,

I was not able to test earlier, sorry about that.
The solutions works for me, it is easy and clean.

Thank you very much.