UI - Decreased device visualizer CPU usage

Keyframes - Snap to closest 50 ms while Ctrl is held down
This commit is contained in:
Robert committed 2021-04-17 10:22:33 +02:00
1 parent 651fc515d2
commit 5e345fed7c
8 files changed
+73 -62

No files matched your search

@@ -109,6 +109,9 @@ namespace Artemis.Core
/// </summary>
public List<ArtemisDeviceInputIdentifier> InputIdentifiers { get; }
/// <summary>
/// Gets a list of input mappings configured on the device
/// </summary>
public Dictionary<ArtemisLed, ArtemisLed> InputMappings { get; }
/// <summary>
@@ -288,7 +291,10 @@ namespace Artemis.Core
/// Attempts to retrieve the <see cref="ArtemisLed" /> that corresponds the provided RGB.NET <see cref="Led" />
/// </summary>
/// <param name="led">The RGB.NET <see cref="Led" /> to find the corresponding <see cref="ArtemisLed" /> for </param>
/// <param name="applyInputMapping">If <see langword="true"/>, LEDs mapped to different LEDs <see cref="InputMappings"/> are taken into consideration</param>
/// <param name="applyInputMapping">
/// If <see langword="true" />, LEDs mapped to different LEDs <see cref="InputMappings" />
/// are taken into consideration
/// </param>
/// <returns>If found, the corresponding <see cref="ArtemisLed" />; otherwise <see langword="null" />.</returns>
public ArtemisLed? GetLed(Led led, bool applyInputMapping)
{
@@ -299,7 +305,10 @@ namespace Artemis.Core
/// Attempts to retrieve the <see cref="ArtemisLed" /> that corresponds the provided RGB.NET <see cref="LedId" />
/// </summary>
/// <param name="ledId">The RGB.NET <see cref="LedId" /> to find the corresponding <see cref="ArtemisLed" /> for </param>
/// <param name="applyInputMapping">If <see langword="true"/>, LEDs mapped to different LEDs <see cref="InputMappings"/> are taken into consideration</param>
/// <param name="applyInputMapping">
/// If <see langword="true" />, LEDs mapped to different LEDs <see cref="InputMappings" />
/// are taken into consideration
/// </param>
/// <returns>If found, the corresponding <see cref="ArtemisLed" />; otherwise <see langword="null" />.</returns>
public ArtemisLed? GetLed(LedId ledId, bool applyInputMapping)
{
@@ -329,12 +338,31 @@ namespace Artemis.Core
return fileName;
}
/// <summary>
/// Occurs when the underlying RGB.NET device was updated
/// </summary>
public event EventHandler? DeviceUpdated;
/// <summary>
/// Invokes the <see cref="DeviceUpdated" /> event
/// </summary>
protected virtual void OnDeviceUpdated()
{
DeviceUpdated?.Invoke(this, EventArgs.Empty);
}
/// <summary>
/// Applies the provided layout to the device
/// </summary>
/// <param name="layout">The layout to apply</param>
/// <param name="createMissingLeds">A boolean indicating whether to add missing LEDs defined in the layout but missing on the device</param>
/// <param name="removeExcessiveLeds">A boolean indicating whether to remove excess LEDs present in the device but missing in the layout</param>
/// <param name="createMissingLeds">
/// A boolean indicating whether to add missing LEDs defined in the layout but missing on
/// the device
/// </param>
/// <param name="removeExcessiveLeds">
/// A boolean indicating whether to remove excess LEDs present in the device but missing
/// in the layout
/// </param>
internal void ApplyLayout(ArtemisLayout layout, bool createMissingLeds, bool removeExcessiveLeds)
{
if (createMissingLeds && !DeviceProvider.CreateMissingLedsSupported)
@@ -355,21 +383,6 @@ namespace Artemis.Core
OnDeviceUpdated();
}
private void UpdateLeds()
{
Leds = RgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
LedIds = new ReadOnlyDictionary<LedId, ArtemisLed>(Leds.ToDictionary(l => l.RgbLed.Id, l => l));
InputMappings.Clear();
foreach (InputMappingEntity deviceEntityInputMapping in DeviceEntity.InputMappings)
{
ArtemisLed? original = Leds.FirstOrDefault(l => l.RgbLed.Id == (LedId) deviceEntityInputMapping.OriginalLedId);
ArtemisLed? mapped = Leds.FirstOrDefault(l => l.RgbLed.Id == (LedId) deviceEntityInputMapping.MappedLedId);
if (original != null && mapped != null)
InputMappings.Add(original, mapped);
}
}
internal void ApplyToEntity()
{
// Other properties are computed
@@ -427,6 +440,21 @@ namespace Artemis.Core
Path = path;
}
private void UpdateLeds()
{
Leds = RgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
LedIds = new ReadOnlyDictionary<LedId, ArtemisLed>(Leds.ToDictionary(l => l.RgbLed.Id, l => l));
InputMappings.Clear();
foreach (InputMappingEntity deviceEntityInputMapping in DeviceEntity.InputMappings)
{
ArtemisLed? original = Leds.FirstOrDefault(l => l.RgbLed.Id == (LedId) deviceEntityInputMapping.OriginalLedId);
ArtemisLed? mapped = Leds.FirstOrDefault(l => l.RgbLed.Id == (LedId) deviceEntityInputMapping.MappedLedId);
if (original != null && mapped != null)
InputMappings.Add(original, mapped);
}
}
private void ApplyKeyboardLayout()
{
if (RgbDevice.DeviceInfo.DeviceType != RGBDeviceType.Keyboard)
@@ -443,22 +471,5 @@ namespace Artemis.Core
else
LogicalLayout = DeviceEntity.LogicalLayout;
}
#region Events
/// <summary>
/// Occurs when the underlying RGB.NET device was updated
/// </summary>
public event EventHandler? DeviceUpdated;
/// <summary>
/// Invokes the <see cref="DeviceUpdated" /> event
/// </summary>
protected virtual void OnDeviceUpdated()
{
DeviceUpdated?.Invoke(this, EventArgs.Empty);
}
#endregion
}
}
@@ -1,17 +1,18 @@
using Artemis.Core.Services;
using RGB.NET.Core;
namespace Artemis.Core
namespace Artemis.Core
{
/// <summary>
/// Represents a device input identifier used by a specific <see cref="Services.InputProvider" /> to identify the device
/// Represents a device input identifier used by a specific <see cref="Services.InputProvider" /> to identify the
/// device
/// </summary>
public class ArtemisDeviceInputIdentifier
{
/// <summary>
/// Creates a new instance of the <see cref="ArtemisDeviceInputIdentifier" /> class
/// </summary>
/// <param name="inputProvider">The full type and namespace of the <see cref="Services.InputProvider" /> this identifier is used by</param>
/// <param name="inputProvider">
/// The full type and namespace of the <see cref="Services.InputProvider" /> this identifier is
/// used by
/// </param>
/// <param name="identifier">A value used to identify the device</param>
internal ArtemisDeviceInputIdentifier(string inputProvider, object identifier)
{
@@ -29,16 +30,4 @@ namespace Artemis.Core
/// </summary>
public object Identifier { get; set; }
}
public class ArtemisDeviceInputMapping
{
public ArtemisLed OriginalLed { get; }
public ArtemisLed MappedLed { get; }
internal ArtemisDeviceInputMapping(ArtemisLed originalLed, ArtemisLed mappedLed)
{
OriginalLed = originalLed;
MappedLed = mappedLed;
}
}
}