Example #1
0
 // Start is called before the first frame update
 void Start()
 {
     reciever1 = new OSCReciever();
     reciever1.Open(port1);
     reciever2 = new OSCReciever();
     reciever2.Open(port2);
 }
 /// <summary>
 /// Initializes the OSC Handler.
 /// Here you can create the OSC servers and clientes.
 /// </summary>
 public void Init()
 {
     //Initialize OSC clients (transmitters)
     CreateClient("UnityOSC", IPAddress.Parse("192.168.2.202"), 8000);
     //Initialize OSC servers (listeners)
     reciever = new OSCReciever();
     reciever.Open(9000);
 }
Example #3
0
 /// <summary>
 /// This function is called when the object becomes enabled and active.
 /// </summary>
 void OnEnable()
 {
     if (reciever == null)
     {
         reciever = new OSCReciever();
         reciever.Open(oscPort);
     }
 }
Example #4
0
    public double deltaM, thetaM, alphaM, muM, smrM, lowbetaM, betaM, highbetaM;                                                                                                    //Waves values (max values)

    // Start is called before the first frame update
    void Start()
    {
        //Initialize all values and recievers
        c         = 0;
        reciever  = new OSCReciever();
        reciever2 = new OSCReciever();
        reciever.Open(port);
        reciever2.Open(port2);
        initWaves();
    }
Example #5
0
    // Use this for initialization
    void Start()
    {
        reciever = new OSCReciever();
        reciever.Open(port);
        _audiosource = GetComponent <AudioSource> ();
        //osc.SetAddressHandler("/audio", GetSpectrumAudioSource);

        for (int i = 0; i > 512; i++)
        {
            _samples[i] = 0.0f;
        }
    }
Example #6
0
    /// <summary>
    /// Registers a holoLens tracker for the master node.
    /// </summary>
    /// <param name="tracker">The holoLens tracker of the master.</param>
    public void RegisterHoloLensTracker(HoloLensTracker tracker)
    {
        // Create the reciever and dictionary if there is none
        if (_reciever == null)
        {
            _reciever = new OSCReciever();
            _reciever.Open(holoPort);
            _holoTrackerFromID = new Dictionary <string, HoloLensTracker>();
        }

        // add tracker to dictionary
        _holoTrackerFromID.Add(tracker.displayID, tracker);
    }
Example #7
0
        public BrainSensor()
        {
            messages = new OSCMessage[datas.Length];

            reciever = new OSCReciever();
            if (!Application.isEditor)
            {
                reciever.Open(port);
                isActive = true;

                CoroutineHandler.StartStaticCoroutine(Update());
            }
        }
Example #8
0
    /// <summary>
    /// This function is called when the behaviour becomes disabled or inactive.
    /// </summary>
    void OnDisable()
    {
        if (reciever != null)
        {
            reciever.Close();
            reciever = null;
        }

        if (oscClient != null)
        {
            oscClient.Close();
            oscClient = null;
        }
    }
Example #9
0
    void Start()
    {
        dancerNames = dancerList.text.Split('\n');
        videoTex    = new RenderTexture(1280, 720, 0, RenderTextureFormat.ARGB32);

        noCachePlayer.loopPointReached += EndReached;
        noCachePlayer.audioOutputMode   = UnityEngine.Video.VideoAudioOutputMode.None;

        cam = GetComponent <Camera>();
        if (reciever == null)
        {
            reciever = new OSCReciever();
            reciever.Open(oscPort);
        }

        info.enabled = false;
        myIP         = GetLocalIPAddress();
        StartCoroutine(ShowInfoForFixedDuration("v" + Application.version + ";" + myIP, 10, 60, 1));
        DeviceUtils.SetScreenBrightness(255);
    }
Example #10
0
    public void Connect()
    {
        Debug.Log("[OCF] Connecting to port " + localPort);
        try
        {
            if (server != null)
            {
                server.Close();
            }

            server = new OSCReciever();
            server.Open(localPort);
            // server.PacketReceivedEvent += packetReceived;

            isConnected = true;
        }
        catch (Exception e)
        {
            Debug.LogError("Error with port " + localPort);
            Debug.LogWarning(e.StackTrace);
            isConnected = false;
            server      = null;
        }
    }
 // Use this for initialization
 void Start()
 {
     reciever = new OSCReciever();
     reciever.Open(port);
     //
 }
