1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

RGB.NET - Updated for latest development branch

This commit is contained in:
Robert 2021-02-07 22:29:30 +01:00
parent 81b8f5bf48
commit 606c1b80f2
13 changed files with 77 additions and 29 deletions

View File

@ -73,6 +73,9 @@
<Reference Include="RGB.NET.Groups"> <Reference Include="RGB.NET.Groups">
<HintPath>..\..\..\RGB.NET\bin\net5.0\RGB.NET.Groups.dll</HintPath> <HintPath>..\..\..\RGB.NET\bin\net5.0\RGB.NET.Groups.dll</HintPath>
</Reference> </Reference>
<Reference Include="RGB.NET.Layout">
<HintPath>..\..\..\RGB.NET\bin\net5.0\RGB.NET.Layout.dll</HintPath>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Update="Resources\intro-profile.json"> <None Update="Resources\intro-profile.json">

View File

@ -16,8 +16,6 @@ namespace Artemis.Core
builder.Append(rgbDevice.DeviceInfo.Model); builder.Append(rgbDevice.DeviceInfo.Model);
builder.Append('-'); builder.Append('-');
builder.Append(rgbDevice.DeviceInfo.DeviceType); builder.Append(rgbDevice.DeviceInfo.DeviceType);
builder.Append('-');
builder.Append(rgbDevice.DeviceInfo.Lighting);
return builder.ToString(); return builder.ToString();
} }
} }

View File

