diff --git a/src/Artemis.Core/Artemis.Core.csproj b/src/Artemis.Core/Artemis.Core.csproj
index bd0e5eb30..b13eae70e 100644
--- a/src/Artemis.Core/Artemis.Core.csproj
+++ b/src/Artemis.Core/Artemis.Core.csproj
@@ -73,6 +73,9 @@
..\..\..\RGB.NET\bin\net5.0\RGB.NET.Groups.dll
+
+ ..\..\..\RGB.NET\bin\net5.0\RGB.NET.Layout.dll
+
diff --git a/src/Artemis.Core/Extensions/RgbDeviceExtensions.cs b/src/Artemis.Core/Extensions/RgbDeviceExtensions.cs
index 12c6988d4..5c1e11353 100644
--- a/src/Artemis.Core/Extensions/RgbDeviceExtensions.cs
+++ b/src/Artemis.Core/Extensions/RgbDeviceExtensions.cs
@@ -16,8 +16,6 @@ namespace Artemis.Core
builder.Append(rgbDevice.DeviceInfo.Model);
builder.Append('-');
builder.Append(rgbDevice.DeviceInfo.DeviceType);
- builder.Append('-');
- builder.Append(rgbDevice.DeviceInfo.Lighting);
return builder.ToString();
}
}
diff --git a/src/Artemis.Core/Models/Profile/Layer.cs b/src/Artemis.Core/Models/Profile/Layer.cs
index 5d7bcdb99..bd2a17907 100644
--- a/src/Artemis.Core/Models/Profile/Layer.cs
+++ b/src/Artemis.Core/Models/Profile/Layer.cs
@@ -287,7 +287,7 @@ namespace Artemis.Core
if (!Enabled || Path == null || LayerShape?.Path == null || !General.PropertiesInitialized || !Transform.PropertiesInitialized)
return;
// Ensure the brush is ready
- if (LayerBrush?.BaseProperties?.PropertiesInitialized == false || LayerBrush?.BrushType != LayerBrushType.Regular)
+ if (LayerBrush?.BaseProperties?.PropertiesInitialized == false)
return;
RenderTimeline(Timeline, canvas);
@@ -322,6 +322,9 @@ namespace Artemis.Core
return;
ApplyTimeline(timeline);
+
+ if (LayerBrush?.BrushType != LayerBrushType.Regular)
+ return;
try
{
diff --git a/src/Artemis.Core/Models/Surface/ArtemisDevice.cs b/src/Artemis.Core/Models/Surface/ArtemisDevice.cs
index 107287d53..4476ef22f 100644
--- a/src/Artemis.Core/Models/Surface/ArtemisDevice.cs
+++ b/src/Artemis.Core/Models/Surface/ArtemisDevice.cs
@@ -31,7 +31,7 @@ namespace Artemis.Core
GreenScale = 1;
BlueScale = 1;
IsEnabled = true;
-
+
deviceProvider.DeviceLayoutPaths.TryGetValue(rgbDevice, out string? layoutPath);
LayoutPath = layoutPath;
@@ -232,6 +232,11 @@ namespace Artemis.Core
///
public string? LayoutPath { get; internal set; }
+ ///
+ /// Gets the layout of the device expanded with Artemis-specific data
+ ///
+ public ArtemisLayout? Layout { get; internal set; }
+
internal DeviceEntity DeviceEntity { get; }
///
diff --git a/src/Artemis.Core/Models/Surface/ArtemisLayout.cs b/src/Artemis.Core/Models/Surface/ArtemisLayout.cs
new file mode 100644
index 000000000..64dc6409a
--- /dev/null
+++ b/src/Artemis.Core/Models/Surface/ArtemisLayout.cs
@@ -0,0 +1,10 @@
+using System;
+
+namespace Artemis.Core
+{
+ public class ArtemisLayout
+ {
+ public ArtemisDevice Device { get; set; }
+ public Uri Image { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/src/Artemis.Core/Plugins/LayerBrushes/RgbNetLayerBrush.cs b/src/Artemis.Core/Plugins/LayerBrushes/RgbNetLayerBrush.cs
index 4028228a7..6424b4f06 100644
--- a/src/Artemis.Core/Plugins/LayerBrushes/RgbNetLayerBrush.cs
+++ b/src/Artemis.Core/Plugins/LayerBrushes/RgbNetLayerBrush.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using Artemis.Core.Services;
+using Ninject;
using RGB.NET.Core;
using RGB.NET.Groups;
using SkiaSharp;
@@ -20,7 +21,6 @@ namespace Artemis.Core.LayerBrushes
///
protected RgbNetLayerBrush()
{
- LedGroup = new ListLedGroup();
BrushType = LayerBrushType.RgbNet;
SupportsTransformation = false;
}
@@ -28,7 +28,10 @@ namespace Artemis.Core.LayerBrushes
///
/// The LED group this layer effect is applied to
///
- public ListLedGroup LedGroup { get; internal set; }
+ public ListLedGroup? LedGroup { get; internal set; }
+
+ [Inject]
+ public IRgbService? RgbService { get; set; }
///
/// Called when Artemis needs an instance of the RGB.NET effect you are implementing
@@ -38,9 +41,14 @@ namespace Artemis.Core.LayerBrushes
internal void UpdateLedGroup()
{
- // TODO: This simply renders it on top of the rest, get a ZIndex based on layer position
- LedGroup.ZIndex = 1;
+ if (LedGroup == null)
+ return;
+ if (Layer.Parent != null)
+ LedGroup.ZIndex = Layer.Parent.Children.Count - Layer.Parent.Children.IndexOf(Layer);
+ else
+ LedGroup.ZIndex = 1;
+
List missingLeds = Layer.Leds.Where(l => !LedGroup.ContainsLed(l.RgbLed)).Select(l => l.RgbLed).ToList();
List extraLeds = LedGroup.GetLeds().Where(l => Layer.Leds.All(layerLed => layerLed.RgbLed != l)).ToList();
LedGroup.AddLeds(missingLeds);
@@ -50,7 +58,10 @@ namespace Artemis.Core.LayerBrushes
internal override void Initialize()
{
- LedGroup = new ListLedGroup();
+ if (RgbService == null)
+ throw new ArtemisCoreException("Cannot initialize RGB.NET layer brush because RgbService is not set");
+
+ LedGroup = new ListLedGroup(RgbService.Surface);
Layer.RenderPropertiesUpdated += LayerOnRenderPropertiesUpdated;
InitializeProperties();
@@ -64,8 +75,12 @@ namespace Artemis.Core.LayerBrushes
{
if (disposing)
{
+ if (RgbService == null)
+ throw new ArtemisCoreException("Cannot dispose RGB.NET layer brush because RgbService is not set");
+
Layer.RenderPropertiesUpdated -= LayerOnRenderPropertiesUpdated;
- LedGroup.Detach();
+ LedGroup?.Detach(RgbService.Surface);
+ LedGroup = null;
}
base.Dispose(disposing);
diff --git a/src/Artemis.Core/Services/DeviceService.cs b/src/Artemis.Core/Services/DeviceService.cs
index 48c64a50f..032c0db53 100644
--- a/src/Artemis.Core/Services/DeviceService.cs
+++ b/src/Artemis.Core/Services/DeviceService.cs
@@ -8,6 +8,13 @@ namespace Artemis.Core.Services
{
internal class DeviceService : IDeviceService
{
+ private readonly IRgbService _rgbService;
+
+ public DeviceService(IRgbService rgbService)
+ {
+ _rgbService = rgbService;
+ }
+
public void IdentifyDevice(ArtemisDevice device)
{
BlinkDevice(device, 0);
@@ -16,9 +23,9 @@ namespace Artemis.Core.Services
private void BlinkDevice(ArtemisDevice device, int blinkCount)
{
// Create a LED group way at the top
- ListLedGroup ledGroup = new(device.Leds.Select(l => l.RgbLed))
+ ListLedGroup ledGroup = new(_rgbService.Surface, device.Leds.Select(l => l.RgbLed))
{
- Brush = new SolidColorBrush(new Color(255, 255, 255)),
+ Brush = new SolidColorBrush(new Color(255, 255, 255)),
ZIndex = 999
};
@@ -26,7 +33,7 @@ namespace Artemis.Core.Services
Task.Run(async () =>
{
await Task.Delay(200);
- ledGroup.Detach();
+ ledGroup.Detach(_rgbService.Surface);
if (blinkCount < 5)
{
diff --git a/src/Artemis.Core/Services/PluginManagementService.cs b/src/Artemis.Core/Services/PluginManagementService.cs
index b67c27470..30e8d79f0 100644
--- a/src/Artemis.Core/Services/PluginManagementService.cs
+++ b/src/Artemis.Core/Services/PluginManagementService.cs
@@ -358,7 +358,7 @@ namespace Artemis.Core.Services
}
catch (Exception e)
{
- throw new ArtemisPluginException(plugin, "Failed to instantiate feature", e);
+ _logger.Warning(new ArtemisPluginException(plugin, "Failed to instantiate feature", e), "Failed to instantiate feature", plugin);
}
}
diff --git a/src/Artemis.Core/Services/RgbService.cs b/src/Artemis.Core/Services/RgbService.cs
index 6d7492100..8d7d05fc7 100644
--- a/src/Artemis.Core/Services/RgbService.cs
+++ b/src/Artemis.Core/Services/RgbService.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using RGB.NET.Core;
using RGB.NET.Groups;
+using RGB.NET.Layout;
using Serilog;
namespace Artemis.Core.Services
@@ -26,7 +27,7 @@ namespace Artemis.Core.Services
_targetFrameRateSetting = settingsService.GetSetting("Core.TargetFrameRate", 25);
_sampleSizeSetting = settingsService.GetSetting("Core.SampleSize", 1);
- Surface = RGBSurface.Instance;
+ Surface = new RGBSurface();
// Let's throw these for now
Surface.Exception += SurfaceOnException;
@@ -50,7 +51,11 @@ namespace Artemis.Core.Services
{
try
{
- Surface.LoadDevices(deviceProvider, RGBDeviceType.All, false, true);
+ // Device provider may have been attached before..?
+ Surface.Detach(deviceProvider.Devices);
+
+ deviceProvider.Initialize(RGBDeviceType.All, true);
+ Surface.Attach(deviceProvider.Devices);
}
catch (Exception e)
{
@@ -117,19 +122,19 @@ namespace Artemis.Core.Services
{
// Apply the application wide brush and decorator
BitmapBrush = new BitmapBrush(new Scale(_renderScaleSetting.Value), _sampleSizeSetting);
- _surfaceLedGroup = new ListLedGroup(artemisSurface.LedMap.Select(l => l.Key)) {Brush = BitmapBrush};
+ _surfaceLedGroup = new ListLedGroup(Surface, artemisSurface.LedMap.Select(l => l.Key)) {Brush = BitmapBrush};
return;
}
lock (_surfaceLedGroup)
{
// Clean up the old background
- _surfaceLedGroup.Detach();
+ _surfaceLedGroup.Detach(Surface);
// Apply the application wide brush and decorator
BitmapBrush.Scale = new Scale(_renderScaleSetting.Value);
BitmapBrush.Surface = artemisSurface;
- _surfaceLedGroup = new ListLedGroup(artemisSurface.LedMap.Select(l => l.Key)) {Brush = BitmapBrush};
+ _surfaceLedGroup = new ListLedGroup(Surface, artemisSurface.LedMap.Select(l => l.Key)) {Brush = BitmapBrush};
}
}
diff --git a/src/Artemis.Core/Services/WebServer/EndPoints/PluginEndPoint.cs b/src/Artemis.Core/Services/WebServer/EndPoints/PluginEndPoint.cs
index c81c772ee..c456ff220 100644
--- a/src/Artemis.Core/Services/WebServer/EndPoints/PluginEndPoint.cs
+++ b/src/Artemis.Core/Services/WebServer/EndPoints/PluginEndPoint.cs
@@ -29,7 +29,7 @@ namespace Artemis.Core.Services
///
/// Gets the full URL of the end point
///
- public string Url => $"{_pluginsModule.ServerUrl.TrimEnd('/')}{_pluginsModule.BaseRoute}{PluginFeature.Plugin.Guid}/{Name}";
+ public string Url => $"{_pluginsModule.ServerUrl?.TrimEnd('/')}{_pluginsModule.BaseRoute}{PluginFeature.Plugin.Guid}/{Name}";
///
/// Gets the plugin the end point is associated with
@@ -45,12 +45,12 @@ namespace Artemis.Core.Services
///
/// Gets the mime type of the input this end point accepts
///
- public string Accepts { get; protected set; }
+ public string? Accepts { get; protected set; }
///
/// Gets the mime type of the output this end point returns
///
- public string Returns { get; protected set; }
+ public string? Returns { get; protected set; }
///
/// Called whenever the end point has to process a request
diff --git a/src/Artemis.UI.Shared/Controls/DeviceVisualizer.cs b/src/Artemis.UI.Shared/Controls/DeviceVisualizer.cs
index 6021653ba..0b3410643 100644
--- a/src/Artemis.UI.Shared/Controls/DeviceVisualizer.cs
+++ b/src/Artemis.UI.Shared/Controls/DeviceVisualizer.cs
@@ -235,8 +235,8 @@ namespace Artemis.UI.Shared
UpdateTransform();
// Load the device main image
- if (Device.RgbDevice.DeviceInfo?.Image?.AbsolutePath != null && File.Exists(Device.RgbDevice.DeviceInfo.Image.AbsolutePath))
- _deviceImage = new BitmapImage(Device.RgbDevice.DeviceInfo.Image);
+ // if (Device.RgbDevice.DeviceInfo?.Image?.AbsolutePath != null && File.Exists(Device.RgbDevice.DeviceInfo.Image.AbsolutePath))
+ // _deviceImage = new BitmapImage(Device.RgbDevice.DeviceInfo.Image);
// Create all the LEDs
foreach (ArtemisLed artemisLed in Device.Leds)
diff --git a/src/Artemis.UI/Screens/Settings/Debug/DeviceDebugViewModel.cs b/src/Artemis.UI/Screens/Settings/Debug/DeviceDebugViewModel.cs
index 9bfac70e9..70bad8603 100644
--- a/src/Artemis.UI/Screens/Settings/Debug/DeviceDebugViewModel.cs
+++ b/src/Artemis.UI/Screens/Settings/Debug/DeviceDebugViewModel.cs
@@ -35,7 +35,7 @@ namespace Artemis.UI.Screens.Settings.Debug
}
}
- public bool CanOpenImageDirectory => Device.RgbDevice.DeviceInfo.Image != null;
+ public bool CanOpenImageDirectory => Device.Layout?.Image != null;
// ReSharper disable UnusedMember.Global
@@ -70,7 +70,7 @@ namespace Artemis.UI.Screens.Settings.Debug
try
{
- Process.Start(Environment.GetEnvironmentVariable("WINDIR") + @"\explorer.exe", Path.GetDirectoryName(Device.RgbDevice.DeviceInfo.Image.AbsolutePath));
+ Process.Start(Environment.GetEnvironmentVariable("WINDIR") + @"\explorer.exe", Path.GetDirectoryName(Device.Layout.Image.AbsolutePath));
}
catch (Exception e)
{
diff --git a/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceDeviceDetectInputViewModel.cs b/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceDeviceDetectInputViewModel.cs
index a3c7d41f9..07f04fce9 100644
--- a/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceDeviceDetectInputViewModel.cs
+++ b/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceDeviceDetectInputViewModel.cs
@@ -14,9 +14,10 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
{
private readonly IInputService _inputService;
private readonly IMessageService _messageService;
+ private readonly IRgbService _rgbService;
private readonly ListLedGroup _ledGroup;
- public SurfaceDeviceDetectInputViewModel(ArtemisDevice device, IInputService inputService, IMessageService messageService)
+ public SurfaceDeviceDetectInputViewModel(ArtemisDevice device, IInputService inputService, IMessageService messageService, IRgbService rgbService)
{
Device = device;
Title = $"{Device.RgbDevice.DeviceInfo.DeviceName} - Detect input";
@@ -24,11 +25,12 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
_inputService = inputService;
_messageService = messageService;
+ _rgbService = rgbService;
_inputService.IdentifyDevice(Device);
_inputService.DeviceIdentified += InputServiceOnDeviceIdentified;
// Create a LED group way at the top
- _ledGroup = new ListLedGroup(Device.Leds.Select(l => l.RgbLed))
+ _ledGroup = new ListLedGroup(_rgbService.Surface, Device.Leds.Select(l => l.RgbLed))
{
Brush = new SolidColorBrush(new Color(255, 255, 0)),
ZIndex = 999
@@ -43,7 +45,7 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
{
base.OnDialogClosed(sender, e);
_inputService.DeviceIdentified -= InputServiceOnDeviceIdentified;
- _ledGroup.Detach();
+ _ledGroup.Detach(_rgbService.Surface);
}
private void InputServiceOnDeviceIdentified(object sender, EventArgs e)