1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Tweening config backend

This commit is contained in:
SpoinkyNL 2016-12-01 00:12:41 +01:00
parent 31b51e561a
commit 041a2db6e2
5 changed files with 70 additions and 56 deletions

View File

@ -19,7 +19,8 @@ namespace Artemis.Profiles.Layers.Models
public LayerModel()
{
Children = new ChildItemCollection<LayerModel, LayerModel>(this);
TweenModel = new TweenModel(this, 200);
TweenModel = new TweenModel(this);
var model = Properties as KeyboardPropertiesModel;
if (model != null)
GifImage = new GifImage(model.GifFile);
@ -53,8 +54,9 @@ namespace Artemis.Profiles.Layers.Models
LayerType.Update(this, dataModel, preview);
LayerAnimation?.Update(this, updateAnimations);
TweenModel.Update();
if (!preview && updateAnimations)
TweenModel.Update();
LastRender = DateTime.Now;
}

View File

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media;
@ -26,6 +27,16 @@ namespace Artemis.Profiles.Layers.Models
Conditions = source.Conditions;
DynamicProperties = source.DynamicProperties;
Brush = source.Brush;
XEase = source.XEase;
YEase = source.YEase;
HeightEase = source.HeightEase;
WidthEase = source.WidthEase;
OpacityEase = source.OpacityEase;
XEaseTime = source.XEaseTime;
YEaseTime = source.YEaseTime;
HeightEaseTime = source.HeightEaseTime;
WidthEaseTime = source.WidthEaseTime;
OpacityEaseTime = source.OpacityEaseTime;
}
public double X { get; set; }
@ -35,6 +46,16 @@ namespace Artemis.Profiles.Layers.Models
public bool Contain { get; set; }
public double Opacity { get; set; }
public double AnimationSpeed { get; set; }
public double OpacityEaseTime { get; set; }
public double HeightEaseTime { get; set; }
public double WidthEaseTime { get; set; }
public double YEaseTime { get; set; }
public double XEaseTime { get; set; }
public string XEase { get; set; }
public string YEase { get; set; }
public string WidthEase { set; get; }
public string HeightEase { get; set; }
public string OpacityEase { get; set; }
public List<LayerConditionModel> Conditions { get; set; } = new List<LayerConditionModel>();
public List<DynamicPropertiesModel> DynamicProperties { get; set; } = new List<DynamicPropertiesModel>();

View File

