maybites/NodeOSC

indexed addresses

Closed this issue · 9 comments

Hello,
is there a way to deal with indexed addresses, for example:
I send to blender addresses formatted like:
/track/1/x
/track/2/x
track/3/x
.........
track/n/x

to control x position of object named icosphere.1 ,icosphere.2, icosphere.3 ....... icosphere.n

I don't know if it's really clear but in depth I want to know if it's possible to declare only one handler for all these addresses?

Currently this is not possible. Right now I have no idea how to implement this, though it should be possible. I will add it as a feature request.

I saw something interesting in /pythonosc/dispatcher.py file comments (line 104):

def handlers_for_address(self, address_pattern: str) -> Generator[None, Handler, None]: """yields Handler namedtuples matching the given OSC pattern.""" # First convert the address_pattern into a matchable regexp. # '?' in the OSC Address Pattern matches any single character. # Let's consider numbers and _ "characters" too here, it's not said # explicitly in the specification but it sounds good. escaped_address_pattern = re.escape(address_pattern) pattern = escaped_address_pattern.replace('\\?', '\\w?') # '*' in the OSC Address Pattern matches any sequence of zero or more # characters. pattern = pattern.replace('\\*', '[\w|\+]*') # The rest of the syntax in the specification is like the re module so # we're fine. pattern = pattern + '$' patterncompiled = re.compile(pattern) matched = False

"?" and/or "*" characters could be used in place of index??

you are correct. the pythonosc library accepts * (and probably '?'). And this works already. but doesn't help you because the matched value of the address is not passed on...

Maybe something interesting to implement wilcards in NodeOSC?:
https://python-osc.readthedocs.io/en/latest/dispatcher.html?highlight=wildcard#example
But I'm not sure how to...

python-oscblend
Finally, I'm able to use '*' character as an index and it works(only as input but I'll continue investigations to make it works as output...).
I'm also able to launch a function (here: my_function) hosted in an internal sript (here: my script)!
All thanks python-osc!!

neat.

though I think about expanding the python osc wildcard thingy with:

/track/#/stack/#

where the # inside the address will be turned into arguments:

so when nodeOSC receives:

/track/5/stack/1 777 888

it will prepend '5' and '1' to the arguments tupple:
[5, 1, 777, 888]

@dewiweb : can you provide the referenced script? I will add your solutions to the wiki..

@maybites :
holo_python_cl

holo_python_cl.zip

In 'holo_python_cl.zip' archive you can retrieve my work-in-progress version of *.blend file with internal texts attached!

Take a look at the 'holo_in' internal text to see how "*" character is filtered (based on an internal dictionnary named 'properties').

Hope it helps!

thanks, appreciate it.

@dewiweb : I was able to stream your code even further:

https://github.com/maybites/blender.NodeOSC/wiki/Custom-Function-Calls

the exec() call is not necessary, there is alread an exec() happening in the background...