diff --git a/RGB.NET.Core/Extensions/EnumExtensions.cs b/RGB.NET.Core/Extensions/EnumExtensions.cs
deleted file mode 100644
index 2122229..0000000
--- a/RGB.NET.Core/Extensions/EnumExtensions.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using System;
-using System.Linq;
-using System.Reflection;
-namespace RGB.NET.Core.Extensions
-{
- public static class EnumExtensions
- {
- ///
- /// A generic extension method that aids in reflecting
- /// and retrieving any attribute that is applied to an `Enum`.
- ///
- public static TAttribute GetAttribute(this Enum enumValue)
- where TAttribute : Attribute
- {
- return enumValue.GetType()
- .GetMember(enumValue.ToString())
- .First()
- .GetCustomAttribute();
- }
- }
-}
diff --git a/RGB.NET.Core/RGB.NET.Core.csproj b/RGB.NET.Core/RGB.NET.Core.csproj
index 5f6b550..f4cb0ae 100644
--- a/RGB.NET.Core/RGB.NET.Core.csproj
+++ b/RGB.NET.Core/RGB.NET.Core.csproj
@@ -54,7 +54,6 @@
-
diff --git a/RGB.NET.Devices.Novation/Attributes/DeviceIdAttribute.cs b/RGB.NET.Devices.Novation/Attributes/DeviceIdAttribute.cs
new file mode 100644
index 0000000..75a4066
--- /dev/null
+++ b/RGB.NET.Devices.Novation/Attributes/DeviceIdAttribute.cs
@@ -0,0 +1,33 @@
+using System;
+
+namespace RGB.NET.Devices.Novation.Attributes
+{
+ ///
+ /// Specifies the device-id of a field.
+ ///
+ [AttributeUsage(AttributeTargets.Field)]
+ public class DeviceIdAttribute : Attribute
+ {
+ #region Properties & Fields
+
+ ///
+ /// Gets the Id.
+ ///
+ public string Id { get; }
+
+ #endregion
+
+ #region Constructors
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The id.
+ public DeviceIdAttribute(string id)
+ {
+ this.Id = id;
+ }
+
+ #endregion
+ }
+}
diff --git a/RGB.NET.Devices.Novation/Enum/NovationDevices.cs b/RGB.NET.Devices.Novation/Enum/NovationDevices.cs
index a61474d..6a4f2b6 100644
--- a/RGB.NET.Devices.Novation/Enum/NovationDevices.cs
+++ b/RGB.NET.Devices.Novation/Enum/NovationDevices.cs
@@ -1,10 +1,17 @@
-using System.ComponentModel.DataAnnotations;
+#pragma warning disable 1591
+// ReSharper disable InconsistentNaming
+// ReSharper disable UnusedMember.Global
+
+using RGB.NET.Devices.Novation.Attributes;
namespace RGB.NET.Devices.Novation
{
+ ///
+ /// Represents a specific novation device.
+ ///
public enum NovationDevices
{
- [Display(Name = "Launchpad S")]
+ [DeviceId("Launchpad S")]
LaunchpadS
}
}
diff --git a/RGB.NET.Devices.Novation/Enum/NovationLedIds.cs b/RGB.NET.Devices.Novation/Enum/NovationLedIds.cs
index ad112db..4023634 100644
--- a/RGB.NET.Devices.Novation/Enum/NovationLedIds.cs
+++ b/RGB.NET.Devices.Novation/Enum/NovationLedIds.cs
@@ -1,4 +1,5 @@
// ReSharper disable InconsistentNaming
+// ReSharper disable UnusedMember.Global
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
diff --git a/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs b/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs
index c2b9a7c..cfde254 100644
--- a/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs
+++ b/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs
@@ -9,7 +9,7 @@ using Sanford.Multimedia.Midi;
namespace RGB.NET.Devices.Novation
{
///
- /// Represents a generic Novation-device. (keyboard, mouse, headset, mousepad).
+ /// Represents a generic Novation-device. (launchpad).
///
public abstract class NovationRGBDevice : AbstractRGBDevice
{
@@ -30,10 +30,11 @@ namespace RGB.NET.Devices.Novation
/// Initializes a new instance of the class.
///
/// The generic information provided by Novation for the device.
- protected NovationRGBDevice(IRGBDeviceInfo info)
+ protected NovationRGBDevice(NovationRGBDeviceInfo info)
{
this.DeviceInfo = info;
- _outputDevice = new OutputDevice(((NovationRGBDeviceInfo)DeviceInfo).DeviceId);
+
+ _outputDevice = new OutputDevice(info.DeviceId);
}
#endregion
@@ -139,9 +140,9 @@ namespace RGB.NET.Devices.Novation
{
color = 17;
- if(((led.Color.R > 127) && (led.Color.G < 127)) || ((led.Color.R < 127) && (led.Color.G > 127)))
+ if (((led.Color.R > 127) && (led.Color.G < 127)) || ((led.Color.R < 127) && (led.Color.G > 127)))
color = 34;
- if((led.Color.R > 127) && (led.Color.G > 127))
+ if ((led.Color.R > 127) && (led.Color.G > 127))
color = 51;
}
diff --git a/RGB.NET.Devices.Novation/Generic/NovationRGBDeviceInfo.cs b/RGB.NET.Devices.Novation/Generic/NovationRGBDeviceInfo.cs
index d95cb42..eecbeb7 100644
--- a/RGB.NET.Devices.Novation/Generic/NovationRGBDeviceInfo.cs
+++ b/RGB.NET.Devices.Novation/Generic/NovationRGBDeviceInfo.cs
@@ -25,7 +25,9 @@ namespace RGB.NET.Devices.Novation
///
public RGBDeviceLighting Lighting => RGBDeviceLighting.Key;
- ///
+ ///
+ /// Gets the (midi)-id of the ..
+ ///
public int DeviceId { get; }
#endregion
@@ -37,6 +39,7 @@ namespace RGB.NET.Devices.Novation
///
/// The type of the .
/// The represented device model.
+ /// The (midi)-id of the .
internal NovationRGBDeviceInfo(RGBDeviceType deviceType, string model, int deviceId)
{
this.DeviceType = deviceType;
diff --git a/RGB.NET.Devices.Novation/Helper/EnumExtension.cs b/RGB.NET.Devices.Novation/Helper/EnumExtension.cs
new file mode 100644
index 0000000..d5f3e2c
--- /dev/null
+++ b/RGB.NET.Devices.Novation/Helper/EnumExtension.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Reflection;
+using RGB.NET.Devices.Novation.Attributes;
+
+namespace RGB.NET.Devices.Novation
+{
+ ///
+ /// Offers some extensions and helper-methods for enum related things.
+ ///
+ internal static class EnumExtension
+ {
+ ///
+ /// Gets the value of the .
+ ///
+ /// The enum value to get the description from.
+ /// The value of the of the source.
+ internal static string GetDeviceId(this Enum source) => source.GetAttribute()?.Id;
+
+ ///
+ /// Gets the attribute of type T.
+ ///
+ /// The enum value to get the attribute from
+ /// The generic attribute type
+ /// The .
+ private static T GetAttribute(this Enum source)
+ where T : Attribute
+ {
+ FieldInfo fi = source.GetType().GetField(source.ToString());
+ T[] attributes = (T[])fi.GetCustomAttributes(typeof(T), false);
+ return attributes.Length > 0 ? attributes[0] : null;
+ }
+ }
+}
diff --git a/RGB.NET.Devices.Novation/Launchpad/NovationLaunchpadRGBDevice.cs b/RGB.NET.Devices.Novation/Launchpad/NovationLaunchpadRGBDevice.cs
index 8cc5435..7625423 100644
--- a/RGB.NET.Devices.Novation/Launchpad/NovationLaunchpadRGBDevice.cs
+++ b/RGB.NET.Devices.Novation/Launchpad/NovationLaunchpadRGBDevice.cs
@@ -1,6 +1,5 @@
using System;
using RGB.NET.Core;
-using Sanford.Multimedia.Midi;
namespace RGB.NET.Devices.Novation
{
@@ -38,8 +37,7 @@ namespace RGB.NET.Devices.Novation
protected override void InitializeLayout()
{
//TODO DarthAffe 15.08.2017: Check if all launchpads are using the same basic layout
- //TODO DarthAffe 15.08.2017: Measure button size
- const int BUTTON_SIZE = 16;
+ const int BUTTON_SIZE = 20;
foreach (NovationLedIds ledId in Enum.GetValues(typeof(NovationLedIds)))
{
Rectangle rectangle;
diff --git a/RGB.NET.Devices.Novation/NovationDeviceProvider.cs b/RGB.NET.Devices.Novation/NovationDeviceProvider.cs
index 604d60c..7c50c45 100644
--- a/RGB.NET.Devices.Novation/NovationDeviceProvider.cs
+++ b/RGB.NET.Devices.Novation/NovationDeviceProvider.cs
@@ -1,13 +1,18 @@
-using System;
+// ReSharper disable MemberCanBePrivate.Global
+// ReSharper disable UnusedMember.Global
+
+using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
-using System.ComponentModel.DataAnnotations;
+using System.Linq;
using RGB.NET.Core;
-using RGB.NET.Core.Extensions;
using Sanford.Multimedia.Midi;
namespace RGB.NET.Devices.Novation
{
+ ///
+ /// Represents a device provider responsible for Novation devices.
+ ///
public class NovationDeviceProvider : IRGBDeviceProvider
{
#region Properties & Fields
@@ -63,13 +68,16 @@ namespace RGB.NET.Devices.Novation
for (int index = 0; index < OutputDeviceBase.DeviceCount; index++)
{
MidiOutCaps outCaps = OutputDeviceBase.GetDeviceCapabilities(index);
+ if (outCaps.name == null) continue;
- if (outCaps.name.Equals(NovationDevices.LaunchpadS.GetAttribute().Name))
- {
- NovationRGBDevice device = new NovationLaunchpadRGBDevice(new NovationLaunchpadRGBDeviceInfo(outCaps.name, index));
- device.Initialize();
- devices.Add(device);
- }
+ NovationDevices? deviceId = (NovationDevices?)Enum.GetValues(typeof(NovationDevices)).Cast()
+ .FirstOrDefault(x => string.Equals(x.GetDeviceId(), outCaps.name, StringComparison.OrdinalIgnoreCase));
+
+ if (deviceId == null) continue;
+
+ NovationRGBDevice device = new NovationLaunchpadRGBDevice(new NovationLaunchpadRGBDeviceInfo(outCaps.name, index));
+ device.Initialize();
+ devices.Add(device);
}
}
catch
diff --git a/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj b/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj
index 5f5ad76..f9f2316 100644
--- a/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj
+++ b/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj
@@ -49,11 +49,13 @@
+
+