mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Fixed animation speed doubling at certain times. Fixed Spotify null reference
This commit is contained in:
parent
1722195529
commit
04497a10e5
@ -8,6 +8,7 @@ namespace Artemis.InjectionModules
|
|||||||
public override void Load()
|
public override void Load()
|
||||||
{
|
{
|
||||||
Bind<MainManager>().ToSelf().InSingletonScope();
|
Bind<MainManager>().ToSelf().InSingletonScope();
|
||||||
|
Bind<LoopManager>().ToSelf().InSingletonScope();
|
||||||
Bind<DeviceManager>().ToSelf().InSingletonScope();
|
Bind<DeviceManager>().ToSelf().InSingletonScope();
|
||||||
Bind<EffectManager>().ToSelf().InSingletonScope();
|
Bind<EffectManager>().ToSelf().InSingletonScope();
|
||||||
Bind<ProfileManager>().ToSelf().InSingletonScope();
|
Bind<ProfileManager>().ToSelf().InSingletonScope();
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
using Artemis.Events;
|
|
||||||
using Caliburn.Micro;
|
using Caliburn.Micro;
|
||||||
using Ninject.Extensions.Logging;
|
using Ninject.Extensions.Logging;
|
||||||
|
using Brush = System.Windows.Media.Brush;
|
||||||
|
|
||||||
namespace Artemis.Managers
|
namespace Artemis.Managers
|
||||||
{
|
{
|
||||||
@ -13,11 +14,12 @@ namespace Artemis.Managers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class LoopManager : IDisposable
|
public class LoopManager : IDisposable
|
||||||
{
|
{
|
||||||
|
private readonly DeviceManager _deviceManager;
|
||||||
private readonly EffectManager _effectManager;
|
private readonly EffectManager _effectManager;
|
||||||
private readonly IEventAggregator _events;
|
private readonly IEventAggregator _events;
|
||||||
private readonly DeviceManager _deviceManager;
|
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly Timer _loopTimer;
|
private readonly Timer _loopTimer;
|
||||||
|
private int _fpsCount;
|
||||||
|
|
||||||
public LoopManager(ILogger logger, IEventAggregator events, EffectManager effectManager,
|
public LoopManager(ILogger logger, IEventAggregator events, EffectManager effectManager,
|
||||||
DeviceManager deviceManager)
|
DeviceManager deviceManager)
|
||||||
@ -27,9 +29,18 @@ namespace Artemis.Managers
|
|||||||
_effectManager = effectManager;
|
_effectManager = effectManager;
|
||||||
_deviceManager = deviceManager;
|
_deviceManager = deviceManager;
|
||||||
|
|
||||||
|
// Setup timers
|
||||||
_loopTimer = new Timer(40);
|
_loopTimer = new Timer(40);
|
||||||
_loopTimer.Elapsed += Render;
|
_loopTimer.Elapsed += Render;
|
||||||
_loopTimer.Start();
|
_loopTimer.Start();
|
||||||
|
|
||||||
|
var fpsTimer = new Timer(1000);
|
||||||
|
fpsTimer.Elapsed += delegate
|
||||||
|
{
|
||||||
|
Debug.WriteLine(_fpsCount);
|
||||||
|
_fpsCount = 0;
|
||||||
|
};
|
||||||
|
fpsTimer.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -121,8 +132,8 @@ namespace Artemis.Managers
|
|||||||
|
|
||||||
// Get ActiveEffect's bitmap
|
// Get ActiveEffect's bitmap
|
||||||
Bitmap bitmap = null;
|
Bitmap bitmap = null;
|
||||||
System.Windows.Media.Brush mouseBrush = null;
|
Brush mouseBrush = null;
|
||||||
System.Windows.Media.Brush headsetBrush = null;
|
Brush headsetBrush = null;
|
||||||
var mice = _deviceManager.MiceProviders.Where(m => m.CanUse).ToList();
|
var mice = _deviceManager.MiceProviders.Where(m => m.CanUse).ToList();
|
||||||
var headsets = _deviceManager.HeadsetProviders.Where(m => m.CanUse).ToList();
|
var headsets = _deviceManager.HeadsetProviders.Where(m => m.CanUse).ToList();
|
||||||
|
|
||||||
@ -144,7 +155,10 @@ namespace Artemis.Managers
|
|||||||
|
|
||||||
// If no bitmap was generated this frame is done
|
// If no bitmap was generated this frame is done
|
||||||
if (bitmap == null)
|
if (bitmap == null)
|
||||||
|
{
|
||||||
|
_fpsCount++;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Fill the bitmap's background with black to avoid trailing colors on some keyboards
|
// Fill the bitmap's background with black to avoid trailing colors on some keyboards
|
||||||
var fixedBmp = new Bitmap(bitmap.Width, bitmap.Height);
|
var fixedBmp = new Bitmap(bitmap.Width, bitmap.Height);
|
||||||
@ -158,6 +172,8 @@ namespace Artemis.Managers
|
|||||||
|
|
||||||
// Update the keyboard
|
// Update the keyboard
|
||||||
_deviceManager.ActiveKeyboard?.DrawBitmap(bitmap);
|
_deviceManager.ActiveKeyboard?.DrawBitmap(bitmap);
|
||||||
|
|
||||||
|
_fpsCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
using Artemis.Models;
|
|
||||||
using Artemis.Modules.Effects.ProfilePreview;
|
using Artemis.Modules.Effects.ProfilePreview;
|
||||||
using Artemis.Settings;
|
using Artemis.Settings;
|
||||||
using Artemis.ViewModels.Abstract;
|
using Artemis.ViewModels.Abstract;
|
||||||
@ -15,7 +14,6 @@ namespace Artemis.Managers
|
|||||||
private readonly EffectManager _effectManager;
|
private readonly EffectManager _effectManager;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly LoopManager _loopManager;
|
private readonly LoopManager _loopManager;
|
||||||
private EffectModel _prePreviewEffect;
|
|
||||||
|
|
||||||
public ProfileManager(ILogger logger, EffectManager effectManager, DeviceManager deviceManager,
|
public ProfileManager(ILogger logger, EffectManager effectManager, DeviceManager deviceManager,
|
||||||
LoopManager loopManager)
|
LoopManager loopManager)
|
||||||
@ -54,21 +52,18 @@ namespace Artemis.Managers
|
|||||||
if (_effectManager.ActiveEffect != ProfilePreviewModel)
|
if (_effectManager.ActiveEffect != ProfilePreviewModel)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_logger.Debug("Clear effect after profile preview");
|
_logger.Debug("Loading last effect after profile preview");
|
||||||
_effectManager.ClearEffect();
|
var lastEffect = _effectManager.GetLastEffect();
|
||||||
|
if (lastEffect != null)
|
||||||
if (_prePreviewEffect == null || _prePreviewEffect is GameModel)
|
_effectManager.ChangeEffect(lastEffect);
|
||||||
return;
|
else
|
||||||
|
_effectManager.ClearEffect();
|
||||||
_logger.Debug("Change back effect after profile preview");
|
|
||||||
_effectManager.ChangeEffect(_prePreviewEffect);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (_effectManager.ActiveEffect != ProfilePreviewModel)
|
if (_effectManager.ActiveEffect != ProfilePreviewModel)
|
||||||
{
|
{
|
||||||
_logger.Debug("Activate profile preview");
|
_logger.Debug("Activate profile preview");
|
||||||
_prePreviewEffect = _effectManager.ActiveEffect;
|
|
||||||
_effectManager.ChangeEffect(ProfilePreviewModel);
|
_effectManager.ChangeEffect(ProfilePreviewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,10 @@ namespace Artemis.Models
|
|||||||
DataModel = dataModel;
|
DataModel = dataModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Used by profile system
|
||||||
|
public IDataModel DataModel { get; set; }
|
||||||
|
public ProfileModel Profile { get; set; }
|
||||||
|
|
||||||
public abstract void Dispose();
|
public abstract void Dispose();
|
||||||
|
|
||||||
// Called on creation
|
// Called on creation
|
||||||
@ -31,12 +35,9 @@ namespace Artemis.Models
|
|||||||
// Called every frame
|
// Called every frame
|
||||||
public abstract void Update();
|
public abstract void Update();
|
||||||
|
|
||||||
// Used by profile system
|
|
||||||
public IDataModel DataModel { get; set; }
|
|
||||||
public ProfileModel Profile { get; set; }
|
|
||||||
|
|
||||||
// Called after every update
|
// Called after every update
|
||||||
public virtual void Render(out Bitmap keyboard, out Brush mouse, out Brush headset, bool renderMice, bool renderHeadsets)
|
public virtual void Render(out Bitmap keyboard, out Brush mouse, out Brush headset, bool renderMice,
|
||||||
|
bool renderHeadsets)
|
||||||
{
|
{
|
||||||
keyboard = null;
|
keyboard = null;
|
||||||
mouse = null;
|
mouse = null;
|
||||||
@ -49,7 +50,8 @@ namespace Artemis.Models
|
|||||||
var renderLayers = GetRenderLayers(renderMice, renderHeadsets);
|
var renderLayers = GetRenderLayers(renderMice, renderHeadsets);
|
||||||
|
|
||||||
// Render the keyboard layer-by-layer
|
// Render the keyboard layer-by-layer
|
||||||
keyboard = Profile.GenerateBitmap(renderLayers, DataModel, MainManager.DeviceManager.ActiveKeyboard.KeyboardRectangle(4), false, true);
|
keyboard = Profile.GenerateBitmap(renderLayers, DataModel,
|
||||||
|
MainManager.DeviceManager.ActiveKeyboard.KeyboardRectangle(4), false, true);
|
||||||
// Render the first enabled mouse (will default to null if renderMice was false)
|
// Render the first enabled mouse (will default to null if renderMice was false)
|
||||||
mouse = Profile.GenerateBrush(renderLayers.LastOrDefault(l => l.LayerType == LayerType.Mouse), DataModel);
|
mouse = Profile.GenerateBrush(renderLayers.LastOrDefault(l => l.LayerType == LayerType.Mouse), DataModel);
|
||||||
// Render the first enabled headset (will default to null if renderHeadsets was false)
|
// Render the first enabled headset (will default to null if renderHeadsets was false)
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using Artemis.Models.Interfaces;
|
using Artemis.Models.Interfaces;
|
||||||
|
using SpotifyAPI.Local.Models;
|
||||||
|
|
||||||
namespace Artemis.Modules.Effects.WindowsProfile
|
namespace Artemis.Modules.Effects.WindowsProfile
|
||||||
{
|
{
|
||||||
@ -27,6 +28,7 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
|||||||
}
|
}
|
||||||
public class Spotify
|
public class Spotify
|
||||||
{
|
{
|
||||||
|
public bool Running { get; set; }
|
||||||
public string Artist { get; set; }
|
public string Artist { get; set; }
|
||||||
public string SongName { get; set; }
|
public string SongName { get; set; }
|
||||||
public int SongPercentCompleted { get; set; }
|
public int SongPercentCompleted { get; set; }
|
||||||
|
|||||||
@ -105,16 +105,25 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
|||||||
{
|
{
|
||||||
StatusResponse status = _spotify.GetStatus();
|
StatusResponse status = _spotify.GetStatus();
|
||||||
if (status == null)
|
if (status == null)
|
||||||
|
{
|
||||||
|
dataModel.Spotify.Running = false;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
dataModel.Spotify.Artist = status.Track.ArtistResource.Name;
|
dataModel.Spotify.Running = true;
|
||||||
dataModel.Spotify.SongName = status.Track.TrackResource.Name;
|
|
||||||
dataModel.Spotify.SongPercentCompleted = (int) (status.PlayingPosition/status.Track.Length*100.0);
|
|
||||||
dataModel.Spotify.SpotifyVolume = (int)(status.Volume * 100);
|
dataModel.Spotify.SpotifyVolume = (int)(status.Volume * 100);
|
||||||
dataModel.Spotify.Album = status.Track.AlbumResource.Name;
|
|
||||||
dataModel.Spotify.Repeat = status.Repeat;
|
dataModel.Spotify.Repeat = status.Repeat;
|
||||||
dataModel.Spotify.Shuffle = status.Shuffle;
|
dataModel.Spotify.Shuffle = status.Shuffle;
|
||||||
dataModel.Spotify.Playing = status.Playing;
|
dataModel.Spotify.Playing = status.Playing;
|
||||||
|
|
||||||
|
// Only update track info if not null
|
||||||
|
if (status.Track == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
dataModel.Spotify.Artist = status.Track.ArtistResource?.Name;
|
||||||
|
dataModel.Spotify.SongName = status.Track.TrackResource?.Name;
|
||||||
|
dataModel.Spotify.SongPercentCompleted = (int)(status.PlayingPosition / status.Track.Length * 100.0);
|
||||||
|
dataModel.Spotify.Album = status.Track.AlbumResource?.Name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2,6 +2,7 @@
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Timers;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
using Artemis.Models.Interfaces;
|
using Artemis.Models.Interfaces;
|
||||||
using Artemis.Models.Profiles;
|
using Artemis.Models.Profiles;
|
||||||
@ -40,6 +41,7 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
.Select(c => new LayerConditionViewModel(this, c, DataModelProps)));
|
.Select(c => new LayerConditionViewModel(this, c, DataModelProps)));
|
||||||
|
|
||||||
PropertyChanged += PropertiesViewModelHandler;
|
PropertyChanged += PropertiesViewModelHandler;
|
||||||
|
|
||||||
PreSelect();
|
PreSelect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user