Esempio n. 1
0
    /// <summary>
    /// Callback when a message is received. It stores the messages in a list of the oscControl
    void OnPacketReceived(OSCServer server, OSCPacket packet)
    {
        // Remember origin
        packet.server = server;

        // Limit buffer
        if (packets.Count > _loglength)
        {
            packets.RemoveRange(0, packets.Count - _loglength);
        }
        // Add to OSCPackets list
        packets.Add(packet);
    }
Esempio n. 2
0
    public static void Initialize()
    {
        live     = new FloorPadState();
        current  = new FloorPadState();
        previous = new FloorPadState();

        // ScreenPlay floor sends OSC packets on port 5000
        if (_OSCServer == null)
        {
            _OSCServer = new OSCServer(5000);
            _OSCServer.PacketReceivedEvent += OnPacketReceived;
        }
    }
Esempio n. 3
0
    void Start()
    {
        ReadFile();
        _senData = new String[num];
        InitStr(ref _senData);
        LoadData(ref _senData);
        var _senLen = 10;

        ModifyData(_senLen);
        oscServer = OCS.GetComponent <OSCServer>();
        tm        = this.GetComponent <TextMesh>();

        //Debug.Log("Senetence Gene Start()" + Time.frameCount);
    }
Esempio n. 4
0
        OSCServer CreateServer(string serverId, int port)
        {
            OSCServer server = new OSCServer(port);

            server.PacketReceivedEvent += OnPacketReceived;

            ServerLog serveritem = new ServerLog();

            serveritem.server  = server;
            serveritem.log     = new List <string>();
            serveritem.packets = new List <OSCPacket>();

            return(server);
        }
Esempio n. 5
0
    /// <summary>
    /// Initializes the OSC Handler.
    /// Here you can create the OSC servers and clientes.
    /// </summary>
    public OSCServer Init()
    {
        //Initialize OSC clients (transmitters)
        //Example:
        //CreateClient("SuperCollider", IPAddress.Parse("127.0.0.1"), 5555);

        //Initialize OSC servers (listeners)
        //Example:

        //Testing version control
        OSCServer server = CreateServer("Binary", 3000);

        return(server);
    }
Esempio n. 6
0
    /// <summary>
    /// Stops this instance.
    /// </summary>
    public void Stop()
    {
        if (this._localServer != null)
        {
            this._localServer.Close();
            this._localServer = null;
        }

        foreach (OSCClient c in this._localClients)
        {
            c.Close();
        }
        this._localClients.Clear();
    }
 void OSCReceicePacket(OSCServer s, OSCPacket p)
 {
     if (p.Address.Equals("/muse/elements/raw_fft0"))
     {
         //Debug.Log("Receiving FFT!");
         //Debug.Log(test.Count);
         //fftqueue.Enqueue(packet.Data);
         for (int i = 0; i < fftarr.Length; i++)
         {
             fftarr[i] = (float)p.Data[i];
             //Debug.Log(fftarr[i]);
         }
     }
 }
Esempio n. 8
0
 void PackedReceived(OSCServer sender, OSCPacket packet)
 {
     if (packet.IsBundle())
     {
         foreach (OSCMessage m in packet.Data)
         {
             HandleMessage(m);
         }
     }
     else
     {
         HandleMessage(packet as OSCMessage);
     }
 }
Esempio n. 9
0
    /// <summary>
    /// Creates an OSC Server (listens to upcoming OSC messages) given an incoming port.
    /// </summary>
    /// <param name="serverId">
    /// A <see cref="System.String"/>
    /// </param>
    /// <param name="port">
    /// A <see cref="System.Int32"/>
    /// </param>
    public void CreateServer(string serverId, int port)
    {
        OSCServer server = new OSCServer(port);

        server.PacketReceivedEvent += OnPacketReceived;

        ServerLog serveritem = new ServerLog();

        serveritem.server  = server;
        serveritem.log     = new List <string>();
        serveritem.packets = new List <OSCPacket>();

        _servers.Add(serverId, serveritem);
    }
Esempio n. 10
0
    //public delegate void ReaperEventReceived(OSCMessage message);
    //public event ReaperEventReceived OnReaperEvent;

    void OnPacketReceived(OSCServer server, OSCPacket packet)
    {
        /*TO DO -- Receive data back from Reaper
         * //Debug.Log ("Event received");
         *
         * foreach (OSCMessage msg in packet.Data) {
         *
         *      Debug.Log (msg.Address.ToString () + msg.Data [0].ToString ());
         *
         *
         *      if (msg.Address.Substring (0, 6) == "/track") {
         *              OnReaperEvent (msg);
         *      }
         * }*/
    }
