using System; using System.Collections.Generic; 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, IDisposable { #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(Dictionary dataSet) { foreach (KeyValuePair data in dataSet) SendMessage(CreateMessage(data)); } /// /// Sends the specified message to the device this queue is performing updates for. /// /// The message to send. protected virtual void SendMessage(ShortMessage message) => _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(KeyValuePair data); /// public void Dispose() => _outputDevice.Dispose(); #endregion } }