1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-13 01:58:30 +00:00

Changed update-Pprameter away from dictionary

This commit is contained in:
Darth Affe 2021-03-03 23:06:22 +01:00
parent 9c8d67740d
commit 2222808c23
27 changed files with 133 additions and 149 deletions

View File

@ -2,7 +2,6 @@
// ReSharper disable UnusedAutoPropertyAccessor.Global // ReSharper disable UnusedAutoPropertyAccessor.Global
using System; using System;
using System.Collections.Generic;
namespace RGB.NET.Core namespace RGB.NET.Core
{ {

View File

@ -3,7 +3,6 @@
// ReSharper disable VirtualMemberNeverOverridden.Global // ReSharper disable VirtualMemberNeverOverridden.Global
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
namespace RGB.NET.Core namespace RGB.NET.Core
{ {

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Buffers;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -16,7 +17,7 @@ namespace RGB.NET.Core
private readonly object _dataLock = new(); private readonly object _dataLock = new();
private readonly IDeviceUpdateTrigger _updateTrigger; private readonly IDeviceUpdateTrigger _updateTrigger;
private Dictionary<TIdentifier, TData>? _currentDataSet; private readonly Dictionary<TIdentifier, TData> _currentDataSet = new();
#endregion #endregion
@ -45,17 +46,25 @@ namespace RGB.NET.Core
/// <param name="customData"><see cref="CustomUpdateData"/> provided by the trigger.</param> /// <param name="customData"><see cref="CustomUpdateData"/> provided by the trigger.</param>
protected virtual void OnUpdate(object? sender, CustomUpdateData customData) protected virtual void OnUpdate(object? sender, CustomUpdateData customData)
{ {
Dictionary<TIdentifier, TData> dataSet; (TIdentifier, TData)[] dataSet;
lock (_dataLock) lock (_dataLock)
{ {
if (_currentDataSet == null) return; if (_currentDataSet.Count == 0) return;
dataSet = _currentDataSet; dataSet = ArrayPool<(TIdentifier, TData)>.Shared.Rent(_currentDataSet.Count);
_currentDataSet = null; Span<(TIdentifier, TData)> data = new Span<(TIdentifier, TData)>(dataSet).Slice(0, _currentDataSet.Count);
int i = 0;
foreach ((TIdentifier key, TData value) in _currentDataSet)
data[i++] = (key, value);
_currentDataSet.Clear();
} }
if (dataSet.Count != 0) if (dataSet.Length != 0)
Update(dataSet); Update(dataSet);
ArrayPool<(TIdentifier, TData)>.Shared.Return(dataSet);
} }
/// <summary> /// <summary>
@ -69,26 +78,22 @@ namespace RGB.NET.Core
/// Performs the update this queue is responsible for. /// Performs the update this queue is responsible for.
/// </summary> /// </summary>
/// <param name="dataSet">The set of data that needs to be updated.</param> /// <param name="dataSet">The set of data that needs to be updated.</param>
protected abstract void Update(Dictionary<TIdentifier, TData> dataSet); protected abstract void Update(in ReadOnlySpan<(TIdentifier key, TData color)> dataSet);
/// <summary> /// <summary>
/// Sets or merges the provided data set in the current dataset and notifies the trigger that there is new data available. /// Sets or merges the provided data set in the current dataset and notifies the trigger that there is new data available.
/// </summary> /// </summary>
/// <param name="dataSet">The set of data.</param> /// <param name="dataSet">The set of data.</param>
// ReSharper disable once MemberCanBeProtected.Global // ReSharper disable once MemberCanBeProtected.Global
public virtual void SetData(Dictionary<TIdentifier, TData> dataSet) public virtual void SetData(IEnumerable<(TIdentifier, TData)> dataSet)
{ {
if (dataSet.Count == 0) return; IList<(TIdentifier, TData)> data = dataSet.ToList();
if (data.Count == 0) return;
lock (_dataLock) lock (_dataLock)
{ {
if (_currentDataSet == null) foreach ((TIdentifier key, TData value) in data)
_currentDataSet = dataSet; _currentDataSet[key] = value;
else
{
foreach ((TIdentifier key, TData value) in dataSet)
_currentDataSet[key] = value;
}
} }
_updateTrigger.TriggerHasData(); _updateTrigger.TriggerHasData();
@ -100,7 +105,7 @@ namespace RGB.NET.Core
public virtual void Reset() public virtual void Reset()
{ {
lock (_dataLock) lock (_dataLock)
_currentDataSet = null; _currentDataSet.Clear();
} }
/// <inheritdoc /> /// <inheritdoc />
@ -135,7 +140,7 @@ namespace RGB.NET.Core
/// Calls <see cref="UpdateQueue{TIdentifier,TData}.SetData"/> for a data set created out of the provided list of <see cref="Led"/>. /// Calls <see cref="UpdateQueue{TIdentifier,TData}.SetData"/> for a data set created out of the provided list of <see cref="Led"/>.
/// </summary> /// </summary>
/// <param name="leds"></param> /// <param name="leds"></param>
public void SetData(IEnumerable<Led> leds) => SetData(leds.ToDictionary(x => x.CustomData ?? x.Id, x => x.Color)); public void SetData(IEnumerable<Led> leds) => SetData(leds.Select(x => (x.CustomData ?? x.Id, x.Color)));
#endregion #endregion
} }

View File

@ -1,4 +1,4 @@
using System.Collections.Generic; using System;
using AuraServiceLib; using AuraServiceLib;
using RGB.NET.Core; using RGB.NET.Core;
@ -43,7 +43,7 @@ namespace RGB.NET.Devices.Asus
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void Update(Dictionary<object, Color> dataSet) protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
{ {
if (Device == null) return; if (Device == null) return;

View File

@ -1,4 +1,4 @@
using System.Collections.Generic; using System;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.CoolerMaster.Native; using RGB.NET.Devices.CoolerMaster.Native;
@ -28,7 +28,7 @@ namespace RGB.NET.Devices.CoolerMaster
: base(updateTrigger) : base(updateTrigger)
{ {
this._deviceIndex = deviceIndex; this._deviceIndex = deviceIndex;
_deviceMatrix = new _CoolerMasterColorMatrix(); _deviceMatrix = new _CoolerMasterColorMatrix();
_deviceMatrix.KeyColor = new _CoolerMasterKeyColor[_CoolerMasterColorMatrix.ROWS, _CoolerMasterColorMatrix.COLUMNS]; _deviceMatrix.KeyColor = new _CoolerMasterKeyColor[_CoolerMasterColorMatrix.ROWS, _CoolerMasterColorMatrix.COLUMNS];
} }
@ -38,12 +38,12 @@ namespace RGB.NET.Devices.CoolerMaster
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override void Update(Dictionary<object, Color> dataSet) protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
{ {
foreach (KeyValuePair<object, Color> data in dataSet) foreach ((object key, Color color) in dataSet)
{ {
(int row, int column) = ((int, int))data.Key; (int row, int column) = ((int, int))key;
_deviceMatrix.KeyColor[row, column] = new _CoolerMasterKeyColor(data.Value.GetR(), data.Value.GetG(), data.Value.GetB()); _deviceMatrix.KeyColor[row, column] = new _CoolerMasterKeyColor(color.GetR(), color.GetG(), color.GetB());
} }
_CoolerMasterSDK.SetAllLedColor(_deviceMatrix, _deviceIndex); _CoolerMasterSDK.SetAllLedColor(_deviceMatrix, _deviceIndex);

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Native; using RGB.NET.Devices.Corsair.Native;
@ -36,26 +35,26 @@ namespace RGB.NET.Devices.Corsair
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override void Update(Dictionary<object, Color> dataSet) protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
{ {
int structSize = Marshal.SizeOf(typeof(_CorsairLedColor)); int structSize = Marshal.SizeOf(typeof(_CorsairLedColor));
IntPtr ptr = Marshal.AllocHGlobal(structSize * dataSet.Count); IntPtr ptr = Marshal.AllocHGlobal(structSize * dataSet.Length);
IntPtr addPtr = new(ptr.ToInt64()); IntPtr addPtr = new(ptr.ToInt64());
foreach (KeyValuePair<object, Color> data in dataSet) foreach ((object key, Color color) in dataSet)
{ {
_CorsairLedColor color = new() _CorsairLedColor corsairColor = new()
{ {
ledId = (int)data.Key, ledId = (int)key,
r = data.Value.GetR(), r = color.GetR(),
g = data.Value.GetG(), g = color.GetG(),
b = data.Value.GetB() b = color.GetB()
}; };
Marshal.StructureToPtr(color, addPtr, false); Marshal.StructureToPtr(corsairColor, addPtr, false);
addPtr = new IntPtr(addPtr.ToInt64() + structSize); addPtr = new IntPtr(addPtr.ToInt64() + structSize);
} }
_CUESDK.CorsairSetLedsColorsBufferByDeviceIndex(_deviceIndex, dataSet.Count, ptr); _CUESDK.CorsairSetLedsColorsBufferByDeviceIndex(_deviceIndex, dataSet.Length, ptr);
_CUESDK.CorsairSetLedsColorsFlushBuffer(); _CUESDK.CorsairSetLedsColorsFlushBuffer();
Marshal.FreeHGlobal(ptr); Marshal.FreeHGlobal(ptr);
} }

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Net.Sockets; using System.Net.Sockets;
using RGB.NET.Core; using RGB.NET.Core;
@ -52,15 +51,15 @@ namespace RGB.NET.Devices.DMX.E131
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override void Update(Dictionary<object, Color> dataSet) protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
{ {
DataPacket.SetSequenceNumber(GetNextSequenceNumber()); DataPacket.SetSequenceNumber(GetNextSequenceNumber());
foreach (KeyValuePair<object, Color> data in dataSet) foreach ((object key, Color color) in dataSet)
{ {
LedChannelMapping mapping = (LedChannelMapping)data.Key; LedChannelMapping mapping = (LedChannelMapping)key;
foreach ((int channel, Func<Color, byte> getValue) in mapping) foreach ((int channel, Func<Color, byte> getValue) in mapping)
DataPacket.SetChannel(channel, getValue(data.Value)); DataPacket.SetChannel(channel, getValue(color));
} }
_socket.Send(DataPacket, DataPacket.Length); _socket.Send(DataPacket, DataPacket.Length);

View File

@ -1,6 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Logitech.Native; using RGB.NET.Devices.Logitech.Native;
@ -27,9 +25,9 @@ namespace RGB.NET.Devices.Logitech
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override void Update(Dictionary<object, Color> dataSet) protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
{ {
Color color = dataSet.Values.First(); Color color = dataSet[0].color;
_LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.DeviceRGB); _LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.DeviceRGB);
_LogitechGSDK.LogiLedSetLighting((int)Math.Round(color.R * 100), _LogitechGSDK.LogiLedSetLighting((int)Math.Round(color.R * 100),

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Logitech.Native; using RGB.NET.Devices.Logitech.Native;
@ -33,27 +32,27 @@ namespace RGB.NET.Devices.Logitech
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override void Update(Dictionary<object, Color> dataSet) protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
{ {
_LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.PerKeyRGB); _LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.PerKeyRGB);
Array.Clear(_bitmap, 0, _bitmap.Length); Array.Clear(_bitmap, 0, _bitmap.Length);
bool usesBitmap = false; bool usesBitmap = false;
foreach (KeyValuePair<object, Color> data in dataSet) foreach ((object key, Color color) in dataSet)
{ {
(LedId id, LogitechLedId customData) = ((LedId, LogitechLedId))data.Key; (LedId id, LogitechLedId customData) = ((LedId, LogitechLedId))key;
// DarthAffe 26.03.2017: This is only needed since update by name doesn't work as expected for all keys ... // DarthAffe 26.03.2017: This is only needed since update by name doesn't work as expected for all keys ...
if (BitmapMapping.BitmapOffset.TryGetValue(id, out int bitmapOffset)) if (BitmapMapping.BitmapOffset.TryGetValue(id, out int bitmapOffset))
{ {
BitmapMapping.SetColor(_bitmap, bitmapOffset, data.Value); BitmapMapping.SetColor(_bitmap, bitmapOffset, color);
usesBitmap = true; usesBitmap = true;
} }
else else
_LogitechGSDK.LogiLedSetLightingForKeyWithKeyName((int)customData, _LogitechGSDK.LogiLedSetLightingForKeyWithKeyName((int)customData,
(int)Math.Round(data.Value.R * 100), (int)MathF.Round(color.R * 100),
(int)Math.Round(data.Value.G * 100), (int)MathF.Round(color.G * 100),
(int)Math.Round(data.Value.B * 100)); (int)MathF.Round(color.B * 100));
} }
if (usesBitmap) if (usesBitmap)

View File

@ -13,12 +13,12 @@ namespace RGB.NET.Devices.Logitech
#region Constants #region Constants
private static readonly Dictionary<RGBDeviceType, LogitechDeviceType> DEVICE_TYPE_MAPPING = new() private static readonly Dictionary<RGBDeviceType, LogitechDeviceType> DEVICE_TYPE_MAPPING = new()
{ {
{RGBDeviceType.Keyboard, LogitechDeviceType.Keyboard}, { RGBDeviceType.Keyboard, LogitechDeviceType.Keyboard },
{RGBDeviceType.Mouse, LogitechDeviceType.Mouse}, { RGBDeviceType.Mouse, LogitechDeviceType.Mouse },
{RGBDeviceType.Headset, LogitechDeviceType.Headset}, { RGBDeviceType.Headset, LogitechDeviceType.Headset },
{RGBDeviceType.Mousepad, LogitechDeviceType.Mousemat}, { RGBDeviceType.Mousepad, LogitechDeviceType.Mousemat },
{RGBDeviceType.Speaker, LogitechDeviceType.Speaker} { RGBDeviceType.Speaker, LogitechDeviceType.Speaker }
}; };
#endregion #endregion
@ -48,17 +48,17 @@ namespace RGB.NET.Devices.Logitech
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override void Update(Dictionary<object, Color> dataSet) protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
{ {
_LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.All); _LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.All);
foreach (KeyValuePair<object, Color> data in dataSet) foreach ((object key, Color color) in dataSet)
{ {
int zone = (int)data.Key; int zone = (int)key;
_LogitechGSDK.LogiLedSetLightingForTargetZone(_deviceType, zone, _LogitechGSDK.LogiLedSetLightingForTargetZone(_deviceType, zone,
(int)Math.Round(data.Value.R * 100), (int)MathF.Round(color.R * 100),
(int)Math.Round(data.Value.G * 100), (int)MathF.Round(color.G * 100),
(int)Math.Round(data.Value.B * 100)); (int)MathF.Round(color.B * 100));
} }
} }

View File

@ -1,4 +1,4 @@
using System.Collections.Generic; using System;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Msi.Native; using RGB.NET.Devices.Msi.Native;
@ -34,10 +34,10 @@ namespace RGB.NET.Devices.Msi
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override void Update(Dictionary<object, Color> dataSet) protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
{ {
foreach (KeyValuePair<object, Color> data in dataSet) foreach ((object key, Color color) in dataSet)
_MsiSDK.SetLedColor(_deviceType, (int)data.Key, data.Value.GetR(), data.Value.GetG(), data.Value.GetB()); _MsiSDK.SetLedColor(_deviceType, (int)key, color.GetR(), color.GetG(), color.GetB());
} }
#endregion #endregion

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using RGB.NET.Core; using RGB.NET.Core;
using Sanford.Multimedia.Midi; using Sanford.Multimedia.Midi;
@ -26,10 +25,10 @@ namespace RGB.NET.Devices.Novation
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override ShortMessage CreateMessage(KeyValuePair<object, Color> data) protected override ShortMessage CreateMessage(object key, in Color color)
{ {
(byte mode, byte id) = ((byte, byte))data.Key; (byte mode, byte id) = ((byte, byte))key;
return new ShortMessage(mode, id, Convert.ToByte(ConvertColor(data.Value))); return new ShortMessage(mode, id, Convert.ToByte(ConvertColor(color)));
} }
/// <summary> /// <summary>
@ -38,9 +37,9 @@ namespace RGB.NET.Devices.Novation
/// </summary> /// </summary>
/// <param name="color">The <see cref="Color"/> to convert.</param> /// <param name="color">The <see cref="Color"/> to convert.</param>
/// <returns>The novation-representation of the <see cref="Color"/>.</returns> /// <returns>The novation-representation of the <see cref="Color"/>.</returns>
protected virtual int ConvertColor(Color color) protected virtual int ConvertColor(in Color color)
{ {
(double hue, double saturation, double value) = color.GetHSV(); (double hue, double _, double value) = color.GetHSV();
if ((hue >= 330) || (hue < 30)) if ((hue >= 330) || (hue < 30))
return (int)Math.Ceiling(value * 3); // red with brightness 1, 2 or 3 return (int)Math.Ceiling(value * 3); // red with brightness 1, 2 or 3

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using RGB.NET.Core; using RGB.NET.Core;
using Sanford.Multimedia.Midi; using Sanford.Multimedia.Midi;
@ -37,10 +36,10 @@ namespace RGB.NET.Devices.Novation
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override void Update(Dictionary<object, Color> dataSet) protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
{ {
foreach (KeyValuePair<object, Color> data in dataSet) foreach ((object key, Color color) in dataSet)
SendMessage(CreateMessage(data)); SendMessage(CreateMessage(key, color));
} }
/// <summary> /// <summary>
@ -59,7 +58,7 @@ namespace RGB.NET.Devices.Novation
/// </summary> /// </summary>
/// <param name="data">The data set to create the message from.</param> /// <param name="data">The data set to create the message from.</param>
/// <returns>The message created out of the data set.</returns> /// <returns>The message created out of the data set.</returns>
protected abstract ShortMessage? CreateMessage(KeyValuePair<object, Color> data); protected abstract ShortMessage? CreateMessage(object key, in Color color);
/// <inheritdoc /> /// <inheritdoc />
public override void Dispose() public override void Dispose()

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using RGB.NET.Core; using RGB.NET.Core;
using Sanford.Multimedia.Midi; using Sanford.Multimedia.Midi;
@ -152,12 +151,12 @@ namespace RGB.NET.Devices.Novation
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override ShortMessage? CreateMessage(KeyValuePair<object, Color> data) protected override ShortMessage? CreateMessage(object key, in Color color)
{ {
(byte mode, byte id) = ((byte, byte))data.Key; (byte mode, byte id) = ((byte, byte))key;
if (mode == 0x00) return null; if (mode == 0x00) return null;
return new ShortMessage(mode, id, Convert.ToByte(ConvertColor(data.Value))); return new ShortMessage(mode, id, Convert.ToByte(ConvertColor(color)));
} }
/// <summary> /// <summary>
@ -166,7 +165,7 @@ namespace RGB.NET.Devices.Novation
/// </summary> /// </summary>
/// <param name="color">The <see cref="Color"/> to convert.</param> /// <param name="color">The <see cref="Color"/> to convert.</param>
/// <returns>The novation-representation of the <see cref="Color"/>.</returns> /// <returns>The novation-representation of the <see cref="Color"/>.</returns>
protected virtual int ConvertColor(Color color) protected virtual int ConvertColor(in Color color)
{ {
int bestVelocity = 0; int bestVelocity = 0;
double bestMatchDistance = double.MaxValue; double bestMatchDistance = double.MaxValue;

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Razer.Native; using RGB.NET.Devices.Razer.Native;
@ -27,15 +26,15 @@ namespace RGB.NET.Devices.Razer
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override IntPtr CreateEffectParams(Dictionary<object, Color> dataSet) protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet)
{ {
_Color[] colors = new _Color[_Defines.CHROMALINK_MAX_LEDS]; _Color[] colors = new _Color[_Defines.CHROMALINK_MAX_LEDS];
foreach (KeyValuePair<object, Color> data in dataSet) foreach ((object key, Color color) in dataSet)
colors[(int)data.Key] = new _Color(data.Value); colors[(int)key] = new _Color(color);
_ChromaLinkCustomEffect effectParams = new() _ChromaLinkCustomEffect effectParams = new()
{ Color = colors }; { Color = colors };
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
Marshal.StructureToPtr(effectParams, ptr, false); Marshal.StructureToPtr(effectParams, ptr, false);

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Razer.Native; using RGB.NET.Devices.Razer.Native;
@ -35,7 +34,7 @@ namespace RGB.NET.Devices.Razer
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override void Update(Dictionary<object, Color> dataSet) protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
{ {
IntPtr effectParams = CreateEffectParams(dataSet); IntPtr effectParams = CreateEffectParams(dataSet);
Guid effectId = Guid.NewGuid(); Guid effectId = Guid.NewGuid();
@ -71,7 +70,7 @@ namespace RGB.NET.Devices.Razer
/// </summary> /// </summary>
/// <param name="dataSet">The data to be updated.</param> /// <param name="dataSet">The data to be updated.</param>
/// <returns>An <see cref="IntPtr"/> pointing to the effect parameter struct.</returns> /// <returns>An <see cref="IntPtr"/> pointing to the effect parameter struct.</returns>
protected abstract IntPtr CreateEffectParams(Dictionary<object, Color> dataSet); protected abstract IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet);
#endregion #endregion
} }

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Razer.Native; using RGB.NET.Devices.Razer.Native;
@ -27,16 +26,16 @@ namespace RGB.NET.Devices.Razer
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override IntPtr CreateEffectParams(Dictionary<object, Color> dataSet) protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet)
{ {
_Color[] colors = new _Color[_Defines.HEADSET_MAX_LEDS]; _Color[] colors = new _Color[_Defines.HEADSET_MAX_LEDS];
foreach (KeyValuePair<object, Color> data in dataSet) foreach ((object key, Color color) in dataSet)
colors[(int)data.Key] = new _Color(data.Value); colors[(int)key] = new _Color(color);
_HeadsetCustomEffect effectParams = new() _HeadsetCustomEffect effectParams = new()
{ Color = colors }; { Color = colors };
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
Marshal.StructureToPtr(effectParams, ptr, false); Marshal.StructureToPtr(effectParams, ptr, false);

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Razer.Native; using RGB.NET.Devices.Razer.Native;
@ -27,15 +26,14 @@ namespace RGB.NET.Devices.Razer
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override IntPtr CreateEffectParams(Dictionary<object, Color> dataSet) protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet)
{ {
_Color[] colors = new _Color[_Defines.KEYBOARD_MAX_LEDS]; _Color[] colors = new _Color[_Defines.KEYBOARD_MAX_LEDS];
foreach (KeyValuePair<object, Color> data in dataSet) foreach ((object key, Color color) in dataSet)
colors[(int)data.Key] = new _Color(data.Value); colors[(int)key] = new _Color(color);
_KeyboardCustomEffect effectParams = new() _KeyboardCustomEffect effectParams = new() { Color = colors };
{ Color = colors };
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
Marshal.StructureToPtr(effectParams, ptr, false); Marshal.StructureToPtr(effectParams, ptr, false);

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Razer.Native; using RGB.NET.Devices.Razer.Native;
@ -27,15 +26,14 @@ namespace RGB.NET.Devices.Razer
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override IntPtr CreateEffectParams(Dictionary<object, Color> dataSet) protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet)
{ {
_Color[] colors = new _Color[_Defines.KEYPAD_MAX_LEDS]; _Color[] colors = new _Color[_Defines.KEYPAD_MAX_LEDS];
foreach (KeyValuePair<object, Color> data in dataSet) foreach ((object key, Color color) in dataSet)
colors[(int)data.Key] = new _Color(data.Value); colors[(int)key] = new _Color(color);
_KeypadCustomEffect effectParams = new() _KeypadCustomEffect effectParams = new() { Color = colors };
{ Color = colors };
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
Marshal.StructureToPtr(effectParams, ptr, false); Marshal.StructureToPtr(effectParams, ptr, false);

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Razer.Native; using RGB.NET.Devices.Razer.Native;
@ -27,15 +26,14 @@ namespace RGB.NET.Devices.Razer
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override IntPtr CreateEffectParams(Dictionary<object, Color> dataSet) protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet)
{ {
_Color[] colors = new _Color[_Defines.MOUSE_MAX_LEDS]; _Color[] colors = new _Color[_Defines.MOUSE_MAX_LEDS];
foreach (KeyValuePair<object, Color> data in dataSet) foreach ((object key, Color color) in dataSet)
colors[(int)data.Key] = new _Color(data.Value); colors[(int)key] = new _Color(color);
_MouseCustomEffect effectParams = new() _MouseCustomEffect effectParams = new() { Color = colors };
{ Color = colors };
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
Marshal.StructureToPtr(effectParams, ptr, false); Marshal.StructureToPtr(effectParams, ptr, false);

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Razer.Native; using RGB.NET.Devices.Razer.Native;
@ -27,15 +26,14 @@ namespace RGB.NET.Devices.Razer
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override IntPtr CreateEffectParams(Dictionary<object, Color> dataSet) protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet)
{ {
_Color[] colors = new _Color[_Defines.MOUSEPAD_MAX_LEDS]; _Color[] colors = new _Color[_Defines.MOUSEPAD_MAX_LEDS];
foreach (KeyValuePair<object, Color> data in dataSet) foreach ((object key, Color color) in dataSet)
colors[(int)data.Key] = new _Color(data.Value); colors[(int)key] = new _Color(color);
_MousepadCustomEffect effectParams = new() _MousepadCustomEffect effectParams = new() { Color = colors };
{ Color = colors };
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
Marshal.StructureToPtr(effectParams, ptr, false); Marshal.StructureToPtr(effectParams, ptr, false);

View File

@ -1,4 +1,4 @@
using System.Collections.Generic; using System;
using System.Linq; using System.Linq;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.SteelSeries.API; using RGB.NET.Devices.SteelSeries.API;
@ -44,8 +44,8 @@ namespace RGB.NET.Devices.SteelSeries
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void Update(Dictionary<object, Color> dataSet) protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
=> SteelSeriesSDK.UpdateLeds(_deviceType, dataSet.Select(x => (((SteelSeriesLedId)x.Key).GetAPIName(), x.Value.ToIntArray())).Where(x => x.Item1 != null).ToList()!); => SteelSeriesSDK.UpdateLeds(_deviceType, dataSet.ToArray().Select(x => (((SteelSeriesLedId)x.key).GetAPIName(), x.color.ToIntArray())).Where(x => x.Item1 != null).ToList()!);
#endregion #endregion
} }

View File

@ -50,9 +50,9 @@ namespace RGB.NET.Devices.WS281X.Arduino
} }
/// <inheritdoc /> /// <inheritdoc />
protected override IEnumerable<byte[]> GetCommands(Dictionary<object, Color> dataSet) protected override IEnumerable<byte[]> GetCommands(IList<(object key, Color color)> dataSet)
{ {
foreach (IGrouping<int, ((int channel, int key), Color Value)> channelData in dataSet.Select(x => (((int channel, int key))x.Key, x.Value)) foreach (IGrouping<int, ((int channel, int key), Color Value)> channelData in dataSet.Select(x => (((int channel, int key))x.key, x.color))
.GroupBy(x => x.Item1.channel)) .GroupBy(x => x.Item1.channel))
{ {
int channel = channelData.Key; int channel = channelData.Key;

View File

@ -36,7 +36,7 @@ namespace RGB.NET.Devices.WS281X.Bitwizard
} }
/// <inheritdoc /> /// <inheritdoc />
protected override IEnumerable<string> GetCommands(Dictionary<object, Color> dataSet) protected override IEnumerable<string> GetCommands(IList<(object key, Color color)> dataSet)
{ {
foreach ((object key, Color value) in dataSet) foreach ((object key, Color value) in dataSet)
yield return $"pix {(int)key} {value.AsRGBHexString(false)}"; yield return $"pix {(int)key} {value.AsRGBHexString(false)}";

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using RGB.NET.Core; using RGB.NET.Core;
namespace RGB.NET.Devices.WS281X namespace RGB.NET.Devices.WS281X
@ -56,9 +57,9 @@ namespace RGB.NET.Devices.WS281X
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void Update(Dictionary<object, Color> dataSet) protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
{ {
foreach (TData command in GetCommands(dataSet)) foreach (TData command in GetCommands(dataSet.ToArray()))
{ {
SerialConnection.ReadTo(Prompt); SerialConnection.ReadTo(Prompt);
SendCommand(command); SendCommand(command);
@ -70,7 +71,7 @@ namespace RGB.NET.Devices.WS281X
/// </summary> /// </summary>
/// <param name="dataSet">The set of data that needs to be updated.</param> /// <param name="dataSet">The set of data that needs to be updated.</param>
/// <returns>The commands to be sent.</returns> /// <returns>The commands to be sent.</returns>
protected abstract IEnumerable<TData> GetCommands(Dictionary<object, Color> dataSet); protected abstract IEnumerable<TData> GetCommands(IList<(object key, Color color)> dataSet);
/// <summary> /// <summary>
/// Sends a command as a string followed by a line-break to the device. /// Sends a command as a string followed by a line-break to the device.

View File

@ -77,10 +77,9 @@ namespace RGB.NET.Devices.WS281X.NodeMCU
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void Update(Dictionary<object, Color> dataSet) protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
{ {
foreach (IGrouping<int, ((int channel, int key), Color Value)> channelData in dataSet.Select(x => (((int channel, int key))x.Key, x.Value)) foreach (IGrouping<int, ((int channel, int key), Color color)> channelData in dataSet.ToArray().Select(x => (((int channel, int key))x.key, x.color)).GroupBy(x => x.Item1.channel))
.GroupBy(x => x.Item1.channel))
{ {
byte[] buffer = GetBuffer(channelData); byte[] buffer = GetBuffer(channelData);
_sendDataAction(buffer); _sendDataAction(buffer);
@ -98,7 +97,7 @@ namespace RGB.NET.Devices.WS281X.NodeMCU
_udpClient?.Send(buffer, buffer.Length); _udpClient?.Send(buffer, buffer.Length);
} }
private byte[] GetBuffer(IGrouping<int, ((int channel, int key), Color Value)> data) private byte[] GetBuffer(IGrouping<int, ((int channel, int key) identifier, Color color)> data)
{ {
int channel = data.Key; int channel = data.Key;
byte[] buffer = _dataBuffer[channel]; byte[] buffer = _dataBuffer[channel];
@ -106,8 +105,8 @@ namespace RGB.NET.Devices.WS281X.NodeMCU
buffer[0] = GetSequenceNumber(channel); buffer[0] = GetSequenceNumber(channel);
buffer[1] = (byte)channel; buffer[1] = (byte)channel;
int i = 2; int i = 2;
foreach ((byte _, byte r, byte g, byte b) in data.OrderBy(x => x.Item1.key) foreach ((byte _, byte r, byte g, byte b) in data.OrderBy(x => x.identifier.key)
.Select(x => x.Value.GetRGBBytes())) .Select(x => x.color.GetRGBBytes()))
{ {
buffer[i++] = r; buffer[i++] = r;
buffer[i++] = g; buffer[i++] = g;

View File

@ -1,4 +1,4 @@
using System.Collections.Generic; using System;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Native; using RGB.NET.Devices.Wooting.Native;
@ -26,17 +26,17 @@ namespace RGB.NET.Devices.Wooting.Generic
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override void Update(Dictionary<object, Color> dataSet) protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
{ {
foreach (KeyValuePair<object, Color> data in dataSet) foreach ((object key, Color color) in dataSet)
{ {
(int row, int column) = ((int, int))data.Key; (int row, int column) = ((int, int))key;
_WootingSDK.ArraySetSingle((byte)row, (byte)column, data.Value.GetR(), data.Value.GetG(), data.Value.GetB()); _WootingSDK.ArraySetSingle((byte)row, (byte)column, color.GetR(), color.GetG(), color.GetB());
} }
_WootingSDK.ArrayUpdateKeyboard(); _WootingSDK.ArrayUpdateKeyboard();
} }
#endregion #endregion
} }
} }