using System; using RGB.NET.Core; using Sanford.Multimedia.Midi; namespace RGB.NET.Devices.Novation { /// /// /// Represents the update-queue performing updates for midi devices. /// public abstract class MidiUpdateQueue : UpdateQueue { #region Properties & Fields private readonly OutputDevice _outputDevice; #endregion #region Constructors /// /// /// Initializes a new instance of the class. /// /// The update trigger used by this queue. /// The id of the device this queue is performing updates for. protected MidiUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceId) : base(updateTrigger) { _outputDevice = new OutputDevice(deviceId); } #endregion #region Methods /// protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) { foreach ((object key, Color color) in dataSet) SendMessage(CreateMessage(key, color)); } /// /// Sends the specified message to the device this queue is performing updates for. /// /// The message to send. protected virtual void SendMessage(ShortMessage? message) { if (message != null) _outputDevice.SendShort(message.Message); } /// /// Creates a update-message out of a given data set. /// /// The data set to create the message from. /// The message created out of the data set. protected abstract ShortMessage? CreateMessage(object key, in Color color); /// public override void Dispose() { base.Dispose(); _outputDevice.Dispose(); GC.SuppressFinalize(this); } #endregion } }