Наследование: Artemis.Profiles.Layers.Models.LayerPropertiesModel
Пример #1
0
        private void ApplyHorizontal(AudioPropertiesModel settings)
        {
            var index = 0;

            foreach (var audioLayer in _audioLayers)
            {
                int width;
                if (SpectrumData.Count > index)
                {
                    width = (int)Math.Round(SpectrumData[index] / 2.55);
                }
                else
                {
                    width = 0;
                }

                // Apply Sensitivity setting
                width = width * settings.Sensitivity;

                var newWidth = settings.Width / 100.0 * width;
                if (newWidth >= audioLayer.Properties.Width)
                {
                    audioLayer.Properties.Width = newWidth;
                }
                else
                {
                    audioLayer.Properties.Width = audioLayer.Properties.Width - settings.FadeSpeed;
                }
                if (audioLayer.Properties.Width < 0)
                {
                    audioLayer.Properties.Width = 0;
                }

                audioLayer.Properties.Brush   = settings.Brush;
                audioLayer.Properties.Contain = false;

                // Reverse the direction if settings require it
                if (settings.Direction == Direction.RightToLeft)
                {
                    audioLayer.Properties.X = settings.X + (settings.Width - audioLayer.Properties.Width);
                }

                audioLayer.Update(null, false, true);
                index++;
            }
        }
Пример #2
0
        private void SetupHorizontal(AudioPropertiesModel settings)
        {
            _lines = (int)settings.Height;
            for (var i = 0; i < _lines; i++)
            {
                var layer = LayerModel.CreateLayer();
                layer.Properties.X       = settings.X;
                layer.Properties.Y       = settings.Y + i;
                layer.Properties.Width   = 0;
                layer.Properties.Height  = 1;
                layer.LayerAnimation     = new NoneAnimation();
                layer.Properties.Brush   = settings.Brush;
                layer.Properties.Contain = false;

                _audioLayers.Add(layer);
                layer.Update(null, false, true);
            }
        }
Пример #3
0
        private void ApplyVertical(AudioPropertiesModel settings)
        {
            var index = 0;

            foreach (var audioLayer in _audioLayers)
            {
                int height;
                if (SpectrumData.Count > index)
                {
                    height = (int)Math.Round(SpectrumData[index] / 2.55);
                }
                else
                {
                    height = 0;
                }

                // Apply Sensitivity setting
                height = height * settings.Sensitivity;

                var newHeight = settings.Height / 100.0 * height;
                if (newHeight >= audioLayer.Properties.Height)
                {
                    audioLayer.Properties.Height = newHeight;
                }
                else
                {
                    audioLayer.Properties.Height = audioLayer.Properties.Height - settings.FadeSpeed;
                }
                if (audioLayer.Properties.Height < 0)
                {
                    audioLayer.Properties.Height = 0;
                }

                // Reverse the direction if settings require it
                if (settings.Direction == Direction.BottomToTop)
                {
                    audioLayer.Properties.Y = settings.Y + (settings.Height - audioLayer.Properties.Height);
                }

                audioLayer.Update(null, false, true);
                index++;
            }
        }
Пример #4
0
        /// <summary>
        ///     Updates the inner layers when the settings have changed
        /// </summary>
        /// <param name="layerModel"></param>
        private void UpdateLayers(LayerModel layerModel)
        {
            var settings = (AudioPropertiesModel)layerModel.Properties;

            if (JsonConvert.SerializeObject(settings).Equals(JsonConvert.SerializeObject(_previousSettings)))
            {
                return;
            }

            _previousSettings = GeneralHelpers.Clone((AudioPropertiesModel)layerModel.Properties);

            _audioLayers.Clear();
            if (settings.Direction == Direction.TopToBottom || settings.Direction == Direction.BottomToTop)
            {
                SetupVertical(settings);
            }
            else if (settings.Direction == Direction.LeftToRight || settings.Direction == Direction.RightToLeft)
            {
                SetupHorizontal(settings);
            }
        }
Пример #5
0
        public void Update(LayerModel layerModel, ModuleDataModel dataModel, bool isPreview = false)
        {
            layerModel.ApplyProperties(true);
            var newProperties = (AudioPropertiesModel)layerModel.Properties;

            if (_properties == null)
            {
                _properties = newProperties;
            }

            SubscribeToAudioChange();

            if (_audioCapture == null || newProperties.Device != _properties.Device || newProperties.DeviceType != _properties.DeviceType)
            {
                var device = GetMmDevice();
                if (device != null)
                {
                    _audioCapture = _audioCaptureManager.GetAudioCapture(device, newProperties.DeviceType);
                }
            }

            _properties = newProperties;

            if (_audioCapture == null)
            {
                return;
            }

            _audioCapture.Pulse();

            var direction = ((AudioPropertiesModel)layerModel.Properties).Direction;

            int    currentLines;
            double currentHeight;

            if (direction == Direction.BottomToTop || direction == Direction.TopToBottom)
            {
                currentLines  = (int)layerModel.Width;
                currentHeight = layerModel.Height;
            }
            else
            {
                currentLines  = (int)layerModel.Height;
                currentHeight = layerModel.Width;
            }

            // Get a new line spectrum if the lines changed, it is null or the layer hasn't rendered for a few frames
            if (_lines != currentLines || _lineSpectrum == null || DateTime.Now - _lastRender > TimeSpan.FromMilliseconds(100))
            {
                _lines        = currentLines;
                _lineSpectrum = _audioCapture.GetLineSpectrum(_lines, ScalingStrategy.Decibel);
            }

            var newLineValues = _audioCapture.GetLineSpectrum(_lines, ScalingStrategy.Decibel)?.GetLineValues(currentHeight);

            if (newLineValues != null)
            {
                _lineValues = newLineValues;
                _lastRender = DateTime.Now;
            }
        }
