Code Monkey home page Code Monkey logo

Comments (8)

derwaldgeist avatar derwaldgeist commented on May 18, 2024 3

+1

For me, this prevents me from using your library. I need to react on all possible OSC messages using the very same handler, since I cannot anticipate what the actual messages will be.

from osc-js.

adzialocha avatar adzialocha commented on May 18, 2024 1

The feature was shipped for version 2.0.0

from osc-js.

adzialocha avatar adzialocha commented on May 18, 2024

Hi @Audiow! Thank you 😺

Yes, wildcards are possible. The library supports OSC address pattern matching. You can read about this here: http://opensoundcontrol.org/spec-1_0-examples#addressparts or here http://opensoundcontrol.org/spec-1_0

-  '?' in the OSC Address Pattern matches any single character
-  '*' in the OSC Address Pattern matches any sequence of zero or more characters
- A string of characters in square brackets (e.g., "[string]") in the OSC Address Pattern matches any character in the string. Inside square brackets, the minus sign (-) and exclamation point (!) have special meanings:
- two characters separated by a minus sign indicate the range of characters between the given two in ASCII collating sequence. (A minus sign at the end of the string has no special meaning.)
- An exclamation point at the beginning of a bracketed string negates the sense of the list, meaning that the list matches any character not in the list. (An exclamation point anywhere besides the first character after the open bracket has no special meaning.)
- A comma-separated list of strings enclosed in curly braces (e.g., "{foo,bar}") in the OSC Address Pattern matches any of the strings in the list.
- Any other character in an OSC Address Pattern can match only the same character.

Please note that this is only possible for sending packages, not receiving (to follow the OSC standard):

When an OSC server receives an OSC Message, it must invoke the appropriate OSC Methods in its OSC Address Space based on the OSC Message's OSC Address Pattern. This process is called dispatching the OSC Message to the OSC Methods that match its OSC Address Pattern. All the matching OSC Methods are invoked with the same argument data, namely, the OSC Arguments in the OSC Message.

See an example here: https://github.com/adzialocha/osc-js/wiki/Basic-Usage#receive-messages

from osc-js.

soundprojects avatar soundprojects commented on May 18, 2024

ah right, that's what I meant: is there any way to respond to every osc message that comes in?

from osc-js.

adzialocha avatar adzialocha commented on May 18, 2024

@Audiow no, thats not implemented yet since it wouldnt' follow the OSC standard (at least how I understand it), but one could think of an extension.

from osc-js.

breedx2 avatar breedx2 commented on May 18, 2024

👍 for this enhancement.

Not only would it help for troubleshooting/logging (like the requester's simple example), but also for those of us who need to do dynamic routing.

My specific use case: I have multiple, dynamic clients connecting to my server. Each of those clients may register an OSC namespace prefix (address prefix) for which it wants to receive messages. Within every namespace are potentially hundreds of methods (param1, param2, ..., paramN). So the overall address space looks like:

/ns1/param1
/ns1/param2
...
/ns1/paramN
/ns2/param1
/ns2/param2
...

If every single possible method (fully qualified address) has to have an .on() set up, it becomes a nightmare to manage! I'd much rather do something like:

osc.on('/ns1/*', message => { 
  // look up the namespace prefix for this address
  var ns = extractNs(message);
  // dispatch message to all clients subscribed to this namespace
  clients[ns].forEach(client => client.send(message));
});

from osc-js.

breedx2 avatar breedx2 commented on May 18, 2024

The OSC 1.0 spec also says:

An OSC Server's OSC Address Space can be dynamic; that is, its contents and shape can change over time.

To me, anyway, that implies that servers may have a general need to pattern match.

from osc-js.

adzialocha avatar adzialocha commented on May 18, 2024

@derwaldgeist sure, I understand. You are welcome to contribute if you feel like making a PR

from osc-js.

Related Issues (20)

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.