@ -287,7 +287,7 @@ namespace Artemis.Core
if (!Enabled || Path == null || LayerShape?.Path == null || !General.PropertiesInitialized || !Transform.PropertiesInitialized) if (!Enabled || Path == null || LayerShape?.Path == null || !General.PropertiesInitialized || !Transform.PropertiesInitialized)
return; return;
// Ensure the brush is ready // Ensure the brush is ready
if (LayerBrush?.BaseProperties?.PropertiesInitialized == false || LayerBrush?.BrushType != LayerBrushType.Regular) if (LayerBrush?.BaseProperties?.PropertiesInitialized == false)
return; return;
RenderTimeline(Timeline, canvas); RenderTimeline(Timeline, canvas);
@ -322,6 +322,9 @@ namespace Artemis.Core
return; return;
ApplyTimeline(timeline); ApplyTimeline(timeline);
if (LayerBrush?.BrushType != LayerBrushType.Regular)
return;
try try
{ {

View File

@ -31,7 +31,7 @@ namespace Artemis.Core
GreenScale = 1; GreenScale = 1;
BlueScale = 1; BlueScale = 1;
IsEnabled = true; IsEnabled = true;
deviceProvider.DeviceLayoutPaths.TryGetValue(rgbDevice, out string? layoutPath); deviceProvider.DeviceLayoutPaths.TryGetValue(rgbDevice, out string? layoutPath);
LayoutPath = layoutPath; LayoutPath = layoutPath;
@ -232,6 +232,11 @@ namespace Artemis.Core
/// </summary> /// </summary>
public string? LayoutPath { get; internal set; } public string? LayoutPath { get; internal set; }
/// <summary>
/// Gets the layout of the device expanded with Artemis-specific data
/// </summary>
public ArtemisLayout? Layout { get; internal set; }
internal DeviceEntity DeviceEntity { get; } internal DeviceEntity DeviceEntity { get; }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -0,0 +1,10 @@
using System;
namespace Artemis.Core
{
public class ArtemisLayout
{
public ArtemisDevice Device { get; set; }
public Uri Image { get; set; }
}
}

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Artemis.Core.Services; using Artemis.Core.Services;
using Ninject;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Groups; using RGB.NET.Groups;
using SkiaSharp; using SkiaSharp;
@ -20,7 +21,6 @@ namespace Artemis.Core.LayerBrushes
/// </summary> /// </summary>
protected RgbNetLayerBrush() protected RgbNetLayerBrush()
{ {
LedGroup = new ListLedGroup();
BrushType = LayerBrushType.RgbNet; BrushType = LayerBrushType.RgbNet;
SupportsTransformation = false; SupportsTransformation = false;
} }
@ -28,7 +28,10 @@ namespace Artemis.Core.LayerBrushes
/// <summary> /// <summary>
/// The LED group this layer effect is applied to /// The LED group this layer effect is applied to
/// </summary> /// </summary>
public ListLedGroup LedGroup { get; internal set; } public ListLedGroup? LedGroup { get; internal set; }
[Inject]
public IRgbService? RgbService { get; set; }
/// <summary> /// <summary>
/// Called when Artemis needs an instance of the RGB.NET effect you are implementing /// 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() internal void UpdateLedGroup()
{ {
// TODO: This simply renders it on top of the rest, get a ZIndex based on layer position if (LedGroup == null)
LedGroup.ZIndex = 1; return;
if (Layer.Parent != null)
LedGroup.ZIndex = Layer.Parent.Children.Count - Layer.Parent.Children.IndexOf(Layer);
else
LedGroup.ZIndex = 1;
List<Led> missingLeds = Layer.Leds.Where(l => !LedGroup.ContainsLed(l.RgbLed)).Select(l => l.RgbLed).ToList(); List<Led> missingLeds = Layer.Leds.Where(l => !LedGroup.ContainsLed(l.RgbLed)).Select(l => l.RgbLed).ToList();
List<Led> extraLeds = LedGroup.GetLeds().Where(l => Layer.Leds.All(layerLed => layerLed.RgbLed != l)).ToList(); List<Led> extraLeds = LedGroup.GetLeds().Where(l => Layer.Leds.All(layerLed => layerLed.RgbLed != l)).ToList();
LedGroup.AddLeds(missingLeds); LedGroup.AddLeds(missingLeds);
@ -50,7 +58,10 @@ namespace Artemis.Core.LayerBrushes
internal override void Initialize() 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; Layer.RenderPropertiesUpdated += LayerOnRenderPropertiesUpdated;
InitializeProperties(); InitializeProperties();
@ -64,8 +75,12 @@ namespace Artemis.Core.LayerBrushes
{ {
if (disposing) if (disposing)
{ {
if (RgbService == null)
throw new ArtemisCoreException("Cannot dispose RGB.NET layer brush because RgbService is not set");
Layer.RenderPropertiesUpdated -= LayerOnRenderPropertiesUpdated; Layer.RenderPropertiesUpdated -= LayerOnRenderPropertiesUpdated;
LedGroup.Detach(); LedGroup?.Detach(RgbService.Surface);
LedGroup = null;
} }
base.Dispose(disposing); base.Dispose(disposing);

View File

@ -8,6 +8,13 @@ namespace Artemis.Core.Services
{ {
internal class DeviceService : IDeviceService internal class DeviceService : IDeviceService
{ {
private readonly IRgbService _rgbService;
public DeviceService(IRgbService rgbService)
{
_rgbService = rgbService;
}
public void IdentifyDevice(ArtemisDevice device) public void IdentifyDevice(ArtemisDevice device)
{ {
BlinkDevice(device, 0); BlinkDevice(device, 0);
@ -16,9 +23,9 @@ namespace Artemis.Core.Services
private void BlinkDevice(ArtemisDevice device, int blinkCount) private void BlinkDevice(ArtemisDevice device, int blinkCount)
{ {
// Create a LED group way at the top // 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 ZIndex = 999
}; };
@ -26,7 +33,7 @@ namespace Artemis.Core.Services
Task.Run(async () => Task.Run(async () =>
{ {
await Task.Delay(200); await Task.Delay(200);
ledGroup.Detach(); ledGroup.Detach(_rgbService.Surface);
if (blinkCount < 5) if (blinkCount < 5)
{ {

View File

@ -358,7 +358,7 @@ namespace Artemis.Core.Services
} }
catch (Exception e) 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);
} }
} }

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Groups; using RGB.NET.Groups;
using RGB.NET.Layout;
using Serilog; using Serilog;
namespace Artemis.Core.Services namespace Artemis.Core.Services
@ -26,7 +27,7 @@ namespace Artemis.Core.Services
_targetFrameRateSetting = settingsService.GetSetting("Core.TargetFrameRate", 25); _targetFrameRateSetting = settingsService.GetSetting("Core.TargetFrameRate", 25);
_sampleSizeSetting = settingsService.GetSetting("Core.SampleSize", 1); _sampleSizeSetting = settingsService.GetSetting("Core.SampleSize", 1);
Surface = RGBSurface.Instance; Surface = new RGBSurface();
// Let's throw these for now // Let's throw these for now
Surface.Exception += SurfaceOnException; Surface.Exception += SurfaceOnException;
@ -50,7 +51,11 @@ namespace Artemis.Core.Services
{ {
try 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) catch (Exception e)
{ {
@ -117,19 +122,19 @@ namespace Artemis.Core.Services
{ {
// Apply the application wide brush and decorator // Apply the application wide brush and decorator
BitmapBrush = new BitmapBrush(new Scale(_renderScaleSetting.Value), _sampleSizeSetting); 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; return;
} }
lock (_surfaceLedGroup) lock (_surfaceLedGroup)
{ {
// Clean up the old background // Clean up the old background
_surfaceLedGroup.Detach(); _surfaceLedGroup.Detach(Surface);
// Apply the application wide brush and decorator // Apply the application wide brush and decorator
BitmapBrush.Scale = new Scale(_renderScaleSetting.Value); BitmapBrush.Scale = new Scale(_renderScaleSetting.Value);
BitmapBrush.Surface = artemisSurface; 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};
} }
} }

View File

@ -29,7 +29,7 @@ namespace Artemis.Core.Services
/// <summary> /// <summary>
/// Gets the full URL of the end point /// Gets the full URL of the end point
/// </summary> /// </summary>
public string Url => $"{_pluginsModule.ServerUrl.TrimEnd('/')}{_pluginsModule.BaseRoute}{PluginFeature.Plugin.Guid}/{Name}"; public string Url => $"{_pluginsModule.ServerUrl?.TrimEnd('/')}{_pluginsModule.BaseRoute}{PluginFeature.Plugin.Guid}/{Name}";
/// <summary> /// <summary>
/// Gets the plugin the end point is associated with /// Gets the plugin the end point is associated with
@ -45,12 +45,12 @@ namespace Artemis.Core.Services
/// <summary> /// <summary>
/// Gets the mime type of the input this end point accepts /// Gets the mime type of the input this end point accepts
/// </summary> /// </summary>
public string Accepts { get; protected set; } public string? Accepts { get; protected set; }
/// <summary> /// <summary>
/// Gets the mime type of the output this end point returns /// Gets the mime type of the output this end point returns
/// </summary> /// </summary>
public string Returns { get; protected set; } public string? Returns { get; protected set; }
/// <summary> /// <summary>
/// Called whenever the end point has to process a request /// Called whenever the end point has to process a request

View File

@ -235,8 +235,8 @@ namespace Artemis.UI.Shared
UpdateTransform(); UpdateTransform();
// Load the device main image // Load the device main image
if (Device.RgbDevice.DeviceInfo?.Image?.AbsolutePath != null && File.Exists(Device.RgbDevice.DeviceInfo.Image.AbsolutePath)) // if (Device.RgbDevice.DeviceInfo?.Image?.AbsolutePath != null && File.Exists(Device.RgbDevice.DeviceInfo.Image.AbsolutePath))
_deviceImage = new BitmapImage(Device.RgbDevice.DeviceInfo.Image); // _deviceImage = new BitmapImage(Device.RgbDevice.DeviceInfo.Image);
// Create all the LEDs // Create all the LEDs
foreach (ArtemisLed artemisLed in Device.Leds) foreach (ArtemisLed artemisLed in Device.Leds)

View File

@ -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 // ReSharper disable UnusedMember.Global
@ -70,7 +70,7 @@ namespace Artemis.UI.Screens.Settings.Debug
try 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) catch (Exception e)
{ {

View File

@ -14,9 +14,10 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
{ {
private readonly IInputService _inputService; private readonly IInputService _inputService;
private readonly IMessageService _messageService; private readonly IMessageService _messageService;
private readonly IRgbService _rgbService;
private readonly ListLedGroup _ledGroup; private readonly ListLedGroup _ledGroup;
public SurfaceDeviceDetectInputViewModel(ArtemisDevice device, IInputService inputService, IMessageService messageService) public SurfaceDeviceDetectInputViewModel(ArtemisDevice device, IInputService inputService, IMessageService messageService, IRgbService rgbService)
{ {
Device = device; Device = device;
Title = $"{Device.RgbDevice.DeviceInfo.DeviceName} - Detect input"; Title = $"{Device.RgbDevice.DeviceInfo.DeviceName} - Detect input";
@ -24,11 +25,12 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
_inputService = inputService; _inputService = inputService;
_messageService = messageService; _messageService = messageService;
_rgbService = rgbService;
_inputService.IdentifyDevice(Device); _inputService.IdentifyDevice(Device);
_inputService.DeviceIdentified += InputServiceOnDeviceIdentified; _inputService.DeviceIdentified += InputServiceOnDeviceIdentified;
// Create a LED group way at the top // 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)), Brush = new SolidColorBrush(new Color(255, 255, 0)),
ZIndex = 999 ZIndex = 999
@ -43,7 +45,7 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
{ {
base.OnDialogClosed(sender, e); base.OnDialogClosed(sender, e);
_inputService.DeviceIdentified -= InputServiceOnDeviceIdentified; _inputService.DeviceIdentified -= InputServiceOnDeviceIdentified;
_ledGroup.Detach(); _ledGroup.Detach(_rgbService.Surface);
} }
private void InputServiceOnDeviceIdentified(object sender, EventArgs e) private void InputServiceOnDeviceIdentified(object sender, EventArgs e)