Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
 internal void PopulateLeds(ArtemisSurface surface)
 {
     foreach (var layer in GetAllLayers())
     {
         layer.PopulateLeds(surface);
     }
 }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
0
        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();
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
 /// <inheritdoc />
 public override void Render(double deltaTime, ArtemisSurface surface, SKCanvas canvas)
 {
     lock (this)
     {
         // Render the profile
         ActiveProfile?.Render(deltaTime, canvas);
     }
 }
Exemplo n.º 8
0
        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);
            }
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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);
            }
        }
Exemplo n.º 11
0
        internal void Activate(ArtemisSurface surface)
        {
            lock (this)
            {
                if (IsActivated)
                {
                    return;
                }

                PopulateLeds(surface);
                OnActivated();
                IsActivated = true;
            }
        }
Exemplo n.º 12
0
        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));
        }
Exemplo n.º 13
0
        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"));
                }
            }
        }
Exemplo n.º 14
0
        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);
            }
        }
Exemplo n.º 15
0
        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();
        }
Exemplo n.º 16
0
        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"));
            }
        }
Exemplo n.º 17
0
 public override void Render(double deltaTime, ArtemisSurface surface, SKCanvas canvas, SKImageInfo canvasInfo)
 {
 }
Exemplo n.º 18
0
 /// <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);
Exemplo n.º 19
0
 internal virtual void InternalRender(double deltaTime, ArtemisSurface surface, SKCanvas canvas, SKImageInfo canvasInfo)
 {
     Render(deltaTime, surface, canvas, canvasInfo);
 }
Exemplo n.º 20
0
 /// <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);
Exemplo n.º 21
0
 /// <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)
 {
 }
Exemplo n.º 22
0
 public SurfaceConfigurationEventArgs(ArtemisSurface surface)
 {
     Surface = surface;
 }