Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[RELEASED] OSC simpl

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

  1. Dirrogate

    Dirrogate

    Joined:
    Feb 18, 2014
    Posts:
    122
    Sorry for being so dumb in the coding dept, @cecarlsen I didnt know where to add this bit
    I tried creating a new C# script and copy pasting but it wont does not work, and if I add it the actual HDAdditionalCamera script it throws up a bunch of errors.
    Is this a standalone script that I add to the camera component stack?

    Sorry for the Noobness. If you do update OSCsimpl to take care of these nested scripts it would be a boon!
    For instance - the new Hdrp Volume stack (fog, Depth of field, Bloom etc.,,) these parameters can't be accessed by just dropping the "Volume" object in the inspector.

    **Edit** Ok it works! I had to name the script the same as the public class - noonbness 101:rolleyes:

    Thanks again for the help!
     
    cecarlsen likes this.
  2. Dirrogate

    Dirrogate

    Joined:
    Feb 18, 2014
    Posts:
    122
    Hi @cecarlsen ,
    OSCsimpl has been a great bridge for allowing non coders such as myself to gain quite a bit of control over Unity.

    I'm reaching out again, as one aspect has me stumped.
    I'm using the CineMachine package (from Unity Package manager) - and have setup two Cinemachine Virtual cameras.
    The way things work with Cinemachine cameras is, you can blend/switch between them based on a 'Priority' field which takes in integer numbers.

    However when I create (using Touch designer on cellphone) either a slider with value of say 1 to 10 or a push button to send a single value of 10, I get a console error in OSCsimpl about int v/s float as in the image below
    int_versus_float.JPG

    Ideally I want to use a slider to blend between Virtual Cameras in Cinemachine under Osc control.
    However, I don't mind just being able to "switch" between two cameras based on their priority being higher.

    If you could spare some time to solve, I'd be grateful.
    Kind Regards
     
  3. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    So, OSC simpl is "[...] designed for those who love the flexibility of scripting". Most times, sending and receiving will involve writing a script.

    In this case, you are receiving a value of type float that you would like to send to a property setter of type int. The OscIn mapping UI does not support casting. This has to be done in a script.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Events;
    3.  
    4. public class FloatToIntMapping : MonoBehaviour
    5. {
    6.     [SerializeField] OscIn _oscIn = null;
    7.     [SerializeField] string _address = "/oscControl/steadyCam";
    8.     [SerializeField] IntEvent _intEvent = null;
    9.  
    10.     // Wrapping the generic UnityEvent is no longer necessary in 2020.1.
    11.     [System.Serializable] public class IntEvent : UnityEvent<int>{ }
    12.  
    13.  
    14.     void Awake()
    15.     {
    16.         _oscIn.MapFloat( _address, OnFloatReceived );
    17.     }
    18.  
    19.  
    20.     void OnFloatReceived( float value )
    21.     {
    22.         _intEvent.Invoke( Mathf.RoundToInt( value ) );
    23.     }
    24. }
     
    Last edited: May 7, 2020
    Dirrogate likes this.
  4. Dirrogate

    Dirrogate

    Joined:
    Feb 18, 2014
    Posts:
    122
    Thank you so much! it works as expected.
    I'm slowly coming to understanding the inner workings of these aspects, while contributing the results and feedback directly to Unity.
    For instance I'll be now writing to the team at Cinemachine - to include or recommend assets such as OSCsimpl for Virtual Cinematography... along with some other settings that should be exposed (which I now realize they aren't, thanks to the OscSimpl script)
     
    cecarlsen likes this.
  5. Dirrogate

    Dirrogate

    Joined:
    Feb 18, 2014
    Posts:
    122
    @cecarlsen For a $5 asset, the support shown on these forums is outstanding. I'd gladly pay double or three times the price for built in features such as dealing with accessing deep nesting of parameters in the editor and also for the ability to do casting (a term I learned from you) intuitively within the OSCsimpl gui - from float to Int.

    I've made much progress with using OSCsimpl with TouchOsc. For instance, at the start of video below, the room light flicker is not a script, but me manually moving a TouchOSC slider. Likewise, the changing of (Cinemachine) cameras.


    Help needed (again)
    I know in message https://forum.unity.com/threads/released-osc-simpl.382244/page-2#post-5697976
    @ruvidan2001 figured out how to move a box. I tool a look at the Getting started Oscin script but yeah, it's still above my coding ability.

    What I want to do is, to use the output from this app: https://sensors2.org/osc/ to pan/tilt a Unity Camera.
    I've got the app successfully sending Gyro, accelerometer and orientation values to OSCsimpl as in the screenshot
    Gyroscopevalues_osc.JPG
    My roadblock is how do I drive the transform of the Unity Camera with these values?
    I know this is spoon-feeding, but my coding skills are up to zilch and hopefully, it will benefit others with zero skills but big plans.

    Kind Regards.
     
    Last edited: May 12, 2020
  6. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    Hi @Dirrogate

    Here is an example of receiving three arguments of type float and forwarding them as a Vector3.

    You will probably have to scale and translate the incoming values to fit your needs. It looks like the incoming orientation is measured in euler angles. If you so, you can use Quaternion.Euler() to convert to a Unity compatible rotation. This however is beyond the support for OSC simpl.

    I recommend the scripting courses available under Unity's Learning sections.
    https://learn.unity.com/course/beginner-scripting

    If you are interested in manually controlling the camera, I can also recommend using the 3D Connexion Space Mouse. I use it for controlling the camera freehand for live concert visuals. The sensitivity is great and it can give a live feel to the scene that animated transitions can't. As far as I know, Unity's new Input System supports it.

    All the best
    Carl Emil


    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Events;
    3.  
    4. public class FloatArgsToVector3Mapping : MonoBehaviour
    5. {
    6.     [SerializeField] OscIn _oscIn = null;
    7.     [SerializeField] string _address = "/accelerometer";
    8.     [SerializeField] Vector3Event _vector3vent = null;
    9.  
    10.     // Wrapping the generic UnityEvent is no longer necessary in 2020.1.
    11.     [System.Serializable] public class Vector3Event : UnityEvent<Vector3>{ }
    12.  
    13.     void Awake()
    14.     {
    15.         _oscIn.Map( _address, OnMessageReceived );
    16.     }
    17.  
    18.     void OnMessageReceived( OscMessage m )
    19.     {
    20.         // Try get values and return early if we fail.
    21.         float x, y, z;
    22.         if( !m.TryGet( 0, out x ) || !m.TryGet( 1, out y ) || !m.TryGet( 2, out z ) ) return;
    23.  
    24.         // Forward!
    25.         _vector3vent.Invoke( new Vector3( x, y, z ) );
    26.     }
    27. }
     
    Dirrogate likes this.
  7. Dirrogate

    Dirrogate

    Joined:
    Feb 18, 2014
    Posts:
    122
    Thanks so much again, Carl.
    I tried out the script, and yeah it would need scaling to turn the camera as smoothly as can be done with a mouse.
    I'll stick to a backup (and more scalable) solution of using a VR controller such as the oculus hand controller instead.

    I'll certainly benefit from learning scripting, and intend to get cracking once these higher level workflows get done (for Virtual Cinematography).
    The thing is, using Unreal Engine is all so plug n play and ready to go in the Virtual Production arena, I'm actually punishing myself (in a good way) by sticking it out with Unity, thereby building a solution from scratch.

    I just like Unity's somewhat more friendly and intuitive approach to gluing things together.
     
    cecarlsen likes this.
  8. aivo

    aivo

    Joined:
    Feb 13, 2017
    Posts:
    21
    Dear Carl
    Thanks for your amazing asset. I use it quite frequently. I have a question though.

    I saw that you are using an async task for receiving the osc messages. I also saw that you are queuing up the received osc messages.

    let's say I am receiving multiple messages during one frame. are they queued up so I can dequeue them in the update loop?
    If so, how would I do that?

    I am using the following (simplified) code:

    Code (CSharp):
    1.     Dictionary<string, MyClass> allData = new Dictionary<string, MyClass>();
    2.     OscIn receiver;
    3.     void Start()
    4.     {
    5.         if (receiver == null) receiver = gameObject.AddComponent<OscIn>();
    6.         receiver.Open(12345);
    7.         receiver.Map("/SomeAddress", OnReceivedEulerAngles);
    8.     }
    9.  
    10.  
    11.     void OnReceivedEulerAngles(OscMessage message)
    12.     {
    13.         MyClass h = new MyClass();
    14.         message.TryGet(0, out h.PitchYawRoll.y);
    15.         message.TryGet(1, out h.PitchYawRoll.x);
    16.         message.TryGet(2, out h.PitchYawRoll.z);
    17.         message.TryGet(3, out h.id);
    18.         if (allData.ContainsKey(h.id))
    19.             allData[h.id] = h;
    20.         else
    21.             allData.Add(h.id, h);
    22.     }

    whereas potentially I receive several osc messages during one frame with different id's. Depending on the ID I would like to update my Dictionnary

    allData


    how would that be possible? Thank you so much.
     
    Last edited: Jun 5, 2020
  9. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    Hi @aivo, sorry to hear you are having issues. First, did you uncheck “filterDuplicates” on the OscIn component? When enabled, if multiple messages with the same address is received, only the newest is passed on.

    EDIT: From version 2.3.0 and onward, filterDuplicates is set to false as default.
     
    Last edited: Jul 1, 2020
  10. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,340
    Awesome plugin. How to get it working on Android?
     
  11. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    Thank you, if you feel like that, please do rate it ;)

    I don't have an Android device at my disposal, so I don't provide official support for that platform. That said, it may work.
     
  12. aivo

    aivo

    Joined:
    Feb 13, 2017
    Posts:
    21
    On my side I had no problem deploying to android. Just switch platform and build&run. Do you have any specific problems?
     
    cecarlsen likes this.
  13. Aike-A

    Aike-A

    Joined:
    Apr 19, 2019
    Posts:
    1
    i @cecarlsen ,

    Came across OSC Simpl trying to figure out how to lannex to Unity. I found your script so script much more simpler to load in the Unity so thank you for that?. I am still quite a new to Unity and there aren't any tutorials on lannex to Unity integration. What would be the steps to connect Iannex to Unity, I would really appreciate some pointers thanks!
     
  14. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    Hi @Aike-A

    When I launched OSC simpl, years ago, I tested connection with Iannix and it worked fine.

    There is a video here showing how osc messages are send from Iannix.


    To understand how to receive them using OSC simpl, please refer to the manual and the examples. It will go someting like this:
    1) Make sure that Iannix is sending to the IP of the machine running Unity, or 127.0.0.1 if it runs on the same machine. And choose a valid port, for example 8888.
    2) In Unity, add an OscIn component to an object in your scene. In the inspector, set the same port (8888).
    3) You should see messages flowing in the inspector.
    4) The manual and the examples shows you how to forward the message arguments to the methods you desire.
     
  15. aivo

    aivo

    Joined:
    Feb 13, 2017
    Posts:
    21
    Hello again.

    I found the following behavior:
    If during one frame I send multiple messages to the same ip address and the same port but to different OscAddresses, OscSimpl automatically generates an OSC bundle.

    Can I switch off this behaviour? Because the recipient cannot handle bundles.

    thanks
     
  16. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    Hi @aivo

    I see. I was not aware of libraries that don't support bundles. What library/software is on the receiving side?

    In earlier versions of OSC simpl, automatic bundling was optional. However, it turned out that messages that are send successively without bundling are very prone to be lost. So I forced automatic bundling as default.

    In the upcoming version (2.3.1), I've brought the option back in, and added some warnings. Send me an email and I'll send you the version right away. It may be a few days before it is available on Asset Store.

    All the best
    Carl Emil
     
    Last edited: Jul 23, 2020
  17. dfarjoun

    dfarjoun

    Joined:
    Aug 6, 2017
    Posts:
    33
    Hi,
    Instead of using touchOSC or TouchDAW, is it possible to create an app similar to these with OSC-Simpl?
    So I could create my interface and communicate not only with Unity applications via smartphone, but also DAW (digital audio workstations like Reaper) or Lightroom, for example. These ones might receive midi messages, right?

    It it possible?
     
  18. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    Yes, totally possible. I used TouchOSC for a long while, but eventually I got annoyed with it's limitations. You can use Unity UI (Canvas) and OSC simpl to create very custom multi touch remote control apps for DAW's and other software that supports OSC.

    OSC simpl supports "MIDI over OSC", meaning that a MIDI message is stored and send as an argument to a OSC message. This is not the same as pure MIDI. As far as I know, only very few apps support "MIDI over OSC", although it is part of the OSC specs v. 1.1. In short, if you also want to send pure MIDI, you will need to look for an additional MIDI extension for Unity.

    All the best
    Carl Emil
     
  19. dfarjoun

    dfarjoun

    Joined:
    Aug 6, 2017
    Posts:
    33
    Thank you very much for the reply. I've sent a DM with some details, if you don't mind.
     
  20. Dirrogate

    Dirrogate

    Joined:
    Feb 18, 2014
    Posts:
    122
    @cecarlsen OSC simpl has played a big role in allowing me to create a Virtual Production pipeline in Unity even with my limited skills (coding) . Thanks again for all the help. Here's a finished film I did while using the asset.
    (lights flickering controlled by slider over OSC, switching Cinemachine cameras over OSC etc)


    I'd like to invite you to join the Facebook Unity Virtual Prod. group. https://www.facebook.com/groups/892348284544650/
    Your insights would be valuable to all.

    On another note, I think I saw in one of the forums - your quest for Cluster rendering and why Unity removed it.
    Today, UE is leading the way in Virtual Prod, because of cluster render (nDisplay)
    Your asset Off-axis camera is another great component in Virtual Prod. Did you solve the Unity cluster rendering debacle?
    I was investigating UniCave https://widve.github.io/UniCAVE/
     
  21. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    Super nice to hear @Dirrogate =)

    I haven't checked up on the state of cluster rendering recently, so I can't really tell if it's dead or alive. Yes, Unreal is the standard choice for virtual production these days, I hear this from many. Unity has clearly neglected the sector. Also, they have made life really hard for those of us who try to extent the engine to do things beyond the scope of their imagination. My hope is that when the HDRP and URP shader libraries and GraphicsBuffer implementation (index and vertex buffers) starts to solidify, we will see a new wave of tools from the community that will give Unity an edge in virtual production.
     
    youri_ssk and Dirrogate like this.
  22. pym4742

    pym4742

    Joined:
    May 14, 2020
    Posts:
    2
    Hello, Carl Emil Carlsen.
    I am a student who purchased OSC simpl you made for audio visualization using Max for live and Unity.

    I want to ask you a question because I have a question while watching Script.

    1.What is the difference between Getting Started Receiving in the Getting Started folder and OscIn in the Runtime folder?

    I know how to use OscIn.
    But when do you use Getting Started Receiving?

    2.How do you extend the range of mapping?

    I want to map the scale of Sphere, but I can't find it in Mapping.
    Is this a problem that I can fix by scripting myself?

    And I wonder if it is possible to move the value from OscIN to VFX Graph.
     
  23. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    Hi @pym4742

    1. It sounds like you have imported the new version (with Unity's recommended folder structure) on top of an old version (that has no Runtime folder) so duplicates are appearing. There should only be one "Getting Started" example scene.

    2. The OscIn inspector only has mappings for single argument OSC supported types. If you want to scale a sphere (presuming uniformly), then you have to look at the GettingStartedReceiving example script. Write a method that takes the incoming (float) value using oscIn.MapFloat() and set the localScale of the target sphere transform. You need to convert the float value to a Vector3 value, like so: transform.localScale = new Vector3( value, value, value ).

    (3). VFXGraph – should be totally possible, by writing a script. Look for examples on how to access exposed properties in VFX Graph.
     
  24. kenman

    kenman

    Joined:
    Mar 3, 2014
    Posts:
    13
    i bought the plugin and planning to do some dmx addressable led.
    I found some reference scripts using artnet to send the data:

    for example :
    data = new data[512]
    artnet.data[0] = 255

    if i want to use your plug-in, how to send the data, can you give me some example? thx so much
     
  25. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    Hi @kenman. DMX is a different protokol. It won't work. Best bet I think is to find a c# implementation and adapt it.
     
  26. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    Update 2.3.2.png
    OscSimpl 2.3.2 is available!

    Minor update with bug fixes and optimisations.

    – Reduced garbage created by OscMessage.ToString() and thereby greatly improved performance of inspectors.
    – Added byte count monitoring for OscIn and OscOut.
    – Optimised internal buffer handling.
    – Fixed bug in OscMessage.RemoveAt().
    – Moved message sending from EndOfFrame to LateUpdate. To send as fast as possible, call OscOut.Send() in Update.
    – Deprecated OscOut.multicastLoopback. This feature was never working as expected because C# Socket.multicastLoopback only affects the same socket. (The plan is to reintegrate it in a future update).
     
  27. Bryan3D

    Bryan3D

    Joined:
    Feb 14, 2013
    Posts:
    18
    What I'm looking for is an OSC asset that will allow me to communicate between a Unity desktop app and a desktop DAW. I'd like to use the DAW's VST host to play high-quality VSTi sound samples on command. Kind of like how CoolSoft's Virtual MIDI Synth can intercept MIDI commands to play Soundfont sound samples. Is this possible somehow?
     
  28. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    If you are absolutely sure that your DAW can receive OSC (not MIDI) and forward it to your VST, then OscSimpl will work fine for you. OscSimpl does support MIDI over OSC, but I have yet to see a DAW that supports that natively, so first test if your DAW can route simple OSC messages to your VST.

    I did something similar back in 2007, where I experimented with using spring physics in Unity and sending collisions events as OSC a physical modeling synth in Logic.
    https://cec.dk/works/nerve/
     
unityunity