@ -17,64 +17,36 @@ namespace Artemis.Profiles.Layers.Models
private float _y;
private Tweener<float> _yTweener;
public TweenModel(LayerModel layerModel, double defaultDuration)
public TweenModel(LayerModel layerModel)
{
_layerModel = layerModel;
XDuration = defaultDuration;
YDuration = defaultDuration;
WidthDuration = defaultDuration;
HeightDuration = defaultDuration;
OpacityDuration = defaultDuration;
XFunc = Ease.Quad.InOut;
YFunc = Ease.Quad.InOut;
WidthFunc = Ease.Quad.InOut;
HeightFunc = Ease.Quad.InOut;
OpacityFunc = Ease.Quad.InOut;
_xTweener = new Tweener<float>(0, (float) layerModel.X, XDuration, XFunc);
_yTweener = new Tweener<float>(0, (float) layerModel.Y, YDuration, YFunc);
_widthTweener = new Tweener<float>(0, (float) layerModel.Width, WidthDuration, WidthFunc);
_heightTweener = new Tweener<float>(0, (float) layerModel.Height, HeightDuration, HeightFunc);
_opacityTweener = new Tweener<float>(0, (float) layerModel.Opacity, OpacityDuration, OpacityFunc);
_xTweener = new Tweener<float>((float) layerModel.X, (float) layerModel.X, 0);
_yTweener = new Tweener<float>((float) layerModel.Y, (float) layerModel.Y, 0);
_widthTweener = new Tweener<float>((float) layerModel.Width, (float) layerModel.Width, 0);
_heightTweener = new Tweener<float>((float) layerModel.Height, (float) layerModel.Height, 0);
_opacityTweener = new Tweener<float>((float) layerModel.Opacity, (float) layerModel.Opacity, 0);
StoreCurrentValues();
}
public double XDuration { get; set; }
public double YDuration { get; set; }
public double WidthDuration { get; set; }
public double HeightDuration { get; set; }
public double OpacityDuration { get; set; }
public EaseFunc XFunc { get; set; }
public EaseFunc YFunc { get; set; }
public EaseFunc WidthFunc { get; set; }
public EaseFunc HeightFunc { get; set; }
public EaseFunc OpacityFunc { get; set; }
private void StoreCurrentValues()
{
_x = (float) _layerModel.X;
_y = (float) _layerModel.Y;
_width = (float) _layerModel.Width;
_height = (float) _layerModel.Height;
_opacity = (float) _layerModel.Opacity;
}
public void Update()
{
if (Math.Abs(_layerModel.X - _x) > 0.001)
_xTweener = new Tweener<float>(_x, (float) _layerModel.X, XDuration, XFunc);
_xTweener = new Tweener<float>(_x, (float) _layerModel.X, _layerModel.Properties.XEaseTime,
GetEaseFunction(_layerModel.Properties.XEase));
if (Math.Abs(_layerModel.Y - _y) > 0.001)
_yTweener = new Tweener<float>(_y, (float) _layerModel.Y, YDuration, YFunc);
_yTweener = new Tweener<float>(_y, (float) _layerModel.Y, _layerModel.Properties.YEaseTime,
GetEaseFunction(_layerModel.Properties.YEase));
if (Math.Abs(_layerModel.Width - _width) > 0.001)
_widthTweener = new Tweener<float>(_width, (float) _layerModel.Width, WidthDuration, WidthFunc);
_widthTweener = new Tweener<float>(_width, (float) _layerModel.Width,
_layerModel.Properties.WidthEaseTime, GetEaseFunction(_layerModel.Properties.WidthEase));
if (Math.Abs(_layerModel.Height - _height) > 0.001)
_heightTweener = new Tweener<float>(_height, (float) _layerModel.Height, HeightDuration, HeightFunc);
_heightTweener = new Tweener<float>(_height, (float) _layerModel.Height,
_layerModel.Properties.HeightEaseTime, GetEaseFunction(_layerModel.Properties.HeightEase));
if (Math.Abs(_layerModel.Opacity - _opacity) > 0.001)
_opacityTweener = new Tweener<float>(_opacity, (float) _layerModel.Opacity, OpacityDuration, OpacityFunc);
_opacityTweener = new Tweener<float>(_opacity, (float) _layerModel.Opacity,
_layerModel.Properties.OpacityEaseTime, GetEaseFunction(_layerModel.Properties.OpacityEase));
_xTweener.Update(40);
_yTweener.Update(40);
@ -90,5 +62,29 @@ namespace Artemis.Profiles.Layers.Models
_layerModel.Height = _heightTweener.Value;
_layerModel.Opacity = _opacityTweener.Value;
}
private void StoreCurrentValues()
{
_x = (float) _layerModel.X;
_y = (float) _layerModel.Y;
_width = (float) _layerModel.Width;
_height = (float) _layerModel.Height;
_opacity = (float) _layerModel.Opacity;
}
private static EaseFunc GetEaseFunction(string functionName)
{
switch (functionName)
{
case "In":
return Ease.Quint.In;
case "Out":
return Ease.Quint.Out;
case "InOut":
return Ease.Quint.InOut;
default:
return Ease.Linear;
}
}
}
}

View File

@ -26,9 +26,9 @@ namespace Artemis.Profiles.Layers.Types.Audio
private readonly MMDevice _device;
private readonly SampleAggregator _sampleAggregator = new SampleAggregator(1024);
private readonly WasapiLoopbackCapture _waveIn;
private DateTime _lastAudioUpdate;
private int _lines;
private AudioPropertiesModel _previousSettings;
private DateTime _lastAudioUpdate;
public AudioType()
{
@ -37,7 +37,7 @@ namespace Artemis.Profiles.Layers.Types.Audio
_sampleAggregator.FftCalculated += FftCalculated;
_sampleAggregator.PerformFFT = true;
// Start listening for sound data
_waveIn = new WasapiLoopbackCapture();
_waveIn.DataAvailable += OnDataAvailable;
@ -223,8 +223,6 @@ namespace Artemis.Profiles.Layers.Types.Audio
audioLayer.Properties.Width = settings.Width;
audioLayer.Properties.Height = settings.Height;
audioLayer.LayerAnimation?.Update(audioLayer, true);
audioLayer.TweenModel.Update();
// Restore the height and width
audioLayer.Properties.Height = oldHeight;
@ -329,9 +327,9 @@ namespace Artemis.Profiles.Layers.Types.Audio
// TODO: Check how often this is called
private void OnDataAvailable(object sender, WaveInEventArgs e)
{
if ((DateTime.Now - _lastAudioUpdate) < TimeSpan.FromMilliseconds(200))
if (DateTime.Now - _lastAudioUpdate < TimeSpan.FromMilliseconds(40))
return;
_lastAudioUpdate = DateTime.Now;
var buffer = e.Buffer;

View File

@ -1,12 +1,9 @@
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using PixelFormat = System.Drawing.Imaging.PixelFormat;
using Point = System.Drawing.Point;
namespace Artemis.Utilities
{