Esempio n. 11
0
    // Script initialization
    void Start()
    {
        // init OSC
        OSCHandler.Instance.Init();

        // Initialize OSC clients (transmitters)
        OSCHandler.Instance.CreateClient("myClient", IPAddress.Parse(outIP), outPort);

        // Initialize OSC servers (listeners)
        myServer = OSCHandler.Instance.CreateServer("myServer", inPort);
        // Set buffer size (bytes) of the server (default 1024)
        myServer.ReceiveBufferSize = 1024;
        // Set the sleeping time of the thread (default 10)
        myServer.SleepMilliseconds = 10;
    }
Esempio n. 12
0
 private void OnPacketReceivedEvent(OSCServer sender, OSCPacket packet)
 {
     // Send something from PureData and it shows up in the Unity console
     if (packet.Address.StartsWith("/muse/elements/experimental/concentration"))
     {
         manager.message(ServerName, "concentration", packet.Data[0]);
     }/*else if(packet.Address.StartsWith("/muse/elements/blink")){
       * manager.message(ServerName, "blink", packet.Data[0]);
       * }*/
     else if (packet.Address.StartsWith("/muse/elements/touching_forehead"))
     {
         manager.message(ServerName, "touching", packet.Data[0]);
     }
     //Debug.Log(packet.Address + ": " + DataToString(packet.Data));
 }
