public void SetActiveSurfaceConfiguration(ArtemisSurface surface) { if (ActiveSurface == surface) return; // Set the new entity ActiveSurface = surface; // Ensure only the new entity is marked as active lock (_surfaceConfigurations) { // Mark only the new surface as active foreach (var configuration in _surfaceConfigurations) { configuration.IsActive = configuration == ActiveSurface; configuration.ApplyToEntity(); _surfaceRepository.Save(configuration.SurfaceEntity); } } // Apply the active surface entity to the devices if (ActiveSurface != null) { foreach (var device in ActiveSurface.Devices) device.ApplyToRgbDevice(); } // Update the RGB service's graphics decorator to work with the new surface entity _rgbService.UpdateSurfaceLedGroup(); OnActiveSurfaceConfigurationChanged(new SurfaceConfigurationEventArgs(ActiveSurface)); }
internal void PopulateLeds(ArtemisSurface surface) { foreach (var layer in GetAllLayers()) { layer.PopulateLeds(surface); } }
public void Initialize() { if (IsInitialized) { throw new ArtemisCoreException("Cannot initialize the core as it is already initialized."); } AssemblyInformationalVersionAttribute?versionAttribute = typeof(CoreService).Assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>(); _logger.Information("Initializing Artemis Core version {version}", versionAttribute?.InformationalVersion); ApplyLoggingLevel(); DeserializationLogger.Initialize(Kernel); // Initialize the services _pluginService.CopyBuiltInPlugins(); _pluginService.LoadPlugins(StartupArguments.Contains("--ignore-plugin-lock")); ArtemisSurface surfaceConfig = _surfaceService.ActiveSurface; if (surfaceConfig != null) { _logger.Information("Initialized with active surface entity {surfaceConfig}-{guid}", surfaceConfig.Name, surfaceConfig.EntityId); } else { _logger.Information("Initialized without an active surface entity"); } PlayIntroAnimation(); OnInitialized(); }
internal async Task ChangeActiveProfileAnimated(Profile profile, ArtemisSurface surface) { if (profile != null && profile.Module != this) { throw new ArtemisCoreException($"Cannot activate a profile of module {profile.Module} on a module of plugin {PluginInfo}."); } if (!IsActivated) { throw new ArtemisCoreException("Cannot activate a profile on a deactivated module"); } if (profile == ActiveProfile || AnimatingProfileChange) { return; } AnimatingProfileChange = true; while (OpacityOverride > 0) { await Task.Delay(50); } ChangeActiveProfile(profile, surface); AnimatingProfileChange = false; while (OpacityOverride < 1) { await Task.Delay(50); } }
internal void ChangeActiveProfile(Profile profile, ArtemisSurface surface) { if (profile != null && profile.Module != this) { throw new ArtemisCoreException($"Cannot activate a profile of module {profile.Module} on a module of plugin {PluginInfo}."); } if (!IsActivated) { throw new ArtemisCoreException("Cannot activate a profile on a deactivated module"); } lock (this) { if (profile == ActiveProfile) { return; } ActiveProfile?.Dispose(); ActiveProfile = profile; ActiveProfile?.Activate(surface); } OnActiveProfileChanged(); }
private void AddDeviceIfMissing(IRGBDevice rgbDevice, ArtemisSurface surface) { string deviceIdentifier = rgbDevice.GetDeviceIdentifier(); ArtemisDevice device = surface.Devices.FirstOrDefault(d => d.DeviceEntity.DeviceIdentifier == deviceIdentifier); if (device != null) { return; } // Find an existing device config and use that DeviceEntity existingDeviceConfig = surface.SurfaceEntity.DeviceEntities.FirstOrDefault(d => d.DeviceIdentifier == deviceIdentifier); if (existingDeviceConfig != null) { Plugin plugin = _pluginService.GetPluginByDevice(rgbDevice); device = new ArtemisDevice(rgbDevice, plugin, surface, existingDeviceConfig); } // Fall back on creating a new device else { _logger.Information( "No device config found for {deviceInfo}, device hash: {deviceHashCode}. Adding a new entry.", rgbDevice.DeviceInfo, deviceIdentifier ); Plugin plugin = _pluginService.GetPluginByDevice(rgbDevice); device = new ArtemisDevice(rgbDevice, plugin, surface); } surface.Devices.Add(device); }
/// <inheritdoc /> public override void Render(double deltaTime, ArtemisSurface surface, SKCanvas canvas) { lock (this) { // Render the profile ActiveProfile?.Render(deltaTime, canvas); } }
private void ActiveProfilesPopulateLeds(ArtemisSurface surface) { var profileModules = _pluginService.GetPluginsOfType <ProfileModule>(); foreach (var profileModule in profileModules.Where(p => p.ActiveProfile != null).ToList()) { profileModule.ActiveProfile.PopulateLeds(surface); } }
internal override void InternalRender(double deltaTime, ArtemisSurface surface, SKCanvas canvas, SKImageInfo canvasInfo) { Render(deltaTime, surface, canvas, canvasInfo); lock (this) { // Render the profile ActiveProfile?.Render(deltaTime, canvas, canvasInfo); } ProfileRendered(deltaTime, surface, canvas, canvasInfo); }
public void DeleteSurfaceConfiguration(ArtemisSurface surface) { if (surface == ActiveSurface) throw new ArtemisCoreException($"Cannot delete surface entity '{surface.Name}' because it is active."); lock (_surfaceConfigurations) { var entity = surface.SurfaceEntity; _surfaceConfigurations.Remove(surface); _surfaceRepository.Remove(entity); } }
internal void Activate(ArtemisSurface surface) { lock (this) { if (IsActivated) { return; } PopulateLeds(surface); OnActivated(); IsActivated = true; } }
public void UpdateSurfaceConfiguration(ArtemisSurface surface, bool includeDevices) { surface.ApplyToEntity(); if (includeDevices) { foreach (var deviceConfiguration in surface.Devices) { deviceConfiguration.ApplyToEntity(); if (surface.IsActive) deviceConfiguration.ApplyToRgbDevice(); } } _surfaceRepository.Save(surface.SurfaceEntity); _rgbService.UpdateSurfaceLedGroup(); OnSurfaceConfigurationUpdated(new SurfaceConfigurationEventArgs(surface)); }
private void LoadFromRepository() { List <SurfaceEntity> configs = _surfaceRepository.GetAll(); foreach (SurfaceEntity surfaceEntity in configs) { // Create the surface entity ArtemisSurface surfaceConfiguration = new ArtemisSurface(_rgbService.Surface, surfaceEntity, _renderScaleSetting.Value); foreach (DeviceEntity position in surfaceEntity.DeviceEntities) { IRGBDevice device = _rgbService.Surface.Devices.FirstOrDefault(d => d.GetDeviceIdentifier() == position.DeviceIdentifier); if (device != null) { Plugin plugin = _pluginService.GetPluginByDevice(device); surfaceConfiguration.Devices.Add(new ArtemisDevice(device, plugin, surfaceConfiguration, position)); } } // Finally, add the surface config to the collection lock (_surfaceConfigurations) { _surfaceConfigurations.Add(surfaceConfiguration); } } // When all surface configs are loaded, apply the active surface config ArtemisSurface active = SurfaceConfigurations.FirstOrDefault(c => c.IsActive); if (active != null) { SetActiveSurfaceConfiguration(active); } else { active = SurfaceConfigurations.FirstOrDefault(); if (active != null) { SetActiveSurfaceConfiguration(active); } else { SetActiveSurfaceConfiguration(CreateSurfaceConfiguration("Default")); } } }
public ArtemisSurface CreateSurfaceConfiguration(string name) { // Create a blank config ArtemisSurface configuration = new ArtemisSurface(_rgbService.Surface, name, _renderScaleSetting.Value); // Add all current devices foreach (IRGBDevice rgbDevice in _rgbService.LoadedDevices) { Plugin plugin = _pluginService.GetPluginByDevice(rgbDevice); configuration.Devices.Add(new ArtemisDevice(rgbDevice, plugin, configuration)); } lock (_surfaceConfigurations) { _surfaceRepository.Add(configuration.SurfaceEntity); _surfaceConfigurations.Add(configuration); UpdateSurfaceConfiguration(configuration, true); return(configuration); } }
internal void ChangeActiveProfile(Profile profile, ArtemisSurface surface) { if (profile != null && profile.PluginInfo != PluginInfo) { throw new ArtemisCoreException($"Cannot activate a profile of plugin {profile.PluginInfo} on a module of plugin {PluginInfo}."); } lock (this) { if (profile == ActiveProfile) { return; } ActiveProfile?.Deactivate(); ActiveProfile = profile; ActiveProfile?.Activate(surface); } OnActiveProfileChanged(); }
private void LoadFromRepository() { var configs = _surfaceRepository.GetAll(); foreach (var surfaceEntity in configs) { // Create the surface entity var surfaceConfiguration = new ArtemisSurface(_rgbService.Surface, surfaceEntity, _renderScaleSetting.Value); foreach (var position in surfaceEntity.DeviceEntities) { var device = _rgbService.Surface.Devices.FirstOrDefault(d => d.GetDeviceHashCode() == position.DeviceHashCode); if (device != null) { var plugin = _pluginService.GetDevicePlugin(device); surfaceConfiguration.Devices.Add(new ArtemisDevice(device, plugin, surfaceConfiguration, position)); } } // Finally, add the surface config to the collection lock (_surfaceConfigurations) { _surfaceConfigurations.Add(surfaceConfiguration); } } // When all surface configs are loaded, apply the active surface config var active = SurfaceConfigurations.FirstOrDefault(c => c.IsActive); if (active != null) SetActiveSurfaceConfiguration(active); else { active = SurfaceConfigurations.FirstOrDefault(); if (active != null) SetActiveSurfaceConfiguration(active); else SetActiveSurfaceConfiguration(CreateSurfaceConfiguration("Default")); } }
public override void Render(double deltaTime, ArtemisSurface surface, SKCanvas canvas, SKImageInfo canvasInfo) { }
/// <summary> /// Called each frame when the module should render /// </summary> /// <param name="deltaTime">Time since the last render</param> /// <param name="surface">The RGB Surface to render to</param> /// <param name="canvas"></param> /// <param name="canvasInfo"></param> public abstract void Render(double deltaTime, ArtemisSurface surface, SKCanvas canvas, SKImageInfo canvasInfo);
internal virtual void InternalRender(double deltaTime, ArtemisSurface surface, SKCanvas canvas, SKImageInfo canvasInfo) { Render(deltaTime, surface, canvas, canvasInfo); }
/// <summary> /// Called each frame when the module must render /// </summary> /// <param name="deltaTime">Time since the last render</param> /// <param name="surface">The RGB Surface to render to</param> /// <param name="canvas"></param> public abstract void Render(double deltaTime, ArtemisSurface surface, SKCanvas canvas);
/// <summary> /// Called after the profile has rendered /// </summary> /// <param name="deltaTime">Time since the last render</param> /// <param name="surface">The RGB Surface to render to</param> /// <param name="canvas"></param> /// <param name="canvasInfo"></param> public virtual void ProfileRendered(double deltaTime, ArtemisSurface surface, SKCanvas canvas, SKImageInfo canvasInfo) { }
public SurfaceConfigurationEventArgs(ArtemisSurface surface) { Surface = surface; }