示例#1
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 bool SetData(int[] arrayValue, int offset, int size)
        {
            if (arrayValue == null)
            {
                throw new ArgumentNullException("arrayValue");
            }
            if (arrayValue.Length < (offset + size))
            {
                throw new ArgumentOutOfRangeException("arrayValue");
            }

            if (this.InvokeRequired)
            {
                SetDataDelegate setDelegate = new SetDataDelegate(this.SetData);
                return((bool)this.Invoke(setDelegate, arrayValue, offset, size));
            }
            bool isRunning = this.IsActive;

            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;
                    }
                    this._meterData[i] = pm;
                }
            }
            Monitor.Exit(this._meterData);

            // check that timer should be restarted
            if (_AnimDelay != Timeout.Infinite)
            {
                if (_animationTimer == null)
                {
                    StartAnimation(_AnimDelay);
                }
            }
            else
            {
                Refresh();
            }

            return(isRunning);
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="thisObject"></param>
        protected void TimerCallback(Object thisObject)
        {
            try
            {
                // refresh now!
                Control thisControl = thisObject as Control;
                if (thisControl != null && thisControl.IsHandleCreated)
                {
                    thisControl.Invoke(new MethodInvoker(Refresh));
                }
                else
                {
                    return;
                }
            }
            catch (Exception)
            {
                // just ignore
            }

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

            Monitor.Enter(this._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(this._meterData);

            if (noUpdate) // Stop timer if no more data but do not reset ID
            {
                StopAnimation();
            }
        }