mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 10:08:31 +00:00
Fixed some code-issues in novation-library
This commit is contained in:
parent
b642cd31b0
commit
5440f9844f
@ -1,21 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
namespace RGB.NET.Core.Extensions
|
||||
{
|
||||
public static class EnumExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// A generic extension method that aids in reflecting
|
||||
/// and retrieving any attribute that is applied to an `Enum`.
|
||||
/// </summary>
|
||||
public static TAttribute GetAttribute<TAttribute>(this Enum enumValue)
|
||||
where TAttribute : Attribute
|
||||
{
|
||||
return enumValue.GetType()
|
||||
.GetMember(enumValue.ToString())
|
||||
.First()
|
||||
.GetCustomAttribute<TAttribute>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -54,7 +54,6 @@
|
||||
<Compile Include="Devices\Layout\LedImage.cs" />
|
||||
<Compile Include="Devices\Layout\LedImageLayout.cs" />
|
||||
<Compile Include="Devices\RGBDeviceLighting.cs" />
|
||||
<Compile Include="Extensions\EnumExtensions.cs" />
|
||||
<Compile Include="Helper\CultureHelper.cs" />
|
||||
<Compile Include="Helper\PathHelper.cs" />
|
||||
<Compile Include="Positioning\Shape.cs" />
|
||||
|
||||
33
RGB.NET.Devices.Novation/Attributes/DeviceIdAttribute.cs
Normal file
33
RGB.NET.Devices.Novation/Attributes/DeviceIdAttribute.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
|
||||
namespace RGB.NET.Devices.Novation.Attributes
|
||||
{
|
||||
/// <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
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DeviceIdAttribute"/> class.
|
||||
/// </summary>
|
||||
/// <param name="id">The id.</param>
|
||||
public DeviceIdAttribute(string id)
|
||||
{
|
||||
this.Id = id;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a specific novation device.
|
||||
/// </summary>
|
||||
public enum NovationDevices
|
||||
{
|
||||
[Display(Name = "Launchpad S")]
|
||||
[DeviceId("Launchpad S")]
|
||||
LaunchpadS
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
// ReSharper disable InconsistentNaming
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ using Sanford.Multimedia.Midi;
|
||||
namespace RGB.NET.Devices.Novation
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a generic Novation-device. (keyboard, mouse, headset, mousepad).
|
||||
/// Represents a generic Novation-device. (launchpad).
|
||||
/// </summary>
|
||||
public abstract class NovationRGBDevice : AbstractRGBDevice
|
||||
{
|
||||
@ -30,10 +30,11 @@ namespace RGB.NET.Devices.Novation
|
||||
/// Initializes a new instance of the <see cref="NovationRGBDevice"/> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The generic information provided by Novation for the device.</param>
|
||||
protected NovationRGBDevice(IRGBDeviceInfo info)
|
||||
protected NovationRGBDevice(NovationRGBDeviceInfo info)
|
||||
{
|
||||
this.DeviceInfo = info;
|
||||
_outputDevice = new OutputDevice(((NovationRGBDeviceInfo)DeviceInfo).DeviceId);
|
||||
|
||||
_outputDevice = new OutputDevice(info.DeviceId);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -25,7 +25,9 @@ namespace RGB.NET.Devices.Novation
|
||||
/// <inheritdoc />
|
||||
public RGBDeviceLighting Lighting => RGBDeviceLighting.Key;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Gets the (midi)-id of the <see cref="IRGBDevice"/>..
|
||||
/// </summary>
|
||||
public int DeviceId { get; }
|
||||
|
||||
#endregion
|
||||
@ -37,6 +39,7 @@ namespace RGB.NET.Devices.Novation
|
||||
/// </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>
|
||||
internal NovationRGBDeviceInfo(RGBDeviceType deviceType, string model, int deviceId)
|
||||
{
|
||||
this.DeviceType = deviceType;
|
||||
|
||||
33
RGB.NET.Devices.Novation/Helper/EnumExtension.cs
Normal file
33
RGB.NET.Devices.Novation/Helper/EnumExtension.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using RGB.NET.Devices.Novation.Attributes;
|
||||
|
||||
namespace RGB.NET.Devices.Novation
|
||||
{
|
||||
/// <summary>
|
||||
/// Offers some extensions and helper-methods for enum related things.
|
||||
/// </summary>
|
||||
internal static class EnumExtension
|
||||
{
|
||||
/// <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 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());
|
||||
T[] attributes = (T[])fi.GetCustomAttributes(typeof(T), false);
|
||||
return attributes.Length > 0 ? attributes[0] : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a device provider responsible for Novation devices.
|
||||
/// </summary>
|
||||
public class NovationDeviceProvider : IRGBDeviceProvider
|
||||
{
|
||||
#region Properties & Fields
|
||||
@ -63,15 +68,18 @@ namespace RGB.NET.Devices.Novation
|
||||
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 => string.Equals(x.GetDeviceId(), outCaps.name, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (deviceId == null) continue;
|
||||
|
||||
if (outCaps.name.Equals(NovationDevices.LaunchpadS.GetAttribute<DisplayAttribute>().Name))
|
||||
{
|
||||
NovationRGBDevice device = new NovationLaunchpadRGBDevice(new NovationLaunchpadRGBDeviceInfo(outCaps.name, index));
|
||||
device.Initialize();
|
||||
devices.Add(device);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (throwExceptions)
|
||||
|
||||
@ -49,11 +49,13 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Attributes\DeviceIdAttribute.cs" />
|
||||
<Compile Include="Enum\NovationDevices.cs" />
|
||||
<Compile Include="Enum\NovationLedIds.cs" />
|
||||
<Compile Include="Generic\NovationLedId.cs" />
|
||||
<Compile Include="Generic\NovationRGBDevice.cs" />
|
||||
<Compile Include="Generic\NovationRGBDeviceInfo.cs" />
|
||||
<Compile Include="Helper\EnumExtension.cs" />
|
||||
<Compile Include="Helper\NovationLedIdsExtension.cs" />
|
||||
<Compile Include="Launchpad\NovationLaunchpadRGBDevice.cs" />
|
||||
<Compile Include="Launchpad\NovationLaunchpadRGBDeviceInfo.cs" />
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user