Esempio n. 13
0
 public void CreateServer(int port)
 {
     try
     {
         m_port        = port;
         m_localIP     = Engine.Net.NetUtility.getFirstIPAddress();
         m_broadcastIP = Engine.Net.NetUtility.getBroadcastAddress(m_localIP);
         m_server      = new OSCServer(port);
         m_server.PacketReceivedEvent += server_PacketReceivedEvent;
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
        public OSCListener(int port, string name) : base(name)
        {
            Port = port;

            try
            {
                listener = new OSCServer(port);
                listener.DefaultOnMessageReceived += Listener_PacketReceived;
                Status.Update(StatusCode.NotStarted, "No messages yet", this);
            }
            catch(Exception e)
            {
                Status.Update(StatusCode.Error, e.Message, this);
            }
        }
Esempio n. 15
0
    public void Open(int port)
    {
#if UNITY_EDITOR
        if (PlayerSettings.runInBackground == false)
        {
            Debug.LogWarning("Recommend PlayerSettings > runInBackground = true");
        }
#endif
        if (_server != null)
        {
            _server.Close();
        }
        _server = new OSCServer(port);
        _server.SleepMilliseconds    = 0;
        _server.PacketReceivedEvent += didRecievedEvent;
    }
 public void AttachOscServer()
 {
     foreach (KeyValuePair <string, ServerLog> pair in OSCHandler.Instance.Servers)
     {
         if (pair.Key == oscServerToListen)
         {
             serverToListen = pair.Value.server;
             serverToListen.PacketReceivedEvent += OnPacketReceived;
             Debug.Log("OSC Server '" + oscServerToListen + "' found on port : " + serverToListen.ServerPort);
         }
     }
     if (serverToListen == null)
     {
         Debug.Log("No server found !");
     }
 }
    void OnPacketReceived_(OSCServer server, OSCPacket packet)
    {
        /********************
        *  for safety
        ********************/
        const int QueueLimitSize = 100;

        if (QueueLimitSize < queue.Count)
        {
            queue.Clear();
        }

        /********************
        ********************/
        queue.Enqueue(packet);
    }
Esempio n. 18
0
    // Use this for initialization
    void Start()
    {
        ambSynthY    = 4;
        cameraScript = camera.GetComponent <CameraScript> ();

        server = new OSCServer(9003);
        server.PacketReceivedEvent += OnPacketReceived;

        excitement = 0f;
        depth      = 0f;
        diversity  = 0f;
        beat       = 0f;

        clients = new LinkedList <OSCClient> ();

        lcDepth      = 0;
        lcExcitement = 0;
        lcDiversity  = 0;

        solo     = false;
        soloTime = 0;
        soloDur  = 0;
        newSolo  = false;

        dustPS = dust.GetComponent <ParticleSystem> ();


        newAudienceMembers    = new LinkedList <Audience> ();
        deleteAudienceMembers = new LinkedList <int> ();
        updateAudienceMembers = new LinkedList <Audience> ();
        nudgeAudienceMembers  = new Dictionary <int, Vector3> ();
        activeAudienceMembers = new Dictionary <int, GameObject> ();
        synthAvatars          = new LinkedList <SynthAvatarScript> ();
        lightSynths           = new LinkedList <LightSynth> ();
        ambientSynths         = new LinkedList <AmbientSynth> ();
        bigSynths             = new LinkedList <BigSynth> ();

        coherence   = 0f;
        motion      = 0;
        textMesh    = codeText.GetComponent <TextMesh>();
        updatedText = "";

//		InvokeRepeating("drawFuncs", 0f, 0.1f);

        print("OsC initialized");
    }
Esempio n. 19
0
 // Use this for initialization
 void Start()
 {
     foreach (KeyValuePair <string, ServerLog> pair in OSCHandler.Instance.Servers)
     {
         if (pair.Key == "MoveObject")
         {
             moveObjectServer = pair.Value.server;
             moveObjectServer.PacketReceivedEvent += OnPacketReceived;
             moveObjectServer.SleepMilliseconds    = 1;
             Debug.Log("Server found : " + moveObjectServer.ToString());
         }
     }
     if (tag == "MonoPlayer" && CommandLineParser.trackerSerial != "" && CommandLineParser.trackerSerial != null)
     {
         serialNumbertoFollow = CommandLineParser.trackerSerial;
     }
 }
Esempio n. 20
0
 public bool RestartLocalServer()
 {
     if (server != null)
     {
         server.Close();
         Log("closing server");
     }
     server = new OSCServer(listenPort);
     server.PacketReceivedEvent += (server, packet) =>
     {
         lock (recievePacketQueue)
         {
             recievePacketQueue.Enqueue(packet);
         }
     };
     return(true);
 }
Esempio n. 21
0
    // Script initialization
    void Start()
    {
        UdpClient            = transform.GetComponent <UDPClient>();
        SetRotation          = transform.GetComponent <ResetPhysics>();
        UnitsRotationPattern = new int[transform.childCount];
        // init OSC
        OSCHandler.Instance.Init();

        myServer = OSCHandler.Instance.CreateServer(this.name, inPort);

        OSCHandler.Instance.AddCallback(this);

        // Set buffer size (bytes) of the server (default 1024)
        myServer.ReceiveBufferSize = 1024;
        // Set the sleeping time of the thread (default 10)
        myServer.SleepMilliseconds = 10;
    }
Esempio n. 22
0
        // Use this for initialization
        void Start()
        {
            if (instance != null)
            {
                Debug.LogError("There are two OptiTrackOSCClients, remove one");
            }
            instance = this;

            mTransform            = transform;
            server                = new OSCServer(oscReceivePort);
            mTransform.localScale = Vector3.one * scale;

            //playerObject.name = playerObjectName;

            server.SleepMilliseconds = 1;
            //server.Connect();
            server.PacketReceivedEvent += PacketReceived;
        }
    public bool StartServer(int port)
    {
        if (m_DebugCreateNoServers)
        {
            return(false);
        }

        if (m_Server != null)
        {
            StopAllServers();
        }

        m_Server = new OSCServer(port);
        Debug.Log("OSC:  Server created.");
        m_ServerInit = !m_Server.PortUnavailable;

        return(!m_Server.PortUnavailable);
    }
Esempio n. 24
0
    /// <summary>
    /// Initializes the OSC Handler.
    /// Here you can create the OSC servers and clientes.
    /// </summary>
    public void Awake()
    {
        // start server
        server = new OSCServer(portIncoming);
        server.PacketReceivedEvent += OnPacketReceived;

        // prepare clients
        clients = new Dictionary <string, OSCClient>();
        foreach (string addr in startClientList)
        {
            clients.Add(addr, new OSCClient(IPAddress.Parse(addr), portOutgoing));
        }

        // do the variable gathering in the first Update call
        // because some Components might not have had Start() called until now.
        variableList    = null;
        clientToExclude = null;
    }
Esempio n. 25
0
File: AMPM.cs Progetto: Potion/ampm
        private static void Server_MessageReceived(OSCServer sender, OSCPacket e)
        {
            if (OnAmpmMessage == null)
            {
                return;
            }

            string   name = e.Address.Replace("/", string.Empty);
            string   json = e.Data.FirstOrDefault() as string;
            JSONNode data = null;

            if (json != null)
            {
                data = JSON.Parse(json);
            }

            OnAmpmMessage(null, new Tuple <string, JSONNode>(name, data));
        }
Esempio n. 26
0
    /// <summary>
    /// Creates an OSC Server (listens to upcoming OSC messages) given an incoming port.
    /// </summary>
    /// <param name="serverId">
    /// A <see cref="System.String"/>
    /// </param>
    /// <param name="port">
    /// A <see cref="System.Int32"/>
    /// </param>
    public bool CreateServer(string serverId, int port)
    {
        var result = false;

        if (!_servers.ContainsKey(serverId))
        {
            OSCServer server = new OSCServer(port);
            server.PacketReceivedEvent += OnPacketReceived;

            ServerLog serveritem = new ServerLog();
            serveritem.server  = server;
            serveritem.log     = new List <string>();
            serveritem.packets = new List <OSCPacket>();

            _servers.Add(serverId, serveritem);
            result = true;
        }
        return(result);
    }
Esempio n. 27
0
    /// <summary>
    /// Called when [packet received].
    /// </summary>
    /// <param name="server">The distant server that sent the packet.</param>
    /// <param name="packet">The packet received.</param>
    private void OnPacketReceived(OSCServer server, OSCPacket packet)
    {
        bool handled = false;

        foreach (OscSubscriber sub in this._serverSubscriber)
        {
            Match m = sub.topicRegex.Match(packet.Address);
            if (m.Success)
            {
                handled = true;
                sub.callback(packet.Address, packet, m.Groups);
            }
        }

        if (!handled)
        { // If not handled => print it
            Debug.LogFormat("OSC Message received on {0} : {1}", packet.Address, packet.Data.Select(d => d.ToString()).Aggregate((a, b) => a + " " + b));
        }
    }
Esempio n. 28
0
    /// <summary>
    /// Callback when a message is received. It stores the messages in a list of the oscControl
    void OnPacketReceived(OSCServer server, OSCPacket packet)
    {
        // Remember origin
        packet.server = server;

        // Limit buffer
        if (packets.Count > _loglength)
        {
            packets.RemoveRange(0, packets.Count - _loglength);
        }
        // Add to OSCPackets list
        packets.Add(packet);

        // handle callback (if any)

        foreach (OSCListener callback in callbacks)
        {
            callback.OnOSC(packet);
        }
    }
Esempio n. 29
0
    void didRecievedEvent(OSCServer sender, OSCPacket packet)
    {
        lock (_queue)
        {
            if (packet.IsBundle())
            {
                var bundle = packet as OSCBundle;

                foreach (object obj in bundle.Data)
                {
                    OSCMessage msg = obj as OSCMessage;
                    _queue.Enqueue(msg);
                }
            }
            else
            {
                _queue.Enqueue(packet as OSCMessage);
            }
        }
    }
Esempio n. 30
0
    private void OscServerOnPacketReceivedEvent(OSCServer sender, OSCPacket packet)
    {
        if (!packet.Address.Equals("/wek/outputs"))
        {
            return;
        }

        var gestureStart = (float)packet.Data[0];
        var gestureEnd   = (float)packet.Data[1];

        if (gestureStart > 0.9 && gestureEnd < 0.1)
        {
            Debug.Log("Starting gesture!");
        }

        if (gestureStart < 0.1 && gestureEnd > 0.9)
        {
            Debug.Log("Gestured ended!");
        }
    }
Esempio n. 31
0
    static void OnPacketReceived(OSCServer server, OSCPacket packet)
    {
        lock (live) {
            // OSC address is of the format /1/pushXXX, where XXX indicates the tile whose
            // state is changing, from 1-100
            string address     = packet.Address;
            string push        = "push";
            int    pushIndex   = address.IndexOf(push);
            int    pushLength  = push.Length;
            int    tileNumber  = Convert.ToInt32(address.Substring(pushIndex + pushLength));
            float  sensorState = (float)packet.Data [0];
            //Debug.Log ("OSC RX: " + tileNumber + " State: " + sensorState);
            bool state = System.Convert.ToBoolean(sensorState);
            int  index = tileNumber - 1;

            live.tiles [index] = state;

            if (state)
            {
                if (!live.pressed.Contains(index))
                {
                    live.pressed.Add(index);
                    if (live.released.Contains(index))
                    {
                        live.released.Remove(index);
                    }
                }
            }
            else
            {
                if (!live.released.Contains(index))
                {
                    live.released.Add(index);
                    if (live.pressed.Contains(index))
                    {
                        live.pressed.Remove(index);
                    }
                }
            }
        }
    }