// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using System;
using System.Collections.Generic;
using System.Linq;
using RGB.NET.Core;
using Sanford.Multimedia.Midi;
namespace RGB.NET.Devices.Novation
{
///
///
/// Represents a device provider responsible for Novation devices.
///
public class NovationDeviceProvider : AbstractRGBDeviceProvider
{
#region Properties & Fields
private static NovationDeviceProvider? _instance;
///
/// Gets the singleton instance.
///
public static NovationDeviceProvider Instance => _instance ?? new NovationDeviceProvider();
#endregion
#region Constructors
///
/// Initializes a new instance of the class.
///
/// Thrown if this constructor is called even if there is already an instance of this class.
private NovationDeviceProvider()
{
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(NovationDeviceProvider)}");
_instance = this;
}
#endregion
#region Methods
protected override void InitializeSDK() { }
protected override IEnumerable LoadDevices()
{
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()
.FirstOrDefault(x => x.GetDeviceId()?.ToUpperInvariant().Contains(outCaps.name.ToUpperInvariant()) ?? false);
if (deviceId == null) continue;
NovationColorCapabilities colorCapability = deviceId.GetColorCapability();
if (colorCapability == NovationColorCapabilities.None) continue;
yield return new NovationLaunchpadRGBDevice(new NovationLaunchpadRGBDeviceInfo(outCaps.name, index, colorCapability, deviceId.GetLedIdMapping()), GetUpdateTrigger());
}
}
#endregion
}
}