Old 03-17-2012, 09:24 AM   #1
captain_caveman
Human being with feelings
 
captain_caveman's Avatar
 
Join Date: Dec 2011
Posts: 999
Default OSC (Protocol) for Dummies (like me)

This thread is only (possibly) relevant if you want to write an app (or (possibly) dig deep into an existing app) to send OSC messages

Following a painful journey to getting a small app to send properly formatted OSC messages to Reaper and a request from Banned to elaborate, I'm distilling the stuff I've learned down here in what should be a jump start to sending OSC messages without reading much (here's the OSC Protocol here though)

Not receiving messages, I haven't touched that yet but the format is the same.

- OSC Packets (the thing that we send over the network) contain either
-- OSC Messages or
-- OSC Bundles (which can contain messages or other bundles (containing other messages (or other bundles) etc etc)

The only thing we need to know about the OSC Packet is that it needs to be in multiples of 32 bits (4, 8 bit bytes). This explains why we need to pad out parts with NULLs (0 value bytes).

We'll just look at OSC Messages, because that's the only thing I've messed around with.......

- OSC Messages contain 3 elements....
-- OSC Address Patterns: The Command
-- OSC Type Tag String: the type of each (if any) arguments that follow
-- Arguments: the values of the arguments we said we were going to send (if any)

A message starts with a forward slash "/" so that OSC knows what follows is a message and not a bundle. So the command "p" is....
Code:
/p
... which needs to be following by a NULL (shown as Z for zero here)...
Code:
/pZ
... and if this isn't a multiple of 4 bytes we need to pad it out make up to 4 bytes (32 bits)...
Code:
/pZZ
... tada!! Send that out over to Reaper and it will hear it as an OSC message and not do anything at all with it because it's just a made up command!

If the command "p" needs an argument then we need to say what it/they are going to be. We put the character "," next in the message which tells the receipient of the OSC Message that there is an OSC Type Tag String coming up.

So if we want an integer argument we....
Code:
,i
.... and, as with pretty much everything in OSC Messages (apart from float and int argument Values (coming next)), it needs a NULL after it and we need to pad it out to 4 bytes if it comes up short...
Code:
,iZZ
.... so the full message so far is....
Code:
/pZZ,iZZ
Next up... numbers.... Grrrr.

Last edited by captain_caveman; 03-18-2012 at 06:15 PM.
captain_caveman is offline   Reply With Quote
Old 03-17-2012, 09:24 AM   #2
captain_caveman
Human being with feelings
 
captain_caveman's Avatar
 
Join Date: Dec 2011
Posts: 999
Default

If, like me, you are hacking things together on a byte by byte basis the different formats of numbers are important to recognise. 32 bit Ints and floats. Both represented by 32 bits (4 bytes in a row) in entirely different ways.

Quote:
Originally Posted by OSC_Protocol
int32
32-bit big-endian two's complement integer

float32
32-bit big-endian IEEE 754 floating point number
Code:
int32
 1 = 0x00000001
 0 = 0x00000000
-1 = 0xFFFFFFFF

float32
 1 = 0x3F800000
 0 = 0x00000000
-1 = 0xBF800000
That's it for now. I have to say that the one thing that totally *(&$ed me up was my final message being lovingly encoded to UTF-8 by the language I am using which completely wrecked it. A value of 255 for example, essential to represent an integer -1 is invalid as a first byte in UTF-8 so I got nonsense out after encoding.

Last edited by captain_caveman; 03-17-2012 at 09:54 AM.
captain_caveman is offline   Reply With Quote
Old 03-17-2012, 09:45 AM   #3
Banned
Human being with feelings
 
Banned's Avatar
 
Join Date: Mar 2008
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
Default

Quote:
Originally Posted by captain_caveman View Post
Following a painful journey to getting a small app to send properly formatted OSC messages to Reaper and a request from Banned to elaborate, I'm distilling the stuff I've learned down here in what should be a jump start to sending OSC messages without reading much [...].
Thanks a bunch, Captain!

I'll add some of my findings here too, so that it hopefully won't be as much of a stumbling block on the road of others who follow the same paths. I managed to kick it out of the way while enjoying a bit of a puzzle, but you never know about the state of the tyres of the next guy on the road...
__________________
˙lɐd 'ʎɐʍ ƃuoɹʍ ǝɥʇ ǝɔıʌǝp ʇɐɥʇ ƃuıploɥ ǝɹ,noʎ
Banned is offline   Reply With Quote
Old 03-17-2012, 10:00 AM   #4
captain_caveman
Human being with feelings
 
captain_caveman's Avatar
 
Join Date: Dec 2011
Posts: 999
Default

No worries, I'm almost certain that stuff is accurate too.
captain_caveman is offline   Reply With Quote
Old 03-17-2012, 11:38 AM   #5
Banned
Human being with feelings
 
Banned's Avatar
 
Join Date: Mar 2008
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
Default

Quote:
Originally Posted by captain_caveman View Post
... tada!! Send that out over to Reaper and it will hear it as an OSC message and not do anything at all with it because it's just a made up command!
Note for the interested reader: if you would now go to the "Learn" feature in REAPER's action menu or for some plugin's parameter bindings, you can make it do almost anything you want, even though it's completely made up (assuming some OSC control surface configuration exists, and is set to allow such bindings). E.g. /p could make REAPER play, if that's what you, the user, want to use as a command for that particular action. If you'd rather use /partytime than /p, or make /p do something entirely different, that is completely up to you.
__________________
˙lɐd 'ʎɐʍ ƃuoɹʍ ǝɥʇ ǝɔıʌǝp ʇɐɥʇ ƃuıploɥ ǝɹ,noʎ
Banned is offline   Reply With Quote
Old 03-18-2012, 11:17 AM   #6
yagonnawantthatcowbell
Human being with feelings
 
Join Date: Aug 2009
Posts: 344
Default

i don't get it...
yagonnawantthatcowbell is offline   Reply With Quote
Old 03-18-2012, 11:42 AM   #7
gofer
-blänk-
 
gofer's Avatar
 
Join Date: Jun 2008
Posts: 11,359
Default

Me don't either, but that just proves we're not Dummies
I will need a tutorial for the extreme hardcore dimbulb, it seems.

Doesn't mean it's not appreciated, Capt'n. It's true that I didn't understand a thing, but the comment is meant tongue in cheek nevertheless . Pretty sure it all would become much clearer if I just dove into it and actually tried some of the stuff out.
gofer is offline   Reply With Quote
Old 03-18-2012, 05:05 PM   #8
captain_caveman
Human being with feelings
 
captain_caveman's Avatar
 
Join Date: Dec 2011
Posts: 999
Default

I suppose it's just another way of partly explaining the OSC protocol, in terms of how messages need to be constructed from the POV of someone writing an app/digging deep into an existing app.

For example reading the protocol, the "multiple of 32bit" thing in terms of how it related to different parts of a message only sunk in when studying the examples of bytes in the official docs. Also, because I was so keen to get going with beaming stuff to Reaps without learning the new development environment/language I was using, the format of numbers tripped me up.

So the chances of this thread being useful to anyone at all are slim... but at least there's a chance.
captain_caveman is offline   Reply With Quote
Old 03-18-2012, 05:24 PM   #9
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 15,733
Default

To provide some context, this thread is similar to explaining MIDI by talking about how status bytes always have the 0x80 bit set. That is important basic information for a programmer who is constructing raw MIDI messages, but the vast majority of MIDI users don't ever need that level of technical detail.
schwa is offline   Reply With Quote
Old 03-18-2012, 06:17 PM   #10
captain_caveman
Human being with feelings
 
captain_caveman's Avatar
 
Join Date: Dec 2011
Posts: 999
Default

Good point, context hopefully provided in first post.
captain_caveman is offline   Reply With Quote
Old 03-18-2012, 06:23 PM   #11
Rellik
Human being with feelings
 
Join Date: Jul 2009
Posts: 64
Default

I've found that there are OSC libraries available in just about every language - not necessarily super well supported or documented, but it's really a very simple protocol, so if it works, it works. I've sent OSC data from Python and C# so far - I found it a lot easier than trying to send OSC from PD actually :P
Rellik is offline   Reply With Quote
Old 03-18-2012, 06:46 PM   #12
captain_caveman
Human being with feelings
 
captain_caveman's Avatar
 
Join Date: Dec 2011
Posts: 999
Default

Quote:
Originally Posted by Rellik View Post
I've found that there are OSC libraries available in just about every language - not necessarily super well supported or documented, but it's really a very simple protocol, so if it works, it works. I've sent OSC data from Python and C# so far - I found it a lot easier than trying to send OSC from PD actually :P
My problem was that MoSync, the C/C++ cross platform native mobile app dev SDK that I've been using does not support UDP network transmission or, for that matter, a OSC library and that Basic4Android - that does support UDP - does not have an OSC library or raw data transmission that includes unformatted strings, ints and floats without the use of another library that, inconveniently enough, doesn't have "OSC" in the title.

Btw MoSync supports every mobile OS (to greater or lesser extents) so it's a tad frustrating that it doesn't support UDP.

So, for me OSC isn't supported on 100% of platforms I have tested, hence this post.
captain_caveman is offline   Reply With Quote
Old 03-18-2012, 08:42 PM   #13
Rellik
Human being with feelings
 
Join Date: Jul 2009
Posts: 64
Default

Quote:
Originally Posted by captain_caveman View Post
So, for me OSC isn't supported on 100% of platforms I have tested, hence this post.
Have you considered developing with Adobe AIR? AS3 has several OSC libraries.

Not to discourage you from rolling your own, just pointing out alternative solutions for others who may view this thread as well!
Rellik is offline   Reply With Quote
Old 03-19-2012, 03:54 AM   #14
captain_caveman
Human being with feelings
 
captain_caveman's Avatar
 
Join Date: Dec 2011
Posts: 999
Default

Quote:
Originally Posted by Rellik View Post
Have you considered developing with Adobe AIR? AS3 has several OSC libraries.

Not to discourage you from rolling your own, just pointing out alternative solutions for others who may view this thread as well!
Not at all, the more info the better. I've already rolled my own address sending functions so it's just sending bundles and parsing received packets I need to do now.

Basic4Android allows easily writing additional libraries in Java for access through its implementation of VB so once I'm done I'll probably do that so nobody else has to experience my pain.
captain_caveman is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 02:44 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.