Refactored LedIds

Everything is now based on the same ids for all devices
This commit is contained in:
DarthAffe committed 2017-12-13 17:19:56 +01:00
1 parent 200e471e4d
commit c5a1825f50
80 files changed
+2923 -3657

No files matched your search

@@ -1,108 +0,0 @@
using System.Diagnostics;
using RGB.NET.Core;
namespace RGB.NET.Devices.Novation
{
/// <inheritdoc />
/// <summary>
/// Represents a Id of a <see cref="T:RGB.NET.Core.Led" /> on a <see cref="T:RGB.NET.Devices.Novation.NovationRGBDevice" />.
/// </summary>
[DebuggerDisplay("{" + nameof(LedId) + "}")]
public class NovationLedId : ILedId
{
#region Properties & Fields
internal readonly NovationLedIds LedId;
/// <inheritdoc />
public IRGBDevice Device { get; }
/// <inheritdoc />
public bool IsValid => LedId != NovationLedIds.Invalid;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="NovationLedId"/> class.
/// </summary>
/// <param name="device">The <see cref="IRGBDevice"/> the <see cref="ILedId"/> belongs to.</param>
/// <param name="ledId">The <see cref="NovationLedId"/> of the represented <see cref="Led"/>.</param>
public NovationLedId(IRGBDevice device, NovationLedIds ledId)
{
this.Device = device;
this.LedId = ledId;
}
#endregion
#region Methods
/// <summary>
/// Converts the Id of this <see cref="NovationLedId"/> to a human-readable string.
/// </summary>
/// <returns>A string that contains the Id of this <see cref="NovationLedId"/>. For example "Enter".</returns>
public override string ToString()
{
return LedId.ToString();
}
/// <summary>
/// Tests whether the specified object is a <see cref="NovationLedId" /> and is equivalent to this <see cref="NovationLedId" />.
/// </summary>
/// <param name="obj">The object to test.</param>
/// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="NovationLedId" /> equivalent to this <see cref="NovationLedId" />; otherwise, <c>false</c>.</returns>
public override bool Equals(object obj)
{
NovationLedId compareLedId = obj as NovationLedId;
if (ReferenceEquals(compareLedId, null))
return false;
if (ReferenceEquals(this, compareLedId))
return true;
if (GetType() != compareLedId.GetType())
return false;
return compareLedId.LedId == LedId;
}
/// <summary>
/// Returns a hash code for this <see cref="NovationLedId" />.
/// </summary>
/// <returns>An integer value that specifies the hash code for this <see cref="NovationLedId" />.</returns>
public override int GetHashCode()
{
return LedId.GetHashCode();
}
#endregion
#region Operators
/// <summary>
/// Returns a value that indicates whether two specified <see cref="NovationLedId" /> are equal.
/// </summary>
/// <param name="ledId1">The first <see cref="NovationLedId" /> to compare.</param>
/// <param name="ledId2">The second <see cref="NovationLedId" /> to compare.</param>
/// <returns><c>true</c> if <paramref name="ledId1" /> and <paramref name="ledId2" /> are equal; otherwise, <c>false</c>.</returns>
public static bool operator ==(NovationLedId ledId1, NovationLedId ledId2)
{
return ReferenceEquals(ledId1, null) ? ReferenceEquals(ledId2, null) : ledId1.Equals(ledId2);
}
/// <summary>
/// Returns a value that indicates whether two specified <see cref="NovationLedId" /> are equal.
/// </summary>
/// <param name="ledId1">The first <see cref="NovationLedId" /> to compare.</param>
/// <param name="ledId2">The second <see cref="NovationLedId" /> to compare.</param>
/// <returns><c>true</c> if <paramref name="ledId1" /> and <paramref name="ledId2" /> are not equal; otherwise, <c>false</c>.</returns>
public static bool operator !=(NovationLedId ledId1, NovationLedId ledId2)
{
return !(ledId1 == ledId2);
}
#endregion
}
}
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using RGB.NET.Core;
using RGB.NET.Core.Layout;
using Sanford.Multimedia.Midi;
namespace RGB.NET.Devices.Novation
@@ -66,44 +64,6 @@ namespace RGB.NET.Devices.Novation
/// </summary>
protected abstract void InitializeLayout();
/// <summary>
/// Applies the given layout.
/// </summary>
/// <param name="layoutPath">The file containing the layout.</param>
/// <param name="imageLayout">The name of the layout used to get the images of the leds.</param>
/// <param name="imageBasePath">The path images for this device are collected in.</param>
protected void ApplyLayoutFromFile(string layoutPath, string imageLayout, string imageBasePath)
{
DeviceLayout layout = DeviceLayout.Load(layoutPath);
if (layout != null)
{
LedImageLayout ledImageLayout = layout.LedImageLayouts.FirstOrDefault(x => string.Equals(x.Layout, imageLayout, StringComparison.OrdinalIgnoreCase));
Size = new Size(layout.Width, layout.Height);
if (layout.Leds != null)
foreach (LedLayout layoutLed in layout.Leds)
{
if (Enum.TryParse(layoutLed.Id, true, out NovationLedIds ledId))
{
if (LedMapping.TryGetValue(new NovationLedId(this, ledId), out Led led))
{
led.LedRectangle.Location = new Point(layoutLed.X, layoutLed.Y);
led.LedRectangle.Size = new Size(layoutLed.Width, layoutLed.Height);
led.Shape = layoutLed.Shape;
led.ShapeData = layoutLed.ShapeData;
LedImage image = ledImageLayout?.LedImages.FirstOrDefault(x => x.Id == layoutLed.Id);
led.Image = (!string.IsNullOrEmpty(image?.Image))
? new Uri(Path.Combine(imageBasePath, image.Image), UriKind.Absolute)
: new Uri(Path.Combine(imageBasePath, "Missing.png"), UriKind.Absolute);
}
}
}
}
}
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate)
{
@@ -113,11 +73,10 @@ namespace RGB.NET.Devices.Novation
{
foreach (Led led in leds)
{
NovationLedId ledId = led.Id as NovationLedId;
if (ledId == null) continue;
NovationLedId ledId = (NovationLedId)led.CustomData;
int color = ConvertColor(led.Color);
SendMessage(ledId.LedId.GetStatus(), ledId.LedId.GetId(), color);
SendMessage(ledId.GetStatus(), ledId.GetId(), color);
}
}
}