Changed all namespaces to file-scope

This commit is contained in:
DarthAffe committed 2021-11-13 17:35:08 +01:00
1 parent a0c6ccebea
commit 30624035f1
353 files changed
+35775 -36129

No files matched your search

@@ -1,10 +1,9 @@
using RGB.NET.Core;
namespace RGB.NET.Devices.Novation
{
/// <summary>
/// Represents a novation RGB-device.
/// </summary>
public interface INovationRGBDevice : IRGBDevice
{ }
}
namespace RGB.NET.Devices.Novation;
/// <summary>
/// Represents a novation RGB-device.
/// </summary>
public interface INovationRGBDevice : IRGBDevice
{ }
@@ -2,61 +2,60 @@
using RGB.NET.Core;
using Sanford.Multimedia.Midi;
namespace RGB.NET.Devices.Novation
namespace RGB.NET.Devices.Novation;
/// <summary>
/// Represents the update-queue performing updates for a limited-color novation device.
/// </summary>
public class LimitedColorUpdateQueue : MidiUpdateQueue
{
#region Constructors
/// <summary>
/// Represents the update-queue performing updates for a limited-color novation device.
/// Initializes a new instance of the <see cref="LimitedColorUpdateQueue"/> class.
/// </summary>
public class LimitedColorUpdateQueue : MidiUpdateQueue
/// <param name="updateTrigger">The update trigger used by this queue.</param>
/// <param name="deviceId">The device-id of the device this queue is performing updates for.</param>
public LimitedColorUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceId)
: base(updateTrigger, deviceId)
{ }
#endregion
#region Methods
/// <inheritdoc />
protected override ShortMessage CreateMessage(object key, in Color color)
{
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="LimitedColorUpdateQueue"/> class.
/// </summary>
/// <param name="updateTrigger">The update trigger used by this queue.</param>
/// <param name="deviceId">The device-id of the device this queue is performing updates for.</param>
public LimitedColorUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceId)
: base(updateTrigger, deviceId)
{ }
#endregion
#region Methods
/// <inheritdoc />
protected override ShortMessage CreateMessage(object key, in Color color)
{
(byte mode, byte id) = ((byte, byte))key;
return new ShortMessage(mode, id, Convert.ToByte(ConvertColor(color)));
}
/// <summary>
/// Convert a <see cref="Color"/> to its novation-representation depending on the <see cref="NovationColorCapabilities"/> of the <see cref="NovationRGBDevice{TDeviceInfo}"/>.
/// The conversion uses only a limited amount of colors (3 red, 3 yellow, 3 green).
/// </summary>
/// <param name="color">The <see cref="Color"/> to convert.</param>
/// <returns>The novation-representation of the <see cref="Color"/>.</returns>
protected virtual int ConvertColor(in Color color)
{
(double hue, double _, double value) = color.GetHSV();
return hue switch
{
>= 330 or < 30 => (int)Math.Ceiling(value * 3), // red with brightness 1, 2 or 3
>= 30 and < 90 => (int)Math.Ceiling(value * 3) * 17, // yellow with brightness 17, 34 or 51
>= 90 and < 150 => (int)Math.Ceiling(value * 3) * 16, // green with brightness 16, 32 or 48
_ => 0
};
}
/// <inheritdoc />
public override void Reset()
{
base.Reset();
SendMessage(new ShortMessage(Convert.ToByte(0xB0), Convert.ToByte(0), Convert.ToByte(0)));
}
#endregion
(byte mode, byte id) = ((byte, byte))key;
return new ShortMessage(mode, id, Convert.ToByte(ConvertColor(color)));
}
}
/// <summary>
/// Convert a <see cref="Color"/> to its novation-representation depending on the <see cref="NovationColorCapabilities"/> of the <see cref="NovationRGBDevice{TDeviceInfo}"/>.
/// The conversion uses only a limited amount of colors (3 red, 3 yellow, 3 green).
/// </summary>
/// <param name="color">The <see cref="Color"/> to convert.</param>
/// <returns>The novation-representation of the <see cref="Color"/>.</returns>
protected virtual int ConvertColor(in Color color)
{
(double hue, double _, double value) = color.GetHSV();
return hue switch
{
>= 330 or < 30 => (int)Math.Ceiling(value * 3), // red with brightness 1, 2 or 3
>= 30 and < 90 => (int)Math.Ceiling(value * 3) * 17, // yellow with brightness 17, 34 or 51
>= 90 and < 150 => (int)Math.Ceiling(value * 3) * 16, // green with brightness 16, 32 or 48
_ => 0
};
}
/// <inheritdoc />
public override void Reset()
{
base.Reset();
SendMessage(new ShortMessage(Convert.ToByte(0xB0), Convert.ToByte(0), Convert.ToByte(0)));
}
#endregion
}
@@ -2,73 +2,72 @@
using RGB.NET.Core;
using Sanford.Multimedia.Midi;
namespace RGB.NET.Devices.Novation
namespace RGB.NET.Devices.Novation;
/// <inheritdoc cref="UpdateQueue" />
/// <summary>
/// Represents the update-queue performing updates for midi devices.
/// </summary>
public abstract class MidiUpdateQueue : UpdateQueue
{
/// <inheritdoc cref="UpdateQueue" />
#region Properties & Fields
private readonly OutputDevice _outputDevice;
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Represents the update-queue performing updates for midi devices.
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Novation.MidiUpdateQueue" /> class.
/// </summary>
public abstract class MidiUpdateQueue : UpdateQueue
/// <param name="updateTrigger">The update trigger used by this queue.</param>
/// <param name="deviceId">The id of the device this queue is performing updates for.</param>
protected MidiUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceId)
: base(updateTrigger)
{
#region Properties & Fields
private readonly OutputDevice _outputDevice;
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Novation.MidiUpdateQueue" /> class.
/// </summary>
/// <param name="updateTrigger">The update trigger used by this queue.</param>
/// <param name="deviceId">The id of the device this queue is performing updates for.</param>
protected MidiUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceId)
: base(updateTrigger)
{
_outputDevice = new OutputDevice(deviceId);
}
#endregion
#region Methods
/// <inheritdoc />
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
{
foreach ((object key, Color color) in dataSet)
SendMessage(CreateMessage(key, color));
}
/// <summary>
/// Sends the specified message to the device this queue is performing updates for.
/// </summary>
/// <param name="message">The message to send.</param>
protected virtual void SendMessage(ShortMessage? message)
{
if (message != null)
_outputDevice.SendShort(message.Message);
}
/// <summary>
/// Creates a update-message out of a specified data set.
/// </summary>
/// <param name="key">The key used to identify the LED to update.</param>
/// <param name="color">The color to send.</param>
/// <returns>The message created out of the data set.</returns>
protected abstract ShortMessage? CreateMessage(object key, in Color color);
/// <inheritdoc />
public override void Dispose()
{
base.Dispose();
_outputDevice.Dispose();
GC.SuppressFinalize(this);
}
#endregion
_outputDevice = new OutputDevice(deviceId);
}
}
#endregion
#region Methods
/// <inheritdoc />
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
{
foreach ((object key, Color color) in dataSet)
SendMessage(CreateMessage(key, color));
}
/// <summary>
/// Sends the specified message to the device this queue is performing updates for.
/// </summary>
/// <param name="message">The message to send.</param>
protected virtual void SendMessage(ShortMessage? message)
{
if (message != null)
_outputDevice.SendShort(message.Message);
}
/// <summary>
/// Creates a update-message out of a specified data set.
/// </summary>
/// <param name="key">The key used to identify the LED to update.</param>
/// <param name="color">The color to send.</param>
/// <returns>The message created out of the data set.</returns>
protected abstract ShortMessage? CreateMessage(object key, in Color color);
/// <inheritdoc />
public override void Dispose()
{
base.Dispose();
_outputDevice.Dispose();
GC.SuppressFinalize(this);
}
#endregion
}
@@ -2,55 +2,54 @@
using System.Collections.Generic;
using RGB.NET.Core;
namespace RGB.NET.Devices.Novation
namespace RGB.NET.Devices.Novation;
/// <inheritdoc cref="AbstractRGBDevice{TDeviceInfo}" />
/// <summary>
/// Represents a generic Novation-device. (launchpad).
/// </summary>
public abstract class NovationRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceInfo>, INovationRGBDevice
where TDeviceInfo : NovationRGBDeviceInfo
{
/// <inheritdoc cref="AbstractRGBDevice{TDeviceInfo}" />
#region Constructors
/// <summary>
/// Represents a generic Novation-device. (launchpad).
/// Initializes a new instance of the <see cref="NovationRGBDevice{TDeviceInfo}"/> class.
/// </summary>
public abstract class NovationRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceInfo>, INovationRGBDevice
where TDeviceInfo : NovationRGBDeviceInfo
{
#region Constructors
/// <param name="info">The generic information provided by Novation for the device.</param>
/// <param name="updateTrigger">The update trigger used to update this device.</param>
protected NovationRGBDevice(TDeviceInfo info, IDeviceUpdateTrigger updateTrigger)
: base(info, GetUpdateQueue(updateTrigger, info))
{ }
/// <summary>
/// Initializes a new instance of the <see cref="NovationRGBDevice{TDeviceInfo}"/> class.
/// </summary>
/// <param name="info">The generic information provided by Novation for the device.</param>
/// <param name="updateTrigger">The update trigger used to update this device.</param>
protected NovationRGBDevice(TDeviceInfo info, IDeviceUpdateTrigger updateTrigger)
: base(info, GetUpdateQueue(updateTrigger, info))
{ }
#endregion
#endregion
#region Methods
#region Methods
private static UpdateQueue GetUpdateQueue(IDeviceUpdateTrigger updateTrigger, TDeviceInfo info) =>
info.ColorCapabilities switch
{
NovationColorCapabilities.LimitedRG => new LimitedColorUpdateQueue(updateTrigger, info.DeviceId),
NovationColorCapabilities.RGB => new RGBColorUpdateQueue(updateTrigger, info.DeviceId),
_ => throw new ArgumentOutOfRangeException()
};
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate));
/// <summary>
/// Resets the <see cref="NovationRGBDevice{TDeviceInfo}"/> back to default.
/// </summary>
public virtual void Reset() => UpdateQueue.Reset();
/// <inheritdoc cref="IDisposable.Dispose" />
/// <inheritdoc cref="AbstractRGBDevice{TDeviceInfo}.Dispose" />
public override void Dispose()
private static UpdateQueue GetUpdateQueue(IDeviceUpdateTrigger updateTrigger, TDeviceInfo info) =>
info.ColorCapabilities switch
{
Reset();
NovationColorCapabilities.LimitedRG => new LimitedColorUpdateQueue(updateTrigger, info.DeviceId),
NovationColorCapabilities.RGB => new RGBColorUpdateQueue(updateTrigger, info.DeviceId),
_ => throw new ArgumentOutOfRangeException()
};
base.Dispose();
}
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate));
#endregion
/// <summary>
/// Resets the <see cref="NovationRGBDevice{TDeviceInfo}"/> back to default.
/// </summary>
public virtual void Reset() => UpdateQueue.Reset();
/// <inheritdoc cref="IDisposable.Dispose" />
/// <inheritdoc cref="AbstractRGBDevice{TDeviceInfo}.Dispose" />
public override void Dispose()
{
Reset();
base.Dispose();
}
}
#endregion
}
@@ -1,61 +1,60 @@
using RGB.NET.Core;
namespace RGB.NET.Devices.Novation
namespace RGB.NET.Devices.Novation;
/// <inheritdoc />
/// <summary>
/// Represents a generic information for a Corsair-<see cref="T:RGB.NET.Core.IRGBDevice" />.
/// </summary>
public class NovationRGBDeviceInfo : IRGBDeviceInfo
{
#region Properties & Fields
/// <inheritdoc />
public RGBDeviceType DeviceType { get; }
/// <inheritdoc />
public string DeviceName { get; }
/// <inheritdoc />
public string Manufacturer => "Novation";
/// <inheritdoc />
public string Model { get; }
/// <inheritdoc />
public object? LayoutMetadata { get; set; }
/// <summary>
/// Represents a generic information for a Corsair-<see cref="T:RGB.NET.Core.IRGBDevice" />.
/// Gets the <see cref="NovationColorCapabilities"/> of the <see cref="IRGBDevice"/>.
/// </summary>
public class NovationRGBDeviceInfo : IRGBDeviceInfo
public NovationColorCapabilities ColorCapabilities { get; }
/// <summary>
/// Gets the (midi)-id of the <see cref="IRGBDevice"/>..
/// </summary>
public int DeviceId { get; }
#endregion
#region Constructors
/// <summary>
/// Internal constructor of managed <see cref="NovationRGBDeviceInfo"/>.
/// </summary>
/// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</param>
/// <param name="model">The represented device model.</param>
/// <param name="deviceId">The (midi)-id of the <see cref="IRGBDevice"/>.</param>
/// <param name="colorCapabilities">The <see cref="NovationColorCapabilities"/> of the <see cref="IRGBDevice"/>.</param>
internal NovationRGBDeviceInfo(RGBDeviceType deviceType, string model, int deviceId, NovationColorCapabilities colorCapabilities)
{
#region Properties & Fields
this.DeviceType = deviceType;
this.Model = model;
this.DeviceId = deviceId;
this.ColorCapabilities = colorCapabilities;
/// <inheritdoc />
public RGBDeviceType DeviceType { get; }
/// <inheritdoc />
public string DeviceName { get; }
/// <inheritdoc />
public string Manufacturer => "Novation";
/// <inheritdoc />
public string Model { get; }
/// <inheritdoc />
public object? LayoutMetadata { get; set; }
/// <summary>
/// Gets the <see cref="NovationColorCapabilities"/> of the <see cref="IRGBDevice"/>.
/// </summary>
public NovationColorCapabilities ColorCapabilities { get; }
/// <summary>
/// Gets the (midi)-id of the <see cref="IRGBDevice"/>..
/// </summary>
public int DeviceId { get; }
#endregion
#region Constructors
/// <summary>
/// Internal constructor of managed <see cref="NovationRGBDeviceInfo"/>.
/// </summary>
/// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</param>
/// <param name="model">The represented device model.</param>
/// <param name="deviceId">The (midi)-id of the <see cref="IRGBDevice"/>.</param>
/// <param name="colorCapabilities">The <see cref="NovationColorCapabilities"/> of the <see cref="IRGBDevice"/>.</param>
internal NovationRGBDeviceInfo(RGBDeviceType deviceType, string model, int deviceId, NovationColorCapabilities colorCapabilities)
{
this.DeviceType = deviceType;
this.Model = model;
this.DeviceId = deviceId;
this.ColorCapabilities = colorCapabilities;
DeviceName = DeviceHelper.CreateDeviceName(Manufacturer, Model);
}
#endregion
DeviceName = DeviceHelper.CreateDeviceName(Manufacturer, Model);
}
}
#endregion
}
@@ -2,193 +2,192 @@
using RGB.NET.Core;
using Sanford.Multimedia.Midi;
namespace RGB.NET.Devices.Novation
namespace RGB.NET.Devices.Novation;
/// <summary>
/// Represents the update-queue performing updates for a RGB-color novation device.
/// </summary>
public class RGBColorUpdateQueue : MidiUpdateQueue
{
/// <summary>
/// Represents the update-queue performing updates for a RGB-color novation device.
/// </summary>
public class RGBColorUpdateQueue : MidiUpdateQueue
#region Properties & Fields
private static readonly (Color, int)[] COLOR_PALETTE =
{
#region Properties & Fields
(new Color(0, 0, 0), 0),
(new Color(28, 28, 28), 1),
(new Color(124, 124, 124), 2),
(new Color(252, 252, 252), 3),
(new Color(255, 77, 71), 4),
(new Color(255, 10, 0), 5),
(new Color(90, 1, 0), 6),
(new Color(25, 0, 0), 7),
(new Color(255, 189, 98), 8),
(new Color(255, 86, 0), 9),
(new Color(90, 29, 0), 10),
(new Color(36, 24, 0), 11),
(new Color(253, 253, 33), 12),
(new Color(253, 253, 0), 13),
(new Color(88, 88, 0), 14),
(new Color(24, 24, 0), 15),
(new Color(128, 253, 42), 16),
(new Color(64, 253, 0), 17),
(new Color(22, 88, 0), 18),
(new Color(19, 40, 0), 19),
(new Color(52, 253, 43), 20),
(new Color(0, 253, 0), 21),
(new Color(0, 88, 0), 22),
(new Color(0, 24, 0), 23),
(new Color(51, 253, 70), 24),
(new Color(50, 253, 126), 28),
(new Color(0, 253, 58), 29),
(new Color(0, 88, 20), 30),
(new Color(0, 28, 15), 31),
(new Color(47, 252, 176), 32),
(new Color(0, 252, 145), 33),
(new Color(0, 88, 49), 34),
(new Color(0, 24, 15), 35),
(new Color(57, 191, 255), 36),
(new Color(0, 167, 255), 37),
(new Color(0, 64, 81), 38),
(new Color(0, 16, 24), 39),
(new Color(65, 134, 255), 40),
(new Color(0, 80, 255), 41),
(new Color(0, 26, 90), 42),
(new Color(0, 7, 25), 43),
(new Color(70, 71, 255), 44),
(new Color(0, 0, 255), 45),
(new Color(0, 0, 91), 46),
(new Color(0, 0, 25), 47),
(new Color(131, 71, 255), 48),
(new Color(80, 0, 255), 49),
(new Color(22, 0, 103), 50),
(new Color(11, 0, 50), 51),
(new Color(255, 73, 255), 52),
(new Color(255, 0, 255), 53),
(new Color(90, 0, 90), 54),
(new Color(25, 0, 25), 55),
(new Color(255, 77, 132), 56),
(new Color(255, 7, 82), 57),
(new Color(90, 1, 27), 58),
(new Color(33, 0, 16), 59),
(new Color(255, 25, 0), 60),
(new Color(155, 53, 0), 61),
(new Color(122, 81, 0), 62),
(new Color(62, 100, 0), 63),
(new Color(0, 56, 0), 64),
(new Color(0, 84, 50), 65),
(new Color(0, 83, 126), 66),
(new Color(0, 68, 77), 68),
(new Color(27, 0, 210), 69),
(new Color(32, 32, 32), 71),
(new Color(186, 253, 0), 73),
(new Color(170, 237, 0), 74),
(new Color(86, 253, 0), 75),
(new Color(0, 136, 0), 76),
(new Color(0, 252, 122), 77),
(new Color(0, 27, 255), 79),
(new Color(53, 0, 255), 80),
(new Color(119, 0, 255), 81),
(new Color(180, 23, 126), 82),
(new Color(65, 32, 0), 83),
(new Color(255, 74, 0), 84),
(new Color(131, 225, 0), 85),
(new Color(101, 253, 0), 86),
(new Color(69, 253, 97), 89),
(new Color(0, 252, 202), 90),
(new Color(80, 134, 255), 91),
(new Color(39, 77, 201), 92),
(new Color(130, 122, 237), 93),
(new Color(211, 12, 255), 94),
(new Color(255, 6, 90), 95),
(new Color(255, 125, 0), 96),
(new Color(185, 177, 0), 97),
(new Color(138, 253, 0), 98),
(new Color(130, 93, 0), 99),
(new Color(57, 40, 0), 100),
(new Color(13, 76, 5), 101),
(new Color(0, 80, 55), 102),
(new Color(19, 19, 41), 103),
(new Color(16, 31, 90), 104),
(new Color(106, 60, 23), 105),
(new Color(172, 4, 0), 106),
(new Color(225, 81, 53), 107),
(new Color(220, 105, 0), 108),
(new Color(255, 255, 0), 109),
(new Color(153, 225, 0), 110),
(new Color(95, 181, 0), 111),
(new Color(27, 27, 49), 112),
(new Color(220, 253, 84), 113),
(new Color(118, 252, 184), 114),
(new Color(150, 151, 255), 115),
(new Color(139, 97, 255), 116),
(new Color(64, 64, 64), 117),
(new Color(116, 116, 116), 118),
(new Color(222, 252, 252), 119),
(new Color(164, 4, 0), 120),
(new Color(53, 0, 0), 121),
(new Color(0, 209, 0), 122),
(new Color(0, 64, 0), 123),
(new Color(61, 48, 0), 125),
(new Color(180, 93, 0), 126),
(new Color(74, 20, 0), 127),
};
private static readonly (Color, int)[] COLOR_PALETTE =
{
(new Color(0, 0, 0), 0),
(new Color(28, 28, 28), 1),
(new Color(124, 124, 124), 2),
(new Color(252, 252, 252), 3),
(new Color(255, 77, 71), 4),
(new Color(255, 10, 0), 5),
(new Color(90, 1, 0), 6),
(new Color(25, 0, 0), 7),
(new Color(255, 189, 98), 8),
(new Color(255, 86, 0), 9),
(new Color(90, 29, 0), 10),
(new Color(36, 24, 0), 11),
(new Color(253, 253, 33), 12),
(new Color(253, 253, 0), 13),
(new Color(88, 88, 0), 14),
(new Color(24, 24, 0), 15),
(new Color(128, 253, 42), 16),
(new Color(64, 253, 0), 17),
(new Color(22, 88, 0), 18),
(new Color(19, 40, 0), 19),
(new Color(52, 253, 43), 20),
(new Color(0, 253, 0), 21),
(new Color(0, 88, 0), 22),
(new Color(0, 24, 0), 23),
(new Color(51, 253, 70), 24),
(new Color(50, 253, 126), 28),
(new Color(0, 253, 58), 29),
(new Color(0, 88, 20), 30),
(new Color(0, 28, 15), 31),
(new Color(47, 252, 176), 32),
(new Color(0, 252, 145), 33),
(new Color(0, 88, 49), 34),
(new Color(0, 24, 15), 35),
(new Color(57, 191, 255), 36),
(new Color(0, 167, 255), 37),
(new Color(0, 64, 81), 38),
(new Color(0, 16, 24), 39),
(new Color(65, 134, 255), 40),
(new Color(0, 80, 255), 41),
(new Color(0, 26, 90), 42),
(new Color(0, 7, 25), 43),
(new Color(70, 71, 255), 44),
(new Color(0, 0, 255), 45),
(new Color(0, 0, 91), 46),
(new Color(0, 0, 25), 47),
(new Color(131, 71, 255), 48),
(new Color(80, 0, 255), 49),
(new Color(22, 0, 103), 50),
(new Color(11, 0, 50), 51),
(new Color(255, 73, 255), 52),
(new Color(255, 0, 255), 53),
(new Color(90, 0, 90), 54),
(new Color(25, 0, 25), 55),
(new Color(255, 77, 132), 56),
(new Color(255, 7, 82), 57),
(new Color(90, 1, 27), 58),
(new Color(33, 0, 16), 59),
(new Color(255, 25, 0), 60),
(new Color(155, 53, 0), 61),
(new Color(122, 81, 0), 62),
(new Color(62, 100, 0), 63),
(new Color(0, 56, 0), 64),
(new Color(0, 84, 50), 65),
(new Color(0, 83, 126), 66),
(new Color(0, 68, 77), 68),
(new Color(27, 0, 210), 69),
(new Color(32, 32, 32), 71),
(new Color(186, 253, 0), 73),
(new Color(170, 237, 0), 74),
(new Color(86, 253, 0), 75),
(new Color(0, 136, 0), 76),
(new Color(0, 252, 122), 77),
(new Color(0, 27, 255), 79),
(new Color(53, 0, 255), 80),
(new Color(119, 0, 255), 81),
(new Color(180, 23, 126), 82),
(new Color(65, 32, 0), 83),
(new Color(255, 74, 0), 84),
(new Color(131, 225, 0), 85),
(new Color(101, 253, 0), 86),
(new Color(69, 253, 97), 89),
(new Color(0, 252, 202), 90),
(new Color(80, 134, 255), 91),
(new Color(39, 77, 201), 92),
(new Color(130, 122, 237), 93),
(new Color(211, 12, 255), 94),
(new Color(255, 6, 90), 95),
(new Color(255, 125, 0), 96),
(new Color(185, 177, 0), 97),
(new Color(138, 253, 0), 98),
(new Color(130, 93, 0), 99),
(new Color(57, 40, 0), 100),
(new Color(13, 76, 5), 101),
(new Color(0, 80, 55), 102),
(new Color(19, 19, 41), 103),
(new Color(16, 31, 90), 104),
(new Color(106, 60, 23), 105),
(new Color(172, 4, 0), 106),
(new Color(225, 81, 53), 107),
(new Color(220, 105, 0), 108),
(new Color(255, 255, 0), 109),
(new Color(153, 225, 0), 110),
(new Color(95, 181, 0), 111),
(new Color(27, 27, 49), 112),
(new Color(220, 253, 84), 113),
(new Color(118, 252, 184), 114),
(new Color(150, 151, 255), 115),
(new Color(139, 97, 255), 116),
(new Color(64, 64, 64), 117),
(new Color(116, 116, 116), 118),
(new Color(222, 252, 252), 119),
(new Color(164, 4, 0), 120),
(new Color(53, 0, 0), 121),
(new Color(0, 209, 0), 122),
(new Color(0, 64, 0), 123),
(new Color(61, 48, 0), 125),
(new Color(180, 93, 0), 126),
(new Color(74, 20, 0), 127),
};
#endregion
#endregion
#region Constructors
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="RGBColorUpdateQueue"/> class.
/// </summary>
/// <param name="updateTrigger">The update trigger used by this queue.</param>
/// <param name="deviceId">The device-id of the device this queue is performing updates for.</param>
public RGBColorUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceId)
: base(updateTrigger, deviceId)
{ }
/// <summary>
/// Initializes a new instance of the <see cref="RGBColorUpdateQueue"/> class.
/// </summary>
/// <param name="updateTrigger">The update trigger used by this queue.</param>
/// <param name="deviceId">The device-id of the device this queue is performing updates for.</param>
public RGBColorUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceId)
: base(updateTrigger, deviceId)
{ }
#endregion
#endregion
#region Methods
#region Methods
/// <inheritdoc />
protected override ShortMessage? CreateMessage(object key, in Color color)
{
(byte mode, byte id) = ((byte, byte))key;
if (mode == 0x00) return null;
/// <inheritdoc />
protected override ShortMessage? CreateMessage(object key, in Color color)
{
(byte mode, byte id) = ((byte, byte))key;
if (mode == 0x00) return null;
return new ShortMessage(mode, id, Convert.ToByte(ConvertColor(color)));
}
/// <summary>
/// Convert a <see cref="Color"/> to its novation-representation depending on the <see cref="NovationColorCapabilities"/> of the <see cref="NovationRGBDevice{TDeviceInfo}"/>.
/// Source: http://www.launchpadfun.com/downloads_de/velocity-colors/
/// </summary>
/// <param name="color">The <see cref="Color"/> to convert.</param>
/// <returns>The novation-representation of the <see cref="Color"/>.</returns>
protected virtual int ConvertColor(in Color color)
{
int bestVelocity = 0;
double bestMatchDistance = double.MaxValue;
foreach ((Color c, int velocity) in COLOR_PALETTE)
{
double distance = c.DistanceTo(color);
if (distance < bestMatchDistance)
{
bestVelocity = velocity;
bestMatchDistance = distance;
}
}
return bestVelocity;
}
/// <inheritdoc />
public override void Reset()
{
base.Reset();
SendMessage(new ShortMessage(Convert.ToByte(0xB0), Convert.ToByte(0), Convert.ToByte(0)));
}
#endregion
return new ShortMessage(mode, id, Convert.ToByte(ConvertColor(color)));
}
}
/// <summary>
/// Convert a <see cref="Color"/> to its novation-representation depending on the <see cref="NovationColorCapabilities"/> of the <see cref="NovationRGBDevice{TDeviceInfo}"/>.
/// Source: http://www.launchpadfun.com/downloads_de/velocity-colors/
/// </summary>
/// <param name="color">The <see cref="Color"/> to convert.</param>
/// <returns>The novation-representation of the <see cref="Color"/>.</returns>
protected virtual int ConvertColor(in Color color)
{
int bestVelocity = 0;
double bestMatchDistance = double.MaxValue;
foreach ((Color c, int velocity) in COLOR_PALETTE)
{
double distance = c.DistanceTo(color);
if (distance < bestMatchDistance)
{
bestVelocity = velocity;
bestMatchDistance = distance;
}
}
return bestVelocity;
}
/// <inheritdoc />
public override void Reset()
{
base.Reset();
SendMessage(new ShortMessage(Convert.ToByte(0xB0), Convert.ToByte(0), Convert.ToByte(0)));
}
#endregion
}