예제 #1
0
        protected void TimerCallback()
        {
            try
            {
                if (IsHandleCreated)
                {
                    BeginInvoke(new MethodInvoker(Refresh));
                }
                else
                {
                    return;
                }
            }
            catch { }

            int  nDecValue = _MaxRangeValue / _LEDCount;
            bool noUpdate  = true;

            Monitor.Enter(_meterData);
            for (int i = 0; i < _meterData.Length; i++)
            {
                PeakMeterData pm = _meterData[i];

                if (pm.Value > 0)
                {
                    pm.Value -= (_LEDCount > 1 ? nDecValue : (_MaxRangeValue * DecrementPercent) / 100);
                    if (pm.Value < 0)
                    {
                        pm.Value = 0;
                    }
                    noUpdate = false;
                }

                if (pm.Speed > 0)
                {
                    pm.Speed -= 1;
                    noUpdate  = false;
                }

                if (pm.Speed == 0 && pm.Falloff > 0)
                {
                    pm.Falloff -= (_LEDCount > 1 ? nDecValue >> 1 : 5);
                    if (pm.Falloff < 0)
                    {
                        pm.Falloff = 0;
                    }
                    noUpdate = false;
                }

                // re-assign PeakMeterData
                _meterData[i] = pm;
            }

            Monitor.Exit(_meterData);

            if (noUpdate)             // Stop timer if no more data but do not reset ID
            {
                StopAnimation();
            }
        }
예제 #2
0
        /// <summary>
        /// Set meter band value
        /// </summary>
        /// <param name="arrayValue">Array value for the bands</param>
        /// <param name="offset">Starting offset position</param>
        /// <param name="size">Number of values to set</param>
        /// <returns></returns>
        public void SetData(int[] arrayValue, int offset, int size)
        {
            if (arrayValue == null)
            {
                throw new ArgumentNullException("arrayValue");
            }
            if (arrayValue.Length < (offset + size))
            {
                throw new ArgumentOutOfRangeException("arrayValue");
            }
            if (_animationTimer == null)
            {
                throw new InvalidOperationException("Peak meter must have been started before setting data.");
            }

            if (InvokeRequired)
            {
                BeginInvoke((Action <int[], int, int>)SetData, arrayValue, offset, size);
                return;
            }

            Monitor.Enter(this._meterData);

            int maxIndex = offset + size;

            for (int i = offset; i < maxIndex; i++)
            {
                if (i < this._meterData.Length)
                {
                    PeakMeterData pm = this._meterData[i];
                    pm.Value = Math.Min(arrayValue[i], this._MaxRangeValue);
                    pm.Value = Math.Max(pm.Value, 0);
                    if (pm.Falloff < pm.Value)
                    {
                        pm.Falloff = pm.Value;
                        pm.Speed   = this._FalloffSpeed;
                    }
                    _meterData[i] = pm;
                }
            }
            Monitor.Exit(_meterData);

            // check that timer should be restarted
            if (!_animationTimer.Enabled)
            {
                _animationTimer.Start();
            }
            else
            {
                Refresh();
            }
        }