From 172219552964ff65fc0a3b9d5a5224c2670e4270 Mon Sep 17 00:00:00 2001 From: Logan Saso Date: Tue, 7 Jun 2016 13:28:27 -0700 Subject: [PATCH] Added spotify support to Windows Profile --- Artemis/Artemis/Artemis.csproj | 4 +++ .../WindowsProfile/WindowsProfileDataModel.cs | 13 ++++++++ .../WindowsProfile/WindowsProfileModel.cs | 33 ++++++++++++++++--- Artemis/Artemis/packages.config | 1 + 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index 9320a58b6..2c146f5fc 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -211,6 +211,10 @@ ..\packages\SharpDX.DXGI.3.0.2\lib\net45\SharpDX.DXGI.dll True + + ..\packages\SpotifyAPI-NET.2.9.0\lib\SpotifyAPI.dll + True + diff --git a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileDataModel.cs b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileDataModel.cs index b1325a3c1..6b35318af 100644 --- a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileDataModel.cs +++ b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileDataModel.cs @@ -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; } + } } \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileModel.cs b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileModel.cs index 8eaef82e3..f550df9c5 100644 --- a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileModel.cs +++ b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileModel.cs @@ -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 _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; + } } } \ No newline at end of file diff --git a/Artemis/Artemis/packages.config b/Artemis/Artemis/packages.config index df6ad5dd7..38d99c3e9 100644 --- a/Artemis/Artemis/packages.config +++ b/Artemis/Artemis/packages.config @@ -23,6 +23,7 @@ +