Just the Best Parts: Open Sound Control - Chapter 2.04

The finished, cleaned-up, copy-edited version of this book is available for purchase in PDF, mobi, and epub formats. You get all three formats when you buy the book. Plus, the paid version is where updates are made and contains content not available in the Web version.

Buy it now and get the most recent content. »

Pattern matching

Sensible hierarchies are also good because OSC allows for pattern matching. Suppose, for example, you have a stage lighting system that defines messages for setting the brightness of any given light. Perhaps you define messages like these:

/stage/lights/1/brightness f

/stage/lights/2/brightness f

/stage/lights/3/brightness f

It’s a small stage so there are only three lights.

For any given light you can send a message and pass along a decimal value (AKA floating-point number) to indicate the brightness. 0.0 means completely off; 1.0 means as bright as the light can be. These message behave much like slider controls you might have for your lights at home.

Note the use of the f in the message description. That’s the type tag for floating-point. But you knew that already.

Now, with this system, you can control any light you like, and if you want them all to be the same value could send three messages, one for each light, passing along the same value:

/stage/lights/1/brightness 0.60

/stage/lights/2/brightness 0.60

/stage/lights/3/brightness 0.60

That will work, and assuming your OSC set-up is decent it should appear that all the lights are changing at once.

But it’s kind of inefficient, and there’s always the chance of a mistake where a light gets omitted or is passed a different value. Or perhaps there’s a transmission error, and one of the message never makes it to the OSC server.

Using OSC pattern matching, you could instead send a single message:

/stage/lights/*/brightness 0.60

The asterisk is a wild-card placeholder, and in an OSC system that supports pattern matching it means “apply this message to any that would match if you swapped in values for the wild-card.”

In this example, a single message is used to set all lights to 60% brightness.

Another advantage to using a single message with pattern matching is that because it applies to all matching address patterns it means you don’t have to change your messages if lights are added or removed.

Keep in mind that not everything that handles OSC will implement pattern matching. For example, the current version of Renoise (2.8.1) does not do any pattern matching.

Next page

comments powered by Disqus

The finished, cleaned-up, copy-edited version of this book is available for purchase in PDF, mobi, and epub formats. You get all three formats when you buy the book.

The paid version is also more current and has additional content not available in the Web version.

Buy it now and get the most recent content. »