mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2026-11-11 04:57:15 +00:00
Streamlined device loading/handling in device providers
This commit is contained in:
1 parent
f6f3e9185c
commit
2a9a43683c
81 files changed
+867
-1864
No files matched your search
@@ -5,8 +5,6 @@ namespace RGB.NET.Devices.Novation
|
||||
/// <summary>
|
||||
/// Represents a novation RGB-device.
|
||||
/// </summary>
|
||||
internal interface INovationRGBDevice : IRGBDevice
|
||||
{
|
||||
void Initialize(IDeviceUpdateTrigger updateTrigger);
|
||||
}
|
||||
public interface INovationRGBDevice : IRGBDevice
|
||||
{ }
|
||||
}
|
||||
@@ -1,76 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.Novation
|
||||
{
|
||||
/// <inheritdoc cref="AbstractRGBDevice{TDeviceInfo}" />
|
||||
/// <inheritdoc cref="INovationRGBDevice" />
|
||||
/// <summary>
|
||||
/// Represents a generic Novation-device. (launchpad).
|
||||
/// </summary>
|
||||
public abstract class NovationRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceInfo>, INovationRGBDevice
|
||||
where TDeviceInfo : NovationRGBDeviceInfo
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Gets information about the <see cref="T:RGB.NET.Devices.Novation.NovationRGBDevice" />.
|
||||
/// </summary>
|
||||
public override TDeviceInfo DeviceInfo { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="MidiUpdateQueue"/> used to update this <see cref="NovationRGBDevice{TDeviceInfo}"/>.
|
||||
/// </summary>
|
||||
// ReSharper disable once MemberCanBePrivate.Global
|
||||
protected MidiUpdateQueue? UpdateQueue { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <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>
|
||||
protected NovationRGBDevice(TDeviceInfo info)
|
||||
{
|
||||
this.DeviceInfo = info;
|
||||
}
|
||||
protected NovationRGBDevice(TDeviceInfo info, IDeviceUpdateTrigger updateTrigger)
|
||||
: base(info, GetUpdateQueue(updateTrigger, info))
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the device.
|
||||
/// </summary>
|
||||
public void Initialize(IDeviceUpdateTrigger updateTrigger)
|
||||
{
|
||||
InitializeLayout();
|
||||
|
||||
UpdateQueue = DeviceInfo.ColorCapabilities switch
|
||||
private static UpdateQueue GetUpdateQueue(IDeviceUpdateTrigger updateTrigger, TDeviceInfo info) =>
|
||||
info.ColorCapabilities switch
|
||||
{
|
||||
NovationColorCapabilities.LimitedRG => new LimitedColorUpdateQueue(updateTrigger, DeviceInfo.DeviceId),
|
||||
NovationColorCapabilities.RGB => new RGBColorUpdateQueue(updateTrigger, DeviceInfo.DeviceId),
|
||||
NovationColorCapabilities.LimitedRG => new LimitedColorUpdateQueue(updateTrigger, info.DeviceId),
|
||||
NovationColorCapabilities.RGB => new RGBColorUpdateQueue(updateTrigger, info.DeviceId),
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the <see cref="Led"/> and <see cref="Size"/> of the device.
|
||||
/// </summary>
|
||||
protected abstract void InitializeLayout();
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue?.SetData(GetUpdateData(ledsToUpdate));
|
||||
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();
|
||||
public virtual void Reset() => UpdateQueue.Reset();
|
||||
|
||||
/// <inheritdoc cref="IDisposable.Dispose" />
|
||||
/// <inheritdoc cref="AbstractRGBDevice{TDeviceInfo}.Dispose" />
|
||||
@@ -78,9 +47,6 @@ namespace RGB.NET.Devices.Novation
|
||||
{
|
||||
Reset();
|
||||
|
||||
try { UpdateQueue?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user