Пример #1
0
        public override void DeepCopy(IDeepCopyable source, ICopyManager copyManager)
        {
            Detach();
            base.DeepCopy(source, copyManager);
            Panel p = (Panel)source;

            Background  = copyManager.GetCopy(p.Background);
            IsItemsHost = p.IsItemsHost;
            FrameworkElementCollection children = Children;

            foreach (FrameworkElement el in p.Children)
            {
                children.Add(copyManager.GetCopy(el), false);
            }
            Attach();
        }
Пример #2
0
        private void InitializeBars()
        {
            IAudioPlayerAnalyze player = ActiveSpectrumPlayer;

            if (player == null)
            {
                _barWidth = 1;
                _maximumFrequencyIndex = -1;
                _minimumFrequencyIndex = 0;
                return;
            }

            if (!_refreshShapes || _spectrumCanvas == null)
            {
                return;
            }

            int  maxIndex;
            int  minIndex;
            bool res = player.GetFFTFrequencyIndex(MaximumFrequency, out maxIndex);

            res |= player.GetFFTFrequencyIndex(MinimumFrequency, out minIndex);
            if (!res)
            {
                return;
            }
            _maximumFrequencyIndex = Math.Min(maxIndex + 1, FREQUENCY_BUFFER_SIZE - 1);
            _minimumFrequencyIndex = Math.Min(minIndex, FREQUENCY_BUFFER_SIZE - 1);

            _barWidth = Math.Max(((_spectrumCanvas.ActualWidth - (BarSpacing * (BarCount + 1))) / BarCount), 1);
            int actualBarCount = _barWidth >= 1.0d ? BarCount : Math.Max((int)((_spectrumCanvas.ActualWidth - BarSpacing) / (_barWidth + BarSpacing)), 1);

            _channelPeakData = new float[actualBarCount];

            int        indexCount            = _maximumFrequencyIndex - _minimumFrequencyIndex;
            int        linearIndexBucketSize = (int)Math.Round(indexCount / (double)actualBarCount, 0);
            List <int> maxIndexList          = new List <int>();
            List <int> maxLogScaleIndexList  = new List <int>();
            double     maxLog = Math.Log(actualBarCount, actualBarCount);

            for (int i = 1; i < actualBarCount; i++)
            {
                maxIndexList.Add(_minimumFrequencyIndex + (i * linearIndexBucketSize));
                int logIndex = (int)((maxLog - Math.Log((actualBarCount + 1) - i, (actualBarCount + 1))) * indexCount) + _minimumFrequencyIndex;
                maxLogScaleIndexList.Add(logIndex);
            }
            maxIndexList.Add(_maximumFrequencyIndex);
            maxLogScaleIndexList.Add(_maximumFrequencyIndex);
            _barIndexMax         = maxIndexList.ToArray();
            _barLogScaleIndexMax = maxLogScaleIndexList.ToArray();

            FrameworkElementCollection canvasChildren = _spectrumCanvas.Children;

            canvasChildren.StartUpdate();
            try
            {
                canvasChildren.Clear();

                double height        = _spectrumCanvas.ActualHeight;
                double peakDotHeight = Math.Max(_barWidth / 2.0f, 1);
                for (int i = 0; i < actualBarCount; i++)
                {
                    // Deep copy the styles to each bar
                    Style barStyleCopy  = MpfCopyManager.DeepCopyCutLVPs(BarStyle);
                    Style peakStyleCopy = MpfCopyManager.DeepCopyCutLVPs(PeakStyle);

                    double  xCoord     = BarSpacing + (_barWidth * i) + (BarSpacing * i) + 1;
                    Control barControl = new Control
                    {
                        Width  = _barWidth,
                        Height = height,
                        Style  = barStyleCopy
                    };
                    Canvas.SetLeft(barControl, xCoord);
                    Canvas.SetBottom(barControl, height);
                    _barShapes.Add(barControl);
                    canvasChildren.Add(barControl);

                    Control peakControl = new Control
                    {
                        Width  = _barWidth,
                        Height = peakDotHeight,
                        Style  = peakStyleCopy
                    };
                    Canvas.SetLeft(peakControl, xCoord);
                    Canvas.SetBottom(peakControl, height);
                    _peakShapes.Add(peakControl);
                    canvasChildren.Add(peakControl);
                }
            }
            finally
            {
                canvasChildren.EndUpdate();
            }
            ActualBarWidth = _barWidth;
            _refreshShapes = false;
        }