mirror of
https://github.com/DarthAffe/KeyboardAudioVisualizer.git
synced 2025-12-12 15:18:30 +00:00
Readded requalizer, started UI for the equalizer
This commit is contained in:
parent
cfff1671c4
commit
478298fac4
2
KeyboardAudioVisualizer.sln.DotSettings
Normal file
2
KeyboardAudioVisualizer.sln.DotSettings
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
|
<s:Boolean x:Key="/Default/CodeInspection/CodeAnnotations/NamespacesWithAnnotations/=KeyboardAudioVisualizer_002EAnnotations/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||||
@ -59,7 +59,7 @@ namespace KeyboardAudioVisualizer.AudioProcessing
|
|||||||
_spectrumProvider.Initialize();
|
_spectrumProvider.Initialize();
|
||||||
|
|
||||||
//TODO DarthAffe 03.08.2017: Initialize correctly; Settings
|
//TODO DarthAffe 03.08.2017: Initialize correctly; Settings
|
||||||
MultiBandEqualizer equalizer = new MultiBandEqualizer { [0] = -3, [1] = -1, [2] = 1, [3] = 2, [4] = 3 };
|
MultiBandEqualizer equalizer = new MultiBandEqualizer();
|
||||||
PrimaryVisualizationProvider = new FrequencyBarsVisualizationProvider(new FrequencyBarsVisualizationProviderConfiguration(), _spectrumProvider) { Equalizer = equalizer };
|
PrimaryVisualizationProvider = new FrequencyBarsVisualizationProvider(new FrequencyBarsVisualizationProviderConfiguration(), _spectrumProvider) { Equalizer = equalizer };
|
||||||
//PrimaryVisualizationProvider = new BeatVisualizationProvider(new BeatVisualizationProviderConfiguration(), _spectrumProvider);
|
//PrimaryVisualizationProvider = new BeatVisualizationProvider(new BeatVisualizationProviderConfiguration(), _spectrumProvider);
|
||||||
PrimaryVisualizationProvider.Initialize();
|
PrimaryVisualizationProvider.Initialize();
|
||||||
|
|||||||
@ -0,0 +1,42 @@
|
|||||||
|
using RGB.NET.Core;
|
||||||
|
|
||||||
|
namespace KeyboardAudioVisualizer.AudioProcessing.Equalizer
|
||||||
|
{
|
||||||
|
public class EqualizerBand : AbstractBindable
|
||||||
|
{
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
private float _offset;
|
||||||
|
public float Offset
|
||||||
|
{
|
||||||
|
get => _offset;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (!IsFixedOffset)
|
||||||
|
SetProperty(ref _offset, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private float _value;
|
||||||
|
public float Value
|
||||||
|
{
|
||||||
|
get => _value;
|
||||||
|
set => SetProperty(ref _value, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsFixedOffset { get; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
public EqualizerBand(float offset, float value = 0, bool fixedOffset = false)
|
||||||
|
{
|
||||||
|
this.Offset = offset;
|
||||||
|
this.Value = value;
|
||||||
|
this.IsFixedOffset = fixedOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,8 +1,13 @@
|
|||||||
namespace KeyboardAudioVisualizer.AudioProcessing.Equalizer
|
using System.Collections.ObjectModel;
|
||||||
|
|
||||||
|
namespace KeyboardAudioVisualizer.AudioProcessing.Equalizer
|
||||||
{
|
{
|
||||||
public interface IEqualizer
|
public interface IEqualizer
|
||||||
{
|
{
|
||||||
bool IsEnabled { get; set; }
|
bool IsEnabled { get; set; }
|
||||||
float[] CalculateValues(int values);
|
|
||||||
|
ObservableCollection<EqualizerBand> Bands { get; }
|
||||||
|
|
||||||
|
float[] CalculateValues(int count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System.Collections.ObjectModel;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace KeyboardAudioVisualizer.AudioProcessing.Equalizer
|
namespace KeyboardAudioVisualizer.AudioProcessing.Equalizer
|
||||||
@ -8,46 +7,35 @@ namespace KeyboardAudioVisualizer.AudioProcessing.Equalizer
|
|||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
|
public ObservableCollection<EqualizerBand> Bands { get; } = new ObservableCollection<EqualizerBand>();
|
||||||
|
|
||||||
private float[] _values;
|
private float[] _values;
|
||||||
|
|
||||||
private readonly List<Band> _bands = new List<Band>();
|
|
||||||
|
|
||||||
public int Bands => _bands.Count;
|
|
||||||
public float this[int band]
|
|
||||||
{
|
|
||||||
get => _bands[band].Value;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_bands[band].Value = value;
|
|
||||||
RecalculateValues();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsEnabled { get; set; } = true;
|
public bool IsEnabled { get; set; } = true;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
public MultiBandEqualizer(int bands = 5)
|
public MultiBandEqualizer()
|
||||||
{
|
{
|
||||||
if (bands < 2) throw new ArgumentOutOfRangeException(nameof(bands), "There must be at least two bands for an working equalizer!");
|
AddBand(0, 0, true);
|
||||||
|
AddBand(1, 0, true);
|
||||||
float reference = (float)Math.Log(bands);
|
|
||||||
|
|
||||||
for (int i = bands - 1; i >= 0; i--)
|
|
||||||
{
|
|
||||||
Band band = new Band((reference - (float)Math.Log(i + 1)) / reference);
|
|
||||||
_bands.Add(band);
|
|
||||||
}
|
|
||||||
|
|
||||||
CalculateValues(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
|
||||||
|
public void AddBand(float frequency, float modification, bool isFixedFrequency = false)
|
||||||
|
{
|
||||||
|
EqualizerBand band = new EqualizerBand(frequency, modification, isFixedFrequency);
|
||||||
|
band.PropertyChanged += (sender, args) => InvalidateCache();
|
||||||
|
Bands.Add(band);
|
||||||
|
|
||||||
|
InvalidateCache();
|
||||||
|
}
|
||||||
|
|
||||||
public float[] CalculateValues(int values)
|
public float[] CalculateValues(int values)
|
||||||
{
|
{
|
||||||
if ((_values == null) || (_values.Length != values))
|
if ((_values == null) || (_values.Length != values))
|
||||||
@ -55,7 +43,6 @@ namespace KeyboardAudioVisualizer.AudioProcessing.Equalizer
|
|||||||
_values = new float[values];
|
_values = new float[values];
|
||||||
RecalculateValues();
|
RecalculateValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
return _values;
|
return _values;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,40 +52,15 @@ namespace KeyboardAudioVisualizer.AudioProcessing.Equalizer
|
|||||||
for (int i = 0; i < _values.Length; i++)
|
for (int i = 0; i < _values.Length; i++)
|
||||||
{
|
{
|
||||||
float offset = (i / width);
|
float offset = (i / width);
|
||||||
|
EqualizerBand bandBefore = Bands.Last(n => n.Offset <= offset);
|
||||||
Band bandBefore = _bands.Last(n => n.Offset <= offset);
|
EqualizerBand bandAfter = Bands.First(n => n.Offset >= offset);
|
||||||
Band bandAfter = _bands.First(n => n.Offset >= offset);
|
|
||||||
|
|
||||||
offset = bandAfter.Offset <= 0 ? 0 : (offset - bandBefore.Offset) / (bandAfter.Offset - bandBefore.Offset);
|
offset = bandAfter.Offset <= 0 ? 0 : (offset - bandBefore.Offset) / (bandAfter.Offset - bandBefore.Offset);
|
||||||
|
|
||||||
float value = (float)((3.0 * (offset * offset)) - (2.0 * (offset * offset * offset)));
|
float value = (float)((3.0 * (offset * offset)) - (2.0 * (offset * offset * offset)));
|
||||||
_values[i] = bandBefore.Value + (value * (bandAfter.Value - bandBefore.Value));
|
_values[i] = bandBefore.Value + (value * (bandAfter.Value - bandBefore.Value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
private void InvalidateCache() => _values = null;
|
||||||
|
|
||||||
#region Data
|
|
||||||
|
|
||||||
private class Band
|
|
||||||
{
|
|
||||||
#region Properties & Fields
|
|
||||||
|
|
||||||
public float Offset { get; set; }
|
|
||||||
public float Value { get; set; }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
|
|
||||||
public Band(float offset, float value = 0)
|
|
||||||
{
|
|
||||||
this.Offset = offset;
|
|
||||||
this.Value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,6 +11,7 @@ namespace KeyboardAudioVisualizer.AudioProcessing.Spectrum
|
|||||||
|
|
||||||
public float LowerFrequency { get; }
|
public float LowerFrequency { get; }
|
||||||
public float UpperFrequency { get; }
|
public float UpperFrequency { get; }
|
||||||
|
public float CenterFrequency { get; }
|
||||||
|
|
||||||
private float? _average = null;
|
private float? _average = null;
|
||||||
public float Average => _average ?? (_average = _data.Average()).Value;
|
public float Average => _average ?? (_average = _data.Average()).Value;
|
||||||
@ -35,6 +36,7 @@ namespace KeyboardAudioVisualizer.AudioProcessing.Spectrum
|
|||||||
{
|
{
|
||||||
this.LowerFrequency = lowerFrequency;
|
this.LowerFrequency = lowerFrequency;
|
||||||
this.UpperFrequency = upperFrequency;
|
this.UpperFrequency = upperFrequency;
|
||||||
|
this.CenterFrequency = (LowerFrequency + UpperFrequency) / 2f; //TODO DarthAffe 12.08.2017: Is this valid for logarithmic scaling?
|
||||||
this._data = data;
|
this._data = data;
|
||||||
|
|
||||||
_resolution = (UpperFrequency - LowerFrequency) / data.Length;
|
_resolution = (UpperFrequency - LowerFrequency) / data.Length;
|
||||||
|
|||||||
@ -127,22 +127,16 @@ namespace KeyboardAudioVisualizer.AudioProcessing.VisualizationProvider
|
|||||||
ISpectrum spectrum = GetSpectrum();
|
ISpectrum spectrum = GetSpectrum();
|
||||||
if (spectrum == null) return;
|
if (spectrum == null) return;
|
||||||
|
|
||||||
|
float[] equalizerValues = Equalizer?.IsEnabled == true ? Equalizer.CalculateValues(spectrum.BandCount) : null;
|
||||||
|
|
||||||
for (int i = 0; i < spectrum.BandCount; i++)
|
for (int i = 0; i < spectrum.BandCount; i++)
|
||||||
{
|
{
|
||||||
double binPower = Math.Max(0, 20 * Math.Log10(GetBandValue(spectrum[i])));
|
double binPower = Math.Max(0, 20 * Math.Log10(GetBandValue(spectrum[i])));
|
||||||
|
|
||||||
//TODO DarthAffe 10.08.2017: Rewrite Equalizer
|
if (equalizerValues != null)
|
||||||
//if (Equalizer?.IsEnabled == true)
|
binPower += equalizerValues[i];
|
||||||
//{
|
|
||||||
// float value = Equalizer.CalculateValues(VisualizationData.Length)[i];
|
|
||||||
// if (Math.Abs(value) > 0.000001)
|
|
||||||
// {
|
|
||||||
// bool lower = value < 0;
|
|
||||||
// value = 1 + (value * value);
|
|
||||||
// binPower *= lower ? 1f / value : value;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
binPower = Math.Max(0, binPower);
|
||||||
binPower /= _configuration.ReferenceLevel;
|
binPower /= _configuration.ReferenceLevel;
|
||||||
if (_configuration.EmphasisePeaks > 0.001)
|
if (_configuration.EmphasisePeaks > 0.001)
|
||||||
binPower = Math.Pow(binPower, 1 + _configuration.EmphasisePeaks) * _emphasiseFactor;
|
binPower = Math.Pow(binPower, 1 + _configuration.EmphasisePeaks) * _emphasiseFactor;
|
||||||
|
|||||||
@ -1,20 +1,15 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
using RGB.NET.Core;
|
||||||
|
|
||||||
namespace KeyboardAudioVisualizer.Configuration
|
namespace KeyboardAudioVisualizer.Configuration
|
||||||
{
|
{
|
||||||
public class AbstractConfiguration : IConfiguration, INotifyPropertyChanged
|
public class AbstractConfiguration : AbstractBindable, IConfiguration, INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
#region Events
|
|
||||||
|
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
|
||||||
protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
|
protected override bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
|
||||||
{
|
{
|
||||||
if ((typeof(T) == typeof(double)) || (typeof(T) == typeof(float)))
|
if ((typeof(T) == typeof(double)) || (typeof(T) == typeof(float)))
|
||||||
{
|
{
|
||||||
@ -31,8 +26,6 @@ namespace KeyboardAudioVisualizer.Configuration
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Data;
|
||||||
|
|
||||||
|
namespace KeyboardAudioVisualizer.Converter
|
||||||
|
{
|
||||||
|
[ValueConversion(typeof(bool), typeof(Visibility))]
|
||||||
|
public class BoolToVisibilityConverter : IValueConverter
|
||||||
|
{
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => (value as bool?) == true ? Visibility.Visible : Visibility.Collapsed;
|
||||||
|
|
||||||
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => value as Visibility? == Visibility.Visible;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
39
KeyboardAudioVisualizer/Converter/OffsetToPosXConverter.cs
Normal file
39
KeyboardAudioVisualizer/Converter/OffsetToPosXConverter.cs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Data;
|
||||||
|
|
||||||
|
namespace KeyboardAudioVisualizer.Converter
|
||||||
|
{
|
||||||
|
public class ValueToPosYConverter : IMultiValueConverter
|
||||||
|
{
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
if ((values.Length != 3) || (values[0] == null) || (values[0] == DependencyProperty.UnsetValue)
|
||||||
|
|| (values[1] == null) || (values[1] == DependencyProperty.UnsetValue)
|
||||||
|
|| (values[2] == null) || (values[2] == DependencyProperty.UnsetValue))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
float val = (float)values[0];
|
||||||
|
double height = (double)values[1];
|
||||||
|
double reference = (double)values[2];
|
||||||
|
|
||||||
|
double halfHeight = height / 2.0;
|
||||||
|
|
||||||
|
double offset = val / reference;
|
||||||
|
if (offset < 0)
|
||||||
|
return halfHeight + (-offset * halfHeight);
|
||||||
|
|
||||||
|
if (offset > 0)
|
||||||
|
return halfHeight - (offset * halfHeight);
|
||||||
|
|
||||||
|
return halfHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) => throw new NotImplementedException();
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
28
KeyboardAudioVisualizer/Converter/ValueToPosYConverter.cs
Normal file
28
KeyboardAudioVisualizer/Converter/ValueToPosYConverter.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Data;
|
||||||
|
|
||||||
|
namespace KeyboardAudioVisualizer.Converter
|
||||||
|
{
|
||||||
|
public class OffsetToPosXConverter : IMultiValueConverter
|
||||||
|
{
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
if ((values.Length != 2) || (values[0] == null) || (values[0] == DependencyProperty.UnsetValue)
|
||||||
|
|| (values[1] == null) || (values[1] == DependencyProperty.UnsetValue))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
float offset = (float)values[0];
|
||||||
|
double width = (double)values[1];
|
||||||
|
|
||||||
|
return offset * width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) => throw new NotImplementedException();
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -106,6 +106,7 @@
|
|||||||
<Compile Include="AudioCapture\CSCoreAudioInput.cs" />
|
<Compile Include="AudioCapture\CSCoreAudioInput.cs" />
|
||||||
<Compile Include="AudioCapture\IAudioInput.cs" />
|
<Compile Include="AudioCapture\IAudioInput.cs" />
|
||||||
<Compile Include="AudioProcessing\AudioProcessor.cs" />
|
<Compile Include="AudioProcessing\AudioProcessor.cs" />
|
||||||
|
<Compile Include="AudioProcessing\Equalizer\EqualizerBand.cs" />
|
||||||
<Compile Include="AudioProcessing\Equalizer\IEqualizer.cs" />
|
<Compile Include="AudioProcessing\Equalizer\IEqualizer.cs" />
|
||||||
<Compile Include="AudioProcessing\Equalizer\MultiBandEqualizer.cs" />
|
<Compile Include="AudioProcessing\Equalizer\MultiBandEqualizer.cs" />
|
||||||
<Compile Include="AudioProcessing\IAudioProcessor.cs" />
|
<Compile Include="AudioProcessing\IAudioProcessor.cs" />
|
||||||
@ -129,7 +130,10 @@
|
|||||||
<Compile Include="Configuration\IConfiguration.cs" />
|
<Compile Include="Configuration\IConfiguration.cs" />
|
||||||
<Compile Include="Controls\Formular.cs" />
|
<Compile Include="Controls\Formular.cs" />
|
||||||
<Compile Include="Controls\ImageButton.cs" />
|
<Compile Include="Controls\ImageButton.cs" />
|
||||||
|
<Compile Include="Converter\BoolToVisibilityConverter.cs" />
|
||||||
<Compile Include="Converter\EqualsToBoolConverter.cs" />
|
<Compile Include="Converter\EqualsToBoolConverter.cs" />
|
||||||
|
<Compile Include="Converter\ValueToPosYConverter.cs" />
|
||||||
|
<Compile Include="Converter\OffsetToPosXConverter.cs" />
|
||||||
<Compile Include="Helper\ActionCommand.cs" />
|
<Compile Include="Helper\ActionCommand.cs" />
|
||||||
<Compile Include="Helper\ExceptionExtension.cs" />
|
<Compile Include="Helper\ExceptionExtension.cs" />
|
||||||
<Compile Include="Helper\FrequencyHelper.cs" />
|
<Compile Include="Helper\FrequencyHelper.cs" />
|
||||||
@ -142,6 +146,7 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="UI\ConfigurationViewModel.cs" />
|
<Compile Include="UI\ConfigurationViewModel.cs" />
|
||||||
<Compile Include="UI\Visualization\BeatVisualizer.cs" />
|
<Compile Include="UI\Visualization\BeatVisualizer.cs" />
|
||||||
|
<Compile Include="UI\Visualization\EqualizerVisualizer.cs" />
|
||||||
<Compile Include="UI\Visualization\FrequencyBarsVisualizer.cs" />
|
<Compile Include="UI\Visualization\FrequencyBarsVisualizer.cs" />
|
||||||
<Compile Include="UI\Visualization\LevelVisualizer.cs" />
|
<Compile Include="UI\Visualization\LevelVisualizer.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@ -15,6 +15,7 @@
|
|||||||
</styles:CachedResourceDictionary.MergedDictionaries>
|
</styles:CachedResourceDictionary.MergedDictionaries>
|
||||||
|
|
||||||
<converter:EqualsToBoolConverter x:Key="EqualsToBoolConverter" />
|
<converter:EqualsToBoolConverter x:Key="EqualsToBoolConverter" />
|
||||||
|
<converter:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
|
||||||
|
|
||||||
<Style TargetType="{x:Type controls:BlurredDecorationWindow}" BasedOn="{StaticResource StyleBlurredDecorationWindow}" />
|
<Style TargetType="{x:Type controls:BlurredDecorationWindow}" BasedOn="{StaticResource StyleBlurredDecorationWindow}" />
|
||||||
<Style TargetType="{x:Type ui:ConfigurationWindow}" BasedOn="{StaticResource StyleBlurredDecorationWindow}" />
|
<Style TargetType="{x:Type ui:ConfigurationWindow}" BasedOn="{StaticResource StyleBlurredDecorationWindow}" />
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
<!-- Box -->
|
<!-- Box -->
|
||||||
<SolidColorBrush x:Key="BrushBoxBorder" presentationOptions:Freeze="True" Color="{StaticResource ColorJetBlackTransparent}" />
|
<SolidColorBrush x:Key="BrushBoxBorder" presentationOptions:Freeze="True" Color="{StaticResource ColorJetBlackTransparent}" />
|
||||||
<SolidColorBrush x:Key="BrushBoxBackground" presentationOptions:Freeze="True" Color="{StaticResource ColorJetBlackSuperTransparent}" />
|
<SolidColorBrush x:Key="BrushBoxBackground" presentationOptions:Freeze="True" Color="{StaticResource ColorJetBlackSuperTransparent}" />
|
||||||
|
|
||||||
<!-- ToolTip -->
|
<!-- ToolTip -->
|
||||||
<SolidColorBrush x:Key="BrushTooltipForeground" presentationOptions:Freeze="True" Color="{StaticResource ColorGainsboro}" />
|
<SolidColorBrush x:Key="BrushTooltipForeground" presentationOptions:Freeze="True" Color="{StaticResource ColorGainsboro}" />
|
||||||
<SolidColorBrush x:Key="BrushTooltipBorder" presentationOptions:Freeze="True" Color="{StaticResource ColorJetBlack}" />
|
<SolidColorBrush x:Key="BrushTooltipBorder" presentationOptions:Freeze="True" Color="{StaticResource ColorJetBlack}" />
|
||||||
@ -34,11 +34,16 @@
|
|||||||
<SolidColorBrush x:Key="BrushComboBoxBackgroundPopup" presentationOptions:Freeze="True" Color="{StaticResource ColorBuckinghamGray}" />
|
<SolidColorBrush x:Key="BrushComboBoxBackgroundPopup" presentationOptions:Freeze="True" Color="{StaticResource ColorBuckinghamGray}" />
|
||||||
<SolidColorBrush x:Key="BrushComboBoxBorder" presentationOptions:Freeze="True" Color="{StaticResource ColorJetBlackTransparent}" />
|
<SolidColorBrush x:Key="BrushComboBoxBorder" presentationOptions:Freeze="True" Color="{StaticResource ColorJetBlackTransparent}" />
|
||||||
<SolidColorBrush x:Key="BrushComboBoxHover" presentationOptions:Freeze="True" Color="{StaticResource ColorJetBlack}" />
|
<SolidColorBrush x:Key="BrushComboBoxHover" presentationOptions:Freeze="True" Color="{StaticResource ColorJetBlack}" />
|
||||||
|
|
||||||
<!-- Navigation -->
|
<!-- Navigation -->
|
||||||
<SolidColorBrush x:Key="BrushNavigationItem" presentationOptions:Freeze="True" Color="{StaticResource ColorGainsboro}" />
|
<SolidColorBrush x:Key="BrushNavigationItem" presentationOptions:Freeze="True" Color="{StaticResource ColorGainsboro}" />
|
||||||
<SolidColorBrush x:Key="BrushNavigationItemBlur" presentationOptions:Freeze="True" Color="{StaticResource ColorBananaYellow}" />
|
<SolidColorBrush x:Key="BrushNavigationItemBlur" presentationOptions:Freeze="True" Color="{StaticResource ColorBananaYellow}" />
|
||||||
|
|
||||||
|
<!-- Equalizer -->
|
||||||
|
<SolidColorBrush x:Key="BrushEqualizerForeground" presentationOptions:Freeze="True" Color="{StaticResource ColorGainsboro}" />
|
||||||
|
<SolidColorBrush x:Key="BrushEqualizerBorder" presentationOptions:Freeze="True" Color="{StaticResource ColorBuckinghamGrayTransparent}" />
|
||||||
|
<SolidColorBrush x:Key="BrushEqualizerBackground" presentationOptions:Freeze="True" Color="{StaticResource ColorJetBlackTransparent}" />
|
||||||
|
|
||||||
|
|
||||||
<!-- ### Border'n'stuff ### -->
|
<!-- ### Border'n'stuff ### -->
|
||||||
<sys:Double x:Key="DoubleNavigationBlurRadius">40</sys:Double>
|
<sys:Double x:Key="DoubleNavigationBlurRadius">40</sys:Double>
|
||||||
|
|||||||
@ -41,7 +41,7 @@
|
|||||||
|
|
||||||
<controls:Formular Grid.Column="2">
|
<controls:Formular Grid.Column="2">
|
||||||
<Label controls:Formular.IsLabel="True" Content="Scale:" />
|
<Label controls:Formular.IsLabel="True" Content="Scale:" />
|
||||||
<Slider controls:Formular.Fill="True" Minimum="1" Maximum="10" IsSnapToTickEnabled="True" TickFrequency="0.5" TickPlacement="BottomRight"
|
<Slider controls:Formular.Fill="True" Minimum="1" Maximum="20" IsSnapToTickEnabled="True" TickFrequency="0.5" TickPlacement="BottomRight"
|
||||||
Value="{Binding Scale}" />
|
Value="{Binding Scale}" />
|
||||||
</controls:Formular>
|
</controls:Formular>
|
||||||
|
|
||||||
|
|||||||
@ -2,10 +2,11 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using KeyboardAudioVisualizer.Helper;
|
using KeyboardAudioVisualizer.Helper;
|
||||||
|
using RGB.NET.Core;
|
||||||
|
|
||||||
namespace KeyboardAudioVisualizer.UI
|
namespace KeyboardAudioVisualizer.UI
|
||||||
{
|
{
|
||||||
public class ConfigurationViewModel
|
public class ConfigurationViewModel : AbstractBindable
|
||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
|
|||||||
101
KeyboardAudioVisualizer/UI/Visualization/EqualizerVisualizer.cs
Normal file
101
KeyboardAudioVisualizer/UI/Visualization/EqualizerVisualizer.cs
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using KeyboardAudioVisualizer.AudioProcessing.Equalizer;
|
||||||
|
|
||||||
|
namespace KeyboardAudioVisualizer.UI.Visualization
|
||||||
|
{
|
||||||
|
//[TemplatePart(Name = "PART_Grips", Type = typeof(Canvas))]
|
||||||
|
public class EqualizerVisualizer : Control
|
||||||
|
{
|
||||||
|
#region DependencyProperties
|
||||||
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
|
public static readonly DependencyProperty EqualizerProperty = DependencyProperty.Register(
|
||||||
|
"Equalizer", typeof(IEqualizer), typeof(EqualizerVisualizer), new PropertyMetadata(default(IEqualizer)));
|
||||||
|
|
||||||
|
public IEqualizer Equalizer
|
||||||
|
{
|
||||||
|
get => (IEqualizer)GetValue(EqualizerProperty);
|
||||||
|
set => SetValue(EqualizerProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly DependencyProperty ReferenceLevelProperty = DependencyProperty.Register(
|
||||||
|
"ReferenceLevel", typeof(double), typeof(EqualizerVisualizer), new PropertyMetadata(default(double)));
|
||||||
|
|
||||||
|
public double ReferenceLevel
|
||||||
|
{
|
||||||
|
get => (double)GetValue(ReferenceLevelProperty);
|
||||||
|
set => SetValue(ReferenceLevelProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReSharper restore InconsistentNaming
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
//private Canvas _canvas;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
//public EqualizerVisualizer()
|
||||||
|
//{
|
||||||
|
// SizeChanged += (sender, args) => Update();
|
||||||
|
// Update();
|
||||||
|
//}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
//public override void OnApplyTemplate()
|
||||||
|
//{
|
||||||
|
// base.OnApplyTemplate();
|
||||||
|
|
||||||
|
// _canvas = GetTemplateChild("PART_Grips") as Canvas;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//private static void EqualizerChanged(DependencyObject dependencyObject,
|
||||||
|
// DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
|
||||||
|
//{
|
||||||
|
// EqualizerVisualizer visualizer = dependencyObject as EqualizerVisualizer;
|
||||||
|
// if (visualizer == null) return;
|
||||||
|
|
||||||
|
// void BandsChanged(object sender, NotifyCollectionChangedEventArgs args) => visualizer.Update();
|
||||||
|
|
||||||
|
// if (dependencyPropertyChangedEventArgs.OldValue is IEqualizer oldEqualizer)
|
||||||
|
// oldEqualizer.Bands.CollectionChanged -= BandsChanged;
|
||||||
|
|
||||||
|
// if (dependencyPropertyChangedEventArgs.NewValue is IEqualizer newEqualizer)
|
||||||
|
// newEqualizer.Bands.CollectionChanged += BandsChanged;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//private void Update()
|
||||||
|
//{
|
||||||
|
// if (_canvas == null) return;
|
||||||
|
|
||||||
|
// void OnBandChanged(object sender, PropertyChangedEventArgs args) => Update();
|
||||||
|
|
||||||
|
// foreach (object child in _canvas.Children)
|
||||||
|
// {
|
||||||
|
// EqualizerBand band = (child as ContentControl)?.Content as EqualizerBand;
|
||||||
|
// if (band == null) continue;
|
||||||
|
// band.PropertyChanged -= OnBandChanged;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// _canvas.Children.Clear();
|
||||||
|
|
||||||
|
// foreach (EqualizerBand band in Equalizer.Bands)
|
||||||
|
// {
|
||||||
|
// ContentControl ctrl = new ContentControl();
|
||||||
|
|
||||||
|
// ctrl.Content = band;
|
||||||
|
|
||||||
|
// _canvas.Children.Add(ctrl);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,19 +2,24 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:styles="clr-namespace:KeyboardAudioVisualizer.Styles"
|
xmlns:styles="clr-namespace:KeyboardAudioVisualizer.Styles"
|
||||||
xmlns:visualizationProvider="clr-namespace:KeyboardAudioVisualizer.AudioProcessing.VisualizationProvider"
|
xmlns:visualizationProvider="clr-namespace:KeyboardAudioVisualizer.AudioProcessing.VisualizationProvider"
|
||||||
xmlns:visualization="clr-namespace:KeyboardAudioVisualizer.UI.Visualization">
|
xmlns:visualization="clr-namespace:KeyboardAudioVisualizer.UI.Visualization"
|
||||||
|
xmlns:equalizer="clr-namespace:KeyboardAudioVisualizer.AudioProcessing.Equalizer"
|
||||||
|
xmlns:converter="clr-namespace:KeyboardAudioVisualizer.Converter">
|
||||||
|
|
||||||
<styles:CachedResourceDictionary.MergedDictionaries>
|
<styles:CachedResourceDictionary.MergedDictionaries>
|
||||||
<styles:CachedResourceDictionary Source="/KeyboardAudioVisualizer;component/Styles/FrameworkElement.xaml" />
|
<styles:CachedResourceDictionary Source="/KeyboardAudioVisualizer;component/Styles/FrameworkElement.xaml" />
|
||||||
<styles:CachedResourceDictionary Source="/KeyboardAudioVisualizer;component/Styles/Theme.xaml" />
|
<styles:CachedResourceDictionary Source="/KeyboardAudioVisualizer;component/Styles/Theme.xaml" />
|
||||||
</styles:CachedResourceDictionary.MergedDictionaries>
|
</styles:CachedResourceDictionary.MergedDictionaries>
|
||||||
|
|
||||||
|
<converter:OffsetToPosXConverter x:Key="OffsetToPosXConverter" />
|
||||||
|
<converter:ValueToPosYConverter x:Key="ValueToPosYConverter" />
|
||||||
|
|
||||||
<Style x:Key="StyleFrequencyBarsVisualizer"
|
<Style x:Key="StyleFrequencyBarsVisualizer"
|
||||||
BasedOn="{StaticResource StyleFrameworkElement}"
|
BasedOn="{StaticResource StyleFrameworkElement}"
|
||||||
TargetType="{x:Type visualization:FrequencyBarsVisualizer}">
|
TargetType="{x:Type visualization:FrequencyBarsVisualizer}">
|
||||||
<Setter Property="SnapsToDevicePixels" Value="False" />
|
<Setter Property="SnapsToDevicePixels" Value="False" />
|
||||||
<Setter Property="UseLayoutRounding" Value="False" />
|
<Setter Property="UseLayoutRounding" Value="False" />
|
||||||
|
|
||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
<ControlTemplate TargetType="{x:Type visualization:FrequencyBarsVisualizer}">
|
<ControlTemplate TargetType="{x:Type visualization:FrequencyBarsVisualizer}">
|
||||||
@ -24,8 +29,87 @@
|
|||||||
</Setter>
|
</Setter>
|
||||||
</Style>
|
</Style>
|
||||||
|
|
||||||
|
<Style x:Key="StyleEqualizerVisualizer"
|
||||||
|
BasedOn="{StaticResource StyleFrameworkElement}"
|
||||||
|
TargetType="{x:Type visualization:EqualizerVisualizer}">
|
||||||
|
<Setter Property="SnapsToDevicePixels" Value="False" />
|
||||||
|
<Setter Property="UseLayoutRounding" Value="False" />
|
||||||
|
|
||||||
|
<Setter Property="Template">
|
||||||
|
<Setter.Value>
|
||||||
|
<ControlTemplate TargetType="{x:Type visualization:EqualizerVisualizer}">
|
||||||
|
<Grid Background="Transparent">
|
||||||
|
<ItemsControl x:Name="PART_Grips" Opacity="0" Margin="-12,-12,12,12"
|
||||||
|
Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Equalizer.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}"
|
||||||
|
ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Equalizer.Bands}">
|
||||||
|
<ItemsControl.ItemsPanel>
|
||||||
|
<ItemsPanelTemplate>
|
||||||
|
<Canvas />
|
||||||
|
</ItemsPanelTemplate>
|
||||||
|
</ItemsControl.ItemsPanel>
|
||||||
|
|
||||||
|
<ItemsControl.ItemTemplate>
|
||||||
|
<DataTemplate DataType="equalizer:EqualizerBand">
|
||||||
|
<Border Width="24" Height="24" CornerRadius="12"
|
||||||
|
BorderThickness="3" BorderBrush="{StaticResource BrushEqualizerBorder}"
|
||||||
|
Background="{StaticResource BrushEqualizerBackground}" />
|
||||||
|
</DataTemplate>
|
||||||
|
</ItemsControl.ItemTemplate>
|
||||||
|
|
||||||
|
<ItemsControl.ItemContainerStyle>
|
||||||
|
<Style TargetType="ContentPresenter">
|
||||||
|
<Setter Property="Canvas.Left">
|
||||||
|
<Setter.Value>
|
||||||
|
<MultiBinding Converter="{StaticResource OffsetToPosXConverter}">
|
||||||
|
<Binding Path="Offset" />
|
||||||
|
<Binding Path="ActualWidth" ElementName="PART_Grips" />
|
||||||
|
</MultiBinding>
|
||||||
|
</Setter.Value>
|
||||||
|
</Setter>
|
||||||
|
<Setter Property="Canvas.Top">
|
||||||
|
<Setter.Value>
|
||||||
|
<MultiBinding Converter="{StaticResource ValueToPosYConverter}">
|
||||||
|
<Binding Path="Value" />
|
||||||
|
<Binding Path="ActualHeight" ElementName="PART_Grips" />
|
||||||
|
<Binding Path="ReferenceLevel" RelativeSource="{RelativeSource AncestorType={x:Type visualization:EqualizerVisualizer}}" />
|
||||||
|
</MultiBinding>
|
||||||
|
</Setter.Value>
|
||||||
|
</Setter>
|
||||||
|
</Style>
|
||||||
|
</ItemsControl.ItemContainerStyle>
|
||||||
|
</ItemsControl>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<ControlTemplate.Triggers>
|
||||||
|
<Trigger Property="IsMouseOver" Value="True">
|
||||||
|
<Trigger.EnterActions>
|
||||||
|
<BeginStoryboard>
|
||||||
|
<Storyboard>
|
||||||
|
<DoubleAnimation Duration="0:0:0.2" To="1"
|
||||||
|
Storyboard.TargetName="PART_Grips" Storyboard.TargetProperty="Opacity" />
|
||||||
|
</Storyboard>
|
||||||
|
</BeginStoryboard>
|
||||||
|
</Trigger.EnterActions>
|
||||||
|
<Trigger.ExitActions>
|
||||||
|
<BeginStoryboard>
|
||||||
|
<Storyboard>
|
||||||
|
<DoubleAnimation Duration="0:0:0.25" To="0"
|
||||||
|
Storyboard.TargetName="PART_Grips" Storyboard.TargetProperty="Opacity" />
|
||||||
|
</Storyboard>
|
||||||
|
</BeginStoryboard>
|
||||||
|
</Trigger.ExitActions>
|
||||||
|
</Trigger>
|
||||||
|
</ControlTemplate.Triggers>
|
||||||
|
</ControlTemplate>
|
||||||
|
</Setter.Value>
|
||||||
|
</Setter>
|
||||||
|
</Style>
|
||||||
|
|
||||||
<DataTemplate DataType="{x:Type visualizationProvider:FrequencyBarsVisualizationProvider}">
|
<DataTemplate DataType="{x:Type visualizationProvider:FrequencyBarsVisualizationProvider}">
|
||||||
<visualization:FrequencyBarsVisualizer Style="{StaticResource StyleFrequencyBarsVisualizer}" VisualizationProvider="{Binding}" />
|
<Grid>
|
||||||
|
<visualization:FrequencyBarsVisualizer Style="{StaticResource StyleFrequencyBarsVisualizer}" VisualizationProvider="{Binding}" />
|
||||||
|
<visualization:EqualizerVisualizer Style="{StaticResource StyleEqualizerVisualizer}" Equalizer="{Binding Equalizer}" ReferenceLevel="{Binding Configuration.ReferenceLevel}" />
|
||||||
|
</Grid>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|
||||||
</styles:CachedResourceDictionary>
|
</styles:CachedResourceDictionary>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user