Exemplo n.º 1
0
 public bool MatchCurrentLoop(LoopArc arc, float time)
 {
     if (currentLoopIndex < 0)
     {
         return(false);
     }
     return(arc.Equals(loopArcs[currentLoopIndex]) && (time - loopArcs[currentLoopIndex].toTime) <= HeadTrack._LOOP_TRANS_DURATION);
 }
Exemplo n.º 2
0
        public override bool Equals(System.Object obj)
        {
            LoopArc otherLoop = obj as LoopArc;

            if (otherLoop == null)
            {
                return(false);
            }
            return(Mathf.Approximately(this.fromTime, otherLoop.fromTime) && Mathf.Approximately(this.toTime, otherLoop.toTime));
        }
Exemplo n.º 3
0
 public int MatchExistingLoop(LoopArc arc)
 {
     for (int j = 0; j < loopArcs.Count; j++)
     {
         if (loopArcs[j].Equals(arc))
         {
             return(j);
         }
     }
     return(-1);
 }
        // Transition where blending happens only in the latter half.
        public bool UnidirectionalTransition()
        {
            LoopArc loopArc   = currentLoopArc;
            float   loopStart = loopArc.toTime;                             // Blend time with respect to main player (forward).
            float   loopEnd   = loopStart + HeadTrack._LOOP_TRANS_DURATION; // Blend time with respect to main player (forward).

            if (GetComponent <HeadTrack>().GetCurrentClipEndTime() >= 0)
            {
                if (GetComponent <HeadTrack>().GetMediaFullDuration() - loopArc.fromTime < HeadTrack._LOOP_TRANS_DURATION)
                {
                    loopEnd = loopArc.toTime + GetComponent <HeadTrack>().GetMediaFullDuration() - loopArc.fromTime;
                }
            }

            if (!Mathf.Approximately(_mediaOffset, loopArc.fromTime - loopArc.toTime))
            {
                _mediaOffset = loopArc.fromTime - loopArc.toTime;
            }
            float currentTime     = GetCurrentTime();
            float currentBlendVal = _mesh.material.GetFloat(_propBlend);

            // Can happen when loop is done or when user seeks in the middle of a transition.
            if (!isBetween(currentTime, loopStart, loopEnd))
            {
                UpdateReturnPlayer(currentBlendVal);
                int finalBlend = _returnMediaIndex == _mainMediaIndex ? 1 : 0;
                _mesh.material.SetFloat(_propBlend, (float)finalBlend);
                _lastBlendValue = finalBlend;
                isTransitioning = false;
                UpdateAudio();
                return(true);  // Done with transition.
            }

            float intermediateBlend = (currentTime - loopStart) / (loopEnd - loopStart);

            intermediateBlend = Mathf.Clamp(intermediateBlend, 0f, 1f);
            if (_lastBlendValue == 0)
            {
                _mesh.material.SetFloat(_propBlend, intermediateBlend);
            }
            else
            {
                _mesh.material.SetFloat(_propBlend, 1.0f - intermediateBlend);
            }
            Debug.Log("Updated blend value to " + _mesh.material.GetFloat(_propBlend));
            isTransitioning = true;
            UpdateAudio();
            return(false);  // Not done with loop transition.
        }
Exemplo n.º 5
0
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }

            LoopArc otherLoopArc = obj as LoopArc;

            if (otherLoopArc == null)
            {
                return(1);
            }
            return(this.fromTime.CompareTo(otherLoopArc.fromTime));
        }
Exemplo n.º 6
0
        public void AddLoopArc(float fromTime, float toTime, float clipStart, float clipEnd)
        {
            if (loopArcs == null)
            {
                loopArcs = new List <LoopArc>();
            }
            LoopArc arc = new LoopArc(fromTime, toTime, clipStart, clipEnd);
            int     existingLoopIndex = MatchExistingLoop(arc);

            if (existingLoopIndex < 0)
            {
                loopArcs.Add(arc);
                currentLoopIndex = loopArcs.Count - 1;
            }
            else
            {
                currentLoopIndex = existingLoopIndex;
            }
        }
