Beispiel #1
0
        private void Update(EvaluationContext context)
        {
            var startPosition = StartValue.GetValue(context);
            var modulo        = Modulo.GetValue(context);
            var increment     = Increment.GetValue(context);

            _rate     = Rate.GetValue(context);
            _phase    = Phase.GetValue(context);
            _blending = Blending.GetValue(context);
            var reset = TriggerReset.GetValue(context);
            var jump  = TriggerCount.GetValue(context);

            //var jump = false;

            if (!_initialized || reset || float.IsNaN(_count))
            {
                _count       = 0;
                _initialized = true;
                jump         = true;
            }

            _beatTime = EvaluationContext.BeatTime;

            if (UseRate)
            {
                var activationIndex = (int)(_beatTime * _rate + _phase);
                if (activationIndex != _lastActivationIndex)
                {
                    //Log.Debug($"ai {activationIndex}  != {_lastActivationIndex}  rate={_rate} t = {_beatTime} ");
                    _lastActivationIndex = activationIndex;
                    jump = true;
                }
            }

            if (jump)
            {
                if (modulo > 0.001f)
                {
                    _jumpStartOffset   = _jumpTargetOffset;
                    _jumpTargetOffset += 1;
                }
                else
                {
                    _jumpStartOffset  = _count;
                    _jumpTargetOffset = _count + increment;
                }

                // if (_jumpTargetOffset > modulo)
                // {
                //     _count = 0;
                //     _jumpStartOffset = 0;
                //     _jumpTargetOffset = increment;
                // }
                _lastJumpTime = _beatTime;
            }

            if (_blending >= 0.001)
            {
                var t = (Fragment / _blending).Clamp(0, 1);
                if (SmoothBlending.GetValue(context))
                {
                    t = MathUtils.SmootherStep(0, 1, t);
                }

                _count = MathUtils.Lerp(_jumpStartOffset, _jumpTargetOffset, t);
            }
            else
            {
                _count = _jumpTargetOffset;
            }

            if (modulo > 0.001f)
            {
                Result.Value = (_count % modulo) * increment + startPosition;
            }
            else
            {
                Result.Value = _count + startPosition;
            }

            WasStep.Value = jump;
            Result.DirtyFlag.Clear();
            WasStep.DirtyFlag.Clear();
        }