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

Added spotify support to Windows Profile

This commit is contained in:
Logan Saso 2016-06-07 13:28:27 -07:00
parent be70786319
commit 1722195529
4 changed files with 47 additions and 4 deletions

View File

@ -211,6 +211,10 @@
<HintPath>..\packages\SharpDX.DXGI.3.0.2\lib\net45\SharpDX.DXGI.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SpotifyAPI, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SpotifyAPI-NET.2.9.0\lib\SpotifyAPI.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Data" />

View File

@ -5,9 +5,11 @@ namespace Artemis.Modules.Effects.WindowsProfile
public class WindowsProfileDataModel : IDataModel
{
public CpuDataModel Cpu { get; set; }
public Spotify Spotify { get; set; }
public WindowsProfileDataModel()
{
Spotify = new Spotify();
Cpu = new CpuDataModel();
}
}
@ -23,4 +25,15 @@ namespace Artemis.Modules.Effects.WindowsProfile
public int Core7Usage { get; set; }
public int Core8Usage { get; set; }
}
public class Spotify
{
public string Artist { get; set; }
public string SongName { get; set; }
public int SongPercentCompleted { get; set; }
public int SpotifyVolume { get; set; }
public string Album { get; set; }
public bool Repeat { get; set; }
public bool Shuffle { get; set; }
public bool Playing { get; set; }
}
}

View File

@ -4,6 +4,8 @@ using System.Diagnostics;
using Artemis.Managers;
using Artemis.Models;
using Artemis.Models.Profiles;
using SpotifyAPI.Local;
using SpotifyAPI.Local.Models;
namespace Artemis.Modules.Effects.WindowsProfile
{
@ -11,12 +13,14 @@ namespace Artemis.Modules.Effects.WindowsProfile
{
private List<PerformanceCounter> _cores;
private int _cpuFrames;
private readonly SpotifyLocalAPI _spotify;
public WindowsProfileModel(MainManager mainManager, WindowsProfileSettings settings)
: base(mainManager, new WindowsProfileDataModel())
{
Name = "WindowsProfile";
Settings = settings;
_spotify = new SpotifyLocalAPI();
}
public WindowsProfileSettings Settings { get; set; }
@ -37,15 +41,22 @@ namespace Artemis.Modules.Effects.WindowsProfile
coreCount++;
}
if (SpotifyLocalAPI.IsSpotifyRunning())
{
_spotify.Connect();
}
Initialized = true;
}
public override void Update()
{
UpdateCpu();
var dataModel = (WindowsProfileDataModel) DataModel;
UpdateCpu(dataModel);
UpdateSpotify(dataModel);
}
private void UpdateCpu()
private void UpdateCpu(WindowsProfileDataModel dataModel)
{
// CPU is only updated every 15 frames, the performance counter gives 0 if updated too often
_cpuFrames++;
@ -54,8 +65,6 @@ namespace Artemis.Modules.Effects.WindowsProfile
_cpuFrames = 0;
var dataModel = (WindowsProfileDataModel)DataModel;
// Update cores, not ideal but data models don't support lists.
if (_cores[0] != null)
dataModel.Cpu.Core1Usage = (int)_cores[0].NextValue();
@ -91,5 +100,21 @@ namespace Artemis.Modules.Effects.WindowsProfile
}
return performanceCounters;
}
public void UpdateSpotify(WindowsProfileDataModel dataModel)
{
StatusResponse status = _spotify.GetStatus();
if (status == 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.SpotifyVolume = (int)(status.Volume * 100);
dataModel.Spotify.Album = status.Track.AlbumResource.Name;
dataModel.Spotify.Repeat = status.Repeat;
dataModel.Spotify.Shuffle = status.Shuffle;
dataModel.Spotify.Playing = status.Playing;
}
}
}

View File

@ -23,6 +23,7 @@
<package id="SharpDX" version="3.0.2" targetFramework="net452" />
<package id="SharpDX.Direct3D11" version="3.0.2" targetFramework="net452" />
<package id="SharpDX.DXGI" version="3.0.2" targetFramework="net452" />
<package id="SpotifyAPI-NET" version="2.9.0" targetFramework="net452" />
<package id="System.Linq.Dynamic" version="1.0.6" targetFramework="net452" />
<package id="VirtualInput" version="1.0.1" targetFramework="net452" />
<package id="WpfExceptionViewer" version="1.0.0.0" targetFramework="net452" />