Forum

You must be logged in to post Login


Lost Your Password?

Search Forums:


 






Wildcard Usage:
*    matches any number of characters
%    matches exactly one character

Sending and Receiving OSC Bundles

UserPost

6:44 am
October 13, 2010


fraguada

Member

posts 4

Post edited 7:45 am – October 13, 2010 by fraguada


Hello,

Paul, we have spoken before.  My name is Luis.  You have been kind enough to answer several of my questions.  We have a little plugin we wrote with your great Bespoke Library.  Somehow, we have overlooked implementing sending and receiving of OSC Bundles.  Do you have any examples of the Server/Client Demos which show the sending and reception of OSC Bundles?  I have been trying to just send bundles to the the demo client from another program (processing), but it does not seem to work.  Everytime I do so, I get an InvalidCastException was unhandled in line 136 of the OSCPacket class.

 

I know there are a bunch of things that could be going wrong, but if you have any examples of the bundle functionality, it would be greatly appreciated.  (I am currently digging into my past emails to recall our last correspondance.  I have unfortunately been too busy to work on this, but I have a bit of time in the next couple of days.)

 

I have attached pictures of how it is working in the plugin.  Note, this is a different implementation, and not the Demo Client.  In the picture you see that it can receive packets just fine.  Below that is the result when I send a bundle.  So it does receive data, but it seems it is not deserialized correctly.  Below is the code I am trying out.

 

Best,

Luis

 

gHowl_bundle_reception

p.s. here is the code I am trying out. 

For OSC packet reception, I get the following output (as seen in the image):

Line 1: The address of the OSC packet (i.e. /test)

Line 2(+): The data

When sending the bundle, I get the following output:

Line 1: #bundle

Line 2: Bespoke.Common.Osc.OscMessage

Line 3: Bespoke.Common.Osc.OscMessage

—Code—

OscPacket msg = OscPacket.FromByteArray(tempIp, receiveBytes);

                           

                            if (msg.IsBundle)

                            {

                              //do something to deserialize bundle correctly

                            }

                            else

                            {

                             // do nothing, OSCPacket reception is working fine

                            }

                            

                        Object[] tempAdd = new Object[msg.Data.Length + 1];

                        tempAdd[0] = msg.Address;

                        

                        Array.Copy(msg.Data, 0, tempAdd, 1, msg.Data.Length);

                        

                        _networkText = tempAdd;

                        _messageReceived = true;

8:06 am
October 13, 2010


fraguada

Member

posts 4

Ok, I got my head around what is going on.  I need to get into the bundle, find out how many OSCMessages are in there, and prepare my data accordingly.  I am crudely seeing the bundle data into my plugin.

9:56 am
October 13, 2010


Paul

Admin

posts 49

Hi Luis,

So, are you good to go, or do you still have questions?

Paul

10:27 am
October 13, 2010


fraguada

Member

posts 4

Post edited 3:36 am – October 14, 2010 by fraguada


Yes Paul, everything is working.  Not the greatest code below, but for the time being it is functional.

Thanks!

Luis

p.s. this means that the plugin can now directly receive things like TUIO bundles from reactivision!  Great Library.

                  (tried for a while to format the code correctly, but did not work out so well for the forum)

 

OscPacket msg = OscPacket.FromByteArray(tempIp, receiveBytes);
                            if (msg.IsBundle)
                            {
                                List<Object> list = new List<Object>();
                                for (int i = 0; i < msg.Data.Length; i++)
                                {
                                    OscMessage bMsg = (OscMessage)msg.Data[i];
                                    list.Add(bMsg.Address);
                                    for (int j = 0; j < bMsg.Data.Length; j++)
                                    {
                                        list.Add(bMsg.Data[j]);
                                    }
                                }

                                Object[] tosend = new Object[list.Count];
                                list.CopyTo(tosend);
                                _networkText = tosend;
                                _messageReceived = true;
                            } else {
                                Object[] tempAdd = new Object[msg.Data.Length + 1];
                                tempAdd[0] = msg.Address;
                                Array.Copy(msg.Data, 0, tempAdd, 1, msg.Data.Length);
                                _networkText = tempAdd;
                                _messageReceived = true;
                            }
                
                    }

10:57 am
October 13, 2010


Paul

Admin

posts 49

Post edited 11:00 am – October 13, 2010 by Paul


Glad to hear it Luis. As an aside, there's an easier way access contained OscMessage objects within a bundle. I've added this to a pending release of the library. Add the following properties to the OscBundle class:

 

  /// <summary>
        /// Gets the array of nested bundles.
        /// </summary>
        public OscBundle[] Bundles
        {
            get
            {
                List<OscBundle> bundles = new List<OscBundle>();
                foreach (object value in mData)
                {
                    if (value is OscBundle)
                    {
                        bundles.Add((OscBundle)value);
                    }
                }
                return bundles.ToArray();
            }
        }
        /// <summary>
        /// Gets the array of contained messages.
        /// </summary>
        public OscMessage[] Messages
        {
            get
            {
                List<OscMessage> messages = new List<OscMessage>();
                foreach (object value in mData)
                {
                    if (value is OscMessage)
                    {
                        messages.Add((OscMessage)value);
                    }                    
                }
                return messages.ToArray();
            }
        }

 

These two properties just do the casting for you for nested bundles and the OscMessage objects contained within a bundle. Then you can simply iterate through the contained messages with code such as:

foreach (OscMessage message in e.Bundle.Messages)

            {
                // Do something with message
            }

 

 

 

3:50 am
October 14, 2010


fraguada

Member

posts 4

Great Paul,  I will go ahead and try to modify the bundle class as you posted above. I have a feeling we will have a good deal of revision for our next version because currently all of the libraries we use are embedded within our assembly.  We are starting now to use separate .dlls for each lib. and finally making an installer.  By the way, not sure I mentioned this before, but we are creating a set of components for a program called Grasshopper: http://www.grasshopper3d.com.  We add MIDI, Spreadsheet, XML, UDP, and OSC (via your lib) interoperability to the program.

Any other interesting things in the next version? 

Thanks,

Luis

 


About the Bespoke Software forum



No Comment

Comments are closed.