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,35 +1,34 @@
using System;
namespace RGB.NET.Devices.Novation.Attributes
namespace RGB.NET.Devices.Novation.Attributes;
/// <inheritdoc />
/// <summary>
/// Specifies the color-capability of a field.
/// </summary>
[AttributeUsage(AttributeTargets.Field)]
public class ColorCapabilityAttribute : Attribute
{
#region Properties & Fields
/// <summary>
/// Gets the Id.
/// </summary>
public NovationColorCapabilities Capability { get; }
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Specifies the color-capability of a field.
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Novation.Attributes.ColorCapabilityAttribute" /> class.
/// </summary>
[AttributeUsage(AttributeTargets.Field)]
public class ColorCapabilityAttribute : Attribute
/// <param name="capability">The capability.</param>
public ColorCapabilityAttribute(NovationColorCapabilities capability)
{
#region Properties & Fields
/// <summary>
/// Gets the Id.
/// </summary>
public NovationColorCapabilities Capability { get; }
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Novation.Attributes.ColorCapabilityAttribute" /> class.
/// </summary>
/// <param name="capability">The capability.</param>
public ColorCapabilityAttribute(NovationColorCapabilities capability)
{
this.Capability = capability;
}
#endregion
this.Capability = capability;
}
}
#endregion
}
@@ -1,35 +1,34 @@
using System;
namespace RGB.NET.Devices.Novation.Attributes
namespace RGB.NET.Devices.Novation.Attributes;
/// <inheritdoc />
/// <summary>
/// Specifies the device-id of a field.
/// </summary>
[AttributeUsage(AttributeTargets.Field)]
public class DeviceIdAttribute : Attribute
{
#region Properties & Fields
/// <summary>
/// Gets the Id.
/// </summary>
public string Id { get; }
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Specifies the device-id of a field.
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Novation.Attributes.DeviceIdAttribute" /> class.
/// </summary>
[AttributeUsage(AttributeTargets.Field)]
public class DeviceIdAttribute : Attribute
/// <param name="id">The id.</param>
public DeviceIdAttribute(string id)
{
#region Properties & Fields
/// <summary>
/// Gets the Id.
/// </summary>
public string Id { get; }
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Novation.Attributes.DeviceIdAttribute" /> class.
/// </summary>
/// <param name="id">The id.</param>
public DeviceIdAttribute(string id)
{
this.Id = id;
}
#endregion
this.Id = id;
}
}
#endregion
}
@@ -1,35 +1,34 @@
using System;
namespace RGB.NET.Devices.Novation.Attributes
namespace RGB.NET.Devices.Novation.Attributes;
/// <inheritdoc />
/// <summary>
/// Specifies the led id mapping of a field.
/// </summary>
[AttributeUsage(AttributeTargets.Field)]
internal class LedIdMappingAttribute : Attribute
{
#region Properties & Fields
/// <summary>
/// Gets the led id mapping.
/// </summary>
internal LedIdMappings LedIdMapping { get; }
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Specifies the led id mapping of a field.
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Novation.Attributes.LedIdMappingAttribute" /> class.
/// </summary>
[AttributeUsage(AttributeTargets.Field)]
internal class LedIdMappingAttribute : Attribute
/// <param name="ledIdMapping">The led id mapping.</param>
internal LedIdMappingAttribute(LedIdMappings ledIdMapping)
{
#region Properties & Fields
/// <summary>
/// Gets the led id mapping.
/// </summary>
internal LedIdMappings LedIdMapping { get; }
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Novation.Attributes.LedIdMappingAttribute" /> class.
/// </summary>
/// <param name="ledIdMapping">The led id mapping.</param>
internal LedIdMappingAttribute(LedIdMappings ledIdMapping)
{
this.LedIdMapping = ledIdMapping;
}
#endregion
this.LedIdMapping = ledIdMapping;
}
}
#endregion
}
@@ -2,15 +2,14 @@
// ReSharper disable InconsistentNaming
// ReSharper disable UnusedMember.Global
namespace RGB.NET.Devices.Novation
namespace RGB.NET.Devices.Novation;
/// <summary>
/// Represents the color-capabilities of a novation device.
/// </summary>
public enum NovationColorCapabilities
{
/// <summary>
/// Represents the color-capabilities of a novation device.
/// </summary>
public enum NovationColorCapabilities
{
None,
RGB,
LimitedRG
}
}
None,
RGB,
LimitedRG
}
@@ -4,26 +4,25 @@
using RGB.NET.Devices.Novation.Attributes;
namespace RGB.NET.Devices.Novation
namespace RGB.NET.Devices.Novation;
/// <summary>
/// Represents a specific novation device.
/// </summary>
public enum NovationDevices
{
/// <summary>
/// Represents a specific novation device.
/// </summary>
public enum NovationDevices
{
[DeviceId("Launchpad S")]
[ColorCapability(NovationColorCapabilities.LimitedRG)]
[LedIdMapping(LedIdMappings.Legacy)]
LaunchpadS,
[DeviceId("Launchpad S")]
[ColorCapability(NovationColorCapabilities.LimitedRG)]
[LedIdMapping(LedIdMappings.Legacy)]
LaunchpadS,
[DeviceId("Launchpad Mini")]
[ColorCapability(NovationColorCapabilities.LimitedRG)]
[LedIdMapping(LedIdMappings.Legacy)]
LaunchpadMini,
[DeviceId("Launchpad Mini")]
[ColorCapability(NovationColorCapabilities.LimitedRG)]
[LedIdMapping(LedIdMappings.Legacy)]
LaunchpadMini,
[DeviceId("Launchpad MK2")]
[ColorCapability(NovationColorCapabilities.RGB)]
[LedIdMapping(LedIdMappings.Current)]
LaunchpadMK2
}
}
[DeviceId("Launchpad MK2")]
[ColorCapability(NovationColorCapabilities.RGB)]
[LedIdMapping(LedIdMappings.Current)]
LaunchpadMK2
}
@@ -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
}
@@ -2,47 +2,46 @@
using System.Reflection;
using RGB.NET.Devices.Novation.Attributes;
namespace RGB.NET.Devices.Novation
namespace RGB.NET.Devices.Novation;
/// <summary>
/// Offers some extensions and helper-methods for enum related things.
/// </summary>
internal static class EnumExtension
{
/// <summary>
/// Offers some extensions and helper-methods for enum related things.
/// Gets the value of the <see cref="DeviceIdAttribute"/>.
/// </summary>
internal static class EnumExtension
/// <param name="source">The enum value to get the description from.</param>
/// <returns>The value of the <see cref="DeviceIdAttribute"/> of the source.</returns>
internal static string? GetDeviceId(this Enum source) => source.GetAttribute<DeviceIdAttribute>()?.Id;
/// <summary>
/// Gets the value of the <see cref="ColorCapabilityAttribute"/>.
/// </summary>
/// <param name="source">The enum value to get the description from.</param>
/// <returns>The value of the <see cref="ColorCapabilityAttribute"/> of the source.</returns>
internal static NovationColorCapabilities GetColorCapability(this Enum source) => source.GetAttribute<ColorCapabilityAttribute>()?.Capability ?? NovationColorCapabilities.None;
/// <summary>
/// Gets the value of the <see cref="LedIdMappingAttribute"/>.
/// </summary>
/// <param name="source">The enum value to get the description from.</param>
/// <returns>The value of the <see cref="LedIdMappingAttribute"/> of the source.</returns>
internal static LedIdMappings GetLedIdMapping(this Enum source) => source.GetAttribute<LedIdMappingAttribute>()?.LedIdMapping ?? LedIdMappings.Current;
/// <summary>
/// Gets the attribute of type T.
/// </summary>
/// <param name="source">The enum value to get the attribute from</param>
/// <typeparam name="T">The generic attribute type</typeparam>
/// <returns>The <see cref="Attribute"/>.</returns>
private static T? GetAttribute<T>(this Enum source)
where T : Attribute
{
/// <summary>
/// Gets the value of the <see cref="DeviceIdAttribute"/>.
/// </summary>
/// <param name="source">The enum value to get the description from.</param>
/// <returns>The value of the <see cref="DeviceIdAttribute"/> of the source.</returns>
internal static string? GetDeviceId(this Enum source) => source.GetAttribute<DeviceIdAttribute>()?.Id;
/// <summary>
/// Gets the value of the <see cref="ColorCapabilityAttribute"/>.
/// </summary>
/// <param name="source">The enum value to get the description from.</param>
/// <returns>The value of the <see cref="ColorCapabilityAttribute"/> of the source.</returns>
internal static NovationColorCapabilities GetColorCapability(this Enum source) => source.GetAttribute<ColorCapabilityAttribute>()?.Capability ?? NovationColorCapabilities.None;
/// <summary>
/// Gets the value of the <see cref="LedIdMappingAttribute"/>.
/// </summary>
/// <param name="source">The enum value to get the description from.</param>
/// <returns>The value of the <see cref="LedIdMappingAttribute"/> of the source.</returns>
internal static LedIdMappings GetLedIdMapping(this Enum source) => source.GetAttribute<LedIdMappingAttribute>()?.LedIdMapping ?? LedIdMappings.Current;
/// <summary>
/// Gets the attribute of type T.
/// </summary>
/// <param name="source">The enum value to get the attribute from</param>
/// <typeparam name="T">The generic attribute type</typeparam>
/// <returns>The <see cref="Attribute"/>.</returns>
private static T? GetAttribute<T>(this Enum source)
where T : Attribute
{
FieldInfo? fi = source.GetType().GetField(source.ToString());
if (fi == null) return null;
T[] attributes = (T[])fi.GetCustomAttributes(typeof(T), false);
return attributes.Length > 0 ? attributes[0] : null;
}
FieldInfo? fi = source.GetType().GetField(source.ToString());
if (fi == null) return null;
T[] attributes = (T[])fi.GetCustomAttributes(typeof(T), false);
return attributes.Length > 0 ? attributes[0] : null;
}
}
}
@@ -1,100 +1,100 @@
using System.Collections.Generic;
using RGB.NET.Core;
namespace RGB.NET.Devices.Novation
namespace RGB.NET.Devices.Novation;
internal static class LaunchpadIdMapping
{
internal static class LaunchpadIdMapping
{
internal static readonly Dictionary<LedId, (byte mode, byte id, int x, int y)> LEGACY = new()
{
{ LedId.Invalid, (0x00, 0xFF, 8, 0) },
internal static readonly Dictionary<LedId, (byte mode, byte id, int x, int y)> LEGACY = new()
{
{ LedId.Invalid, (0x00, 0xFF, 8, 0) },
{ LedId.LedMatrix1, (0x90, 0x00, 0, 1) },
{ LedId.LedMatrix2, (0x90, 0x01, 1, 1) },
{ LedId.LedMatrix3, (0x90, 0x02, 2, 1) },
{ LedId.LedMatrix4, (0x90, 0x03, 3, 1) },
{ LedId.LedMatrix5, (0x90, 0x04, 4, 1) },
{ LedId.LedMatrix6, (0x90, 0x05, 5, 1) },
{ LedId.LedMatrix7, (0x90, 0x06, 6, 1) },
{ LedId.LedMatrix8, (0x90, 0x07, 7, 1) },
{ LedId.LedMatrix9, (0x90, 0x10, 0, 2) },
{ LedId.LedMatrix10, (0x90, 0x11, 1, 2) },
{ LedId.LedMatrix11, (0x90, 0x12, 2, 2) },
{ LedId.LedMatrix12, (0x90, 0x13, 3, 2) },
{ LedId.LedMatrix13, (0x90, 0x14, 4, 2) },
{ LedId.LedMatrix14, (0x90, 0x15, 5, 2) },
{ LedId.LedMatrix15, (0x90, 0x16, 6, 2) },
{ LedId.LedMatrix16, (0x90, 0x17, 7, 2) },
{ LedId.LedMatrix17, (0x90, 0x20, 0, 3) },
{ LedId.LedMatrix18, (0x90, 0x21, 1, 3) },
{ LedId.LedMatrix19, (0x90, 0x22, 2, 3) },
{ LedId.LedMatrix20, (0x90, 0x23, 3, 3) },
{ LedId.LedMatrix21, (0x90, 0x24, 4, 3) },
{ LedId.LedMatrix22, (0x90, 0x25, 5, 3) },
{ LedId.LedMatrix23, (0x90, 0x26, 6, 3) },
{ LedId.LedMatrix24, (0x90, 0x27, 7, 3) },
{ LedId.LedMatrix25, (0x90, 0x30, 0, 4) },
{ LedId.LedMatrix26, (0x90, 0x31, 1, 4) },
{ LedId.LedMatrix27, (0x90, 0x32, 2, 4) },
{ LedId.LedMatrix28, (0x90, 0x33, 3, 4) },
{ LedId.LedMatrix29, (0x90, 0x34, 4, 4) },
{ LedId.LedMatrix30, (0x90, 0x35, 5, 4) },
{ LedId.LedMatrix31, (0x90, 0x36, 6, 4) },
{ LedId.LedMatrix32, (0x90, 0x37, 7, 4) },
{ LedId.LedMatrix33, (0x90, 0x40, 0, 5) },
{ LedId.LedMatrix34, (0x90, 0x41, 1, 5) },
{ LedId.LedMatrix35, (0x90, 0x42, 2, 5) },
{ LedId.LedMatrix36, (0x90, 0x43, 3, 5) },
{ LedId.LedMatrix37, (0x90, 0x44, 4, 5) },
{ LedId.LedMatrix38, (0x90, 0x45, 5, 5) },
{ LedId.LedMatrix39, (0x90, 0x46, 6, 5) },
{ LedId.LedMatrix40, (0x90, 0x47, 7, 5) },
{ LedId.LedMatrix41, (0x90, 0x50, 0, 6) },
{ LedId.LedMatrix42, (0x90, 0x51, 1, 6) },
{ LedId.LedMatrix43, (0x90, 0x52, 2, 6) },
{ LedId.LedMatrix44, (0x90, 0x53, 3, 6) },
{ LedId.LedMatrix45, (0x90, 0x54, 4, 6) },
{ LedId.LedMatrix46, (0x90, 0x55, 5, 6) },
{ LedId.LedMatrix47, (0x90, 0x56, 6, 6) },
{ LedId.LedMatrix48, (0x90, 0x57, 7, 6) },
{ LedId.LedMatrix49, (0x90, 0x60, 0, 7) },
{ LedId.LedMatrix50, (0x90, 0x61, 1, 7) },
{ LedId.LedMatrix51, (0x90, 0x62, 2, 7) },
{ LedId.LedMatrix52, (0x90, 0x63, 3, 7) },
{ LedId.LedMatrix53, (0x90, 0x64, 4, 7) },
{ LedId.LedMatrix54, (0x90, 0x65, 5, 7) },
{ LedId.LedMatrix55, (0x90, 0x66, 6, 7) },
{ LedId.LedMatrix56, (0x90, 0x67, 7, 7) },
{ LedId.LedMatrix57, (0x90, 0x70, 0, 8) },
{ LedId.LedMatrix58, (0x90, 0x71, 1, 8) },
{ LedId.LedMatrix59, (0x90, 0x72, 2, 8) },
{ LedId.LedMatrix60, (0x90, 0x73, 3, 8) },
{ LedId.LedMatrix61, (0x90, 0x74, 4, 8) },
{ LedId.LedMatrix62, (0x90, 0x75, 5, 8) },
{ LedId.LedMatrix63, (0x90, 0x76, 6, 8) },
{ LedId.LedMatrix64, (0x90, 0x77, 7, 8) },
{ LedId.LedMatrix1, (0x90, 0x00, 0, 1) },
{ LedId.LedMatrix2, (0x90, 0x01, 1, 1) },
{ LedId.LedMatrix3, (0x90, 0x02, 2, 1) },
{ LedId.LedMatrix4, (0x90, 0x03, 3, 1) },
{ LedId.LedMatrix5, (0x90, 0x04, 4, 1) },
{ LedId.LedMatrix6, (0x90, 0x05, 5, 1) },
{ LedId.LedMatrix7, (0x90, 0x06, 6, 1) },
{ LedId.LedMatrix8, (0x90, 0x07, 7, 1) },
{ LedId.LedMatrix9, (0x90, 0x10, 0, 2) },
{ LedId.LedMatrix10, (0x90, 0x11, 1, 2) },
{ LedId.LedMatrix11, (0x90, 0x12, 2, 2) },
{ LedId.LedMatrix12, (0x90, 0x13, 3, 2) },
{ LedId.LedMatrix13, (0x90, 0x14, 4, 2) },
{ LedId.LedMatrix14, (0x90, 0x15, 5, 2) },
{ LedId.LedMatrix15, (0x90, 0x16, 6, 2) },
{ LedId.LedMatrix16, (0x90, 0x17, 7, 2) },
{ LedId.LedMatrix17, (0x90, 0x20, 0, 3) },
{ LedId.LedMatrix18, (0x90, 0x21, 1, 3) },
{ LedId.LedMatrix19, (0x90, 0x22, 2, 3) },
{ LedId.LedMatrix20, (0x90, 0x23, 3, 3) },
{ LedId.LedMatrix21, (0x90, 0x24, 4, 3) },
{ LedId.LedMatrix22, (0x90, 0x25, 5, 3) },
{ LedId.LedMatrix23, (0x90, 0x26, 6, 3) },
{ LedId.LedMatrix24, (0x90, 0x27, 7, 3) },
{ LedId.LedMatrix25, (0x90, 0x30, 0, 4) },
{ LedId.LedMatrix26, (0x90, 0x31, 1, 4) },
{ LedId.LedMatrix27, (0x90, 0x32, 2, 4) },
{ LedId.LedMatrix28, (0x90, 0x33, 3, 4) },
{ LedId.LedMatrix29, (0x90, 0x34, 4, 4) },
{ LedId.LedMatrix30, (0x90, 0x35, 5, 4) },
{ LedId.LedMatrix31, (0x90, 0x36, 6, 4) },
{ LedId.LedMatrix32, (0x90, 0x37, 7, 4) },
{ LedId.LedMatrix33, (0x90, 0x40, 0, 5) },
{ LedId.LedMatrix34, (0x90, 0x41, 1, 5) },
{ LedId.LedMatrix35, (0x90, 0x42, 2, 5) },
{ LedId.LedMatrix36, (0x90, 0x43, 3, 5) },
{ LedId.LedMatrix37, (0x90, 0x44, 4, 5) },
{ LedId.LedMatrix38, (0x90, 0x45, 5, 5) },
{ LedId.LedMatrix39, (0x90, 0x46, 6, 5) },
{ LedId.LedMatrix40, (0x90, 0x47, 7, 5) },
{ LedId.LedMatrix41, (0x90, 0x50, 0, 6) },
{ LedId.LedMatrix42, (0x90, 0x51, 1, 6) },
{ LedId.LedMatrix43, (0x90, 0x52, 2, 6) },
{ LedId.LedMatrix44, (0x90, 0x53, 3, 6) },
{ LedId.LedMatrix45, (0x90, 0x54, 4, 6) },
{ LedId.LedMatrix46, (0x90, 0x55, 5, 6) },
{ LedId.LedMatrix47, (0x90, 0x56, 6, 6) },
{ LedId.LedMatrix48, (0x90, 0x57, 7, 6) },
{ LedId.LedMatrix49, (0x90, 0x60, 0, 7) },
{ LedId.LedMatrix50, (0x90, 0x61, 1, 7) },
{ LedId.LedMatrix51, (0x90, 0x62, 2, 7) },
{ LedId.LedMatrix52, (0x90, 0x63, 3, 7) },
{ LedId.LedMatrix53, (0x90, 0x64, 4, 7) },
{ LedId.LedMatrix54, (0x90, 0x65, 5, 7) },
{ LedId.LedMatrix55, (0x90, 0x66, 6, 7) },
{ LedId.LedMatrix56, (0x90, 0x67, 7, 7) },
{ LedId.LedMatrix57, (0x90, 0x70, 0, 8) },
{ LedId.LedMatrix58, (0x90, 0x71, 1, 8) },
{ LedId.LedMatrix59, (0x90, 0x72, 2, 8) },
{ LedId.LedMatrix60, (0x90, 0x73, 3, 8) },
{ LedId.LedMatrix61, (0x90, 0x74, 4, 8) },
{ LedId.LedMatrix62, (0x90, 0x75, 5, 8) },
{ LedId.LedMatrix63, (0x90, 0x76, 6, 8) },
{ LedId.LedMatrix64, (0x90, 0x77, 7, 8) },
{ LedId.Custom1, (0xB0, 0x68, 0, 0) }, // Up
{ LedId.Custom2, (0xB0, 0x69, 1, 0) }, // Down
{ LedId.Custom3, (0xB0, 0x6A, 2, 0) }, // Left
{ LedId.Custom4, (0xB0, 0x6B, 3, 0) }, // Right
{ LedId.Custom5, (0xB0, 0x6C, 4, 0) }, // Session
{ LedId.Custom6, (0xB0, 0x6D, 5, 0) }, // User 1
{ LedId.Custom7, (0xB0, 0x6E, 6, 0) }, // User 2
{ LedId.Custom8, (0xB0, 0x6F, 7, 0) }, // Mix
{ LedId.Custom1, (0xB0, 0x68, 0, 0) }, // Up
{ LedId.Custom2, (0xB0, 0x69, 1, 0) }, // Down
{ LedId.Custom3, (0xB0, 0x6A, 2, 0) }, // Left
{ LedId.Custom4, (0xB0, 0x6B, 3, 0) }, // Right
{ LedId.Custom5, (0xB0, 0x6C, 4, 0) }, // Session
{ LedId.Custom6, (0xB0, 0x6D, 5, 0) }, // User 1
{ LedId.Custom7, (0xB0, 0x6E, 6, 0) }, // User 2
{ LedId.Custom8, (0xB0, 0x6F, 7, 0) }, // Mix
{ LedId.Custom9, (0x90, 0x08, 8, 1) }, //Scene1
{ LedId.Custom10, (0x90, 0x18, 8, 2) }, //Scene2
{ LedId.Custom11, (0x90, 0x28, 8, 3) }, //Scene3
{ LedId.Custom12, (0x90, 0x38, 8, 4) }, //Scene4
{ LedId.Custom13, (0x90, 0x48, 8, 5) }, //Scene5
{ LedId.Custom14, (0x90, 0x58, 8, 6) }, //Scene6
{ LedId.Custom15, (0x90, 0x68, 8, 7) }, //Scene7
{ LedId.Custom16, (0x90, 0x78, 8, 8) }, //Scene8
};
{ LedId.Custom9, (0x90, 0x08, 8, 1) }, //Scene1
{ LedId.Custom10, (0x90, 0x18, 8, 2) }, //Scene2
{ LedId.Custom11, (0x90, 0x28, 8, 3) }, //Scene3
{ LedId.Custom12, (0x90, 0x38, 8, 4) }, //Scene4
{ LedId.Custom13, (0x90, 0x48, 8, 5) }, //Scene5
{ LedId.Custom14, (0x90, 0x58, 8, 6) }, //Scene6
{ LedId.Custom15, (0x90, 0x68, 8, 7) }, //Scene7
{ LedId.Custom16, (0x90, 0x78, 8, 8) }, //Scene8
};
internal static readonly Dictionary<LedId, (byte mode, byte id, int x, int y)> CURRENT = new()
{
internal static readonly Dictionary<LedId, (byte mode, byte id, int x, int y)> CURRENT = new()
{
{ LedId.Invalid, (0x00, 0xFF, 8, 0) },
{ LedId.LedMatrix1, (0x90, 81, 0, 1) },
@@ -180,5 +180,4 @@ namespace RGB.NET.Devices.Novation
{ LedId.Custom15, (0x90, 29, 8, 7) }, //Scene7
{ LedId.Custom16, (0x90, 19, 8, 8) }, //Scene8
};
}
}
}
@@ -1,8 +1,7 @@
namespace RGB.NET.Devices.Novation
namespace RGB.NET.Devices.Novation;
internal enum LedIdMappings
{
internal enum LedIdMappings
{
Current,
Legacy
}
}
Current,
Legacy
}
@@ -2,62 +2,61 @@
using System.Collections.Generic;
using RGB.NET.Core;
namespace RGB.NET.Devices.Novation
namespace RGB.NET.Devices.Novation;
/// <inheritdoc cref="NovationRGBDevice{TDeviceInfo}" />
/// <summary>
/// Represents a Novation launchpad.
/// </summary>
public class NovationLaunchpadRGBDevice : NovationRGBDevice<NovationLaunchpadRGBDeviceInfo>, ILedMatrix
{
/// <inheritdoc cref="NovationRGBDevice{TDeviceInfo}" />
#region Constructors
/// <inheritdoc />
/// <summary>
/// Represents a Novation launchpad.
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Novation.NovationLaunchpadRGBDevice" /> class.
/// </summary>
public class NovationLaunchpadRGBDevice : NovationRGBDevice<NovationLaunchpadRGBDeviceInfo>, ILedMatrix
/// <param name="info">The specific information provided by Novation for the launchpad</param>
/// <param name="updateTrigger">The update trigger used to update this device.</param>
internal NovationLaunchpadRGBDevice(NovationLaunchpadRGBDeviceInfo info, IDeviceUpdateTrigger updateTrigger)
: base(info, updateTrigger)
{
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Novation.NovationLaunchpadRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by Novation for the launchpad</param>
/// <param name="updateTrigger">The update trigger used to update this device.</param>
internal NovationLaunchpadRGBDevice(NovationLaunchpadRGBDeviceInfo info, IDeviceUpdateTrigger updateTrigger)
: base(info, updateTrigger)
{
InitializeLayout();
}
#endregion
#region Methods
private void InitializeLayout()
{
Dictionary<LedId, (byte mode, byte id, int x, int y)> mapping = GetDeviceMapping();
const int BUTTON_SIZE = 20;
foreach (LedId ledId in mapping.Keys)
{
(_, _, int x, int y) = mapping[ledId];
AddLed(ledId, new Point(BUTTON_SIZE * x, BUTTON_SIZE * y), new Size(BUTTON_SIZE));
}
}
/// <inheritdoc />
// ReSharper disable RedundantCast
protected override object GetLedCustomData(LedId ledId) => GetDeviceMapping().TryGetValue(ledId, out (byte mode, byte id, int _, int __) data) ? (data.mode, data.id) : ((byte)0x00, (byte)0x00);
// ReSharper restore RedundantCast
/// <summary>
/// Gets the mapping used to access the LEDs of the device based on <see cref="NovationLaunchpadRGBDeviceInfo.LedMapping"/>.
/// </summary>
/// <returns>The mapping of the device.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown if the value of <see cref="NovationLaunchpadRGBDeviceInfo.LedMapping"/> is not known.</exception>
protected virtual Dictionary<LedId, (byte mode, byte id, int x, int y)> GetDeviceMapping()
=> DeviceInfo.LedMapping switch
{
LedIdMappings.Current => LaunchpadIdMapping.CURRENT,
LedIdMappings.Legacy => LaunchpadIdMapping.LEGACY,
_ => throw new ArgumentOutOfRangeException()
};
#endregion
InitializeLayout();
}
#endregion
#region Methods
private void InitializeLayout()
{
Dictionary<LedId, (byte mode, byte id, int x, int y)> mapping = GetDeviceMapping();
const int BUTTON_SIZE = 20;
foreach (LedId ledId in mapping.Keys)
{
(_, _, int x, int y) = mapping[ledId];
AddLed(ledId, new Point(BUTTON_SIZE * x, BUTTON_SIZE * y), new Size(BUTTON_SIZE));
}
}
/// <inheritdoc />
// ReSharper disable RedundantCast
protected override object GetLedCustomData(LedId ledId) => GetDeviceMapping().TryGetValue(ledId, out (byte mode, byte id, int _, int __) data) ? (data.mode, data.id) : ((byte)0x00, (byte)0x00);
// ReSharper restore RedundantCast
/// <summary>
/// Gets the mapping used to access the LEDs of the device based on <see cref="NovationLaunchpadRGBDeviceInfo.LedMapping"/>.
/// </summary>
/// <returns>The mapping of the device.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown if the value of <see cref="NovationLaunchpadRGBDeviceInfo.LedMapping"/> is not known.</exception>
protected virtual Dictionary<LedId, (byte mode, byte id, int x, int y)> GetDeviceMapping()
=> DeviceInfo.LedMapping switch
{
LedIdMappings.Current => LaunchpadIdMapping.CURRENT,
LedIdMappings.Legacy => LaunchpadIdMapping.LEGACY,
_ => throw new ArgumentOutOfRangeException()
};
#endregion
}
@@ -1,35 +1,34 @@
using RGB.NET.Core;
namespace RGB.NET.Devices.Novation
namespace RGB.NET.Devices.Novation;
/// <inheritdoc />
/// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.Novation.NovationLaunchpadRGBDevice" />.
/// </summary>
public class NovationLaunchpadRGBDeviceInfo : NovationRGBDeviceInfo
{
#region Properties & Fields
internal LedIdMappings LedMapping { get; }
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.Novation.NovationLaunchpadRGBDevice" />.
/// Internal constructor of managed <see cref="T:RGB.NET.Devices.Novation.NovationLaunchpadRGBDeviceInfo" />.
/// </summary>
public class NovationLaunchpadRGBDeviceInfo : NovationRGBDeviceInfo
/// <param name="model">The represented device model.</param>
/// <param name="deviceId">The id of the device.</param>
/// <param name="colorCapabilities">The <see cref="T:RGB.NET.Devices.Novation.NovationColorCapabilities" /> of the <see cref="T:RGB.NET.Core.IRGBDevice" />.</param>
/// <param name="ledMapping">A mapping of leds this device is initialized with.</param>
internal NovationLaunchpadRGBDeviceInfo(string model, int deviceId, NovationColorCapabilities colorCapabilities, LedIdMappings ledMapping)
: base(RGBDeviceType.LedMatrix, model, deviceId, colorCapabilities)
{
#region Properties & Fields
internal LedIdMappings LedMapping { get; }
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Internal constructor of managed <see cref="T:RGB.NET.Devices.Novation.NovationLaunchpadRGBDeviceInfo" />.
/// </summary>
/// <param name="model">The represented device model.</param>
/// <param name="deviceId">The id of the device.</param>
/// <param name="colorCapabilities">The <see cref="T:RGB.NET.Devices.Novation.NovationColorCapabilities" /> of the <see cref="T:RGB.NET.Core.IRGBDevice" />.</param>
/// <param name="ledMapping">A mapping of leds this device is initialized with.</param>
internal NovationLaunchpadRGBDeviceInfo(string model, int deviceId, NovationColorCapabilities colorCapabilities, LedIdMappings ledMapping)
: base(RGBDeviceType.LedMatrix, model, deviceId, colorCapabilities)
{
this.LedMapping = ledMapping;
}
#endregion
this.LedMapping = ledMapping;
}
}
#endregion
}
@@ -7,64 +7,63 @@ using System.Linq;
using RGB.NET.Core;
using Sanford.Multimedia.Midi;
namespace RGB.NET.Devices.Novation
namespace RGB.NET.Devices.Novation;
/// <inheritdoc />
/// <summary>
/// Represents a device provider responsible for Novation devices.
/// </summary>
public class NovationDeviceProvider : AbstractRGBDeviceProvider
{
/// <inheritdoc />
#region Properties & Fields
private static NovationDeviceProvider? _instance;
/// <summary>
/// Represents a device provider responsible for Novation devices.
/// Gets the singleton <see cref="NovationDeviceProvider"/> instance.
/// </summary>
public class NovationDeviceProvider : AbstractRGBDeviceProvider
public static NovationDeviceProvider Instance => _instance ?? new NovationDeviceProvider();
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="NovationDeviceProvider"/> class.
/// </summary>
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
private NovationDeviceProvider()
{
#region Properties & Fields
private static NovationDeviceProvider? _instance;
/// <summary>
/// Gets the singleton <see cref="NovationDeviceProvider"/> instance.
/// </summary>
public static NovationDeviceProvider Instance => _instance ?? new NovationDeviceProvider();
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="NovationDeviceProvider"/> class.
/// </summary>
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
private NovationDeviceProvider()
{
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(NovationDeviceProvider)}");
_instance = this;
}
#endregion
#region Methods
/// <inheritdoc />
protected override void InitializeSDK() { }
/// <inheritdoc />
protected override IEnumerable<IRGBDevice> LoadDevices()
{
for (int index = 0; index < OutputDeviceBase.DeviceCount; index++)
{
MidiOutCaps outCaps = OutputDeviceBase.GetDeviceCapabilities(index);
if (outCaps.name == null) continue;
NovationDevices? deviceId = (NovationDevices?)Enum.GetValues(typeof(NovationDevices))
.Cast<Enum>()
.FirstOrDefault(x => x.GetDeviceId()?.ToUpperInvariant().Contains(outCaps.name.ToUpperInvariant()) ?? false);
if (deviceId == null) continue;
NovationColorCapabilities colorCapability = deviceId.GetColorCapability();
if (colorCapability == NovationColorCapabilities.None) continue;
yield return new NovationLaunchpadRGBDevice(new NovationLaunchpadRGBDeviceInfo(outCaps.name, index, colorCapability, deviceId.GetLedIdMapping()), GetUpdateTrigger());
}
}
#endregion
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(NovationDeviceProvider)}");
_instance = this;
}
}
#endregion
#region Methods
/// <inheritdoc />
protected override void InitializeSDK() { }
/// <inheritdoc />
protected override IEnumerable<IRGBDevice> LoadDevices()
{
for (int index = 0; index < OutputDeviceBase.DeviceCount; index++)
{
MidiOutCaps outCaps = OutputDeviceBase.GetDeviceCapabilities(index);
if (outCaps.name == null) continue;
NovationDevices? deviceId = (NovationDevices?)Enum.GetValues(typeof(NovationDevices))
.Cast<Enum>()
.FirstOrDefault(x => x.GetDeviceId()?.ToUpperInvariant().Contains(outCaps.name.ToUpperInvariant()) ?? false);
if (deviceId == null) continue;
NovationColorCapabilities colorCapability = deviceId.GetColorCapability();
if (colorCapability == NovationColorCapabilities.None) continue;
yield return new NovationLaunchpadRGBDevice(new NovationLaunchpadRGBDeviceInfo(outCaps.name, index, colorCapability, deviceId.GetLedIdMapping()), GetUpdateTrigger());
}
}
#endregion
}