Example #12
0
 void Start()
 {
     reciever = new OSCReciever();
     reciever.Open(port);
     Debug.Log("Waiting messages・・・");
 }
Example #13
0
	// Use this for initialization
	void Start () {
		reciever = new OSCReciever();
		Debug.Log("Open port " + port);
		reciever.Open(port);
	}
Example #14
0
    void ExecuteOSCCmd(string address, List <System.Object> dataList)
    {
        int count = dataList.Count;

        if (address.Equals("/play-video"))
        {
            if (count > 0)
            {
                ResetVideoRelatedParams();
                var url = dataList[0].ToString();
                if (!url.Contains("http"))
                {
                    if (url.Equals("-1"))
                    {
                        StopVideo();
                        DoNextCmd();
                        return;
                    }
                    var fileName = Path.GetFileName(url);
                    var fullPath = Path.Combine(Application.persistentDataPath, fileName);
                    url = "file://" + fullPath;
                    if (!File.Exists(fullPath))
                    {
                        StartCoroutine(ShowInfoForFixedDuration("no " + fileName, 3, 40));
                        return;
                    }
                }

                var isLooping = false;
                int val       = 0;
                if (count > 1)
                {
                    float.TryParse(dataList[1].ToString(), out firstPlayStartPos);
                }

                if (count > 2)
                {
                    float.TryParse(dataList[2].ToString(), out firstPlayStopPos);
                }

                if (count > 3 && int.TryParse(dataList[3].ToString(), out val))
                {
                    isLooping = val == 1;
                }

                if (count > 4)
                {
                    float.TryParse(dataList[4].ToString(), out loopingStartPos);
                }

                if (count > 5)
                {
                    float.TryParse(dataList[5].ToString(), out loopingStopPos);
                }

                PlayVideo(url, isLooping, false);
            }
            else
            {
                DoNextCmd();
            }
        }
        else if (address.Equals("/stop-video"))
        {
            StopVideo();
            DoNextCmd();
        }
        else if (address.Equals("/pause-video"))
        {
            if (curPlayer != null)
            {
                curPlayer.Pause();
            }
            DoNextCmd();
        }
        else if (address.Equals("/continue-video"))
        {
            if (curPlayer != null && !curPlayer.isPlaying)
            {
                ResetVideoRelatedParams();
                if (count > 0)
                {
                    float.TryParse(dataList[0].ToString(), out firstPlayStopPos);
                    if (firstPlayStopPos > 0)
                    {
                        stopFrame = (long)(curPlayer.frameCount * firstPlayStopPos);
                    }
                }

                if (count > 1)
                {
                    float.TryParse(dataList[1].ToString(), out loopingStartPos);
                }

                if (count > 2)
                {
                    float.TryParse(dataList[2].ToString(), out loopingStopPos);
                }
                curPlayer.Play();
            }
            else
            {
                DoNextCmd();
            }
        }
        else if (address.Equals("/load-video"))
        {
            if (count > 0)
            {
                var url = dataList[0].ToString();
                if (!url.Contains("http"))
                {
                    if (url.Equals("-1"))
                    {
                        StopVideo();
                        return;
                    }
                    var fileName = Path.GetFileName(url);
                    var fullPath = Path.Combine(Application.persistentDataPath, fileName);
                    url = "file://" + fullPath;
                    if (!File.Exists(fullPath))
                    {
                        StartCoroutine(ShowInfoForFixedDuration("no " + fileName, 3, 40));
                        return;
                    }
                }

                LoadVideo(url, true, false, OnVideoLoaded);
            }
            else
            {
                DoNextCmd();
            }
        }
        else if (address.Equals("/download-file"))
        {
            if (count > 0)
            {
                var  url      = dataList[0].ToString();
                var  filename = Path.GetFileName(url);
                var  filePath = Path.Combine(Application.persistentDataPath, filename);
                int  val;
                bool testPlay  = false;
                bool overwrite = true;
                bool interruptDuringDownload = false;

                if (count > 1 && int.TryParse(dataList[1].ToString(), out val))
                {
                    interruptDuringDownload = val == 1;
                }

                if (count > 2 && int.TryParse(dataList[2].ToString(), out val))
                {
                    overwrite = val == 1;
                }

                if (count > 3 && int.TryParse(dataList[3].ToString(), out val))
                {
                    testPlay = val == 1;
                }

                if (!overwrite && File.Exists(filePath))
                {
                    return;
                }
                if (downloadRoutine != null)
                {
                    if (interruptDuringDownload)
                    {
                        StopCoroutine(downloadRoutine);
                    }
                    else
                    {
                        return;
                    }
                }
                downloadRoutine = StartCoroutine(DownloadFileToPath(url, filePath, () => {
                    var fileExist = File.Exists(filePath);
                    if (!fileExist)
                    {
                        StartCoroutine(ShowInfoForFixedDuration("download failed", 3, 40));
                        return;
                    }

                    if (testPlay)
                    {
                        PlayVideo("file://" + filePath, false, false);
                    }

                    if (oscClient != null)
                    {
                        OSCMessage message = new OSCMessage("/download-done");
                        message.Append(myIP);
                        message.Append(filename);
                        message.Append(fileExist? "succeed" : "failed");
                        oscClient.Send(message);
                    }

                    DoNextCmd();
                }));
            }
            else
            {
                DoNextCmd();
            }
        }
        else if (address.Equals("/set-server"))
        {
            if (count > 1)
            {
                if (oscClient != null)
                {
                    oscClient.Close();
                    oscClient = null;
                }

                targetServerIP = dataList[0].ToString();
                if (int.TryParse(dataList[1].ToString(), out port))
                {
                    oscClient = CreateOSCClient(targetServerIP, port);
                    var oscMsg = new OSCMessage("/set-server-response");
                    oscMsg.Append(myIP);
                    oscMsg.Append("connected");
                    oscClient.Send(oscMsg);
                }
                DoNextCmd();
            }
            else
            {
                DoNextCmd();
            }
        }
        else if (address.Equals("/set-id"))
        {
            if (count > 0)
            {
                if (count > 1)
                {
                    int val = 1;
                    if (int.TryParse(dataList[1].ToString(), out val))
                    {
                        info.enabled = val == 1;
                    }
                }
                else
                {
                    info.enabled = !info.enabled;
                }

                if (info.enabled)
                {
                    info.fontSize = 90;
                    int index = -1;
                    int.TryParse(dataList[0].ToString(), out index);

                    if (index >= 0 && index < dancerNames.Length)
                    {
                        info.text = dancerNames[index];
                    }
                    else
                    {
                        info.text = dataList[0].ToString();
                    }
                }
                DoNextCmd();
            }
            else
            {
                DoNextCmd();
            }
        }
        else if (address.Equals("/set-effect-param"))
        {
            if (count > 0)
            {
                int effectIndex = -1;
                if (int.TryParse(dataList[0].ToString(), out effectIndex))
                {
                    if (effectIndex >= 0 && effectIndex < effectList.Length)
                    {
                        bool toRecord = false;
                        int  temp     = 0;
                        if (count > 1)
                        {
                            int.TryParse(dataList[1].ToString(), out temp);
                            toRecord = temp == 1;

                            EffectParamsRecording.EffectParams paramFrame = null;
                            if (toRecord && paramRecording.state == EffectParamsRecording.State.Recording && curPlayer != null && curPlayer.isPlaying)
                            {
                                for (int i = 0; i < paramRecording.seq.Count; i++)
                                {
                                    var frameData = paramRecording.seq[i];
                                    if (frameData.effectIndex == effectIndex && frameData.videoFrame == curPlayer.frame)
                                    {
                                        paramFrame = frameData;
                                        break;
                                    }
                                }

                                if (paramFrame == null)
                                {
                                    paramFrame = new EffectParamsRecording.EffectParams();
                                    paramRecording.seq.Add(paramFrame);
                                    paramFrame.effectIndex = effectIndex;
                                    paramFrame.videoFrame  = curPlayer.frame;
                                }
                            }

                            var   effect     = effectList[effectIndex];
                            float val        = -1;
                            int   paramIndex = -1;

                            for (int i = 2; i < count;)
                            {
                                var data = dataList[i].ToString();
                                if (data.Equals("i"))
                                {
                                    if ((i + 2) < count && int.TryParse(dataList[i + 1].ToString(), out paramIndex) && float.TryParse(dataList[i + 2].ToString(), out val))
                                    {
                                        effect.SetParameter(paramIndex, val);
                                        if (paramFrame != null)
                                        {
                                            paramFrame.paramIndex.Add(paramIndex);
                                            paramFrame.paramVal.Add(val);
                                        }
                                    }
                                    i += 3;
                                }
                                else if (data.Equals("s"))
                                {
                                    int startIndex = 0;
                                    int paramCount = 0;
                                    if ((i + 2) < count && int.TryParse(dataList[i + 1].ToString(), out startIndex) && int.TryParse(dataList[i + 2].ToString(), out paramCount))
                                    {
                                        if (i + 2 + paramCount < count)
                                        {
                                            for (int k = 0; k < paramCount; k++)
                                            {
                                                if (float.TryParse(dataList[k + i + 3].ToString(), out val))
                                                {
                                                    paramIndex = startIndex + k;
                                                    effect.SetParameter(paramIndex, val);
                                                    if (paramFrame != null)
                                                    {
                                                        paramFrame.paramIndex.Add(paramIndex);
                                                        paramFrame.paramVal.Add(val);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    i += (3 + paramCount);
                                }
                                else
                                {
                                    i++;
                                }
                            }
                            effect.SetEffectActive(true);
                        }
                    }
                    else
                    {
                        StartCoroutine(ShowInfoForFixedDuration("effectIndex out of bound", 3, 25));
                    }
                    DoNextCmd();
                }
            }
            else
            {
                DoNextCmd();
            }
        }
        else if (address.Equals("/trigger-effect"))
        {
            if (count > 0)
            {
                int effectIndex = -1;
                if (int.TryParse(dataList[0].ToString(), out effectIndex))
                {
                    if (effectIndex >= 0 && effectIndex < effectList.Length)
                    {
                        paramRecording.Reset();
                        float duration = 1;
                        float.TryParse(dataList[1].ToString(), out duration);

                        var effect = effectList[effectIndex];
                        effect.ResetTriggerData();
                        effect.SetEffectRoutineDuration(duration);
                        List <object> funcParamBuf = new List <object>();
                        for (int i = 2; i < count;)
                        {
                            int paramIndex = -1, patternID = -1, funcParamCount = -1;
                            funcParamBuf.Clear();
                            int.TryParse(dataList[i].ToString(), out paramIndex);
                            int.TryParse(dataList[i + 1].ToString(), out patternID);
                            int.TryParse(dataList[i + 2].ToString(), out funcParamCount);
                            if (paramIndex >= 0 && patternID >= 0 && funcParamCount > 0)
                            {
                                for (int k = 0; k < funcParamCount; k++)
                                {
                                    funcParamBuf.Add(dataList[i + 3 + k].ToString());
                                }
                                var paramFunc = ParamPattern.GetFunc(
                                    (ParamPattern.PatternType)patternID,
                                    funcParamBuf);
                                effect.AddData(paramIndex, paramFunc);
                                i = i + 3 + funcParamCount;
                            }
                            else
                            {
                                i += 3;
                            }
                        }

                        effect.TriggerEffect(DoNextCmd);
                    }
                    else
                    {
                        StartCoroutine(ShowInfoForFixedDuration("effectIndex out of bound", 3, 25));
                        DoNextCmd();
                    }
                }
            }
            else
            {
                return;
            }
        }
        else if (address.Equals("/record-params"))
        {
            int policy = 0;
            if (count > 0)
            {
                int.TryParse(dataList[0].ToString(), out policy);
            }

            paramRecording.Reset();
            paramRecording.state = EffectParamsRecording.State.Recording;

            if (curPlayer != null && curPlayer.url != null)
            {
                switch (policy)
                {
                case 0:                         //replay
                    if (curPlayer.isPlaying)
                    {
                        PlayVideo(curPlayer.url, true, false);
                    }
                    break;

                case 1:                         //no replay
                    if (!curPlayer.isPlaying)
                    {
                        PlayVideo(curPlayer.url, true, false);
                    }
                    break;

                case 2:
                    //no action
                    break;
                }
            }
            DoNextCmd();
        }
        else if (address.Equals("/stop-recording"))
        {
            StopRecording();
            DoNextCmd();
        }
        else if (address.Equals("/clear-recording"))
        {
            paramRecording.Reset();
            DoNextCmd();
        }
        else if (address.Equals("/set-image"))
        {
            if (count > 0)
            {
                var imgName = dataList[0].ToString();
                if (imgName.Equals("-1"))
                {
                    stillImage.sprite = null;
                }
                else if (imgCache.ContainsKey(imgName))
                {
                    var img = imgCache[imgName];
                    stillImage.sprite = img;
                }
                else
                {
                    var sprite = LoadSprite(imgName);
                    if (sprite != null)
                    {
                        imgCache.Add(imgName, sprite);
                        stillImage.sprite = sprite;
                    }
                }

                if (count > 1)
                {
                    float alpha = 0;
                    if (float.TryParse(dataList[1].ToString(), out alpha))
                    {
                        var color = stillImage.color;
                        color.a            = alpha;
                        stillImage.color   = color;
                        stillImage.enabled = true;
                        bgCanvas.enabled   = true;
                    }
                }

                DoNextCmd();
            }
            else
            {
                DoNextCmd();
            }
        }
        else if (address.Equals("/load-image"))
        {
            if (count > 0)
            {
                var imgName = dataList[0].ToString();
                var img     = LoadSprite(imgName);
                if (imgCache.ContainsKey(imgName))
                {
                    imgCache[imgName] = img;
                }
                else
                {
                    imgCache.Add(imgName, img);
                }

                DoNextCmd();
            }
            else
            {
                DoNextCmd();
            }
        }
        else if (address.Equals("/disable-effect"))
        {
            if (count > 0)
            {
                if (dataList[0].ToString().Equals("-1"))
                {
                    DisableAllEffect();
                }
                else
                {
                    for (int i = 0; i < count; i++)
                    {
                        int effectIndex = -1;
                        if (int.TryParse(dataList[i].ToString(), out effectIndex))
                        {
                            if (effectList.Length > effectIndex && effectIndex >= 0)
                            {
                                effectList[effectIndex].SetEffectActive(false);
                            }
                        }
                    }
                }
            }
            paramRecording.Reset();
            DoNextCmd();
        }
        else if (address.Equals("/close-all"))
        {
            CloseAll();
            DoNextCmd();
        }
        else if (address.Equals("/show-text"))
        {
            if (count > 5)
            {
                TextManager.SentenceData sd = null;
                string content = dataList[0].ToString();

                if (content.Equals("-1"))
                {
                    sd = txtManager.GetRandSentenceData();
                }
                else
                {
                    sd      = new TextManager.SentenceData();
                    sd.main = content;
                }
                TextManager.Orientation orient = TextManager.Orientation.Horizontal;
                int   fontSize    = 28;
                float posX        = 0.5f;
                float posY        = 0.5f;
                int   effectIndex = 0;

                int val = 0;
                if (int.TryParse(dataList[1].ToString(), out val))
                {
                    orient = (TextManager.Orientation)val;
                }
                if (count > 2)
                {
                    int.TryParse(dataList[2].ToString(), out fontSize);
                }

                if (count > 3)
                {
                    float.TryParse(dataList[3].ToString(), out posX);
                }

                if (count > 4)
                {
                    float.TryParse(dataList[4].ToString(), out posY);
                }

                if (count > 5)
                {
                    int.TryParse(dataList[5].ToString(), out effectIndex);
                }

                dataBuf.Clear();
                for (int i = 6; i < count; i++)
                {
                    dataBuf.Add(dataList[i].ToString());
                }

                txtManager.ShowText(sd, orient, fontSize, posX, posY, effectIndex, dataBuf);
            }
            else
            {
                txtManager.ShowText();
            }

            DoNextCmd();
        }
        else if (address.Equals("/set-brightness"))
        {
            if (count > 0)
            {
                int val = 0;
                if (int.TryParse(dataList[0].ToString(), out val))
                {
                    DeviceUtils.SetScreenBrightness(val);
                }
            }

            DoNextCmd();
        }
        else if (address.Equals("/set-bg-color"))
        {
            if (count > 0)
            {
                float val   = 0;
                Color color = Color.white;
                int   i     = 0;
                foreach (var valStr in dataList)
                {
                    if (float.TryParse(valStr.ToString(), out val))
                    {
                        if (i == 0)
                        {
                            color.r = val;
                        }
                        else if (i == 1)
                        {
                            color.g = val;
                        }
                        else if (i == 2)
                        {
                            color.b = val;
                        }
                        else
                        {
                            color.a = val;
                        }
                    }
                    i++;
                }
                bg.color = color;
                DoNextCmd();
            }
            else
            {
                DoNextCmd();
            }
        }
        else if (address.Equals("/set-video-alpha"))
        {
            if (count > 0)
            {
                float alpha = 1;
                if (float.TryParse(dataList[0].ToString(), out alpha))
                {
                    var color = videoImage.color;
                    color.a          = alpha;
                    videoImage.color = color;
                }

                DoNextCmd();
            }
            else
            {
                DoNextCmd();
            }
        }
        else if (address.Equals("/set-video-speed"))
        {
            if (count > 0)
            {
                float factor = 0;
                if (float.TryParse(dataList[0].ToString(), out factor))
                {
                    SetVideoSpeed(factor);
                }

                DoNextCmd();
            }
        }
        else if (address.Equals("/set-start-pos"))
        {
            if (count > 0)
            {
                float val = -1;
                float.TryParse(dataList[0].ToString(), out val);
                SetLoopStartPos(val);
                DoNextCmd();
            }
            else
            {
                DoNextCmd();
            }
        }
        else if (address.Equals("/get-battery-level"))
        {
            if (oscClient != null)
            {
                if (oscClient != null)
                {
                    OSCMessage message = new OSCMessage("/battery-level");
                    message.Append(SystemInfo.batteryLevel);
                    oscClient.Send(message);
                }
            }

            DoNextCmd();
        }
        else if (address.Equals("/set-text-effect-sentences-file"))
        {
            if (count > 0)
            {
                string path = GetTextFilePath(dataList[0].ToString());
                if (!File.Exists(path))
                {
                    StartCoroutine(ShowInfoForFixedDuration("no such text file", 3, 25));
                    return;
                }
                else
                {
                    PlayerPrefs.SetString(TextManager.sentenceInputPathKey, path);
                    txtManager.ProcessInputData(File.ReadAllText(path));
                }

                DoNextCmd();
            }
            else
            {
                DoNextCmd();
            }
        }
        else if (address.Equals("/reset-receiver"))
        {
            Debug.Log("reset receiver");
            reciever.Close();
            reciever = new OSCReciever();
            reciever.Open(oscPort);

            DoNextCmd();
        }
        //unused cmds
        else if (address.Equals("/set-canvas"))
        {
            if (count > 0)
            {
                int val = 1;
                if (int.TryParse(dataList[0].ToString(), out val))
                {
                    if (count > 1)
                    {
                        if (dataList[1].ToString().Equals("txt"))
                        {
                            txtCanvas.enabled = val == 1;
                        }
                        else
                        {
                            bgCanvas.enabled = val == 1;
                        }
                    }
                    else
                    {
                        bgCanvas.enabled = val == 1;
                    }
                }
            }
            else
            {
                return;
            }
        }
        else if (address.Equals("/set-camera"))
        {
            if (count > 0 && cam != null)
            {
                int val = 0;
                if (int.TryParse(dataList[0].ToString(), out val))
                {
                    cam.clearFlags = (CameraClearFlags)val;
                }
            }
        }
        else if (address.Equals("/cache-video"))
        {
            if (count > 0)
            {
                var url = dataList[0].ToString();
                CacheVideoPlayer(url);
            }
            else
            {
                return;
            }
        }
        else if (address.Equals("/release-video"))
        {
            if (count > 0)
            {
                var url = dataList[0].ToString();
                ReleaseVideoPlayer(url);
            }
            else
            {
                return;
            }
        }
    }
Example #15
0
 // Use this for initialization
 void Start()
 {
     manager = new OSCReciever();
     manager.Open(port);
 }