Пример #6
0
        public void Update(LayerModel layerModel, ModuleDataModel dataModel, bool isPreview = false)
        {
            layerModel.ApplyProperties(true);
            var newProperties = (AudioPropertiesModel)layerModel.Properties;

            if (_properties == null)
            {
                _properties = newProperties;
            }

            SubscribeToAudioChange();

            if (_audioCapture == null || newProperties.Device != _properties.Device ||
                newProperties.DeviceType != _properties.DeviceType)
            {
                var device = GetMmDevice();
                if (device != null)
                {
                    _audioCapture = _audioCaptureManager.GetAudioCapture(device, newProperties.DeviceType);
                }
            }

            _properties = newProperties;

            if (_audioCapture == null)
            {
                return;
            }

            _audioCapture.Pulse();

            var direction = ((AudioPropertiesModel)layerModel.Properties).Direction;

            int    currentLines;
            double currentHeight;

            if (direction == Direction.BottomToTop || direction == Direction.TopToBottom)
            {
                currentLines  = (int)layerModel.Width;
                currentHeight = layerModel.Height;
            }
            else
            {
                currentLines  = (int)layerModel.Height;
                currentHeight = layerModel.Width;
            }

            if (_lines != currentLines || _lineSpectrum == null)
            {
                _lines        = currentLines;
                _lineSpectrum = _audioCapture.GetLineSpectrum(_lines, ScalingStrategy.Decibel);
                if (_lineSpectrum == null)
                {
                    return;
                }
            }

            var newLineValues = _lineSpectrum?.GetLineValues(currentHeight);

            if (newLineValues != null)
            {
                _lineValues = newLineValues;
            }
        }
Пример #7
0
        private void SetupHorizontal(AudioPropertiesModel settings)
        {
            _lines = (int) settings.Height;
            for (var i = 0; i < _lines; i++)
            {
                var layer = LayerModel.CreateLayer();
                layer.Properties.X = settings.X;
                layer.Properties.Y = settings.Y + i;
                layer.Properties.Width = 0;
                layer.Properties.Height = 1;
                layer.LayerAnimation = new NoneAnimation();
                layer.Properties.Brush = settings.Brush;
                layer.Properties.Contain = false;

                _audioLayers.Add(layer);
                layer.Update(null, false, true);
            }
        }
Пример #8
0
        /// <summary>
        ///     Updates the inner layers when the settings have changed
        /// </summary>
        /// <param name="layerModel"></param>
        private void UpdateLayers(LayerModel layerModel)
        {
            var settings = (AudioPropertiesModel) layerModel.Properties;
            if (JsonConvert.SerializeObject(settings).Equals(JsonConvert.SerializeObject(_previousSettings)))
                return;

            _previousSettings = GeneralHelpers.Clone((AudioPropertiesModel) layerModel.Properties);

            _audioLayers.Clear();
            if (settings.Direction == Direction.TopToBottom || settings.Direction == Direction.BottomToTop)
                SetupVertical(settings);
            else if (settings.Direction == Direction.LeftToRight || settings.Direction == Direction.RightToLeft)
                SetupHorizontal(settings);
        }
Пример #9
0
        private void ApplyHorizontal(AudioPropertiesModel settings)
        {
            var index = 0;
            foreach (var audioLayer in _audioLayers)
            {
                int width;
                if (SpectrumData.Count > index)
                    width = (int) Math.Round(SpectrumData[index]/2.55);
                else
                    width = 0;

                // Apply Sensitivity setting
                width = width*settings.Sensitivity;

                var newWidth = settings.Width/100.0*width;
                if (newWidth >= audioLayer.Properties.Width)
                    audioLayer.Properties.Width = newWidth;
                else
                    audioLayer.Properties.Width = audioLayer.Properties.Width - settings.FadeSpeed;
                if (audioLayer.Properties.Width < 0)
                    audioLayer.Properties.Width = 0;

                audioLayer.Properties.Brush = settings.Brush;
                audioLayer.Properties.Contain = false;

                // Reverse the direction if settings require it
                if (settings.Direction == Direction.RightToLeft)
                    audioLayer.Properties.X = settings.X + (settings.Width - audioLayer.Properties.Width);

                audioLayer.Update(null, false, true);
                index++;
            }
        }
Пример #10
0
        private void ApplyVertical(AudioPropertiesModel settings)
        {
            var index = 0;
            foreach (var audioLayer in _audioLayers)
            {
                int height;
                if (SpectrumData.Count > index)
                    height = (int) Math.Round(SpectrumData[index]/2.55);
                else
                    height = 0;

                // Apply Sensitivity setting
                height = height*settings.Sensitivity;

                var newHeight = settings.Height/100.0*height;
                if (newHeight >= audioLayer.Properties.Height)
                    audioLayer.Properties.Height = newHeight;
                else
                    audioLayer.Properties.Height = audioLayer.Properties.Height - settings.FadeSpeed;
                if (audioLayer.Properties.Height < 0)
                    audioLayer.Properties.Height = 0;

                // Reverse the direction if settings require it
                if (settings.Direction == Direction.BottomToTop)
                    audioLayer.Properties.Y = settings.Y + (settings.Height - audioLayer.Properties.Height);

                audioLayer.Update(null, false, true);
                index++;
            }
        }