mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Implemented audiovisualization directions
This commit is contained in:
parent
278afc9110
commit
821726d376
@ -2,7 +2,6 @@
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using Artemis.DeviceProviders.Logitech.Utilities;
|
||||
using Artemis.Utilities;
|
||||
using Artemis.Utilities.DataReaders;
|
||||
using Microsoft.Win32;
|
||||
|
||||
@ -12,7 +11,7 @@ namespace Artemis.DeviceProviders.Logitech
|
||||
{
|
||||
public override bool CanEnable()
|
||||
{
|
||||
//Check to see if VC++ 2012 x64 is installed.
|
||||
// Check to see if VC++ 2012 x64 is installed.
|
||||
if (Registry.LocalMachine.OpenSubKey(
|
||||
@"SOFTWARE\Classes\Installer\Dependencies\{ca67548a-5ebe-413a-b50c-4b9ceb6d66c6}") == null)
|
||||
{
|
||||
|
||||
@ -89,44 +89,21 @@ namespace Artemis.Profiles.Layers.Types.Audio
|
||||
|
||||
public void Update(LayerModel layerModel, IDataModel dataModel, bool isPreview = false)
|
||||
{
|
||||
_lines = (int) layerModel.Properties.Width;
|
||||
if ((_device == null) || isPreview)
|
||||
return;
|
||||
|
||||
lock (SpectrumData)
|
||||
{
|
||||
UpdateLayers(layerModel);
|
||||
|
||||
if (!SpectrumData.Any())
|
||||
return;
|
||||
|
||||
CompareSettings(layerModel);
|
||||
|
||||
var index = 0;
|
||||
var settings = (AudioPropertiesModel) layerModel.Properties;
|
||||
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;
|
||||
|
||||
audioLayer.Properties.Brush = layerModel.Properties.Brush;
|
||||
audioLayer.Properties.Contain = false;
|
||||
|
||||
audioLayer.Update(null, false, true);
|
||||
index++;
|
||||
}
|
||||
if (settings.Direction == Direction.TopToBottom || settings.Direction == Direction.BottomToTop)
|
||||
ApplyVertical(settings);
|
||||
else if (settings.Direction == Direction.LeftToRight || settings.Direction == Direction.RightToLeft)
|
||||
ApplyHorizontal(settings);
|
||||
}
|
||||
}
|
||||
|
||||
@ -150,7 +127,76 @@ namespace Artemis.Profiles.Layers.Types.Audio
|
||||
return new AudioPropertiesViewModel(proposedLayer, dataModel);
|
||||
}
|
||||
|
||||
private void CompareSettings(LayerModel layerModel)
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
/// <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)))
|
||||
@ -159,25 +205,56 @@ namespace Artemis.Profiles.Layers.Types.Audio
|
||||
_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);
|
||||
}
|
||||
|
||||
private void SetupVertical(AudioPropertiesModel settings)
|
||||
{
|
||||
_lines = (int) settings.Width;
|
||||
for (var i = 0; i < _lines; i++)
|
||||
{
|
||||
var layer = LayerModel.CreateLayer();
|
||||
layer.Properties.X = layerModel.Properties.X + i;
|
||||
layer.Properties.Y = layerModel.Properties.Y;
|
||||
layer.Properties.X = settings.X + i;
|
||||
layer.Properties.Y = settings.Y;
|
||||
layer.Properties.Width = 1;
|
||||
layer.Properties.Height = 0;
|
||||
layer.LayerAnimation = new NoneAnimation();
|
||||
|
||||
// TODO: Setup the brush according to settings
|
||||
layer.Properties.Brush = new SolidColorBrush(Colors.White);
|
||||
layer.Properties.Brush = settings.Brush;
|
||||
layer.Properties.Contain = false;
|
||||
|
||||
_audioLayers.Add(layer);
|
||||
layer.Update(null, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void FftCalculated(object sender, FftEventArgs e)
|
||||
{
|
||||
if (_lines == 0)
|
||||
return;
|
||||
|
||||
lock (SpectrumData)
|
||||
{
|
||||
int x;
|
||||
@ -205,6 +282,7 @@ namespace Artemis.Profiles.Layers.Types.Audio
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Check how often this is called
|
||||
private void OnDataAvailable(object sender, WaveInEventArgs e)
|
||||
{
|
||||
var buffer = e.Buffer;
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using Artemis.DAL;
|
||||
using Artemis.Utilities;
|
||||
@ -89,10 +90,18 @@ namespace Artemis.Settings
|
||||
{
|
||||
using (var mgr = new UpdateManager(""))
|
||||
{
|
||||
if (Autorun)
|
||||
mgr.CreateShortcutsForExecutable("Artemis.exe", ShortcutLocation.Startup, false);
|
||||
else
|
||||
mgr.RemoveShortcutsForExecutable("Artemis.exe", ShortcutLocation.Startup);
|
||||
try
|
||||
{
|
||||
if (Autorun)
|
||||
mgr.CreateShortcutsForExecutable("Artemis.exe", ShortcutLocation.Startup, false);
|
||||
else
|
||||
mgr.RemoveShortcutsForExecutable("Artemis.exe", ShortcutLocation.Startup);
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
// ignored, this'll only occur if Artemis isn't installed (ran from VS)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user