Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[RELEASED] OSC simpl

Discussion in 'Assets and Asset Store' started by cecarlsen, Jan 27, 2016.

  1. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    858
    Dear Unity community

    Today the Asset Store approved OSC simpl, an Open Sound Control implementation tailored for Unity at $10 (excluding VAT).

    With one existing solution on the Asset Store and a few open source (and free) solutions to choose from, WHY on earth I would put effort into making another OSC implementation?

    All the implementations I have tried so far needed a considerable massage to achieve the simplicity I expect in Unity, or they were not fully implemented, or the API was not as simple as I thought it should be. I have used OSC for various purposes over the past 10 years and have messed around with many different implementations. A couple of months ago I decided to start over, build it from scratch and get it right once and for all. When I had something rock stable, I wrapped it in user-friendly candy paper with nicely commented code, a manual, a reference and a bunch of examples.

    I owe a big thank you to a couple of open source projects that I have learned from.
    oscP5 by Andreas Schlegel
    OSCsharp by Valentin Simonov
    Bespoke.Osc by Paul Varcholik​

    Other sources of learning include the 1.0 spec (naturally), the original implementation by Matt Wright and a paper publish in 2009 titled "Features and Future of Open Sound Control version 1.1 for NIME".

    I am using the package myself frequently and that is enough motivation to keep it up to date. The small income from Asset Store is meant to maintain my motivation for keeping things user-friendly.

    Post feedback on this thread and I will do my best to answer.

    All the best
    Carl Emil


    OSC simpl
    http://u3d.as/nwx

    Supports
    - All OSC argument types (except MIDI)
    - Bundles with timetags
    - UDP IPv4 Unicast, Broadcast and Multicast
    - Unity's .Net 2.0 Subset
    - OSX, Windows and probably other platforms

    Includes
    - Manual
    - Reference
    - Examples
    - Full source code
    - Runtime UI prefabs

    Features
    - Map addresses from scripts and inspector
    - Monitor messages
    - Monitor remote connection status
    - Filter message duplicates (optional)
    - Auto bundle messages (optional)
    - Add timetag to bundled message (optional)
    - Disable multicast loopback (optional)

    Tested with
    OpenFrameworks, Processing, Max/MSP, VVVV, TouchOSC, Lemur, Iannix and Vezer.

    01 How to send.png

    02 How to receive.png

    03 Inspector panels.png

    04 Runtime UI.png

    05 Argument Type Test.png
     
    ZJP and elbows like this.
  2. hmb3141

    hmb3141

    Joined:
    Oct 8, 2014
    Posts:
    18
    Hi,

    Thanks for putting in the time to develop this, I like how simple and lightweight it is compared to the other options out there.

    I'm having some trouble setting up multiple receivers to use the same port. Currently if I try and open multiple receivers on the same port from different scripts, only the most recently created one will receive. As a work around I'm using the code below to just use the first receiver that owns that port, which is fine but it would be nice just be able to call oscIn.Open(). I noticed in OscIn.cs around line 366 there's some mention of having multiple OscIn objects listening on the same port, hopefully it's not too complicated a fix.

    Thanks,

    Harvey

    Code (CSharp):
    1.         OscIn[] existingReceivers = GameObject.FindObjectsOfType<OscIn>();
    2.         foreach (OscIn receiver in existingReceivers)
    3.         {
    4.             if (receiver.port == 9007)
    5.             {
    6.                 oscIn = receiver;
    7.                 break;
    8.             }
    9.         }
    10.         if (!oscIn) oscIn = gameObject.AddComponent<OscIn>();
    11.         oscIn.Open(9007);
     
  3. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    858
    Hi Harvey

    I did some tests and can confirm the issue. I eventually found this:

    "That's the nature of sockets. Even in cases (such as UDP) where multiple applications can access the same port, the data is handed out first-come, first-serve. UDP is also designed with minimum overhead, so there isn't even an opportunity to "check the queue," like you (hypothetically) could with TCP."
    http://stackoverflow.com/questions/22810511/bind-multiple-listener-to-the-same-port

    The line of code you refer to in OscIn.cs simply makes sure that no error is thrown when multiple OscIn objects share port.

    In order to share messages between OscIn objects that share the same port, they will need to keep track of each other. I will have to consider whether thats worth implementing.

    Meanwhile, I'd recommend simply not using the same port for multiple OscIn objects. You can for example handle this by keeping track of the ports in a Dictionary<port,OscIn>.

    All the best
    Carl Emil
     
  4. hmb3141

    hmb3141

    Joined:
    Oct 8, 2014
    Posts:
    18
    Hi Carl,

    That makes sense, thanks!

    I use TouchOSC as a controller for Unity so I tend to keep everything on the same port. I'll just keep using one OscIn but kind of treat it as a singeton. I made a little static class to handle this should anyone find it helpful.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public static class OscSimplUtils {
    5.  
    6.     public static OscIn Open(int port, OscIn oscIn, GameObject obj)
    7.     {
    8.         OscIn[] existingReceivers = GameObject.FindObjectsOfType<OscIn>();
    9.         foreach (OscIn receiver in existingReceivers)
    10.         {
    11.             if (receiver.port == port)
    12.             {
    13.                 oscIn = receiver;
    14.                 break;
    15.             }
    16.         }
    17.         if (!oscIn) oscIn = obj.gameObject.AddComponent<OscIn>();
    18.         oscIn.Open(port);
    19.         return oscIn;
    20.     }
    21.  
    22.     public static OscOut Open(int port, OscOut oscOut, GameObject obj)
    23.     {
    24.         OscOut[] existingSenders = GameObject.FindObjectsOfType<OscOut>();
    25.         foreach (OscOut sender in existingSenders)
    26.         {
    27.             if (sender.port == port)
    28.             {
    29.                 oscOut = sender;
    30.                 break;
    31.             }
    32.         }
    33.         if (!oscOut) oscOut = obj.gameObject.AddComponent<OscOut>();
    34.         oscOut.Open(port);
    35.         return oscOut;
    36.     }
    37. }
    38.  
    Code (CSharp):
    1.         oscIn   = OscSimplUtils.Open(9007, oscIn, this.gameObject);
    2.         oscOut  = OscSimplUtils.Open(9001, oscOut, this.gameObject);
     
  5. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    858
    Perhaps also consider getting rid of OscIn and OscOut components that are no loger used. Your singleton class will potentially leak. If you are only communicating with one TouchOsc device then you will never need more than one OscIn and one OscOut object. I'd recommend using the Runtime UI prefabs in the included examples so that you can change the port as needed.
     
  6. garrilla

    garrilla

    Joined:
    Jan 12, 2016
    Posts:
    28
    While this thread is still active, I'd just like thank @CarlEmail for a great library.

    Works really well - we're using it with Unity/Lemur/Reaper.

    Only issue we have is that debug in VS2015 produces some warnings at start-up
    Severity Code Description Project File Line Suppression State
    Warning CS0169 The field 'OscIn._settingsFoldout' is never used u3d_sympan_controller.CSharp D:\garry\Documents\_sympan_dev\_sympan_super_repo\u3d_sympan_controller\Assets\OSC simpl\OscIn.cs 144 Active
    Warning CS0169 The field 'OscIn._mappingsFoldout' is never used u3d_sympan_controller.CSharp D:\garry\Documents\_sympan_dev\_sympan_super_repo\u3d_sympan_controller\Assets\OSC simpl\OscIn.cs 145 Active
    Warning CS0169 The field 'OscIn._messagesFoldout' is never used u3d_sympan_controller.CSharp D:\garry\Documents\_sympan_dev\_sympan_super_repo\u3d_sympan_controller\Assets\OSC simpl\OscIn.cs 146 Active
    Warning CS0169 The field 'OscOut._settingsFoldout' is never used u3d_sympan_controller.CSharp D:\garry\Documents\_sympan_dev\_sympan_super_repo\u3d_sympan_controller\Assets\OSC simpl\OscOut.cs 116 Active
    Warning CS0169 The field 'OscOut._messagesFoldout' is never used u3d_sympan_controller.CSharp D:\garry\Documents\_sympan_dev\_sympan_super_repo\u3d_sympan_controller\Assets\OSC simpl\OscOut.cs 117 Active​
     
  7. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    858
    Thanks for reporting this. Put this line in the top of OscIn.cs and OscOut.cs. I'll include it in the next version.

    #pragma warning disable 169 // Don't complain over editor foldout flags (_settingsFoldout etc.)
     
  8. bdepper

    bdepper

    Joined:
    Apr 12, 2007
    Posts:
    2
    Is there a way to use address wildcard characters to set up mappings within OscSimpl? I am trying to get data from the Kinect v2 via Kinectv2OSC. It formats the addresses as /bodies/{Body ID #}/joints/{Joint Name}.
    It would be great if I could use a wildcard for the {Body ID #} as this is a long number that changes each time the body is detected. In my case the ID would not be relevant and I would like to be able to create a mapping that does not require changing this in the editor each time.
     
  9. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    858
    That's not currently possible. You will have to loop through the bodies and map each joint. You can use a delegate to forward the information as you prefer. In the example below I assume you'll make a OnJointUpdated method.

    [EDIT] something happened to the formatting of the code below. Just fixing.

    Code (csharp):
    1.  
    2. string[] jointNames = newstring[]{ "Head", "Hand", "Leg" };
    3. for( int b = 0; b < 6; b++ ){
    4. foreach( string jointName in jointNames ){
    5. oscIn.Map( "/bodies/" + b + "/joints/" + jointName, delegate( OscMessage message ){
    6. OnJointUpdated( b, jointName, message );
    7. });
    8. }
    9. }
    10.  
     
  10. bdepper

    bdepper

    Joined:
    Apr 12, 2007
    Posts:
    2
    Thanks, this was unfortunately what I was afraid of. In the address I am receiving the Body ID # looks to be a time stamp so I would need to replace the b in your code above with the long number coming from the software. I was wondering whether I can grab an address from the message queue and extract the id # and then concatenate in manner similar to your code.
    I will also look to see if I can alter the output from the sending software as this might be easier.
    Thanks again.
     
  11. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    858
    In that case I'd recommend subscribing to oscIn.onAnyMessage and write logic for parsing the messages as they come in.
     
  12. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,459
    Great package.
    Having Midi support would be totally awesome. Would it be possible to add midi support in a future update.
     
  13. aoleynikov678

    aoleynikov678

    Joined:
    Aug 12, 2015
    Posts:
    8
    Hi,

    I'm using OSC Simpl with Unity3d 5.4.1f and I have problems with receiving large string by OSC. I made a simple sender in openFrameworks, which sends string with ~20k symbols. In max/msp, for example, string receives normally, but in Unity I get OSC disconnect. Maximum size of received string was just 8k of symbols. I also tried to divide the string into different arguments, but Unity didn't receive such messages too.

    I think the problem maybe in maximum buffer size or something like this, but I cannot find this parameter in the asset's source.
     
  14. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    858
    [EDIT]
    I found that the Mono UdpClient which OSC simpl relies on has a hardcoded receive buffer size at 8192 bytes. I will have to rewrite a few things to make the buffer size accessible. I put it on the todo.
     
    Last edited: Dec 20, 2016
  15. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    858
    [EDIT] Version 1.2 is now available and will fix the issue described below.

    Unity 5.5.0 breaks OSC simpl. It will give you an error CS0121 complaining about ambiguous method calls. I have submitted an update to fix this.

    The issue seems to stem from a bug in C#.
    https://forum.unity3d.com/threads/unity-5-5-unityaction-error-cs0121-is-this-a-bug.445139/

    Sorry for the inconvenience. UT says it takes them 5 to 10 business days to review the update.
     
    Last edited: Dec 20, 2016
  16. mraeclo

    mraeclo

    Joined:
    Dec 3, 2016
    Posts:
    10
    Hello!
    First of all, thank you for this, looks quite useful although I`m still trying to figure out how to use It the way I need right now.
    Basically, I`m using an osc application to control the camera of the game inside unity, here`s a screenshot of the script attached to the camera. Screen Shot 2016-12-20 at 7.17.17 PM.png

    Using the "How to receive using scripting" part of the manual as guide, I thought it would call the function every time It got a message with names /x, /y and /z and call the function after that name, inside the argument of oscIn.Map. Thats not whats happening, first of all, I get the errors shown at the picture when using the Map function, so I`ve tried the MapFloat function, by doing so, no more error, the script compiles but whats happens is that it prints the "Recebeu" inside onEnable() function, but seems to never run the others. The funny thing is that I can see the messages (sent by a processing sketch) on the editor, like this

    Screen Shot 2016-12-20 at 7.24.41 PM.png

    What am I missing? After going trough the reference I`ve found that on the OscIn part, the "OscMessageEvent onAnyMessage" could be useful, I could get any message, check the name and call the function manually with the value inside, but I`m not sure if OscMessageEvent is a function or how to use it at all, or even compare the names if I could use it.
    Someone can help?

    Using
    Mac OSX 10.10.5
    Unity 5.5.0f3 Personal
    The app is for android, samsung gear VR, samsung galaxy s7, but the tests are being made using the computer so I`m not sure if this information is useful, anyways..

    thanks in advance
    =)
     
  17. mraeclo

    mraeclo

    Joined:
    Dec 3, 2016
    Posts:
    10
    Well, ignore message above, problem solved. I`ve inserted a OscIn component at the same gameObject that has the cript, then used it at the Publlc Osc In at that script.
    Not sure why but it worked, something was going wrong when adding the OscIn component trough script.

    Thanks again.
     
  18. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    858
    Hi mraeclo

    I was just looking into it and I'm happy to hear you fixed it.

    If you are calling map methods in OnEnable, you must remember to call the corresponding unmap methods OnDisable.

    If you were adding OscIn by script and nothing worked, perhaps you forgot to call the Open method?

    All the best
     
  19. Jeffkeuh

    Jeffkeuh

    Joined:
    Oct 10, 2013
    Posts:
    1
    EDIT: ignore the part below, I think the problem has to do with using Unity 5.5, is it possible that SimplOSC is not working even after the 1.2 update? It fixed the compiler errors but it's not working in Unity 5.5 editor for me.
    EDIT 2: It's not working in the editor, but it's working fine when using a standalone build.



    (nevermind this, caused by using Unity 5.5, probably not a .NET issue)
    Is there a way to make SimplOSC work using .NET 2.0 instead of the .NET 2.0 Subset? I'm trying to communicate between android and pc. It works fine when the subset is selected in player settings but I need .NET 2.0 since there's some arduino stuff involved and I need the System.IO ports. When I select .NET 2.0 I can't recieve any messages.
     
    Last edited: Dec 21, 2016
  20. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    858
    I have tried to reproduce this by sending from MaxMSP to OSC simpl 1.2 in Unity 5.5 on OSX and Windows, both with .NET 2.0 and .NET 2.0 subset. I can't reproduce the issue you describe. Unfortunately I don't have an Android device and therefore I can't guarantee that Android will work for you.

    Do you get any errors on Android if you build with debugging turned on?
     
  21. Partomo

    Partomo

    Joined:
    Oct 7, 2013
    Posts:
    17
    Hi,

    I need to compile to Windows Store from Unity (for Hololens). Would that work with OSC Simple? Or only with Windows standalone?
     
  22. Partomo

    Partomo

    Joined:
    Oct 7, 2013
    Posts:
    17
    Hi,

    Just bought OSCSimpl. I'm trying to compile for Windows Store (Universal 10, D3D) and I get the error:

    "The type or namespace name 'UdpClient could not be found (are you missing a using directive or an assembly reference?)

    Any idea what could be going wrong?


    //Tom
     
  23. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    858
    It seems that UdpClient is not included in the Unity build for Windows Store. This is unfortunate since OSC simpl relies on it. Have you tried to build with .NET 2.0 instead of .NET 2.0 subset? The setting is found in the Unity Player Settings for your project. If that does not help then I would recommend using another library for now.
     
  24. hierro__

    hierro__

    Joined:
    Sep 22, 2014
    Posts:
    59
    Hi, is this packaging supporting UDP multicast ?
     
  25. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    858
    As stated in the description. Yes.
     
  26. hierro__

    hierro__

    Joined:
    Sep 22, 2014
    Posts:
    59
    You never know...since in screenshots, it is never shown.
     
  27. hierro__

    hierro__

    Joined:
    Sep 22, 2014
    Posts:
    59
    Hi, I'm trying to use Multicast on Android, seems that there is now very clean support from android itself, anyway can't have it working, which device, os, you tested it with ? Any suggestion ?
     
  28. kitty_meow_kiss

    kitty_meow_kiss

    Joined:
    Nov 23, 2016
    Posts:
    1
    Hi,
    can you help me please? I am rly new with Unity. I want to try using it for PureData visualisation.
    And this was looking as better solution. Maybe it is only for more advanced persons.
    But please..

    From GUI solution, I do not understand these handlers methods. Or it would be great, to be able to find anything, like in Blender. Anyway.
    I want for beginning rotate, or translate cube.. I have script, reacting to keystrokes. So there is probably way, how to continue, using scripting there.
    But, I rly do not understand, why is it so unclear, how to map osc message /variable1 to some float in any script.
    I do not understand examples with different kinds of variables, which u have in your library. It is maybe to complex.
    Why not to use something simple, for somebody, like me, who want to pay for something, instead of nights of: "why is it not working". But maybe it was not good idea. It is not so cheap, anyway :D. Sorry.
    just thanks for any hint. I can show more of my steps. But I do not see step from osc to script variables. It is probably in about oscIn.MapFloat("/test1",variable); But I was trying to apply it in sevveral vays or like in the examples. > ]

    THX
    Jakub


    // update:
    So it is working now. I learned something. Would be happy see working with more data from my PD patch. Still, in sense of OSC, it would be fine to have more simple examples. When artists are maybe not so programing able. xD
     
    Last edited: Jan 1, 2017
  29. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    858
    Hi Hierro. Unfortunately I don't have a Android device and therefore can't guarantee that OSC simpl will work on that platform. I apologise for the vage statement in the product description "OSX, Windows and probably other platforms". I have an update pending that states this more clearly.
     
  30. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    858
    Hi Jakub, happy to hear you solved it. Point taken. It may make sense to make a couple of readymades for controlling transforms, lights and such.
     
    Last edited: Jan 7, 2017
  31. hierro__

    hierro__

    Joined:
    Sep 22, 2014
    Posts:
    59
    Hi Carl, no problem, i spent a couple of days on that, and finally I implemented a native plugin to better manage multicast on android, but for some devices it is still a mistery (nexus5), if you are further developing, I can share what achieved so far, regards.
     
    cecarlsen likes this.
  32. Anraksha

    Anraksha

    Joined:
    Dec 9, 2016
    Posts:
    10
    Hello,
    That make some week that we use your asset in our compagny if at the origin the application we developed was for windows, the compagny decided to port the app on android(nvidia shield) and it seem that it dont work well.
    For the explanation sometime the command we use to subcribe to the server pass (it appear that it only pass when the tablet is connected to the computer and that we build & run the project after we disactivate and reactivate the wifi) and the other time it dont work. after having install some utilities on android to look the open port we have noticed that the port of the OSCIn actually work and wait the information but the port of the OSCOut dont appear. Does your asset really have a problem with android?

    Thanks for the reading.
    Have a good day, hopping that you can help us.
     
  33. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    858
    Hi Anraksha

    I'm sorry to hear you ran into problems. As it states in the asset description; OSC simpl supports "Export for OSX, iOS, and Windows (no guarantee for other platforms, but they might work.[...]". I don't have an Android device so it's currently not possible for me to reproduce your error.

    Are you getting any error messages? If not, then you can try to Debug.Log all exceptions in OscOut.cs from line 332 and forth. Perhaps this could give a clue.

    All the best
     
  34. Anraksha

    Anraksha

    Joined:
    Dec 9, 2016
    Posts:
    10
    Thanks for the reply ^^ I dont have any error message I gonna test the debug.log from the lien you mentionned if i found the problem i will transmit it to you ^^

    Edit: i found something interresting the osc in listen on the good port but the oscout seem to create a protocol udp to a port that i didn't entrer or write : i wanna instanciate the oscout on the port 8479 and it create an udp protocol on a port like 44353, 58898,36698 in short on a port which look like random. While for the OSCIn the port is good i ask to listen on port 8480 and it create a udp protocol on the port 8480. The problem is only seen on the Android version.
     
    Last edited: Feb 24, 2017
  35. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    858
    Thanks for posting your findings. I will look into this when I eventually get my hands on and android device. If you find other clues or solve it please let me know.
     
  36. martinamenegon

    martinamenegon

    Joined:
    Aug 28, 2014
    Posts:
    31
    hey, so just want to be sure before buying! I will be able to send values from MaxMsp to Unity 5.6 and also have this connection working once i export my project as standalone? thanks in advance for the info!
     
  37. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    858
    Hi Mijn. On OSX, iOS and Windows, yes, absolutely.
     
  38. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,459
    Very nice project, will you be supporting Midi in the near future
     
  39. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    858
    Thanks Rocki. If I make a MIDI extension, then it will be published a separate project. I currently use Keijiros MidiJack. It works fine, but does lack some important features, like MIDI clock. https://github.com/keijiro/MidiJack
     
  40. hmb3141

    hmb3141

    Joined:
    Oct 8, 2014
    Posts:
    18
    Hi,

    I've got a bit of an issue when trying to receive multiple messages with multiple arguments, with the same osc address.

    I've uploaded my testing setup here - , which includes

    An openframeworks app 'oscSender' which sends 6 messages in a loop when the 's' key is pressed.

    Another openframeworks app 'oscReceiveDebugger' which receives messages from the sender app and logs them.

    A Unity project with a scene 'Test' which receives messages from the sender app and logs them using osc-simpl

    The openframeworks app receives all of the messages, but in Unity only the last message is received each time. Do you have any idea what might be causing this? I tried using bundles but from what I can tell each message in the bundle must have a different address.

    Thanks,

    Harvey
     
    Last edited: Sep 4, 2017
  41. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    858
    Thanks for the example Harvey, I have downloaded it. Please remove the public link again. I will have a look.
     
  42. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    858
    Ah. You simply have to turn off 'Filter Duplicates' under the settings foldout in OscIn. This is enabled by default because in most cases you want Unity to only react once per frame. You can disable this from a script as well:

    oscIn.filterDuplicates = false;

    Also, beware that OSC is based on UDP, which does not guarantee that messages are transmitted successfully. Messages can drop out if the connection is bad. Therefore, if you have super important messages, like setting up remote apps, then send the messages continuously instead of once and check for changes at the remote end.
     
    Last edited: Sep 1, 2017
  43. hmb3141

    hmb3141

    Joined:
    Oct 8, 2014
    Posts:
    18
    This fixed my issue. Thanks. I've removed the link, sorry about that!
     
    cecarlsen likes this.
  44. AbradolfLinkler

    AbradolfLinkler

    Joined:
    Feb 26, 2017
    Posts:
    26
    Dear Carl,

    I have a problem with OSC simpl asset for Unity 2017.2 it and would like to kindly ask for Your help.

    I am trying to send a list of integers from Max/MSP to Unity via OSC simpl.

    However the OSCin only receives the first integer from the list in an OSC message.

    How do You handle lists in the OSCin receive code?

    The asset works fine with all of the datatypes mentioned in the manual which I studied thoroughly - one value for a given message (using MapInt function) but I don’t seem to find the right function of lists or arrays of data.

    ANy help would be much appreciated.

    Dariusz
     
  45. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    858
    Hi Dariusz. I have replied on your email as well.

    Yes that should be possible indeed. You will need to write your own receive script – like you have noticed MapInt presumes a single integer.

    Have a look at the OnTest3 method in the included GettingStartedReceiving.cs script from the GettingStarted example. You will need to write a similar method, just for integers. Something like this:

    void OnTest4( OscMessage message )
    {
    // Get int arguments at index 0 and 1 safely.
    int value1, value2;
    if( message.TryGet( 0, out value1 ) && message.TryGet( 1, out value2 ) ){
    Debug.Log( "Received: " + value1 + " " + value2 );
    }
    }

    Or you can iterate through the list, as exemplified (commented out) in the OnTest3 method.

    All the best
    Carl Emil
     
  46. AbradolfLinkler

    AbradolfLinkler

    Joined:
    Feb 26, 2017
    Posts:
    26
    Dear Carl,
    Thank You for Your swift reply.
    I must apologise as I did not provide enough information:

    I imagine I could do this for a list of few ints, but I actually need to send a graphic matrix (like a 128 x 128 matrix = 16384 long list).

    i realise there's many ways to approach this: from putting each matrix element into a separate message to dropping the OSC altogather and try and track the image in Unity... Trying to find the most CPU cheap solution for letting unity know what image the camera sees...
     
  47. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    858
    Thats a lot of data for UDP (about 65Kb if I am right). I would try sending it as a byte blob. It may be tricky to encode the bytes in Max though. I am not sure it would be reliable to send as a list of ints, but you can try. Just iterate though the arguments in the message and use modulo and division to convert back to a matrix.
     
  48. AbradolfLinkler

    AbradolfLinkler

    Joined:
    Feb 26, 2017
    Posts:
    26
    Thank You for Your response.
    Sounds like a bit of research which - despite being a possible solution - could be quite time consuming for someone with limited programming skills like me :)

    I'll try the first solution and limit the number of data sent to an absolute minimum by filtering first...
     
  49. AbradolfLinkler

    AbradolfLinkler

    Joined:
    Feb 26, 2017
    Posts:
    26
    Dear Carl,

    Thank You for Your support. Could you help me out one more time? I would need a short receive script for blob datatype for OSC simpl.

    I am sending blob data from max like so through open sound control object:
    /test5 OSCBlob 8 1 2 3 4 5 6 7 8, bang
    where /test5 is the name of receiving function in OSC simpl
    OSCBlob is required before sending the list
    8 - is the length of the list
    1 2 3 4 5 6 7 8 - are the list contents
    bang - to actually send the list

    on the unity side I get
    Received: System.Byte[]
    in the console while I am using the function to decode the byte[] like so:

    void OnTest5( byte[] value )
    {
    Debug.Log( "Received: " + value);
    }

    Now i need to convert the byte[] value to a usable list of ints in Unity.

    Can You help me out with that?

    Kind Regards

    Dariusz
     
  50. AbradolfLinkler

    AbradolfLinkler

    Joined:
    Feb 26, 2017
    Posts:
    26
    P.S. Just trying to use the proposed blob solution as when I send a consecutive list of int messages in rapid order (every 200ms) I only get the last one received in Unity...