using System;
using System.Collections.Generic;
using System.Linq;
using RGB.NET.Core;
namespace RGB.NET.Devices.Novation
{
///
///
///
/// Represents a generic Novation-device. (launchpad).
///
public abstract class NovationRGBDevice : AbstractRGBDevice, INovationRGBDevice
where TDeviceInfo : NovationRGBDeviceInfo
{
#region Properties & Fields
///
///
/// Gets information about the .
///
public override TDeviceInfo DeviceInfo { get; }
///
/// The used to update this .
///
// ReSharper disable once MemberCanBePrivate.Global
protected MidiUpdateQueue UpdateQueue { get; set; }
#endregion
#region Constructors
///
/// Initializes a new instance of the class.
///
/// The generic information provided by Novation for the device.
protected NovationRGBDevice(TDeviceInfo info)
{
this.DeviceInfo = info;
}
#endregion
#region Methods
///
/// Initializes the device.
///
public void Initialize(IDeviceUpdateTrigger updateTrigger)
{
InitializeLayout();
if (Size == Size.Invalid)
{
Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
}
UpdateQueue = DeviceInfo.ColorCapabilities switch
{
NovationColorCapabilities.LimitedRG => new LimitedColorUpdateQueue(updateTrigger, DeviceInfo.DeviceId),
NovationColorCapabilities.RGB => new RGBColorUpdateQueue(updateTrigger, DeviceInfo.DeviceId),
_ => throw new ArgumentOutOfRangeException()
};
}
///
/// Initializes the and of the device.
///
protected abstract void InitializeLayout();
///
protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
///
/// Resets the back to default.
///
public virtual void Reset() => UpdateQueue.Reset();
///
///
public override void Dispose()
{
Reset();
try { UpdateQueue?.Dispose(); }
catch { /* at least we tried */ }
base.Dispose();
}
#endregion
}
}