From 943f6a4f931b9d411e22129f2ca11eef2c859210 Mon Sep 17 00:00:00 2001 From: Cheerpipe Date: Fri, 20 Aug 2021 11:59:49 -0400 Subject: [PATCH 1/7] Peak volume per audio sessions --- .../DataModels/PlaybackVolumeDataModel.cs | 17 +++++++- .../PlaybackVolumeModule.cs | 43 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/DataModels/PlaybackVolumeDataModel.cs b/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/DataModels/PlaybackVolumeDataModel.cs index 21fa96aa..284b4e2b 100644 --- a/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/DataModels/PlaybackVolumeDataModel.cs +++ b/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/DataModels/PlaybackVolumeDataModel.cs @@ -2,12 +2,13 @@ using Artemis.Core; using Artemis.Core.Modules; using NAudio.CoreAudioApi; +using NAudio.CoreAudioApi.Interfaces; namespace Artemis.Plugins.Audio.DataModelExpansion.DataModels { public class PlaybackVolumeDataModel : DataModel { - [DataModelProperty(Description ="Name of the current playback device.")] + [DataModelProperty(Description = "Name of the current playback device.")] public string DefaultDeviceName { get; set; } [DataModelProperty(Description = "Channel count of the the current playback device.")] public int ChannelCount { get; set; } @@ -32,6 +33,7 @@ public class PlaybackVolumeDataModel : DataModel [DataModelProperty(Description = "Event triggered when current playback device master volume is changed.")] public DataModelEvent VolumeChanged { get; set; } = new DataModelEvent(); public ChannelsDataModel Channels { get; set; } = new ChannelsDataModel(); + public SessionsDataModel Sessions { get; set; } = new SessionsDataModel(); public void Reset() { @@ -49,6 +51,19 @@ public void Reset() } public class ChannelsDataModel : DataModel { } + + public class SessionsDataModel : DataModel { } + + public class SessionDataModel : DataModel + { + public string Id { get; set; } + public string Name { get; set; } + public AudioSessionState? State { get; set; } + public float PeakVolume { get; set; } + public float PeakVolumeNormalized { get; set; } + public string debugData { get; set; } + } + public class ChannelDataModel : DataModel { public int ChannelIndex { get; set; } diff --git a/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/PlaybackVolumeModule.cs b/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/PlaybackVolumeModule.cs index f195b89d..6e70b232 100644 --- a/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/PlaybackVolumeModule.cs +++ b/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/PlaybackVolumeModule.cs @@ -119,6 +119,49 @@ private void UpdatePeakVolume(double deltaTime) channelDataModel.Value.PeakVolumeNormalized = channelsVolumeNormalized[i]; channelDataModel.Value.PeakVolume = channelsVolumeNormalized[i] * 100f; } + + // Populate Sessions DataModel + var audioSessions = _playbackDevice?.AudioSessionManager.Sessions; + for (int i = 0; i < audioSessions.Count; i++) + { + var session = audioSessions[i]; + // Don't waste resources parsing system sessions data + if (session.IsSystemSoundsSession) + continue; + + var slices = session.GetSessionInstanceIdentifier.Split("%b"); + string key = slices[2]; + string name = System.IO.Path.GetFileNameWithoutExtension(slices[0]); + + // Ignore sessions without name. It may be a valid session but without a name it is useless for conditions system + if (string.IsNullOrEmpty(name) || !int.TryParse(key, out _)) + continue; + + if (DataModel.Sessions.TryGetDynamicChild(key, out DynamicChild sessionDataModel)) + { + sessionDataModel.Value.Id = key; + sessionDataModel.Value.Name = name; + sessionDataModel.Value.State = session.State; + sessionDataModel.Value.PeakVolume = session.AudioMeterInformation.MasterPeakValue; + sessionDataModel.Value.PeakVolumeNormalized = session.AudioMeterInformation.MasterPeakValue / 100; + sessionDataModel.Value.debugData = session.GetSessionInstanceIdentifier; + } + else + { + DataModel.Sessions.AddDynamicChild( + key, + new SessionDataModel() + { + Id = key, + Name = name, + State = _playbackDevice?.AudioSessionManager.Sessions[i].State, + PeakVolume = _playbackDevice?.AudioSessionManager.Sessions[i].AudioMeterInformation.MasterPeakValue ?? 0, + PeakVolumeNormalized = _playbackDevice?.AudioSessionManager.Sessions[i].AudioMeterInformation.MasterPeakValue / 100 ?? 0 + }, + name + ); + } + } } } From 76b3f8834300252ff2edd7fc73357d2e437fd3ef Mon Sep 17 00:00:00 2001 From: Cheerpipe Date: Fri, 20 Aug 2021 13:04:49 -0400 Subject: [PATCH 2/7] Code Optimize Thanks to Darth Affe for their span thing sorcery --- .../DataModels/PlaybackVolumeDataModel.cs | 3 +- .../PlaybackVolumeModule.cs | 30 ++++++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/DataModels/PlaybackVolumeDataModel.cs b/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/DataModels/PlaybackVolumeDataModel.cs index 284b4e2b..8e3d339f 100644 --- a/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/DataModels/PlaybackVolumeDataModel.cs +++ b/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/DataModels/PlaybackVolumeDataModel.cs @@ -56,12 +56,11 @@ public class SessionsDataModel : DataModel { } public class SessionDataModel : DataModel { - public string Id { get; set; } + public uint Id { get; set; } public string Name { get; set; } public AudioSessionState? State { get; set; } public float PeakVolume { get; set; } public float PeakVolumeNormalized { get; set; } - public string debugData { get; set; } } public class ChannelDataModel : DataModel diff --git a/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/PlaybackVolumeModule.cs b/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/PlaybackVolumeModule.cs index 6e70b232..c2e2e450 100644 --- a/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/PlaybackVolumeModule.cs +++ b/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/PlaybackVolumeModule.cs @@ -129,30 +129,38 @@ private void UpdatePeakVolume(double deltaTime) if (session.IsSystemSoundsSession) continue; - var slices = session.GetSessionInstanceIdentifier.Split("%b"); - string key = slices[2]; - string name = System.IO.Path.GetFileNameWithoutExtension(slices[0]); + // Span Code thanks to Darth Affe https://github.com/DarthAffe + ReadOnlySpan data = session.GetSessionInstanceIdentifier.AsSpan(); + int pidStart = data.LastIndexOf("%") + 2; + int nameStart = data.LastIndexOf("\\") + 1; + + ReadOnlySpan nameSlice = data.Slice(nameStart); + int nameEnd = nameSlice.LastIndexOf("."); + string name = nameSlice.Slice(0, nameEnd).ToString(); // Ignore sessions without name. It may be a valid session but without a name it is useless for conditions system - if (string.IsNullOrEmpty(name) || !int.TryParse(key, out _)) + if (string.IsNullOrEmpty(name)) + continue; + + if (!uint.TryParse(data.Slice(pidStart), out uint pid)) continue; - if (DataModel.Sessions.TryGetDynamicChild(key, out DynamicChild sessionDataModel)) + // Don't remove unused sessions as these becomes just inactive for a while. It is faster to keep them than scan and remove them. + if (DataModel.Sessions.TryGetDynamicChild(pid.ToString(), out DynamicChild sessionDataModel)) { - sessionDataModel.Value.Id = key; + sessionDataModel.Value.Id = pid; sessionDataModel.Value.Name = name; sessionDataModel.Value.State = session.State; - sessionDataModel.Value.PeakVolume = session.AudioMeterInformation.MasterPeakValue; - sessionDataModel.Value.PeakVolumeNormalized = session.AudioMeterInformation.MasterPeakValue / 100; - sessionDataModel.Value.debugData = session.GetSessionInstanceIdentifier; + sessionDataModel.Value.PeakVolume = session.AudioMeterInformation.MasterPeakValue * 100; + sessionDataModel.Value.PeakVolumeNormalized = session.AudioMeterInformation.MasterPeakValue; } else { DataModel.Sessions.AddDynamicChild( - key, + pid.ToString(), new SessionDataModel() { - Id = key, + Id = pid, Name = name, State = _playbackDevice?.AudioSessionManager.Sessions[i].State, PeakVolume = _playbackDevice?.AudioSessionManager.Sessions[i].AudioMeterInformation.MasterPeakValue ?? 0, From 5e9fe316af1e9e6901b44e6a5518b4ceebc3bcc8 Mon Sep 17 00:00:00 2001 From: Cheerpipe Date: Fri, 20 Aug 2021 14:51:35 -0400 Subject: [PATCH 3/7] Dummy sessions for plugin startup --- .../DataModels/PlaybackVolumeDataModel.cs | 1 - .../PlaybackVolumeModule.cs | 74 ++++++++++++++++--- 2 files changed, 62 insertions(+), 13 deletions(-) diff --git a/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/DataModels/PlaybackVolumeDataModel.cs b/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/DataModels/PlaybackVolumeDataModel.cs index 8e3d339f..e1a8ce7c 100644 --- a/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/DataModels/PlaybackVolumeDataModel.cs +++ b/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/DataModels/PlaybackVolumeDataModel.cs @@ -56,7 +56,6 @@ public class SessionsDataModel : DataModel { } public class SessionDataModel : DataModel { - public uint Id { get; set; } public string Name { get; set; } public AudioSessionState? State { get; set; } public float PeakVolume { get; set; } diff --git a/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/PlaybackVolumeModule.cs b/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/PlaybackVolumeModule.cs index c2e2e450..098fad84 100644 --- a/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/PlaybackVolumeModule.cs +++ b/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/PlaybackVolumeModule.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Artemis.Core; using Artemis.Core.Modules; using Artemis.Plugins.Audio.DataModelExpansion.DataModels; @@ -16,10 +17,11 @@ public class PlaybackVolumeModule : Module #region Constructor - public PlaybackVolumeModule(ILogger logger, NAudioDeviceEnumerationService naudioDeviceEnumerationService) + public PlaybackVolumeModule(ILogger logger, NAudioDeviceEnumerationService naudioDeviceEnumerationService, PluginSettings pluginSettings) { _logger = logger; _naudioDeviceEnumerationService = naudioDeviceEnumerationService; + _savedSessionsSetting = pluginSettings.GetSetting("SavedSessionsSetting", new HashSet()); } #endregion @@ -30,6 +32,7 @@ public PlaybackVolumeModule(ILogger logger, NAudioDeviceEnumerationService naudi private readonly ILogger _logger; private readonly object _audioEventLock = new(); private readonly List> _channelsDataModels = new(); + private readonly PluginSetting> _savedSessionsSetting; private bool _playbackDeviceChanged; private float _lastMasterPeakVolumeNormalized; private MMDevice _playbackDevice; @@ -46,6 +49,55 @@ public override void Enable() // We don't need mor than ~30 updates per second. It will keep CPU usage controlled. 60 or more updates per second could rise cpu usage AddTimedUpdate(TimeSpan.FromMilliseconds(33), UpdatePeakVolume, "UpdatePeakVolume"); + + LoadInUseSessions(); + + DataModel.ActivePathAdded += DataModel_ActivePathAdded; + DataModel.ActivePathRemoved += DataModel_ActivePathRemoved; + } + + private void LoadInUseSessions() + { + // We need to create used sessions datamodels before plugin is enabled or the conditions system will be set these conditions as invalid. + // Just create a default session datamodel for each used session. + + foreach (var sName in _savedSessionsSetting.Value) + { + DataModel.Sessions.AddDynamicChild( + sName, + new SessionDataModel() + { + Name = sName, + State = NAudio.CoreAudioApi.Interfaces.AudioSessionState.AudioSessionStateInactive, + PeakVolume = 0, + PeakVolumeNormalized = 0 + }, + sName + ); + } + } + + private void DataModel_ActivePathRemoved(object sender, DataModelPathEventArgs e) + { + if (e.DataModelPath.Path.StartsWith("Sessions.")) + { + string sName = e.DataModelPath.Path.Split(".")[1]; + if (DataModel.ActivePaths.Count(p => p.Path.Contains($".{sName}.")) <= 1) + { + _ = _savedSessionsSetting.Value.Remove(sName); + _savedSessionsSetting.Save(); + } + } + } + + private void DataModel_ActivePathAdded(object sender, DataModelPathEventArgs e) + { + if (e.DataModelPath.Path.StartsWith("Sessions.")) + { + string sName = e.DataModelPath.Path.Split(".")[1]; + _ = _savedSessionsSetting.Value.Add(sName); + _savedSessionsSetting.Save(); + } } public override void Disable() @@ -120,11 +172,12 @@ private void UpdatePeakVolume(double deltaTime) channelDataModel.Value.PeakVolume = channelsVolumeNormalized[i] * 100f; } - // Populate Sessions DataModel + // Populate Sessions DataModel. Note that if the node don't exists, conditions using these values will become invalid var audioSessions = _playbackDevice?.AudioSessionManager.Sessions; for (int i = 0; i < audioSessions.Count; i++) { var session = audioSessions[i]; + // Don't waste resources parsing system sessions data if (session.IsSystemSoundsSession) continue; @@ -137,18 +190,16 @@ private void UpdatePeakVolume(double deltaTime) ReadOnlySpan nameSlice = data.Slice(nameStart); int nameEnd = nameSlice.LastIndexOf("."); string name = nameSlice.Slice(0, nameEnd).ToString(); + if (!uint.TryParse(data.Slice(pidStart), out uint pid)) + continue; // Ignore sessions without name. It may be a valid session but without a name it is useless for conditions system if (string.IsNullOrEmpty(name)) continue; - if (!uint.TryParse(data.Slice(pidStart), out uint pid)) - continue; - // Don't remove unused sessions as these becomes just inactive for a while. It is faster to keep them than scan and remove them. - if (DataModel.Sessions.TryGetDynamicChild(pid.ToString(), out DynamicChild sessionDataModel)) + if (DataModel.Sessions.TryGetDynamicChild(name, out DynamicChild sessionDataModel)) { - sessionDataModel.Value.Id = pid; sessionDataModel.Value.Name = name; sessionDataModel.Value.State = session.State; sessionDataModel.Value.PeakVolume = session.AudioMeterInformation.MasterPeakValue * 100; @@ -157,14 +208,13 @@ private void UpdatePeakVolume(double deltaTime) else { DataModel.Sessions.AddDynamicChild( - pid.ToString(), + name, new SessionDataModel() { - Id = pid, Name = name, - State = _playbackDevice?.AudioSessionManager.Sessions[i].State, - PeakVolume = _playbackDevice?.AudioSessionManager.Sessions[i].AudioMeterInformation.MasterPeakValue ?? 0, - PeakVolumeNormalized = _playbackDevice?.AudioSessionManager.Sessions[i].AudioMeterInformation.MasterPeakValue / 100 ?? 0 + State = session.State, + PeakVolume = session.AudioMeterInformation.MasterPeakValue * 100, + PeakVolumeNormalized = session.AudioMeterInformation.MasterPeakValue }, name ); From c2981e77df8915584f17331dabd21d5902dafe21 Mon Sep 17 00:00:00 2001 From: Cheerpipe Date: Fri, 20 Aug 2021 20:21:15 -0400 Subject: [PATCH 4/7] Fix crash with exe names with '.' character --- .../DataModelExpansion/PlaybackVolumeModule.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/PlaybackVolumeModule.cs b/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/PlaybackVolumeModule.cs index 098fad84..a999b7b3 100644 --- a/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/PlaybackVolumeModule.cs +++ b/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/PlaybackVolumeModule.cs @@ -189,7 +189,10 @@ private void UpdatePeakVolume(double deltaTime) ReadOnlySpan nameSlice = data.Slice(nameStart); int nameEnd = nameSlice.LastIndexOf("."); - string name = nameSlice.Slice(0, nameEnd).ToString(); + + // To avoid crashed with exe name that contains '.' character + string name = nameSlice.Slice(0, nameEnd).ToString().Replace('.',' '); + if (!uint.TryParse(data.Slice(pidStart), out uint pid)) continue; From 8ac0b39622e7c1ccfc517e80154e57dd7d19aeca Mon Sep 17 00:00:00 2001 From: Cheerpipe Date: Fri, 20 Aug 2021 20:44:21 -0400 Subject: [PATCH 5/7] Fix remove unused dummies session datamodels --- .../DataModelExpansion/PlaybackVolumeModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/PlaybackVolumeModule.cs b/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/PlaybackVolumeModule.cs index a999b7b3..cef72318 100644 --- a/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/PlaybackVolumeModule.cs +++ b/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/PlaybackVolumeModule.cs @@ -82,7 +82,7 @@ private void DataModel_ActivePathRemoved(object sender, DataModelPathEventArgs e if (e.DataModelPath.Path.StartsWith("Sessions.")) { string sName = e.DataModelPath.Path.Split(".")[1]; - if (DataModel.ActivePaths.Count(p => p.Path.Contains($".{sName}.")) <= 1) + if (DataModel.ActivePaths.Count(p => p.Path.Contains($".{sName}")) <= 1) { _ = _savedSessionsSetting.Value.Remove(sName); _savedSessionsSetting.Save(); From 2bbd3b618498ae960c2450ea2f6c6a73f38159d4 Mon Sep 17 00:00:00 2001 From: Cheepipe Date: Wed, 29 Sep 2021 18:04:07 -0300 Subject: [PATCH 6/7] Remove workarround for node systems --- .../PlaybackVolumeModule.cs | 73 +++---------------- 1 file changed, 11 insertions(+), 62 deletions(-) diff --git a/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/PlaybackVolumeModule.cs b/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/PlaybackVolumeModule.cs index cef72318..f161b22a 100644 --- a/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/PlaybackVolumeModule.cs +++ b/src/Collections/Artemis.Plugins.Audio/DataModelExpansion/PlaybackVolumeModule.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using Artemis.Core; using Artemis.Core.Modules; using Artemis.Plugins.Audio.DataModelExpansion.DataModels; @@ -17,11 +16,10 @@ public class PlaybackVolumeModule : Module #region Constructor - public PlaybackVolumeModule(ILogger logger, NAudioDeviceEnumerationService naudioDeviceEnumerationService, PluginSettings pluginSettings) + public PlaybackVolumeModule(ILogger logger, NAudioDeviceEnumerationService naudioDeviceEnumerationService) { _logger = logger; _naudioDeviceEnumerationService = naudioDeviceEnumerationService; - _savedSessionsSetting = pluginSettings.GetSetting("SavedSessionsSetting", new HashSet()); } #endregion @@ -32,7 +30,6 @@ public PlaybackVolumeModule(ILogger logger, NAudioDeviceEnumerationService naudi private readonly ILogger _logger; private readonly object _audioEventLock = new(); private readonly List> _channelsDataModels = new(); - private readonly PluginSetting> _savedSessionsSetting; private bool _playbackDeviceChanged; private float _lastMasterPeakVolumeNormalized; private MMDevice _playbackDevice; @@ -49,55 +46,6 @@ public override void Enable() // We don't need mor than ~30 updates per second. It will keep CPU usage controlled. 60 or more updates per second could rise cpu usage AddTimedUpdate(TimeSpan.FromMilliseconds(33), UpdatePeakVolume, "UpdatePeakVolume"); - - LoadInUseSessions(); - - DataModel.ActivePathAdded += DataModel_ActivePathAdded; - DataModel.ActivePathRemoved += DataModel_ActivePathRemoved; - } - - private void LoadInUseSessions() - { - // We need to create used sessions datamodels before plugin is enabled or the conditions system will be set these conditions as invalid. - // Just create a default session datamodel for each used session. - - foreach (var sName in _savedSessionsSetting.Value) - { - DataModel.Sessions.AddDynamicChild( - sName, - new SessionDataModel() - { - Name = sName, - State = NAudio.CoreAudioApi.Interfaces.AudioSessionState.AudioSessionStateInactive, - PeakVolume = 0, - PeakVolumeNormalized = 0 - }, - sName - ); - } - } - - private void DataModel_ActivePathRemoved(object sender, DataModelPathEventArgs e) - { - if (e.DataModelPath.Path.StartsWith("Sessions.")) - { - string sName = e.DataModelPath.Path.Split(".")[1]; - if (DataModel.ActivePaths.Count(p => p.Path.Contains($".{sName}")) <= 1) - { - _ = _savedSessionsSetting.Value.Remove(sName); - _savedSessionsSetting.Save(); - } - } - } - - private void DataModel_ActivePathAdded(object sender, DataModelPathEventArgs e) - { - if (e.DataModelPath.Path.StartsWith("Sessions.")) - { - string sName = e.DataModelPath.Path.Split(".")[1]; - _ = _savedSessionsSetting.Value.Add(sName); - _savedSessionsSetting.Save(); - } } public override void Disable() @@ -141,10 +89,11 @@ private void UpdatePeakVolume(double deltaTime) // Update Main volume Peak lock (_audioEventLock) // To avoid query an Device/EndPoint that is not the current device anymore or has more or less channels { + // Absolute master peak volume - float peakVolumeNormalized = _playbackDevice?.AudioMeterInformation.MasterPeakValue ?? 0f; + float peakVolumeNormalized = (float) _playbackDevice?.AudioMeterInformation.MasterPeakValue; - // Don't update datamodel if not neeeded + // Don't update datamodel if not needed if (Math.Abs(_lastMasterPeakVolumeNormalized - peakVolumeNormalized) < 0.00001f) return; @@ -173,10 +122,10 @@ private void UpdatePeakVolume(double deltaTime) } // Populate Sessions DataModel. Note that if the node don't exists, conditions using these values will become invalid - var audioSessions = _playbackDevice?.AudioSessionManager.Sessions; + SessionCollection audioSessions = _playbackDevice?.AudioSessionManager.Sessions; for (int i = 0; i < audioSessions.Count; i++) { - var session = audioSessions[i]; + AudioSessionControl session = audioSessions[i]; // Don't waste resources parsing system sessions data if (session.IsSystemSoundsSession) @@ -189,11 +138,11 @@ private void UpdatePeakVolume(double deltaTime) ReadOnlySpan nameSlice = data.Slice(nameStart); int nameEnd = nameSlice.LastIndexOf("."); - + // To avoid crashed with exe name that contains '.' character - string name = nameSlice.Slice(0, nameEnd).ToString().Replace('.',' '); - - if (!uint.TryParse(data.Slice(pidStart), out uint pid)) + string name = nameSlice.Slice(0, nameEnd).ToString().Replace('.', ' '); + + if (!uint.TryParse(data.Slice(pidStart), out uint _)) continue; // Ignore sessions without name. It may be a valid session but without a name it is useless for conditions system @@ -201,7 +150,7 @@ private void UpdatePeakVolume(double deltaTime) continue; // Don't remove unused sessions as these becomes just inactive for a while. It is faster to keep them than scan and remove them. - if (DataModel.Sessions.TryGetDynamicChild(name, out DynamicChild sessionDataModel)) + if (DataModel.Sessions.TryGetDynamicChild(name, out DynamicChild sessionDataModel)) { sessionDataModel.Value.Name = name; sessionDataModel.Value.State = session.State; From 6e7b74d396c31035a1c8061ec687a46288f9db6d Mon Sep 17 00:00:00 2001 From: Cheepipe Date: Thu, 30 Sep 2021 12:02:08 -0300 Subject: [PATCH 7/7] Minor code fix