Exemplo n.º 7
0
        public void Transition(int currentFrame, int curView, MultiplePlayerControl multiMedia, HeadTrack _headtrack)
        {
            int gateFrame = (int)(this.gateTime * multiMedia.Player.Info.GetVideoFrameRate());

            if (!isTargetView(curView) && (multiMedia.expectedCurrentFrame == gateFrame || multiMedia.expectedNextFrame == gateFrame) && currentFrame != multiMedia.expectedCurrentFrame && currentFrame != multiMedia.expectedNextFrame)
            {
                Debug.LogError("SKIPPED GATE FRAME!");
            }
            else if (currentFrame > gateFrame || isTargetView(curView))
            {
                multiMedia.expectedCurrentFrame = currentFrame;
                multiMedia.expectedNextFrame    = currentFrame + 1;

                if (sp.jumpImmediately && currentFrame < gateFrame - HeadTrack._LOOP_TRANS_DURATION && isTargetView(curView))
                {
                    int jumpToFrame = gateFrame - (int)(HeadTrack._LOOP_TRANS_DURATION * multiMedia.Player.Info.GetVideoFrameRate());
                    if (sp.views[curView].CanJumpTo(currentFrame, jumpToFrame, sp.jumpThreshold))
                    {
                        float jumpToTime = this.gateTime - HeadTrack._LOOP_TRANS_DURATION;
                        Debug.Log("Frame rate: " + multiMedia.Player.Info.GetVideoFrameRate());
                        Debug.Log("Sp start time: " + sp.startTime + " Jump to time: " + jumpToTime);
                        Debug.Log("GOING to jump from " + (sp.startTime + 1f * currentFrame / multiMedia.Player.Info.GetVideoFrameRate()) + " to time " + (sp.startTime + jumpToTime));
                        this.sp.views[curView].AddLoopArc(sp.startTime + 1f * currentFrame / multiMedia.Player.Info.GetVideoFrameRate(), sp.startTime + jumpToTime, sp.startTime, sp.endTime);
                        Debug.Log("Sp now has " + this.sp.views[curView].GetLoopArcs().Count() + " looparcs");

                        LoopArc currentLoop = this.sp.views[curView].GetCurrentLoop();
                        multiMedia.currentLoopArc = currentLoop;
                        multiMedia._mediaOffset   = currentLoop.fromTime - currentLoop.toTime;
                        Debug.Log("Media current loop arc is " + multiMedia.currentLoopArc + ". Set media offset to " + multiMedia._mediaOffset);

                        // Seek to apply media offset.
                        multiMedia.isTransitioning = true;
                        multiMedia.SyncMediaPlayers();
                        multiMedia.expectedCurrentFrame = jumpToFrame;
                        multiMedia.expectedNextFrame    = jumpToFrame + 1;
                    }
                }

                return; // Don't transition if current frame is past gate frame.
            }

            int jumpTo;
            int fromFrame = currentFrame;

            if (sp.ReachedCutFrame(curView, currentFrame))
            {
                jumpTo = sp.FindJumpToFrame(curView, currentFrame);
                Debug.Log("Reached cut frame. Jumping to: " + jumpTo);
            }
            else if (sp.PastLastCutFrame(curView, currentFrame))  // May happen if computer suddenly lagged and missed a frame update.
            {
                Debug.LogWarning("ERROR! REACHED DANGER ZONE " + curView + ", " + currentFrame);
                int lastCutFrame = sp.FindLastCutFrame(curView);
                jumpTo    = sp.FindJumpToFrame(curView, lastCutFrame);
                fromFrame = lastCutFrame;
            }
            else
            {
                jumpTo = currentFrame + 1;
            }
            multiMedia.expectedCurrentFrame = currentFrame;
            multiMedia.expectedNextFrame    = jumpTo;

            if (jumpTo == currentFrame)
            {
                Debug.Log("Paused media player because jumpto " + jumpTo + " is same as current frame: " + currentFrame);
                _headtrack.playMode = false;
                multiMedia.Pause();
            }
            else if (jumpTo != currentFrame + 1)  // if jumping to a frame that's not the next frame, then perform a seek. Otherwise just keep playing.
            {
                float jumpToTime = 1f * jumpTo / multiMedia.Player.Info.GetVideoFrameRate();
                Debug.Log("Frame rate: " + multiMedia.Player.Info.GetVideoFrameRate());
                Debug.Log("Sp start tiem: " + sp.startTime + " Jump to time: " + jumpToTime);
                Debug.Log("GOING to jump from " + (sp.startTime + 1f * currentFrame / multiMedia.Player.Info.GetVideoFrameRate()) + " to time " + (sp.startTime + jumpToTime));
                this.sp.views[curView].AddLoopArc(sp.startTime + currentFrame / multiMedia.Player.Info.GetVideoFrameRate(), sp.startTime + jumpToTime, sp.startTime, sp.endTime);
                Debug.Log("Sp now has " + this.sp.views[curView].GetLoopArcs().Count() + " looparcs");

                // Set media offset.
                LoopArc currentLoop = this.sp.views[curView].GetCurrentLoop();
                multiMedia.currentLoopArc = currentLoop;
                multiMedia._mediaOffset   = currentLoop.fromTime - currentLoop.toTime;

                Debug.Log("Set media offset to " + multiMedia._mediaOffset);

                // Seek to apply media offset.
                multiMedia.isTransitioning = true;
                multiMedia.SyncMediaPlayers();
                multiMedia.expectedCurrentFrame = jumpTo;
                multiMedia.expectedNextFrame    = jumpTo + 1;
            }
        }