mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2026-11-11 04:56:44 +00:00
First attempt to rewrite Effects
This commit is contained in:
1 parent
5a296dd048
commit
ba80ef9848
32 files changed
+353
-325
No files matched your search
@@ -3,7 +3,9 @@ using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using CUE.NET;
|
||||
using CUE.NET.Brushes;
|
||||
using CUE.NET.Devices.Generic.Enums;
|
||||
using CUE.NET.Devices.Keyboard;
|
||||
using CUE.NET.Devices.Keyboard.Keys;
|
||||
using CUE.NET.Exceptions;
|
||||
using CUE.NET.Gradients;
|
||||
using Example_AudioAnalyzer_full.TakeAsIs;
|
||||
@@ -60,18 +62,22 @@ namespace Example_AudioAnalyzer_full
|
||||
|
||||
public void Run()
|
||||
{
|
||||
// Add a lack background. We want this to be semi-transparent to add some sort of fade-effect - this will smooth everything out a bit
|
||||
_keyboard.UpdateMode = UpdateMode.Continuous;
|
||||
// Add a black background. We want this to be semi-transparent to add some sort of fade-effect - this will smooth everything out a bit
|
||||
// Note that this isn't a 'real effect' since it's update-rate dependent. A real effect would do always the same thing not mather how fast the keyboard updates.
|
||||
_keyboard.Brush = new SolidColorBrush(Color.FromArgb(96, 0, 0, 0));
|
||||
// Add our song-beat-effect. Remember to uncomment the update in the spectrum effect if you want to remove this.
|
||||
_keyboard.AttachEffect(new SongBeatEffect(_soundDataProcessor, Color.FromArgb(127, 164, 164, 164)));
|
||||
ListKeyGroup songBeatGroup = new ListKeyGroup(_keyboard, _keyboard);
|
||||
songBeatGroup.Brush = new SolidColorBrush(Color.FromArgb(127, 164, 164, 164));
|
||||
songBeatGroup.Brush.AddEffect(new SongBeatEffect(_soundDataProcessor));
|
||||
|
||||
// Add our spectrum-effect using the soundDataProcessor and a rainbow from purple to red as gradient
|
||||
_keyboard.AttachEffect(new AudioSpectrumEffect(_soundDataProcessor, new RainbowGradient(300, -14)));
|
||||
ListKeyGroup spectrumGroup = new ListKeyGroup(_keyboard, _keyboard);
|
||||
spectrumGroup.Brush = new AudioSpectrumBrush(_soundDataProcessor, new RainbowGradient(300, -14));
|
||||
|
||||
// Hook onto the keyboard update and process data
|
||||
_keyboard.Updating += (sender, args) => _soundDataProcessor.Process();
|
||||
|
||||
|
||||
// If you don't like rainbows replace the gradient with anything you like. For example:
|
||||
//_keyboard.AttachEffect(new AudioSpectrumEffect(_soundDataProcessor, new LinearGradient(new GradientStop(0f, Color.Blue), new GradientStop(1f, Color.Red))));
|
||||
|
||||
|
||||
@@ -11,16 +11,18 @@ namespace Example_AudioAnalyzer_full
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
public float[] BarData { get; set; }
|
||||
private SoundDataProcessor _soundDataProcessor;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
// default values for start/end are fine
|
||||
public AudioSpectrumBrush(IGradient gradient)
|
||||
public AudioSpectrumBrush(SoundDataProcessor soundDataProcessor, IGradient gradient)
|
||||
: base(gradient)
|
||||
{ }
|
||||
{
|
||||
this._soundDataProcessor = soundDataProcessor;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -28,11 +30,11 @@ namespace Example_AudioAnalyzer_full
|
||||
|
||||
public override Color GetColorAtPoint(RectangleF rectangle, PointF point)
|
||||
{
|
||||
if (BarData == null) return Color.Transparent;
|
||||
if (_soundDataProcessor?.BarValues == null) return Color.Transparent;
|
||||
|
||||
// This logic is also stolen from AterialDawn
|
||||
int barSampleIndex = (int)Math.Floor(BarData.Length * (point.X / (rectangle.X + rectangle.Width))); // Calculate bar sampling index
|
||||
float curBarHeight = 1f - Utility.Clamp(BarData[barSampleIndex], 0f, 1f); // Invert this value since the keyboard is laid out with topleft being point 0,0
|
||||
int barSampleIndex = (int)Math.Floor(_soundDataProcessor.BarValues.Length * (point.X / (rectangle.X + rectangle.Width))); // Calculate bar sampling index
|
||||
float curBarHeight = 1f - Utility.Clamp(_soundDataProcessor.BarValues[barSampleIndex], 0f, 1f); // Invert this value since the keyboard is laid out with topleft being point 0,0
|
||||
float verticalPos = (point.Y / rectangle.Height);
|
||||
|
||||
// If the barHeight is lower than the vertical pos currently calculated return the brush value. Otherwise do nothing by returning transparent.
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
using CUE.NET.Brushes;
|
||||
using CUE.NET.Effects;
|
||||
using CUE.NET.Gradients;
|
||||
using Example_AudioAnalyzer_full.TakeAsIs;
|
||||
|
||||
namespace Example_AudioAnalyzer_full
|
||||
{
|
||||
public class AudioSpectrumEffect : AbstractEffect
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private SoundDataProcessor _dataProcessor;
|
||||
|
||||
private AudioSpectrumBrush _audioSpectrumBrush;
|
||||
public override IBrush EffectBrush => _audioSpectrumBrush;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public AudioSpectrumEffect(SoundDataProcessor dataProcessor, IGradient gradient)
|
||||
{
|
||||
this._dataProcessor = dataProcessor;
|
||||
_audioSpectrumBrush = new AudioSpectrumBrush(gradient);
|
||||
|
||||
// Give this effect a high Z-Index to keep it in the foreground
|
||||
ZIndex = 10;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
_audioSpectrumBrush.BarData = _dataProcessor.BarValues;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,6 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="AudioAnalyzerExample.cs" />
|
||||
<Compile Include="AudioSpectrumBrush.cs" />
|
||||
<Compile Include="AudioSpectrumEffect.cs" />
|
||||
<Compile Include="SongBeatEffect.cs" />
|
||||
<Compile Include="TakeAsIs\BassHelper.cs" />
|
||||
<Compile Include="TakeAsIs\SoundDataProcessor.cs" />
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
using System.Drawing;
|
||||
using CUE.NET.Brushes;
|
||||
using CUE.NET.Effects;
|
||||
using CUE.NET.Effects;
|
||||
using Example_AudioAnalyzer_full.TakeAsIs;
|
||||
|
||||
namespace Example_AudioAnalyzer_full
|
||||
{
|
||||
public class SongBeatEffect : AbstractEffect
|
||||
public class SongBeatEffect : AbstractBrushEffect
|
||||
{
|
||||
#region Constants
|
||||
|
||||
@@ -22,17 +20,13 @@ namespace Example_AudioAnalyzer_full
|
||||
|
||||
private float _currentEffect = -1f;
|
||||
|
||||
private SolidColorBrush _brush;
|
||||
public override IBrush EffectBrush => _brush;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public SongBeatEffect(SoundDataProcessor dataProcessor, Color color)
|
||||
public SongBeatEffect(SoundDataProcessor dataProcessor)
|
||||
{
|
||||
this._dataProcessor = dataProcessor;
|
||||
_brush = new SolidColorBrush(color);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -48,7 +42,7 @@ namespace Example_AudioAnalyzer_full
|
||||
_currentEffect -= deltaTime;
|
||||
|
||||
// and set the current brush-opacity
|
||||
_brush.Opacity = _currentEffect > 0f ? (_currentEffect / FLASH_DURATION) : 0f;
|
||||
Brush.Opacity = _currentEffect > 0f ? (_currentEffect / FLASH_DURATION) : 0f;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in new issue
Block a user