Example #1
0
        /// <inheritdoc cref="AbstractUpdateAwareDecorator.OnAttached" />
        /// <inheritdoc cref="IDecorator.OnAttached" />
        public override void OnAttached(IDecoratable decoratable)
        {
            base.OnAttached(decoratable);

            _currentPhase      = ADSRPhase.Attack;
            _currentPhaseValue = Attack;
            _repetitionCount   = 0;
            _currentValue      = 0;
        }
Example #2
0
        /// <summary>
        /// Resets the effect.
        /// </summary>
        public override void OnAttach(IBrush brush)
        {
            base.OnAttach(brush);

            _currentPhase      = ADSRPhase.Attack;
            _currentPhaseValue = Attack;
            _repetitionCount   = 0;
            brush.Opacity      = 0f;
        }
Example #3
0
        public override void Update(float deltaTime)
        {
            _currentPhaseValue -= deltaTime;

            // Using ifs instead of a switch allows to skip phases with time 0.

            if (_currentPhase == ADSRPhase.Attack)
                if (_currentPhaseValue > 0f)
                    EffectBrush.Opacity = Math.Min(1f, (Attack - _currentPhaseValue) / Attack) * AttackValue;
                else
                {
                    _currentPhaseValue = Decay;
                    _currentPhase = ADSRPhase.Decay;
                }

            if (_currentPhase == ADSRPhase.Decay)
                if (_currentPhaseValue > 0f)
                    EffectBrush.Opacity = SustainValue + (Math.Min(1f, _currentPhaseValue / Decay) * (AttackValue - SustainValue));
                else
                {
                    _currentPhaseValue = Sustain;
                    _currentPhase = ADSRPhase.Sustain;
                }

            if (_currentPhase == ADSRPhase.Sustain)
                if (_currentPhaseValue > 0f)
                    EffectBrush.Opacity = SustainValue;
                else
                {
                    _currentPhaseValue = Release;
                    _currentPhase = ADSRPhase.Release;
                }

            if (_currentPhase == ADSRPhase.Release)
                if (_currentPhaseValue > 0f)
                    EffectBrush.Opacity = Math.Min(1f, _currentPhaseValue / Release) * SustainValue;
                else
                {
                    _currentPhaseValue = Interval;
                    _currentPhase = ADSRPhase.Pause;
                }

            if (_currentPhase == ADSRPhase.Pause)
                if (_currentPhaseValue > 0f)
                    EffectBrush.Opacity = 0f;
                else
                {
                    if (++_repetitionCount >= Repetitions && Repetitions > 0)
                        IsDone = true;
                    _currentPhaseValue = Attack;
                    _currentPhase = ADSRPhase.Attack;
                }
        }
Example #4
0
        /// <inheritdoc />
        protected override void Update(double deltaTime)
        {
            _currentPhaseValue -= deltaTime;

            // Using ifs instead of a switch allows to skip phases with time 0.
            // ReSharper disable InvertIf

            if (_currentPhase == ADSRPhase.Attack)
            {
                if (_currentPhaseValue > 0)
                {
                    _currentValue = PauseValue + (Math.Min(1, (Attack - _currentPhaseValue) / Attack) * (AttackValue - PauseValue));
                }
                else
                {
                    _currentPhaseValue = Decay;
                    _currentPhase      = ADSRPhase.Decay;
                }
            }

            if (_currentPhase == ADSRPhase.Decay)
            {
                if (_currentPhaseValue > 0)
                {
                    _currentValue = SustainValue + (Math.Min(1, _currentPhaseValue / Decay) * (AttackValue - SustainValue));
                }
                else
                {
                    _currentPhaseValue = Sustain;
                    _currentPhase      = ADSRPhase.Sustain;
                }
            }

            if (_currentPhase == ADSRPhase.Sustain)
            {
                if (_currentPhaseValue > 0)
                {
                    _currentValue = SustainValue;
                }
                else
                {
                    _currentPhaseValue = Release;
                    _currentPhase      = ADSRPhase.Release;
                }
            }

            if (_currentPhase == ADSRPhase.Release)
            {
                if (_currentPhaseValue > 0)
                {
                    _currentValue = PauseValue + (Math.Min(1, _currentPhaseValue / Release) * (SustainValue - PauseValue));
                }
                else
                {
                    _currentPhaseValue = Interval;
                    _currentPhase      = ADSRPhase.Pause;
                }
            }

            if (_currentPhase == ADSRPhase.Pause)
            {
                if (_currentPhaseValue > 0)
                {
                    _currentValue = PauseValue;
                }
                else
                {
                    if ((++_repetitionCount >= Repetitions) && (Repetitions > 0))
                    {
                        Detach <IBrush, FlashDecorator>();
                    }
                    _currentPhaseValue = Attack;
                    _currentPhase      = ADSRPhase.Attack;
                }
            }

            // ReSharper restore InvertIf
        }
Example #5
0
        public override void OnAttach()
        {
            base.OnAttach();

            _currentPhase = ADSRPhase.Attack;
            _currentPhaseValue = Attack;
            _repetitionCount = 0;
            EffectBrush.Opacity = 0f;
        }
Example #6
0
        /// <summary>
        /// Updates the effect.
        /// </summary>
        /// <param name="deltaTime">The elapsed time (in seconds) since the last update.</param>
        public override void Update(float deltaTime)
        {
            _currentPhaseValue -= deltaTime;

            // Using ifs instead of a switch allows to skip phases with time 0.
            // ReSharper disable InvertIf

            if (_currentPhase == ADSRPhase.Attack)
            {
                if (_currentPhaseValue > 0f)
                {
                    Brush.Opacity = Math.Min(1f, (Attack - _currentPhaseValue) / Attack) * AttackValue;
                }
                else
                {
                    _currentPhaseValue = Decay;
                    _currentPhase      = ADSRPhase.Decay;
                }
            }

            if (_currentPhase == ADSRPhase.Decay)
            {
                if (_currentPhaseValue > 0f)
                {
                    Brush.Opacity = SustainValue + (Math.Min(1f, _currentPhaseValue / Decay) * (AttackValue - SustainValue));
                }
                else
                {
                    _currentPhaseValue = Sustain;
                    _currentPhase      = ADSRPhase.Sustain;
                }
            }

            if (_currentPhase == ADSRPhase.Sustain)
            {
                if (_currentPhaseValue > 0f)
                {
                    Brush.Opacity = SustainValue;
                }
                else
                {
                    _currentPhaseValue = Release;
                    _currentPhase      = ADSRPhase.Release;
                }
            }

            if (_currentPhase == ADSRPhase.Release)
            {
                if (_currentPhaseValue > 0f)
                {
                    Brush.Opacity = Math.Min(1f, _currentPhaseValue / Release) * SustainValue;
                }
                else
                {
                    _currentPhaseValue = Interval;
                    _currentPhase      = ADSRPhase.Pause;
                }
            }

            if (_currentPhase == ADSRPhase.Pause)
            {
                if (_currentPhaseValue > 0f)
                {
                    Brush.Opacity = 0f;
                }
                else
                {
                    if (++_repetitionCount >= Repetitions && Repetitions > 0)
                    {
                        IsDone = true;
                    }
                    _currentPhaseValue = Attack;
                    _currentPhase      = ADSRPhase.Attack;
                }
            }

            // ReSharper restore InvertIf
        }