From f05f717832eaf3a62cae037940650a17374969a0 Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 00:41:29 +0200 Subject: [PATCH 01/47] Reorganized the mess --- SteelSeriesAPI.Sample/Program.cs | 3 ++- SteelSeriesAPI.Tests/Program.cs | 4 ++-- .../{ => Sonar}/Events/SonarAudienceMonitoringEvent.cs | 2 +- SteelSeriesAPI/{ => Sonar}/Events/SonarChatMixEvent.cs | 2 +- SteelSeriesAPI/{ => Sonar}/Events/SonarConfigEvent.cs | 2 +- SteelSeriesAPI/{ => Sonar}/Events/SonarModeEvent.cs | 2 +- SteelSeriesAPI/{ => Sonar}/Events/SonarMuteEvent.cs | 2 +- .../{ => Sonar}/Events/SonarRedirectionDeviceEvent.cs | 2 +- .../{ => Sonar}/Events/SonarRedirectionStateEvent.cs | 2 +- SteelSeriesAPI/{ => Sonar}/Events/SonarVolumeEvent.cs | 2 +- SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs | 2 +- SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs | 2 +- SteelSeriesAPI/{ => Sonar}/Interfaces/ISonarBridge.cs | 2 +- .../{ => Sonar}/Interfaces/ISonarCommandHandler.cs | 2 +- SteelSeriesAPI/{ => Sonar}/Interfaces/ISonarDataProvider.cs | 2 +- SteelSeriesAPI/{ => Sonar}/Interfaces/ISonarSocket.cs | 2 +- SteelSeriesAPI/Sonar/{ => Managers}/SonarEventManager.cs | 4 ++-- SteelSeriesAPI/{ => Sonar}/SonarBridge.cs | 5 +++-- SteelSeriesAPI/Sonar/SonarSocket.cs | 3 ++- 19 files changed, 25 insertions(+), 22 deletions(-) rename SteelSeriesAPI/{ => Sonar}/Events/SonarAudienceMonitoringEvent.cs (81%) rename SteelSeriesAPI/{ => Sonar}/Events/SonarChatMixEvent.cs (74%) rename SteelSeriesAPI/{ => Sonar}/Events/SonarConfigEvent.cs (81%) rename SteelSeriesAPI/{ => Sonar}/Events/SonarModeEvent.cs (78%) rename SteelSeriesAPI/{ => Sonar}/Events/SonarMuteEvent.cs (90%) rename SteelSeriesAPI/{ => Sonar}/Events/SonarRedirectionDeviceEvent.cs (92%) rename SteelSeriesAPI/{ => Sonar}/Events/SonarRedirectionStateEvent.cs (88%) rename SteelSeriesAPI/{ => Sonar}/Events/SonarVolumeEvent.cs (90%) rename SteelSeriesAPI/{ => Sonar}/Interfaces/ISonarBridge.cs (92%) rename SteelSeriesAPI/{ => Sonar}/Interfaces/ISonarCommandHandler.cs (99%) rename SteelSeriesAPI/{ => Sonar}/Interfaces/ISonarDataProvider.cs (99%) rename SteelSeriesAPI/{ => Sonar}/Interfaces/ISonarSocket.cs (75%) rename SteelSeriesAPI/Sonar/{ => Managers}/SonarEventManager.cs (99%) rename SteelSeriesAPI/{ => Sonar}/SonarBridge.cs (98%) diff --git a/SteelSeriesAPI.Sample/Program.cs b/SteelSeriesAPI.Sample/Program.cs index 1ce22e2..ed0abbd 100644 --- a/SteelSeriesAPI.Sample/Program.cs +++ b/SteelSeriesAPI.Sample/Program.cs @@ -1,4 +1,5 @@ -using SteelSeriesAPI.Events; +using SteelSeriesAPI.Sonar; +using SteelSeriesAPI.Sonar.Events; using SteelSeriesAPI.Sonar.Enums; using SteelSeriesAPI.Sonar.Models; diff --git a/SteelSeriesAPI.Tests/Program.cs b/SteelSeriesAPI.Tests/Program.cs index 092d874..25e70a5 100644 --- a/SteelSeriesAPI.Tests/Program.cs +++ b/SteelSeriesAPI.Tests/Program.cs @@ -1,5 +1,5 @@ -using SteelSeriesAPI.Events; -using SteelSeriesAPI.Sonar; +using SteelSeriesAPI.Sonar; +using SteelSeriesAPI.Sonar.Events; using SteelSeriesAPI.Sonar.Enums; using SteelSeriesAPI.Sonar.Models; diff --git a/SteelSeriesAPI/Events/SonarAudienceMonitoringEvent.cs b/SteelSeriesAPI/Sonar/Events/SonarAudienceMonitoringEvent.cs similarity index 81% rename from SteelSeriesAPI/Events/SonarAudienceMonitoringEvent.cs rename to SteelSeriesAPI/Sonar/Events/SonarAudienceMonitoringEvent.cs index 2b81278..32aec9b 100644 --- a/SteelSeriesAPI/Events/SonarAudienceMonitoringEvent.cs +++ b/SteelSeriesAPI/Sonar/Events/SonarAudienceMonitoringEvent.cs @@ -1,4 +1,4 @@ -namespace SteelSeriesAPI.Events; +namespace SteelSeriesAPI.Sonar.Events; public class SonarAudienceMonitoringEvent : EventArgs { diff --git a/SteelSeriesAPI/Events/SonarChatMixEvent.cs b/SteelSeriesAPI/Sonar/Events/SonarChatMixEvent.cs similarity index 74% rename from SteelSeriesAPI/Events/SonarChatMixEvent.cs rename to SteelSeriesAPI/Sonar/Events/SonarChatMixEvent.cs index 551539e..352ab66 100644 --- a/SteelSeriesAPI/Events/SonarChatMixEvent.cs +++ b/SteelSeriesAPI/Sonar/Events/SonarChatMixEvent.cs @@ -1,4 +1,4 @@ -namespace SteelSeriesAPI.Events; +namespace SteelSeriesAPI.Sonar.Events; public class SonarChatMixEvent : EventArgs { diff --git a/SteelSeriesAPI/Events/SonarConfigEvent.cs b/SteelSeriesAPI/Sonar/Events/SonarConfigEvent.cs similarity index 81% rename from SteelSeriesAPI/Events/SonarConfigEvent.cs rename to SteelSeriesAPI/Sonar/Events/SonarConfigEvent.cs index 2d53fdb..5777090 100644 --- a/SteelSeriesAPI/Events/SonarConfigEvent.cs +++ b/SteelSeriesAPI/Sonar/Events/SonarConfigEvent.cs @@ -1,4 +1,4 @@ -namespace SteelSeriesAPI.Events; +namespace SteelSeriesAPI.Sonar.Events; public class SonarConfigEvent : EventArgs { diff --git a/SteelSeriesAPI/Events/SonarModeEvent.cs b/SteelSeriesAPI/Sonar/Events/SonarModeEvent.cs similarity index 78% rename from SteelSeriesAPI/Events/SonarModeEvent.cs rename to SteelSeriesAPI/Sonar/Events/SonarModeEvent.cs index c432ac5..965313c 100644 --- a/SteelSeriesAPI/Events/SonarModeEvent.cs +++ b/SteelSeriesAPI/Sonar/Events/SonarModeEvent.cs @@ -1,6 +1,6 @@ using SteelSeriesAPI.Sonar.Enums; -namespace SteelSeriesAPI.Events; +namespace SteelSeriesAPI.Sonar.Events; public class SonarModeEvent : EventArgs { diff --git a/SteelSeriesAPI/Events/SonarMuteEvent.cs b/SteelSeriesAPI/Sonar/Events/SonarMuteEvent.cs similarity index 90% rename from SteelSeriesAPI/Events/SonarMuteEvent.cs rename to SteelSeriesAPI/Sonar/Events/SonarMuteEvent.cs index 836be38..c637501 100644 --- a/SteelSeriesAPI/Events/SonarMuteEvent.cs +++ b/SteelSeriesAPI/Sonar/Events/SonarMuteEvent.cs @@ -1,6 +1,6 @@ using SteelSeriesAPI.Sonar.Enums; -namespace SteelSeriesAPI.Events; +namespace SteelSeriesAPI.Sonar.Events; public class SonarMuteEvent : EventArgs { diff --git a/SteelSeriesAPI/Events/SonarRedirectionDeviceEvent.cs b/SteelSeriesAPI/Sonar/Events/SonarRedirectionDeviceEvent.cs similarity index 92% rename from SteelSeriesAPI/Events/SonarRedirectionDeviceEvent.cs rename to SteelSeriesAPI/Sonar/Events/SonarRedirectionDeviceEvent.cs index 146dbbe..5db2057 100644 --- a/SteelSeriesAPI/Events/SonarRedirectionDeviceEvent.cs +++ b/SteelSeriesAPI/Sonar/Events/SonarRedirectionDeviceEvent.cs @@ -1,6 +1,6 @@ using SteelSeriesAPI.Sonar.Enums; -namespace SteelSeriesAPI.Events; +namespace SteelSeriesAPI.Sonar.Events; public class SonarRedirectionDeviceEvent : EventArgs { diff --git a/SteelSeriesAPI/Events/SonarRedirectionStateEvent.cs b/SteelSeriesAPI/Sonar/Events/SonarRedirectionStateEvent.cs similarity index 88% rename from SteelSeriesAPI/Events/SonarRedirectionStateEvent.cs rename to SteelSeriesAPI/Sonar/Events/SonarRedirectionStateEvent.cs index e16d110..56c8137 100644 --- a/SteelSeriesAPI/Events/SonarRedirectionStateEvent.cs +++ b/SteelSeriesAPI/Sonar/Events/SonarRedirectionStateEvent.cs @@ -1,6 +1,6 @@ using SteelSeriesAPI.Sonar.Enums; -namespace SteelSeriesAPI.Events; +namespace SteelSeriesAPI.Sonar.Events; public class SonarRedirectionStateEvent : EventArgs { diff --git a/SteelSeriesAPI/Events/SonarVolumeEvent.cs b/SteelSeriesAPI/Sonar/Events/SonarVolumeEvent.cs similarity index 90% rename from SteelSeriesAPI/Events/SonarVolumeEvent.cs rename to SteelSeriesAPI/Sonar/Events/SonarVolumeEvent.cs index f9c798a..8bea8d4 100644 --- a/SteelSeriesAPI/Events/SonarVolumeEvent.cs +++ b/SteelSeriesAPI/Sonar/Events/SonarVolumeEvent.cs @@ -1,6 +1,6 @@ using SteelSeriesAPI.Sonar.Enums; -namespace SteelSeriesAPI.Events; +namespace SteelSeriesAPI.Sonar.Events; public class SonarVolumeEvent : EventArgs { diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs index a9d55c1..b0219c2 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs @@ -1,6 +1,6 @@ using System.Globalization; using System.Text.Json; -using SteelSeriesAPI.Interfaces; +using SteelSeriesAPI.Sonar.Interfaces; using SteelSeriesAPI.Sonar.Enums; using Channel = SteelSeriesAPI.Sonar.Enums.Channel; diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs index 9185e18..4b837ed 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs @@ -1,6 +1,6 @@ using System.Collections; using System.Text.Json; -using SteelSeriesAPI.Interfaces; +using SteelSeriesAPI.Sonar.Interfaces; using SteelSeriesAPI.Sonar.Enums; using SteelSeriesAPI.Sonar.Models; diff --git a/SteelSeriesAPI/Interfaces/ISonarBridge.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarBridge.cs similarity index 92% rename from SteelSeriesAPI/Interfaces/ISonarBridge.cs rename to SteelSeriesAPI/Sonar/Interfaces/ISonarBridge.cs index 712a80c..a6c80e6 100644 --- a/SteelSeriesAPI/Interfaces/ISonarBridge.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarBridge.cs @@ -1,4 +1,4 @@ -namespace SteelSeriesAPI.Interfaces; +namespace SteelSeriesAPI.Sonar.Interfaces; public interface ISonarBridge : ISonarDataProvider, ISonarCommandHandler { diff --git a/SteelSeriesAPI/Interfaces/ISonarCommandHandler.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs similarity index 99% rename from SteelSeriesAPI/Interfaces/ISonarCommandHandler.cs rename to SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs index 1896656..e214d7b 100644 --- a/SteelSeriesAPI/Interfaces/ISonarCommandHandler.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs @@ -1,6 +1,6 @@ using SteelSeriesAPI.Sonar.Enums; -namespace SteelSeriesAPI.Interfaces; +namespace SteelSeriesAPI.Sonar.Interfaces; public interface ISonarCommandHandler { diff --git a/SteelSeriesAPI/Interfaces/ISonarDataProvider.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs similarity index 99% rename from SteelSeriesAPI/Interfaces/ISonarDataProvider.cs rename to SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs index faba306..5b068f4 100644 --- a/SteelSeriesAPI/Interfaces/ISonarDataProvider.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs @@ -1,7 +1,7 @@ using SteelSeriesAPI.Sonar.Enums; using SteelSeriesAPI.Sonar.Models; -namespace SteelSeriesAPI.Interfaces; +namespace SteelSeriesAPI.Sonar.Interfaces; public interface ISonarDataProvider { diff --git a/SteelSeriesAPI/Interfaces/ISonarSocket.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarSocket.cs similarity index 75% rename from SteelSeriesAPI/Interfaces/ISonarSocket.cs rename to SteelSeriesAPI/Sonar/Interfaces/ISonarSocket.cs index c59296c..0ec5e69 100644 --- a/SteelSeriesAPI/Interfaces/ISonarSocket.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarSocket.cs @@ -1,4 +1,4 @@ -namespace SteelSeriesAPI.Interfaces; +namespace SteelSeriesAPI.Sonar.Interfaces; public interface ISonarSocket { diff --git a/SteelSeriesAPI/Sonar/SonarEventManager.cs b/SteelSeriesAPI/Sonar/Managers/SonarEventManager.cs similarity index 99% rename from SteelSeriesAPI/Sonar/SonarEventManager.cs rename to SteelSeriesAPI/Sonar/Managers/SonarEventManager.cs index a0f1835..a660878 100644 --- a/SteelSeriesAPI/Sonar/SonarEventManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/SonarEventManager.cs @@ -1,8 +1,8 @@ using System.Globalization; -using SteelSeriesAPI.Events; +using SteelSeriesAPI.Sonar.Events; using SteelSeriesAPI.Sonar.Enums; -namespace SteelSeriesAPI.Sonar; +namespace SteelSeriesAPI.Sonar.Managers; public class SonarEventManager { diff --git a/SteelSeriesAPI/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs similarity index 98% rename from SteelSeriesAPI/SonarBridge.cs rename to SteelSeriesAPI/Sonar/SonarBridge.cs index eb4eb53..8cbc047 100644 --- a/SteelSeriesAPI/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -1,11 +1,12 @@ using System.Security.Principal; using SteelSeriesAPI.Interfaces; -using SteelSeriesAPI.Sonar; using SteelSeriesAPI.Sonar.Enums; using SteelSeriesAPI.Sonar.Http; +using SteelSeriesAPI.Sonar.Interfaces; +using SteelSeriesAPI.Sonar.Managers; using SteelSeriesAPI.Sonar.Models; -namespace SteelSeriesAPI; +namespace SteelSeriesAPI.Sonar; /// /// The Sonar object, to control Sonar
Allow you to listen for event, get or set volumes, muted states, ... diff --git a/SteelSeriesAPI/Sonar/SonarSocket.cs b/SteelSeriesAPI/Sonar/SonarSocket.cs index 58b5932..e8a5c5d 100644 --- a/SteelSeriesAPI/Sonar/SonarSocket.cs +++ b/SteelSeriesAPI/Sonar/SonarSocket.cs @@ -1,7 +1,8 @@ using System.Net; using System.Net.Sockets; using System.Text; -using SteelSeriesAPI.Interfaces; +using SteelSeriesAPI.Sonar.Interfaces; +using SteelSeriesAPI.Sonar.Managers; namespace SteelSeriesAPI.Sonar; From 113232b2f232c304c7e0428e6a96c185f4e7c501 Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 01:21:12 +0200 Subject: [PATCH 02/47] Renamed a lot of things Renamed a lot of things to follow SteelSeries doc, for conventions and better understanding of what you are doing/manipulating --- SteelSeriesAPI.Sample/Program.cs | 96 +++++----- SteelSeriesAPI.Tests/Program.cs | 172 +++++++++--------- SteelSeriesAPI/Sonar/Enums/Channel.cs | 74 ++++++-- SteelSeriesAPI/Sonar/Enums/DataFlow.cs | 34 ++++ SteelSeriesAPI/Sonar/Enums/Device.cs | 86 --------- SteelSeriesAPI/Sonar/Enums/Direction.cs | 34 ---- SteelSeriesAPI/Sonar/Enums/Mix.cs | 34 ++++ SteelSeriesAPI/Sonar/Enums/Mode.cs | 12 +- .../Sonar/Enums/RoutedProcessState.cs | 12 +- SteelSeriesAPI/Sonar/Events/SonarMuteEvent.cs | 4 +- ...ceEvent.cs => SonarPlaybackDeviceEvent.cs} | 6 +- .../Events/SonarRedirectionStateEvent.cs | 2 +- .../Sonar/Events/SonarVolumeEvent.cs | 4 +- SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs | 49 +++-- .../Sonar/Http/SonarHttpProvider.cs | 122 ++++++------- .../Sonar/Interfaces/ISonarCommandHandler.cs | 74 ++++---- .../Sonar/Interfaces/ISonarDataProvider.cs | 94 +++++----- .../{SonarEventManager.cs => EventManager.cs} | 56 +++--- SteelSeriesAPI/Sonar/Models/PlaybackDevice.cs | 6 + .../Sonar/Models/RedirectionDevice.cs | 6 - .../Sonar/Models/SonarAudioConfiguration.cs | 2 +- SteelSeriesAPI/Sonar/SonarBridge.cs | 98 +++++----- SteelSeriesAPI/Sonar/SonarSocket.cs | 8 +- 23 files changed, 542 insertions(+), 543 deletions(-) create mode 100644 SteelSeriesAPI/Sonar/Enums/DataFlow.cs delete mode 100644 SteelSeriesAPI/Sonar/Enums/Device.cs delete mode 100644 SteelSeriesAPI/Sonar/Enums/Direction.cs create mode 100644 SteelSeriesAPI/Sonar/Enums/Mix.cs rename SteelSeriesAPI/Sonar/Events/{SonarRedirectionDeviceEvent.cs => SonarPlaybackDeviceEvent.cs} (74%) rename SteelSeriesAPI/Sonar/Managers/{SonarEventManager.cs => EventManager.cs} (78%) create mode 100644 SteelSeriesAPI/Sonar/Models/PlaybackDevice.cs delete mode 100644 SteelSeriesAPI/Sonar/Models/RedirectionDevice.cs diff --git a/SteelSeriesAPI.Sample/Program.cs b/SteelSeriesAPI.Sample/Program.cs index ed0abbd..3390ffe 100644 --- a/SteelSeriesAPI.Sample/Program.cs +++ b/SteelSeriesAPI.Sample/Program.cs @@ -18,42 +18,42 @@ static void Main(string[] args) // If I want to detect changes made on GG, I can use the listener (require admin rights) sonarManager.StartListener(); // Then I register the events I want (I've put them all to demonstrate) - sonarManager.SonarEventManager.OnSonarModeChange += OnModeChangeHandler; // When the mode is change - sonarManager.SonarEventManager.OnSonarVolumeChange += OnVolumeChangeHandler; // When the volume of a Sonar Device or Channel is changed - sonarManager.SonarEventManager.OnSonarMuteChange += OnMuteChangeHandler; // When a Sonar Device or Channel is muted or unmuted - sonarManager.SonarEventManager.OnSonarConfigChange += OnConfigChangeHandler; // When a new config is set to a Sonar Device - sonarManager.SonarEventManager.OnSonarChatMixChange += OnChatMixChangeHandler; // When the ChatMix value is changed - sonarManager.SonarEventManager.OnSonarRedirectionDeviceChange += OnRedirectionDeviceChangeHandler; // When the Redirection Device of a Sonar Device is changed - sonarManager.SonarEventManager.OnSonarRedirectionStateChange += OnRedirectionStateChangeHandler; // When the Redirection of a Sonar Channel is muted or unmuted - sonarManager.SonarEventManager.OnSonarAudienceMonitoringChange += OnAudienceMonitoringChangeHandler; // When the Audience Monitoring is muted or unmuted + sonarManager.EventManager.OnSonarModeChange += OnModeChangeHandler; // When the mode is change + sonarManager.EventManager.OnSonarVolumeChange += OnVolumeChangeHandler; // When the volume of a Sonar Channel or Mix is changed + sonarManager.EventManager.OnSonarMuteChange += OnMuteChangeHandler; // When a Sonar Channel or Mix is muted or unmuted + sonarManager.EventManager.OnSonarConfigChange += OnConfigChangeHandler; // When a new config is set to a Sonar Channel + sonarManager.EventManager.OnSonarChatMixChange += OnChatMixChangeHandler; // When the ChatMix value is changed + sonarManager.EventManager.OnSonarRedirectionDeviceChange += OnRedirectionDeviceChangeHandler; // When the Redirection Channel of a Sonar Channel is changed + sonarManager.EventManager.OnSonarRedirectionStateChange += OnRedirectionStateChangeHandler; // When the Redirection of a Sonar Mix is muted or unmuted + sonarManager.EventManager.OnSonarAudienceMonitoringChange += OnAudienceMonitoringChangeHandler; // When the Audience Monitoring is muted or unmuted // Get current sonar mode Mode mode = sonarManager.GetMode(); // Change sonar mode to Streamer - sonarManager.SetMode(Mode.Streamer); + sonarManager.SetMode(Mode.STREAMER); - // Get current volume of a Sonar Device - double vol = sonarManager.GetVolume(Device.Media); // Get current volume of a Sonar Channel - double vol2 = sonarManager.GetVolume(Device.Chat, Channel.Stream); - // Set the volume of a Sonar Device - sonarManager.SetVolume(0.75, Device.Game); + double vol = sonarManager.GetVolume(Channel.MEDIA); + // Get current volume of a Sonar Mix + double vol2 = sonarManager.GetVolume(Channel.CHAT, Mix.STREAM); // Set the volume of a Sonar Channel - sonarManager.SetVolume(0.1, Device.Media, Channel.Monitoring); + sonarManager.SetVolume(0.75, Channel.GAME); + // Set the volume of a Sonar Mix + sonarManager.SetVolume(0.1, Channel.MEDIA, Mix.MONITORING); - // Get the current mute state of a Sonar Device - bool state = sonarManager.GetMute(Device.Chat); - bool state2 = sonarManager.GetMute(Device.Master, Channel.Monitoring); - // Set the current mute state of a Sonar Device - sonarManager.SetMute(true, Device.Chat); // Mute chat + // Get the current mute state of a Sonar Channel + bool state = sonarManager.GetMute(Channel.CHAT); + bool state2 = sonarManager.GetMute(Channel.MASTER, Mix.MONITORING); + // Set the current mute state of a Sonar Channel + sonarManager.SetMute(true, Channel.CHAT); // Mute chat // Get audio configs - List allConfigs = sonarManager.GetAllAudioConfigurations().ToList(); // Return all configs (A SonarAudioConfiguration contains an Id, a Name and an AssociatedDevice) - List mediaConfigs = sonarManager.GetAudioConfigurations(Device.Media).ToList(); // Return all configs of a Sonar Device - SonarAudioConfiguration currentConfig = sonarManager.GetSelectedAudioConfiguration(Device.Media); // Return the currently used config of a Sonar Device - // Set the config of a Sonar Device - sonarManager.SetConfig(Device.Media, "Podcast"); // Using its name - sonarManager.SetConfig(currentConfig.Id); // Using its id (no need to precise which Sonar Device, one id goes to one Sonar Device) + List allConfigs = sonarManager.GetAllAudioConfigurations().ToList(); // Return all configs (A SonarAudioConfiguration contains an Id, a Name and an AssociatedChannel) + List mediaConfigs = sonarManager.GetAudioConfigurations(Channel.MEDIA).ToList(); // Return all configs of a Sonar Channel + SonarAudioConfiguration currentConfig = sonarManager.GetSelectedAudioConfiguration(Channel.MEDIA); // Return the currently used config of a Sonar Channel + // Set the config of a Sonar Channel + sonarManager.SetConfig(Channel.MEDIA, "Podcast"); // Using its name + sonarManager.SetConfig(currentConfig.Id); // Using its id (no need to precise which Sonar Channel, one id goes to one Sonar Channel) // Get ChatMix info double chatMixBalance = sonarManager.GetChatMixBalance(); // The ChatMix value between -1 and 1 @@ -61,32 +61,32 @@ static void Main(string[] args) // Change ChatMix value sonarManager.SetChatMixBalance(0.5); // 0.5 is halfway to Chat - // Get redirection devices (Windows devices) - List inputDevices = sonarManager.GetRedirectionDevices(Direction.Input).ToList(); // Input devices (Mics...) - sonarManager.GetRedirectionDevices(Direction.Output); // Output devices (headset, speakers...) - sonarManager.GetRedirectionDeviceFromId("{0.0.0.00000000}.{192b4f5b-9cc1-4eb2-b752-c5e15b99d548}"); // Get a redirection device from its id - RedirectionDevice gameRDevice = sonarManager.GetClassicRedirectionDevice(Device.Game); // Give currently used Redirection Device for classic mode - sonarManager.GetStreamRedirectionDevice(Channel.Monitoring); // Give currently used Redirection Device for Streamer mode - sonarManager.GetStreamRedirectionDevice(Device.Mic); // Give currently used Redirection Device for Mic in streamer mode - // Change redirection devices using their id - sonarManager.SetClassicRedirectionDevice(gameRDevice.Id, Device.Game); - sonarManager.SetStreamRedirectionDevice(gameRDevice.Id, Channel.Monitoring); - sonarManager.SetStreamRedirectionDevice(inputDevices[0].Id, Device.Mic); + // Get playback devices (Windows devices) + List inputDevices = sonarManager.GetPlaybackDevices(DataFlow.INPUT).ToList(); // Input devices (Mics...) + sonarManager.GetPlaybackDevices(DataFlow.OUTPUT); // Output devices (headset, speakers...) + sonarManager.GetPlaybackDeviceFromId("{0.0.0.00000000}.{192b4f5b-9cc1-4eb2-b752-c5e15b99d548}"); // Get a redirection channel from its id + PlaybackDevice gameRDevice = sonarManager.GetClassicPlaybackDevice(Channel.GAME); // Give currently used Redirection Channel for classic mode + sonarManager.GetStreamPlaybackDevice(Mix.MONITORING); // Give currently used Redirection Channel for Streamer mode + sonarManager.GetStreamPlaybackDevice(Channel.MIC); // Give currently used Redirection Channel for Mic in streamer mode + // Change playback devices using their id + sonarManager.SetClassicPlaybackDevice(gameRDevice.Id, Channel.GAME); + sonarManager.SetStreamPlaybackDevice(gameRDevice.Id, Mix.MONITORING); + sonarManager.SetStreamPlaybackDevice(inputDevices[0].Id, Channel.MIC); // Get the redirections states - sonarManager.GetRedirectionState(Device.Media, Channel.Monitoring); + sonarManager.GetRedirectionState(Channel.MEDIA, Mix.MONITORING); // Change the redirections states - sonarManager.SetRedirectionState(false, Device.Media, Channel.Monitoring); + sonarManager.SetRedirectionState(false, Channel.MEDIA, Mix.MONITORING); // Get Audience Monitoring state sonarManager.GetAudienceMonitoringState(); // Change Audience Monitoring state sonarManager.SetAudienceMonitoringState(false); - // Get routed processes of a Sonar Device - List mediaProcesses = sonarManager.GetRoutedProcess(Device.Media).ToList(); // Will surely return apps like Google Chrome or Spotify - // Route a process to a Sonar Device using its process ID (pid) - sonarManager.SetProcessToDeviceRouting(mediaProcesses[0].PId, Device.Media); + // Get routed processes of a Sonar Channel + List mediaProcesses = sonarManager.GetRoutedProcess(Channel.MEDIA).ToList(); // Will surely return apps like Google Chrome or Spotify + // Route a process to a Sonar Channel using its process ID (pid) + sonarManager.SetProcessToDeviceRouting(mediaProcesses[0].PId, Channel.MEDIA); } static void OnModeChangeHandler(object? sender, SonarModeEvent eventArgs) @@ -96,12 +96,12 @@ static void OnModeChangeHandler(object? sender, SonarModeEvent eventArgs) static void OnVolumeChangeHandler(object? sender, SonarVolumeEvent eventArgs) { - Console.WriteLine("Received Volume Event : " + eventArgs.Volume + ", " + eventArgs.Mode + ", " + eventArgs.Device + ", " + eventArgs.Channel); + Console.WriteLine("Received Volume Event : " + eventArgs.Volume + ", " + eventArgs.Mode + ", " + eventArgs.Channel + ", " + eventArgs.Mix); } static void OnMuteChangeHandler(object? sender, SonarMuteEvent eventArgs) { - Console.WriteLine("Received Mute Event : " + eventArgs.Muted + ", " + eventArgs.Mode + ", " + eventArgs.Device + ", " + eventArgs.Channel); + Console.WriteLine("Received Mute Event : " + eventArgs.Muted + ", " + eventArgs.Mode + ", " + eventArgs.Channel + ", " + eventArgs.Mix); } static void OnConfigChangeHandler(object? sender, SonarConfigEvent eventArgs) @@ -114,14 +114,14 @@ static void OnChatMixChangeHandler(object? sender, SonarChatMixEvent eventArgs) Console.WriteLine("Received ChatMix Event : " + eventArgs.Balance); } - static void OnRedirectionDeviceChangeHandler(object? sender, SonarRedirectionDeviceEvent eventArgs) + static void OnRedirectionDeviceChangeHandler(object? sender, SonarPlaybackDeviceEvent eventArgs) { - Console.WriteLine("Received Redirection Device Event : " + eventArgs.RedirectionDeviceId + ", " + eventArgs.Mode + ", " + eventArgs.Device + ", " + eventArgs.Channel); + Console.WriteLine("Received Redirection Channel Event : " + eventArgs.RedirectionDeviceId + ", " + eventArgs.Mode + ", " + eventArgs.Device + ", " + eventArgs.Channel); } static void OnRedirectionStateChangeHandler(object? sender, SonarRedirectionStateEvent eventArgs) { - Console.WriteLine("Received Redirection State Event : " + eventArgs.State + ", " + eventArgs.Device + ", " + eventArgs.Channel); + Console.WriteLine("Received Redirection State Event : " + eventArgs.State + ", " + eventArgs.Channel + ", " + eventArgs.Mix); } static void OnAudienceMonitoringChangeHandler(object? sender, SonarAudienceMonitoringEvent eventArgs) diff --git a/SteelSeriesAPI.Tests/Program.cs b/SteelSeriesAPI.Tests/Program.cs index 25e70a5..f91bab5 100644 --- a/SteelSeriesAPI.Tests/Program.cs +++ b/SteelSeriesAPI.Tests/Program.cs @@ -18,14 +18,14 @@ static void Main(string[] args) // Thread.Sleep(1000); // sonarManager.StopListener(); - sonarManager.SonarEventManager.OnSonarModeChange += OnModeChangeHandler; - sonarManager.SonarEventManager.OnSonarVolumeChange += OnVolumeChangeHandler; - sonarManager.SonarEventManager.OnSonarMuteChange += OnMuteChangeHandler; - sonarManager.SonarEventManager.OnSonarConfigChange += OnConfigChangeHandler; - sonarManager.SonarEventManager.OnSonarChatMixChange += OnChatMixChangeHandler; - sonarManager.SonarEventManager.OnSonarRedirectionDeviceChange += OnRedirectionDeviceChangeHandler; - sonarManager.SonarEventManager.OnSonarRedirectionStateChange += OnRedirectionStateChangeHandler; - sonarManager.SonarEventManager.OnSonarAudienceMonitoringChange += OnAudienceMonitoringChangeHandler; + sonarManager.EventManager.OnSonarModeChange += OnModeChangeHandler; + sonarManager.EventManager.OnSonarVolumeChange += OnVolumeChangeHandler; + sonarManager.EventManager.OnSonarMuteChange += OnMuteChangeHandler; + sonarManager.EventManager.OnSonarConfigChange += OnConfigChangeHandler; + sonarManager.EventManager.OnSonarChatMixChange += OnChatMixChangeHandler; + sonarManager.EventManager.OnSonarRedirectionDeviceChange += OnRedirectionDeviceChangeHandler; + sonarManager.EventManager.OnSonarRedirectionStateChange += OnRedirectionStateChangeHandler; + sonarManager.EventManager.OnSonarAudienceMonitoringChange += OnAudienceMonitoringChangeHandler; // new Program().GetTest(sonarManager); // new Program().SetTest(sonarManager); @@ -36,87 +36,87 @@ void TestMaster(SonarBridge sonarManager) { // Classic - sonarManager.SetMode(Mode.Classic); + sonarManager.SetMode(Mode.CLASSIC); Console.WriteLine("------ Classic Master Test ------"); - Console.WriteLine(sonarManager.GetVolume(Device.Master)); - Console.WriteLine(sonarManager.GetMute(Device.Master)); - sonarManager.SetVolume(0.25f, Device.Master); - sonarManager.SetVolume(1, Device.Master); - sonarManager.SetMute(true, Device.Master); - sonarManager.SetMute(false, Device.Master); + Console.WriteLine(sonarManager.GetVolume(Channel.MASTER)); + Console.WriteLine(sonarManager.GetMute(Channel.MASTER)); + sonarManager.SetVolume(0.25f, Channel.MASTER); + sonarManager.SetVolume(1, Channel.MASTER); + sonarManager.SetMute(true, Channel.MASTER); + sonarManager.SetMute(false, Channel.MASTER); // Streamer - sonarManager.SetMode(Mode.Streamer); + sonarManager.SetMode(Mode.STREAMER); Console.WriteLine("------ Streamer Master Test ------"); - Console.WriteLine(sonarManager.GetVolume(Device.Master, Channel.Monitoring)); - Console.WriteLine(sonarManager.GetVolume(Device.Master, Channel.Stream)); - Console.WriteLine(sonarManager.GetMute(Device.Master, Channel.Monitoring)); - Console.WriteLine(sonarManager.GetMute(Device.Master, Channel.Stream)); - sonarManager.SetVolume(0.25f, Device.Master, Channel.Monitoring); - sonarManager.SetVolume(0.25f, Device.Master, Channel.Stream); - sonarManager.SetVolume(1, Device.Master, Channel.Monitoring); - sonarManager.SetVolume(1, Device.Master, Channel.Stream); - sonarManager.SetMute(true, Device.Master, Channel.Monitoring); - sonarManager.SetMute(true, Device.Master, Channel.Stream); - sonarManager.SetMute(false, Device.Master, Channel.Monitoring); - sonarManager.SetMute(false, Device.Master, Channel.Stream); + Console.WriteLine(sonarManager.GetVolume(Channel.MASTER, Mix.MONITORING)); + Console.WriteLine(sonarManager.GetVolume(Channel.MASTER, Mix.STREAM)); + Console.WriteLine(sonarManager.GetMute(Channel.MASTER, Mix.MONITORING)); + Console.WriteLine(sonarManager.GetMute(Channel.MASTER, Mix.STREAM)); + sonarManager.SetVolume(0.25f, Channel.MASTER, Mix.MONITORING); + sonarManager.SetVolume(0.25f, Channel.MASTER, Mix.STREAM); + sonarManager.SetVolume(1, Channel.MASTER, Mix.MONITORING); + sonarManager.SetVolume(1, Channel.MASTER, Mix.STREAM); + sonarManager.SetMute(true, Channel.MASTER, Mix.MONITORING); + sonarManager.SetMute(true, Channel.MASTER, Mix.STREAM); + sonarManager.SetMute(false, Channel.MASTER, Mix.MONITORING); + sonarManager.SetMute(false, Channel.MASTER, Mix.STREAM); - sonarManager.SetMode(Mode.Classic); + sonarManager.SetMode(Mode.CLASSIC); } void GetTest(SonarBridge sonarManager) { Console.WriteLine(sonarManager.GetMode()); - Console.WriteLine("" + sonarManager.GetVolume(Device.Master) + " " + sonarManager.GetMute(Device.Master)); - Console.WriteLine("" + sonarManager.GetVolume(Device.Game) + " " + sonarManager.GetMute(Device.Game)); - Console.WriteLine("" + sonarManager.GetVolume(Device.Chat) + " " + sonarManager.GetMute(Device.Chat)); - Console.WriteLine("" + sonarManager.GetVolume(Device.Media) + " " + sonarManager.GetMute(Device.Media)); - Console.WriteLine("" + sonarManager.GetVolume(Device.Aux) + " " + sonarManager.GetMute(Device.Aux)); - Console.WriteLine("" + sonarManager.GetVolume(Device.Mic) + " " + sonarManager.GetMute(Device.Mic)); + Console.WriteLine("" + sonarManager.GetVolume(Channel.MASTER) + " " + sonarManager.GetMute(Channel.MASTER)); + Console.WriteLine("" + sonarManager.GetVolume(Channel.GAME) + " " + sonarManager.GetMute(Channel.GAME)); + Console.WriteLine("" + sonarManager.GetVolume(Channel.CHAT) + " " + sonarManager.GetMute(Channel.CHAT)); + Console.WriteLine("" + sonarManager.GetVolume(Channel.MEDIA) + " " + sonarManager.GetMute(Channel.MEDIA)); + Console.WriteLine("" + sonarManager.GetVolume(Channel.AUX) + " " + sonarManager.GetMute(Channel.AUX)); + Console.WriteLine("" + sonarManager.GetVolume(Channel.MIC) + " " + sonarManager.GetMute(Channel.MIC)); Console.WriteLine("-----------------Streamer-Monitoring-------------"); - Console.WriteLine("" + sonarManager.GetVolume(Device.Master, Channel.Monitoring) + " " + sonarManager.GetMute(Device.Master, Channel.Monitoring)); - Console.WriteLine("" + sonarManager.GetVolume(Device.Game, Channel.Monitoring) + " " + sonarManager.GetMute(Device.Game, Channel.Monitoring)); - Console.WriteLine("" + sonarManager.GetVolume(Device.Chat, Channel.Monitoring) + " " + sonarManager.GetMute(Device.Chat, Channel.Monitoring)); - Console.WriteLine("" + sonarManager.GetVolume(Device.Media, Channel.Monitoring) + " " + sonarManager.GetMute(Device.Media, Channel.Monitoring)); - Console.WriteLine("" + sonarManager.GetVolume(Device.Aux, Channel.Monitoring) + " " + sonarManager.GetMute(Device.Aux, Channel.Monitoring)); - Console.WriteLine("" + sonarManager.GetVolume(Device.Mic, Channel.Monitoring) + " " + sonarManager.GetMute(Device.Mic, Channel.Monitoring)); + Console.WriteLine("" + sonarManager.GetVolume(Channel.MASTER, Mix.MONITORING) + " " + sonarManager.GetMute(Channel.MASTER, Mix.MONITORING)); + Console.WriteLine("" + sonarManager.GetVolume(Channel.GAME, Mix.MONITORING) + " " + sonarManager.GetMute(Channel.GAME, Mix.MONITORING)); + Console.WriteLine("" + sonarManager.GetVolume(Channel.CHAT, Mix.MONITORING) + " " + sonarManager.GetMute(Channel.CHAT, Mix.MONITORING)); + Console.WriteLine("" + sonarManager.GetVolume(Channel.MEDIA, Mix.MONITORING) + " " + sonarManager.GetMute(Channel.MEDIA, Mix.MONITORING)); + Console.WriteLine("" + sonarManager.GetVolume(Channel.AUX, Mix.MONITORING) + " " + sonarManager.GetMute(Channel.AUX, Mix.MONITORING)); + Console.WriteLine("" + sonarManager.GetVolume(Channel.MIC, Mix.MONITORING) + " " + sonarManager.GetMute(Channel.MIC, Mix.MONITORING)); Console.WriteLine("-----------------Streamer-Stream-------------"); - Console.WriteLine("" + sonarManager.GetVolume(Device.Master, Channel.Stream) + " " + sonarManager.GetMute(Device.Master, Channel.Stream)); - Console.WriteLine("" + sonarManager.GetVolume(Device.Game, Channel.Stream) + " " + sonarManager.GetMute(Device.Game, Channel.Stream)); - Console.WriteLine("" + sonarManager.GetVolume(Device.Chat, Channel.Stream) + " " + sonarManager.GetMute(Device.Chat, Channel.Stream)); - Console.WriteLine("" + sonarManager.GetVolume(Device.Media, Channel.Stream) + " " + sonarManager.GetMute(Device.Media, Channel.Stream)); - Console.WriteLine("" + sonarManager.GetVolume(Device.Aux, Channel.Stream) + " " + sonarManager.GetMute(Device.Aux, Channel.Stream)); - Console.WriteLine("" + sonarManager.GetVolume(Device.Mic, Channel.Stream) + " " + sonarManager.GetMute(Device.Mic, Channel.Stream)); + Console.WriteLine("" + sonarManager.GetVolume(Channel.MASTER, Mix.STREAM) + " " + sonarManager.GetMute(Channel.MASTER, Mix.STREAM)); + Console.WriteLine("" + sonarManager.GetVolume(Channel.GAME, Mix.STREAM) + " " + sonarManager.GetMute(Channel.GAME, Mix.STREAM)); + Console.WriteLine("" + sonarManager.GetVolume(Channel.CHAT, Mix.STREAM) + " " + sonarManager.GetMute(Channel.CHAT, Mix.STREAM)); + Console.WriteLine("" + sonarManager.GetVolume(Channel.MEDIA, Mix.STREAM) + " " + sonarManager.GetMute(Channel.MEDIA, Mix.STREAM)); + Console.WriteLine("" + sonarManager.GetVolume(Channel.AUX, Mix.STREAM) + " " + sonarManager.GetMute(Channel.AUX, Mix.STREAM)); + Console.WriteLine("" + sonarManager.GetVolume(Channel.MIC, Mix.STREAM) + " " + sonarManager.GetMute(Channel.MIC, Mix.STREAM)); Console.WriteLine("----AudioConfigs----------"); foreach (var config in sonarManager.GetAllAudioConfigurations()) { - Console.WriteLine(config.Id + ", " + config.Name + ", " + config.AssociatedDevice); + Console.WriteLine(config.Id + ", " + config.Name + ", " + config.AssociatedChannel); } Console.WriteLine("----Media-Configs----------"); - foreach (var config in sonarManager.GetAudioConfigurations(Device.Media)) + foreach (var config in sonarManager.GetAudioConfigurations(Channel.MEDIA)) { Console.WriteLine(config.Id + ", " + config.Name); } Console.WriteLine("----Mic-Configs----------"); - foreach (var config in sonarManager.GetAudioConfigurations(Device.Mic)) + foreach (var config in sonarManager.GetAudioConfigurations(Channel.MIC)) { Console.WriteLine(config.Id + ", " + config.Name); } Console.WriteLine("----Current Media Config----------"); - Console.WriteLine(sonarManager.GetSelectedAudioConfiguration(Device.Media).Name); - Console.WriteLine("----Device from config ID----------"); - Console.WriteLine(sonarManager.GetAudioConfiguration("29ae2c02-792b-4487-863c-dc3e11a7a469").AssociatedDevice); + Console.WriteLine(sonarManager.GetSelectedAudioConfiguration(Channel.MEDIA).Name); + Console.WriteLine("----Channel from config ID----------"); + Console.WriteLine(sonarManager.GetAudioConfiguration("29ae2c02-792b-4487-863c-dc3e11a7a469").AssociatedChannel); Console.WriteLine("--------ChatMix---------"); Console.WriteLine(sonarManager.GetChatMixBalance()); Console.WriteLine(sonarManager.GetChatMixState()); Console.WriteLine("-----Redirection Devices-----------"); Console.WriteLine("---Output---"); - foreach (var rDevice in sonarManager.GetRedirectionDevices(Direction.Output)) + foreach (var rDevice in sonarManager.GetPlaybackDevices(DataFlow.OUTPUT)) { Console.WriteLine(rDevice.Id + ", " + rDevice.Name); foreach (var device in rDevice.AssociatedClassicDevices) @@ -131,7 +131,7 @@ void GetTest(SonarBridge sonarManager) } Console.WriteLine("---Input---"); - foreach (var rDevice in sonarManager.GetRedirectionDevices(Direction.Input)) + foreach (var rDevice in sonarManager.GetPlaybackDevices(DataFlow.INPUT)) { Console.WriteLine(rDevice.Id + ", " + rDevice.Name); foreach (var device in rDevice.AssociatedClassicDevices) @@ -146,7 +146,7 @@ void GetTest(SonarBridge sonarManager) } Console.WriteLine("-----Classic Redirection Devices------------"); - RedirectionDevice reDevice = sonarManager.GetClassicRedirectionDevice(Device.Game); + PlaybackDevice reDevice = sonarManager.GetClassicPlaybackDevice(Channel.GAME); Console.WriteLine(reDevice.Id + ", " + reDevice.Name); foreach (var device in reDevice.AssociatedClassicDevices) { @@ -159,7 +159,7 @@ void GetTest(SonarBridge sonarManager) } Console.WriteLine("-----Stream Redirection Devices------------"); - RedirectionDevice reDeviceS = sonarManager.GetStreamRedirectionDevice(Device.Mic); // sonarManager.GetStreamRedirectionDevice(Channel.Monitoring); + PlaybackDevice reDeviceS = sonarManager.GetStreamPlaybackDevice(Channel.MIC); // sonarManager.GetStreamPlaybackDevice(Mix.MONITORING); Console.WriteLine(reDeviceS.Id + ", " + reDeviceS.Name); foreach (var device in reDeviceS.AssociatedClassicDevices) { @@ -171,8 +171,8 @@ void GetTest(SonarBridge sonarManager) Console.WriteLine("...." + channel); } - Console.WriteLine("-----Redirection Device From Id"); - // RedirectionDevice someDevice = sonarManager.GetRedirectionDeviceFromId("{0.0.0.00000000}.{453f6e2f-375e-4b36-97b2-2aa55691ab3c}"); + Console.WriteLine("-----Redirection Channel From Id"); + // PlaybackDevice someDevice = sonarManager.GetPlaybackDeviceFromId("{0.0.0.00000000}.{453f6e2f-375e-4b36-97b2-2aa55691ab3c}"); // Console.WriteLine(someDevice.Id + ", " + someDevice.Name + ", " + someDevice.DataFlow); // foreach (var associatedClassicDevice in someDevice.AssociatedClassicDevices) // { @@ -185,22 +185,22 @@ void GetTest(SonarBridge sonarManager) // } Console.WriteLine("-----Redirection States---------"); - Console.WriteLine(sonarManager.GetRedirectionState(Device.Game, Channel.Monitoring)); - Console.WriteLine(sonarManager.GetRedirectionState(Device.Chat, Channel.Monitoring)); - Console.WriteLine(sonarManager.GetRedirectionState(Device.Media, Channel.Monitoring)); - Console.WriteLine(sonarManager.GetRedirectionState(Device.Aux, Channel.Monitoring)); - Console.WriteLine(sonarManager.GetRedirectionState(Device.Mic, Channel.Monitoring)); - Console.WriteLine(sonarManager.GetRedirectionState(Device.Game, Channel.Stream)); - Console.WriteLine(sonarManager.GetRedirectionState(Device.Chat, Channel.Stream)); - Console.WriteLine(sonarManager.GetRedirectionState(Device.Media, Channel.Stream)); - Console.WriteLine(sonarManager.GetRedirectionState(Device.Aux, Channel.Stream)); - Console.WriteLine(sonarManager.GetRedirectionState(Device.Mic, Channel.Stream)); + Console.WriteLine(sonarManager.GetRedirectionState(Channel.GAME, Mix.MONITORING)); + Console.WriteLine(sonarManager.GetRedirectionState(Channel.CHAT, Mix.MONITORING)); + Console.WriteLine(sonarManager.GetRedirectionState(Channel.MEDIA, Mix.MONITORING)); + Console.WriteLine(sonarManager.GetRedirectionState(Channel.AUX, Mix.MONITORING)); + Console.WriteLine(sonarManager.GetRedirectionState(Channel.MIC, Mix.MONITORING)); + Console.WriteLine(sonarManager.GetRedirectionState(Channel.GAME, Mix.STREAM)); + Console.WriteLine(sonarManager.GetRedirectionState(Channel.CHAT, Mix.STREAM)); + Console.WriteLine(sonarManager.GetRedirectionState(Channel.MEDIA, Mix.STREAM)); + Console.WriteLine(sonarManager.GetRedirectionState(Channel.AUX, Mix.STREAM)); + Console.WriteLine(sonarManager.GetRedirectionState(Channel.MIC, Mix.STREAM)); Console.WriteLine("-----Audience Monitoring-------"); Console.WriteLine(sonarManager.GetAudienceMonitoringState()); Console.WriteLine("-----Routed Processes-----------"); - foreach (Device device in (Device[])Enum.GetValues(typeof(Device))) + foreach (Channel device in (Channel[])Enum.GetValues(typeof(Channel))) { - if (device == Device.Master) + if (device == Channel.MASTER) { continue; } @@ -216,22 +216,22 @@ void GetTest(SonarBridge sonarManager) void SetTest(SonarBridge sonarManager){ - sonarManager.SetMode(Mode.Classic); - sonarManager.SetVolume(0.4, Device.Media); - sonarManager.SetMute(false, Device.Media); - string configId = sonarManager.GetAudioConfigurations(Device.Media).FirstOrDefault(config => config.Name == "Default")?.Id; + sonarManager.SetMode(Mode.CLASSIC); + sonarManager.SetVolume(0.4, Channel.MEDIA); + sonarManager.SetMute(false, Channel.MEDIA); + string configId = sonarManager.GetAudioConfigurations(Channel.MEDIA).FirstOrDefault(config => config.Name == "Default")?.Id; sonarManager.SetConfig(configId); - sonarManager.SetConfig(Device.Media, "Default"); + sonarManager.SetConfig(Channel.MEDIA, "Default"); sonarManager.SetChatMixBalance(0.5); - var redirectionDevices = sonarManager.GetRedirectionDevices(Direction.Input); + var redirectionDevices = sonarManager.GetPlaybackDevices(DataFlow.INPUT); redirectionDevices.GetEnumerator().MoveNext(); - sonarManager.SetClassicRedirectionDevice(redirectionDevices.GetEnumerator().Current.Id, Device.Mic); - sonarManager.SetStreamRedirectionDevice(redirectionDevices.GetEnumerator().Current.Id, Device.Mic); + sonarManager.SetClassicPlaybackDevice(redirectionDevices.GetEnumerator().Current.Id, Channel.MIC); + sonarManager.SetStreamPlaybackDevice(redirectionDevices.GetEnumerator().Current.Id, Channel.MIC); - sonarManager.SetRedirectionState(true, Device.Media, Channel.Stream); + sonarManager.SetRedirectionState(true, Channel.MEDIA, Mix.STREAM); sonarManager.SetAudienceMonitoringState(false); - sonarManager.SetProcessToDeviceRouting(19152, Device.Mic); + sonarManager.SetProcessToDeviceRouting(19152, Channel.MIC); } static void OnModeChangeHandler(object? sender, SonarModeEvent eventArgs) @@ -241,12 +241,12 @@ static void OnModeChangeHandler(object? sender, SonarModeEvent eventArgs) static void OnVolumeChangeHandler(object? sender, SonarVolumeEvent eventArgs) { - Console.WriteLine("Received Volume Event : " + eventArgs.Volume + ", " + eventArgs.Mode + ", " + eventArgs.Device + ", " + eventArgs.Channel); + Console.WriteLine("Received Volume Event : " + eventArgs.Volume + ", " + eventArgs.Mode + ", " + eventArgs.Channel + ", " + eventArgs.Mix); } static void OnMuteChangeHandler(object? sender, SonarMuteEvent eventArgs) { - Console.WriteLine("Received Mute Event : " + eventArgs.Muted + ", " + eventArgs.Mode + ", " + eventArgs.Device + ", " + eventArgs.Channel); + Console.WriteLine("Received Mute Event : " + eventArgs.Muted + ", " + eventArgs.Mode + ", " + eventArgs.Channel + ", " + eventArgs.Mix); } static void OnConfigChangeHandler(object? sender, SonarConfigEvent eventArgs) @@ -259,14 +259,14 @@ static void OnChatMixChangeHandler(object? sender, SonarChatMixEvent eventArgs) Console.WriteLine("Received ChatMix Event : " + eventArgs.Balance); } - static void OnRedirectionDeviceChangeHandler(object? sender, SonarRedirectionDeviceEvent eventArgs) + static void OnRedirectionDeviceChangeHandler(object? sender, SonarPlaybackDeviceEvent eventArgs) { - Console.WriteLine("Received Redirection Device Event : " + eventArgs.RedirectionDeviceId + ", " + eventArgs.Mode + ", " + eventArgs.Device + ", " + eventArgs.Channel); + Console.WriteLine("Received Redirection Channel Event : " + eventArgs.RedirectionDeviceId + ", " + eventArgs.Mode + ", " + eventArgs.Device + ", " + eventArgs.Channel); } static void OnRedirectionStateChangeHandler(object? sender, SonarRedirectionStateEvent eventArgs) { - Console.WriteLine("Received Redirection State Event : " + eventArgs.State + ", " + eventArgs.Device + ", " + eventArgs.Channel); + Console.WriteLine("Received Redirection State Event : " + eventArgs.State + ", " + eventArgs.Channel + ", " + eventArgs.Mix); } static void OnAudienceMonitoringChangeHandler(object? sender, SonarAudienceMonitoringEvent eventArgs) diff --git a/SteelSeriesAPI/Sonar/Enums/Channel.cs b/SteelSeriesAPI/Sonar/Enums/Channel.cs index 367bc5c..4e82dec 100644 --- a/SteelSeriesAPI/Sonar/Enums/Channel.cs +++ b/SteelSeriesAPI/Sonar/Enums/Channel.cs @@ -2,30 +2,82 @@ namespace SteelSeriesAPI.Sonar.Enums; public enum Channel { - Monitoring, - Stream + MASTER, + GAME, + CHAT, + MEDIA, + AUX, + MIC +} + +public enum ChannelMapChoice +{ + JsonDict, + HttpDict, + ChannelDict } public static class ChannelExtensions { - private static readonly Dictionary ChannelMap = new Dictionary + private static readonly Dictionary ChannelJsonMap = new Dictionary + { + { Channel.MASTER, "masters" }, + { Channel.GAME, "game" }, + { Channel.CHAT, "chatRender" }, + { Channel.MEDIA, "media" }, + { Channel.AUX, "aux" }, + { Channel.MIC, "chatCapture" } + }; + + private static readonly Dictionary ChannelHttpMap = new Dictionary { - { Channel.Monitoring, "monitoring" }, - { Channel.Stream, "streaming" } + { Channel.MASTER, "Master" }, + { Channel.GAME, "game" }, + { Channel.CHAT, "chatRender" }, + { Channel.MEDIA, "media" }, + { Channel.AUX, "aux" }, + { Channel.MIC, "chatCapture" } }; - public static string ToDictKey(this Channel channel) + private static readonly Dictionary ChannelMap = new Dictionary + { + { Channel.MASTER, "master" }, + { Channel.GAME, "game" }, + { Channel.CHAT, "chat" }, + { Channel.MEDIA, "media" }, + { Channel.AUX, "aux" }, + { Channel.MIC, "mic" } + }; + + public static string ToDictKey(this Channel channel, ChannelMapChoice context = ChannelMapChoice.JsonDict) { - return ChannelMap[channel]; + return context switch + { + ChannelMapChoice.JsonDict => ChannelJsonMap.ContainsKey(channel) ? ChannelJsonMap[channel] : null, + ChannelMapChoice.HttpDict => ChannelHttpMap.ContainsKey(channel) ? ChannelHttpMap[channel] : null, + ChannelMapChoice.ChannelDict => ChannelMap.ContainsKey(channel) ? ChannelMap[channel] : null, + _ => null + }; } - public static Channel? FromDictKey(string jsonKey) + public static Channel? FromDictKey(string jsonKey, ChannelMapChoice context = ChannelMapChoice.JsonDict) { - foreach (var pair in ChannelMap) + var map = context switch + { + ChannelMapChoice.JsonDict => ChannelJsonMap, + ChannelMapChoice.HttpDict => ChannelHttpMap, + ChannelMapChoice.ChannelDict => ChannelMap, + _ => null + }; + + if (map != null) { - if (pair.Value == jsonKey) + foreach (var pair in map) { - return pair.Key; + if (pair.Value.ToLower() == jsonKey.ToLower()) + { + return pair.Key; + } } } diff --git a/SteelSeriesAPI/Sonar/Enums/DataFlow.cs b/SteelSeriesAPI/Sonar/Enums/DataFlow.cs new file mode 100644 index 0000000..082ff07 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Enums/DataFlow.cs @@ -0,0 +1,34 @@ +namespace SteelSeriesAPI.Sonar.Enums; + +public enum DataFlow +{ + INPUT, + OUTPUT +} + +public static class DataFlowExtensions +{ + private static readonly Dictionary DataFlowMap = new Dictionary + { + { DataFlow.INPUT, "capture" }, + { DataFlow.OUTPUT, "render" } + }; + + public static string ToDictKey(this DataFlow dataFlow) + { + return DataFlowMap[dataFlow]; + } + + public static DataFlow? FromDictKey(string jsonKey) + { + foreach (var pair in DataFlowMap) + { + if (pair.Value == jsonKey) + { + return pair.Key; + } + } + + return null; + } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Enums/Device.cs b/SteelSeriesAPI/Sonar/Enums/Device.cs deleted file mode 100644 index 539f81d..0000000 --- a/SteelSeriesAPI/Sonar/Enums/Device.cs +++ /dev/null @@ -1,86 +0,0 @@ -namespace SteelSeriesAPI.Sonar.Enums; - -public enum Device -{ - Master, - Game, - Chat, - Media, - Aux, - Mic -} - -public enum DeviceMapChoice -{ - JsonDict, - HttpDict, - DeviceDict -} - -public static class DeviceExtensions -{ - private static readonly Dictionary DeviceJsonMap = new Dictionary - { - { Device.Master, "masters" }, - { Device.Game, "game" }, - { Device.Chat, "chatRender" }, - { Device.Media, "media" }, - { Device.Aux, "aux" }, - { Device.Mic, "chatCapture" } - }; - - private static readonly Dictionary DeviceHttpMap = new Dictionary - { - { Device.Master, "Master" }, - { Device.Game, "game" }, - { Device.Chat, "chatRender" }, - { Device.Media, "media" }, - { Device.Aux, "aux" }, - { Device.Mic, "chatCapture" } - }; - - private static readonly Dictionary DeviceMap = new Dictionary - { - { Device.Master, "master" }, - { Device.Game, "game" }, - { Device.Chat, "chat" }, - { Device.Media, "media" }, - { Device.Aux, "aux" }, - { Device.Mic, "mic" } - }; - - public static string ToDictKey(this Device device, DeviceMapChoice context = DeviceMapChoice.JsonDict) - { - return context switch - { - DeviceMapChoice.JsonDict => DeviceJsonMap.ContainsKey(device) ? DeviceJsonMap[device] : null, - DeviceMapChoice.HttpDict => DeviceHttpMap.ContainsKey(device) ? DeviceHttpMap[device] : null, - DeviceMapChoice.DeviceDict => DeviceMap.ContainsKey(device) ? DeviceMap[device] : null, - _ => null - }; - } - - public static Device? FromDictKey(string jsonKey, DeviceMapChoice context = DeviceMapChoice.JsonDict) - { - var map = context switch - { - DeviceMapChoice.JsonDict => DeviceJsonMap, - DeviceMapChoice.HttpDict => DeviceHttpMap, - DeviceMapChoice.DeviceDict => DeviceMap, - _ => null - }; - - if (map != null) - { - foreach (var pair in map) - { - if (pair.Value.ToLower() == jsonKey.ToLower()) - { - return pair.Key; - } - } - } - - return null; - } -} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Enums/Direction.cs b/SteelSeriesAPI/Sonar/Enums/Direction.cs deleted file mode 100644 index 58e641b..0000000 --- a/SteelSeriesAPI/Sonar/Enums/Direction.cs +++ /dev/null @@ -1,34 +0,0 @@ -namespace SteelSeriesAPI.Sonar.Enums; - -public enum Direction -{ - Input, - Output -} - -public static class DirectionExtensions -{ - private static readonly Dictionary DirectionMap = new Dictionary - { - { Direction.Input, "capture" }, - { Direction.Output, "render" } - }; - - public static string ToDictKey(this Direction direction) - { - return DirectionMap[direction]; - } - - public static Direction? FromDictKey(string jsonKey) - { - foreach (var pair in DirectionMap) - { - if (pair.Value == jsonKey) - { - return pair.Key; - } - } - - return null; - } -} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Enums/Mix.cs b/SteelSeriesAPI/Sonar/Enums/Mix.cs new file mode 100644 index 0000000..0c817a0 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Enums/Mix.cs @@ -0,0 +1,34 @@ +namespace SteelSeriesAPI.Sonar.Enums; + +public enum Mix +{ + MONITORING, + STREAM +} + +public static class MixExtensions +{ + private static readonly Dictionary MixMap = new Dictionary + { + { Mix.MONITORING, "monitoring" }, + { Mix.STREAM, "streaming" } + }; + + public static string ToDictKey(this Mix mix) + { + return MixMap[mix]; + } + + public static Mix? FromDictKey(string jsonKey) + { + foreach (var pair in MixMap) + { + if (pair.Value == jsonKey) + { + return pair.Key; + } + } + + return null; + } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Enums/Mode.cs b/SteelSeriesAPI/Sonar/Enums/Mode.cs index 0eca32a..de0a76a 100644 --- a/SteelSeriesAPI/Sonar/Enums/Mode.cs +++ b/SteelSeriesAPI/Sonar/Enums/Mode.cs @@ -2,8 +2,8 @@ namespace SteelSeriesAPI.Sonar.Enums; public enum Mode { - Classic, - Streamer + CLASSIC, + STREAMER } public enum ModeMapChoice @@ -16,14 +16,14 @@ public static class ModeExtensions { private static readonly Dictionary PrimaryModeMap = new Dictionary { - { Mode.Classic, "classic" }, - { Mode.Streamer, "streamer" } + { Mode.CLASSIC, "classic" }, + { Mode.STREAMER, "streamer" } }; private static readonly Dictionary SecondaryModeMap = new Dictionary { - { Mode.Classic, "classic" }, - { Mode.Streamer, "stream" } + { Mode.CLASSIC, "classic" }, + { Mode.STREAMER, "stream" } }; public static string ToDictKey(this Mode mode, ModeMapChoice context = ModeMapChoice.StreamerDict) diff --git a/SteelSeriesAPI/Sonar/Enums/RoutedProcessState.cs b/SteelSeriesAPI/Sonar/Enums/RoutedProcessState.cs index 57985bd..5e0a91a 100644 --- a/SteelSeriesAPI/Sonar/Enums/RoutedProcessState.cs +++ b/SteelSeriesAPI/Sonar/Enums/RoutedProcessState.cs @@ -2,18 +2,18 @@ namespace SteelSeriesAPI.Sonar.Enums; public enum RoutedProcessState { - Active, - Inactive, - Expired + ACTIVE, + INACTIVE, + EXPIRED } public static class RoutedProcessStateExtensions { private static readonly Dictionary RoutedProcessStateMap = new Dictionary { - { RoutedProcessState.Active, "active" }, - { RoutedProcessState.Inactive, "inactive" }, - { RoutedProcessState.Expired, "expired" }, + { RoutedProcessState.ACTIVE, "active" }, + { RoutedProcessState.INACTIVE, "inactive" }, + { RoutedProcessState.EXPIRED, "expired" }, }; public static string ToDictKey(this RoutedProcessState state) diff --git a/SteelSeriesAPI/Sonar/Events/SonarMuteEvent.cs b/SteelSeriesAPI/Sonar/Events/SonarMuteEvent.cs index c637501..3f2bf5b 100644 --- a/SteelSeriesAPI/Sonar/Events/SonarMuteEvent.cs +++ b/SteelSeriesAPI/Sonar/Events/SonarMuteEvent.cs @@ -11,6 +11,6 @@ public class SonarMuteEvent : EventArgs public Mode Mode { get; set; } - public Device Device { get; set; } - public Channel? Channel { get; set; } + public Channel Channel { get; set; } + public Mix? Mix { get; set; } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Events/SonarRedirectionDeviceEvent.cs b/SteelSeriesAPI/Sonar/Events/SonarPlaybackDeviceEvent.cs similarity index 74% rename from SteelSeriesAPI/Sonar/Events/SonarRedirectionDeviceEvent.cs rename to SteelSeriesAPI/Sonar/Events/SonarPlaybackDeviceEvent.cs index 5db2057..8e3e76b 100644 --- a/SteelSeriesAPI/Sonar/Events/SonarRedirectionDeviceEvent.cs +++ b/SteelSeriesAPI/Sonar/Events/SonarPlaybackDeviceEvent.cs @@ -2,7 +2,7 @@ namespace SteelSeriesAPI.Sonar.Events; -public class SonarRedirectionDeviceEvent : EventArgs +public class SonarPlaybackDeviceEvent : EventArgs { // /classicRedirections/game/deviceId/%7B0.0.0.00000000%7D.%7B1e1ebefc-2c51-4675-aebe-085a06efd255%7D // /streamRedirections/monitoring/deviceId/%7B0.0.0.00000000%7D.%7B1e1ebefc-2c51-4675-aebe-085a06efd255%7D @@ -11,6 +11,6 @@ public class SonarRedirectionDeviceEvent : EventArgs public Mode Mode { get; set; } - public Device? Device { get; set; } - public Channel? Channel { get; set; } + public Channel? Device { get; set; } + public Mix? Channel { get; set; } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Events/SonarRedirectionStateEvent.cs b/SteelSeriesAPI/Sonar/Events/SonarRedirectionStateEvent.cs index 56c8137..bdda476 100644 --- a/SteelSeriesAPI/Sonar/Events/SonarRedirectionStateEvent.cs +++ b/SteelSeriesAPI/Sonar/Events/SonarRedirectionStateEvent.cs @@ -8,6 +8,6 @@ public class SonarRedirectionStateEvent : EventArgs public bool State { get; set; } - public Device Device { get; set; } public Channel Channel { get; set; } + public Mix Mix { get; set; } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Events/SonarVolumeEvent.cs b/SteelSeriesAPI/Sonar/Events/SonarVolumeEvent.cs index 8bea8d4..65d3098 100644 --- a/SteelSeriesAPI/Sonar/Events/SonarVolumeEvent.cs +++ b/SteelSeriesAPI/Sonar/Events/SonarVolumeEvent.cs @@ -11,6 +11,6 @@ public class SonarVolumeEvent : EventArgs public Mode Mode { get; set; } - public Device Device { get; set; } - public Channel? Channel { get; set; } + public Channel Channel { get; set; } + public Mix? Mix { get; set; } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs index b0219c2..9b76680 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs @@ -2,7 +2,6 @@ using System.Text.Json; using SteelSeriesAPI.Sonar.Interfaces; using SteelSeriesAPI.Sonar.Enums; -using Channel = SteelSeriesAPI.Sonar.Enums.Channel; namespace SteelSeriesAPI.Sonar.Http; @@ -21,26 +20,26 @@ public void SetMode(Mode mode) Thread.Sleep(100); // Prevent bugs/freezes/crashes } - public void SetVolume(double vol, Device device) + public void SetVolume(double vol, Channel channel) { string _vol = vol.ToString("0.00", CultureInfo.InvariantCulture); - new HttpPut("volumeSettings/classic/" + device.ToDictKey(DeviceMapChoice.HttpDict) + "/Volume/" + _vol); + new HttpPut("volumeSettings/classic/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/Volume/" + _vol); } - public void SetVolume(double vol, Device device, Channel channel) + public void SetVolume(double vol, Channel channel, Mix mix) { string _vol = vol.ToString("0.00", CultureInfo.InvariantCulture); - new HttpPut("volumeSettings/streamer/" + channel.ToDictKey() + "/" + device.ToDictKey(DeviceMapChoice.HttpDict) + "/volume/" + _vol); + new HttpPut("volumeSettings/streamer/" + mix.ToDictKey() + "/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/volume/" + _vol); } - public void SetMute(bool mute, Device device) + public void SetMute(bool mute, Channel channel) { - new HttpPut("volumeSettings/classic/" + device.ToDictKey(DeviceMapChoice.HttpDict) + "/Mute/" + mute); + new HttpPut("volumeSettings/classic/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/Mute/" + mute); } - public void SetMute(bool mute, Device device, Channel channel) + public void SetMute(bool mute, Channel channel, Mix mix) { - new HttpPut("volumeSettings/streamer/" + channel.ToDictKey() + "/" + device.ToDictKey(DeviceMapChoice.HttpDict) + "/isMuted/" + mute); + new HttpPut("volumeSettings/streamer/" + mix.ToDictKey() + "/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/isMuted/" + mute); } public void SetConfig(string configId) @@ -50,9 +49,9 @@ public void SetConfig(string configId) new HttpPut("configs/" + configId + "/select"); } - public void SetConfig(Device device, string name) + public void SetConfig(Channel channel, string name) { - var configs = _sonarBridge.GetAudioConfigurations(device).ToList(); + var configs = _sonarBridge.GetAudioConfigurations(channel).ToList(); foreach (var config in configs) { if (config.Name == name) @@ -78,29 +77,29 @@ public void SetChatMixBalance(double balance) new HttpPut("chatMix?balance=" + balance.ToString("0.00", CultureInfo.InvariantCulture)); } - public void SetClassicRedirectionDevice(string deviceId, Device device) + public void SetClassicPlaybackDevice(string deviceId, Channel channel) { - new HttpPut("classicRedirections/" + device.ToDictKey(DeviceMapChoice.DeviceDict) +"/deviceId/" + deviceId); + new HttpPut("classicRedirections/" + channel.ToDictKey(ChannelMapChoice.ChannelDict) +"/deviceId/" + deviceId); } - public void SetStreamRedirectionDevice(string deviceId, Channel channel) + public void SetStreamPlaybackDevice(string deviceId, Mix mix) { - new HttpPut("streamRedirections/" + channel.ToDictKey() +"/deviceId/" + deviceId); + new HttpPut("streamRedirections/" + mix.ToDictKey() +"/deviceId/" + deviceId); } - public void SetStreamRedirectionDevice(string deviceId, Device device) + public void SetStreamPlaybackDevice(string deviceId, Channel channel) { - if (device != Device.Mic) + if (channel != Channel.MIC) { - throw new Exception("Can only change stream redirection device for Mic"); + throw new Exception("Can only change stream redirection channel for Mic"); } - new HttpPut("streamRedirections/" + device.ToDictKey(DeviceMapChoice.DeviceDict) +"/deviceId/" + deviceId); + new HttpPut("streamRedirections/" + channel.ToDictKey(ChannelMapChoice.ChannelDict) +"/deviceId/" + deviceId); } - public void SetRedirectionState(bool newState, Device device, Channel channel) + public void SetRedirectionState(bool newState, Channel channel, Mix mix) { - new HttpPut("streamRedirections/" + channel.ToDictKey() + "/redirections/" + device.ToDictKey() + + new HttpPut("streamRedirections/" + mix.ToDictKey() + "/redirections/" + channel.ToDictKey() + "/isEnabled/" + newState); } @@ -109,9 +108,9 @@ public void SetAudienceMonitoringState(bool newState) new HttpPut("streamRedirections/isStreamMonitoringEnabled/" + newState); } - public void SetProcessToDeviceRouting(int pId, Device device) + public void SetProcessToDeviceRouting(int pId, Channel channel) { - if (device == Device.Master) + if (channel == Channel.MASTER) { throw new Exception("Can't set process to master routing"); } @@ -120,9 +119,9 @@ public void SetProcessToDeviceRouting(int pId, Device device) foreach (var element in audioDeviceRouting.RootElement.EnumerateArray()) { - if (element.GetProperty("role").GetString() == device.ToDictKey()) + if (element.GetProperty("role").GetString() == channel.ToDictKey()) { - if (device == Device.Mic) + if (channel == Channel.MIC) { new HttpPut("AudioDeviceRouting/capture/" + element.GetProperty("deviceId").GetString() + "/" + pId); break; diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs index 4b837ed..effd04d 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs @@ -22,40 +22,40 @@ public Mode GetMode() return (Mode)ModeExtensions.FromDictKey(mode, ModeMapChoice.StreamDict); } - public double GetVolume(Device device) + public double GetVolume(Channel channel) { JsonDocument volumeSettings = new HttpProvider("volumeSettings/classic/").Provide(); - if (device == Device.Master) + if (channel == Channel.MASTER) return volumeSettings.RootElement.GetProperty("masters").GetProperty("classic").GetProperty("volume").GetDouble(); - return volumeSettings.RootElement.GetProperty("devices").GetProperty(device.ToDictKey()).GetProperty("classic").GetProperty("volume").GetDouble(); + return volumeSettings.RootElement.GetProperty("devices").GetProperty(channel.ToDictKey()).GetProperty("classic").GetProperty("volume").GetDouble(); } - public double GetVolume(Device device, Channel channel) + public double GetVolume(Channel channel, Mix mix) { JsonDocument volumeSettings = new HttpProvider("volumeSettings/streamer/").Provide(); - if (device == Device.Master) - return volumeSettings.RootElement.GetProperty("masters").GetProperty("stream").GetProperty(channel.ToDictKey()).GetProperty("volume").GetDouble(); - return volumeSettings.RootElement.GetProperty("devices").GetProperty(device.ToDictKey()).GetProperty("stream").GetProperty(channel.ToDictKey()).GetProperty("volume").GetDouble(); + if (channel == Channel.MASTER) + return volumeSettings.RootElement.GetProperty("masters").GetProperty("stream").GetProperty(mix.ToDictKey()).GetProperty("volume").GetDouble(); + return volumeSettings.RootElement.GetProperty("devices").GetProperty(channel.ToDictKey()).GetProperty("stream").GetProperty(mix.ToDictKey()).GetProperty("volume").GetDouble(); } - public bool GetMute(Device device) + public bool GetMute(Channel channel) { JsonDocument volumeSettings = new HttpProvider("volumeSettings/classic/").Provide(); - if (device == Device.Master) + if (channel == Channel.MASTER) return volumeSettings.RootElement.GetProperty("masters").GetProperty("classic").GetProperty("muted").GetBoolean(); - return volumeSettings.RootElement.GetProperty("devices").GetProperty(device.ToDictKey()).GetProperty("classic").GetProperty("muted").GetBoolean(); + return volumeSettings.RootElement.GetProperty("devices").GetProperty(channel.ToDictKey()).GetProperty("classic").GetProperty("muted").GetBoolean(); } - public bool GetMute(Device device, Channel channel) + public bool GetMute(Channel channel, Mix mix) { JsonDocument volumeSettings = new HttpProvider("volumeSettings/streamer/").Provide(); - if (device == Device.Master) - return volumeSettings.RootElement.GetProperty("masters").GetProperty("stream").GetProperty(channel.ToDictKey()).GetProperty("muted").GetBoolean(); - return volumeSettings.RootElement.GetProperty("devices").GetProperty(device.ToDictKey()).GetProperty("stream").GetProperty(channel.ToDictKey()).GetProperty("muted").GetBoolean(); + if (channel == Channel.MASTER) + return volumeSettings.RootElement.GetProperty("masters").GetProperty("stream").GetProperty(mix.ToDictKey()).GetProperty("muted").GetBoolean(); + return volumeSettings.RootElement.GetProperty("devices").GetProperty(channel.ToDictKey()).GetProperty("stream").GetProperty(mix.ToDictKey()).GetProperty("muted").GetBoolean(); } #region AudioConfigs @@ -70,7 +70,7 @@ public IEnumerable GetAllAudioConfigurations() string id = element.GetProperty("id").GetString(); string name = element.GetProperty("name").GetString(); - yield return new SonarAudioConfiguration(id, name, (Device)DeviceExtensions.FromDictKey(vDevice)); + yield return new SonarAudioConfiguration(id, name, (Channel)ChannelExtensions.FromDictKey(vDevice)); } } @@ -91,9 +91,9 @@ public SonarAudioConfiguration GetAudioConfiguration(string configId) return sonarConfig; } - public IEnumerable GetAudioConfigurations(Device device) + public IEnumerable GetAudioConfigurations(Channel channel) { - if (device == Device.Master) + if (channel == Channel.MASTER) { throw new Exception("Can't get audio configurations for master"); } @@ -103,7 +103,7 @@ public IEnumerable GetAudioConfigurations(Device device foreach (var config in configs) { - if (config.AssociatedDevice == device) + if (config.AssociatedChannel == channel) { deviceConfigs.Add(config); } @@ -112,9 +112,9 @@ public IEnumerable GetAudioConfigurations(Device device return deviceConfigs.OrderBy(s => s.Name); } - public SonarAudioConfiguration GetSelectedAudioConfiguration(Device device) + public SonarAudioConfiguration GetSelectedAudioConfiguration(Channel channel) { - if (device == Device.Master) + if (channel == Channel.MASTER) { throw new Exception("Can't get audio configuration for master"); } @@ -124,7 +124,7 @@ public SonarAudioConfiguration GetSelectedAudioConfiguration(Device device) foreach (var config in selectedConfigs.RootElement.EnumerateArray()) { - if (config.GetProperty("virtualAudioDevice").GetString() == device.ToDictKey()) + if (config.GetProperty("virtualAudioDevice").GetString() == channel.ToDictKey()) { sConfig = config; break; @@ -135,7 +135,7 @@ public SonarAudioConfiguration GetSelectedAudioConfiguration(Device device) string name = sConfig.GetProperty("name").GetString(); string vDevice = sConfig.GetProperty("virtualAudioDevice").GetString(); - return new SonarAudioConfiguration(id, name, (Device)DeviceExtensions.FromDictKey(vDevice)); + return new SonarAudioConfiguration(id, name, (Channel)ChannelExtensions.FromDictKey(vDevice)); } #endregion @@ -167,7 +167,7 @@ public bool GetChatMixState() #endregion - public IEnumerable GetRedirectionDevices(Direction direction) + public IEnumerable GetPlaybackDevices(DataFlow _dataFlow) { JsonDocument audioDevices = new HttpProvider("audioDevices").Provide(); JsonDocument classicRedirections = new HttpProvider("classicRedirections").Provide(); @@ -183,23 +183,23 @@ public IEnumerable GetRedirectionDevices(Direction direction) string id = element.GetProperty("id").GetString(); string name = element.GetProperty("friendlyName").GetString(); string dataFlow = element.GetProperty("dataFlow").GetString(); - List associatedClassicDevices = new List(); + List associatedClassicDevices = new List(); ArrayList associatedStreamDevices = new ArrayList(); GetAssociatedDevices(id, associatedClassicDevices, associatedStreamDevices); - if (dataFlow == direction.ToDictKey()) + if (dataFlow == _dataFlow.ToDictKey()) { - yield return new RedirectionDevice(id, name, (Direction)DirectionExtensions.FromDictKey(dataFlow), associatedClassicDevices, associatedStreamDevices); + yield return new PlaybackDevice(id, name, (DataFlow)DataFlowExtensions.FromDictKey(dataFlow), associatedClassicDevices, associatedStreamDevices); } } } - public RedirectionDevice GetClassicRedirectionDevice(Device device) + public PlaybackDevice GetClassicPlaybackDevice(Channel channel) { - if (device == Device.Master) + if (channel == Channel.MASTER) { - throw new Exception("Can't get redirection device for master"); + throw new Exception("Can't get redirection channel for master"); } JsonDocument classicRedirections = new HttpProvider("classicRedirections").Provide(); @@ -207,7 +207,7 @@ public RedirectionDevice GetClassicRedirectionDevice(Device device) foreach (var element in classicRedirections.RootElement.EnumerateArray()) { - if (element.GetProperty("id").GetString() == device.ToDictKey(DeviceMapChoice.DeviceDict)) + if (element.GetProperty("id").GetString() == channel.ToDictKey(ChannelMapChoice.ChannelDict)) { cRedirections = element; break; @@ -215,7 +215,7 @@ public RedirectionDevice GetClassicRedirectionDevice(Device device) } string deviceId = cRedirections.GetProperty("deviceId").GetString(); - List associatedClassicDevices = new List(); + List associatedClassicDevices = new List(); ArrayList associatedStreamDevices = new ArrayList(); GetAssociatedDevices(deviceId, associatedClassicDevices, associatedStreamDevices); @@ -223,19 +223,19 @@ public RedirectionDevice GetClassicRedirectionDevice(Device device) JsonDocument audioDevice = new HttpProvider("audioDevices/" + deviceId).Provide(); string name = audioDevice.RootElement.GetProperty("friendlyName").GetString(); - Direction dataFlow = (Direction)DirectionExtensions.FromDictKey(audioDevice.RootElement.GetProperty("dataFlow").GetString()); + DataFlow dataFlow = (DataFlow)DataFlowExtensions.FromDictKey(audioDevice.RootElement.GetProperty("dataFlow").GetString()); - return new RedirectionDevice(deviceId, name, dataFlow, associatedClassicDevices, associatedStreamDevices); + return new PlaybackDevice(deviceId, name, dataFlow, associatedClassicDevices, associatedStreamDevices); } - public RedirectionDevice GetStreamRedirectionDevice(Channel channel) + public PlaybackDevice GetStreamPlaybackDevice(Mix mix) { JsonDocument streamRedirections = new HttpProvider("streamRedirections").Provide(); JsonElement sRedirections = default; foreach (var element in streamRedirections.RootElement.EnumerateArray()) { - if (element.GetProperty("streamRedirectionId").GetString() == channel.ToDictKey()) + if (element.GetProperty("streamRedirectionId").GetString() == mix.ToDictKey()) { sRedirections = element; break; @@ -243,23 +243,23 @@ public RedirectionDevice GetStreamRedirectionDevice(Channel channel) } string deviceId = sRedirections.GetProperty("deviceId").GetString(); - List associatedClassicDevices = new List();ArrayList associatedStreamDevices = new ArrayList(); + List associatedClassicDevices = new List();ArrayList associatedStreamDevices = new ArrayList(); GetAssociatedDevices(deviceId, associatedClassicDevices, associatedStreamDevices); JsonDocument audioDevice = new HttpProvider("audioDevices/" + deviceId).Provide(); string name = audioDevice.RootElement.GetProperty("friendlyName").GetString(); - Direction dataFlow = (Direction)DirectionExtensions.FromDictKey(audioDevice.RootElement.GetProperty("dataFlow").GetString()); + DataFlow dataFlow = (DataFlow)DataFlowExtensions.FromDictKey(audioDevice.RootElement.GetProperty("dataFlow").GetString()); - return new RedirectionDevice(deviceId, name, dataFlow, associatedClassicDevices, associatedStreamDevices); + return new PlaybackDevice(deviceId, name, dataFlow, associatedClassicDevices, associatedStreamDevices); } - public RedirectionDevice GetStreamRedirectionDevice(Device device) + public PlaybackDevice GetStreamPlaybackDevice(Channel channel) { - if (device != Device.Mic) + if (channel != Channel.MIC) { - throw new Exception("Can only get stream redirection device for Mic"); + throw new Exception("Can only get stream redirection channel for Mic"); } JsonDocument streamRedirections = new HttpProvider("streamRedirections").Provide(); @@ -267,7 +267,7 @@ public RedirectionDevice GetStreamRedirectionDevice(Device device) foreach (var element in streamRedirections.RootElement.EnumerateArray()) { - if (element.GetProperty("streamRedirectionId").GetString() == device.ToDictKey(DeviceMapChoice.DeviceDict)) + if (element.GetProperty("streamRedirectionId").GetString() == channel.ToDictKey(ChannelMapChoice.ChannelDict)) { sRedirections = element; break; @@ -275,7 +275,7 @@ public RedirectionDevice GetStreamRedirectionDevice(Device device) } string deviceId = sRedirections.GetProperty("deviceId").GetString(); - List associatedClassicDevices = new List(); + List associatedClassicDevices = new List(); ArrayList associatedStreamDevices = new ArrayList(); GetAssociatedDevices(deviceId, associatedClassicDevices, associatedStreamDevices); @@ -283,12 +283,12 @@ public RedirectionDevice GetStreamRedirectionDevice(Device device) JsonDocument audioDevice = new HttpProvider("audioDevices/" + deviceId).Provide(); string name = audioDevice.RootElement.GetProperty("friendlyName").GetString(); - Direction dataFlow = (Direction)DirectionExtensions.FromDictKey(audioDevice.RootElement.GetProperty("dataFlow").GetString()); + DataFlow dataFlow = (DataFlow)DataFlowExtensions.FromDictKey(audioDevice.RootElement.GetProperty("dataFlow").GetString()); - return new RedirectionDevice(deviceId, name, dataFlow, associatedClassicDevices, associatedStreamDevices); + return new PlaybackDevice(deviceId, name, dataFlow, associatedClassicDevices, associatedStreamDevices); } - public RedirectionDevice GetRedirectionDeviceFromId(string deviceId) + public PlaybackDevice GetPlaybackDeviceFromId(string deviceId) { try { @@ -297,21 +297,21 @@ public RedirectionDevice GetRedirectionDeviceFromId(string deviceId) string id = device.GetProperty("id").GetString(); string name = device.GetProperty("friendlyName").GetString(); string dataFlow = device.GetProperty("dataFlow").GetString(); - List associatedClassicDevices = new List(); + List associatedClassicDevices = new List(); ArrayList associatedStreamDevices = new ArrayList(); GetAssociatedDevices(deviceId, associatedClassicDevices, associatedStreamDevices); - return new RedirectionDevice(id, name, (Direction)DirectionExtensions.FromDictKey(dataFlow), associatedClassicDevices, associatedStreamDevices); + return new PlaybackDevice(id, name, (DataFlow)DataFlowExtensions.FromDictKey(dataFlow), associatedClassicDevices, associatedStreamDevices); } catch (Exception e) { Console.WriteLine(e); - throw new Exception("Can't get any device from this Id, maybe the device doesn't exist or its Id changed."); + throw new Exception("Can't get any channel from this Id, maybe the channel doesn't exist or its Id changed."); } } - private void GetAssociatedDevices(string deviceId, List associatedClassicDevices, ArrayList associatedStreamDevices) + private void GetAssociatedDevices(string deviceId, List associatedClassicDevices, ArrayList associatedStreamDevices) { JsonDocument classicRedirections = new HttpProvider("classicRedirections").Provide(); JsonDocument streamRedirections = new HttpProvider("streamRedirections").Provide(); @@ -320,7 +320,7 @@ private void GetAssociatedDevices(string deviceId, List associatedClassi { if (element.GetProperty("deviceId").GetString() == deviceId) { - associatedClassicDevices.Add((Device)DeviceExtensions.FromDictKey(element.GetProperty("id").GetString(), DeviceMapChoice.DeviceDict)); + associatedClassicDevices.Add((Channel)ChannelExtensions.FromDictKey(element.GetProperty("id").GetString(), ChannelMapChoice.ChannelDict)); } } @@ -330,19 +330,19 @@ private void GetAssociatedDevices(string deviceId, List associatedClassi { if (element.GetProperty("streamRedirectionId").GetString() == "mic") { - associatedStreamDevices.Add((Device)DeviceExtensions.FromDictKey(element.GetProperty("streamRedirectionId").GetString(), DeviceMapChoice.DeviceDict)); + associatedStreamDevices.Add((Channel)ChannelExtensions.FromDictKey(element.GetProperty("streamRedirectionId").GetString(), ChannelMapChoice.ChannelDict)); } else { - associatedStreamDevices.Add((Channel)ChannelExtensions.FromDictKey(element.GetProperty("streamRedirectionId").GetString())); + associatedStreamDevices.Add((Mix)MixExtensions.FromDictKey(element.GetProperty("streamRedirectionId").GetString())); } } } } - public bool GetRedirectionState(Device device, Channel channel) + public bool GetRedirectionState(Channel channel, Mix mix) { - if (device == Device.Master) + if (channel == Channel.MASTER) { throw new Exception("Can't get redirection state for master"); } @@ -352,7 +352,7 @@ public bool GetRedirectionState(Device device, Channel channel) foreach (var element in streamRedirections.RootElement.EnumerateArray()) { - if (element.GetProperty("streamRedirectionId").GetString() == channel.ToDictKey()) + if (element.GetProperty("streamRedirectionId").GetString() == mix.ToDictKey()) { streamChannel = element; break; @@ -363,7 +363,7 @@ public bool GetRedirectionState(Device device, Channel channel) foreach (var element in streamChannel.GetProperty("status").EnumerateArray()) { - if (element.GetProperty("role").GetString() == device.ToDictKey()) + if (element.GetProperty("role").GetString() == channel.ToDictKey()) { status = element; break; @@ -382,9 +382,9 @@ public bool GetAudienceMonitoringState() return streamMonitoring.RootElement.GetBoolean(); } - public IEnumerable GetRoutedProcess(Device device) + public IEnumerable GetRoutedProcess(Channel channel) { - if (device == Device.Master) + if (channel == Channel.MASTER) { throw new Exception("Can't get routed process for Master"); } @@ -393,7 +393,7 @@ public IEnumerable GetRoutedProcess(Device device) foreach (var element in audioDeviceRoutings.RootElement.EnumerateArray()) { - if (element.GetProperty("role").GetString() != device.ToDictKey()) + if (element.GetProperty("role").GetString() != channel.ToDictKey()) { continue; } @@ -408,7 +408,7 @@ public IEnumerable GetRoutedProcess(Device device) RoutedProcessState state = (RoutedProcessState)RoutedProcessStateExtensions.FromDictKey(session.GetProperty("state").GetString()); string displayName = session.GetProperty("displayName").GetString(); - if (processName == "Idle" && displayName == "Idle" && state == RoutedProcessState.Inactive && pId == 0) + if (processName == "Idle" && displayName == "Idle" && state == RoutedProcessState.INACTIVE && pId == 0) { continue; } diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs index e214d7b..ed732c6 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs @@ -11,86 +11,86 @@ public interface ISonarCommandHandler void SetMode(Mode mode); /// - /// Set the volume of a Sonar + /// Set the volume of a Sonar /// /// The volume you want to set, between 1 and 0 - /// The you want to change the volume - void SetVolume(double vol, Device device); + /// The you want to change the volume + void SetVolume(double vol, Channel channel); /// - /// Set the volume of a Streamer mode Sonar + /// Set the volume of a Streamer mode Sonar /// /// The volume you want to set, between 1 and 0 - /// The you want to change the volume /// The you want to change the volume - void SetVolume(double vol, Device device, Channel channel); + /// The you want to change the volume + void SetVolume(double vol, Channel channel, Mix mix); /// - /// Mute or unmute a Sonar + /// Mute or unmute a Sonar /// /// The new muted state - /// The you want to un/mute - void SetMute(bool mute, Device device); + /// The you want to un/mute + void SetMute(bool mute, Channel channel); /// - /// Mute or unmute a Streamer mode Sonar + /// Mute or unmute a Streamer mode Sonar /// /// The new muted state - /// The you want to un/mute /// The you want to un/mute - void SetMute(bool mute, Device device, Channel channel); + /// The you want to un/mute + void SetMute(bool mute, Channel channel, Mix mix); /// - /// Set the config of a Sonar by giving its id + /// Set the config of a Sonar by giving its id /// /// For more explanation, go on the GitHub wiki /// The id of the config void SetConfig(string configId); /// - /// Set the config of a Sonar by giving its name + /// Set the config of a Sonar by giving its name /// /// For more explanation, go on the GitHub wiki - /// The you want to change the config + /// The you want to change the config /// The name of the config - void SetConfig(Device device, string name); + void SetConfig(Channel channel, string name); /// /// Set the balance of the ChatMix /// - /// -1 to balance to Game device
1 to balance to Chat device
+ /// -1 to balance to Game channel
1 to balance to Chat channel
/// A between -1 and 1 void SetChatMixBalance(double balance); /// - /// Set the Redirection Device of a Sonar using its ID + /// Set the Redirection Channel of a Sonar using its ID /// - /// The id of the new Redirection Device - /// The Sonar you want to change the Redirection Device - void SetClassicRedirectionDevice(string deviceId, Device device); + /// The id of the new Redirection Channel + /// The Sonar you want to change the Redirection Channel + void SetClassicPlaybackDevice(string deviceId, Channel channel); /// - /// Set the Redirection Device of a Streamer mode Sonar using its ID + /// Set the Redirection Channel of a Streamer mode Sonar using its ID /// - /// The id of the new Redirection Device - /// The Sonar you want to change the Redirection Device - void SetStreamRedirectionDevice(string deviceId, Channel channel); + /// The id of the new Redirection Channel + /// The Sonar you want to change the Redirection Channel + void SetStreamPlaybackDevice(string deviceId, Mix mix); /// - /// Set the Redirection Device of the Streamer mode Sonar using its ID + /// Set the Redirection Channel of the Streamer mode Sonar using its ID /// - /// The id of the new Redirection Device - /// The Sonar you want to change the redirection device - /// should be set to for it to work - void SetStreamRedirectionDevice(string deviceId, Device device = Device.Mic); + /// The id of the new Redirection Channel + /// The Sonar you want to change the redirection channel + /// should be set to for it to work + void SetStreamPlaybackDevice(string deviceId, Channel channel = Channel.MIC); /// - /// Enable or disable the Redirection of the chosen Sonar of the chosen Sonar + /// Enable or disable the Redirection of the chosen Sonar of the chosen Sonar /// /// The new state of the Redirection - /// The Sonar you want to un/mute a Sonar redirection channel - /// The Sonar you want to un/mute - void SetRedirectionState(bool newState, Device device, Channel channel); + /// The Sonar you want to un/mute a Sonar redirection mix + /// The Sonar you want to un/mute + void SetRedirectionState(bool newState, Channel channel, Mix mix); /// /// Listen to what your audience hear @@ -99,9 +99,9 @@ public interface ISonarCommandHandler void SetAudienceMonitoringState(bool newState); /// - /// Redirect the audio of an app to a Sonar + /// Redirect the audio of an app to a Sonar /// /// The process ID of the app - /// The Sonar you want to set the app audio - void SetProcessToDeviceRouting(int pId, Device device); + /// The Sonar you want to set the app audio + void SetProcessToDeviceRouting(int pId, Channel channel); } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs index 5b068f4..b909867 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs @@ -12,34 +12,34 @@ public interface ISonarDataProvider Mode GetMode(); /// - /// Get the volume of a Sonar + /// Get the volume of a Sonar /// - /// The Sonar you want the volume - /// The volume of the channel in double, value between 0 and 1 - double GetVolume(Device device); + /// The Sonar you want the volume + /// The volume of the mix in double, value between 0 and 1 + double GetVolume(Channel channel); /// - /// Get the volume of a Steamer mode Sonar + /// Get the volume of a Steamer mode Sonar /// - /// The Sonar you want the volume /// The Sonar you want the volume - /// The volume of the channel in double, value between 0 and 1 - double GetVolume(Device device, Channel channel); + /// The Sonar you want the volume + /// The volume of the mix in double, value between 0 and 1 + double GetVolume(Channel channel, Mix mix); /// - /// Get the mute state of a Sonar + /// Get the mute state of a Sonar /// - /// The Sonar you want the mute state + /// The Sonar you want the mute state /// The mute state, a boolean - bool GetMute(Device device); + bool GetMute(Channel channel); /// - /// Get the mute state of a Streamer mode Sonar + /// Get the mute state of a Streamer mode Sonar /// - /// The Sonar you want the mute state /// The Sonar you want the mute state + /// The Sonar you want the mute state /// The mute state, a boolean - bool GetMute(Device device, Channel channel); + bool GetMute(Channel channel, Mix mix); /// /// Get all audio configurations from Sonar @@ -55,18 +55,18 @@ public interface ISonarDataProvider SonarAudioConfiguration GetAudioConfiguration(string configId); /// - /// Get all audio configurations of a from Sonar + /// Get all audio configurations of a from Sonar /// - /// The device you want the configs + /// The channel you want the configs /// An IEnumerable of ordered alphabetically - IEnumerable GetAudioConfigurations(Device device); + IEnumerable GetAudioConfigurations(Channel channel); /// - /// Get the current audio configuration of a chosen + /// Get the current audio configuration of a chosen /// - /// The device you want the current config + /// The channel you want the current config /// A - SonarAudioConfiguration GetSelectedAudioConfiguration(Device device); + SonarAudioConfiguration GetSelectedAudioConfiguration(Channel channel); /// /// Get the actual ChatMix balance value @@ -83,46 +83,46 @@ public interface ISonarDataProvider /// /// Get all the in/output Redirection Devices (Windows devices) /// - /// The DataFlow of the device (In/Output) - /// A list of - IEnumerable GetRedirectionDevices(Direction direction); + /// The DataFlow of the channel (In/Output) + /// A list of + IEnumerable GetPlaybackDevices(DataFlow dataFlow); /// - /// Get the current Redirection Device of a Sonar + /// Get the current Redirection Channel of a Sonar /// - /// The Sonar you want the redirection device - /// - RedirectionDevice GetClassicRedirectionDevice(Device device); + /// The Sonar you want the redirection channel + /// + PlaybackDevice GetClassicPlaybackDevice(Channel channel); /// - /// Get the current Redirection Device of a Streamer mode Sonar + /// Get the current Redirection Channel of a Streamer mode Sonar /// - /// The Sonar you want the redirection device - /// A - RedirectionDevice GetStreamRedirectionDevice(Channel channel); + /// The Sonar you want the redirection channel + /// A + PlaybackDevice GetStreamPlaybackDevice(Mix mix); /// - /// Get the current Redirection Device of the Streamer mode Sonar + /// Get the current Redirection Channel of the Streamer mode Sonar /// - /// The Sonar you want to change the redirection device - /// - /// should be set to for it to work - RedirectionDevice GetStreamRedirectionDevice(Device device = Device.Mic); + /// The Sonar you want to change the redirection channel + /// + /// should be set to for it to work + PlaybackDevice GetStreamPlaybackDevice(Channel channel = Channel.MIC); /// - /// Get a Redirection Device using its ID + /// Get a Redirection Channel using its ID /// - /// The ID of the Redirection Device - /// - RedirectionDevice GetRedirectionDeviceFromId(string deviceId); + /// The ID of the Redirection Channel + /// + PlaybackDevice GetPlaybackDeviceFromId(string deviceId); /// - /// Get the mute state of the Redirection of the chosen Sonar of the chosen Sonar + /// Get the mute state of the Redirection of the chosen Sonar of the chosen Sonar /// - /// The Sonar you want the mute state of a Redirection channel - /// The Sonar you want to get the mute state + /// The Sonar you want the mute state of a Redirection mix + /// The Sonar you want to get the mute state /// The current state, un/muted - bool GetRedirectionState(Device device, Channel channel); + bool GetRedirectionState(Channel channel, Mix mix); /// /// Get the current state of the Audience Monitoring @@ -131,9 +131,9 @@ public interface ISonarDataProvider bool GetAudienceMonitoringState(); /// - /// Get the apps which their audio is redirected to a Sonar + /// Get the apps which their audio is redirected to a Sonar /// - /// The Sonar you want the associated processes + /// The Sonar you want the associated processes /// A list of - IEnumerable GetRoutedProcess(Device device); + IEnumerable GetRoutedProcess(Channel channel); } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/SonarEventManager.cs b/SteelSeriesAPI/Sonar/Managers/EventManager.cs similarity index 78% rename from SteelSeriesAPI/Sonar/Managers/SonarEventManager.cs rename to SteelSeriesAPI/Sonar/Managers/EventManager.cs index a660878..ef3857c 100644 --- a/SteelSeriesAPI/Sonar/Managers/SonarEventManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/EventManager.cs @@ -4,7 +4,7 @@ namespace SteelSeriesAPI.Sonar.Managers; -public class SonarEventManager +public class EventManager { /// /// Notify when mode changed @@ -12,17 +12,17 @@ public class SonarEventManager public event EventHandler OnSonarModeChange = delegate{ }; /// - /// Notify when a volume of a device changed + /// Notify when a volume of a channel changed /// public event EventHandler OnSonarVolumeChange = delegate{ }; /// - /// Notify when a device is un/muted + /// Notify when a channel is un/muted /// public event EventHandler OnSonarMuteChange = delegate{ }; /// - /// Notify when the config of a device is changed + /// Notify when the config of a channel is changed /// public event EventHandler OnSonarConfigChange = delegate{ }; @@ -32,9 +32,9 @@ public class SonarEventManager public event EventHandler OnSonarChatMixChange = delegate{ }; /// - /// Notify when a redirection device of a device is changed + /// Notify when a redirection channel of a channel is changed /// - public event EventHandler OnSonarRedirectionDeviceChange = delegate{ }; + public event EventHandler OnSonarRedirectionDeviceChange = delegate{ }; /// /// Notify when a redirection state is changed @@ -66,7 +66,7 @@ public void HandleEvent(string path) case SonarChatMixEvent sonarChatMixEvent: OnSonarChatMixChange(this, sonarChatMixEvent); break; - case SonarRedirectionDeviceEvent sonarRedirectionDeviceEvent: + case SonarPlaybackDeviceEvent sonarRedirectionDeviceEvent: OnSonarRedirectionDeviceChange(this, sonarRedirectionDeviceEvent); break; case SonarRedirectionStateEvent sonarRedirectionStateEvent: @@ -99,16 +99,16 @@ private EventArgs PathResolver(string path) eventArgs = new SonarVolumeEvent() { Volume = double.Parse(subs[5], CultureInfo.InvariantCulture.NumberFormat), - Mode = Mode.Classic, - Device = (Device)DeviceExtensions.FromDictKey(subs[3], DeviceMapChoice.HttpDict) + Mode = Mode.CLASSIC, + Channel = (Channel)ChannelExtensions.FromDictKey(subs[3], ChannelMapChoice.HttpDict) }; break; case"Mute": eventArgs = new SonarMuteEvent() { Muted = Convert.ToBoolean(subs[5]), - Mode = Mode.Classic, - Device = (Device)DeviceExtensions.FromDictKey(subs[3], DeviceMapChoice.HttpDict) + Mode = Mode.CLASSIC, + Channel = (Channel)ChannelExtensions.FromDictKey(subs[3], ChannelMapChoice.HttpDict) }; break; } @@ -120,18 +120,18 @@ private EventArgs PathResolver(string path) eventArgs = new SonarVolumeEvent() { Volume = double.Parse(subs[6], CultureInfo.InvariantCulture.NumberFormat), - Mode = Mode.Streamer, - Device = (Device)DeviceExtensions.FromDictKey(subs[4], DeviceMapChoice.HttpDict), - Channel = (Channel)ChannelExtensions.FromDictKey(subs[3]) + Mode = Mode.STREAMER, + Channel = (Channel)ChannelExtensions.FromDictKey(subs[4], ChannelMapChoice.HttpDict), + Mix = (Mix)MixExtensions.FromDictKey(subs[3]) }; break; case "isMuted": eventArgs = new SonarMuteEvent() { Muted = Convert.ToBoolean(subs[6]), - Mode = Mode.Streamer, - Device = (Device)DeviceExtensions.FromDictKey(subs[4], DeviceMapChoice.HttpDict), - Channel = (Channel)ChannelExtensions.FromDictKey(subs[3]) + Mode = Mode.STREAMER, + Channel = (Channel)ChannelExtensions.FromDictKey(subs[4], ChannelMapChoice.HttpDict), + Mix = (Mix)MixExtensions.FromDictKey(subs[3]) }; break; } @@ -145,11 +145,11 @@ private EventArgs PathResolver(string path) } break; case "classicRedirections": - eventArgs = new SonarRedirectionDeviceEvent() + eventArgs = new SonarPlaybackDeviceEvent() { RedirectionDeviceId = subs[4].Replace("%7B", "{").Replace("%7D", "}"), - Mode = Mode.Classic, - Device = (Device)DeviceExtensions.FromDictKey(subs[2], DeviceMapChoice.DeviceDict) + Mode = Mode.CLASSIC, + Device = (Channel)ChannelExtensions.FromDictKey(subs[2], ChannelMapChoice.ChannelDict) }; break; case "streamRedirections": @@ -164,28 +164,28 @@ private EventArgs PathResolver(string path) case "deviceId": if (subs[2] == "mic") { - eventArgs = new SonarRedirectionDeviceEvent() + eventArgs = new SonarPlaybackDeviceEvent() { RedirectionDeviceId = subs[4].Replace("%7B", "{").Replace("%7D", "}"), - Mode = Mode.Streamer, - Device = Device.Mic + Mode = Mode.STREAMER, + Device = Channel.MIC }; break; } - eventArgs = new SonarRedirectionDeviceEvent() + eventArgs = new SonarPlaybackDeviceEvent() { RedirectionDeviceId = subs[4].Replace("%7B", "{").Replace("%7D", "}"), - Mode = Mode.Streamer, - Channel = (Channel)ChannelExtensions.FromDictKey(subs[2]) + Mode = Mode.STREAMER, + Channel = (Mix)MixExtensions.FromDictKey(subs[2]) }; break; case "redirections": eventArgs = new SonarRedirectionStateEvent() { State = Convert.ToBoolean(subs[6]), - Device = (Device)DeviceExtensions.FromDictKey(subs[4]), - Channel = (Channel)ChannelExtensions.FromDictKey(subs[2]) + Channel = (Channel)ChannelExtensions.FromDictKey(subs[4]), + Mix = (Mix)MixExtensions.FromDictKey(subs[2]) }; break; } diff --git a/SteelSeriesAPI/Sonar/Models/PlaybackDevice.cs b/SteelSeriesAPI/Sonar/Models/PlaybackDevice.cs new file mode 100644 index 0000000..9e568b6 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Models/PlaybackDevice.cs @@ -0,0 +1,6 @@ +using System.Collections; +using SteelSeriesAPI.Sonar.Enums; + +namespace SteelSeriesAPI.Sonar.Models; + +public record PlaybackDevice(string Id, string Name, DataFlow DataFlow, List? AssociatedClassicDevices, ArrayList? AssociatedStreamDevices); \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Models/RedirectionDevice.cs b/SteelSeriesAPI/Sonar/Models/RedirectionDevice.cs deleted file mode 100644 index c371e83..0000000 --- a/SteelSeriesAPI/Sonar/Models/RedirectionDevice.cs +++ /dev/null @@ -1,6 +0,0 @@ -using System.Collections; -using SteelSeriesAPI.Sonar.Enums; - -namespace SteelSeriesAPI.Sonar.Models; - -public record RedirectionDevice(string Id, string Name, Direction DataFlow, List? AssociatedClassicDevices, ArrayList? AssociatedStreamDevices); \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Models/SonarAudioConfiguration.cs b/SteelSeriesAPI/Sonar/Models/SonarAudioConfiguration.cs index b4e5725..c76b2fe 100644 --- a/SteelSeriesAPI/Sonar/Models/SonarAudioConfiguration.cs +++ b/SteelSeriesAPI/Sonar/Models/SonarAudioConfiguration.cs @@ -2,4 +2,4 @@ namespace SteelSeriesAPI.Sonar.Models; -public record SonarAudioConfiguration(string Id, string Name, Device AssociatedDevice); \ No newline at end of file +public record SonarAudioConfiguration(string Id, string Name, Channel AssociatedChannel); \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index 8cbc047..3b9e71c 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -19,7 +19,7 @@ public class SonarBridge : ISonarBridge private readonly ISonarCommandHandler _sonarCommand; private readonly ISonarDataProvider _sonarProvider; private readonly ISonarSocket _sonarSocket; - public readonly SonarEventManager SonarEventManager; + public readonly EventManager EventManager; private string _sonarWebServerAddress; @@ -28,8 +28,8 @@ public SonarBridge() _sonarRetriever = SonarRetriever.Instance; WaitUntilSonarStarted(); _sonarWebServerAddress = _sonarRetriever.WebServerAddress(); - SonarEventManager = new SonarEventManager(); - _sonarSocket = new SonarSocket(_sonarWebServerAddress, SonarEventManager); + EventManager = new EventManager(); + _sonarSocket = new SonarSocket(_sonarWebServerAddress, EventManager); _sonarCommand = new SonarHttpCommand(this); _sonarProvider = new SonarHttpProvider(this); } @@ -94,24 +94,24 @@ public Mode GetMode() } // volume = 0,00000000 <-- 8 decimal max - public double GetVolume(Device device) + public double GetVolume(Channel channel) { - return _sonarProvider.GetVolume(device); + return _sonarProvider.GetVolume(channel); } - public double GetVolume(Device device, Channel channel) + public double GetVolume(Channel channel, Mix mix) { - return _sonarProvider.GetVolume(device, channel); + return _sonarProvider.GetVolume(channel, mix); } - public bool GetMute(Device device) + public bool GetMute(Channel channel) { - return _sonarProvider.GetMute(device); + return _sonarProvider.GetMute(channel); } - public bool GetMute(Device device, Channel channel) + public bool GetMute(Channel channel, Mix mix) { - return _sonarProvider.GetMute(device, channel); + return _sonarProvider.GetMute(channel, mix); } public IEnumerable GetAllAudioConfigurations() @@ -124,14 +124,14 @@ public SonarAudioConfiguration GetAudioConfiguration(string configId) return _sonarProvider.GetAudioConfiguration(configId); } - public IEnumerable GetAudioConfigurations(Device device) + public IEnumerable GetAudioConfigurations(Channel channel) { - return _sonarProvider.GetAudioConfigurations(device); + return _sonarProvider.GetAudioConfigurations(channel); } - public SonarAudioConfiguration GetSelectedAudioConfiguration(Device device) + public SonarAudioConfiguration GetSelectedAudioConfiguration(Channel channel) { - return _sonarProvider.GetSelectedAudioConfiguration(device); + return _sonarProvider.GetSelectedAudioConfiguration(channel); } public double GetChatMixBalance() @@ -144,34 +144,34 @@ public bool GetChatMixState() return _sonarProvider.GetChatMixState(); } - public IEnumerable GetRedirectionDevices(Direction direction) + public IEnumerable GetPlaybackDevices(DataFlow dataFlow) { - return _sonarProvider.GetRedirectionDevices(direction); + return _sonarProvider.GetPlaybackDevices(dataFlow); } - public RedirectionDevice GetClassicRedirectionDevice(Device device) + public PlaybackDevice GetClassicPlaybackDevice(Channel channel) { - return _sonarProvider.GetClassicRedirectionDevice(device); + return _sonarProvider.GetClassicPlaybackDevice(channel); } - public RedirectionDevice GetStreamRedirectionDevice(Channel channel) + public PlaybackDevice GetStreamPlaybackDevice(Mix mix) { - return _sonarProvider.GetStreamRedirectionDevice(channel); + return _sonarProvider.GetStreamPlaybackDevice(mix); } - public RedirectionDevice GetStreamRedirectionDevice(Device device = Device.Mic) + public PlaybackDevice GetStreamPlaybackDevice(Channel channel = Channel.MIC) { - return _sonarProvider.GetStreamRedirectionDevice(device); + return _sonarProvider.GetStreamPlaybackDevice(channel); } - public RedirectionDevice GetRedirectionDeviceFromId(string deviceId) + public PlaybackDevice GetPlaybackDeviceFromId(string deviceId) { - return _sonarProvider.GetRedirectionDeviceFromId(deviceId); + return _sonarProvider.GetPlaybackDeviceFromId(deviceId); } - public bool GetRedirectionState(Device device, Channel channel) + public bool GetRedirectionState(Channel channel, Mix mix) { - return _sonarProvider.GetRedirectionState(device, channel); + return _sonarProvider.GetRedirectionState(channel, mix); } public bool GetAudienceMonitoringState() @@ -179,9 +179,9 @@ public bool GetAudienceMonitoringState() return _sonarProvider.GetAudienceMonitoringState(); } - public IEnumerable GetRoutedProcess(Device device) + public IEnumerable GetRoutedProcess(Channel channel) { - return _sonarProvider.GetRoutedProcess(device); + return _sonarProvider.GetRoutedProcess(channel); } #endregion @@ -193,24 +193,24 @@ public void SetMode(Mode mode) _sonarCommand.SetMode(mode); } - public void SetVolume(double vol, Device device) + public void SetVolume(double vol, Channel channel) { - _sonarCommand.SetVolume(vol, device); + _sonarCommand.SetVolume(vol, channel); } - public void SetVolume(double vol, Device device, Channel channel) + public void SetVolume(double vol, Channel channel, Mix mix) { - _sonarCommand.SetVolume(vol, device, channel); + _sonarCommand.SetVolume(vol, channel, mix); } - public void SetMute(bool mute, Device device) + public void SetMute(bool mute, Channel channel) { - _sonarCommand.SetMute(mute, device); + _sonarCommand.SetMute(mute, channel); } - public void SetMute(bool mute, Device device, Channel channel) + public void SetMute(bool mute, Channel channel, Mix mix) { - _sonarCommand.SetMute(mute, device, channel); + _sonarCommand.SetMute(mute, channel, mix); } public void SetConfig(string configId) @@ -218,9 +218,9 @@ public void SetConfig(string configId) _sonarCommand.SetConfig(configId); } - public void SetConfig(Device device, string name) + public void SetConfig(Channel channel, string name) { - _sonarCommand.SetConfig(device, name); + _sonarCommand.SetConfig(channel, name); } public void SetChatMixBalance(double balance) @@ -228,24 +228,24 @@ public void SetChatMixBalance(double balance) _sonarCommand.SetChatMixBalance(balance); } - public void SetClassicRedirectionDevice(string deviceId, Device device) + public void SetClassicPlaybackDevice(string deviceId, Channel channel) { - _sonarCommand.SetClassicRedirectionDevice(deviceId, device); + _sonarCommand.SetClassicPlaybackDevice(deviceId, channel); } - public void SetStreamRedirectionDevice(string deviceId, Channel channel) + public void SetStreamPlaybackDevice(string deviceId, Mix mix) { - _sonarCommand.SetStreamRedirectionDevice(deviceId, channel); + _sonarCommand.SetStreamPlaybackDevice(deviceId, mix); } - public void SetStreamRedirectionDevice(string deviceId, Device device = Device.Mic) + public void SetStreamPlaybackDevice(string deviceId, Channel channel = Channel.MIC) { - _sonarCommand.SetStreamRedirectionDevice(deviceId, device); + _sonarCommand.SetStreamPlaybackDevice(deviceId, channel); } - public void SetRedirectionState(bool newState, Device device, Channel channel) + public void SetRedirectionState(bool newState, Channel channel, Mix mix) { - _sonarCommand.SetRedirectionState(newState, device, channel); + _sonarCommand.SetRedirectionState(newState, channel, mix); } public void SetAudienceMonitoringState(bool newState) @@ -253,9 +253,9 @@ public void SetAudienceMonitoringState(bool newState) _sonarCommand.SetAudienceMonitoringState(newState); } - public void SetProcessToDeviceRouting(int pId, Device device) + public void SetProcessToDeviceRouting(int pId, Channel channel) { - _sonarCommand.SetProcessToDeviceRouting(pId, device); + _sonarCommand.SetProcessToDeviceRouting(pId, channel); } #endregion diff --git a/SteelSeriesAPI/Sonar/SonarSocket.cs b/SteelSeriesAPI/Sonar/SonarSocket.cs index e8a5c5d..232d6cc 100644 --- a/SteelSeriesAPI/Sonar/SonarSocket.cs +++ b/SteelSeriesAPI/Sonar/SonarSocket.cs @@ -12,16 +12,16 @@ public class SonarSocket : ISonarSocket private readonly Thread _listenerThread; private readonly Uri _sonarWebServerAddress; - private readonly SonarEventManager _sonarEventManager; + private readonly EventManager _eventManager; private Socket _socket; private bool _isClosing; - public SonarSocket(string sonarWebServerAddress, SonarEventManager sonarEventManager) + public SonarSocket(string sonarWebServerAddress, EventManager eventManager) { _sonarWebServerAddress = new Uri(sonarWebServerAddress); _listenerThread = new Thread(ListenerThreadSync) { IsBackground = false }; - _sonarEventManager = sonarEventManager; + _eventManager = eventManager; } public bool Connect() @@ -103,7 +103,7 @@ private void ListenerThreadSync() { string path = putData.Split("PUT ")[1].Split(" HTTP")[0]; // Console.WriteLine(path); // For debugging - _sonarEventManager.HandleEvent(path); // Invoke events + _eventManager.HandleEvent(path); // Invoke events } } } From 5c344701a3470e7f13032480c7f2e45476e61332 Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 01:29:20 +0200 Subject: [PATCH 03/47] Created 3 Managers --- .../Sonar/Interfaces/Managers/IConfigurationManager.cs | 6 ++++++ .../Sonar/Interfaces/Managers/IPlaybackDeviceManager.cs | 6 ++++++ .../Sonar/Interfaces/Managers/IVolumeSettingsManager.cs | 6 ++++++ SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs | 6 ++++++ SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs | 6 ++++++ SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs | 6 ++++++ 6 files changed, 36 insertions(+) create mode 100644 SteelSeriesAPI/Sonar/Interfaces/Managers/IConfigurationManager.cs create mode 100644 SteelSeriesAPI/Sonar/Interfaces/Managers/IPlaybackDeviceManager.cs create mode 100644 SteelSeriesAPI/Sonar/Interfaces/Managers/IVolumeSettingsManager.cs create mode 100644 SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs create mode 100644 SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs create mode 100644 SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IConfigurationManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IConfigurationManager.cs new file mode 100644 index 0000000..0ffacb2 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IConfigurationManager.cs @@ -0,0 +1,6 @@ +namespace SteelSeriesAPI.Sonar.Interfaces.Managers; + +public interface IConfigurationManager +{ + +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IPlaybackDeviceManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IPlaybackDeviceManager.cs new file mode 100644 index 0000000..50d0ddc --- /dev/null +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IPlaybackDeviceManager.cs @@ -0,0 +1,6 @@ +namespace SteelSeriesAPI.Sonar.Interfaces.Managers; + +public interface IPlaybackDeviceManager +{ + +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IVolumeSettingsManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IVolumeSettingsManager.cs new file mode 100644 index 0000000..8bfea29 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IVolumeSettingsManager.cs @@ -0,0 +1,6 @@ +namespace SteelSeriesAPI.Sonar.Interfaces.Managers; + +public interface IVolumeSettingsManager +{ + +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs b/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs new file mode 100644 index 0000000..70c33d7 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs @@ -0,0 +1,6 @@ +namespace SteelSeriesAPI.Sonar.Managers; + +public class ConfigurationManager +{ + +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs b/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs new file mode 100644 index 0000000..df26d8a --- /dev/null +++ b/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs @@ -0,0 +1,6 @@ +namespace SteelSeriesAPI.Sonar.Managers; + +public class PlaybackDeviceManager +{ + +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs b/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs new file mode 100644 index 0000000..bd4b29a --- /dev/null +++ b/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs @@ -0,0 +1,6 @@ +namespace SteelSeriesAPI.Sonar.Managers; + +public class VolumeSettingsManager +{ + +} \ No newline at end of file From 836ec5ed2b307efbdc492483e2292a6e8e119fe6 Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 01:47:38 +0200 Subject: [PATCH 04/47] Added VolumeSettingsManager as a category --- SteelSeriesAPI.Sample/Program.cs | 30 +++--- SteelSeriesAPI.Tests/Program.cs | 92 +++++++++---------- SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs | 22 ----- .../Sonar/Http/SonarHttpProvider.cs | 36 -------- .../Sonar/Interfaces/ISonarCommandHandler.cs | 30 ------ .../Sonar/Interfaces/ISonarDataProvider.cs | 30 ------ .../Managers/IVolumeSettingsManager.cs | 64 ++++++++++++- .../Sonar/Managers/VolumeSettingsManager.cs | 70 +++++++++++++- SteelSeriesAPI/Sonar/SonarBridge.cs | 50 ++-------- 9 files changed, 196 insertions(+), 228 deletions(-) diff --git a/SteelSeriesAPI.Sample/Program.cs b/SteelSeriesAPI.Sample/Program.cs index 3390ffe..f2f87d4 100644 --- a/SteelSeriesAPI.Sample/Program.cs +++ b/SteelSeriesAPI.Sample/Program.cs @@ -18,14 +18,14 @@ static void Main(string[] args) // If I want to detect changes made on GG, I can use the listener (require admin rights) sonarManager.StartListener(); // Then I register the events I want (I've put them all to demonstrate) - sonarManager.EventManager.OnSonarModeChange += OnModeChangeHandler; // When the mode is change - sonarManager.EventManager.OnSonarVolumeChange += OnVolumeChangeHandler; // When the volume of a Sonar Channel or Mix is changed - sonarManager.EventManager.OnSonarMuteChange += OnMuteChangeHandler; // When a Sonar Channel or Mix is muted or unmuted - sonarManager.EventManager.OnSonarConfigChange += OnConfigChangeHandler; // When a new config is set to a Sonar Channel - sonarManager.EventManager.OnSonarChatMixChange += OnChatMixChangeHandler; // When the ChatMix value is changed - sonarManager.EventManager.OnSonarRedirectionDeviceChange += OnRedirectionDeviceChangeHandler; // When the Redirection Channel of a Sonar Channel is changed - sonarManager.EventManager.OnSonarRedirectionStateChange += OnRedirectionStateChangeHandler; // When the Redirection of a Sonar Mix is muted or unmuted - sonarManager.EventManager.OnSonarAudienceMonitoringChange += OnAudienceMonitoringChangeHandler; // When the Audience Monitoring is muted or unmuted + sonarManager.Event.OnSonarModeChange += OnModeChangeHandler; // When the mode is change + sonarManager.Event.OnSonarVolumeChange += OnVolumeChangeHandler; // When the volume of a Sonar Channel or Mix is changed + sonarManager.Event.OnSonarMuteChange += OnMuteChangeHandler; // When a Sonar Channel or Mix is muted or unmuted + sonarManager.Event.OnSonarConfigChange += OnConfigChangeHandler; // When a new config is set to a Sonar Channel + sonarManager.Event.OnSonarChatMixChange += OnChatMixChangeHandler; // When the ChatMix value is changed + sonarManager.Event.OnSonarRedirectionDeviceChange += OnRedirectionDeviceChangeHandler; // When the Redirection Channel of a Sonar Channel is changed + sonarManager.Event.OnSonarRedirectionStateChange += OnRedirectionStateChangeHandler; // When the Redirection of a Sonar Mix is muted or unmuted + sonarManager.Event.OnSonarAudienceMonitoringChange += OnAudienceMonitoringChangeHandler; // When the Audience Monitoring is muted or unmuted // Get current sonar mode Mode mode = sonarManager.GetMode(); @@ -33,19 +33,19 @@ static void Main(string[] args) sonarManager.SetMode(Mode.STREAMER); // Get current volume of a Sonar Channel - double vol = sonarManager.GetVolume(Channel.MEDIA); + double vol = sonarManager.VolumeSettings.GetVolume(Channel.MEDIA); // Get current volume of a Sonar Mix - double vol2 = sonarManager.GetVolume(Channel.CHAT, Mix.STREAM); + double vol2 = sonarManager.VolumeSettings.GetVolume(Channel.CHAT, Mix.STREAM); // Set the volume of a Sonar Channel - sonarManager.SetVolume(0.75, Channel.GAME); + sonarManager.VolumeSettings.SetVolume(0.75, Channel.GAME); // Set the volume of a Sonar Mix - sonarManager.SetVolume(0.1, Channel.MEDIA, Mix.MONITORING); + sonarManager.VolumeSettings.SetVolume(0.1, Channel.MEDIA, Mix.MONITORING); // Get the current mute state of a Sonar Channel - bool state = sonarManager.GetMute(Channel.CHAT); - bool state2 = sonarManager.GetMute(Channel.MASTER, Mix.MONITORING); + bool state = sonarManager.VolumeSettings.GetMute(Channel.CHAT); + bool state2 = sonarManager.VolumeSettings.GetMute(Channel.MASTER, Mix.MONITORING); // Set the current mute state of a Sonar Channel - sonarManager.SetMute(true, Channel.CHAT); // Mute chat + sonarManager.VolumeSettings.SetMute(true, Channel.CHAT); // Mute chat // Get audio configs List allConfigs = sonarManager.GetAllAudioConfigurations().ToList(); // Return all configs (A SonarAudioConfiguration contains an Id, a Name and an AssociatedChannel) diff --git a/SteelSeriesAPI.Tests/Program.cs b/SteelSeriesAPI.Tests/Program.cs index f91bab5..5774719 100644 --- a/SteelSeriesAPI.Tests/Program.cs +++ b/SteelSeriesAPI.Tests/Program.cs @@ -18,14 +18,14 @@ static void Main(string[] args) // Thread.Sleep(1000); // sonarManager.StopListener(); - sonarManager.EventManager.OnSonarModeChange += OnModeChangeHandler; - sonarManager.EventManager.OnSonarVolumeChange += OnVolumeChangeHandler; - sonarManager.EventManager.OnSonarMuteChange += OnMuteChangeHandler; - sonarManager.EventManager.OnSonarConfigChange += OnConfigChangeHandler; - sonarManager.EventManager.OnSonarChatMixChange += OnChatMixChangeHandler; - sonarManager.EventManager.OnSonarRedirectionDeviceChange += OnRedirectionDeviceChangeHandler; - sonarManager.EventManager.OnSonarRedirectionStateChange += OnRedirectionStateChangeHandler; - sonarManager.EventManager.OnSonarAudienceMonitoringChange += OnAudienceMonitoringChangeHandler; + sonarManager.Event.OnSonarModeChange += OnModeChangeHandler; + sonarManager.Event.OnSonarVolumeChange += OnVolumeChangeHandler; + sonarManager.Event.OnSonarMuteChange += OnMuteChangeHandler; + sonarManager.Event.OnSonarConfigChange += OnConfigChangeHandler; + sonarManager.Event.OnSonarChatMixChange += OnChatMixChangeHandler; + sonarManager.Event.OnSonarRedirectionDeviceChange += OnRedirectionDeviceChangeHandler; + sonarManager.Event.OnSonarRedirectionStateChange += OnRedirectionStateChangeHandler; + sonarManager.Event.OnSonarAudienceMonitoringChange += OnAudienceMonitoringChangeHandler; // new Program().GetTest(sonarManager); // new Program().SetTest(sonarManager); @@ -38,28 +38,28 @@ void TestMaster(SonarBridge sonarManager) // Classic sonarManager.SetMode(Mode.CLASSIC); Console.WriteLine("------ Classic Master Test ------"); - Console.WriteLine(sonarManager.GetVolume(Channel.MASTER)); - Console.WriteLine(sonarManager.GetMute(Channel.MASTER)); - sonarManager.SetVolume(0.25f, Channel.MASTER); - sonarManager.SetVolume(1, Channel.MASTER); - sonarManager.SetMute(true, Channel.MASTER); - sonarManager.SetMute(false, Channel.MASTER); + Console.WriteLine(sonarManager.VolumeSettings.GetVolume(Channel.MASTER)); + Console.WriteLine(sonarManager.VolumeSettings.GetMute(Channel.MASTER)); + sonarManager.VolumeSettings.SetVolume(0.25f, Channel.MASTER); + sonarManager.VolumeSettings.SetVolume(1, Channel.MASTER); + sonarManager.VolumeSettings.SetMute(true, Channel.MASTER); + sonarManager.VolumeSettings.SetMute(false, Channel.MASTER); // Streamer sonarManager.SetMode(Mode.STREAMER); Console.WriteLine("------ Streamer Master Test ------"); - Console.WriteLine(sonarManager.GetVolume(Channel.MASTER, Mix.MONITORING)); - Console.WriteLine(sonarManager.GetVolume(Channel.MASTER, Mix.STREAM)); - Console.WriteLine(sonarManager.GetMute(Channel.MASTER, Mix.MONITORING)); - Console.WriteLine(sonarManager.GetMute(Channel.MASTER, Mix.STREAM)); - sonarManager.SetVolume(0.25f, Channel.MASTER, Mix.MONITORING); - sonarManager.SetVolume(0.25f, Channel.MASTER, Mix.STREAM); - sonarManager.SetVolume(1, Channel.MASTER, Mix.MONITORING); - sonarManager.SetVolume(1, Channel.MASTER, Mix.STREAM); - sonarManager.SetMute(true, Channel.MASTER, Mix.MONITORING); - sonarManager.SetMute(true, Channel.MASTER, Mix.STREAM); - sonarManager.SetMute(false, Channel.MASTER, Mix.MONITORING); - sonarManager.SetMute(false, Channel.MASTER, Mix.STREAM); + Console.WriteLine(sonarManager.VolumeSettings.GetVolume(Channel.MASTER, Mix.MONITORING)); + Console.WriteLine(sonarManager.VolumeSettings.GetVolume(Channel.MASTER, Mix.STREAM)); + Console.WriteLine(sonarManager.VolumeSettings.GetMute(Channel.MASTER, Mix.MONITORING)); + Console.WriteLine(sonarManager.VolumeSettings.GetMute(Channel.MASTER, Mix.STREAM)); + sonarManager.VolumeSettings.SetVolume(0.25f, Channel.MASTER, Mix.MONITORING); + sonarManager.VolumeSettings.SetVolume(0.25f, Channel.MASTER, Mix.STREAM); + sonarManager.VolumeSettings.SetVolume(1, Channel.MASTER, Mix.MONITORING); + sonarManager.VolumeSettings.SetVolume(1, Channel.MASTER, Mix.STREAM); + sonarManager.VolumeSettings.SetMute(true, Channel.MASTER, Mix.MONITORING); + sonarManager.VolumeSettings.SetMute(true, Channel.MASTER, Mix.STREAM); + sonarManager.VolumeSettings.SetMute(false, Channel.MASTER, Mix.MONITORING); + sonarManager.VolumeSettings.SetMute(false, Channel.MASTER, Mix.STREAM); sonarManager.SetMode(Mode.CLASSIC); } @@ -68,26 +68,26 @@ void GetTest(SonarBridge sonarManager) { Console.WriteLine(sonarManager.GetMode()); - Console.WriteLine("" + sonarManager.GetVolume(Channel.MASTER) + " " + sonarManager.GetMute(Channel.MASTER)); - Console.WriteLine("" + sonarManager.GetVolume(Channel.GAME) + " " + sonarManager.GetMute(Channel.GAME)); - Console.WriteLine("" + sonarManager.GetVolume(Channel.CHAT) + " " + sonarManager.GetMute(Channel.CHAT)); - Console.WriteLine("" + sonarManager.GetVolume(Channel.MEDIA) + " " + sonarManager.GetMute(Channel.MEDIA)); - Console.WriteLine("" + sonarManager.GetVolume(Channel.AUX) + " " + sonarManager.GetMute(Channel.AUX)); - Console.WriteLine("" + sonarManager.GetVolume(Channel.MIC) + " " + sonarManager.GetMute(Channel.MIC)); + Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.MASTER) + " " + sonarManager.VolumeSettings.GetMute(Channel.MASTER)); + Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.GAME) + " " + sonarManager.VolumeSettings.GetMute(Channel.GAME)); + Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.CHAT) + " " + sonarManager.VolumeSettings.GetMute(Channel.CHAT)); + Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.MEDIA) + " " + sonarManager.VolumeSettings.GetMute(Channel.MEDIA)); + Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.AUX) + " " + sonarManager.VolumeSettings.GetMute(Channel.AUX)); + Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.MIC) + " " + sonarManager.VolumeSettings.GetMute(Channel.MIC)); Console.WriteLine("-----------------Streamer-Monitoring-------------"); - Console.WriteLine("" + sonarManager.GetVolume(Channel.MASTER, Mix.MONITORING) + " " + sonarManager.GetMute(Channel.MASTER, Mix.MONITORING)); - Console.WriteLine("" + sonarManager.GetVolume(Channel.GAME, Mix.MONITORING) + " " + sonarManager.GetMute(Channel.GAME, Mix.MONITORING)); - Console.WriteLine("" + sonarManager.GetVolume(Channel.CHAT, Mix.MONITORING) + " " + sonarManager.GetMute(Channel.CHAT, Mix.MONITORING)); - Console.WriteLine("" + sonarManager.GetVolume(Channel.MEDIA, Mix.MONITORING) + " " + sonarManager.GetMute(Channel.MEDIA, Mix.MONITORING)); - Console.WriteLine("" + sonarManager.GetVolume(Channel.AUX, Mix.MONITORING) + " " + sonarManager.GetMute(Channel.AUX, Mix.MONITORING)); - Console.WriteLine("" + sonarManager.GetVolume(Channel.MIC, Mix.MONITORING) + " " + sonarManager.GetMute(Channel.MIC, Mix.MONITORING)); + Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.MASTER, Mix.MONITORING) + " " + sonarManager.VolumeSettings.GetMute(Channel.MASTER, Mix.MONITORING)); + Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.GAME, Mix.MONITORING) + " " + sonarManager.VolumeSettings.GetMute(Channel.GAME, Mix.MONITORING)); + Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.CHAT, Mix.MONITORING) + " " + sonarManager.VolumeSettings.GetMute(Channel.CHAT, Mix.MONITORING)); + Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.MEDIA, Mix.MONITORING) + " " + sonarManager.VolumeSettings.GetMute(Channel.MEDIA, Mix.MONITORING)); + Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.AUX, Mix.MONITORING) + " " + sonarManager.VolumeSettings.GetMute(Channel.AUX, Mix.MONITORING)); + Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.MIC, Mix.MONITORING) + " " + sonarManager.VolumeSettings.GetMute(Channel.MIC, Mix.MONITORING)); Console.WriteLine("-----------------Streamer-Stream-------------"); - Console.WriteLine("" + sonarManager.GetVolume(Channel.MASTER, Mix.STREAM) + " " + sonarManager.GetMute(Channel.MASTER, Mix.STREAM)); - Console.WriteLine("" + sonarManager.GetVolume(Channel.GAME, Mix.STREAM) + " " + sonarManager.GetMute(Channel.GAME, Mix.STREAM)); - Console.WriteLine("" + sonarManager.GetVolume(Channel.CHAT, Mix.STREAM) + " " + sonarManager.GetMute(Channel.CHAT, Mix.STREAM)); - Console.WriteLine("" + sonarManager.GetVolume(Channel.MEDIA, Mix.STREAM) + " " + sonarManager.GetMute(Channel.MEDIA, Mix.STREAM)); - Console.WriteLine("" + sonarManager.GetVolume(Channel.AUX, Mix.STREAM) + " " + sonarManager.GetMute(Channel.AUX, Mix.STREAM)); - Console.WriteLine("" + sonarManager.GetVolume(Channel.MIC, Mix.STREAM) + " " + sonarManager.GetMute(Channel.MIC, Mix.STREAM)); + Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.MASTER, Mix.STREAM) + " " + sonarManager.VolumeSettings.GetMute(Channel.MASTER, Mix.STREAM)); + Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.GAME, Mix.STREAM) + " " + sonarManager.VolumeSettings.GetMute(Channel.GAME, Mix.STREAM)); + Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.CHAT, Mix.STREAM) + " " + sonarManager.VolumeSettings.GetMute(Channel.CHAT, Mix.STREAM)); + Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.MEDIA, Mix.STREAM) + " " + sonarManager.VolumeSettings.GetMute(Channel.MEDIA, Mix.STREAM)); + Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.AUX, Mix.STREAM) + " " + sonarManager.VolumeSettings.GetMute(Channel.AUX, Mix.STREAM)); + Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.MIC, Mix.STREAM) + " " + sonarManager.VolumeSettings.GetMute(Channel.MIC, Mix.STREAM)); Console.WriteLine("----AudioConfigs----------"); foreach (var config in sonarManager.GetAllAudioConfigurations()) { @@ -217,8 +217,8 @@ void GetTest(SonarBridge sonarManager) void SetTest(SonarBridge sonarManager){ sonarManager.SetMode(Mode.CLASSIC); - sonarManager.SetVolume(0.4, Channel.MEDIA); - sonarManager.SetMute(false, Channel.MEDIA); + sonarManager.VolumeSettings.SetVolume(0.4, Channel.MEDIA); + sonarManager.VolumeSettings.SetMute(false, Channel.MEDIA); string configId = sonarManager.GetAudioConfigurations(Channel.MEDIA).FirstOrDefault(config => config.Name == "Default")?.Id; sonarManager.SetConfig(configId); sonarManager.SetConfig(Channel.MEDIA, "Default"); diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs index 9b76680..6da47e1 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs @@ -20,28 +20,6 @@ public void SetMode(Mode mode) Thread.Sleep(100); // Prevent bugs/freezes/crashes } - public void SetVolume(double vol, Channel channel) - { - string _vol = vol.ToString("0.00", CultureInfo.InvariantCulture); - new HttpPut("volumeSettings/classic/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/Volume/" + _vol); - } - - public void SetVolume(double vol, Channel channel, Mix mix) - { - string _vol = vol.ToString("0.00", CultureInfo.InvariantCulture); - new HttpPut("volumeSettings/streamer/" + mix.ToDictKey() + "/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/volume/" + _vol); - } - - public void SetMute(bool mute, Channel channel) - { - new HttpPut("volumeSettings/classic/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/Mute/" + mute); - } - - public void SetMute(bool mute, Channel channel, Mix mix) - { - new HttpPut("volumeSettings/streamer/" + mix.ToDictKey() + "/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/isMuted/" + mute); - } - public void SetConfig(string configId) { if (string.IsNullOrEmpty(configId)) throw new Exception("Couldn't retrieve config id"); diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs index effd04d..e5b8d08 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs @@ -22,42 +22,6 @@ public Mode GetMode() return (Mode)ModeExtensions.FromDictKey(mode, ModeMapChoice.StreamDict); } - public double GetVolume(Channel channel) - { - JsonDocument volumeSettings = new HttpProvider("volumeSettings/classic/").Provide(); - - if (channel == Channel.MASTER) - return volumeSettings.RootElement.GetProperty("masters").GetProperty("classic").GetProperty("volume").GetDouble(); - return volumeSettings.RootElement.GetProperty("devices").GetProperty(channel.ToDictKey()).GetProperty("classic").GetProperty("volume").GetDouble(); - } - - public double GetVolume(Channel channel, Mix mix) - { - JsonDocument volumeSettings = new HttpProvider("volumeSettings/streamer/").Provide(); - - if (channel == Channel.MASTER) - return volumeSettings.RootElement.GetProperty("masters").GetProperty("stream").GetProperty(mix.ToDictKey()).GetProperty("volume").GetDouble(); - return volumeSettings.RootElement.GetProperty("devices").GetProperty(channel.ToDictKey()).GetProperty("stream").GetProperty(mix.ToDictKey()).GetProperty("volume").GetDouble(); - } - - public bool GetMute(Channel channel) - { - JsonDocument volumeSettings = new HttpProvider("volumeSettings/classic/").Provide(); - - if (channel == Channel.MASTER) - return volumeSettings.RootElement.GetProperty("masters").GetProperty("classic").GetProperty("muted").GetBoolean(); - return volumeSettings.RootElement.GetProperty("devices").GetProperty(channel.ToDictKey()).GetProperty("classic").GetProperty("muted").GetBoolean(); - } - - public bool GetMute(Channel channel, Mix mix) - { - JsonDocument volumeSettings = new HttpProvider("volumeSettings/streamer/").Provide(); - - if (channel == Channel.MASTER) - return volumeSettings.RootElement.GetProperty("masters").GetProperty("stream").GetProperty(mix.ToDictKey()).GetProperty("muted").GetBoolean(); - return volumeSettings.RootElement.GetProperty("devices").GetProperty(channel.ToDictKey()).GetProperty("stream").GetProperty(mix.ToDictKey()).GetProperty("muted").GetBoolean(); - } - #region AudioConfigs public IEnumerable GetAllAudioConfigurations() diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs index ed732c6..7aba1d1 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs @@ -10,36 +10,6 @@ public interface ISonarCommandHandler /// The you want to set void SetMode(Mode mode); - /// - /// Set the volume of a Sonar - /// - /// The volume you want to set, between 1 and 0 - /// The you want to change the volume - void SetVolume(double vol, Channel channel); - - /// - /// Set the volume of a Streamer mode Sonar - /// - /// The volume you want to set, between 1 and 0 - /// The you want to change the volume - /// The you want to change the volume - void SetVolume(double vol, Channel channel, Mix mix); - - /// - /// Mute or unmute a Sonar - /// - /// The new muted state - /// The you want to un/mute - void SetMute(bool mute, Channel channel); - - /// - /// Mute or unmute a Streamer mode Sonar - /// - /// The new muted state - /// The you want to un/mute - /// The you want to un/mute - void SetMute(bool mute, Channel channel, Mix mix); - /// /// Set the config of a Sonar by giving its id /// diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs index b909867..9e3690c 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs @@ -10,36 +10,6 @@ public interface ISonarDataProvider /// /// A , either Classic or Streamer Mode GetMode(); - - /// - /// Get the volume of a Sonar - /// - /// The Sonar you want the volume - /// The volume of the mix in double, value between 0 and 1 - double GetVolume(Channel channel); - - /// - /// Get the volume of a Steamer mode Sonar - /// - /// The Sonar you want the volume - /// The Sonar you want the volume - /// The volume of the mix in double, value between 0 and 1 - double GetVolume(Channel channel, Mix mix); - - /// - /// Get the mute state of a Sonar - /// - /// The Sonar you want the mute state - /// The mute state, a boolean - bool GetMute(Channel channel); - - /// - /// Get the mute state of a Streamer mode Sonar - /// - /// The Sonar you want the mute state - /// The Sonar you want the mute state - /// The mute state, a boolean - bool GetMute(Channel channel, Mix mix); /// /// Get all audio configurations from Sonar diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IVolumeSettingsManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IVolumeSettingsManager.cs index 8bfea29..e23f041 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/Managers/IVolumeSettingsManager.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IVolumeSettingsManager.cs @@ -1,6 +1,66 @@ -namespace SteelSeriesAPI.Sonar.Interfaces.Managers; +using SteelSeriesAPI.Sonar.Enums; -public interface IVolumeSettingsManager +namespace SteelSeriesAPI.Sonar.Interfaces.Managers; + +internal interface IVolumeSettingsManager { + /// + /// Get the volume of a Sonar + /// + /// The Sonar you want the volume + /// The volume of the channel in double, value between 0 and 1 + double GetVolume(Channel channel); + + /// + /// Get the volume of a Steamer mode Sonar + /// + /// The Sonar you want the volume + /// The Sonar you want the volume + /// The volume of the mix in double, value between 0 and 1 + double GetVolume(Channel channel, Mix mix); + + /// + /// Get the mute state of a Sonar + /// + /// The Sonar you want the mute state + /// The mute state, a boolean + bool GetMute(Channel channel); + + /// + /// Get the mute state of a Streamer mode Sonar + /// + /// The Sonar you want the mute state + /// The Sonar you want the mute state + /// The mute state, a boolean + bool GetMute(Channel channel, Mix mix); + + /// + /// Set the volume of a Sonar + /// + /// The volume you want to set, between 1 and 0 + /// The you want to change the volume + void SetVolume(double vol, Channel channel); + + /// + /// Set the volume of a Streamer mode Sonar + /// + /// The volume you want to set, between 1 and 0 + /// The you want to change the volume + /// The you want to change the volume + void SetVolume(double vol, Channel channel, Mix mix); + + /// + /// Mute or unmute a Sonar + /// + /// The new muted state + /// The you want to un/mute + void SetMute(bool mute, Channel channel); + /// + /// Mute or unmute a Streamer mode Sonar + /// + /// The new muted state + /// The you want to un/mute + /// The you want to un/mute + void SetMute(bool mute, Channel channel, Mix mix); } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs b/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs index bd4b29a..52caedb 100644 --- a/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs @@ -1,6 +1,70 @@ -namespace SteelSeriesAPI.Sonar.Managers; +using SteelSeriesAPI.Sonar.Interfaces.Managers; +using SteelSeriesAPI.Sonar.Enums; +using SteelSeriesAPI.Sonar.Http; -public class VolumeSettingsManager +using System.Globalization; +using System.Text.Json; + +namespace SteelSeriesAPI.Sonar.Managers; + +public class VolumeSettingsManager : IVolumeSettingsManager { - + // volume = 0,00000000 <-- 8 decimal max + public double GetVolume(Channel channel) + { + JsonDocument volumeSettings = new HttpProvider("volumeSettings/classic/").Provide(); + + if (channel == Channel.MASTER) + return volumeSettings.RootElement.GetProperty("masters").GetProperty("classic").GetProperty("volume").GetDouble(); + return volumeSettings.RootElement.GetProperty("devices").GetProperty(channel.ToDictKey()).GetProperty("classic").GetProperty("volume").GetDouble(); + } + + public double GetVolume(Channel channel, Mix mix) + { + JsonDocument volumeSettings = new HttpProvider("volumeSettings/streamer/").Provide(); + + if (channel == Channel.MASTER) + return volumeSettings.RootElement.GetProperty("masters").GetProperty("stream").GetProperty(mix.ToDictKey()).GetProperty("volume").GetDouble(); + return volumeSettings.RootElement.GetProperty("devices").GetProperty(channel.ToDictKey()).GetProperty("stream").GetProperty(mix.ToDictKey()).GetProperty("volume").GetDouble(); + } + + public bool GetMute(Channel channel) + { + JsonDocument volumeSettings = new HttpProvider("volumeSettings/classic/").Provide(); + + if (channel == Channel.MASTER) + return volumeSettings.RootElement.GetProperty("masters").GetProperty("classic").GetProperty("muted").GetBoolean(); + return volumeSettings.RootElement.GetProperty("devices").GetProperty(channel.ToDictKey()).GetProperty("classic").GetProperty("muted").GetBoolean(); + } + + public bool GetMute(Channel channel, Mix mix) + { + JsonDocument volumeSettings = new HttpProvider("volumeSettings/streamer/").Provide(); + + if (channel == Channel.MASTER) + return volumeSettings.RootElement.GetProperty("masters").GetProperty("stream").GetProperty(mix.ToDictKey()).GetProperty("muted").GetBoolean(); + return volumeSettings.RootElement.GetProperty("devices").GetProperty(channel.ToDictKey()).GetProperty("stream").GetProperty(mix.ToDictKey()).GetProperty("muted").GetBoolean(); + } + + public void SetVolume(double vol, Channel channel) + { + string _vol = vol.ToString("0.00", CultureInfo.InvariantCulture); + new HttpPut("volumeSettings/classic/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/Volume/" + _vol); + } + + public void SetVolume(double vol, Channel channel, Mix mix) + { + string _vol = vol.ToString("0.00", CultureInfo.InvariantCulture); + new HttpPut("volumeSettings/streamer/" + mix.ToDictKey() + "/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/volume/" + _vol); + } + + public void SetMute(bool mute, Channel channel) + { + new HttpPut("volumeSettings/classic/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/Mute/" + mute); + } + + public void SetMute(bool mute, Channel channel, Mix mix) + { + new HttpPut("volumeSettings/streamer/" + mix.ToDictKey() + "/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/isMuted/" + mute); + } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index 3b9e71c..98c5753 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -19,7 +19,9 @@ public class SonarBridge : ISonarBridge private readonly ISonarCommandHandler _sonarCommand; private readonly ISonarDataProvider _sonarProvider; private readonly ISonarSocket _sonarSocket; - public readonly EventManager EventManager; + + public readonly VolumeSettingsManager VolumeSettings; + public readonly EventManager Event; private string _sonarWebServerAddress; @@ -28,10 +30,11 @@ public SonarBridge() _sonarRetriever = SonarRetriever.Instance; WaitUntilSonarStarted(); _sonarWebServerAddress = _sonarRetriever.WebServerAddress(); - EventManager = new EventManager(); - _sonarSocket = new SonarSocket(_sonarWebServerAddress, EventManager); + Event = new EventManager(); + _sonarSocket = new SonarSocket(_sonarWebServerAddress, Event); _sonarCommand = new SonarHttpCommand(this); _sonarProvider = new SonarHttpProvider(this); + VolumeSettings = new VolumeSettingsManager(); } #region Listener @@ -92,27 +95,6 @@ public Mode GetMode() { return _sonarProvider.GetMode(); } - - // volume = 0,00000000 <-- 8 decimal max - public double GetVolume(Channel channel) - { - return _sonarProvider.GetVolume(channel); - } - - public double GetVolume(Channel channel, Mix mix) - { - return _sonarProvider.GetVolume(channel, mix); - } - - public bool GetMute(Channel channel) - { - return _sonarProvider.GetMute(channel); - } - - public bool GetMute(Channel channel, Mix mix) - { - return _sonarProvider.GetMute(channel, mix); - } public IEnumerable GetAllAudioConfigurations() { @@ -193,26 +175,6 @@ public void SetMode(Mode mode) _sonarCommand.SetMode(mode); } - public void SetVolume(double vol, Channel channel) - { - _sonarCommand.SetVolume(vol, channel); - } - - public void SetVolume(double vol, Channel channel, Mix mix) - { - _sonarCommand.SetVolume(vol, channel, mix); - } - - public void SetMute(bool mute, Channel channel) - { - _sonarCommand.SetMute(mute, channel); - } - - public void SetMute(bool mute, Channel channel, Mix mix) - { - _sonarCommand.SetMute(mute, channel, mix); - } - public void SetConfig(string configId) { _sonarCommand.SetConfig(configId); From 6c6532589c6ee1ebe7382d2f6eae7e8444bc0709 Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 02:03:27 +0200 Subject: [PATCH 05/47] Added ConfigurationManager and removed old method from Http managers --- SteelSeriesAPI.Sample/Program.cs | 11 +- SteelSeriesAPI.Tests/Program.cs | 16 +-- SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs | 20 --- .../Sonar/Http/SonarHttpProvider.cs | 82 ------------- .../Sonar/Interfaces/ISonarCommandHandler.cs | 15 --- .../Sonar/Interfaces/ISonarDataProvider.cs | 27 ----- .../Managers/IConfigurationManager.cs | 53 +++++++- .../Sonar/Managers/ConfigurationManager.cs | 114 +++++++++++++++++- SteelSeriesAPI/Sonar/SonarBridge.cs | 32 +---- 9 files changed, 179 insertions(+), 191 deletions(-) diff --git a/SteelSeriesAPI.Sample/Program.cs b/SteelSeriesAPI.Sample/Program.cs index f2f87d4..bf60bb7 100644 --- a/SteelSeriesAPI.Sample/Program.cs +++ b/SteelSeriesAPI.Sample/Program.cs @@ -48,12 +48,13 @@ static void Main(string[] args) sonarManager.VolumeSettings.SetMute(true, Channel.CHAT); // Mute chat // Get audio configs - List allConfigs = sonarManager.GetAllAudioConfigurations().ToList(); // Return all configs (A SonarAudioConfiguration contains an Id, a Name and an AssociatedChannel) - List mediaConfigs = sonarManager.GetAudioConfigurations(Channel.MEDIA).ToList(); // Return all configs of a Sonar Channel - SonarAudioConfiguration currentConfig = sonarManager.GetSelectedAudioConfiguration(Channel.MEDIA); // Return the currently used config of a Sonar Channel + List allConfigs = sonarManager.Configurations.GetAllAudioConfigurations().ToList(); // Return all configs (A SonarAudioConfiguration contains an Id, a Name and an AssociatedChannel) + List mediaConfigs = sonarManager.Configurations.GetAudioConfigurations(Channel.MEDIA).ToList(); // Return all configs of a Sonar Channel + SonarAudioConfiguration currentConfig = sonarManager.Configurations.GetSelectedAudioConfiguration(Channel.MEDIA); // Return the currently used config of a Sonar Channel // Set the config of a Sonar Channel - sonarManager.SetConfig(Channel.MEDIA, "Podcast"); // Using its name - sonarManager.SetConfig(currentConfig.Id); // Using its id (no need to precise which Sonar Channel, one id goes to one Sonar Channel) + sonarManager.Configurations.SetConfigByName(Channel.MEDIA, "Podcast"); // Using its name + sonarManager.Configurations.SetConfig(currentConfig.Id); // Using its id (no need to precise which Sonar Channel, one id goes to one Sonar Channel) + sonarManager.Configurations.SetConfig(currentConfig); // Or you can just directly give the config // Get ChatMix info double chatMixBalance = sonarManager.GetChatMixBalance(); // The ChatMix value between -1 and 1 diff --git a/SteelSeriesAPI.Tests/Program.cs b/SteelSeriesAPI.Tests/Program.cs index 5774719..5f2930b 100644 --- a/SteelSeriesAPI.Tests/Program.cs +++ b/SteelSeriesAPI.Tests/Program.cs @@ -89,27 +89,27 @@ void GetTest(SonarBridge sonarManager) Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.AUX, Mix.STREAM) + " " + sonarManager.VolumeSettings.GetMute(Channel.AUX, Mix.STREAM)); Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.MIC, Mix.STREAM) + " " + sonarManager.VolumeSettings.GetMute(Channel.MIC, Mix.STREAM)); Console.WriteLine("----AudioConfigs----------"); - foreach (var config in sonarManager.GetAllAudioConfigurations()) + foreach (var config in sonarManager.Configurations.GetAllAudioConfigurations()) { Console.WriteLine(config.Id + ", " + config.Name + ", " + config.AssociatedChannel); } Console.WriteLine("----Media-Configs----------"); - foreach (var config in sonarManager.GetAudioConfigurations(Channel.MEDIA)) + foreach (var config in sonarManager.Configurations.GetAudioConfigurations(Channel.MEDIA)) { Console.WriteLine(config.Id + ", " + config.Name); } Console.WriteLine("----Mic-Configs----------"); - foreach (var config in sonarManager.GetAudioConfigurations(Channel.MIC)) + foreach (var config in sonarManager.Configurations.GetAudioConfigurations(Channel.MIC)) { Console.WriteLine(config.Id + ", " + config.Name); } Console.WriteLine("----Current Media Config----------"); - Console.WriteLine(sonarManager.GetSelectedAudioConfiguration(Channel.MEDIA).Name); + Console.WriteLine(sonarManager.Configurations.GetSelectedAudioConfiguration(Channel.MEDIA).Name); Console.WriteLine("----Channel from config ID----------"); - Console.WriteLine(sonarManager.GetAudioConfiguration("29ae2c02-792b-4487-863c-dc3e11a7a469").AssociatedChannel); + Console.WriteLine(sonarManager.Configurations.GetAudioConfiguration("29ae2c02-792b-4487-863c-dc3e11a7a469").AssociatedChannel); Console.WriteLine("--------ChatMix---------"); Console.WriteLine(sonarManager.GetChatMixBalance()); Console.WriteLine(sonarManager.GetChatMixState()); @@ -219,9 +219,9 @@ void SetTest(SonarBridge sonarManager){ sonarManager.SetMode(Mode.CLASSIC); sonarManager.VolumeSettings.SetVolume(0.4, Channel.MEDIA); sonarManager.VolumeSettings.SetMute(false, Channel.MEDIA); - string configId = sonarManager.GetAudioConfigurations(Channel.MEDIA).FirstOrDefault(config => config.Name == "Default")?.Id; - sonarManager.SetConfig(configId); - sonarManager.SetConfig(Channel.MEDIA, "Default"); + string configId = sonarManager.Configurations.GetAudioConfigurations(Channel.MEDIA).FirstOrDefault(config => config.Name == "Default")?.Id; + sonarManager.Configurations.SetConfig(configId); + sonarManager.Configurations.SetConfigByName(Channel.MEDIA, "Default"); sonarManager.SetChatMixBalance(0.5); var redirectionDevices = sonarManager.GetPlaybackDevices(DataFlow.INPUT); diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs index 6da47e1..602a64d 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs @@ -20,26 +20,6 @@ public void SetMode(Mode mode) Thread.Sleep(100); // Prevent bugs/freezes/crashes } - public void SetConfig(string configId) - { - if (string.IsNullOrEmpty(configId)) throw new Exception("Couldn't retrieve config id"); - - new HttpPut("configs/" + configId + "/select"); - } - - public void SetConfig(Channel channel, string name) - { - var configs = _sonarBridge.GetAudioConfigurations(channel).ToList(); - foreach (var config in configs) - { - if (config.Name == name) - { - SetConfig(config.Id); - break; - } - } - } - public void SetChatMixBalance(double balance) { if (!_sonarBridge.GetChatMixState()) diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs index e5b8d08..f61f433 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs @@ -22,88 +22,6 @@ public Mode GetMode() return (Mode)ModeExtensions.FromDictKey(mode, ModeMapChoice.StreamDict); } - #region AudioConfigs - - public IEnumerable GetAllAudioConfigurations() - { - JsonDocument configs = new HttpProvider("configs").Provide(); - - foreach (var element in configs.RootElement.EnumerateArray()) - { - string vDevice = element.GetProperty("virtualAudioDevice").GetString(); - string id = element.GetProperty("id").GetString(); - string name = element.GetProperty("name").GetString(); - - yield return new SonarAudioConfiguration(id, name, (Channel)ChannelExtensions.FromDictKey(vDevice)); - } - } - - public SonarAudioConfiguration GetAudioConfiguration(string configId) - { - IEnumerable configs = GetAllAudioConfigurations(); - SonarAudioConfiguration sonarConfig = null; - - foreach (var config in configs) - { - if (config.Id == configId) - { - sonarConfig = config; - break; - } - } - - return sonarConfig; - } - - public IEnumerable GetAudioConfigurations(Channel channel) - { - if (channel == Channel.MASTER) - { - throw new Exception("Can't get audio configurations for master"); - } - - IEnumerable configs = GetAllAudioConfigurations(); - List deviceConfigs = new List(); - - foreach (var config in configs) - { - if (config.AssociatedChannel == channel) - { - deviceConfigs.Add(config); - } - } - - return deviceConfigs.OrderBy(s => s.Name); - } - - public SonarAudioConfiguration GetSelectedAudioConfiguration(Channel channel) - { - if (channel == Channel.MASTER) - { - throw new Exception("Can't get audio configuration for master"); - } - - JsonDocument selectedConfigs = new HttpProvider("configs/selected").Provide(); - JsonElement sConfig = default; - - foreach (var config in selectedConfigs.RootElement.EnumerateArray()) - { - if (config.GetProperty("virtualAudioDevice").GetString() == channel.ToDictKey()) - { - sConfig = config; - break; - } - } - - string id = sConfig.GetProperty("id").GetString(); - string name = sConfig.GetProperty("name").GetString(); - string vDevice = sConfig.GetProperty("virtualAudioDevice").GetString(); - - return new SonarAudioConfiguration(id, name, (Channel)ChannelExtensions.FromDictKey(vDevice)); - } - - #endregion - #region ChatMix public double GetChatMixBalance() diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs index 7aba1d1..67adfc9 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs @@ -9,21 +9,6 @@ public interface ISonarCommandHandler /// /// The you want to set void SetMode(Mode mode); - - /// - /// Set the config of a Sonar by giving its id - /// - /// For more explanation, go on the GitHub wiki - /// The id of the config - void SetConfig(string configId); - - /// - /// Set the config of a Sonar by giving its name - /// - /// For more explanation, go on the GitHub wiki - /// The you want to change the config - /// The name of the config - void SetConfig(Channel channel, string name); /// /// Set the balance of the ChatMix diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs index 9e3690c..374c5d4 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs @@ -10,33 +10,6 @@ public interface ISonarDataProvider /// /// A , either Classic or Streamer Mode GetMode(); - - /// - /// Get all audio configurations from Sonar - /// - /// An IEnumerable of - IEnumerable GetAllAudioConfigurations(); - - /// - /// Get a specific audio configuration from Sonar - /// - /// The id of the config - /// A - SonarAudioConfiguration GetAudioConfiguration(string configId); - - /// - /// Get all audio configurations of a from Sonar - /// - /// The channel you want the configs - /// An IEnumerable of ordered alphabetically - IEnumerable GetAudioConfigurations(Channel channel); - - /// - /// Get the current audio configuration of a chosen - /// - /// The channel you want the current config - /// A - SonarAudioConfiguration GetSelectedAudioConfiguration(Channel channel); /// /// Get the actual ChatMix balance value diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IConfigurationManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IConfigurationManager.cs index 0ffacb2..1db642a 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/Managers/IConfigurationManager.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IConfigurationManager.cs @@ -1,6 +1,57 @@ -namespace SteelSeriesAPI.Sonar.Interfaces.Managers; +using SteelSeriesAPI.Sonar.Enums; +using SteelSeriesAPI.Sonar.Models; + +namespace SteelSeriesAPI.Sonar.Interfaces.Managers; public interface IConfigurationManager { + /// + /// Get all audio configurations from Sonar + /// + /// An IEnumerable of + IEnumerable GetAllAudioConfigurations(); + + /// + /// Get all audio configurations of a from Sonar + /// + /// The channel you want the configs + /// An IEnumerable of ordered alphabetically + IEnumerable GetAudioConfigurations(Channel channel); + + /// + /// Get a specific audio configuration from Sonar + /// + /// The id of the config + /// A + SonarAudioConfiguration GetAudioConfiguration(string configId); + + /// + /// Get the current audio configuration of a chosen + /// + /// The channel you want the current config + /// A + SonarAudioConfiguration GetSelectedAudioConfiguration(Channel channel); + + /// + /// Set the config of a Sonar by giving its id + /// + /// For more explanation, go on the GitHub wiki + /// The id of the config + void SetConfig(string configId); + + /// + /// Set the config of a Sonar by giving a + /// + /// For more explanation, go on the GitHub wiki + /// The id + void SetConfig(SonarAudioConfiguration config); + + /// + /// Set the config of a Sonar by giving its name + /// + /// For more explanation, go on the GitHub wiki + /// The you want to change the config + /// The name of the config + void SetConfigByName(Channel channel, string name); } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs b/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs index 70c33d7..c030d62 100644 --- a/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs @@ -1,6 +1,114 @@ -namespace SteelSeriesAPI.Sonar.Managers; +using SteelSeriesAPI.Sonar.Interfaces.Managers; +using SteelSeriesAPI.Sonar.Enums; +using SteelSeriesAPI.Sonar.Http; +using SteelSeriesAPI.Sonar.Models; -public class ConfigurationManager +using System.Text.Json; + +namespace SteelSeriesAPI.Sonar.Managers; + +public class ConfigurationManager : IConfigurationManager { - + public IEnumerable GetAllAudioConfigurations() + { + JsonDocument configs = new HttpProvider("configs").Provide(); + + foreach (var element in configs.RootElement.EnumerateArray()) + { + string vDevice = element.GetProperty("virtualAudioDevice").GetString(); + string id = element.GetProperty("id").GetString(); + string name = element.GetProperty("name").GetString(); + + yield return new SonarAudioConfiguration(id, name, (Channel)ChannelExtensions.FromDictKey(vDevice)); + } + } + + public IEnumerable GetAudioConfigurations(Channel channel) + { + if (channel == Channel.MASTER) + { + throw new Exception("Can't get audio configurations for master"); + } + + IEnumerable configs = GetAllAudioConfigurations(); + List deviceConfigs = new List(); + + foreach (var config in configs) + { + if (config.AssociatedChannel == channel) + { + deviceConfigs.Add(config); + } + } + + return deviceConfigs.OrderBy(s => s.Name); + } + + public SonarAudioConfiguration GetAudioConfiguration(string configId) + { + IEnumerable configs = GetAllAudioConfigurations(); + SonarAudioConfiguration sonarConfig = null; + + foreach (var config in configs) + { + if (config.Id == configId) + { + sonarConfig = config; + break; + } + } + + return sonarConfig; + } + + public SonarAudioConfiguration GetSelectedAudioConfiguration(Channel channel) + { + if (channel == Channel.MASTER) + { + throw new Exception("Can't get audio configuration for master"); + } + + JsonDocument selectedConfigs = new HttpProvider("configs/selected").Provide(); + JsonElement sConfig = default; + + foreach (var config in selectedConfigs.RootElement.EnumerateArray()) + { + if (config.GetProperty("virtualAudioDevice").GetString() == channel.ToDictKey()) + { + sConfig = config; + break; + } + } + + string id = sConfig.GetProperty("id").GetString(); + string name = sConfig.GetProperty("name").GetString(); + string vDevice = sConfig.GetProperty("virtualAudioDevice").GetString(); + + return new SonarAudioConfiguration(id, name, (Channel)ChannelExtensions.FromDictKey(vDevice)); + } + + public void SetConfig(string configId) + { + if (string.IsNullOrEmpty(configId)) throw new Exception("Couldn't retrieve config id"); + + new HttpPut("configs/" + configId + "/select"); + } + + public void SetConfig(SonarAudioConfiguration config) + { + SetConfig(config.Id); + } + + public void SetConfigByName(Channel channel, string name) + { + var configs = GetAudioConfigurations(channel).ToList(); + foreach (var config in configs) + { + if (config.Name == name) + { + SetConfig(config.Id); + break; + } + } + } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index 98c5753..87b6ae7 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -21,6 +21,7 @@ public class SonarBridge : ISonarBridge private readonly ISonarSocket _sonarSocket; public readonly VolumeSettingsManager VolumeSettings; + public readonly ConfigurationManager Configurations; public readonly EventManager Event; private string _sonarWebServerAddress; @@ -35,6 +36,7 @@ public SonarBridge() _sonarCommand = new SonarHttpCommand(this); _sonarProvider = new SonarHttpProvider(this); VolumeSettings = new VolumeSettingsManager(); + Configurations = new ConfigurationManager(); } #region Listener @@ -95,26 +97,6 @@ public Mode GetMode() { return _sonarProvider.GetMode(); } - - public IEnumerable GetAllAudioConfigurations() - { - return _sonarProvider.GetAllAudioConfigurations(); - } - - public SonarAudioConfiguration GetAudioConfiguration(string configId) - { - return _sonarProvider.GetAudioConfiguration(configId); - } - - public IEnumerable GetAudioConfigurations(Channel channel) - { - return _sonarProvider.GetAudioConfigurations(channel); - } - - public SonarAudioConfiguration GetSelectedAudioConfiguration(Channel channel) - { - return _sonarProvider.GetSelectedAudioConfiguration(channel); - } public double GetChatMixBalance() { @@ -175,16 +157,6 @@ public void SetMode(Mode mode) _sonarCommand.SetMode(mode); } - public void SetConfig(string configId) - { - _sonarCommand.SetConfig(configId); - } - - public void SetConfig(Channel channel, string name) - { - _sonarCommand.SetConfig(channel, name); - } - public void SetChatMixBalance(double balance) { _sonarCommand.SetChatMixBalance(balance); From a48d5333a41ed2bd612b460c4b34a2d1e2bf9a30 Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 02:11:00 +0200 Subject: [PATCH 06/47] Forgot to rename a variable --- SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs b/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs index c030d62..9a417fb 100644 --- a/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs @@ -31,17 +31,17 @@ public IEnumerable GetAudioConfigurations(Channel chann } IEnumerable configs = GetAllAudioConfigurations(); - List deviceConfigs = new List(); + List channelConfigs = new List(); foreach (var config in configs) { if (config.AssociatedChannel == channel) { - deviceConfigs.Add(config); + channelConfigs.Add(config); } } - return deviceConfigs.OrderBy(s => s.Name); + return channelConfigs.OrderBy(s => s.Name); } public SonarAudioConfiguration GetAudioConfiguration(string configId) From d88c05db1b3833f125a7f564a14e26f38a7762d6 Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 02:27:57 +0200 Subject: [PATCH 07/47] Added PlaybackDeviceManager --- SteelSeriesAPI.Sample/Program.cs | 18 +- SteelSeriesAPI.Tests/Program.cs | 38 +-- SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs | 20 -- .../Sonar/Http/SonarHttpProvider.cs | 173 -------------- .../Sonar/Interfaces/ISonarCommandHandler.cs | 22 -- .../Sonar/Interfaces/ISonarDataProvider.cs | 36 --- .../Managers/IPlaybackDeviceManager.cs | 64 ++++- .../Sonar/Managers/PlaybackDeviceManager.cs | 219 +++++++++++++++++- SteelSeriesAPI/Sonar/Models/PlaybackDevice.cs | 2 +- SteelSeriesAPI/Sonar/SonarBridge.cs | 42 +--- 10 files changed, 311 insertions(+), 323 deletions(-) diff --git a/SteelSeriesAPI.Sample/Program.cs b/SteelSeriesAPI.Sample/Program.cs index bf60bb7..326e9f5 100644 --- a/SteelSeriesAPI.Sample/Program.cs +++ b/SteelSeriesAPI.Sample/Program.cs @@ -63,16 +63,16 @@ static void Main(string[] args) sonarManager.SetChatMixBalance(0.5); // 0.5 is halfway to Chat // Get playback devices (Windows devices) - List inputDevices = sonarManager.GetPlaybackDevices(DataFlow.INPUT).ToList(); // Input devices (Mics...) - sonarManager.GetPlaybackDevices(DataFlow.OUTPUT); // Output devices (headset, speakers...) - sonarManager.GetPlaybackDeviceFromId("{0.0.0.00000000}.{192b4f5b-9cc1-4eb2-b752-c5e15b99d548}"); // Get a redirection channel from its id - PlaybackDevice gameRDevice = sonarManager.GetClassicPlaybackDevice(Channel.GAME); // Give currently used Redirection Channel for classic mode - sonarManager.GetStreamPlaybackDevice(Mix.MONITORING); // Give currently used Redirection Channel for Streamer mode - sonarManager.GetStreamPlaybackDevice(Channel.MIC); // Give currently used Redirection Channel for Mic in streamer mode + List inputDevices = sonarManager.PlaybackDevices.GetPlaybackDevices(DataFlow.INPUT).ToList(); // Input devices (Mics...) + sonarManager.PlaybackDevices.GetPlaybackDevices(DataFlow.OUTPUT); // Output devices (headset, speakers...) + sonarManager.PlaybackDevices.GetPlaybackDevice("{0.0.0.00000000}.{192b4f5b-9cc1-4eb2-b752-c5e15b99d548}"); // Get a redirection channel from its id + PlaybackDevice gameRDevice = sonarManager.PlaybackDevices.GetClassicPlaybackDevice(Channel.GAME); // Give currently used Redirection Channel for classic mode + sonarManager.PlaybackDevices.GetStreamerPlaybackDevice(Mix.MONITORING); // Give currently used Redirection Channel for Streamer mode + sonarManager.PlaybackDevices.GetStreamerPlaybackDevice(Channel.MIC); // Give currently used Redirection Channel for Mic in streamer mode // Change playback devices using their id - sonarManager.SetClassicPlaybackDevice(gameRDevice.Id, Channel.GAME); - sonarManager.SetStreamPlaybackDevice(gameRDevice.Id, Mix.MONITORING); - sonarManager.SetStreamPlaybackDevice(inputDevices[0].Id, Channel.MIC); + sonarManager.PlaybackDevices.SetClassicPlaybackDevice(gameRDevice.Id, Channel.GAME); + sonarManager.PlaybackDevices.SetStreamerPlaybackDevice(gameRDevice.Id, Mix.MONITORING); + sonarManager.PlaybackDevices.SetStreamerPlaybackDevice(inputDevices[0].Id, Channel.MIC); // Get the redirections states sonarManager.GetRedirectionState(Channel.MEDIA, Mix.MONITORING); diff --git a/SteelSeriesAPI.Tests/Program.cs b/SteelSeriesAPI.Tests/Program.cs index 5f2930b..608deb2 100644 --- a/SteelSeriesAPI.Tests/Program.cs +++ b/SteelSeriesAPI.Tests/Program.cs @@ -116,57 +116,57 @@ void GetTest(SonarBridge sonarManager) Console.WriteLine("-----Redirection Devices-----------"); Console.WriteLine("---Output---"); - foreach (var rDevice in sonarManager.GetPlaybackDevices(DataFlow.OUTPUT)) + foreach (var rDevice in sonarManager.PlaybackDevices.GetPlaybackDevices(DataFlow.OUTPUT)) { Console.WriteLine(rDevice.Id + ", " + rDevice.Name); - foreach (var device in rDevice.AssociatedClassicDevices) + foreach (var device in rDevice.AssociatedClassicChannels) { Console.WriteLine("...." + device); } - foreach (var channel in rDevice.AssociatedStreamDevices) + foreach (var channel in rDevice.AssociatedStreamChannels) { Console.WriteLine("...." + channel); } } Console.WriteLine("---Input---"); - foreach (var rDevice in sonarManager.GetPlaybackDevices(DataFlow.INPUT)) + foreach (var rDevice in sonarManager.PlaybackDevices.GetPlaybackDevices(DataFlow.INPUT)) { Console.WriteLine(rDevice.Id + ", " + rDevice.Name); - foreach (var device in rDevice.AssociatedClassicDevices) + foreach (var device in rDevice.AssociatedClassicChannels) { Console.WriteLine("...." + device); } - foreach (var channel in rDevice.AssociatedStreamDevices) + foreach (var channel in rDevice.AssociatedStreamChannels) { Console.WriteLine("...." + channel); } } - Console.WriteLine("-----Classic Redirection Devices------------"); - PlaybackDevice reDevice = sonarManager.GetClassicPlaybackDevice(Channel.GAME); + Console.WriteLine("-----Classic Playback Devices------------"); + PlaybackDevice reDevice = sonarManager.PlaybackDevices.GetClassicPlaybackDevice(Channel.GAME); Console.WriteLine(reDevice.Id + ", " + reDevice.Name); - foreach (var device in reDevice.AssociatedClassicDevices) + foreach (var device in reDevice.AssociatedClassicChannels) { Console.WriteLine("...." + device); } - foreach (var channel in reDevice.AssociatedStreamDevices) + foreach (var channel in reDevice.AssociatedStreamChannels) { Console.WriteLine("...." + channel); } - Console.WriteLine("-----Stream Redirection Devices------------"); - PlaybackDevice reDeviceS = sonarManager.GetStreamPlaybackDevice(Channel.MIC); // sonarManager.GetStreamPlaybackDevice(Mix.MONITORING); + Console.WriteLine("-----Stream Playback Devices------------"); + PlaybackDevice reDeviceS = sonarManager.PlaybackDevices.GetStreamerPlaybackDevice(Channel.MIC); // sonarManager.GetStreamPlaybackDevice(Mix.MONITORING); Console.WriteLine(reDeviceS.Id + ", " + reDeviceS.Name); - foreach (var device in reDeviceS.AssociatedClassicDevices) + foreach (var device in reDeviceS.AssociatedClassicChannels) { Console.WriteLine("...." + device); } - foreach (var channel in reDeviceS.AssociatedStreamDevices) + foreach (var channel in reDeviceS.AssociatedStreamChannels) { Console.WriteLine("...." + channel); } @@ -174,12 +174,12 @@ void GetTest(SonarBridge sonarManager) Console.WriteLine("-----Redirection Channel From Id"); // PlaybackDevice someDevice = sonarManager.GetPlaybackDeviceFromId("{0.0.0.00000000}.{453f6e2f-375e-4b36-97b2-2aa55691ab3c}"); // Console.WriteLine(someDevice.Id + ", " + someDevice.Name + ", " + someDevice.DataFlow); - // foreach (var associatedClassicDevice in someDevice.AssociatedClassicDevices) + // foreach (var associatedClassicDevice in someDevice.AssociatedClassicChannels) // { // Console.WriteLine("...." + associatedClassicDevice); // } // - // foreach (var associatedStreamDevice in someDevice.AssociatedStreamDevices) + // foreach (var associatedStreamDevice in someDevice.AssociatedStreamChannels) // { // Console.WriteLine("...." + associatedStreamDevice); // } @@ -224,10 +224,10 @@ void SetTest(SonarBridge sonarManager){ sonarManager.Configurations.SetConfigByName(Channel.MEDIA, "Default"); sonarManager.SetChatMixBalance(0.5); - var redirectionDevices = sonarManager.GetPlaybackDevices(DataFlow.INPUT); + var redirectionDevices = sonarManager.PlaybackDevices.GetPlaybackDevices(DataFlow.INPUT); redirectionDevices.GetEnumerator().MoveNext(); - sonarManager.SetClassicPlaybackDevice(redirectionDevices.GetEnumerator().Current.Id, Channel.MIC); - sonarManager.SetStreamPlaybackDevice(redirectionDevices.GetEnumerator().Current.Id, Channel.MIC); + sonarManager.PlaybackDevices.SetClassicPlaybackDevice(redirectionDevices.GetEnumerator().Current.Id, Channel.MIC); + sonarManager.PlaybackDevices.SetStreamerPlaybackDevice(redirectionDevices.GetEnumerator().Current.Id, Channel.MIC); sonarManager.SetRedirectionState(true, Channel.MEDIA, Mix.STREAM); sonarManager.SetAudienceMonitoringState(false); diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs index 602a64d..d51b368 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs @@ -35,26 +35,6 @@ public void SetChatMixBalance(double balance) new HttpPut("chatMix?balance=" + balance.ToString("0.00", CultureInfo.InvariantCulture)); } - public void SetClassicPlaybackDevice(string deviceId, Channel channel) - { - new HttpPut("classicRedirections/" + channel.ToDictKey(ChannelMapChoice.ChannelDict) +"/deviceId/" + deviceId); - } - - public void SetStreamPlaybackDevice(string deviceId, Mix mix) - { - new HttpPut("streamRedirections/" + mix.ToDictKey() +"/deviceId/" + deviceId); - } - - public void SetStreamPlaybackDevice(string deviceId, Channel channel) - { - if (channel != Channel.MIC) - { - throw new Exception("Can only change stream redirection channel for Mic"); - } - - new HttpPut("streamRedirections/" + channel.ToDictKey(ChannelMapChoice.ChannelDict) +"/deviceId/" + deviceId); - } - public void SetRedirectionState(bool newState, Channel channel, Mix mix) { new HttpPut("streamRedirections/" + mix.ToDictKey() + "/redirections/" + channel.ToDictKey() + diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs index f61f433..a999e9f 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs @@ -49,179 +49,6 @@ public bool GetChatMixState() #endregion - public IEnumerable GetPlaybackDevices(DataFlow _dataFlow) - { - JsonDocument audioDevices = new HttpProvider("audioDevices").Provide(); - JsonDocument classicRedirections = new HttpProvider("classicRedirections").Provide(); - JsonDocument streamRedirections = new HttpProvider("streamRedirections").Provide(); - - foreach (var element in audioDevices.RootElement.EnumerateArray()) - { - if (element.GetProperty("role").GetString() != "none") - { - continue; - } - - string id = element.GetProperty("id").GetString(); - string name = element.GetProperty("friendlyName").GetString(); - string dataFlow = element.GetProperty("dataFlow").GetString(); - List associatedClassicDevices = new List(); - ArrayList associatedStreamDevices = new ArrayList(); - - GetAssociatedDevices(id, associatedClassicDevices, associatedStreamDevices); - - if (dataFlow == _dataFlow.ToDictKey()) - { - yield return new PlaybackDevice(id, name, (DataFlow)DataFlowExtensions.FromDictKey(dataFlow), associatedClassicDevices, associatedStreamDevices); - } - } - } - - public PlaybackDevice GetClassicPlaybackDevice(Channel channel) - { - if (channel == Channel.MASTER) - { - throw new Exception("Can't get redirection channel for master"); - } - - JsonDocument classicRedirections = new HttpProvider("classicRedirections").Provide(); - JsonElement cRedirections = default; - - foreach (var element in classicRedirections.RootElement.EnumerateArray()) - { - if (element.GetProperty("id").GetString() == channel.ToDictKey(ChannelMapChoice.ChannelDict)) - { - cRedirections = element; - break; - } - } - - string deviceId = cRedirections.GetProperty("deviceId").GetString(); - List associatedClassicDevices = new List(); - ArrayList associatedStreamDevices = new ArrayList(); - - GetAssociatedDevices(deviceId, associatedClassicDevices, associatedStreamDevices); - - JsonDocument audioDevice = new HttpProvider("audioDevices/" + deviceId).Provide(); - - string name = audioDevice.RootElement.GetProperty("friendlyName").GetString(); - DataFlow dataFlow = (DataFlow)DataFlowExtensions.FromDictKey(audioDevice.RootElement.GetProperty("dataFlow").GetString()); - - return new PlaybackDevice(deviceId, name, dataFlow, associatedClassicDevices, associatedStreamDevices); - } - - public PlaybackDevice GetStreamPlaybackDevice(Mix mix) - { - JsonDocument streamRedirections = new HttpProvider("streamRedirections").Provide(); - JsonElement sRedirections = default; - - foreach (var element in streamRedirections.RootElement.EnumerateArray()) - { - if (element.GetProperty("streamRedirectionId").GetString() == mix.ToDictKey()) - { - sRedirections = element; - break; - } - } - - string deviceId = sRedirections.GetProperty("deviceId").GetString(); - List associatedClassicDevices = new List();ArrayList associatedStreamDevices = new ArrayList(); - - GetAssociatedDevices(deviceId, associatedClassicDevices, associatedStreamDevices); - - JsonDocument audioDevice = new HttpProvider("audioDevices/" + deviceId).Provide(); - - string name = audioDevice.RootElement.GetProperty("friendlyName").GetString(); - DataFlow dataFlow = (DataFlow)DataFlowExtensions.FromDictKey(audioDevice.RootElement.GetProperty("dataFlow").GetString()); - - return new PlaybackDevice(deviceId, name, dataFlow, associatedClassicDevices, associatedStreamDevices); - } - - public PlaybackDevice GetStreamPlaybackDevice(Channel channel) - { - if (channel != Channel.MIC) - { - throw new Exception("Can only get stream redirection channel for Mic"); - } - - JsonDocument streamRedirections = new HttpProvider("streamRedirections").Provide(); - JsonElement sRedirections = default; - - foreach (var element in streamRedirections.RootElement.EnumerateArray()) - { - if (element.GetProperty("streamRedirectionId").GetString() == channel.ToDictKey(ChannelMapChoice.ChannelDict)) - { - sRedirections = element; - break; - } - } - - string deviceId = sRedirections.GetProperty("deviceId").GetString(); - List associatedClassicDevices = new List(); - ArrayList associatedStreamDevices = new ArrayList(); - - GetAssociatedDevices(deviceId, associatedClassicDevices, associatedStreamDevices); - - JsonDocument audioDevice = new HttpProvider("audioDevices/" + deviceId).Provide(); - - string name = audioDevice.RootElement.GetProperty("friendlyName").GetString(); - DataFlow dataFlow = (DataFlow)DataFlowExtensions.FromDictKey(audioDevice.RootElement.GetProperty("dataFlow").GetString()); - - return new PlaybackDevice(deviceId, name, dataFlow, associatedClassicDevices, associatedStreamDevices); - } - - public PlaybackDevice GetPlaybackDeviceFromId(string deviceId) - { - try - { - JsonElement device = new HttpProvider("audioDevices/" + deviceId).Provide().RootElement; - - string id = device.GetProperty("id").GetString(); - string name = device.GetProperty("friendlyName").GetString(); - string dataFlow = device.GetProperty("dataFlow").GetString(); - List associatedClassicDevices = new List(); - ArrayList associatedStreamDevices = new ArrayList(); - - GetAssociatedDevices(deviceId, associatedClassicDevices, associatedStreamDevices); - - return new PlaybackDevice(id, name, (DataFlow)DataFlowExtensions.FromDictKey(dataFlow), associatedClassicDevices, associatedStreamDevices); - } - catch (Exception e) - { - Console.WriteLine(e); - throw new Exception("Can't get any channel from this Id, maybe the channel doesn't exist or its Id changed."); - } - } - - private void GetAssociatedDevices(string deviceId, List associatedClassicDevices, ArrayList associatedStreamDevices) - { - JsonDocument classicRedirections = new HttpProvider("classicRedirections").Provide(); - JsonDocument streamRedirections = new HttpProvider("streamRedirections").Provide(); - - foreach (var element in classicRedirections.RootElement.EnumerateArray()) - { - if (element.GetProperty("deviceId").GetString() == deviceId) - { - associatedClassicDevices.Add((Channel)ChannelExtensions.FromDictKey(element.GetProperty("id").GetString(), ChannelMapChoice.ChannelDict)); - } - } - - foreach (var element in streamRedirections.RootElement.EnumerateArray()) - { - if (element.GetProperty("deviceId").GetString() == deviceId) - { - if (element.GetProperty("streamRedirectionId").GetString() == "mic") - { - associatedStreamDevices.Add((Channel)ChannelExtensions.FromDictKey(element.GetProperty("streamRedirectionId").GetString(), ChannelMapChoice.ChannelDict)); - } - else - { - associatedStreamDevices.Add((Mix)MixExtensions.FromDictKey(element.GetProperty("streamRedirectionId").GetString())); - } - } - } - } - public bool GetRedirectionState(Channel channel, Mix mix) { if (channel == Channel.MASTER) diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs index 67adfc9..69f47c9 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs @@ -17,28 +17,6 @@ public interface ISonarCommandHandler /// A between -1 and 1 void SetChatMixBalance(double balance); - /// - /// Set the Redirection Channel of a Sonar using its ID - /// - /// The id of the new Redirection Channel - /// The Sonar you want to change the Redirection Channel - void SetClassicPlaybackDevice(string deviceId, Channel channel); - - /// - /// Set the Redirection Channel of a Streamer mode Sonar using its ID - /// - /// The id of the new Redirection Channel - /// The Sonar you want to change the Redirection Channel - void SetStreamPlaybackDevice(string deviceId, Mix mix); - - /// - /// Set the Redirection Channel of the Streamer mode Sonar using its ID - /// - /// The id of the new Redirection Channel - /// The Sonar you want to change the redirection channel - /// should be set to for it to work - void SetStreamPlaybackDevice(string deviceId, Channel channel = Channel.MIC); - /// /// Enable or disable the Redirection of the chosen Sonar of the chosen Sonar /// diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs index 374c5d4..01d296e 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs @@ -23,42 +23,6 @@ public interface ISonarDataProvider /// True if ChatMix is enabled
False if ChatMix is disabled
bool GetChatMixState(); - /// - /// Get all the in/output Redirection Devices (Windows devices) - /// - /// The DataFlow of the channel (In/Output) - /// A list of - IEnumerable GetPlaybackDevices(DataFlow dataFlow); - - /// - /// Get the current Redirection Channel of a Sonar - /// - /// The Sonar you want the redirection channel - /// - PlaybackDevice GetClassicPlaybackDevice(Channel channel); - - /// - /// Get the current Redirection Channel of a Streamer mode Sonar - /// - /// The Sonar you want the redirection channel - /// A - PlaybackDevice GetStreamPlaybackDevice(Mix mix); - - /// - /// Get the current Redirection Channel of the Streamer mode Sonar - /// - /// The Sonar you want to change the redirection channel - /// - /// should be set to for it to work - PlaybackDevice GetStreamPlaybackDevice(Channel channel = Channel.MIC); - - /// - /// Get a Redirection Channel using its ID - /// - /// The ID of the Redirection Channel - /// - PlaybackDevice GetPlaybackDeviceFromId(string deviceId); - /// /// Get the mute state of the Redirection of the chosen Sonar of the chosen Sonar /// diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IPlaybackDeviceManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IPlaybackDeviceManager.cs index 50d0ddc..1fc84e2 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/Managers/IPlaybackDeviceManager.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IPlaybackDeviceManager.cs @@ -1,6 +1,68 @@ -namespace SteelSeriesAPI.Sonar.Interfaces.Managers; +using SteelSeriesAPI.Sonar.Enums; +using SteelSeriesAPI.Sonar.Models; + +namespace SteelSeriesAPI.Sonar.Interfaces.Managers; public interface IPlaybackDeviceManager { + /// + /// Get all the in/output Redirection Devices (Windows devices) + /// + /// The DataFlow of the channel (In/Output) + /// A list of + IEnumerable GetPlaybackDevices(DataFlow _dataFlow); + + /// + /// Get a Redirection Channel using its ID + /// + /// The ID of the Redirection Channel + /// + PlaybackDevice GetPlaybackDevice(string deviceId); + + /// + /// Get the current Redirection Channel of a Sonar + /// + /// The Sonar you want the redirection channel + /// + PlaybackDevice GetClassicPlaybackDevice(Channel channel); + + /// + /// Get the current Redirection Channel of a Streamer mode Sonar + /// + /// The Sonar you want the redirection channel + /// A + PlaybackDevice GetStreamerPlaybackDevice(Mix mix); + + /// + /// Get the current Redirection Channel of the Streamer mode Sonar + /// + /// The Sonar you want to change the redirection channel + /// + /// should be set to for it to work + PlaybackDevice GetStreamerPlaybackDevice(Channel channel = Channel.MIC); + + /// + /// Set the Redirection Channel of a Sonar using its ID + /// + /// The id of the new Redirection Channel + /// The Sonar you want to change the Redirection Channel + void SetClassicPlaybackDevice(string deviceId, Channel channel); + + /// + /// Set the Redirection Channel of a Streamer mode Sonar using its ID + /// + /// The id of the new Redirection Channel + /// The Sonar you want to change the Redirection Channel + void SetStreamerPlaybackDevice(string deviceId, Mix mix); + /// + /// Set the Redirection Channel of the Streamer mode Sonar using its ID + /// + /// The id of the new Redirection Channel + /// The Sonar you want to change the redirection channel + /// should be set to for it to work + void SetStreamerPlaybackDevice(string deviceId, Channel channel = Channel.MIC); + void SetClassicPlaybackDevice(PlaybackDevice playbackDevice, Channel channel); + void SetStreamerPlaybackDevice(PlaybackDevice playbackDevice, Mix mix); + void SetStreamerPlaybackDevice(PlaybackDevice playbackDevice, Channel channel = Channel.MIC); } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs b/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs index df26d8a..a84cb90 100644 --- a/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs @@ -1,6 +1,221 @@ -namespace SteelSeriesAPI.Sonar.Managers; +using System.Collections; +using SteelSeriesAPI.Sonar.Interfaces.Managers; +using SteelSeriesAPI.Sonar.Enums; +using SteelSeriesAPI.Sonar.Http; +using SteelSeriesAPI.Sonar.Models; -public class PlaybackDeviceManager +using System.Text.Json; + +namespace SteelSeriesAPI.Sonar.Managers; + +public class PlaybackDeviceManager : IPlaybackDeviceManager { + public IEnumerable GetPlaybackDevices(DataFlow _dataFlow) + { + JsonDocument audioDevices = new HttpProvider("audioDevices").Provide(); + // JsonDocument classicRedirections = new HttpProvider("classicRedirections").Provide(); + // JsonDocument streamRedirections = new HttpProvider("streamRedirections").Provide(); + + foreach (var element in audioDevices.RootElement.EnumerateArray()) + { + if (element.GetProperty("role").GetString() != "none") + { + continue; + } + + string id = element.GetProperty("id").GetString(); + string name = element.GetProperty("friendlyName").GetString(); + string dataFlow = element.GetProperty("dataFlow").GetString(); + List associatedClassicChannels = new List(); + ArrayList associatedStreamChannels = new ArrayList(); + + GetAssociatedChannels(id, associatedClassicChannels, associatedStreamChannels); + + if (dataFlow == _dataFlow.ToDictKey()) + { + yield return new PlaybackDevice(id, name, (DataFlow)DataFlowExtensions.FromDictKey(dataFlow), associatedClassicChannels, associatedStreamChannels); + } + } + } + + public PlaybackDevice GetPlaybackDevice(string deviceId) + { + try + { + JsonElement device = new HttpProvider("audioDevices/" + deviceId).Provide().RootElement; + + string id = device.GetProperty("id").GetString(); + string name = device.GetProperty("friendlyName").GetString(); + string dataFlow = device.GetProperty("dataFlow").GetString(); + List associatedClassicChannels = new List(); + ArrayList associatedStreamChannels = new ArrayList(); + + GetAssociatedChannels(deviceId, associatedClassicChannels, associatedStreamChannels); + + return new PlaybackDevice(id, name, (DataFlow)DataFlowExtensions.FromDictKey(dataFlow), associatedClassicChannels, associatedStreamChannels); + } + catch (Exception e) + { + Console.WriteLine(e); + throw new Exception("Can't get any channel from this Id, maybe the channel doesn't exist or its Id changed."); + } + } + + public PlaybackDevice GetClassicPlaybackDevice(Channel channel) + { + if (channel == Channel.MASTER) + { + throw new Exception("Can't get redirection channel for master"); + } + + JsonDocument classicRedirections = new HttpProvider("classicRedirections").Provide(); + JsonElement cRedirections = default; + + foreach (var element in classicRedirections.RootElement.EnumerateArray()) + { + if (element.GetProperty("id").GetString() == channel.ToDictKey(ChannelMapChoice.ChannelDict)) + { + cRedirections = element; + break; + } + } + + string deviceId = cRedirections.GetProperty("deviceId").GetString(); + List associatedClassicChannels = new List(); + ArrayList associatedStreamChannels = new ArrayList(); + + GetAssociatedChannels(deviceId, associatedClassicChannels, associatedStreamChannels); + + JsonDocument audioDevice = new HttpProvider("audioDevices/" + deviceId).Provide(); + + string name = audioDevice.RootElement.GetProperty("friendlyName").GetString(); + DataFlow dataFlow = (DataFlow)DataFlowExtensions.FromDictKey(audioDevice.RootElement.GetProperty("dataFlow").GetString()); + + return new PlaybackDevice(deviceId, name, dataFlow, associatedClassicChannels, associatedStreamChannels); + } + + public PlaybackDevice GetStreamerPlaybackDevice(Mix mix) + { + JsonDocument streamRedirections = new HttpProvider("streamRedirections").Provide(); + JsonElement sRedirections = default; + + foreach (var element in streamRedirections.RootElement.EnumerateArray()) + { + if (element.GetProperty("streamRedirectionId").GetString() == mix.ToDictKey()) + { + sRedirections = element; + break; + } + } + + string deviceId = sRedirections.GetProperty("deviceId").GetString(); + List associatedClassicChannels = new List(); + ArrayList associatedStreamChannels = new ArrayList(); + + GetAssociatedChannels(deviceId, associatedClassicChannels, associatedStreamChannels); + + JsonDocument audioDevice = new HttpProvider("audioDevices/" + deviceId).Provide(); + string name = audioDevice.RootElement.GetProperty("friendlyName").GetString(); + DataFlow dataFlow = (DataFlow)DataFlowExtensions.FromDictKey(audioDevice.RootElement.GetProperty("dataFlow").GetString()); + + return new PlaybackDevice(deviceId, name, dataFlow, associatedClassicChannels, associatedStreamChannels); + } + + public PlaybackDevice GetStreamerPlaybackDevice(Channel channel = Channel.MIC) + { + if (channel != Channel.MIC) + { + throw new Exception("Can only get stream redirection channel for Mic"); + } + + JsonDocument streamRedirections = new HttpProvider("streamRedirections").Provide(); + JsonElement sRedirections = default; + + foreach (var element in streamRedirections.RootElement.EnumerateArray()) + { + if (element.GetProperty("streamRedirectionId").GetString() == channel.ToDictKey(ChannelMapChoice.ChannelDict)) + { + sRedirections = element; + break; + } + } + + string deviceId = sRedirections.GetProperty("deviceId").GetString(); + List associatedClassicChannels = new List(); + ArrayList associatedStreamChannels = new ArrayList(); + + GetAssociatedChannels(deviceId, associatedClassicChannels, associatedStreamChannels); + + JsonDocument audioDevice = new HttpProvider("audioDevices/" + deviceId).Provide(); + + string name = audioDevice.RootElement.GetProperty("friendlyName").GetString(); + DataFlow dataFlow = (DataFlow)DataFlowExtensions.FromDictKey(audioDevice.RootElement.GetProperty("dataFlow").GetString()); + + return new PlaybackDevice(deviceId, name, dataFlow, associatedClassicChannels, associatedStreamChannels); + } + + private void GetAssociatedChannels(string deviceId, List associatedClassicDevices, ArrayList associatedStreamDevices) + { + JsonDocument classicRedirections = new HttpProvider("classicRedirections").Provide(); + JsonDocument streamRedirections = new HttpProvider("streamRedirections").Provide(); + + foreach (var element in classicRedirections.RootElement.EnumerateArray()) + { + if (element.GetProperty("deviceId").GetString() == deviceId) + { + associatedClassicDevices.Add((Channel)ChannelExtensions.FromDictKey(element.GetProperty("id").GetString(), ChannelMapChoice.ChannelDict)); + } + } + + foreach (var element in streamRedirections.RootElement.EnumerateArray()) + { + if (element.GetProperty("deviceId").GetString() == deviceId) + { + if (element.GetProperty("streamRedirectionId").GetString() == "mic") + { + associatedStreamDevices.Add((Channel)ChannelExtensions.FromDictKey(element.GetProperty("streamRedirectionId").GetString(), ChannelMapChoice.ChannelDict)); + } + else + { + associatedStreamDevices.Add((Mix)MixExtensions.FromDictKey(element.GetProperty("streamRedirectionId").GetString())); + } + } + } + } + + public void SetClassicPlaybackDevice(string deviceId, Channel channel) + { + new HttpPut("classicRedirections/" + channel.ToDictKey(ChannelMapChoice.ChannelDict) +"/deviceId/" + deviceId); + } + + public void SetStreamerPlaybackDevice(string deviceId, Mix mix) + { + new HttpPut("streamRedirections/" + mix.ToDictKey() +"/deviceId/" + deviceId); + } + + public void SetStreamerPlaybackDevice(string deviceId, Channel channel = Channel.MIC) + { + if (channel != Channel.MIC) + { + throw new Exception("Can only change stream redirection channel for Mic"); + } + + new HttpPut("streamRedirections/" + channel.ToDictKey(ChannelMapChoice.ChannelDict) +"/deviceId/" + deviceId); + } + + public void SetClassicPlaybackDevice(PlaybackDevice playbackDevice, Channel channel) + { + SetClassicPlaybackDevice(playbackDevice.Id, channel); + } + + public void SetStreamerPlaybackDevice(PlaybackDevice playbackDevice, Mix mix) + { + SetStreamerPlaybackDevice(playbackDevice.Id, mix); + } + + public void SetStreamerPlaybackDevice(PlaybackDevice playbackDevice, Channel channel = Channel.MIC) + { + SetStreamerPlaybackDevice(playbackDevice.Id, channel); + } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Models/PlaybackDevice.cs b/SteelSeriesAPI/Sonar/Models/PlaybackDevice.cs index 9e568b6..6ff6ed3 100644 --- a/SteelSeriesAPI/Sonar/Models/PlaybackDevice.cs +++ b/SteelSeriesAPI/Sonar/Models/PlaybackDevice.cs @@ -3,4 +3,4 @@ namespace SteelSeriesAPI.Sonar.Models; -public record PlaybackDevice(string Id, string Name, DataFlow DataFlow, List? AssociatedClassicDevices, ArrayList? AssociatedStreamDevices); \ No newline at end of file +public record PlaybackDevice(string Id, string Name, DataFlow DataFlow, List? AssociatedClassicChannels, ArrayList? AssociatedStreamChannels); \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index 87b6ae7..2543055 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -22,6 +22,7 @@ public class SonarBridge : ISonarBridge public readonly VolumeSettingsManager VolumeSettings; public readonly ConfigurationManager Configurations; + public readonly PlaybackDeviceManager PlaybackDevices; public readonly EventManager Event; private string _sonarWebServerAddress; @@ -37,6 +38,7 @@ public SonarBridge() _sonarProvider = new SonarHttpProvider(this); VolumeSettings = new VolumeSettingsManager(); Configurations = new ConfigurationManager(); + PlaybackDevices = new PlaybackDeviceManager(); } #region Listener @@ -108,31 +110,6 @@ public bool GetChatMixState() return _sonarProvider.GetChatMixState(); } - public IEnumerable GetPlaybackDevices(DataFlow dataFlow) - { - return _sonarProvider.GetPlaybackDevices(dataFlow); - } - - public PlaybackDevice GetClassicPlaybackDevice(Channel channel) - { - return _sonarProvider.GetClassicPlaybackDevice(channel); - } - - public PlaybackDevice GetStreamPlaybackDevice(Mix mix) - { - return _sonarProvider.GetStreamPlaybackDevice(mix); - } - - public PlaybackDevice GetStreamPlaybackDevice(Channel channel = Channel.MIC) - { - return _sonarProvider.GetStreamPlaybackDevice(channel); - } - - public PlaybackDevice GetPlaybackDeviceFromId(string deviceId) - { - return _sonarProvider.GetPlaybackDeviceFromId(deviceId); - } - public bool GetRedirectionState(Channel channel, Mix mix) { return _sonarProvider.GetRedirectionState(channel, mix); @@ -161,21 +138,6 @@ public void SetChatMixBalance(double balance) { _sonarCommand.SetChatMixBalance(balance); } - - public void SetClassicPlaybackDevice(string deviceId, Channel channel) - { - _sonarCommand.SetClassicPlaybackDevice(deviceId, channel); - } - - public void SetStreamPlaybackDevice(string deviceId, Mix mix) - { - _sonarCommand.SetStreamPlaybackDevice(deviceId, mix); - } - - public void SetStreamPlaybackDevice(string deviceId, Channel channel = Channel.MIC) - { - _sonarCommand.SetStreamPlaybackDevice(deviceId, channel); - } public void SetRedirectionState(bool newState, Channel channel, Mix mix) { From 72fa1f76d59f309f8f60d448875792315e0b037f Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 02:47:18 +0200 Subject: [PATCH 08/47] Remove useless parameter --- SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs | 7 ------- SteelSeriesAPI/Sonar/SonarBridge.cs | 4 ++-- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs index a999e9f..2314f55 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs @@ -8,13 +8,6 @@ namespace SteelSeriesAPI.Sonar.Http; public class SonarHttpProvider : ISonarDataProvider { - private readonly ISonarBridge _sonarBridge; - - public SonarHttpProvider(SonarBridge sonarBridge) - { - _sonarBridge = sonarBridge; - } - public Mode GetMode() { string mode = new HttpProvider("mode").Provide().RootElement.ToString(); diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index 2543055..b04f58a 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -32,13 +32,13 @@ public SonarBridge() _sonarRetriever = SonarRetriever.Instance; WaitUntilSonarStarted(); _sonarWebServerAddress = _sonarRetriever.WebServerAddress(); - Event = new EventManager(); _sonarSocket = new SonarSocket(_sonarWebServerAddress, Event); _sonarCommand = new SonarHttpCommand(this); - _sonarProvider = new SonarHttpProvider(this); + _sonarProvider = new SonarHttpProvider(); VolumeSettings = new VolumeSettingsManager(); Configurations = new ConfigurationManager(); PlaybackDevices = new PlaybackDeviceManager(); + Event = new EventManager(); } #region Listener From eca12241b9dd805099e582b01b0a878a5b8a3689 Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 02:59:13 +0200 Subject: [PATCH 09/47] Removed the WaitUntilSonarStart in the constructor so it only depends on the user, and not always when creating a bridge object --- SteelSeriesAPI.Tests/Program.cs | 2 +- SteelSeriesAPI/Sonar/SonarBridge.cs | 12 +++++------- SteelSeriesAPI/Sonar/SonarSocket.cs | 4 ++-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/SteelSeriesAPI.Tests/Program.cs b/SteelSeriesAPI.Tests/Program.cs index 608deb2..bf3aa3e 100644 --- a/SteelSeriesAPI.Tests/Program.cs +++ b/SteelSeriesAPI.Tests/Program.cs @@ -11,7 +11,7 @@ static void Main(string[] args) { SonarBridge sonarManager = new SonarBridge(); sonarManager.WaitUntilSonarStarted(); - Console.WriteLine(new SonarRetriever().WebServerAddress()); + Console.WriteLine(SonarRetriever.Instance.WebServerAddress()); sonarManager.StartListener(); diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index b04f58a..ce41e8b 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -18,21 +18,17 @@ public class SonarBridge : ISonarBridge private readonly IAppRetriever _sonarRetriever; private readonly ISonarCommandHandler _sonarCommand; private readonly ISonarDataProvider _sonarProvider; - private readonly ISonarSocket _sonarSocket; + private ISonarSocket _sonarSocket; public readonly VolumeSettingsManager VolumeSettings; public readonly ConfigurationManager Configurations; public readonly PlaybackDeviceManager PlaybackDevices; public readonly EventManager Event; - private string _sonarWebServerAddress; - public SonarBridge() { _sonarRetriever = SonarRetriever.Instance; - WaitUntilSonarStarted(); - _sonarWebServerAddress = _sonarRetriever.WebServerAddress(); - _sonarSocket = new SonarSocket(_sonarWebServerAddress, Event); + _sonarCommand = new SonarHttpCommand(this); _sonarProvider = new SonarHttpProvider(); VolumeSettings = new VolumeSettingsManager(); @@ -50,11 +46,13 @@ public bool StartListener() throw new ApplicationException("Listener requires Administrator rights to be used"); } - if (_sonarSocket.IsConnected) + if (_sonarSocket != null && _sonarSocket.IsConnected) { throw new Exception("Listener already started"); } + _sonarSocket = new SonarSocket(Event); + var connected = _sonarSocket.Connect(); if (!connected) { diff --git a/SteelSeriesAPI/Sonar/SonarSocket.cs b/SteelSeriesAPI/Sonar/SonarSocket.cs index 232d6cc..8e5ea77 100644 --- a/SteelSeriesAPI/Sonar/SonarSocket.cs +++ b/SteelSeriesAPI/Sonar/SonarSocket.cs @@ -17,9 +17,9 @@ public class SonarSocket : ISonarSocket private bool _isClosing; - public SonarSocket(string sonarWebServerAddress, EventManager eventManager) + public SonarSocket(EventManager eventManager) { - _sonarWebServerAddress = new Uri(sonarWebServerAddress); + _sonarWebServerAddress = new Uri(SonarRetriever.Instance.WebServerAddress()); _listenerThread = new Thread(ListenerThreadSync) { IsBackground = false }; _eventManager = eventManager; } From 2a4518a4deecdc278824bbf82ac3c63e7b2cc719 Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 03:21:28 +0200 Subject: [PATCH 10/47] Renamed event i forgot --- SteelSeriesAPI.Sample/Program.cs | 4 ++-- SteelSeriesAPI.Tests/Program.cs | 4 ++-- SteelSeriesAPI/Sonar/Managers/EventManager.cs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/SteelSeriesAPI.Sample/Program.cs b/SteelSeriesAPI.Sample/Program.cs index 326e9f5..956e64c 100644 --- a/SteelSeriesAPI.Sample/Program.cs +++ b/SteelSeriesAPI.Sample/Program.cs @@ -23,7 +23,7 @@ static void Main(string[] args) sonarManager.Event.OnSonarMuteChange += OnMuteChangeHandler; // When a Sonar Channel or Mix is muted or unmuted sonarManager.Event.OnSonarConfigChange += OnConfigChangeHandler; // When a new config is set to a Sonar Channel sonarManager.Event.OnSonarChatMixChange += OnChatMixChangeHandler; // When the ChatMix value is changed - sonarManager.Event.OnSonarRedirectionDeviceChange += OnRedirectionDeviceChangeHandler; // When the Redirection Channel of a Sonar Channel is changed + sonarManager.Event.OnSonarPlaybackDeviceChange += OnPlaybackDeviceChangeHandler; // When the Redirection Channel of a Sonar Channel is changed sonarManager.Event.OnSonarRedirectionStateChange += OnRedirectionStateChangeHandler; // When the Redirection of a Sonar Mix is muted or unmuted sonarManager.Event.OnSonarAudienceMonitoringChange += OnAudienceMonitoringChangeHandler; // When the Audience Monitoring is muted or unmuted @@ -115,7 +115,7 @@ static void OnChatMixChangeHandler(object? sender, SonarChatMixEvent eventArgs) Console.WriteLine("Received ChatMix Event : " + eventArgs.Balance); } - static void OnRedirectionDeviceChangeHandler(object? sender, SonarPlaybackDeviceEvent eventArgs) + static void OnPlaybackDeviceChangeHandler(object? sender, SonarPlaybackDeviceEvent eventArgs) { Console.WriteLine("Received Redirection Channel Event : " + eventArgs.RedirectionDeviceId + ", " + eventArgs.Mode + ", " + eventArgs.Device + ", " + eventArgs.Channel); } diff --git a/SteelSeriesAPI.Tests/Program.cs b/SteelSeriesAPI.Tests/Program.cs index bf3aa3e..ff05fd6 100644 --- a/SteelSeriesAPI.Tests/Program.cs +++ b/SteelSeriesAPI.Tests/Program.cs @@ -23,7 +23,7 @@ static void Main(string[] args) sonarManager.Event.OnSonarMuteChange += OnMuteChangeHandler; sonarManager.Event.OnSonarConfigChange += OnConfigChangeHandler; sonarManager.Event.OnSonarChatMixChange += OnChatMixChangeHandler; - sonarManager.Event.OnSonarRedirectionDeviceChange += OnRedirectionDeviceChangeHandler; + sonarManager.Event.OnSonarPlaybackDeviceChange += OnPlaybackDeviceChangeHandler; sonarManager.Event.OnSonarRedirectionStateChange += OnRedirectionStateChangeHandler; sonarManager.Event.OnSonarAudienceMonitoringChange += OnAudienceMonitoringChangeHandler; @@ -259,7 +259,7 @@ static void OnChatMixChangeHandler(object? sender, SonarChatMixEvent eventArgs) Console.WriteLine("Received ChatMix Event : " + eventArgs.Balance); } - static void OnRedirectionDeviceChangeHandler(object? sender, SonarPlaybackDeviceEvent eventArgs) + static void OnPlaybackDeviceChangeHandler(object? sender, SonarPlaybackDeviceEvent eventArgs) { Console.WriteLine("Received Redirection Channel Event : " + eventArgs.RedirectionDeviceId + ", " + eventArgs.Mode + ", " + eventArgs.Device + ", " + eventArgs.Channel); } diff --git a/SteelSeriesAPI/Sonar/Managers/EventManager.cs b/SteelSeriesAPI/Sonar/Managers/EventManager.cs index ef3857c..b2ca772 100644 --- a/SteelSeriesAPI/Sonar/Managers/EventManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/EventManager.cs @@ -34,7 +34,7 @@ public class EventManager /// /// Notify when a redirection channel of a channel is changed /// - public event EventHandler OnSonarRedirectionDeviceChange = delegate{ }; + public event EventHandler OnSonarPlaybackDeviceChange = delegate{ }; /// /// Notify when a redirection state is changed @@ -67,7 +67,7 @@ public void HandleEvent(string path) OnSonarChatMixChange(this, sonarChatMixEvent); break; case SonarPlaybackDeviceEvent sonarRedirectionDeviceEvent: - OnSonarRedirectionDeviceChange(this, sonarRedirectionDeviceEvent); + OnSonarPlaybackDeviceChange(this, sonarRedirectionDeviceEvent); break; case SonarRedirectionStateEvent sonarRedirectionStateEvent: OnSonarRedirectionStateChange(this, sonarRedirectionStateEvent); From a81d035936bbac6d2f48bafa7f51acb270f26511 Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 03:22:45 +0200 Subject: [PATCH 11/47] Made GG check running better, created a method to wait for GG to start and made it always depends on the user --- SteelSeriesAPI/Sonar/SonarBridge.cs | 15 ++++++++++----- SteelSeriesAPI/Sonar/SonarRetriever.cs | 17 ++++++++--------- SteelSeriesAPI/SteelSeriesRetriever.cs | 14 ++++---------- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index ce41e8b..e4e6c68 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -13,9 +13,8 @@ namespace SteelSeriesAPI.Sonar; /// public class SonarBridge : ISonarBridge { - public bool IsRunning => _sonarRetriever is { IsEnabled: true, IsReady: true, IsRunning: true }; + public bool IsRunning => SonarRetriever.Instance is { IsEnabled: true, IsReady: true, IsRunning: true }; - private readonly IAppRetriever _sonarRetriever; private readonly ISonarCommandHandler _sonarCommand; private readonly ISonarDataProvider _sonarProvider; private ISonarSocket _sonarSocket; @@ -27,8 +26,6 @@ public class SonarBridge : ISonarBridge public SonarBridge() { - _sonarRetriever = SonarRetriever.Instance; - _sonarCommand = new SonarHttpCommand(this); _sonarProvider = new SonarHttpProvider(); VolumeSettings = new VolumeSettingsManager(); @@ -83,12 +80,20 @@ private bool IsRunAsAdmin() #endregion + /// + /// Wait until SteelSeries GG is started and running before running your code below + /// + public void WaitUntilSteelSeriesStarted() + { + SteelSeriesRetriever.Instance.WaitUntilSteelSeriesStarted(); + } + /// /// Wait until Sonar is started and running before running your code below /// public void WaitUntilSonarStarted() { - _sonarRetriever.WaitUntilAppStarted(); + SonarRetriever.Instance.WaitUntilAppStarted(); } #region Providers diff --git a/SteelSeriesAPI/Sonar/SonarRetriever.cs b/SteelSeriesAPI/Sonar/SonarRetriever.cs index c957eba..4f469df 100644 --- a/SteelSeriesAPI/Sonar/SonarRetriever.cs +++ b/SteelSeriesAPI/Sonar/SonarRetriever.cs @@ -20,8 +20,6 @@ public class SonarRetriever : IAppRetriever public bool ToggleViaSettings => GetMetaDatas()[6]; public bool IsBrowserViewSupported => GetMetaDatas()[7]; - private readonly ISteelSeriesRetriever _ssRetriever; - private readonly string _ggEncryptedAddress; private readonly HttpClient _httpClient; /// @@ -29,10 +27,6 @@ public class SonarRetriever : IAppRetriever /// public SonarRetriever() { - _ssRetriever = SteelSeriesRetriever.Instance; - _ssRetriever.WaitUntilSteelSeriesStarted(); - _ggEncryptedAddress = _ssRetriever.GetggEncryptedAddress(); - HttpClientHandler clientHandler = new HttpClientHandler(); clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; }; _httpClient = new(clientHandler); @@ -40,14 +34,14 @@ public SonarRetriever() public bool[] GetMetaDatas() { - if (!_ssRetriever.Running) + if (!SteelSeriesRetriever.Instance.Running) { throw new Exception("SteelSeries Sonar is not running."); } try { - JsonDocument subApps = JsonDocument.Parse(_httpClient.GetStringAsync("https://" + _ggEncryptedAddress + "/subApps").Result); + JsonDocument subApps = JsonDocument.Parse(_httpClient.GetStringAsync("https://" + SteelSeriesRetriever.Instance.GetggEncryptedAddress() + "/subApps").Result); JsonElement appElement = subApps.RootElement.GetProperty("subApps").GetProperty(Name); bool isEnabled = appElement.GetProperty("isEnabled").GetBoolean(); @@ -81,7 +75,7 @@ public string WebServerAddress() throw new Exception("SteelSeries Sonar not running"); } - JsonDocument subApps = JsonDocument.Parse(_httpClient.GetStringAsync("https://" + _ggEncryptedAddress + "/subApps").Result); + JsonDocument subApps = JsonDocument.Parse(_httpClient.GetStringAsync("https://" + SteelSeriesRetriever.Instance.GetggEncryptedAddress() + "/subApps").Result); JsonElement appElement = subApps.RootElement.GetProperty("subApps").GetProperty(Name); return appElement.GetProperty("metadata").GetProperty("webServerAddress") + "/"; @@ -92,6 +86,11 @@ public string WebServerAddress() ///
public void WaitUntilAppStarted() { + if (!SteelSeriesRetriever.Instance.Running) + { + SteelSeriesRetriever.Instance.WaitUntilSteelSeriesStarted(); + } + if (!IsEnabled || !IsReady || !IsRunning) { Console.WriteLine("Waiting for Sonar to start"); diff --git a/SteelSeriesAPI/SteelSeriesRetriever.cs b/SteelSeriesAPI/SteelSeriesRetriever.cs index 413d23f..fda64f9 100644 --- a/SteelSeriesAPI/SteelSeriesRetriever.cs +++ b/SteelSeriesAPI/SteelSeriesRetriever.cs @@ -10,16 +10,13 @@ public class SteelSeriesRetriever : ISteelSeriesRetriever public static SteelSeriesRetriever Instance => _instance.Value; - public bool Running => _steelSeriesProcesses.Length > 0; + public bool Running => SteelSeriesProcessesChecker(); - private readonly Thread _checkerThread; private Process[] _steelSeriesProcesses; public SteelSeriesRetriever() { _steelSeriesProcesses = Process.GetProcessesByName("SteelSeriesSonar"); - _checkerThread = new Thread(SteelSeriesProcessesCheckerThread) { IsBackground = true }; - _checkerThread.Start(); } public string GetggEncryptedAddress() @@ -54,12 +51,9 @@ public void WaitUntilSteelSeriesStarted() } } - private void SteelSeriesProcessesCheckerThread() + private bool SteelSeriesProcessesChecker() { - while (_checkerThread.IsAlive) - { - Thread.Sleep(100); - _steelSeriesProcesses = Process.GetProcessesByName("SteelSeriesSonar"); - } + _steelSeriesProcesses = Process.GetProcessesByName("SteelSeriesSonar"); + return _steelSeriesProcesses.Length > 0; } } \ No newline at end of file From 56694ae0a8ea03dabe78b14633f300effbbf3021 Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 21:03:48 +0200 Subject: [PATCH 12/47] Created HttpFetcher class instead of HttpPut and HttpProvider --- SteelSeriesAPI.Sample/Program.cs | 16 +++---- SteelSeriesAPI.Tests/Program.cs | 21 ++++----- SteelSeriesAPI/Sonar/Http/HttpFetcher.cs | 33 ++++++++++++++ SteelSeriesAPI/Sonar/Http/HttpProvider.cs | 43 ------------------- SteelSeriesAPI/Sonar/Http/HttpPut.cs | 43 ------------------- SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs | 16 +++---- .../Sonar/Http/SonarHttpProvider.cs | 12 +++--- .../Sonar/Managers/ConfigurationManager.cs | 6 +-- .../Sonar/Managers/PlaybackDeviceManager.cs | 26 +++++------ .../Sonar/Managers/VolumeSettingsManager.cs | 16 +++---- SteelSeriesAPI/Sonar/SonarBridge.cs | 6 +-- 11 files changed, 93 insertions(+), 145 deletions(-) create mode 100644 SteelSeriesAPI/Sonar/Http/HttpFetcher.cs delete mode 100644 SteelSeriesAPI/Sonar/Http/HttpProvider.cs delete mode 100644 SteelSeriesAPI/Sonar/Http/HttpPut.cs diff --git a/SteelSeriesAPI.Sample/Program.cs b/SteelSeriesAPI.Sample/Program.cs index 956e64c..377e5bd 100644 --- a/SteelSeriesAPI.Sample/Program.cs +++ b/SteelSeriesAPI.Sample/Program.cs @@ -18,14 +18,14 @@ static void Main(string[] args) // If I want to detect changes made on GG, I can use the listener (require admin rights) sonarManager.StartListener(); // Then I register the events I want (I've put them all to demonstrate) - sonarManager.Event.OnSonarModeChange += OnModeChangeHandler; // When the mode is change - sonarManager.Event.OnSonarVolumeChange += OnVolumeChangeHandler; // When the volume of a Sonar Channel or Mix is changed - sonarManager.Event.OnSonarMuteChange += OnMuteChangeHandler; // When a Sonar Channel or Mix is muted or unmuted - sonarManager.Event.OnSonarConfigChange += OnConfigChangeHandler; // When a new config is set to a Sonar Channel - sonarManager.Event.OnSonarChatMixChange += OnChatMixChangeHandler; // When the ChatMix value is changed - sonarManager.Event.OnSonarPlaybackDeviceChange += OnPlaybackDeviceChangeHandler; // When the Redirection Channel of a Sonar Channel is changed - sonarManager.Event.OnSonarRedirectionStateChange += OnRedirectionStateChangeHandler; // When the Redirection of a Sonar Mix is muted or unmuted - sonarManager.Event.OnSonarAudienceMonitoringChange += OnAudienceMonitoringChangeHandler; // When the Audience Monitoring is muted or unmuted + sonarManager.Events.OnSonarModeChange += OnModeChangeHandler; // When the mode is change + sonarManager.Events.OnSonarVolumeChange += OnVolumeChangeHandler; // When the volume of a Sonar Channel or Mix is changed + sonarManager.Events.OnSonarMuteChange += OnMuteChangeHandler; // When a Sonar Channel or Mix is muted or unmuted + sonarManager.Events.OnSonarConfigChange += OnConfigChangeHandler; // When a new config is set to a Sonar Channel + sonarManager.Events.OnSonarChatMixChange += OnChatMixChangeHandler; // When the ChatMix value is changed + sonarManager.Events.OnSonarPlaybackDeviceChange += OnPlaybackDeviceChangeHandler; // When the Redirection Channel of a Sonar Channel is changed + sonarManager.Events.OnSonarRedirectionStateChange += OnRedirectionStateChangeHandler; // When the Redirection of a Sonar Mix is muted or unmuted + sonarManager.Events.OnSonarAudienceMonitoringChange += OnAudienceMonitoringChangeHandler; // When the Audience Monitoring is muted or unmuted // Get current sonar mode Mode mode = sonarManager.GetMode(); diff --git a/SteelSeriesAPI.Tests/Program.cs b/SteelSeriesAPI.Tests/Program.cs index ff05fd6..a745607 100644 --- a/SteelSeriesAPI.Tests/Program.cs +++ b/SteelSeriesAPI.Tests/Program.cs @@ -10,22 +10,23 @@ class Program static void Main(string[] args) { SonarBridge sonarManager = new SonarBridge(); + sonarManager.WaitUntilSteelSeriesStarted(); sonarManager.WaitUntilSonarStarted(); Console.WriteLine(SonarRetriever.Instance.WebServerAddress()); - sonarManager.StartListener(); + // sonarManager.StartListener(); // Thread.Sleep(1000); // sonarManager.StopListener(); - - sonarManager.Event.OnSonarModeChange += OnModeChangeHandler; - sonarManager.Event.OnSonarVolumeChange += OnVolumeChangeHandler; - sonarManager.Event.OnSonarMuteChange += OnMuteChangeHandler; - sonarManager.Event.OnSonarConfigChange += OnConfigChangeHandler; - sonarManager.Event.OnSonarChatMixChange += OnChatMixChangeHandler; - sonarManager.Event.OnSonarPlaybackDeviceChange += OnPlaybackDeviceChangeHandler; - sonarManager.Event.OnSonarRedirectionStateChange += OnRedirectionStateChangeHandler; - sonarManager.Event.OnSonarAudienceMonitoringChange += OnAudienceMonitoringChangeHandler; + + // sonarManager.Events.OnSonarModeChange += OnModeChangeHandler; + // sonarManager.Events.OnSonarVolumeChange += OnVolumeChangeHandler; + // sonarManager.Events.OnSonarMuteChange += OnMuteChangeHandler; + // sonarManager.Events.OnSonarConfigChange += OnConfigChangeHandler; + // sonarManager.Events.OnSonarChatMixChange += OnChatMixChangeHandler; + // sonarManager.Events.OnSonarPlaybackDeviceChange += OnPlaybackDeviceChangeHandler; + // sonarManager.Events.OnSonarRedirectionStateChange += OnRedirectionStateChangeHandler; + // sonarManager.Events.OnSonarAudienceMonitoringChange += OnAudienceMonitoringChangeHandler; // new Program().GetTest(sonarManager); // new Program().SetTest(sonarManager); diff --git a/SteelSeriesAPI/Sonar/Http/HttpFetcher.cs b/SteelSeriesAPI/Sonar/Http/HttpFetcher.cs new file mode 100644 index 0000000..c399a60 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Http/HttpFetcher.cs @@ -0,0 +1,33 @@ +using System.Text.Json; +using SteelSeriesAPI.Interfaces; + +namespace SteelSeriesAPI.Sonar.Http; + +public class HttpFetcher +{ + private readonly HttpClient _httpClient; + private readonly IAppRetriever _sonarRetriever; + + public HttpFetcher() + { + _sonarRetriever = SonarRetriever.Instance; + + HttpClientHandler clientHandler = new HttpClientHandler(); + clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true; + _httpClient = new(clientHandler); + } + + public JsonDocument Provide(string targetHttp) + { + JsonDocument response = JsonDocument.Parse(_httpClient.GetStringAsync(_sonarRetriever.WebServerAddress() + targetHttp).Result); + return response; + } + + public void Put(string targetHttp) + { + HttpResponseMessage httpResponseMessage = _httpClient + .PutAsync(_sonarRetriever.WebServerAddress() + targetHttp, null) + .GetAwaiter().GetResult(); + httpResponseMessage.EnsureSuccessStatusCode(); + } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Http/HttpProvider.cs b/SteelSeriesAPI/Sonar/Http/HttpProvider.cs deleted file mode 100644 index 9f81858..0000000 --- a/SteelSeriesAPI/Sonar/Http/HttpProvider.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Text.Json; -using SteelSeriesAPI.Interfaces; - -namespace SteelSeriesAPI.Sonar.Http; - -public class HttpProvider -{ - private readonly HttpClient _httpClient; - private readonly IAppRetriever _sonarRetriever; - - private readonly string _targetHttp; - - public HttpProvider(string targetHttp) - { - _targetHttp = targetHttp; - _sonarRetriever = SonarRetriever.Instance; - - HttpClientHandler clientHandler = new HttpClientHandler(); - clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true; - _httpClient = new(clientHandler); - } - - public JsonDocument Provide() - { - if (_sonarRetriever is { IsEnabled: false, IsReady: false, IsRunning: false }) - { - Console.WriteLine("Sonar is not running."); - return null; - } - - try - { - JsonDocument response = JsonDocument.Parse(_httpClient.GetStringAsync(_sonarRetriever.WebServerAddress() + _targetHttp).Result); - return response; - } - catch (Exception e) - { - Console.WriteLine(e); - Console.WriteLine("Sonar may not be running."); - throw; - } - } -} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Http/HttpPut.cs b/SteelSeriesAPI/Sonar/Http/HttpPut.cs deleted file mode 100644 index e501824..0000000 --- a/SteelSeriesAPI/Sonar/Http/HttpPut.cs +++ /dev/null @@ -1,43 +0,0 @@ -using SteelSeriesAPI.Interfaces; - -namespace SteelSeriesAPI.Sonar.Http; - -public class HttpPut -{ - private readonly HttpClient _httpClient; - private readonly IAppRetriever _sonarRetriever; - - public HttpPut(string targetHttp) - { - _sonarRetriever = SonarRetriever.Instance; - - HttpClientHandler clientHandler = new HttpClientHandler(); - clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true; - _httpClient = new(clientHandler); - - Put(targetHttp); - } - - private void Put(string targetHttp) - { - if (_sonarRetriever is { IsEnabled: false, IsReady: false, IsRunning: false }) - { - Console.WriteLine("Sonar is not running."); - return; - } - - try - { - HttpResponseMessage httpResponseMessage = _httpClient - .PutAsync(_sonarRetriever.WebServerAddress() + targetHttp, null) - .GetAwaiter().GetResult(); - httpResponseMessage.EnsureSuccessStatusCode(); - } - catch (Exception e) - { - Console.WriteLine(e); - Console.WriteLine("Sonar may not be running."); - throw; - } - } -} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs index d51b368..cf84673 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs @@ -16,7 +16,7 @@ public SonarHttpCommand(SonarBridge sonarBridge) public void SetMode(Mode mode) { - new HttpPut("mode/" + mode.ToDictKey(ModeMapChoice.StreamDict)); + new HttpFetcher().Put("mode/" + mode.ToDictKey(ModeMapChoice.StreamDict)); Thread.Sleep(100); // Prevent bugs/freezes/crashes } @@ -32,18 +32,18 @@ public void SetChatMixBalance(double balance) throw new Exception("ChatMix balance can't be less than -1 and greater than 1"); } - new HttpPut("chatMix?balance=" + balance.ToString("0.00", CultureInfo.InvariantCulture)); + new HttpFetcher().Put("chatMix?balance=" + balance.ToString("0.00", CultureInfo.InvariantCulture)); } public void SetRedirectionState(bool newState, Channel channel, Mix mix) { - new HttpPut("streamRedirections/" + mix.ToDictKey() + "/redirections/" + channel.ToDictKey() + - "/isEnabled/" + newState); + new HttpFetcher().Put("streamRedirections/" + mix.ToDictKey() + "/redirections/" + channel.ToDictKey() + + "/isEnabled/" + newState); } public void SetAudienceMonitoringState(bool newState) { - new HttpPut("streamRedirections/isStreamMonitoringEnabled/" + newState); + new HttpFetcher().Put("streamRedirections/isStreamMonitoringEnabled/" + newState); } public void SetProcessToDeviceRouting(int pId, Channel channel) @@ -53,7 +53,7 @@ public void SetProcessToDeviceRouting(int pId, Channel channel) throw new Exception("Can't set process to master routing"); } - JsonDocument audioDeviceRouting = new HttpProvider("AudioDeviceRouting").Provide(); + JsonDocument audioDeviceRouting = new HttpFetcher().Provide("AudioDeviceRouting"); foreach (var element in audioDeviceRouting.RootElement.EnumerateArray()) { @@ -61,12 +61,12 @@ public void SetProcessToDeviceRouting(int pId, Channel channel) { if (channel == Channel.MIC) { - new HttpPut("AudioDeviceRouting/capture/" + element.GetProperty("deviceId").GetString() + "/" + pId); + new HttpFetcher().Put("AudioDeviceRouting/capture/" + element.GetProperty("deviceId").GetString() + "/" + pId); break; } else { - new HttpPut("AudioDeviceRouting/render/" + element.GetProperty("deviceId").GetString() + "/" + pId); + new HttpFetcher().Put("AudioDeviceRouting/render/" + element.GetProperty("deviceId").GetString() + "/" + pId); break; } } diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs index 2314f55..139df3b 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs @@ -10,7 +10,7 @@ public class SonarHttpProvider : ISonarDataProvider { public Mode GetMode() { - string mode = new HttpProvider("mode").Provide().RootElement.ToString(); + string mode = new HttpFetcher().Provide("mode").RootElement.ToString(); return (Mode)ModeExtensions.FromDictKey(mode, ModeMapChoice.StreamDict); } @@ -19,14 +19,14 @@ public Mode GetMode() public double GetChatMixBalance() { - JsonDocument chatMix = new HttpProvider("chatMix").Provide(); + JsonDocument chatMix = new HttpFetcher().Provide("chatMix"); return chatMix.RootElement.GetProperty("balance").GetDouble(); } public bool GetChatMixState() { - JsonDocument chatMix = new HttpProvider("chatMix").Provide(); + JsonDocument chatMix = new HttpFetcher().Provide("chatMix"); string cState = chatMix.RootElement.GetProperty("state").ToString(); if (cState == "enabled") { @@ -49,7 +49,7 @@ public bool GetRedirectionState(Channel channel, Mix mix) throw new Exception("Can't get redirection state for master"); } - JsonDocument streamRedirections = new HttpProvider("streamRedirections").Provide(); + JsonDocument streamRedirections = new HttpFetcher().Provide("streamRedirections"); JsonElement streamChannel = default; foreach (var element in streamRedirections.RootElement.EnumerateArray()) @@ -79,7 +79,7 @@ public bool GetRedirectionState(Channel channel, Mix mix) public bool GetAudienceMonitoringState() { - JsonDocument streamMonitoring = new HttpProvider("streamRedirections/isStreamMonitoringEnabled").Provide(); + JsonDocument streamMonitoring = new HttpFetcher().Provide("streamRedirections/isStreamMonitoringEnabled"); return streamMonitoring.RootElement.GetBoolean(); } @@ -91,7 +91,7 @@ public IEnumerable GetRoutedProcess(Channel channel) throw new Exception("Can't get routed process for Master"); } - JsonDocument audioDeviceRoutings = new HttpProvider("AudioDeviceRouting").Provide(); + JsonDocument audioDeviceRoutings = new HttpFetcher().Provide("AudioDeviceRouting"); foreach (var element in audioDeviceRoutings.RootElement.EnumerateArray()) { diff --git a/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs b/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs index 9a417fb..10e2146 100644 --- a/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs @@ -11,7 +11,7 @@ public class ConfigurationManager : IConfigurationManager { public IEnumerable GetAllAudioConfigurations() { - JsonDocument configs = new HttpProvider("configs").Provide(); + JsonDocument configs = new HttpFetcher().Provide("configs"); foreach (var element in configs.RootElement.EnumerateArray()) { @@ -68,7 +68,7 @@ public SonarAudioConfiguration GetSelectedAudioConfiguration(Channel channel) throw new Exception("Can't get audio configuration for master"); } - JsonDocument selectedConfigs = new HttpProvider("configs/selected").Provide(); + JsonDocument selectedConfigs = new HttpFetcher().Provide("configs/selected"); JsonElement sConfig = default; foreach (var config in selectedConfigs.RootElement.EnumerateArray()) @@ -91,7 +91,7 @@ public void SetConfig(string configId) { if (string.IsNullOrEmpty(configId)) throw new Exception("Couldn't retrieve config id"); - new HttpPut("configs/" + configId + "/select"); + new HttpFetcher().Put("configs/" + configId + "/select"); } public void SetConfig(SonarAudioConfiguration config) diff --git a/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs b/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs index a84cb90..ae65c40 100644 --- a/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs @@ -12,7 +12,7 @@ public class PlaybackDeviceManager : IPlaybackDeviceManager { public IEnumerable GetPlaybackDevices(DataFlow _dataFlow) { - JsonDocument audioDevices = new HttpProvider("audioDevices").Provide(); + JsonDocument audioDevices = new HttpFetcher().Provide("audioDevices"); // JsonDocument classicRedirections = new HttpProvider("classicRedirections").Provide(); // JsonDocument streamRedirections = new HttpProvider("streamRedirections").Provide(); @@ -42,7 +42,7 @@ public PlaybackDevice GetPlaybackDevice(string deviceId) { try { - JsonElement device = new HttpProvider("audioDevices/" + deviceId).Provide().RootElement; + JsonElement device = new HttpFetcher().Provide("audioDevices/" + deviceId).RootElement; string id = device.GetProperty("id").GetString(); string name = device.GetProperty("friendlyName").GetString(); @@ -68,7 +68,7 @@ public PlaybackDevice GetClassicPlaybackDevice(Channel channel) throw new Exception("Can't get redirection channel for master"); } - JsonDocument classicRedirections = new HttpProvider("classicRedirections").Provide(); + JsonDocument classicRedirections = new HttpFetcher().Provide("classicRedirections"); JsonElement cRedirections = default; foreach (var element in classicRedirections.RootElement.EnumerateArray()) @@ -86,7 +86,7 @@ public PlaybackDevice GetClassicPlaybackDevice(Channel channel) GetAssociatedChannels(deviceId, associatedClassicChannels, associatedStreamChannels); - JsonDocument audioDevice = new HttpProvider("audioDevices/" + deviceId).Provide(); + JsonDocument audioDevice = new HttpFetcher().Provide("audioDevices/" + deviceId); string name = audioDevice.RootElement.GetProperty("friendlyName").GetString(); DataFlow dataFlow = (DataFlow)DataFlowExtensions.FromDictKey(audioDevice.RootElement.GetProperty("dataFlow").GetString()); @@ -96,7 +96,7 @@ public PlaybackDevice GetClassicPlaybackDevice(Channel channel) public PlaybackDevice GetStreamerPlaybackDevice(Mix mix) { - JsonDocument streamRedirections = new HttpProvider("streamRedirections").Provide(); + JsonDocument streamRedirections = new HttpFetcher().Provide("streamRedirections"); JsonElement sRedirections = default; foreach (var element in streamRedirections.RootElement.EnumerateArray()) @@ -114,7 +114,7 @@ public PlaybackDevice GetStreamerPlaybackDevice(Mix mix) GetAssociatedChannels(deviceId, associatedClassicChannels, associatedStreamChannels); - JsonDocument audioDevice = new HttpProvider("audioDevices/" + deviceId).Provide(); + JsonDocument audioDevice = new HttpFetcher().Provide("audioDevices/" + deviceId); string name = audioDevice.RootElement.GetProperty("friendlyName").GetString(); DataFlow dataFlow = (DataFlow)DataFlowExtensions.FromDictKey(audioDevice.RootElement.GetProperty("dataFlow").GetString()); @@ -129,7 +129,7 @@ public PlaybackDevice GetStreamerPlaybackDevice(Channel channel = Channel.MIC) throw new Exception("Can only get stream redirection channel for Mic"); } - JsonDocument streamRedirections = new HttpProvider("streamRedirections").Provide(); + JsonDocument streamRedirections = new HttpFetcher().Provide("streamRedirections"); JsonElement sRedirections = default; foreach (var element in streamRedirections.RootElement.EnumerateArray()) @@ -147,7 +147,7 @@ public PlaybackDevice GetStreamerPlaybackDevice(Channel channel = Channel.MIC) GetAssociatedChannels(deviceId, associatedClassicChannels, associatedStreamChannels); - JsonDocument audioDevice = new HttpProvider("audioDevices/" + deviceId).Provide(); + JsonDocument audioDevice = new HttpFetcher().Provide("audioDevices/" + deviceId); string name = audioDevice.RootElement.GetProperty("friendlyName").GetString(); DataFlow dataFlow = (DataFlow)DataFlowExtensions.FromDictKey(audioDevice.RootElement.GetProperty("dataFlow").GetString()); @@ -157,8 +157,8 @@ public PlaybackDevice GetStreamerPlaybackDevice(Channel channel = Channel.MIC) private void GetAssociatedChannels(string deviceId, List associatedClassicDevices, ArrayList associatedStreamDevices) { - JsonDocument classicRedirections = new HttpProvider("classicRedirections").Provide(); - JsonDocument streamRedirections = new HttpProvider("streamRedirections").Provide(); + JsonDocument classicRedirections = new HttpFetcher().Provide("classicRedirections"); + JsonDocument streamRedirections = new HttpFetcher().Provide("streamRedirections"); foreach (var element in classicRedirections.RootElement.EnumerateArray()) { @@ -186,12 +186,12 @@ private void GetAssociatedChannels(string deviceId, List associatedClas public void SetClassicPlaybackDevice(string deviceId, Channel channel) { - new HttpPut("classicRedirections/" + channel.ToDictKey(ChannelMapChoice.ChannelDict) +"/deviceId/" + deviceId); + new HttpFetcher().Put("classicRedirections/" + channel.ToDictKey(ChannelMapChoice.ChannelDict) +"/deviceId/" + deviceId); } public void SetStreamerPlaybackDevice(string deviceId, Mix mix) { - new HttpPut("streamRedirections/" + mix.ToDictKey() +"/deviceId/" + deviceId); + new HttpFetcher().Put("streamRedirections/" + mix.ToDictKey() +"/deviceId/" + deviceId); } public void SetStreamerPlaybackDevice(string deviceId, Channel channel = Channel.MIC) @@ -201,7 +201,7 @@ public void SetStreamerPlaybackDevice(string deviceId, Channel channel = Channel throw new Exception("Can only change stream redirection channel for Mic"); } - new HttpPut("streamRedirections/" + channel.ToDictKey(ChannelMapChoice.ChannelDict) +"/deviceId/" + deviceId); + new HttpFetcher().Put("streamRedirections/" + channel.ToDictKey(ChannelMapChoice.ChannelDict) +"/deviceId/" + deviceId); } public void SetClassicPlaybackDevice(PlaybackDevice playbackDevice, Channel channel) diff --git a/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs b/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs index 52caedb..5c97803 100644 --- a/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs @@ -12,7 +12,7 @@ public class VolumeSettingsManager : IVolumeSettingsManager // volume = 0,00000000 <-- 8 decimal max public double GetVolume(Channel channel) { - JsonDocument volumeSettings = new HttpProvider("volumeSettings/classic/").Provide(); + JsonDocument volumeSettings = new HttpFetcher().Provide("volumeSettings/classic/"); if (channel == Channel.MASTER) return volumeSettings.RootElement.GetProperty("masters").GetProperty("classic").GetProperty("volume").GetDouble(); @@ -21,7 +21,7 @@ public double GetVolume(Channel channel) public double GetVolume(Channel channel, Mix mix) { - JsonDocument volumeSettings = new HttpProvider("volumeSettings/streamer/").Provide(); + JsonDocument volumeSettings = new HttpFetcher().Provide("volumeSettings/streamer/"); if (channel == Channel.MASTER) return volumeSettings.RootElement.GetProperty("masters").GetProperty("stream").GetProperty(mix.ToDictKey()).GetProperty("volume").GetDouble(); @@ -30,7 +30,7 @@ public double GetVolume(Channel channel, Mix mix) public bool GetMute(Channel channel) { - JsonDocument volumeSettings = new HttpProvider("volumeSettings/classic/").Provide(); + JsonDocument volumeSettings = new HttpFetcher().Provide("volumeSettings/classic/"); if (channel == Channel.MASTER) return volumeSettings.RootElement.GetProperty("masters").GetProperty("classic").GetProperty("muted").GetBoolean(); @@ -39,7 +39,7 @@ public bool GetMute(Channel channel) public bool GetMute(Channel channel, Mix mix) { - JsonDocument volumeSettings = new HttpProvider("volumeSettings/streamer/").Provide(); + JsonDocument volumeSettings = new HttpFetcher().Provide("volumeSettings/streamer/"); if (channel == Channel.MASTER) return volumeSettings.RootElement.GetProperty("masters").GetProperty("stream").GetProperty(mix.ToDictKey()).GetProperty("muted").GetBoolean(); @@ -49,22 +49,22 @@ public bool GetMute(Channel channel, Mix mix) public void SetVolume(double vol, Channel channel) { string _vol = vol.ToString("0.00", CultureInfo.InvariantCulture); - new HttpPut("volumeSettings/classic/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/Volume/" + _vol); + new HttpFetcher().Put("volumeSettings/classic/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/Volume/" + _vol); } public void SetVolume(double vol, Channel channel, Mix mix) { string _vol = vol.ToString("0.00", CultureInfo.InvariantCulture); - new HttpPut("volumeSettings/streamer/" + mix.ToDictKey() + "/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/volume/" + _vol); + new HttpFetcher().Put("volumeSettings/streamer/" + mix.ToDictKey() + "/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/volume/" + _vol); } public void SetMute(bool mute, Channel channel) { - new HttpPut("volumeSettings/classic/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/Mute/" + mute); + new HttpFetcher().Put("volumeSettings/classic/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/Mute/" + mute); } public void SetMute(bool mute, Channel channel, Mix mix) { - new HttpPut("volumeSettings/streamer/" + mix.ToDictKey() + "/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/isMuted/" + mute); + new HttpFetcher().Put("volumeSettings/streamer/" + mix.ToDictKey() + "/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/isMuted/" + mute); } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index e4e6c68..0a0441e 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -22,7 +22,7 @@ public class SonarBridge : ISonarBridge public readonly VolumeSettingsManager VolumeSettings; public readonly ConfigurationManager Configurations; public readonly PlaybackDeviceManager PlaybackDevices; - public readonly EventManager Event; + public readonly EventManager Events; public SonarBridge() { @@ -31,7 +31,7 @@ public SonarBridge() VolumeSettings = new VolumeSettingsManager(); Configurations = new ConfigurationManager(); PlaybackDevices = new PlaybackDeviceManager(); - Event = new EventManager(); + Events = new EventManager(); } #region Listener @@ -48,7 +48,7 @@ public bool StartListener() throw new Exception("Listener already started"); } - _sonarSocket = new SonarSocket(Event); + _sonarSocket = new SonarSocket(Events); var connected = _sonarSocket.Connect(); if (!connected) From 0984fa37f8ab42659a5b2fae573755da9d1a722e Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 21:58:20 +0200 Subject: [PATCH 13/47] Change of SteelSeries GG was detected as running --- SteelSeriesAPI/SteelSeriesRetriever.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SteelSeriesAPI/SteelSeriesRetriever.cs b/SteelSeriesAPI/SteelSeriesRetriever.cs index fda64f9..f1bef63 100644 --- a/SteelSeriesAPI/SteelSeriesRetriever.cs +++ b/SteelSeriesAPI/SteelSeriesRetriever.cs @@ -1,4 +1,4 @@ -using System.Diagnostics; +using System.Diagnostics; using System.Text.Json; using SteelSeriesAPI.Interfaces; @@ -16,7 +16,7 @@ public class SteelSeriesRetriever : ISteelSeriesRetriever public SteelSeriesRetriever() { - _steelSeriesProcesses = Process.GetProcessesByName("SteelSeriesSonar"); + _steelSeriesProcesses = Process.GetProcessesByName("SteelSeriesGG"); } public string GetggEncryptedAddress() @@ -53,7 +53,7 @@ public void WaitUntilSteelSeriesStarted() private bool SteelSeriesProcessesChecker() { - _steelSeriesProcesses = Process.GetProcessesByName("SteelSeriesSonar"); + _steelSeriesProcesses = Process.GetProcessesByName("SteelSeriesGG"); return _steelSeriesProcesses.Length > 0; } } \ No newline at end of file From ea91f7031a6a4576621661d1f04ddf10b397fc9d Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 22:00:43 +0200 Subject: [PATCH 14/47] Created NotRunning exceptions for Sonar and Steelseries --- .../SteelSeriesNotRunningException.cs | 8 ++++ .../Exceptions/SonarNotRunningException.cs | 8 ++++ SteelSeriesAPI/Sonar/Http/HttpFetcher.cs | 44 ++++++++++++++++--- SteelSeriesAPI/Sonar/SonarRetriever.cs | 6 ++- SteelSeriesAPI/SteelSeriesRetriever.cs | 5 ++- 5 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 SteelSeriesAPI/Exceptions/SteelSeriesNotRunningException.cs create mode 100644 SteelSeriesAPI/Sonar/Exceptions/SonarNotRunningException.cs diff --git a/SteelSeriesAPI/Exceptions/SteelSeriesNotRunningException.cs b/SteelSeriesAPI/Exceptions/SteelSeriesNotRunningException.cs new file mode 100644 index 0000000..a2de28a --- /dev/null +++ b/SteelSeriesAPI/Exceptions/SteelSeriesNotRunningException.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Exceptions; + +public class SteelSeriesNotRunningException : Exception +{ + public SteelSeriesNotRunningException() : base("SteelSeries is not running.") { } + public SteelSeriesNotRunningException(string message) : base(message) { } + public SteelSeriesNotRunningException(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/SonarNotRunningException.cs b/SteelSeriesAPI/Sonar/Exceptions/SonarNotRunningException.cs new file mode 100644 index 0000000..96b60e8 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/SonarNotRunningException.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class SonarNotRunningException : Exception +{ + public SonarNotRunningException() : base("Sonar is not running.") { } + public SonarNotRunningException(string message) : base(message) { } + public SonarNotRunningException(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Http/HttpFetcher.cs b/SteelSeriesAPI/Sonar/Http/HttpFetcher.cs index c399a60..b8de29e 100644 --- a/SteelSeriesAPI/Sonar/Http/HttpFetcher.cs +++ b/SteelSeriesAPI/Sonar/Http/HttpFetcher.cs @@ -1,6 +1,8 @@ -using System.Text.Json; +using SteelSeriesAPI.Sonar.Exceptions; using SteelSeriesAPI.Interfaces; +using System.Text.Json; + namespace SteelSeriesAPI.Sonar.Http; public class HttpFetcher @@ -19,15 +21,43 @@ public HttpFetcher() public JsonDocument Provide(string targetHttp) { - JsonDocument response = JsonDocument.Parse(_httpClient.GetStringAsync(_sonarRetriever.WebServerAddress() + targetHttp).Result); - return response; + if (_sonarRetriever is { IsEnabled: false, IsReady: false, IsRunning: false }) + { + throw new SonarNotRunningException(); + } + + try + { + JsonDocument response = JsonDocument.Parse(_httpClient.GetStringAsync(_sonarRetriever.WebServerAddress() + targetHttp).Result); + return response; + } + catch (Exception e) + { + Console.WriteLine(e); + Console.WriteLine("Sonar may not be running."); + throw; + } } public void Put(string targetHttp) { - HttpResponseMessage httpResponseMessage = _httpClient - .PutAsync(_sonarRetriever.WebServerAddress() + targetHttp, null) - .GetAwaiter().GetResult(); - httpResponseMessage.EnsureSuccessStatusCode(); + if (_sonarRetriever is { IsEnabled: false, IsReady: false, IsRunning: false }) + { + throw new SonarNotRunningException(); + } + + try + { + HttpResponseMessage httpResponseMessage = _httpClient + .PutAsync(_sonarRetriever.WebServerAddress() + targetHttp, null) + .GetAwaiter().GetResult(); + httpResponseMessage.EnsureSuccessStatusCode(); + } + catch (Exception e) + { + Console.WriteLine(e); + Console.WriteLine("Sonar may not be running."); + throw; + } } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/SonarRetriever.cs b/SteelSeriesAPI/Sonar/SonarRetriever.cs index 4f469df..14dd3a5 100644 --- a/SteelSeriesAPI/Sonar/SonarRetriever.cs +++ b/SteelSeriesAPI/Sonar/SonarRetriever.cs @@ -1,6 +1,8 @@ using System.Diagnostics; using System.Text.Json; +using SteelSeriesAPI.Exceptions; using SteelSeriesAPI.Interfaces; +using SteelSeriesAPI.Sonar.Exceptions; namespace SteelSeriesAPI.Sonar; @@ -36,7 +38,7 @@ public bool[] GetMetaDatas() { if (!SteelSeriesRetriever.Instance.Running) { - throw new Exception("SteelSeries Sonar is not running."); + throw new SteelSeriesNotRunningException(); } try @@ -72,7 +74,7 @@ public string WebServerAddress() { if (!IsEnabled || !IsReady || !IsRunning) { - throw new Exception("SteelSeries Sonar not running"); + throw new SonarNotRunningException(); } JsonDocument subApps = JsonDocument.Parse(_httpClient.GetStringAsync("https://" + SteelSeriesRetriever.Instance.GetggEncryptedAddress() + "/subApps").Result); diff --git a/SteelSeriesAPI/SteelSeriesRetriever.cs b/SteelSeriesAPI/SteelSeriesRetriever.cs index f1bef63..ccc98be 100644 --- a/SteelSeriesAPI/SteelSeriesRetriever.cs +++ b/SteelSeriesAPI/SteelSeriesRetriever.cs @@ -1,5 +1,6 @@ -using System.Diagnostics; +using System.Diagnostics; using System.Text.Json; +using SteelSeriesAPI.Exceptions; using SteelSeriesAPI.Interfaces; namespace SteelSeriesAPI; @@ -23,7 +24,7 @@ public string GetggEncryptedAddress() { if (!Running) { - throw new Exception("SteelSeries is not started"); + throw new SteelSeriesNotRunningException(); } try From 86d4846f1f18eb4c90b97d2e4535979e4a4342eb Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 22:07:00 +0200 Subject: [PATCH 15/47] Created SonarListenerNotConnected.cs and updated SonarSocket.cs --- .../Sonar/Exceptions/SonarListenerNotConnected.cs | 8 ++++++++ SteelSeriesAPI/Sonar/SonarSocket.cs | 10 ++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 SteelSeriesAPI/Sonar/Exceptions/SonarListenerNotConnected.cs diff --git a/SteelSeriesAPI/Sonar/Exceptions/SonarListenerNotConnected.cs b/SteelSeriesAPI/Sonar/Exceptions/SonarListenerNotConnected.cs new file mode 100644 index 0000000..cbce5b9 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/SonarListenerNotConnected.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class SonarListenerNotConnected : Exception +{ + public SonarListenerNotConnected() : base("Listener need to be connected before listening") { } + public SonarListenerNotConnected(string message) : base(message) { } + public SonarListenerNotConnected(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/SonarSocket.cs b/SteelSeriesAPI/Sonar/SonarSocket.cs index 8e5ea77..6bd5631 100644 --- a/SteelSeriesAPI/Sonar/SonarSocket.cs +++ b/SteelSeriesAPI/Sonar/SonarSocket.cs @@ -1,9 +1,11 @@ -using System.Net; -using System.Net.Sockets; -using System.Text; +using SteelSeriesAPI.Sonar.Exceptions; using SteelSeriesAPI.Sonar.Interfaces; using SteelSeriesAPI.Sonar.Managers; +using System.Net; +using System.Net.Sockets; +using System.Text; + namespace SteelSeriesAPI.Sonar; public class SonarSocket : ISonarSocket @@ -46,7 +48,7 @@ public bool Listen() { if (!IsConnected) { - throw new Exception("Listener need to be connected before listening"); + throw new SonarListenerNotConnected(); } _listenerThread.Start(); From 271b281b51e0b5905164bdaf17ef2fcf798fd92f Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 22:18:54 +0200 Subject: [PATCH 16/47] Added exceptions for master and mic channel and for audio configs --- SteelSeriesAPI/Sonar/Exceptions/ConfigNotFound.cs | 8 ++++++++ .../Sonar/Exceptions/MasterChannelNotSupported.cs | 8 ++++++++ SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnly.cs | 8 ++++++++ SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs | 3 ++- SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs | 5 +++-- SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs | 7 ++++--- SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs | 9 +++++---- 7 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 SteelSeriesAPI/Sonar/Exceptions/ConfigNotFound.cs create mode 100644 SteelSeriesAPI/Sonar/Exceptions/MasterChannelNotSupported.cs create mode 100644 SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnly.cs diff --git a/SteelSeriesAPI/Sonar/Exceptions/ConfigNotFound.cs b/SteelSeriesAPI/Sonar/Exceptions/ConfigNotFound.cs new file mode 100644 index 0000000..4632d17 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/ConfigNotFound.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class ConfigNotFound : Exception +{ + public ConfigNotFound() : base("No audio configuration found.") { } + public ConfigNotFound(string message) : base(message) { } + public ConfigNotFound(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/MasterChannelNotSupported.cs b/SteelSeriesAPI/Sonar/Exceptions/MasterChannelNotSupported.cs new file mode 100644 index 0000000..f16c9a8 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/MasterChannelNotSupported.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class MasterChannelNotSupported : Exception +{ + public MasterChannelNotSupported() : base("Master Channel is not supported in this case.") { } + public MasterChannelNotSupported(string message) : base(message) { } + public MasterChannelNotSupported(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnly.cs b/SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnly.cs new file mode 100644 index 0000000..32fdc11 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnly.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class MicChannelSupportOnly : Exception +{ + public MicChannelSupportOnly() : base("Only the Mic Channel is supported in this case.") { } + public MicChannelSupportOnly(string message) : base(message) { } + public MicChannelSupportOnly(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs index cf84673..6dad7c4 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs @@ -2,6 +2,7 @@ using System.Text.Json; using SteelSeriesAPI.Sonar.Interfaces; using SteelSeriesAPI.Sonar.Enums; +using SteelSeriesAPI.Sonar.Exceptions; namespace SteelSeriesAPI.Sonar.Http; @@ -50,7 +51,7 @@ public void SetProcessToDeviceRouting(int pId, Channel channel) { if (channel == Channel.MASTER) { - throw new Exception("Can't set process to master routing"); + throw new MasterChannelNotSupported(); } JsonDocument audioDeviceRouting = new HttpFetcher().Provide("AudioDeviceRouting"); diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs index 139df3b..e4ee8cf 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs @@ -2,6 +2,7 @@ using System.Text.Json; using SteelSeriesAPI.Sonar.Interfaces; using SteelSeriesAPI.Sonar.Enums; +using SteelSeriesAPI.Sonar.Exceptions; using SteelSeriesAPI.Sonar.Models; namespace SteelSeriesAPI.Sonar.Http; @@ -46,7 +47,7 @@ public bool GetRedirectionState(Channel channel, Mix mix) { if (channel == Channel.MASTER) { - throw new Exception("Can't get redirection state for master"); + throw new MasterChannelNotSupported(); } JsonDocument streamRedirections = new HttpFetcher().Provide("streamRedirections"); @@ -88,7 +89,7 @@ public IEnumerable GetRoutedProcess(Channel channel) { if (channel == Channel.MASTER) { - throw new Exception("Can't get routed process for Master"); + throw new MasterChannelNotSupported(); } JsonDocument audioDeviceRoutings = new HttpFetcher().Provide("AudioDeviceRouting"); diff --git a/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs b/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs index 10e2146..abf221c 100644 --- a/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs @@ -4,6 +4,7 @@ using SteelSeriesAPI.Sonar.Models; using System.Text.Json; +using SteelSeriesAPI.Sonar.Exceptions; namespace SteelSeriesAPI.Sonar.Managers; @@ -27,7 +28,7 @@ public IEnumerable GetAudioConfigurations(Channel chann { if (channel == Channel.MASTER) { - throw new Exception("Can't get audio configurations for master"); + throw new MasterChannelNotSupported(); } IEnumerable configs = GetAllAudioConfigurations(); @@ -65,7 +66,7 @@ public SonarAudioConfiguration GetSelectedAudioConfiguration(Channel channel) { if (channel == Channel.MASTER) { - throw new Exception("Can't get audio configuration for master"); + throw new MasterChannelNotSupported(); } JsonDocument selectedConfigs = new HttpFetcher().Provide("configs/selected"); @@ -89,7 +90,7 @@ public SonarAudioConfiguration GetSelectedAudioConfiguration(Channel channel) public void SetConfig(string configId) { - if (string.IsNullOrEmpty(configId)) throw new Exception("Couldn't retrieve config id"); + if (string.IsNullOrEmpty(configId)) throw new ConfigNotFound($"No audio configuration found with this id: {configId}"); new HttpFetcher().Put("configs/" + configId + "/select"); } diff --git a/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs b/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs index ae65c40..10cee6b 100644 --- a/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs @@ -5,6 +5,7 @@ using SteelSeriesAPI.Sonar.Models; using System.Text.Json; +using SteelSeriesAPI.Sonar.Exceptions; namespace SteelSeriesAPI.Sonar.Managers; @@ -57,7 +58,7 @@ public PlaybackDevice GetPlaybackDevice(string deviceId) catch (Exception e) { Console.WriteLine(e); - throw new Exception("Can't get any channel from this Id, maybe the channel doesn't exist or its Id changed."); + throw new Exception("Can't get any device from this Id, maybe the device doesn't exist or its Id changed."); } } @@ -65,7 +66,7 @@ public PlaybackDevice GetClassicPlaybackDevice(Channel channel) { if (channel == Channel.MASTER) { - throw new Exception("Can't get redirection channel for master"); + throw new MasterChannelNotSupported(); } JsonDocument classicRedirections = new HttpFetcher().Provide("classicRedirections"); @@ -126,7 +127,7 @@ public PlaybackDevice GetStreamerPlaybackDevice(Channel channel = Channel.MIC) { if (channel != Channel.MIC) { - throw new Exception("Can only get stream redirection channel for Mic"); + throw new MicChannelSupportOnly(); } JsonDocument streamRedirections = new HttpFetcher().Provide("streamRedirections"); @@ -198,7 +199,7 @@ public void SetStreamerPlaybackDevice(string deviceId, Channel channel = Channel { if (channel != Channel.MIC) { - throw new Exception("Can only change stream redirection channel for Mic"); + throw new MicChannelSupportOnly(); } new HttpFetcher().Put("streamRedirections/" + channel.ToDictKey(ChannelMapChoice.ChannelDict) +"/deviceId/" + deviceId); From 775d3c8f815c2fa19648b9d60d39845d14ab95e8 Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 22:46:32 +0200 Subject: [PATCH 17/47] Added ChatMix manager --- SteelSeriesAPI.Sample/Program.cs | 6 +-- SteelSeriesAPI.Tests/Program.cs | 6 +-- .../Exceptions/ChatMixBalanceException.cs | 8 ++++ .../Exceptions/ChatMixDisabledException.cs | 8 ++++ SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs | 15 +----- .../Sonar/Http/SonarHttpProvider.cs | 27 ----------- .../Sonar/Interfaces/ISonarCommandHandler.cs | 7 --- .../Sonar/Interfaces/ISonarDataProvider.cs | 12 ----- .../Interfaces/Managers/IChatMixManager.cs | 23 ++++++++++ .../Sonar/Managers/ChatMixManager.cs | 46 +++++++++++++++++++ SteelSeriesAPI/Sonar/SonarBridge.cs | 17 +------ 11 files changed, 94 insertions(+), 81 deletions(-) create mode 100644 SteelSeriesAPI/Sonar/Exceptions/ChatMixBalanceException.cs create mode 100644 SteelSeriesAPI/Sonar/Exceptions/ChatMixDisabledException.cs create mode 100644 SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs create mode 100644 SteelSeriesAPI/Sonar/Managers/ChatMixManager.cs diff --git a/SteelSeriesAPI.Sample/Program.cs b/SteelSeriesAPI.Sample/Program.cs index 377e5bd..005cbae 100644 --- a/SteelSeriesAPI.Sample/Program.cs +++ b/SteelSeriesAPI.Sample/Program.cs @@ -57,10 +57,10 @@ static void Main(string[] args) sonarManager.Configurations.SetConfig(currentConfig); // Or you can just directly give the config // Get ChatMix info - double chatMixBalance = sonarManager.GetChatMixBalance(); // The ChatMix value between -1 and 1 - bool chatMixState = sonarManager.GetChatMixState(); // If ChatMix is usable or not + double chatMixBalance = sonarManager.ChatMix.GetBalance(); // The ChatMix value between -1 and 1 + bool chatMixState = sonarManager.ChatMix.GetState(); // If ChatMix is usable or not // Change ChatMix value - sonarManager.SetChatMixBalance(0.5); // 0.5 is halfway to Chat + sonarManager.ChatMix.SetBalance(0.5); // 0.5 is halfway to Chat // Get playback devices (Windows devices) List inputDevices = sonarManager.PlaybackDevices.GetPlaybackDevices(DataFlow.INPUT).ToList(); // Input devices (Mics...) diff --git a/SteelSeriesAPI.Tests/Program.cs b/SteelSeriesAPI.Tests/Program.cs index a745607..d67f076 100644 --- a/SteelSeriesAPI.Tests/Program.cs +++ b/SteelSeriesAPI.Tests/Program.cs @@ -112,8 +112,8 @@ void GetTest(SonarBridge sonarManager) Console.WriteLine("----Channel from config ID----------"); Console.WriteLine(sonarManager.Configurations.GetAudioConfiguration("29ae2c02-792b-4487-863c-dc3e11a7a469").AssociatedChannel); Console.WriteLine("--------ChatMix---------"); - Console.WriteLine(sonarManager.GetChatMixBalance()); - Console.WriteLine(sonarManager.GetChatMixState()); + Console.WriteLine(sonarManager.ChatMix.GetBalance()); + Console.WriteLine(sonarManager.ChatMix.GetState()); Console.WriteLine("-----Redirection Devices-----------"); Console.WriteLine("---Output---"); @@ -223,7 +223,7 @@ void SetTest(SonarBridge sonarManager){ string configId = sonarManager.Configurations.GetAudioConfigurations(Channel.MEDIA).FirstOrDefault(config => config.Name == "Default")?.Id; sonarManager.Configurations.SetConfig(configId); sonarManager.Configurations.SetConfigByName(Channel.MEDIA, "Default"); - sonarManager.SetChatMixBalance(0.5); + sonarManager.ChatMix.SetBalance(0.5); var redirectionDevices = sonarManager.PlaybackDevices.GetPlaybackDevices(DataFlow.INPUT); redirectionDevices.GetEnumerator().MoveNext(); diff --git a/SteelSeriesAPI/Sonar/Exceptions/ChatMixBalanceException.cs b/SteelSeriesAPI/Sonar/Exceptions/ChatMixBalanceException.cs new file mode 100644 index 0000000..b00a8dc --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/ChatMixBalanceException.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class ChatMixBalanceException : Exception +{ + public ChatMixBalanceException() : base("ChatMix balance out of range.") { } + public ChatMixBalanceException(string message) : base(message) { } + public ChatMixBalanceException(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/ChatMixDisabledException.cs b/SteelSeriesAPI/Sonar/Exceptions/ChatMixDisabledException.cs new file mode 100644 index 0000000..be52eff --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/ChatMixDisabledException.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class ChatMixDisabledException : Exception +{ + public ChatMixDisabledException() : base("ChatMix is not enabled.") { } + public ChatMixDisabledException(string message) : base(message) { } + public ChatMixDisabledException(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs index 6dad7c4..683ae8c 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs @@ -21,20 +21,7 @@ public void SetMode(Mode mode) Thread.Sleep(100); // Prevent bugs/freezes/crashes } - public void SetChatMixBalance(double balance) - { - if (!_sonarBridge.GetChatMixState()) - { - throw new Exception("Can't change the value of the balance of the ChatMix when it is not enabled"); - } - - if (balance > 1 || balance < -1) - { - throw new Exception("ChatMix balance can't be less than -1 and greater than 1"); - } - - new HttpFetcher().Put("chatMix?balance=" + balance.ToString("0.00", CultureInfo.InvariantCulture)); - } + public void SetRedirectionState(bool newState, Channel channel, Mix mix) { diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs index e4ee8cf..8a602e5 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs @@ -16,33 +16,6 @@ public Mode GetMode() return (Mode)ModeExtensions.FromDictKey(mode, ModeMapChoice.StreamDict); } - #region ChatMix - - public double GetChatMixBalance() - { - JsonDocument chatMix = new HttpFetcher().Provide("chatMix"); - - return chatMix.RootElement.GetProperty("balance").GetDouble(); - } - - public bool GetChatMixState() - { - JsonDocument chatMix = new HttpFetcher().Provide("chatMix"); - string cState = chatMix.RootElement.GetProperty("state").ToString(); - if (cState == "enabled") - { - return true; - } - else if (cState == "differentDeviceSelected") - { - return false; - } - - return false; - } - - #endregion - public bool GetRedirectionState(Channel channel, Mix mix) { if (channel == Channel.MASTER) diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs index 69f47c9..775efe7 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs @@ -9,13 +9,6 @@ public interface ISonarCommandHandler ///
/// The you want to set void SetMode(Mode mode); - - /// - /// Set the balance of the ChatMix - /// - /// -1 to balance to Game channel
1 to balance to Chat channel
- /// A between -1 and 1 - void SetChatMixBalance(double balance); /// /// Enable or disable the Redirection of the chosen Sonar of the chosen Sonar diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs index 01d296e..edce5d6 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs @@ -11,18 +11,6 @@ public interface ISonarDataProvider /// A , either Classic or Streamer Mode GetMode(); - /// - /// Get the actual ChatMix balance value - /// - /// A double between -1 and 1 - double GetChatMixBalance(); - - /// - /// Get the actual state of the ChatMix - /// - /// True if ChatMix is enabled
False if ChatMix is disabled
- bool GetChatMixState(); - /// /// Get the mute state of the Redirection of the chosen Sonar of the chosen Sonar /// diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs new file mode 100644 index 0000000..6e3dc1f --- /dev/null +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs @@ -0,0 +1,23 @@ +namespace SteelSeriesAPI.Sonar.Interfaces.Managers; + +public interface IChatMixManager +{ + /// + /// Get the actual ChatMix balance value + /// + /// A double between -1 and 1 + double GetBalance(); + + /// + /// Get the actual state of the ChatMix + /// + /// True if ChatMix is enabled
False if ChatMix is disabled
+ bool GetState(); + + /// + /// Set the balance of the ChatMix + /// + /// -1 to balance to Game channel
1 to balance to Chat channel
+ /// A between -1 and 1 + void SetBalance(double balance); +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/ChatMixManager.cs b/SteelSeriesAPI/Sonar/Managers/ChatMixManager.cs new file mode 100644 index 0000000..f288615 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Managers/ChatMixManager.cs @@ -0,0 +1,46 @@ +using SteelSeriesAPI.Sonar.Exceptions; +using SteelSeriesAPI.Sonar.Interfaces.Managers; +using SteelSeriesAPI.Sonar.Http; + +using System.Text.Json; +using System.Globalization; + +namespace SteelSeriesAPI.Sonar.Managers; + +public class ChatMixManager : IChatMixManager +{ + public double GetBalance() + { + JsonDocument chatMix = new HttpFetcher().Provide("chatMix"); + + return chatMix.RootElement.GetProperty("balance").GetDouble(); + } + + public bool GetState() + { + JsonDocument chatMix = new HttpFetcher().Provide("chatMix"); + string cState = chatMix.RootElement.GetProperty("state").ToString(); + + if (cState == "enabled") + { + return true; + } + + return false; + } + + public void SetBalance(double balance) + { + if (!GetState()) + { + throw new ChatMixDisabledException(); + } + + if (balance > 1 || balance < -1) + { + throw new ChatMixBalanceException(); + } + + new HttpFetcher().Put("chatMix?balance=" + balance.ToString("0.00", CultureInfo.InvariantCulture)); + } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index 0a0441e..8e05db0 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -20,6 +20,7 @@ public class SonarBridge : ISonarBridge private ISonarSocket _sonarSocket; public readonly VolumeSettingsManager VolumeSettings; + public readonly ChatMixManager ChatMix; public readonly ConfigurationManager Configurations; public readonly PlaybackDeviceManager PlaybackDevices; public readonly EventManager Events; @@ -29,6 +30,7 @@ public SonarBridge() _sonarCommand = new SonarHttpCommand(this); _sonarProvider = new SonarHttpProvider(); VolumeSettings = new VolumeSettingsManager(); + ChatMix = new ChatMixManager(); Configurations = new ConfigurationManager(); PlaybackDevices = new PlaybackDeviceManager(); Events = new EventManager(); @@ -102,16 +104,6 @@ public Mode GetMode() { return _sonarProvider.GetMode(); } - - public double GetChatMixBalance() - { - return _sonarProvider.GetChatMixBalance(); - } - - public bool GetChatMixState() - { - return _sonarProvider.GetChatMixState(); - } public bool GetRedirectionState(Channel channel, Mix mix) { @@ -136,11 +128,6 @@ public void SetMode(Mode mode) { _sonarCommand.SetMode(mode); } - - public void SetChatMixBalance(double balance) - { - _sonarCommand.SetChatMixBalance(balance); - } public void SetRedirectionState(bool newState, Channel channel, Mix mix) { From c03092479d5c8780fa3424224620bc2cb23f6a6a Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 22:48:24 +0200 Subject: [PATCH 18/47] Forgot "Exception" at the end of the exceptions name --- SteelSeriesAPI/Sonar/Exceptions/ConfigNotFound.cs | 8 -------- .../Sonar/Exceptions/ConfigNotFoundException.cs | 8 ++++++++ .../Sonar/Exceptions/MasterChannelNotSupported.cs | 8 -------- .../Exceptions/MasterChannelNotSupportedException.cs | 8 ++++++++ SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnly.cs | 8 -------- .../Sonar/Exceptions/MicChannelSupportOnlyException.cs | 8 ++++++++ .../Sonar/Exceptions/SonarListenerNotConnected.cs | 8 -------- .../Exceptions/SonarListenerNotConnectedException.cs | 8 ++++++++ SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs | 2 +- SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs | 4 ++-- SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs | 6 +++--- SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs | 6 +++--- SteelSeriesAPI/Sonar/SonarSocket.cs | 2 +- 13 files changed, 42 insertions(+), 42 deletions(-) delete mode 100644 SteelSeriesAPI/Sonar/Exceptions/ConfigNotFound.cs create mode 100644 SteelSeriesAPI/Sonar/Exceptions/ConfigNotFoundException.cs delete mode 100644 SteelSeriesAPI/Sonar/Exceptions/MasterChannelNotSupported.cs create mode 100644 SteelSeriesAPI/Sonar/Exceptions/MasterChannelNotSupportedException.cs delete mode 100644 SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnly.cs create mode 100644 SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnlyException.cs delete mode 100644 SteelSeriesAPI/Sonar/Exceptions/SonarListenerNotConnected.cs create mode 100644 SteelSeriesAPI/Sonar/Exceptions/SonarListenerNotConnectedException.cs diff --git a/SteelSeriesAPI/Sonar/Exceptions/ConfigNotFound.cs b/SteelSeriesAPI/Sonar/Exceptions/ConfigNotFound.cs deleted file mode 100644 index 4632d17..0000000 --- a/SteelSeriesAPI/Sonar/Exceptions/ConfigNotFound.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace SteelSeriesAPI.Sonar.Exceptions; - -public class ConfigNotFound : Exception -{ - public ConfigNotFound() : base("No audio configuration found.") { } - public ConfigNotFound(string message) : base(message) { } - public ConfigNotFound(string message, Exception innerException) : base(message, innerException) { } -} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/ConfigNotFoundException.cs b/SteelSeriesAPI/Sonar/Exceptions/ConfigNotFoundException.cs new file mode 100644 index 0000000..1084652 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/ConfigNotFoundException.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class ConfigNotFoundException : Exception +{ + public ConfigNotFoundException() : base("No audio configuration found.") { } + public ConfigNotFoundException(string message) : base(message) { } + public ConfigNotFoundException(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/MasterChannelNotSupported.cs b/SteelSeriesAPI/Sonar/Exceptions/MasterChannelNotSupported.cs deleted file mode 100644 index f16c9a8..0000000 --- a/SteelSeriesAPI/Sonar/Exceptions/MasterChannelNotSupported.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace SteelSeriesAPI.Sonar.Exceptions; - -public class MasterChannelNotSupported : Exception -{ - public MasterChannelNotSupported() : base("Master Channel is not supported in this case.") { } - public MasterChannelNotSupported(string message) : base(message) { } - public MasterChannelNotSupported(string message, Exception innerException) : base(message, innerException) { } -} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/MasterChannelNotSupportedException.cs b/SteelSeriesAPI/Sonar/Exceptions/MasterChannelNotSupportedException.cs new file mode 100644 index 0000000..91b8755 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/MasterChannelNotSupportedException.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class MasterChannelNotSupportedException : Exception +{ + public MasterChannelNotSupportedException() : base("Master Channel is not supported in this case.") { } + public MasterChannelNotSupportedException(string message) : base(message) { } + public MasterChannelNotSupportedException(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnly.cs b/SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnly.cs deleted file mode 100644 index 32fdc11..0000000 --- a/SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnly.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace SteelSeriesAPI.Sonar.Exceptions; - -public class MicChannelSupportOnly : Exception -{ - public MicChannelSupportOnly() : base("Only the Mic Channel is supported in this case.") { } - public MicChannelSupportOnly(string message) : base(message) { } - public MicChannelSupportOnly(string message, Exception innerException) : base(message, innerException) { } -} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnlyException.cs b/SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnlyException.cs new file mode 100644 index 0000000..ab83946 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnlyException.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class MicChannelSupportOnlyException : Exception +{ + public MicChannelSupportOnlyException() : base("Only the Mic Channel is supported in this case.") { } + public MicChannelSupportOnlyException(string message) : base(message) { } + public MicChannelSupportOnlyException(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/SonarListenerNotConnected.cs b/SteelSeriesAPI/Sonar/Exceptions/SonarListenerNotConnected.cs deleted file mode 100644 index cbce5b9..0000000 --- a/SteelSeriesAPI/Sonar/Exceptions/SonarListenerNotConnected.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace SteelSeriesAPI.Sonar.Exceptions; - -public class SonarListenerNotConnected : Exception -{ - public SonarListenerNotConnected() : base("Listener need to be connected before listening") { } - public SonarListenerNotConnected(string message) : base(message) { } - public SonarListenerNotConnected(string message, Exception innerException) : base(message, innerException) { } -} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/SonarListenerNotConnectedException.cs b/SteelSeriesAPI/Sonar/Exceptions/SonarListenerNotConnectedException.cs new file mode 100644 index 0000000..03294b7 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/SonarListenerNotConnectedException.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class SonarListenerNotConnectedException : Exception +{ + public SonarListenerNotConnectedException() : base("Listener need to be connected before listening") { } + public SonarListenerNotConnectedException(string message) : base(message) { } + public SonarListenerNotConnectedException(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs index 683ae8c..bd92157 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs @@ -38,7 +38,7 @@ public void SetProcessToDeviceRouting(int pId, Channel channel) { if (channel == Channel.MASTER) { - throw new MasterChannelNotSupported(); + throw new MasterChannelNotSupportedException(); } JsonDocument audioDeviceRouting = new HttpFetcher().Provide("AudioDeviceRouting"); diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs index 8a602e5..c754e7c 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs @@ -20,7 +20,7 @@ public bool GetRedirectionState(Channel channel, Mix mix) { if (channel == Channel.MASTER) { - throw new MasterChannelNotSupported(); + throw new MasterChannelNotSupportedException(); } JsonDocument streamRedirections = new HttpFetcher().Provide("streamRedirections"); @@ -62,7 +62,7 @@ public IEnumerable GetRoutedProcess(Channel channel) { if (channel == Channel.MASTER) { - throw new MasterChannelNotSupported(); + throw new MasterChannelNotSupportedException(); } JsonDocument audioDeviceRoutings = new HttpFetcher().Provide("AudioDeviceRouting"); diff --git a/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs b/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs index abf221c..b78df4e 100644 --- a/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs @@ -28,7 +28,7 @@ public IEnumerable GetAudioConfigurations(Channel chann { if (channel == Channel.MASTER) { - throw new MasterChannelNotSupported(); + throw new MasterChannelNotSupportedException(); } IEnumerable configs = GetAllAudioConfigurations(); @@ -66,7 +66,7 @@ public SonarAudioConfiguration GetSelectedAudioConfiguration(Channel channel) { if (channel == Channel.MASTER) { - throw new MasterChannelNotSupported(); + throw new MasterChannelNotSupportedException(); } JsonDocument selectedConfigs = new HttpFetcher().Provide("configs/selected"); @@ -90,7 +90,7 @@ public SonarAudioConfiguration GetSelectedAudioConfiguration(Channel channel) public void SetConfig(string configId) { - if (string.IsNullOrEmpty(configId)) throw new ConfigNotFound($"No audio configuration found with this id: {configId}"); + if (string.IsNullOrEmpty(configId)) throw new ConfigNotFoundException($"No audio configuration found with this id: {configId}"); new HttpFetcher().Put("configs/" + configId + "/select"); } diff --git a/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs b/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs index 10cee6b..2607dcd 100644 --- a/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs @@ -66,7 +66,7 @@ public PlaybackDevice GetClassicPlaybackDevice(Channel channel) { if (channel == Channel.MASTER) { - throw new MasterChannelNotSupported(); + throw new MasterChannelNotSupportedException(); } JsonDocument classicRedirections = new HttpFetcher().Provide("classicRedirections"); @@ -127,7 +127,7 @@ public PlaybackDevice GetStreamerPlaybackDevice(Channel channel = Channel.MIC) { if (channel != Channel.MIC) { - throw new MicChannelSupportOnly(); + throw new MicChannelSupportOnlyException(); } JsonDocument streamRedirections = new HttpFetcher().Provide("streamRedirections"); @@ -199,7 +199,7 @@ public void SetStreamerPlaybackDevice(string deviceId, Channel channel = Channel { if (channel != Channel.MIC) { - throw new MicChannelSupportOnly(); + throw new MicChannelSupportOnlyException(); } new HttpFetcher().Put("streamRedirections/" + channel.ToDictKey(ChannelMapChoice.ChannelDict) +"/deviceId/" + deviceId); diff --git a/SteelSeriesAPI/Sonar/SonarSocket.cs b/SteelSeriesAPI/Sonar/SonarSocket.cs index 6bd5631..4d28201 100644 --- a/SteelSeriesAPI/Sonar/SonarSocket.cs +++ b/SteelSeriesAPI/Sonar/SonarSocket.cs @@ -48,7 +48,7 @@ public bool Listen() { if (!IsConnected) { - throw new SonarListenerNotConnected(); + throw new SonarListenerNotConnectedException(); } _listenerThread.Start(); From 9e16e258a2664d6adf70d2f38881e52ac09a58d1 Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 22:57:33 +0200 Subject: [PATCH 19/47] Added Manager for routed processes --- SteelSeriesAPI.Tests/Program.cs | 4 +- SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs | 27 ------- .../Sonar/Http/SonarHttpProvider.cs | 36 --------- .../Sonar/Interfaces/ISonarCommandHandler.cs | 7 -- .../Sonar/Interfaces/ISonarDataProvider.cs | 7 -- .../Managers/IRoutedProcessManager.cs | 21 ++++++ .../Sonar/Managers/RoutedProcessManager.cs | 75 +++++++++++++++++++ SteelSeriesAPI/Sonar/SonarBridge.cs | 12 +-- 8 files changed, 100 insertions(+), 89 deletions(-) create mode 100644 SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs create mode 100644 SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs diff --git a/SteelSeriesAPI.Tests/Program.cs b/SteelSeriesAPI.Tests/Program.cs index d67f076..85b529d 100644 --- a/SteelSeriesAPI.Tests/Program.cs +++ b/SteelSeriesAPI.Tests/Program.cs @@ -207,7 +207,7 @@ void GetTest(SonarBridge sonarManager) } Console.WriteLine("-- " + device); - foreach (var routed in sonarManager.GetRoutedProcess(device)) + foreach (var routed in sonarManager.RoutedProcesses.GetRoutedProcesses(device)) { Console.WriteLine(routed.Id + ", " + routed.ProcessName + ", " + routed.PId + ", " + routed.State + ", " + routed.DisplayName); @@ -232,7 +232,7 @@ void SetTest(SonarBridge sonarManager){ sonarManager.SetRedirectionState(true, Channel.MEDIA, Mix.STREAM); sonarManager.SetAudienceMonitoringState(false); - sonarManager.SetProcessToDeviceRouting(19152, Channel.MIC); + sonarManager.RoutedProcesses.RouteProcessToChannel(19152, Channel.MIC); } static void OnModeChangeHandler(object? sender, SonarModeEvent eventArgs) diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs index bd92157..9c07a0a 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs @@ -33,31 +33,4 @@ public void SetAudienceMonitoringState(bool newState) { new HttpFetcher().Put("streamRedirections/isStreamMonitoringEnabled/" + newState); } - - public void SetProcessToDeviceRouting(int pId, Channel channel) - { - if (channel == Channel.MASTER) - { - throw new MasterChannelNotSupportedException(); - } - - JsonDocument audioDeviceRouting = new HttpFetcher().Provide("AudioDeviceRouting"); - - foreach (var element in audioDeviceRouting.RootElement.EnumerateArray()) - { - if (element.GetProperty("role").GetString() == channel.ToDictKey()) - { - if (channel == Channel.MIC) - { - new HttpFetcher().Put("AudioDeviceRouting/capture/" + element.GetProperty("deviceId").GetString() + "/" + pId); - break; - } - else - { - new HttpFetcher().Put("AudioDeviceRouting/render/" + element.GetProperty("deviceId").GetString() + "/" + pId); - break; - } - } - } - } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs index c754e7c..431a4da 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs @@ -57,40 +57,4 @@ public bool GetAudienceMonitoringState() return streamMonitoring.RootElement.GetBoolean(); } - - public IEnumerable GetRoutedProcess(Channel channel) - { - if (channel == Channel.MASTER) - { - throw new MasterChannelNotSupportedException(); - } - - JsonDocument audioDeviceRoutings = new HttpFetcher().Provide("AudioDeviceRouting"); - - foreach (var element in audioDeviceRoutings.RootElement.EnumerateArray()) - { - if (element.GetProperty("role").GetString() != channel.ToDictKey()) - { - continue; - } - - var audioSessions = element.GetProperty("audioSessions"); - - foreach (var session in audioSessions.EnumerateArray()) - { - string id = session.GetProperty("id").GetString().Split("|")[0]; - string processName = session.GetProperty("processName").GetString(); - int pId = session.GetProperty("processId").GetInt32(); - RoutedProcessState state = (RoutedProcessState)RoutedProcessStateExtensions.FromDictKey(session.GetProperty("state").GetString()); - string displayName = session.GetProperty("displayName").GetString(); - - if (processName == "Idle" && displayName == "Idle" && state == RoutedProcessState.INACTIVE && pId == 0) - { - continue; - } - - yield return new RoutedProcess(id, processName, pId, state, displayName); - } - } - } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs index 775efe7..0313b87 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs @@ -23,11 +23,4 @@ public interface ISonarCommandHandler ///
/// The new state, un/muted void SetAudienceMonitoringState(bool newState); - - /// - /// Redirect the audio of an app to a Sonar - /// - /// The process ID of the app - /// The Sonar you want to set the app audio - void SetProcessToDeviceRouting(int pId, Channel channel); } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs index edce5d6..f7297bf 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs @@ -24,11 +24,4 @@ public interface ISonarDataProvider ///
/// The current state, un/muted bool GetAudienceMonitoringState(); - - /// - /// Get the apps which their audio is redirected to a Sonar - /// - /// The Sonar you want the associated processes - /// A list of - IEnumerable GetRoutedProcess(Channel channel); } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs new file mode 100644 index 0000000..03dd22d --- /dev/null +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs @@ -0,0 +1,21 @@ +using SteelSeriesAPI.Sonar.Enums; +using SteelSeriesAPI.Sonar.Models; + +namespace SteelSeriesAPI.Sonar.Interfaces.Managers; + +public interface IRoutedProcessManager +{ + /// + /// Get the apps which their audio is redirected to a Sonar + /// + /// The Sonar you want the associated processes + /// A list of + IEnumerable GetRoutedProcesses(Channel channel); + + /// + /// Redirect the audio of an app to a Sonar + /// + /// The process ID of the app + /// The Sonar you want to set the app audio + void RouteProcessToChannel(int pId, Channel channel); +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs b/SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs new file mode 100644 index 0000000..52d253d --- /dev/null +++ b/SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs @@ -0,0 +1,75 @@ +using SteelSeriesAPI.Sonar.Exceptions; +using SteelSeriesAPI.Sonar.Enums; +using SteelSeriesAPI.Sonar.Http; +using SteelSeriesAPI.Sonar.Models; +using SteelSeriesAPI.Sonar.Interfaces.Managers; + +using System.Text.Json; + +namespace SteelSeriesAPI.Sonar.Managers; + +public class RoutedProcessManager : IRoutedProcessManager +{ + public IEnumerable GetRoutedProcesses(Channel channel) + { + if (channel == Channel.MASTER) + { + throw new MasterChannelNotSupportedException(); + } + + JsonDocument audioDeviceRoutings = new HttpFetcher().Provide("AudioDeviceRouting"); + + foreach (var element in audioDeviceRoutings.RootElement.EnumerateArray()) + { + if (element.GetProperty("role").GetString() != channel.ToDictKey()) + { + continue; + } + + var audioSessions = element.GetProperty("audioSessions"); + + foreach (var session in audioSessions.EnumerateArray()) + { + string id = session.GetProperty("id").GetString().Split("|")[0]; + string processName = session.GetProperty("processName").GetString(); + int pId = session.GetProperty("processId").GetInt32(); + RoutedProcessState state = (RoutedProcessState)RoutedProcessStateExtensions.FromDictKey(session.GetProperty("state").GetString()); + string displayName = session.GetProperty("displayName").GetString(); + + if (processName == "Idle" && displayName == "Idle" && state == RoutedProcessState.INACTIVE && pId == 0) + { + continue; + } + + yield return new RoutedProcess(id, processName, pId, state, displayName); + } + } + } + + public void RouteProcessToChannel(int pId, Channel channel) + { + if (channel == Channel.MASTER) + { + throw new MasterChannelNotSupportedException(); + } + + JsonDocument audioDeviceRouting = new HttpFetcher().Provide("AudioDeviceRouting"); + + foreach (var element in audioDeviceRouting.RootElement.EnumerateArray()) + { + if (element.GetProperty("role").GetString() == channel.ToDictKey()) + { + if (channel == Channel.MIC) + { + new HttpFetcher().Put("AudioDeviceRouting/capture/" + element.GetProperty("deviceId").GetString() + "/" + pId); + break; + } + else + { + new HttpFetcher().Put("AudioDeviceRouting/render/" + element.GetProperty("deviceId").GetString() + "/" + pId); + break; + } + } + } + } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index 8e05db0..0b40f13 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -23,6 +23,7 @@ public class SonarBridge : ISonarBridge public readonly ChatMixManager ChatMix; public readonly ConfigurationManager Configurations; public readonly PlaybackDeviceManager PlaybackDevices; + public readonly RoutedProcessManager RoutedProcesses; public readonly EventManager Events; public SonarBridge() @@ -33,6 +34,7 @@ public SonarBridge() ChatMix = new ChatMixManager(); Configurations = new ConfigurationManager(); PlaybackDevices = new PlaybackDeviceManager(); + RoutedProcesses = new RoutedProcessManager(); Events = new EventManager(); } @@ -115,11 +117,6 @@ public bool GetAudienceMonitoringState() return _sonarProvider.GetAudienceMonitoringState(); } - public IEnumerable GetRoutedProcess(Channel channel) - { - return _sonarProvider.GetRoutedProcess(channel); - } - #endregion #region Commands @@ -139,10 +136,5 @@ public void SetAudienceMonitoringState(bool newState) _sonarCommand.SetAudienceMonitoringState(newState); } - public void SetProcessToDeviceRouting(int pId, Channel channel) - { - _sonarCommand.SetProcessToDeviceRouting(pId, channel); - } - #endregion } \ No newline at end of file From d17c926e3a1a54497ae7d8852f4bcae2140b7e4c Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 23:01:31 +0200 Subject: [PATCH 20/47] Made the managers interfaces internal --- SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs | 2 +- .../Sonar/Interfaces/Managers/IConfigurationManager.cs | 2 +- .../Sonar/Interfaces/Managers/IPlaybackDeviceManager.cs | 2 +- .../Sonar/Interfaces/Managers/IRoutedProcessManager.cs | 2 +- SteelSeriesAPI/Sonar/SonarBridge.cs | 2 -- 5 files changed, 4 insertions(+), 6 deletions(-) diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs index 6e3dc1f..da719c8 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs @@ -1,6 +1,6 @@ namespace SteelSeriesAPI.Sonar.Interfaces.Managers; -public interface IChatMixManager +internal interface IChatMixManager { /// /// Get the actual ChatMix balance value diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IConfigurationManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IConfigurationManager.cs index 1db642a..204698a 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/Managers/IConfigurationManager.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IConfigurationManager.cs @@ -3,7 +3,7 @@ namespace SteelSeriesAPI.Sonar.Interfaces.Managers; -public interface IConfigurationManager +internal interface IConfigurationManager { /// diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IPlaybackDeviceManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IPlaybackDeviceManager.cs index 1fc84e2..af31262 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/Managers/IPlaybackDeviceManager.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IPlaybackDeviceManager.cs @@ -3,7 +3,7 @@ namespace SteelSeriesAPI.Sonar.Interfaces.Managers; -public interface IPlaybackDeviceManager +internal interface IPlaybackDeviceManager { /// /// Get all the in/output Redirection Devices (Windows devices) diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs index 03dd22d..e744cc7 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs @@ -3,7 +3,7 @@ namespace SteelSeriesAPI.Sonar.Interfaces.Managers; -public interface IRoutedProcessManager +internal interface IRoutedProcessManager { /// /// Get the apps which their audio is redirected to a Sonar diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index 0b40f13..5c9d58b 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -1,10 +1,8 @@ using System.Security.Principal; -using SteelSeriesAPI.Interfaces; using SteelSeriesAPI.Sonar.Enums; using SteelSeriesAPI.Sonar.Http; using SteelSeriesAPI.Sonar.Interfaces; using SteelSeriesAPI.Sonar.Managers; -using SteelSeriesAPI.Sonar.Models; namespace SteelSeriesAPI.Sonar; From 9a61522fe5e4310c9ac5b1828de2d43a764cb33b Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 23:07:04 +0200 Subject: [PATCH 21/47] Added Mode manager --- SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs | 8 ------- .../Sonar/Http/SonarHttpProvider.cs | 7 ------- .../Sonar/Interfaces/ISonarCommandHandler.cs | 6 ------ .../Sonar/Interfaces/ISonarDataProvider.cs | 6 ------ .../Sonar/Interfaces/Managers/IModeManager.cs | 18 ++++++++++++++++ SteelSeriesAPI/Sonar/Managers/ModeManager.cs | 21 +++++++++++++++++++ SteelSeriesAPI/Sonar/SonarBridge.cs | 12 ++--------- 7 files changed, 41 insertions(+), 37 deletions(-) create mode 100644 SteelSeriesAPI/Sonar/Interfaces/Managers/IModeManager.cs create mode 100644 SteelSeriesAPI/Sonar/Managers/ModeManager.cs diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs index 9c07a0a..9e199b3 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs @@ -15,14 +15,6 @@ public SonarHttpCommand(SonarBridge sonarBridge) _sonarBridge = sonarBridge; } - public void SetMode(Mode mode) - { - new HttpFetcher().Put("mode/" + mode.ToDictKey(ModeMapChoice.StreamDict)); - Thread.Sleep(100); // Prevent bugs/freezes/crashes - } - - - public void SetRedirectionState(bool newState, Channel channel, Mix mix) { new HttpFetcher().Put("streamRedirections/" + mix.ToDictKey() + "/redirections/" + channel.ToDictKey() + diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs index 431a4da..f711448 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs @@ -9,13 +9,6 @@ namespace SteelSeriesAPI.Sonar.Http; public class SonarHttpProvider : ISonarDataProvider { - public Mode GetMode() - { - string mode = new HttpFetcher().Provide("mode").RootElement.ToString(); - - return (Mode)ModeExtensions.FromDictKey(mode, ModeMapChoice.StreamDict); - } - public bool GetRedirectionState(Channel channel, Mix mix) { if (channel == Channel.MASTER) diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs index 0313b87..37eed08 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs @@ -4,12 +4,6 @@ namespace SteelSeriesAPI.Sonar.Interfaces; public interface ISonarCommandHandler { - /// - /// Set the Sonar will be using - /// - /// The you want to set - void SetMode(Mode mode); - /// /// Enable or disable the Redirection of the chosen Sonar of the chosen Sonar /// diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs index f7297bf..57108da 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs @@ -5,12 +5,6 @@ namespace SteelSeriesAPI.Sonar.Interfaces; public interface ISonarDataProvider { - /// - /// Get the current mode used by Sonar - /// - /// A , either Classic or Streamer - Mode GetMode(); - /// /// Get the mute state of the Redirection of the chosen Sonar of the chosen Sonar /// diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IModeManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IModeManager.cs new file mode 100644 index 0000000..f01f412 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IModeManager.cs @@ -0,0 +1,18 @@ +using SteelSeriesAPI.Sonar.Enums; + +namespace SteelSeriesAPI.Sonar.Interfaces.Managers; + +internal interface IModeManager +{ + /// + /// Get the current mode used by Sonar + /// + /// A , either Classic or Streamer + Mode Get(); + + /// + /// Set the Sonar will be using + /// + /// The you want to set + void Set(Mode mode); +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/ModeManager.cs b/SteelSeriesAPI/Sonar/Managers/ModeManager.cs new file mode 100644 index 0000000..1595164 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Managers/ModeManager.cs @@ -0,0 +1,21 @@ +using SteelSeriesAPI.Sonar.Enums; +using SteelSeriesAPI.Sonar.Http; +using SteelSeriesAPI.Sonar.Interfaces.Managers; + +namespace SteelSeriesAPI.Sonar.Managers; + +public class ModeManager : IModeManager +{ + public Mode Get() + { + string mode = new HttpFetcher().Provide("mode").RootElement.ToString(); + + return (Mode)ModeExtensions.FromDictKey(mode, ModeMapChoice.StreamDict); + } + + public void Set(Mode mode) + { + new HttpFetcher().Put("mode/" + mode.ToDictKey(ModeMapChoice.StreamDict)); + Thread.Sleep(100); // Prevent bugs/freezes/crashes + } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index 5c9d58b..9920a8a 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -17,6 +17,7 @@ public class SonarBridge : ISonarBridge private readonly ISonarDataProvider _sonarProvider; private ISonarSocket _sonarSocket; + public readonly ModeManager Mode; public readonly VolumeSettingsManager VolumeSettings; public readonly ChatMixManager ChatMix; public readonly ConfigurationManager Configurations; @@ -28,6 +29,7 @@ public SonarBridge() { _sonarCommand = new SonarHttpCommand(this); _sonarProvider = new SonarHttpProvider(); + Mode = new ModeManager(); VolumeSettings = new VolumeSettingsManager(); ChatMix = new ChatMixManager(); Configurations = new ConfigurationManager(); @@ -100,11 +102,6 @@ public void WaitUntilSonarStarted() #region Providers - public Mode GetMode() - { - return _sonarProvider.GetMode(); - } - public bool GetRedirectionState(Channel channel, Mix mix) { return _sonarProvider.GetRedirectionState(channel, mix); @@ -118,11 +115,6 @@ public bool GetAudienceMonitoringState() #endregion #region Commands - - public void SetMode(Mode mode) - { - _sonarCommand.SetMode(mode); - } public void SetRedirectionState(bool newState, Channel channel, Mix mix) { From e38dc3f20add6cfcdb7e6316b7de986bf65bc6a1 Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 23:12:29 +0200 Subject: [PATCH 22/47] Added Redirection State Manager --- SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs | 13 ----- .../Sonar/Http/SonarHttpProvider.cs | 35 ------------- .../Sonar/Interfaces/ISonarCommandHandler.cs | 8 --- .../Sonar/Interfaces/ISonarDataProvider.cs | 8 --- .../Managers/IRedirectionStateManager.cs | 22 ++++++++ .../Sonar/Managers/RedirectionStateManager.cs | 52 +++++++++++++++++++ SteelSeriesAPI/Sonar/SonarBridge.cs | 14 ++--- 7 files changed, 77 insertions(+), 75 deletions(-) create mode 100644 SteelSeriesAPI/Sonar/Interfaces/Managers/IRedirectionStateManager.cs create mode 100644 SteelSeriesAPI/Sonar/Managers/RedirectionStateManager.cs diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs index 9e199b3..15f9fca 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs @@ -8,19 +8,6 @@ namespace SteelSeriesAPI.Sonar.Http; public class SonarHttpCommand : ISonarCommandHandler { - private readonly ISonarBridge _sonarBridge; - - public SonarHttpCommand(SonarBridge sonarBridge) - { - _sonarBridge = sonarBridge; - } - - public void SetRedirectionState(bool newState, Channel channel, Mix mix) - { - new HttpFetcher().Put("streamRedirections/" + mix.ToDictKey() + "/redirections/" + channel.ToDictKey() + - "/isEnabled/" + newState); - } - public void SetAudienceMonitoringState(bool newState) { new HttpFetcher().Put("streamRedirections/isStreamMonitoringEnabled/" + newState); diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs index f711448..fe7dd45 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs @@ -9,41 +9,6 @@ namespace SteelSeriesAPI.Sonar.Http; public class SonarHttpProvider : ISonarDataProvider { - public bool GetRedirectionState(Channel channel, Mix mix) - { - if (channel == Channel.MASTER) - { - throw new MasterChannelNotSupportedException(); - } - - JsonDocument streamRedirections = new HttpFetcher().Provide("streamRedirections"); - JsonElement streamChannel = default; - - foreach (var element in streamRedirections.RootElement.EnumerateArray()) - { - if (element.GetProperty("streamRedirectionId").GetString() == mix.ToDictKey()) - { - streamChannel = element; - break; - } - } - - JsonElement status = default; - - foreach (var element in streamChannel.GetProperty("status").EnumerateArray()) - { - if (element.GetProperty("role").GetString() == channel.ToDictKey()) - { - status = element; - break; - } - } - - bool state = status.GetProperty("isEnabled").GetBoolean(); - - return state; - } - public bool GetAudienceMonitoringState() { JsonDocument streamMonitoring = new HttpFetcher().Provide("streamRedirections/isStreamMonitoringEnabled"); diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs index 37eed08..d89f592 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs @@ -4,14 +4,6 @@ namespace SteelSeriesAPI.Sonar.Interfaces; public interface ISonarCommandHandler { - /// - /// Enable or disable the Redirection of the chosen Sonar of the chosen Sonar - /// - /// The new state of the Redirection - /// The Sonar you want to un/mute a Sonar redirection mix - /// The Sonar you want to un/mute - void SetRedirectionState(bool newState, Channel channel, Mix mix); - /// /// Listen to what your audience hear /// diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs index 57108da..957cc01 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs @@ -5,14 +5,6 @@ namespace SteelSeriesAPI.Sonar.Interfaces; public interface ISonarDataProvider { - /// - /// Get the mute state of the Redirection of the chosen Sonar of the chosen Sonar - /// - /// The Sonar you want the mute state of a Redirection mix - /// The Sonar you want to get the mute state - /// The current state, un/muted - bool GetRedirectionState(Channel channel, Mix mix); - /// /// Get the current state of the Audience Monitoring /// diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IRedirectionStateManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IRedirectionStateManager.cs new file mode 100644 index 0000000..c64c4d5 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IRedirectionStateManager.cs @@ -0,0 +1,22 @@ +using SteelSeriesAPI.Sonar.Enums; + +namespace SteelSeriesAPI.Sonar.Interfaces.Managers; + +internal interface IRedirectionStateManager +{ + /// + /// Get the mute state of the Redirection of the chosen Sonar of the chosen Sonar + /// + /// The Sonar you want the mute state of a Redirection mix + /// The Sonar you want to get the mute state + /// The current state, un/muted + bool Get(Channel channel, Mix mix); + + /// + /// Enable or disable the Redirection of the chosen Sonar of the chosen Sonar + /// + /// The new state of the Redirection + /// The Sonar you want to un/mute a Sonar redirection mix + /// The Sonar you want to un/mute + void Set(bool newState, Channel channel, Mix mix); +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/RedirectionStateManager.cs b/SteelSeriesAPI/Sonar/Managers/RedirectionStateManager.cs new file mode 100644 index 0000000..352e6c1 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Managers/RedirectionStateManager.cs @@ -0,0 +1,52 @@ +using SteelSeriesAPI.Sonar.Exceptions; +using SteelSeriesAPI.Sonar.Enums; +using SteelSeriesAPI.Sonar.Http; +using SteelSeriesAPI.Sonar.Interfaces.Managers; + +using System.Text.Json; + +namespace SteelSeriesAPI.Sonar.Managers; + +public class RedirectionStateManager : IRedirectionStateManager +{ + public bool Get(Channel channel, Mix mix) + { + if (channel == Channel.MASTER) + { + throw new MasterChannelNotSupportedException(); + } + + JsonDocument streamRedirections = new HttpFetcher().Provide("streamRedirections"); + JsonElement streamChannel = default; + + foreach (var element in streamRedirections.RootElement.EnumerateArray()) + { + if (element.GetProperty("streamRedirectionId").GetString() == mix.ToDictKey()) + { + streamChannel = element; + break; + } + } + + JsonElement status = default; + + foreach (var element in streamChannel.GetProperty("status").EnumerateArray()) + { + if (element.GetProperty("role").GetString() == channel.ToDictKey()) + { + status = element; + break; + } + } + + bool state = status.GetProperty("isEnabled").GetBoolean(); + + return state; + } + + public void Set(bool newState, Channel channel, Mix mix) + { + new HttpFetcher().Put("streamRedirections/" + mix.ToDictKey() + "/redirections/" + channel.ToDictKey() + + "/isEnabled/" + newState); + } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index 9920a8a..218e273 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -22,18 +22,20 @@ public class SonarBridge : ISonarBridge public readonly ChatMixManager ChatMix; public readonly ConfigurationManager Configurations; public readonly PlaybackDeviceManager PlaybackDevices; + public readonly RedirectionStateManager RedirectionStates; public readonly RoutedProcessManager RoutedProcesses; public readonly EventManager Events; public SonarBridge() { - _sonarCommand = new SonarHttpCommand(this); + _sonarCommand = new SonarHttpCommand(); _sonarProvider = new SonarHttpProvider(); Mode = new ModeManager(); VolumeSettings = new VolumeSettingsManager(); ChatMix = new ChatMixManager(); Configurations = new ConfigurationManager(); PlaybackDevices = new PlaybackDeviceManager(); + RedirectionStates = new RedirectionStateManager(); RoutedProcesses = new RoutedProcessManager(); Events = new EventManager(); } @@ -102,11 +104,6 @@ public void WaitUntilSonarStarted() #region Providers - public bool GetRedirectionState(Channel channel, Mix mix) - { - return _sonarProvider.GetRedirectionState(channel, mix); - } - public bool GetAudienceMonitoringState() { return _sonarProvider.GetAudienceMonitoringState(); @@ -115,11 +112,6 @@ public bool GetAudienceMonitoringState() #endregion #region Commands - - public void SetRedirectionState(bool newState, Channel channel, Mix mix) - { - _sonarCommand.SetRedirectionState(newState, channel, mix); - } public void SetAudienceMonitoringState(bool newState) { From c1971e3e6bcd53133a128580b2057defc2e04d76 Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 23:18:29 +0200 Subject: [PATCH 23/47] Added Audience Monitoring Manager and removed old Sonar http command and provider as well as their interfaces --- SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs | 15 ------------ .../Sonar/Http/SonarHttpProvider.cs | 18 -------------- .../Sonar/Interfaces/ISonarBridge.cs | 2 +- .../Sonar/Interfaces/ISonarCommandHandler.cs | 12 ---------- .../Sonar/Interfaces/ISonarDataProvider.cs | 13 ---------- .../Managers/IAudienceMonitoringManager.cs | 16 +++++++++++++ .../Managers/AudienceMonitoringManager.cs | 21 ++++++++++++++++ SteelSeriesAPI/Sonar/SonarBridge.cs | 24 ++----------------- 8 files changed, 40 insertions(+), 81 deletions(-) delete mode 100644 SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs delete mode 100644 SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs delete mode 100644 SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs delete mode 100644 SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs create mode 100644 SteelSeriesAPI/Sonar/Interfaces/Managers/IAudienceMonitoringManager.cs create mode 100644 SteelSeriesAPI/Sonar/Managers/AudienceMonitoringManager.cs diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs deleted file mode 100644 index 15f9fca..0000000 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Globalization; -using System.Text.Json; -using SteelSeriesAPI.Sonar.Interfaces; -using SteelSeriesAPI.Sonar.Enums; -using SteelSeriesAPI.Sonar.Exceptions; - -namespace SteelSeriesAPI.Sonar.Http; - -public class SonarHttpCommand : ISonarCommandHandler -{ - public void SetAudienceMonitoringState(bool newState) - { - new HttpFetcher().Put("streamRedirections/isStreamMonitoringEnabled/" + newState); - } -} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs deleted file mode 100644 index fe7dd45..0000000 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections; -using System.Text.Json; -using SteelSeriesAPI.Sonar.Interfaces; -using SteelSeriesAPI.Sonar.Enums; -using SteelSeriesAPI.Sonar.Exceptions; -using SteelSeriesAPI.Sonar.Models; - -namespace SteelSeriesAPI.Sonar.Http; - -public class SonarHttpProvider : ISonarDataProvider -{ - public bool GetAudienceMonitoringState() - { - JsonDocument streamMonitoring = new HttpFetcher().Provide("streamRedirections/isStreamMonitoringEnabled"); - - return streamMonitoring.RootElement.GetBoolean(); - } -} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarBridge.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarBridge.cs index a6c80e6..23cc498 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarBridge.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarBridge.cs @@ -1,6 +1,6 @@ namespace SteelSeriesAPI.Sonar.Interfaces; -public interface ISonarBridge : ISonarDataProvider, ISonarCommandHandler +public interface ISonarBridge { /// /// The running state of Sonar diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs deleted file mode 100644 index d89f592..0000000 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs +++ /dev/null @@ -1,12 +0,0 @@ -using SteelSeriesAPI.Sonar.Enums; - -namespace SteelSeriesAPI.Sonar.Interfaces; - -public interface ISonarCommandHandler -{ - /// - /// Listen to what your audience hear - /// - /// The new state, un/muted - void SetAudienceMonitoringState(bool newState); -} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs deleted file mode 100644 index 957cc01..0000000 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs +++ /dev/null @@ -1,13 +0,0 @@ -using SteelSeriesAPI.Sonar.Enums; -using SteelSeriesAPI.Sonar.Models; - -namespace SteelSeriesAPI.Sonar.Interfaces; - -public interface ISonarDataProvider -{ - /// - /// Get the current state of the Audience Monitoring - /// - /// The current state, un/muted - bool GetAudienceMonitoringState(); -} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IAudienceMonitoringManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IAudienceMonitoringManager.cs new file mode 100644 index 0000000..87e0dad --- /dev/null +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IAudienceMonitoringManager.cs @@ -0,0 +1,16 @@ +namespace SteelSeriesAPI.Sonar.Interfaces.Managers; + +public interface IAudienceMonitoringManager +{ + /// + /// Get the current state of the Audience Monitoring + /// + /// The current state, un/muted + bool GetState(); + + /// + /// Listen to what your audience hear + /// + /// The new state, un/muted + void SetState(bool newState); +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/AudienceMonitoringManager.cs b/SteelSeriesAPI/Sonar/Managers/AudienceMonitoringManager.cs new file mode 100644 index 0000000..635e1cc --- /dev/null +++ b/SteelSeriesAPI/Sonar/Managers/AudienceMonitoringManager.cs @@ -0,0 +1,21 @@ +using SteelSeriesAPI.Sonar.Http; +using SteelSeriesAPI.Sonar.Interfaces.Managers; + +using System.Text.Json; + +namespace SteelSeriesAPI.Sonar.Managers; + +public class AudienceMonitoringManager : IAudienceMonitoringManager +{ + public bool GetState() + { + JsonDocument streamMonitoring = new HttpFetcher().Provide("streamRedirections/isStreamMonitoringEnabled"); + + return streamMonitoring.RootElement.GetBoolean(); + } + + public void SetState(bool newState) + { + new HttpFetcher().Put("streamRedirections/isStreamMonitoringEnabled/" + newState); + } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index 218e273..4fdb362 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -13,8 +13,6 @@ public class SonarBridge : ISonarBridge { public bool IsRunning => SonarRetriever.Instance is { IsEnabled: true, IsReady: true, IsRunning: true }; - private readonly ISonarCommandHandler _sonarCommand; - private readonly ISonarDataProvider _sonarProvider; private ISonarSocket _sonarSocket; public readonly ModeManager Mode; @@ -23,19 +21,19 @@ public class SonarBridge : ISonarBridge public readonly ConfigurationManager Configurations; public readonly PlaybackDeviceManager PlaybackDevices; public readonly RedirectionStateManager RedirectionStates; + public readonly AudienceMonitoringManager AudienceMonitoring; public readonly RoutedProcessManager RoutedProcesses; public readonly EventManager Events; public SonarBridge() { - _sonarCommand = new SonarHttpCommand(); - _sonarProvider = new SonarHttpProvider(); Mode = new ModeManager(); VolumeSettings = new VolumeSettingsManager(); ChatMix = new ChatMixManager(); Configurations = new ConfigurationManager(); PlaybackDevices = new PlaybackDeviceManager(); RedirectionStates = new RedirectionStateManager(); + AudienceMonitoring = new AudienceMonitoringManager(); RoutedProcesses = new RoutedProcessManager(); Events = new EventManager(); } @@ -101,22 +99,4 @@ public void WaitUntilSonarStarted() { SonarRetriever.Instance.WaitUntilAppStarted(); } - - #region Providers - - public bool GetAudienceMonitoringState() - { - return _sonarProvider.GetAudienceMonitoringState(); - } - - #endregion - - #region Commands - - public void SetAudienceMonitoringState(bool newState) - { - _sonarCommand.SetAudienceMonitoringState(newState); - } - - #endregion } \ No newline at end of file From ba5b6a8135ce024be3f85873d34f5f90aa3d6c9a Mon Sep 17 00:00:00 2001 From: DataNext Date: Sat, 26 Apr 2025 02:32:12 +0200 Subject: [PATCH 24/47] Renamed HttpFetcher to simply Fetcher --- .../Sonar/Http/{HttpFetcher.cs => Fetcher.cs} | 4 +-- .../Managers/AudienceMonitoringManager.cs | 4 +-- .../Sonar/Managers/ChatMixManager.cs | 6 ++--- .../Sonar/Managers/ConfigurationManager.cs | 6 ++--- SteelSeriesAPI/Sonar/Managers/ModeManager.cs | 4 +-- .../Sonar/Managers/PlaybackDeviceManager.cs | 26 +++++++++---------- .../Sonar/Managers/RedirectionStateManager.cs | 4 +-- .../Sonar/Managers/RoutedProcessManager.cs | 8 +++--- .../Sonar/Managers/VolumeSettingsManager.cs | 16 ++++++------ 9 files changed, 39 insertions(+), 39 deletions(-) rename SteelSeriesAPI/Sonar/Http/{HttpFetcher.cs => Fetcher.cs} (97%) diff --git a/SteelSeriesAPI/Sonar/Http/HttpFetcher.cs b/SteelSeriesAPI/Sonar/Http/Fetcher.cs similarity index 97% rename from SteelSeriesAPI/Sonar/Http/HttpFetcher.cs rename to SteelSeriesAPI/Sonar/Http/Fetcher.cs index b8de29e..d405f4e 100644 --- a/SteelSeriesAPI/Sonar/Http/HttpFetcher.cs +++ b/SteelSeriesAPI/Sonar/Http/Fetcher.cs @@ -5,12 +5,12 @@ namespace SteelSeriesAPI.Sonar.Http; -public class HttpFetcher +public class Fetcher { private readonly HttpClient _httpClient; private readonly IAppRetriever _sonarRetriever; - public HttpFetcher() + public Fetcher() { _sonarRetriever = SonarRetriever.Instance; diff --git a/SteelSeriesAPI/Sonar/Managers/AudienceMonitoringManager.cs b/SteelSeriesAPI/Sonar/Managers/AudienceMonitoringManager.cs index 635e1cc..d0be916 100644 --- a/SteelSeriesAPI/Sonar/Managers/AudienceMonitoringManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/AudienceMonitoringManager.cs @@ -9,13 +9,13 @@ public class AudienceMonitoringManager : IAudienceMonitoringManager { public bool GetState() { - JsonDocument streamMonitoring = new HttpFetcher().Provide("streamRedirections/isStreamMonitoringEnabled"); + JsonDocument streamMonitoring = new Fetcher().Provide("streamRedirections/isStreamMonitoringEnabled"); return streamMonitoring.RootElement.GetBoolean(); } public void SetState(bool newState) { - new HttpFetcher().Put("streamRedirections/isStreamMonitoringEnabled/" + newState); + new Fetcher().Put("streamRedirections/isStreamMonitoringEnabled/" + newState); } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/ChatMixManager.cs b/SteelSeriesAPI/Sonar/Managers/ChatMixManager.cs index f288615..dbbf204 100644 --- a/SteelSeriesAPI/Sonar/Managers/ChatMixManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/ChatMixManager.cs @@ -11,14 +11,14 @@ public class ChatMixManager : IChatMixManager { public double GetBalance() { - JsonDocument chatMix = new HttpFetcher().Provide("chatMix"); + JsonDocument chatMix = new Fetcher().Provide("chatMix"); return chatMix.RootElement.GetProperty("balance").GetDouble(); } public bool GetState() { - JsonDocument chatMix = new HttpFetcher().Provide("chatMix"); + JsonDocument chatMix = new Fetcher().Provide("chatMix"); string cState = chatMix.RootElement.GetProperty("state").ToString(); if (cState == "enabled") @@ -41,6 +41,6 @@ public void SetBalance(double balance) throw new ChatMixBalanceException(); } - new HttpFetcher().Put("chatMix?balance=" + balance.ToString("0.00", CultureInfo.InvariantCulture)); + new Fetcher().Put("chatMix?balance=" + balance.ToString("0.00", CultureInfo.InvariantCulture)); } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs b/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs index b78df4e..6baecaf 100644 --- a/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs @@ -12,7 +12,7 @@ public class ConfigurationManager : IConfigurationManager { public IEnumerable GetAllAudioConfigurations() { - JsonDocument configs = new HttpFetcher().Provide("configs"); + JsonDocument configs = new Fetcher().Provide("configs"); foreach (var element in configs.RootElement.EnumerateArray()) { @@ -69,7 +69,7 @@ public SonarAudioConfiguration GetSelectedAudioConfiguration(Channel channel) throw new MasterChannelNotSupportedException(); } - JsonDocument selectedConfigs = new HttpFetcher().Provide("configs/selected"); + JsonDocument selectedConfigs = new Fetcher().Provide("configs/selected"); JsonElement sConfig = default; foreach (var config in selectedConfigs.RootElement.EnumerateArray()) @@ -92,7 +92,7 @@ public void SetConfig(string configId) { if (string.IsNullOrEmpty(configId)) throw new ConfigNotFoundException($"No audio configuration found with this id: {configId}"); - new HttpFetcher().Put("configs/" + configId + "/select"); + new Fetcher().Put("configs/" + configId + "/select"); } public void SetConfig(SonarAudioConfiguration config) diff --git a/SteelSeriesAPI/Sonar/Managers/ModeManager.cs b/SteelSeriesAPI/Sonar/Managers/ModeManager.cs index 1595164..d393937 100644 --- a/SteelSeriesAPI/Sonar/Managers/ModeManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/ModeManager.cs @@ -8,14 +8,14 @@ public class ModeManager : IModeManager { public Mode Get() { - string mode = new HttpFetcher().Provide("mode").RootElement.ToString(); + string mode = new Fetcher().Provide("mode").RootElement.ToString(); return (Mode)ModeExtensions.FromDictKey(mode, ModeMapChoice.StreamDict); } public void Set(Mode mode) { - new HttpFetcher().Put("mode/" + mode.ToDictKey(ModeMapChoice.StreamDict)); + new Fetcher().Put("mode/" + mode.ToDictKey(ModeMapChoice.StreamDict)); Thread.Sleep(100); // Prevent bugs/freezes/crashes } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs b/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs index 2607dcd..9aa1a50 100644 --- a/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs @@ -13,7 +13,7 @@ public class PlaybackDeviceManager : IPlaybackDeviceManager { public IEnumerable GetPlaybackDevices(DataFlow _dataFlow) { - JsonDocument audioDevices = new HttpFetcher().Provide("audioDevices"); + JsonDocument audioDevices = new Fetcher().Provide("audioDevices"); // JsonDocument classicRedirections = new HttpProvider("classicRedirections").Provide(); // JsonDocument streamRedirections = new HttpProvider("streamRedirections").Provide(); @@ -43,7 +43,7 @@ public PlaybackDevice GetPlaybackDevice(string deviceId) { try { - JsonElement device = new HttpFetcher().Provide("audioDevices/" + deviceId).RootElement; + JsonElement device = new Fetcher().Provide("audioDevices/" + deviceId).RootElement; string id = device.GetProperty("id").GetString(); string name = device.GetProperty("friendlyName").GetString(); @@ -69,7 +69,7 @@ public PlaybackDevice GetClassicPlaybackDevice(Channel channel) throw new MasterChannelNotSupportedException(); } - JsonDocument classicRedirections = new HttpFetcher().Provide("classicRedirections"); + JsonDocument classicRedirections = new Fetcher().Provide("classicRedirections"); JsonElement cRedirections = default; foreach (var element in classicRedirections.RootElement.EnumerateArray()) @@ -87,7 +87,7 @@ public PlaybackDevice GetClassicPlaybackDevice(Channel channel) GetAssociatedChannels(deviceId, associatedClassicChannels, associatedStreamChannels); - JsonDocument audioDevice = new HttpFetcher().Provide("audioDevices/" + deviceId); + JsonDocument audioDevice = new Fetcher().Provide("audioDevices/" + deviceId); string name = audioDevice.RootElement.GetProperty("friendlyName").GetString(); DataFlow dataFlow = (DataFlow)DataFlowExtensions.FromDictKey(audioDevice.RootElement.GetProperty("dataFlow").GetString()); @@ -97,7 +97,7 @@ public PlaybackDevice GetClassicPlaybackDevice(Channel channel) public PlaybackDevice GetStreamerPlaybackDevice(Mix mix) { - JsonDocument streamRedirections = new HttpFetcher().Provide("streamRedirections"); + JsonDocument streamRedirections = new Fetcher().Provide("streamRedirections"); JsonElement sRedirections = default; foreach (var element in streamRedirections.RootElement.EnumerateArray()) @@ -115,7 +115,7 @@ public PlaybackDevice GetStreamerPlaybackDevice(Mix mix) GetAssociatedChannels(deviceId, associatedClassicChannels, associatedStreamChannels); - JsonDocument audioDevice = new HttpFetcher().Provide("audioDevices/" + deviceId); + JsonDocument audioDevice = new Fetcher().Provide("audioDevices/" + deviceId); string name = audioDevice.RootElement.GetProperty("friendlyName").GetString(); DataFlow dataFlow = (DataFlow)DataFlowExtensions.FromDictKey(audioDevice.RootElement.GetProperty("dataFlow").GetString()); @@ -130,7 +130,7 @@ public PlaybackDevice GetStreamerPlaybackDevice(Channel channel = Channel.MIC) throw new MicChannelSupportOnlyException(); } - JsonDocument streamRedirections = new HttpFetcher().Provide("streamRedirections"); + JsonDocument streamRedirections = new Fetcher().Provide("streamRedirections"); JsonElement sRedirections = default; foreach (var element in streamRedirections.RootElement.EnumerateArray()) @@ -148,7 +148,7 @@ public PlaybackDevice GetStreamerPlaybackDevice(Channel channel = Channel.MIC) GetAssociatedChannels(deviceId, associatedClassicChannels, associatedStreamChannels); - JsonDocument audioDevice = new HttpFetcher().Provide("audioDevices/" + deviceId); + JsonDocument audioDevice = new Fetcher().Provide("audioDevices/" + deviceId); string name = audioDevice.RootElement.GetProperty("friendlyName").GetString(); DataFlow dataFlow = (DataFlow)DataFlowExtensions.FromDictKey(audioDevice.RootElement.GetProperty("dataFlow").GetString()); @@ -158,8 +158,8 @@ public PlaybackDevice GetStreamerPlaybackDevice(Channel channel = Channel.MIC) private void GetAssociatedChannels(string deviceId, List associatedClassicDevices, ArrayList associatedStreamDevices) { - JsonDocument classicRedirections = new HttpFetcher().Provide("classicRedirections"); - JsonDocument streamRedirections = new HttpFetcher().Provide("streamRedirections"); + JsonDocument classicRedirections = new Fetcher().Provide("classicRedirections"); + JsonDocument streamRedirections = new Fetcher().Provide("streamRedirections"); foreach (var element in classicRedirections.RootElement.EnumerateArray()) { @@ -187,12 +187,12 @@ private void GetAssociatedChannels(string deviceId, List associatedClas public void SetClassicPlaybackDevice(string deviceId, Channel channel) { - new HttpFetcher().Put("classicRedirections/" + channel.ToDictKey(ChannelMapChoice.ChannelDict) +"/deviceId/" + deviceId); + new Fetcher().Put("classicRedirections/" + channel.ToDictKey(ChannelMapChoice.ChannelDict) +"/deviceId/" + deviceId); } public void SetStreamerPlaybackDevice(string deviceId, Mix mix) { - new HttpFetcher().Put("streamRedirections/" + mix.ToDictKey() +"/deviceId/" + deviceId); + new Fetcher().Put("streamRedirections/" + mix.ToDictKey() +"/deviceId/" + deviceId); } public void SetStreamerPlaybackDevice(string deviceId, Channel channel = Channel.MIC) @@ -202,7 +202,7 @@ public void SetStreamerPlaybackDevice(string deviceId, Channel channel = Channel throw new MicChannelSupportOnlyException(); } - new HttpFetcher().Put("streamRedirections/" + channel.ToDictKey(ChannelMapChoice.ChannelDict) +"/deviceId/" + deviceId); + new Fetcher().Put("streamRedirections/" + channel.ToDictKey(ChannelMapChoice.ChannelDict) +"/deviceId/" + deviceId); } public void SetClassicPlaybackDevice(PlaybackDevice playbackDevice, Channel channel) diff --git a/SteelSeriesAPI/Sonar/Managers/RedirectionStateManager.cs b/SteelSeriesAPI/Sonar/Managers/RedirectionStateManager.cs index 352e6c1..d6e9576 100644 --- a/SteelSeriesAPI/Sonar/Managers/RedirectionStateManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/RedirectionStateManager.cs @@ -16,7 +16,7 @@ public bool Get(Channel channel, Mix mix) throw new MasterChannelNotSupportedException(); } - JsonDocument streamRedirections = new HttpFetcher().Provide("streamRedirections"); + JsonDocument streamRedirections = new Fetcher().Provide("streamRedirections"); JsonElement streamChannel = default; foreach (var element in streamRedirections.RootElement.EnumerateArray()) @@ -46,7 +46,7 @@ public bool Get(Channel channel, Mix mix) public void Set(bool newState, Channel channel, Mix mix) { - new HttpFetcher().Put("streamRedirections/" + mix.ToDictKey() + "/redirections/" + channel.ToDictKey() + + new Fetcher().Put("streamRedirections/" + mix.ToDictKey() + "/redirections/" + channel.ToDictKey() + "/isEnabled/" + newState); } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs b/SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs index 52d253d..68c12a9 100644 --- a/SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs @@ -17,7 +17,7 @@ public IEnumerable GetRoutedProcesses(Channel channel) throw new MasterChannelNotSupportedException(); } - JsonDocument audioDeviceRoutings = new HttpFetcher().Provide("AudioDeviceRouting"); + JsonDocument audioDeviceRoutings = new Fetcher().Provide("AudioDeviceRouting"); foreach (var element in audioDeviceRoutings.RootElement.EnumerateArray()) { @@ -53,7 +53,7 @@ public void RouteProcessToChannel(int pId, Channel channel) throw new MasterChannelNotSupportedException(); } - JsonDocument audioDeviceRouting = new HttpFetcher().Provide("AudioDeviceRouting"); + JsonDocument audioDeviceRouting = new Fetcher().Provide("AudioDeviceRouting"); foreach (var element in audioDeviceRouting.RootElement.EnumerateArray()) { @@ -61,12 +61,12 @@ public void RouteProcessToChannel(int pId, Channel channel) { if (channel == Channel.MIC) { - new HttpFetcher().Put("AudioDeviceRouting/capture/" + element.GetProperty("deviceId").GetString() + "/" + pId); + new Fetcher().Put("AudioDeviceRouting/capture/" + element.GetProperty("deviceId").GetString() + "/" + pId); break; } else { - new HttpFetcher().Put("AudioDeviceRouting/render/" + element.GetProperty("deviceId").GetString() + "/" + pId); + new Fetcher().Put("AudioDeviceRouting/render/" + element.GetProperty("deviceId").GetString() + "/" + pId); break; } } diff --git a/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs b/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs index 5c97803..01520aa 100644 --- a/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs @@ -12,7 +12,7 @@ public class VolumeSettingsManager : IVolumeSettingsManager // volume = 0,00000000 <-- 8 decimal max public double GetVolume(Channel channel) { - JsonDocument volumeSettings = new HttpFetcher().Provide("volumeSettings/classic/"); + JsonDocument volumeSettings = new Fetcher().Provide("volumeSettings/classic/"); if (channel == Channel.MASTER) return volumeSettings.RootElement.GetProperty("masters").GetProperty("classic").GetProperty("volume").GetDouble(); @@ -21,7 +21,7 @@ public double GetVolume(Channel channel) public double GetVolume(Channel channel, Mix mix) { - JsonDocument volumeSettings = new HttpFetcher().Provide("volumeSettings/streamer/"); + JsonDocument volumeSettings = new Fetcher().Provide("volumeSettings/streamer/"); if (channel == Channel.MASTER) return volumeSettings.RootElement.GetProperty("masters").GetProperty("stream").GetProperty(mix.ToDictKey()).GetProperty("volume").GetDouble(); @@ -30,7 +30,7 @@ public double GetVolume(Channel channel, Mix mix) public bool GetMute(Channel channel) { - JsonDocument volumeSettings = new HttpFetcher().Provide("volumeSettings/classic/"); + JsonDocument volumeSettings = new Fetcher().Provide("volumeSettings/classic/"); if (channel == Channel.MASTER) return volumeSettings.RootElement.GetProperty("masters").GetProperty("classic").GetProperty("muted").GetBoolean(); @@ -39,7 +39,7 @@ public bool GetMute(Channel channel) public bool GetMute(Channel channel, Mix mix) { - JsonDocument volumeSettings = new HttpFetcher().Provide("volumeSettings/streamer/"); + JsonDocument volumeSettings = new Fetcher().Provide("volumeSettings/streamer/"); if (channel == Channel.MASTER) return volumeSettings.RootElement.GetProperty("masters").GetProperty("stream").GetProperty(mix.ToDictKey()).GetProperty("muted").GetBoolean(); @@ -49,22 +49,22 @@ public bool GetMute(Channel channel, Mix mix) public void SetVolume(double vol, Channel channel) { string _vol = vol.ToString("0.00", CultureInfo.InvariantCulture); - new HttpFetcher().Put("volumeSettings/classic/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/Volume/" + _vol); + new Fetcher().Put("volumeSettings/classic/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/Volume/" + _vol); } public void SetVolume(double vol, Channel channel, Mix mix) { string _vol = vol.ToString("0.00", CultureInfo.InvariantCulture); - new HttpFetcher().Put("volumeSettings/streamer/" + mix.ToDictKey() + "/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/volume/" + _vol); + new Fetcher().Put("volumeSettings/streamer/" + mix.ToDictKey() + "/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/volume/" + _vol); } public void SetMute(bool mute, Channel channel) { - new HttpFetcher().Put("volumeSettings/classic/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/Mute/" + mute); + new Fetcher().Put("volumeSettings/classic/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/Mute/" + mute); } public void SetMute(bool mute, Channel channel, Mix mix) { - new HttpFetcher().Put("volumeSettings/streamer/" + mix.ToDictKey() + "/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/isMuted/" + mute); + new Fetcher().Put("volumeSettings/streamer/" + mix.ToDictKey() + "/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/isMuted/" + mute); } } \ No newline at end of file From 1f73e54e12e426b764c5efd9689caae6eabb5faf Mon Sep 17 00:00:00 2001 From: DataNext Date: Sat, 26 Apr 2025 02:34:11 +0200 Subject: [PATCH 25/47] Made the HandleEvent method internal --- SteelSeriesAPI/Sonar/Managers/EventManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SteelSeriesAPI/Sonar/Managers/EventManager.cs b/SteelSeriesAPI/Sonar/Managers/EventManager.cs index b2ca772..0d0628c 100644 --- a/SteelSeriesAPI/Sonar/Managers/EventManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/EventManager.cs @@ -46,7 +46,7 @@ public class EventManager /// public event EventHandler OnSonarAudienceMonitoringChange = delegate{ }; - public void HandleEvent(string path) + internal void HandleEvent(string path) { var eventMessage = PathResolver(path); switch (eventMessage) From bf937c674652a622e555d5d24b9c00a11c788a76 Mon Sep 17 00:00:00 2001 From: DataNext Date: Sat, 26 Apr 2025 05:27:51 +0200 Subject: [PATCH 26/47] Reworked RedirectionStateManager and renamed it to MixManager --- .../Exceptions/ChannelNotFoundException.cs | 8 +++ .../Sonar/Exceptions/MixNotFoundException.cs | 8 +++ .../NoStreamRedirectionSetException.cs | 8 +++ .../Sonar/Interfaces/Managers/IMixManager.cs | 39 ++++++++++++++ .../Managers/IRedirectionStateManager.cs | 22 -------- SteelSeriesAPI/Sonar/Managers/EventManager.cs | 2 +- SteelSeriesAPI/Sonar/Managers/MixManager.cs | 49 +++++++++++++++++ .../Sonar/Managers/RedirectionStateManager.cs | 52 ------------------- SteelSeriesAPI/Sonar/SonarBridge.cs | 16 +++--- 9 files changed, 121 insertions(+), 83 deletions(-) create mode 100644 SteelSeriesAPI/Sonar/Exceptions/ChannelNotFoundException.cs create mode 100644 SteelSeriesAPI/Sonar/Exceptions/MixNotFoundException.cs create mode 100644 SteelSeriesAPI/Sonar/Exceptions/NoStreamRedirectionSetException.cs create mode 100644 SteelSeriesAPI/Sonar/Interfaces/Managers/IMixManager.cs delete mode 100644 SteelSeriesAPI/Sonar/Interfaces/Managers/IRedirectionStateManager.cs create mode 100644 SteelSeriesAPI/Sonar/Managers/MixManager.cs delete mode 100644 SteelSeriesAPI/Sonar/Managers/RedirectionStateManager.cs diff --git a/SteelSeriesAPI/Sonar/Exceptions/ChannelNotFoundException.cs b/SteelSeriesAPI/Sonar/Exceptions/ChannelNotFoundException.cs new file mode 100644 index 0000000..73a5baf --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/ChannelNotFoundException.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class ChannelNotFoundException : Exception +{ + public ChannelNotFoundException() : base("Channel could not be found.") { } + public ChannelNotFoundException(string message) : base(message) { } + public ChannelNotFoundException(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/MixNotFoundException.cs b/SteelSeriesAPI/Sonar/Exceptions/MixNotFoundException.cs new file mode 100644 index 0000000..65b339f --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/MixNotFoundException.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class MixNotFoundException : Exception +{ + public MixNotFoundException() : base("Mix could not be found.") { } + public MixNotFoundException(string message) : base(message) { } + public MixNotFoundException(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/NoStreamRedirectionSetException.cs b/SteelSeriesAPI/Sonar/Exceptions/NoStreamRedirectionSetException.cs new file mode 100644 index 0000000..467c7de --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/NoStreamRedirectionSetException.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class NoStreamRedirectionSetException : Exception +{ + public NoStreamRedirectionSetException() : base("No redirection was set. Check the playback devices of the streamer mode") { } + public NoStreamRedirectionSetException(string message) : base("No redirection was set. Check the playback devices of the streamer mode\n" + message) { } + public NoStreamRedirectionSetException(string message, Exception innerException) : base("No redirection was set. Check the playback devices of the streamer mode\n" + message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IMixManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IMixManager.cs new file mode 100644 index 0000000..d867d74 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IMixManager.cs @@ -0,0 +1,39 @@ +using SteelSeriesAPI.Sonar.Enums; + +namespace SteelSeriesAPI.Sonar.Interfaces.Managers; + +/// +/// Manage the personal and stream mix for each channel +/// +public interface IMixManager +{ + /// + /// Get the state of the chosen Sonar of the chosen Sonar + /// + /// The Sonar of the + /// The Sonar you want the state of + /// The current state, activated/deactivated + bool GetState(Channel channel, Mix mix); + + /// + /// Activate or deactivate a Sonar of a Sonar + /// + /// The new state of the Mix + /// The Sonar of the + /// The Sonar you want to activate/deactivate + void SetState(bool newState, Channel channel, Mix mix); + + /// + /// Activate a Sonar of a Sonar + /// + /// The Sonar of the + /// The Sonar you want to activate + void Activate(Channel channel, Mix mix); + + /// + /// Deactivate a Sonar of a Sonar + /// + /// The Sonar of the + /// The Sonar you want to deactivate + void Deactivate(Channel channel, Mix mix); +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IRedirectionStateManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IRedirectionStateManager.cs deleted file mode 100644 index c64c4d5..0000000 --- a/SteelSeriesAPI/Sonar/Interfaces/Managers/IRedirectionStateManager.cs +++ /dev/null @@ -1,22 +0,0 @@ -using SteelSeriesAPI.Sonar.Enums; - -namespace SteelSeriesAPI.Sonar.Interfaces.Managers; - -internal interface IRedirectionStateManager -{ - /// - /// Get the mute state of the Redirection of the chosen Sonar of the chosen Sonar - /// - /// The Sonar you want the mute state of a Redirection mix - /// The Sonar you want to get the mute state - /// The current state, un/muted - bool Get(Channel channel, Mix mix); - - /// - /// Enable or disable the Redirection of the chosen Sonar of the chosen Sonar - /// - /// The new state of the Redirection - /// The Sonar you want to un/mute a Sonar redirection mix - /// The Sonar you want to un/mute - void Set(bool newState, Channel channel, Mix mix); -} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/EventManager.cs b/SteelSeriesAPI/Sonar/Managers/EventManager.cs index 0d0628c..79f9447 100644 --- a/SteelSeriesAPI/Sonar/Managers/EventManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/EventManager.cs @@ -32,7 +32,7 @@ public class EventManager public event EventHandler OnSonarChatMixChange = delegate{ }; /// - /// Notify when a redirection channel of a channel is changed + /// Notify when a playback device of a channel is changed /// public event EventHandler OnSonarPlaybackDeviceChange = delegate{ }; diff --git a/SteelSeriesAPI/Sonar/Managers/MixManager.cs b/SteelSeriesAPI/Sonar/Managers/MixManager.cs new file mode 100644 index 0000000..8c8c555 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Managers/MixManager.cs @@ -0,0 +1,49 @@ +using SteelSeriesAPI.Sonar.Exceptions; +using SteelSeriesAPI.Sonar.Enums; +using SteelSeriesAPI.Sonar.Http; + +using System.Text.Json; +using SteelSeriesAPI.Sonar.Interfaces.Managers; + +namespace SteelSeriesAPI.Sonar.Managers; + +internal class MixManager : IMixManager +{ + public bool GetState(Channel channel, Mix mix) + { + JsonElement streamRedirections = new Fetcher().Provide("streamRedirections").RootElement; + + foreach (JsonElement element in streamRedirections.EnumerateArray()) + { + if (element.GetProperty("streamRedirectionId").GetString() == mix.ToDictKey()) + { + foreach (JsonElement status in element.GetProperty("status").EnumerateArray()) + { + if (status.GetProperty("role").GetString() == channel.ToDictKey()) + { + return status.GetProperty("isEnabled").GetBoolean(); + } + } + + throw new ChannelNotFoundException(); + } + } + + throw new MixNotFoundException(); + } + + public void SetState(bool newState,Channel channel, Mix mix) + { + new Fetcher().Put("streamRedirections/" + mix.ToDictKey() + "/redirections/" + channel.ToDictKey() + "/isEnabled/" + newState); + } + + public void Activate(Channel channel, Mix mix) + { + new Fetcher().Put("streamRedirections/" + mix.ToDictKey() + "/redirections/" + channel.ToDictKey() + "/isEnabled/true"); + } + + public void Deactivate(Channel channel, Mix mix) + { + new Fetcher().Put("streamRedirections/" + mix.ToDictKey() + "/redirections/" + channel.ToDictKey() + "/isEnabled/false"); + } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/RedirectionStateManager.cs b/SteelSeriesAPI/Sonar/Managers/RedirectionStateManager.cs deleted file mode 100644 index d6e9576..0000000 --- a/SteelSeriesAPI/Sonar/Managers/RedirectionStateManager.cs +++ /dev/null @@ -1,52 +0,0 @@ -using SteelSeriesAPI.Sonar.Exceptions; -using SteelSeriesAPI.Sonar.Enums; -using SteelSeriesAPI.Sonar.Http; -using SteelSeriesAPI.Sonar.Interfaces.Managers; - -using System.Text.Json; - -namespace SteelSeriesAPI.Sonar.Managers; - -public class RedirectionStateManager : IRedirectionStateManager -{ - public bool Get(Channel channel, Mix mix) - { - if (channel == Channel.MASTER) - { - throw new MasterChannelNotSupportedException(); - } - - JsonDocument streamRedirections = new Fetcher().Provide("streamRedirections"); - JsonElement streamChannel = default; - - foreach (var element in streamRedirections.RootElement.EnumerateArray()) - { - if (element.GetProperty("streamRedirectionId").GetString() == mix.ToDictKey()) - { - streamChannel = element; - break; - } - } - - JsonElement status = default; - - foreach (var element in streamChannel.GetProperty("status").EnumerateArray()) - { - if (element.GetProperty("role").GetString() == channel.ToDictKey()) - { - status = element; - break; - } - } - - bool state = status.GetProperty("isEnabled").GetBoolean(); - - return state; - } - - public void Set(bool newState, Channel channel, Mix mix) - { - new Fetcher().Put("streamRedirections/" + mix.ToDictKey() + "/redirections/" + channel.ToDictKey() + - "/isEnabled/" + newState); - } -} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index 4fdb362..9e69fb9 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -1,9 +1,9 @@ -using System.Security.Principal; -using SteelSeriesAPI.Sonar.Enums; -using SteelSeriesAPI.Sonar.Http; -using SteelSeriesAPI.Sonar.Interfaces; +using SteelSeriesAPI.Sonar.Interfaces; +using SteelSeriesAPI.Sonar.Interfaces.Managers; using SteelSeriesAPI.Sonar.Managers; +using System.Security.Principal; + namespace SteelSeriesAPI.Sonar; /// @@ -20,9 +20,9 @@ public class SonarBridge : ISonarBridge public readonly ChatMixManager ChatMix; public readonly ConfigurationManager Configurations; public readonly PlaybackDeviceManager PlaybackDevices; - public readonly RedirectionStateManager RedirectionStates; - public readonly AudienceMonitoringManager AudienceMonitoring; public readonly RoutedProcessManager RoutedProcesses; + public readonly IMixManager Mix; + public readonly AudienceMonitoringManager AudienceMonitoring; public readonly EventManager Events; public SonarBridge() @@ -32,9 +32,9 @@ public SonarBridge() ChatMix = new ChatMixManager(); Configurations = new ConfigurationManager(); PlaybackDevices = new PlaybackDeviceManager(); - RedirectionStates = new RedirectionStateManager(); - AudienceMonitoring = new AudienceMonitoringManager(); RoutedProcesses = new RoutedProcessManager(); + Mix = new MixManager(); + AudienceMonitoring = new AudienceMonitoringManager(); Events = new EventManager(); } From bf9b8930332bfa26f8013848dbe12945cadf2944 Mon Sep 17 00:00:00 2001 From: DataNext Date: Sun, 27 Apr 2025 04:51:01 +0200 Subject: [PATCH 27/47] Reworked entirely the Routed Processes system and added events for it --- .../Sonar/Events/SonarRoutedProcessEvent.cs | 40 ++++ .../RoutedProcessNotFoundException.cs | 8 + .../Managers/IRoutedProcessManager.cs | 57 ++++- SteelSeriesAPI/Sonar/Managers/EventManager.cs | 14 ++ .../Sonar/Managers/RoutedProcessManager.cs | 197 +++++++++++++++--- SteelSeriesAPI/Sonar/Models/RoutedProcess.cs | 2 +- SteelSeriesAPI/Sonar/SonarBridge.cs | 2 +- 7 files changed, 283 insertions(+), 37 deletions(-) create mode 100644 SteelSeriesAPI/Sonar/Events/SonarRoutedProcessEvent.cs create mode 100644 SteelSeriesAPI/Sonar/Exceptions/RoutedProcessNotFoundException.cs diff --git a/SteelSeriesAPI/Sonar/Events/SonarRoutedProcessEvent.cs b/SteelSeriesAPI/Sonar/Events/SonarRoutedProcessEvent.cs new file mode 100644 index 0000000..86271e7 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Events/SonarRoutedProcessEvent.cs @@ -0,0 +1,40 @@ +using SteelSeriesAPI.Sonar.Enums; +using SteelSeriesAPI.Sonar.Http; +using SteelSeriesAPI.Sonar.Exceptions; + +using System.Text.Json; + +namespace SteelSeriesAPI.Sonar.Events; + +public class SonarRoutedProcessEvent : EventArgs +{ + // /AudioDeviceRouting/render/%7B0.0.0.00000000%7D.%7Beb78557a-9882-4205-8014-ad9384173901%7D/4476 + // /AudioDeviceRouting/capture/%7B0.0.1.00000000%7D.%7B989ad130-4b1f-4828-a85a-7aef7fd362b7%7D/4476 + + public int ProcessId { get; init; } + + public Channel NewChannel { get; init; } + + internal SonarRoutedProcessEvent(string deviceId) + { + NewChannel = DeviceIdToChannel(deviceId); + } + + private Channel DeviceIdToChannel(string deviceId) + { + JsonElement audioDeviceRouting = new Fetcher().Provide("AudioDeviceRouting").RootElement; + + foreach (JsonElement device in audioDeviceRouting.EnumerateArray()) + { + if (device.GetProperty("role").GetString() != "none") + { + if (device.GetProperty("deviceId").GetString() == deviceId) + { + return (Channel)ChannelExtensions.FromDictKey(device.GetProperty("role").GetString()!)!; + } + } + } + + throw new RoutedProcessNotFoundException("Event error: Could not find the channel"); + } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/RoutedProcessNotFoundException.cs b/SteelSeriesAPI/Sonar/Exceptions/RoutedProcessNotFoundException.cs new file mode 100644 index 0000000..604deaa --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/RoutedProcessNotFoundException.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class RoutedProcessNotFoundException : Exception +{ + public RoutedProcessNotFoundException() : base("Could not find any routed process") { } + public RoutedProcessNotFoundException(string message) : base(message) { } + public RoutedProcessNotFoundException(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs index e744cc7..2c6f95c 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs @@ -3,19 +3,62 @@ namespace SteelSeriesAPI.Sonar.Interfaces.Managers; -internal interface IRoutedProcessManager +/// +/// Manage routed audio processes +/// +public interface IRoutedProcessManager { /// - /// Get the apps which their audio is redirected to a Sonar + /// Get all audio processes that are routed to Sonar /// - /// The Sonar you want the associated processes + /// A list of + IEnumerable GetAllRoutedProcesses(); + + /// + /// Get all audio processes that are routed to Sonar and currently active + /// + /// A list of + IEnumerable GetAllActiveRoutedProcesses(); + + /// + /// Get all audio processes that are routed to a + /// + /// /// A list of IEnumerable GetRoutedProcesses(Channel channel); /// - /// Redirect the audio of an app to a Sonar + /// Get all audio processes that are routed to a and currently active + /// + /// + /// A list of + IEnumerable GetActiveRoutedProcesses(Channel channel); + + /// + /// Get an audio process that is routed to Sonar whatever its state + /// + /// The id of the process + /// A list of + IEnumerable GetRoutedProcessesById(int processId); + + /// + /// Get an audio process that is routed to Sonar and is active + /// + /// The id of the process + /// + RoutedProcess GetActiveRoutedProcessesById(int processId); + + /// + /// Route an audio process to a specific + /// + /// The id of the process + /// + void RouteProcessToChannel(int processId, Channel channel); + + /// + /// Route an audio process to a specific /// - /// The process ID of the app - /// The Sonar you want to set the app audio - void RouteProcessToChannel(int pId, Channel channel); + /// + /// + void RouteProcessToChannel(RoutedProcess process, Channel channel); } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/EventManager.cs b/SteelSeriesAPI/Sonar/Managers/EventManager.cs index 79f9447..a1d06ad 100644 --- a/SteelSeriesAPI/Sonar/Managers/EventManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/EventManager.cs @@ -36,6 +36,11 @@ public class EventManager /// public event EventHandler OnSonarPlaybackDeviceChange = delegate{ }; + /// + /// Notify when an audio process is routed to a new + /// + public event EventHandler OnSonarRoutedProcessChange = delegate{ }; + /// /// Notify when a redirection state is changed /// @@ -69,6 +74,9 @@ internal void HandleEvent(string path) case SonarPlaybackDeviceEvent sonarRedirectionDeviceEvent: OnSonarPlaybackDeviceChange(this, sonarRedirectionDeviceEvent); break; + case SonarRoutedProcessEvent sonarRoutedProcessEvent: + OnSonarRoutedProcessChange(this, sonarRoutedProcessEvent); + break; case SonarRedirectionStateEvent sonarRedirectionStateEvent: OnSonarRedirectionStateChange(this, sonarRedirectionStateEvent); break; @@ -190,6 +198,12 @@ private EventArgs PathResolver(string path) break; } break; + case "AudioDeviceRouting": + eventArgs = new SonarRoutedProcessEvent(subs[3].Replace("%7B", "{").Replace("%7D", "}")) + { + ProcessId = Convert.ToInt32(subs[4]) + }; + break; default: if (subs[1].StartsWith("chatMix")) { diff --git a/SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs b/SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs index 68c12a9..11b157c 100644 --- a/SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs @@ -1,15 +1,72 @@ using SteelSeriesAPI.Sonar.Exceptions; using SteelSeriesAPI.Sonar.Enums; using SteelSeriesAPI.Sonar.Http; -using SteelSeriesAPI.Sonar.Models; using SteelSeriesAPI.Sonar.Interfaces.Managers; +using SteelSeriesAPI.Sonar.Models; using System.Text.Json; namespace SteelSeriesAPI.Sonar.Managers; -public class RoutedProcessManager : IRoutedProcessManager +internal class RoutedProcessManager : IRoutedProcessManager { + public IEnumerable GetAllRoutedProcesses() + { + JsonElement audioDeviceRouting = new Fetcher().Provide("AudioDeviceRouting").RootElement; + + foreach (JsonElement device in audioDeviceRouting.EnumerateArray()) + { + string role = device.GetProperty("role").GetString()!; + if (role != "none") + { + foreach (JsonElement session in device.GetProperty("audioSessions").EnumerateArray()) + { + int processId = session.GetProperty("processId").GetInt32(); + string processName = session.GetProperty("processName").GetString()!; + string displayName = session.GetProperty("displayName").GetString()!; + + if (processId == 0 && processName == "Idle" && displayName == "Idle") continue; + + RoutedProcessState state = (RoutedProcessState)RoutedProcessStateExtensions.FromDictKey(device.GetProperty("state").GetString()!)!; + Channel channel = (Channel)ChannelExtensions.FromDictKey(role)!; + string processPath = session.GetProperty("id").GetString()!.Split("|")[1].Replace('\\', '/'); + + yield return new RoutedProcess(processId, processName, displayName, state, channel, processPath); + } + } + } + } + + public IEnumerable GetAllActiveRoutedProcesses() + { + JsonElement audioDeviceRouting = new Fetcher().Provide("AudioDeviceRouting").RootElement; + + foreach (JsonElement device in audioDeviceRouting.EnumerateArray()) + { + string role = device.GetProperty("role").GetString()!; + if (role != "none") + { + foreach (JsonElement session in device.GetProperty("audioSessions").EnumerateArray()) + { + if (session.GetProperty("state").GetString() == "active") + { + int processId = session.GetProperty("processId").GetInt32(); + string processName = session.GetProperty("processName").GetString()!; + string displayName = session.GetProperty("displayName").GetString()!; + + if (processId == 0 && processName == "Idle" && displayName == "Idle") continue; + + RoutedProcessState state = RoutedProcessState.ACTIVE; + Channel channel = (Channel)ChannelExtensions.FromDictKey(role)!; + string processPath = session.GetProperty("id").GetString()!.Split("|")[1].Replace('\\', '/'); + + yield return new RoutedProcess(processId, processName, displayName, state, channel, processPath); + } + } + } + } + } + public IEnumerable GetRoutedProcesses(Channel channel) { if (channel == Channel.MASTER) @@ -17,59 +74,143 @@ public IEnumerable GetRoutedProcesses(Channel channel) throw new MasterChannelNotSupportedException(); } - JsonDocument audioDeviceRoutings = new Fetcher().Provide("AudioDeviceRouting"); + JsonElement audioDeviceRouting = new Fetcher().Provide("AudioDeviceRouting").RootElement; + + foreach (JsonElement device in audioDeviceRouting.EnumerateArray()) + { + if (device.GetProperty("role").GetString() == channel.ToDictKey()) + { + foreach (JsonElement session in device.GetProperty("audioSessions").EnumerateArray()) + { + int processId = session.GetProperty("processId").GetInt32(); + string processName = session.GetProperty("processName").GetString()!; + string displayName = session.GetProperty("displayName").GetString()!; + + if (processId == 0 && processName == "Idle" && displayName == "Idle") continue; + + RoutedProcessState state = (RoutedProcessState)RoutedProcessStateExtensions.FromDictKey(device.GetProperty("state").GetString()!)!; + string processPath = session.GetProperty("id").GetString()!.Split("|")[1].Replace('\\', '/'); + + yield return new RoutedProcess(processId, processName, displayName, state, channel, processPath); + } + } + } + } + + public IEnumerable GetActiveRoutedProcesses(Channel channel) + { + if (channel == Channel.MASTER) + { + throw new MasterChannelNotSupportedException(); + } + + JsonElement audioDeviceRouting = new Fetcher().Provide("AudioDeviceRouting").RootElement; - foreach (var element in audioDeviceRoutings.RootElement.EnumerateArray()) + foreach (JsonElement device in audioDeviceRouting.EnumerateArray()) { - if (element.GetProperty("role").GetString() != channel.ToDictKey()) + if (device.GetProperty("role").GetString() == channel.ToDictKey()) { - continue; + foreach (JsonElement session in device.GetProperty("audioSessions").EnumerateArray()) + { + if (session.GetProperty("state").GetString() == "active") + { + int processId = session.GetProperty("processId").GetInt32(); + string processName = session.GetProperty("processName").GetString()!; + string displayName = session.GetProperty("displayName").GetString()!; + + if (processId == 0 && processName == "Idle" && displayName == "Idle") continue; + + RoutedProcessState state = RoutedProcessState.ACTIVE; + string processPath = session.GetProperty("id").GetString()!.Split("|")[1].Replace('\\', '/'); + + yield return new RoutedProcess(processId, processName, displayName, state, channel, processPath); + } + } } + } + } - var audioSessions = element.GetProperty("audioSessions"); + public IEnumerable GetRoutedProcessesById(int processId) + { + JsonElement audioDeviceRouting = new Fetcher().Provide("AudioDeviceRouting").RootElement; - foreach (var session in audioSessions.EnumerateArray()) + foreach (JsonElement device in audioDeviceRouting.EnumerateArray()) + { + string role = device.GetProperty("role").GetString()!; + if (role != "none") { - string id = session.GetProperty("id").GetString().Split("|")[0]; - string processName = session.GetProperty("processName").GetString(); - int pId = session.GetProperty("processId").GetInt32(); - RoutedProcessState state = (RoutedProcessState)RoutedProcessStateExtensions.FromDictKey(session.GetProperty("state").GetString()); - string displayName = session.GetProperty("displayName").GetString(); + foreach (JsonElement session in device.GetProperty("audioSessions").EnumerateArray()) + { + if (session.GetProperty("processId").GetInt32() == processId) + { + string processName = session.GetProperty("processName").GetString()!; + string displayName = session.GetProperty("displayName").GetString()!; + RoutedProcessState state = (RoutedProcessState)RoutedProcessStateExtensions.FromDictKey(device.GetProperty("state").GetString()!)!; + Channel channel = (Channel)ChannelExtensions.FromDictKey(role)!; + string processPath = session.GetProperty("id").GetString()!.Split("|")[1].Replace('\\', '/'); + + yield return new RoutedProcess(processId, processName, displayName, state, channel, processPath); + } + } + } + } + } - if (processName == "Idle" && displayName == "Idle" && state == RoutedProcessState.INACTIVE && pId == 0) + public RoutedProcess GetActiveRoutedProcessesById(int processId) + { + JsonElement audioDeviceRouting = new Fetcher().Provide("AudioDeviceRouting").RootElement; + + foreach (JsonElement device in audioDeviceRouting.EnumerateArray()) + { + string role = device.GetProperty("role").GetString()!; + if (role != "none") + { + foreach (JsonElement session in device.GetProperty("audioSessions").EnumerateArray()) { - continue; + if (session.GetProperty("state").GetString() == "active" && session.GetProperty("processId").GetInt32() == processId) + { + string processName = session.GetProperty("processName").GetString()!; + string displayName = session.GetProperty("displayName").GetString()!; + RoutedProcessState state = RoutedProcessState.ACTIVE; + Channel channel = (Channel)ChannelExtensions.FromDictKey(role)!; + string processPath = session.GetProperty("id").GetString()!.Split("|")[1].Replace('\\', '/'); + + return new RoutedProcess(processId, processName, displayName, state, channel, processPath); + } } - - yield return new RoutedProcess(id, processName, pId, state, displayName); } } + + throw new RoutedProcessNotFoundException("No active processes with id " + processId + " found"); } - - public void RouteProcessToChannel(int pId, Channel channel) + + public void RouteProcessToChannel(int processId, Channel channel) { if (channel == Channel.MASTER) { throw new MasterChannelNotSupportedException(); } - JsonDocument audioDeviceRouting = new Fetcher().Provide("AudioDeviceRouting"); + JsonElement audioDeviceRouting = new Fetcher().Provide("AudioDeviceRouting").RootElement; - foreach (var element in audioDeviceRouting.RootElement.EnumerateArray()) + foreach (JsonElement device in audioDeviceRouting.EnumerateArray()) { - if (element.GetProperty("role").GetString() == channel.ToDictKey()) + if (device.GetProperty("role").GetString() == channel.ToDictKey()) { if (channel == Channel.MIC) { - new Fetcher().Put("AudioDeviceRouting/capture/" + element.GetProperty("deviceId").GetString() + "/" + pId); - break; - } - else - { - new Fetcher().Put("AudioDeviceRouting/render/" + element.GetProperty("deviceId").GetString() + "/" + pId); + new Fetcher().Put("AudioDeviceRouting/capture/" + device.GetProperty("deviceId").GetString() + "/" + processId); break; } + + new Fetcher().Put("AudioDeviceRouting/render/" + device.GetProperty("deviceId").GetString() + "/" + processId); + break; } } } + + public void RouteProcessToChannel(RoutedProcess process, Channel channel) + { + RouteProcessToChannel(process.ProcessId, channel); + } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Models/RoutedProcess.cs b/SteelSeriesAPI/Sonar/Models/RoutedProcess.cs index bcb256f..09c8c97 100644 --- a/SteelSeriesAPI/Sonar/Models/RoutedProcess.cs +++ b/SteelSeriesAPI/Sonar/Models/RoutedProcess.cs @@ -2,4 +2,4 @@ namespace SteelSeriesAPI.Sonar.Models; -public record RoutedProcess(string Id, string ProcessName, int PId, RoutedProcessState State, string DisplayName); \ No newline at end of file +public record RoutedProcess(int ProcessId, string ProcessName, string DisplayName, RoutedProcessState State, Channel Channel, string ProcessPath); \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index 9e69fb9..fed1dce 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -20,7 +20,7 @@ public class SonarBridge : ISonarBridge public readonly ChatMixManager ChatMix; public readonly ConfigurationManager Configurations; public readonly PlaybackDeviceManager PlaybackDevices; - public readonly RoutedProcessManager RoutedProcesses; + public readonly IRoutedProcessManager RoutedProcesses; public readonly IMixManager Mix; public readonly AudienceMonitoringManager AudienceMonitoring; public readonly EventManager Events; From d48e411538dd6a2b47453067bd6bfb5e78306a8a Mon Sep 17 00:00:00 2001 From: DataNext Date: Sun, 27 Apr 2025 17:27:08 +0200 Subject: [PATCH 28/47] Revamped events --- .../Events/SonarAudienceMonitoringEvent.cs | 4 +- ...irectionStateEvent.cs => SonarMixEvent.cs} | 5 +- SteelSeriesAPI/Sonar/Events/SonarMuteEvent.cs | 1 + .../Sonar/Events/SonarPlaybackDeviceEvent.cs | 3 +- .../Sonar/Events/SonarVolumeEvent.cs | 1 + SteelSeriesAPI/Sonar/Managers/EventManager.cs | 81 ++++++++++--------- 6 files changed, 51 insertions(+), 44 deletions(-) rename SteelSeriesAPI/Sonar/Events/{SonarRedirectionStateEvent.cs => SonarMixEvent.cs} (73%) diff --git a/SteelSeriesAPI/Sonar/Events/SonarAudienceMonitoringEvent.cs b/SteelSeriesAPI/Sonar/Events/SonarAudienceMonitoringEvent.cs index 32aec9b..279839d 100644 --- a/SteelSeriesAPI/Sonar/Events/SonarAudienceMonitoringEvent.cs +++ b/SteelSeriesAPI/Sonar/Events/SonarAudienceMonitoringEvent.cs @@ -2,6 +2,6 @@ namespace SteelSeriesAPI.Sonar.Events; public class SonarAudienceMonitoringEvent : EventArgs { - // /streamRedirections/isStreamMonitoringEnabled/bool - public bool AudienceMonitoringState { get; set; } + // /streamRedirections/isStreamMonitoringEnabled/true + public bool NewState { get; set; } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Events/SonarRedirectionStateEvent.cs b/SteelSeriesAPI/Sonar/Events/SonarMixEvent.cs similarity index 73% rename from SteelSeriesAPI/Sonar/Events/SonarRedirectionStateEvent.cs rename to SteelSeriesAPI/Sonar/Events/SonarMixEvent.cs index bdda476..d4fae6c 100644 --- a/SteelSeriesAPI/Sonar/Events/SonarRedirectionStateEvent.cs +++ b/SteelSeriesAPI/Sonar/Events/SonarMixEvent.cs @@ -2,12 +2,13 @@ namespace SteelSeriesAPI.Sonar.Events; -public class SonarRedirectionStateEvent : EventArgs +public class SonarMixEvent : EventArgs { // /streamRedirections/monitoring/redirections/chatRender/isEnabled/true - public bool State { get; set; } + public bool NewState { get; set; } public Channel Channel { get; set; } + public Mix Mix { get; set; } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Events/SonarMuteEvent.cs b/SteelSeriesAPI/Sonar/Events/SonarMuteEvent.cs index 3f2bf5b..1cce0a9 100644 --- a/SteelSeriesAPI/Sonar/Events/SonarMuteEvent.cs +++ b/SteelSeriesAPI/Sonar/Events/SonarMuteEvent.cs @@ -12,5 +12,6 @@ public class SonarMuteEvent : EventArgs public Mode Mode { get; set; } public Channel Channel { get; set; } + public Mix? Mix { get; set; } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Events/SonarPlaybackDeviceEvent.cs b/SteelSeriesAPI/Sonar/Events/SonarPlaybackDeviceEvent.cs index 8e3e76b..5ef3a9a 100644 --- a/SteelSeriesAPI/Sonar/Events/SonarPlaybackDeviceEvent.cs +++ b/SteelSeriesAPI/Sonar/Events/SonarPlaybackDeviceEvent.cs @@ -7,10 +7,11 @@ public class SonarPlaybackDeviceEvent : EventArgs // /classicRedirections/game/deviceId/%7B0.0.0.00000000%7D.%7B1e1ebefc-2c51-4675-aebe-085a06efd255%7D // /streamRedirections/monitoring/deviceId/%7B0.0.0.00000000%7D.%7B1e1ebefc-2c51-4675-aebe-085a06efd255%7D - public string RedirectionDeviceId { get; set; } + public string PlaybackDeviceId { get; set; } public Mode Mode { get; set; } public Channel? Device { get; set; } + public Mix? Channel { get; set; } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Events/SonarVolumeEvent.cs b/SteelSeriesAPI/Sonar/Events/SonarVolumeEvent.cs index 65d3098..e00607e 100644 --- a/SteelSeriesAPI/Sonar/Events/SonarVolumeEvent.cs +++ b/SteelSeriesAPI/Sonar/Events/SonarVolumeEvent.cs @@ -12,5 +12,6 @@ public class SonarVolumeEvent : EventArgs public Mode Mode { get; set; } public Channel Channel { get; set; } + public Mix? Mix { get; set; } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/EventManager.cs b/SteelSeriesAPI/Sonar/Managers/EventManager.cs index a1d06ad..e20a657 100644 --- a/SteelSeriesAPI/Sonar/Managers/EventManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/EventManager.cs @@ -4,25 +4,28 @@ namespace SteelSeriesAPI.Sonar.Managers; +/// +/// Manage the different Sonar Events +/// public class EventManager { /// - /// Notify when mode changed + /// Notify when the current changed /// public event EventHandler OnSonarModeChange = delegate{ }; /// - /// Notify when a volume of a channel changed + /// Notify when the volume of a has changed /// public event EventHandler OnSonarVolumeChange = delegate{ }; /// - /// Notify when a channel is un/muted + /// Notify when a gets un/muted /// public event EventHandler OnSonarMuteChange = delegate{ }; /// - /// Notify when the config of a channel is changed + /// Notify when the config of a is changed /// public event EventHandler OnSonarConfigChange = delegate{ }; @@ -32,7 +35,7 @@ public class EventManager public event EventHandler OnSonarChatMixChange = delegate{ }; /// - /// Notify when a playback device of a channel is changed + /// Notify when the playback device of a is changed /// public event EventHandler OnSonarPlaybackDeviceChange = delegate{ }; @@ -42,9 +45,9 @@ public class EventManager public event EventHandler OnSonarRoutedProcessChange = delegate{ }; /// - /// Notify when a redirection state is changed + /// Notify when a gets de/activated /// - public event EventHandler OnSonarRedirectionStateChange = delegate{ }; + public event EventHandler OnSonarMixChange = delegate{ }; /// /// Notify when the audience monitoring state is changed @@ -71,14 +74,14 @@ internal void HandleEvent(string path) case SonarChatMixEvent sonarChatMixEvent: OnSonarChatMixChange(this, sonarChatMixEvent); break; - case SonarPlaybackDeviceEvent sonarRedirectionDeviceEvent: - OnSonarPlaybackDeviceChange(this, sonarRedirectionDeviceEvent); + case SonarPlaybackDeviceEvent sonarPlaybackDeviceEvent: + OnSonarPlaybackDeviceChange(this, sonarPlaybackDeviceEvent); break; case SonarRoutedProcessEvent sonarRoutedProcessEvent: OnSonarRoutedProcessChange(this, sonarRoutedProcessEvent); break; - case SonarRedirectionStateEvent sonarRedirectionStateEvent: - OnSonarRedirectionStateChange(this, sonarRedirectionStateEvent); + case SonarMixEvent sonarMixEvent: + OnSonarMixChange(this, sonarMixEvent); break; case SonarAudienceMonitoringEvent sonarAudienceMonitoringEvent: OnSonarAudienceMonitoringChange(this, sonarAudienceMonitoringEvent); @@ -89,13 +92,13 @@ internal void HandleEvent(string path) private EventArgs PathResolver(string path) { string[] subs = path.Split("/"); - EventArgs eventArgs = null; + EventArgs eventArgs = null!; switch (subs[1]) { case "mode": - eventArgs = new SonarModeEvent() - { NewMode = (Mode)ModeExtensions.FromDictKey(subs[2], ModeMapChoice.StreamDict) }; + eventArgs = new SonarModeEvent + { NewMode = (Mode)ModeExtensions.FromDictKey(subs[2], ModeMapChoice.StreamDict)! }; break; case "volumeSettings": switch (subs[2]) @@ -104,19 +107,19 @@ private EventArgs PathResolver(string path) switch (subs[4]) { case "Volume": - eventArgs = new SonarVolumeEvent() + eventArgs = new SonarVolumeEvent { Volume = double.Parse(subs[5], CultureInfo.InvariantCulture.NumberFormat), Mode = Mode.CLASSIC, - Channel = (Channel)ChannelExtensions.FromDictKey(subs[3], ChannelMapChoice.HttpDict) + Channel = (Channel)ChannelExtensions.FromDictKey(subs[3], ChannelMapChoice.HttpDict)! }; break; case"Mute": - eventArgs = new SonarMuteEvent() + eventArgs = new SonarMuteEvent { Muted = Convert.ToBoolean(subs[5]), Mode = Mode.CLASSIC, - Channel = (Channel)ChannelExtensions.FromDictKey(subs[3], ChannelMapChoice.HttpDict) + Channel = (Channel)ChannelExtensions.FromDictKey(subs[3], ChannelMapChoice.HttpDict)! }; break; } @@ -125,21 +128,21 @@ private EventArgs PathResolver(string path) switch (subs[5]) { case "volume": - eventArgs = new SonarVolumeEvent() + eventArgs = new SonarVolumeEvent { Volume = double.Parse(subs[6], CultureInfo.InvariantCulture.NumberFormat), Mode = Mode.STREAMER, - Channel = (Channel)ChannelExtensions.FromDictKey(subs[4], ChannelMapChoice.HttpDict), - Mix = (Mix)MixExtensions.FromDictKey(subs[3]) + Channel = (Channel)ChannelExtensions.FromDictKey(subs[4], ChannelMapChoice.HttpDict)!, + Mix = (Mix)MixExtensions.FromDictKey(subs[3])! }; break; case "isMuted": - eventArgs = new SonarMuteEvent() + eventArgs = new SonarMuteEvent { Muted = Convert.ToBoolean(subs[6]), Mode = Mode.STREAMER, - Channel = (Channel)ChannelExtensions.FromDictKey(subs[4], ChannelMapChoice.HttpDict), - Mix = (Mix)MixExtensions.FromDictKey(subs[3]) + Channel = (Channel)ChannelExtensions.FromDictKey(subs[4], ChannelMapChoice.HttpDict)!, + Mix = (Mix)MixExtensions.FromDictKey(subs[3])! }; break; } @@ -149,21 +152,21 @@ private EventArgs PathResolver(string path) case "configs": if (!(subs.Length < 3)) { - eventArgs = new SonarConfigEvent() { ConfigId = subs[2] }; + eventArgs = new SonarConfigEvent { ConfigId = subs[2] }; } break; case "classicRedirections": - eventArgs = new SonarPlaybackDeviceEvent() + eventArgs = new SonarPlaybackDeviceEvent { - RedirectionDeviceId = subs[4].Replace("%7B", "{").Replace("%7D", "}"), + PlaybackDeviceId = subs[4].Replace("%7B", "{").Replace("%7D", "}"), Mode = Mode.CLASSIC, - Device = (Channel)ChannelExtensions.FromDictKey(subs[2], ChannelMapChoice.ChannelDict) + Device = (Channel)ChannelExtensions.FromDictKey(subs[2], ChannelMapChoice.ChannelDict)! }; break; case "streamRedirections": if (subs[2] == "isStreamMonitoringEnabled") { - eventArgs = new SonarAudienceMonitoringEvent() { AudienceMonitoringState = Convert.ToBoolean(subs[3]) }; + eventArgs = new SonarAudienceMonitoringEvent { NewState = Convert.ToBoolean(subs[3]) }; break; } @@ -172,28 +175,28 @@ private EventArgs PathResolver(string path) case "deviceId": if (subs[2] == "mic") { - eventArgs = new SonarPlaybackDeviceEvent() + eventArgs = new SonarPlaybackDeviceEvent { - RedirectionDeviceId = subs[4].Replace("%7B", "{").Replace("%7D", "}"), + PlaybackDeviceId = subs[4].Replace("%7B", "{").Replace("%7D", "}"), Mode = Mode.STREAMER, Device = Channel.MIC }; break; } - eventArgs = new SonarPlaybackDeviceEvent() + eventArgs = new SonarPlaybackDeviceEvent { - RedirectionDeviceId = subs[4].Replace("%7B", "{").Replace("%7D", "}"), + PlaybackDeviceId = subs[4].Replace("%7B", "{").Replace("%7D", "}"), Mode = Mode.STREAMER, - Channel = (Mix)MixExtensions.FromDictKey(subs[2]) + Channel = (Mix)MixExtensions.FromDictKey(subs[2])! }; break; case "redirections": - eventArgs = new SonarRedirectionStateEvent() + eventArgs = new SonarMixEvent { - State = Convert.ToBoolean(subs[6]), - Channel = (Channel)ChannelExtensions.FromDictKey(subs[4]), - Mix = (Mix)MixExtensions.FromDictKey(subs[2]) + NewState = Convert.ToBoolean(subs[6]), + Channel = (Channel)ChannelExtensions.FromDictKey(subs[4])!, + Mix = (Mix)MixExtensions.FromDictKey(subs[2])! }; break; } @@ -207,7 +210,7 @@ private EventArgs PathResolver(string path) default: if (subs[1].StartsWith("chatMix")) { - eventArgs = new SonarChatMixEvent() { Balance = Convert.ToDouble(subs[1].Split("=")[1], CultureInfo.InvariantCulture) }; + eventArgs = new SonarChatMixEvent { Balance = Convert.ToDouble(subs[1].Split("=")[1], CultureInfo.InvariantCulture) }; } break; } From a92a13761f1c0ca6c23512e528098a43432c7ab8 Mon Sep 17 00:00:00 2001 From: DataNext Date: Sun, 27 Apr 2025 17:43:18 +0200 Subject: [PATCH 29/47] Revamped Mode Manager --- .../Sonar/Interfaces/Managers/IModeManager.cs | 11 +++++++---- SteelSeriesAPI/Sonar/Managers/ModeManager.cs | 4 ++-- SteelSeriesAPI/Sonar/SonarBridge.cs | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IModeManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IModeManager.cs index f01f412..d827430 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/Managers/IModeManager.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IModeManager.cs @@ -2,17 +2,20 @@ namespace SteelSeriesAPI.Sonar.Interfaces.Managers; -internal interface IModeManager +/// +/// Manage the Sonar +/// +public interface IModeManager { /// - /// Get the current mode used by Sonar + /// Get the current used by Sonar /// - /// A , either Classic or Streamer + /// Mode Get(); /// /// Set the Sonar will be using /// - /// The you want to set + /// void Set(Mode mode); } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/ModeManager.cs b/SteelSeriesAPI/Sonar/Managers/ModeManager.cs index d393937..f8ce852 100644 --- a/SteelSeriesAPI/Sonar/Managers/ModeManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/ModeManager.cs @@ -4,13 +4,13 @@ namespace SteelSeriesAPI.Sonar.Managers; -public class ModeManager : IModeManager +internal class ModeManager : IModeManager { public Mode Get() { string mode = new Fetcher().Provide("mode").RootElement.ToString(); - return (Mode)ModeExtensions.FromDictKey(mode, ModeMapChoice.StreamDict); + return (Mode)ModeExtensions.FromDictKey(mode, ModeMapChoice.StreamDict)!; } public void Set(Mode mode) diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index fed1dce..9cd7089 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -15,7 +15,7 @@ public class SonarBridge : ISonarBridge private ISonarSocket _sonarSocket; - public readonly ModeManager Mode; + public readonly IModeManager Mode; public readonly VolumeSettingsManager VolumeSettings; public readonly ChatMixManager ChatMix; public readonly ConfigurationManager Configurations; From 66ee788366069667a1fcb640755806210693c727 Mon Sep 17 00:00:00 2001 From: DataNext Date: Sun, 27 Apr 2025 17:52:20 +0200 Subject: [PATCH 30/47] Revamped VolumeSettings Manager --- .../Managers/IVolumeSettingsManager.cs | 25 +++++++++++-------- .../Sonar/Managers/VolumeSettingsManager.cs | 2 +- SteelSeriesAPI/Sonar/SonarBridge.cs | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IVolumeSettingsManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IVolumeSettingsManager.cs index e23f041..e782cf0 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/Managers/IVolumeSettingsManager.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IVolumeSettingsManager.cs @@ -2,35 +2,38 @@ namespace SteelSeriesAPI.Sonar.Interfaces.Managers; -internal interface IVolumeSettingsManager +/// +/// Manage the volumes and muted state of each +/// +public interface IVolumeSettingsManager { /// /// Get the volume of a Sonar /// - /// The Sonar you want the volume + /// The Sonar you want the volume of /// The volume of the channel in double, value between 0 and 1 double GetVolume(Channel channel); /// /// Get the volume of a Steamer mode Sonar /// - /// The Sonar you want the volume - /// The Sonar you want the volume + /// The Sonar of the you want the volume of + /// The Sonar you want the volume of /// The volume of the mix in double, value between 0 and 1 double GetVolume(Channel channel, Mix mix); /// /// Get the mute state of a Sonar /// - /// The Sonar you want the mute state + /// The Sonar you want the mute state of /// The mute state, a boolean bool GetMute(Channel channel); /// /// Get the mute state of a Streamer mode Sonar /// - /// The Sonar you want the mute state - /// The Sonar you want the mute state + /// The Sonar of the you want the mute state of + /// The Sonar you want the mute state of /// The mute state, a boolean bool GetMute(Channel channel, Mix mix); @@ -38,15 +41,15 @@ internal interface IVolumeSettingsManager /// Set the volume of a Sonar /// /// The volume you want to set, between 1 and 0 - /// The you want to change the volume + /// The you want to change the volume of void SetVolume(double vol, Channel channel); /// /// Set the volume of a Streamer mode Sonar /// /// The volume you want to set, between 1 and 0 - /// The you want to change the volume - /// The you want to change the volume + /// The of the you want to change the volume of + /// The you want to change the volume of void SetVolume(double vol, Channel channel, Mix mix); /// @@ -60,7 +63,7 @@ internal interface IVolumeSettingsManager /// Mute or unmute a Streamer mode Sonar /// /// The new muted state - /// The you want to un/mute + /// The of the you want to un/mute /// The you want to un/mute void SetMute(bool mute, Channel channel, Mix mix); } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs b/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs index 01520aa..8a72511 100644 --- a/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs @@ -7,7 +7,7 @@ namespace SteelSeriesAPI.Sonar.Managers; -public class VolumeSettingsManager : IVolumeSettingsManager +internal class VolumeSettingsManager : IVolumeSettingsManager { // volume = 0,00000000 <-- 8 decimal max public double GetVolume(Channel channel) diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index 9cd7089..1796c95 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -16,7 +16,7 @@ public class SonarBridge : ISonarBridge private ISonarSocket _sonarSocket; public readonly IModeManager Mode; - public readonly VolumeSettingsManager VolumeSettings; + public readonly IVolumeSettingsManager VolumeSettings; public readonly ChatMixManager ChatMix; public readonly ConfigurationManager Configurations; public readonly PlaybackDeviceManager PlaybackDevices; From 21dde972e11dad5ac12c91df445b25669bf2dba2 Mon Sep 17 00:00:00 2001 From: DataNext Date: Sun, 27 Apr 2025 18:21:14 +0200 Subject: [PATCH 31/47] Revamped ChatMix manager --- SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs | 2 +- SteelSeriesAPI/Sonar/Managers/ChatMixManager.cs | 2 +- SteelSeriesAPI/Sonar/SonarBridge.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs index da719c8..6e3dc1f 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs @@ -1,6 +1,6 @@ namespace SteelSeriesAPI.Sonar.Interfaces.Managers; -internal interface IChatMixManager +public interface IChatMixManager { /// /// Get the actual ChatMix balance value diff --git a/SteelSeriesAPI/Sonar/Managers/ChatMixManager.cs b/SteelSeriesAPI/Sonar/Managers/ChatMixManager.cs index dbbf204..06c0a71 100644 --- a/SteelSeriesAPI/Sonar/Managers/ChatMixManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/ChatMixManager.cs @@ -7,7 +7,7 @@ namespace SteelSeriesAPI.Sonar.Managers; -public class ChatMixManager : IChatMixManager +internal class ChatMixManager : IChatMixManager { public double GetBalance() { diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index 1796c95..fef806b 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -17,7 +17,7 @@ public class SonarBridge : ISonarBridge public readonly IModeManager Mode; public readonly IVolumeSettingsManager VolumeSettings; - public readonly ChatMixManager ChatMix; + public readonly IChatMixManager ChatMix; public readonly ConfigurationManager Configurations; public readonly PlaybackDeviceManager PlaybackDevices; public readonly IRoutedProcessManager RoutedProcesses; From 4edf86c971f1645c227b76ebb978a97866d63745 Mon Sep 17 00:00:00 2001 From: DataNext Date: Sun, 27 Apr 2025 19:23:11 +0200 Subject: [PATCH 32/47] Reworked Configuration manager --- .../Managers/IConfigurationManager.cs | 25 +++-- .../Sonar/Managers/ConfigurationManager.cs | 101 ++++++++++-------- SteelSeriesAPI/Sonar/SonarBridge.cs | 2 +- 3 files changed, 72 insertions(+), 56 deletions(-) diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IConfigurationManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IConfigurationManager.cs index 204698a..3b865e4 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/Managers/IConfigurationManager.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IConfigurationManager.cs @@ -3,35 +3,38 @@ namespace SteelSeriesAPI.Sonar.Interfaces.Managers; -internal interface IConfigurationManager +/// +/// Manage audio configurations for each +/// +public interface IConfigurationManager { /// - /// Get all audio configurations from Sonar + /// Get all audio configurations of Sonar /// /// An IEnumerable of IEnumerable GetAllAudioConfigurations(); /// - /// Get all audio configurations of a from Sonar + /// Get all audio configurations of a /// - /// The channel you want the configs - /// An IEnumerable of ordered alphabetically + /// The channel you want the configs of + /// An IEnumerable of IEnumerable GetAudioConfigurations(Channel channel); /// - /// Get a specific audio configuration from Sonar + /// Get the current audio configuration of a /// - /// The id of the config + /// The channel you want the current config /// A - SonarAudioConfiguration GetAudioConfiguration(string configId); + SonarAudioConfiguration GetSelectedAudioConfiguration(Channel channel); /// - /// Get the current audio configuration of a chosen + /// Get a specific audio configuration from Sonar /// - /// The channel you want the current config + /// The id of the config /// A - SonarAudioConfiguration GetSelectedAudioConfiguration(Channel channel); + SonarAudioConfiguration GetAudioConfiguration(string configId); /// /// Set the config of a Sonar by giving its id diff --git a/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs b/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs index 6baecaf..1cf0cd5 100644 --- a/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs @@ -8,19 +8,19 @@ namespace SteelSeriesAPI.Sonar.Managers; -public class ConfigurationManager : IConfigurationManager +internal class ConfigurationManager : IConfigurationManager { public IEnumerable GetAllAudioConfigurations() { - JsonDocument configs = new Fetcher().Provide("configs"); + JsonElement configs = new Fetcher().Provide("configs").RootElement; - foreach (var element in configs.RootElement.EnumerateArray()) + foreach (JsonElement config in configs.EnumerateArray()) { - string vDevice = element.GetProperty("virtualAudioDevice").GetString(); - string id = element.GetProperty("id").GetString(); - string name = element.GetProperty("name").GetString(); + string device = config.GetProperty("virtualAudioDevice").GetString()!; + string id = config.GetProperty("id").GetString()!; + string name = config.GetProperty("name").GetString()!; - yield return new SonarAudioConfiguration(id, name, (Channel)ChannelExtensions.FromDictKey(vDevice)); + yield return new SonarAudioConfiguration(id, name, (Channel)ChannelExtensions.FromDictKey(device)!); } } @@ -31,68 +31,81 @@ public IEnumerable GetAudioConfigurations(Channel chann throw new MasterChannelNotSupportedException(); } - IEnumerable configs = GetAllAudioConfigurations(); - List channelConfigs = new List(); - - foreach (var config in configs) + JsonElement configs = new Fetcher().Provide("configs").RootElement; + + foreach (JsonElement config in configs.EnumerateArray()) { - if (config.AssociatedChannel == channel) + string device = config.GetProperty("virtualAudioDevice").GetString()!; + if (device == channel.ToDictKey()) { - channelConfigs.Add(config); + string id = config.GetProperty("id").GetString()!; + string name = config.GetProperty("name").GetString()!; + + yield return new SonarAudioConfiguration(id, name, (Channel)ChannelExtensions.FromDictKey(device)!); } } - - return channelConfigs.OrderBy(s => s.Name); } - - public SonarAudioConfiguration GetAudioConfiguration(string configId) + + public SonarAudioConfiguration GetSelectedAudioConfiguration(Channel channel) { - IEnumerable configs = GetAllAudioConfigurations(); - SonarAudioConfiguration sonarConfig = null; + if (channel == Channel.MASTER) + { + throw new MasterChannelNotSupportedException(); + } - foreach (var config in configs) + JsonElement selectedConfigs = new Fetcher().Provide("configs/selected").RootElement; + + foreach (JsonElement config in selectedConfigs.EnumerateArray()) { - if (config.Id == configId) + var device = config.GetProperty("virtualAudioDevice").GetString()!; + if (device == channel.ToDictKey()) { - sonarConfig = config; - break; + string id = config.GetProperty("id").GetString()!; + string name = config.GetProperty("name").GetString()!; + + return new SonarAudioConfiguration(id, name, (Channel)ChannelExtensions.FromDictKey(device)!); } } - return sonarConfig; + throw new ChannelNotFoundException(); } - public SonarAudioConfiguration GetSelectedAudioConfiguration(Channel channel) + public SonarAudioConfiguration GetAudioConfiguration(string configId) { - if (channel == Channel.MASTER) - { - throw new MasterChannelNotSupportedException(); - } - - JsonDocument selectedConfigs = new Fetcher().Provide("configs/selected"); - JsonElement sConfig = default; + JsonElement configs = new Fetcher().Provide("configs").RootElement; - foreach (var config in selectedConfigs.RootElement.EnumerateArray()) + foreach (JsonElement config in configs.EnumerateArray()) { - if (config.GetProperty("virtualAudioDevice").GetString() == channel.ToDictKey()) + string id = config.GetProperty("id").GetString()!; + if (id == configId) { - sConfig = config; - break; + string device = config.GetProperty("virtualAudioDevice").GetString()!; + string name = config.GetProperty("name").GetString()!; + + return new SonarAudioConfiguration(id, name, (Channel)ChannelExtensions.FromDictKey(device)!); } } - - string id = sConfig.GetProperty("id").GetString(); - string name = sConfig.GetProperty("name").GetString(); - string vDevice = sConfig.GetProperty("virtualAudioDevice").GetString(); - - return new SonarAudioConfiguration(id, name, (Channel)ChannelExtensions.FromDictKey(vDevice)); + + throw new ConfigNotFoundException($"No audio configuration found with this id: {configId}"); } public void SetConfig(string configId) { - if (string.IsNullOrEmpty(configId)) throw new ConfigNotFoundException($"No audio configuration found with this id: {configId}"); + if (string.IsNullOrEmpty(configId)) throw new ConfigNotFoundException("Id can't be null or empty"); + + JsonElement configs = new Fetcher().Provide("configs").RootElement; - new Fetcher().Put("configs/" + configId + "/select"); + foreach (JsonElement config in configs.EnumerateArray()) + { + string id = config.GetProperty("id").GetString()!; + if (id == configId) + { + new Fetcher().Put("configs/" + configId + "/select"); + return; + } + } + + throw new ConfigNotFoundException($"No audio configuration found with this id: {configId}"); } public void SetConfig(SonarAudioConfiguration config) diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index fef806b..c26ed47 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -18,7 +18,7 @@ public class SonarBridge : ISonarBridge public readonly IModeManager Mode; public readonly IVolumeSettingsManager VolumeSettings; public readonly IChatMixManager ChatMix; - public readonly ConfigurationManager Configurations; + public readonly IConfigurationManager Configurations; public readonly PlaybackDeviceManager PlaybackDevices; public readonly IRoutedProcessManager RoutedProcesses; public readonly IMixManager Mix; From 01b8da6698d3c27274a367bfc3f6ede54d02c61d Mon Sep 17 00:00:00 2001 From: DataNext Date: Sun, 27 Apr 2025 19:26:37 +0200 Subject: [PATCH 33/47] Revamped Audience Monitoring Manager --- .../Sonar/Interfaces/Managers/IAudienceMonitoringManager.cs | 4 ++++ SteelSeriesAPI/Sonar/Managers/AudienceMonitoringManager.cs | 2 +- SteelSeriesAPI/Sonar/SonarBridge.cs | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IAudienceMonitoringManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IAudienceMonitoringManager.cs index 87e0dad..69c20d9 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/Managers/IAudienceMonitoringManager.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IAudienceMonitoringManager.cs @@ -1,5 +1,8 @@ namespace SteelSeriesAPI.Sonar.Interfaces.Managers; +/// +/// Manage the Audience Monitoring feature of the streamer mode +/// public interface IAudienceMonitoringManager { /// @@ -9,6 +12,7 @@ public interface IAudienceMonitoringManager bool GetState(); /// + /// Activate or deactivate Audience Monitoring
/// Listen to what your audience hear ///
/// The new state, un/muted diff --git a/SteelSeriesAPI/Sonar/Managers/AudienceMonitoringManager.cs b/SteelSeriesAPI/Sonar/Managers/AudienceMonitoringManager.cs index d0be916..4378dcf 100644 --- a/SteelSeriesAPI/Sonar/Managers/AudienceMonitoringManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/AudienceMonitoringManager.cs @@ -5,7 +5,7 @@ namespace SteelSeriesAPI.Sonar.Managers; -public class AudienceMonitoringManager : IAudienceMonitoringManager +internal class AudienceMonitoringManager : IAudienceMonitoringManager { public bool GetState() { diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index c26ed47..e90ba4c 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -22,7 +22,7 @@ public class SonarBridge : ISonarBridge public readonly PlaybackDeviceManager PlaybackDevices; public readonly IRoutedProcessManager RoutedProcesses; public readonly IMixManager Mix; - public readonly AudienceMonitoringManager AudienceMonitoring; + public readonly IAudienceMonitoringManager AudienceMonitoring; public readonly EventManager Events; public SonarBridge() From 7f120f051e1e6f05ae8d9ad83606174ce92e2bed Mon Sep 17 00:00:00 2001 From: DataNext Date: Mon, 28 Apr 2025 01:01:12 +0200 Subject: [PATCH 34/47] Reworked entirely the Playback device manager --- .../ChannelNoStreamerSupportException.cs | 8 + .../MicChannelSupportOnlyException.cs | 8 - .../PlaybackDeviceDataFlowException.cs | 8 + .../PlaybackDeviceNotFoundException.cs | 8 + .../Managers/IPlaybackDeviceManager.cs | 106 +++-- .../Sonar/Managers/PlaybackDeviceManager.cs | 393 ++++++++++++------ SteelSeriesAPI/Sonar/Models/PlaybackDevice.cs | 4 +- SteelSeriesAPI/Sonar/SonarBridge.cs | 2 +- 8 files changed, 360 insertions(+), 177 deletions(-) create mode 100644 SteelSeriesAPI/Sonar/Exceptions/ChannelNoStreamerSupportException.cs delete mode 100644 SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnlyException.cs create mode 100644 SteelSeriesAPI/Sonar/Exceptions/PlaybackDeviceDataFlowException.cs create mode 100644 SteelSeriesAPI/Sonar/Exceptions/PlaybackDeviceNotFoundException.cs diff --git a/SteelSeriesAPI/Sonar/Exceptions/ChannelNoStreamerSupportException.cs b/SteelSeriesAPI/Sonar/Exceptions/ChannelNoStreamerSupportException.cs new file mode 100644 index 0000000..db31ce5 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/ChannelNoStreamerSupportException.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class ChannelNoStreamerSupportException : Exception +{ + public ChannelNoStreamerSupportException() : base("Only the Mic Channel is supported in this case.") { } + public ChannelNoStreamerSupportException(string message) : base(message) { } + public ChannelNoStreamerSupportException(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnlyException.cs b/SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnlyException.cs deleted file mode 100644 index ab83946..0000000 --- a/SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnlyException.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace SteelSeriesAPI.Sonar.Exceptions; - -public class MicChannelSupportOnlyException : Exception -{ - public MicChannelSupportOnlyException() : base("Only the Mic Channel is supported in this case.") { } - public MicChannelSupportOnlyException(string message) : base(message) { } - public MicChannelSupportOnlyException(string message, Exception innerException) : base(message, innerException) { } -} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/PlaybackDeviceDataFlowException.cs b/SteelSeriesAPI/Sonar/Exceptions/PlaybackDeviceDataFlowException.cs new file mode 100644 index 0000000..3fb0027 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/PlaybackDeviceDataFlowException.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class PlaybackDeviceDataFlowException : Exception +{ + public PlaybackDeviceDataFlowException() : base("DataFlows do not match.") { } + public PlaybackDeviceDataFlowException(string message) : base(message) { } + public PlaybackDeviceDataFlowException(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/PlaybackDeviceNotFoundException.cs b/SteelSeriesAPI/Sonar/Exceptions/PlaybackDeviceNotFoundException.cs new file mode 100644 index 0000000..25296e7 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/PlaybackDeviceNotFoundException.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class PlaybackDeviceNotFoundException : Exception +{ + public PlaybackDeviceNotFoundException() : base("Could not find corresponding playback device") { } + public PlaybackDeviceNotFoundException(string message) : base(message) { } + public PlaybackDeviceNotFoundException(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IPlaybackDeviceManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IPlaybackDeviceManager.cs index af31262..b761e5e 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/Managers/IPlaybackDeviceManager.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IPlaybackDeviceManager.cs @@ -3,66 +3,104 @@ namespace SteelSeriesAPI.Sonar.Interfaces.Managers; -internal interface IPlaybackDeviceManager +/// +/// Manage the playback device of each +/// +public interface IPlaybackDeviceManager { + + + /// + /// Get all the Playback Devices (Windows devices) + /// + /// A list of + IEnumerable GetAllPlaybackDevices(); + /// - /// Get all the in/output Redirection Devices (Windows devices) + /// Get all output playback devices /// - /// The DataFlow of the channel (In/Output) /// A list of - IEnumerable GetPlaybackDevices(DataFlow _dataFlow); + IEnumerable GetOutputPlaybackDevices(); /// - /// Get a Redirection Channel using its ID + /// Get all input playback devices /// - /// The ID of the Redirection Channel + /// A list of + IEnumerable GetInputPlaybackDevices(); + + /// + /// Get the playback device of a + /// + /// /// - PlaybackDevice GetPlaybackDevice(string deviceId); + PlaybackDevice GetPlaybackDevice(Channel channel); /// - /// Get the current Redirection Channel of a Sonar + /// Get the playback device of a depending on the mode
+ /// Mainly used to get the Streamer Mode Mic ///
- /// The Sonar you want the redirection channel + /// + /// /// - PlaybackDevice GetClassicPlaybackDevice(Channel channel); + PlaybackDevice GetPlaybackDevice(Channel channel, Mode mode); /// - /// Get the current Redirection Channel of a Streamer mode Sonar + /// Get the playback device of a /// - /// The Sonar you want the redirection channel - /// A - PlaybackDevice GetStreamerPlaybackDevice(Mix mix); + /// + /// + PlaybackDevice GetPlaybackDevice(Mix mix); /// - /// Get the current Redirection Channel of the Streamer mode Sonar + /// Get a playback device using its id /// - /// The Sonar you want to change the redirection channel + /// The id of the device /// - /// should be set to for it to work - PlaybackDevice GetStreamerPlaybackDevice(Channel channel = Channel.MIC); + PlaybackDevice GetPlaybackDevice(string deviceId); + + /// + /// Set the playback device of a + /// + /// The id of the device + /// + void SetPlaybackDevice(string deviceId, Channel channel); + + /// + /// Set the playback device of a depending on the mode
+ /// Mainly used to change the playback device of the Streamer Mode + ///
+ /// The id of the device + /// + /// + void SetPlaybackDevice(string deviceId, Channel channel, Mode mode); + + /// + /// Set the playback device of a + /// + /// The id of the device + /// + void SetPlaybackDevice(string deviceId, Mix mix); /// - /// Set the Redirection Channel of a Sonar using its ID + /// Set the playback device of a /// - /// The id of the new Redirection Channel - /// The Sonar you want to change the Redirection Channel - void SetClassicPlaybackDevice(string deviceId, Channel channel); + /// + /// + void SetPlaybackDevice(PlaybackDevice device, Channel channel); /// - /// Set the Redirection Channel of a Streamer mode Sonar using its ID + /// Set the playback device of a depending on the mode
+ /// Mainly used to change the playback device of the Streamer Mode ///
- /// The id of the new Redirection Channel - /// The Sonar you want to change the Redirection Channel - void SetStreamerPlaybackDevice(string deviceId, Mix mix); + /// + /// + /// + void SetPlaybackDevice(PlaybackDevice device, Channel channel, Mode mode); /// - /// Set the Redirection Channel of the Streamer mode Sonar using its ID + /// Set the playback device of a /// - /// The id of the new Redirection Channel - /// The Sonar you want to change the redirection channel - /// should be set to for it to work - void SetStreamerPlaybackDevice(string deviceId, Channel channel = Channel.MIC); - void SetClassicPlaybackDevice(PlaybackDevice playbackDevice, Channel channel); - void SetStreamerPlaybackDevice(PlaybackDevice playbackDevice, Mix mix); - void SetStreamerPlaybackDevice(PlaybackDevice playbackDevice, Channel channel = Channel.MIC); + /// + /// + void SetPlaybackDevice(PlaybackDevice device, Mix mix); } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs b/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs index 9aa1a50..02d93dd 100644 --- a/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs @@ -1,222 +1,351 @@ using System.Collections; -using SteelSeriesAPI.Sonar.Interfaces.Managers; +using SteelSeriesAPI.Sonar.Exceptions; using SteelSeriesAPI.Sonar.Enums; using SteelSeriesAPI.Sonar.Http; +using SteelSeriesAPI.Sonar.Interfaces.Managers; using SteelSeriesAPI.Sonar.Models; using System.Text.Json; -using SteelSeriesAPI.Sonar.Exceptions; namespace SteelSeriesAPI.Sonar.Managers; -public class PlaybackDeviceManager : IPlaybackDeviceManager +internal class PlaybackDeviceManager : IPlaybackDeviceManager { - public IEnumerable GetPlaybackDevices(DataFlow _dataFlow) + public IEnumerable GetAllPlaybackDevices() { - JsonDocument audioDevices = new Fetcher().Provide("audioDevices"); - // JsonDocument classicRedirections = new HttpProvider("classicRedirections").Provide(); - // JsonDocument streamRedirections = new HttpProvider("streamRedirections").Provide(); - - foreach (var element in audioDevices.RootElement.EnumerateArray()) + JsonElement audioDevices = new Fetcher().Provide("audioDevices").RootElement; + + foreach (JsonElement device in audioDevices.EnumerateArray()) { - if (element.GetProperty("role").GetString() != "none") + if (device.GetProperty("role").GetString() == "none") { - continue; + string id = device.GetProperty("id").GetString()!; + string name = device.GetProperty("friendlyName").GetString()!; + DataFlow dataFlow = (DataFlow)DataFlowExtensions.FromDictKey(device.GetProperty("dataFlow").GetString()!)!; + List> channels = new List>(); + List mixes = new List(); + + GetChannelsAndMixes(id, channels, mixes); + + yield return new PlaybackDevice(id, name, dataFlow, channels, mixes); } - - string id = element.GetProperty("id").GetString(); - string name = element.GetProperty("friendlyName").GetString(); - string dataFlow = element.GetProperty("dataFlow").GetString(); - List associatedClassicChannels = new List(); - ArrayList associatedStreamChannels = new ArrayList(); - - GetAssociatedChannels(id, associatedClassicChannels, associatedStreamChannels); - - if (dataFlow == _dataFlow.ToDictKey()) + } + } + + public IEnumerable GetOutputPlaybackDevices() + { + JsonElement audioDevices = new Fetcher().Provide("audioDevices").RootElement; + + foreach (JsonElement device in audioDevices.EnumerateArray()) + { + if (device.GetProperty("role").GetString() == "none") { - yield return new PlaybackDevice(id, name, (DataFlow)DataFlowExtensions.FromDictKey(dataFlow), associatedClassicChannels, associatedStreamChannels); + string dataFlow = device.GetProperty("dataFlow").GetString()!; + if (dataFlow == "render") + { + string id = device.GetProperty("id").GetString()!; + string name = device.GetProperty("friendlyName").GetString()!; + List> channels = new List>(); + List mixes = new List(); + + GetChannelsAndMixes(id, channels, mixes); + + yield return new PlaybackDevice(id, name, DataFlow.OUTPUT, channels, mixes); + } } } } - public PlaybackDevice GetPlaybackDevice(string deviceId) + public IEnumerable GetInputPlaybackDevices() { - try - { - JsonElement device = new Fetcher().Provide("audioDevices/" + deviceId).RootElement; - - string id = device.GetProperty("id").GetString(); - string name = device.GetProperty("friendlyName").GetString(); - string dataFlow = device.GetProperty("dataFlow").GetString(); - List associatedClassicChannels = new List(); - ArrayList associatedStreamChannels = new ArrayList(); - - GetAssociatedChannels(deviceId, associatedClassicChannels, associatedStreamChannels); - - return new PlaybackDevice(id, name, (DataFlow)DataFlowExtensions.FromDictKey(dataFlow), associatedClassicChannels, associatedStreamChannels); + JsonElement audioDevices = new Fetcher().Provide("audioDevices").RootElement; + + foreach (JsonElement device in audioDevices.EnumerateArray()) + { + if (device.GetProperty("role").GetString() == "none") + { + string dataFlow = device.GetProperty("dataFlow").GetString()!; + if (dataFlow == "capture") + { + string id = device.GetProperty("id").GetString()!; + string name = device.GetProperty("friendlyName").GetString()!; + List> channels = new List>(); + List mixes = new List(); + + GetChannelsAndMixes(id, channels, mixes); + + yield return new PlaybackDevice(id, name, DataFlow.INPUT, channels, mixes); + } + } } - catch (Exception e) + } + + public PlaybackDevice GetPlaybackDevice(Channel channel) + { + JsonElement classicRedirections = new Fetcher().Provide("classicRedirections").RootElement; + JsonElement audioDevices = new Fetcher().Provide("audioDevices").RootElement; + + foreach (JsonElement redirection in classicRedirections.EnumerateArray()) { - Console.WriteLine(e); - throw new Exception("Can't get any device from this Id, maybe the device doesn't exist or its Id changed."); + if (redirection.GetProperty("id").GetString() == channel.ToDictKey(ChannelMapChoice.ChannelDict)) + { + string deviceId = redirection.GetProperty("deviceId").GetString()!; + + if (string.IsNullOrEmpty(deviceId)) + { + throw new PlaybackDeviceNotFoundException("No device set on this channel"); + } + + foreach (JsonElement device in audioDevices.EnumerateArray()) + { + if (device.GetProperty("id").GetString() == deviceId) + { + string name = device.GetProperty("friendlyName").GetString()!; + DataFlow dataFlow = (DataFlow)DataFlowExtensions.FromDictKey(device.GetProperty("dataFlow").GetString()!)!; + List> channels = new List>(); + List mixes = new List(); + + GetChannelsAndMixes(deviceId, channels, mixes); + + return new PlaybackDevice(deviceId, name, dataFlow, channels, mixes); + } + } + + throw new PlaybackDeviceNotFoundException("Could not find the device"); + } } + + throw new ChannelNotFoundException("Could not find the Channel"); } - public PlaybackDevice GetClassicPlaybackDevice(Channel channel) + public PlaybackDevice GetPlaybackDevice(Channel channel, Mode mode) { - if (channel == Channel.MASTER) + if (mode == Mode.CLASSIC) + { + return GetPlaybackDevice(channel); + } + + if (mode == Mode.STREAMER && channel != Channel.MIC) { - throw new MasterChannelNotSupportedException(); + throw new ChannelNoStreamerSupportException(); } - JsonDocument classicRedirections = new Fetcher().Provide("classicRedirections"); - JsonElement cRedirections = default; - - foreach (var element in classicRedirections.RootElement.EnumerateArray()) + JsonElement streamRedirections = new Fetcher().Provide("streamRedirections").RootElement; + JsonElement audioDevices = new Fetcher().Provide("audioDevices").RootElement; + + foreach (JsonElement redirection in streamRedirections.EnumerateArray()) { - if (element.GetProperty("id").GetString() == channel.ToDictKey(ChannelMapChoice.ChannelDict)) + if (redirection.GetProperty("streamRedirectionId").GetString() == channel.ToDictKey(ChannelMapChoice.ChannelDict)) { - cRedirections = element; - break; + string deviceId = redirection.GetProperty("deviceId").GetString()!; + + if (string.IsNullOrEmpty(deviceId)) + { + throw new PlaybackDeviceNotFoundException("No device set on this channel"); + } + + foreach (JsonElement device in audioDevices.EnumerateArray()) + { + if (device.GetProperty("id").GetString() == deviceId) + { + string name = device.GetProperty("friendlyName").GetString()!; + DataFlow dataFlow = (DataFlow)DataFlowExtensions.FromDictKey(device.GetProperty("dataFlow").GetString()!)!; + List> channels = new List>(); + List mixes = new List(); + + GetChannelsAndMixes(deviceId, channels, mixes); + + return new PlaybackDevice(deviceId, name, dataFlow, channels, mixes); + } + } + + throw new PlaybackDeviceNotFoundException("Could not find the device"); } } - string deviceId = cRedirections.GetProperty("deviceId").GetString(); - List associatedClassicChannels = new List(); - ArrayList associatedStreamChannels = new ArrayList(); - - GetAssociatedChannels(deviceId, associatedClassicChannels, associatedStreamChannels); - - JsonDocument audioDevice = new Fetcher().Provide("audioDevices/" + deviceId); - - string name = audioDevice.RootElement.GetProperty("friendlyName").GetString(); - DataFlow dataFlow = (DataFlow)DataFlowExtensions.FromDictKey(audioDevice.RootElement.GetProperty("dataFlow").GetString()); - - return new PlaybackDevice(deviceId, name, dataFlow, associatedClassicChannels, associatedStreamChannels); + throw new ChannelNotFoundException("Could not find the Channel"); } - public PlaybackDevice GetStreamerPlaybackDevice(Mix mix) + public PlaybackDevice GetPlaybackDevice(Mix mix) { - JsonDocument streamRedirections = new Fetcher().Provide("streamRedirections"); - JsonElement sRedirections = default; - - foreach (var element in streamRedirections.RootElement.EnumerateArray()) + JsonElement streamRedirections = new Fetcher().Provide("streamRedirections").RootElement; + JsonElement audioDevices = new Fetcher().Provide("audioDevices").RootElement; + + foreach (JsonElement redirection in streamRedirections.EnumerateArray()) { - if (element.GetProperty("streamRedirectionId").GetString() == mix.ToDictKey()) + if (redirection.GetProperty("streamRedirectionId").GetString() == mix.ToDictKey()) { - sRedirections = element; - break; + string deviceId = redirection.GetProperty("deviceId").GetString()!; + + if (string.IsNullOrEmpty(deviceId)) + { + throw new PlaybackDeviceNotFoundException("No device set on this channel"); + } + + foreach (JsonElement device in audioDevices.EnumerateArray()) + { + if (device.GetProperty("id").GetString() == deviceId) + { + string name = device.GetProperty("friendlyName").GetString()!; + DataFlow dataFlow = (DataFlow)DataFlowExtensions.FromDictKey(device.GetProperty("dataFlow").GetString()!)!; + List> channels = new List>(); + List mixes = new List(); + + GetChannelsAndMixes(deviceId, channels, mixes); + + return new PlaybackDevice(deviceId, name, dataFlow, channels, mixes); + } + } + + throw new PlaybackDeviceNotFoundException("Could not find the device"); } } - string deviceId = sRedirections.GetProperty("deviceId").GetString(); - List associatedClassicChannels = new List(); - ArrayList associatedStreamChannels = new ArrayList(); - - GetAssociatedChannels(deviceId, associatedClassicChannels, associatedStreamChannels); - - JsonDocument audioDevice = new Fetcher().Provide("audioDevices/" + deviceId); - - string name = audioDevice.RootElement.GetProperty("friendlyName").GetString(); - DataFlow dataFlow = (DataFlow)DataFlowExtensions.FromDictKey(audioDevice.RootElement.GetProperty("dataFlow").GetString()); - - return new PlaybackDevice(deviceId, name, dataFlow, associatedClassicChannels, associatedStreamChannels); + throw new ChannelNotFoundException("Could not find the Channel"); } - public PlaybackDevice GetStreamerPlaybackDevice(Channel channel = Channel.MIC) + public PlaybackDevice GetPlaybackDevice(string deviceId) { - if (channel != Channel.MIC) - { - throw new MicChannelSupportOnlyException(); - } - - JsonDocument streamRedirections = new Fetcher().Provide("streamRedirections"); - JsonElement sRedirections = default; - - foreach (var element in streamRedirections.RootElement.EnumerateArray()) + JsonElement audioDevices = new Fetcher().Provide("audioDevices").RootElement; + + foreach (JsonElement device in audioDevices.EnumerateArray()) { - if (element.GetProperty("streamRedirectionId").GetString() == channel.ToDictKey(ChannelMapChoice.ChannelDict)) + if (device.GetProperty("id").GetString() == deviceId) { - sRedirections = element; - break; + string name = device.GetProperty("friendlyName").GetString()!; + DataFlow dataFlow = (DataFlow)DataFlowExtensions.FromDictKey(device.GetProperty("dataFlow").GetString()!)!; + List> channels = new List>(); + List mixes = new List(); + + GetChannelsAndMixes(deviceId, channels, mixes); + + return new PlaybackDevice(deviceId, name, dataFlow, channels, mixes); } } - string deviceId = sRedirections.GetProperty("deviceId").GetString(); - List associatedClassicChannels = new List(); - ArrayList associatedStreamChannels = new ArrayList(); - - GetAssociatedChannels(deviceId, associatedClassicChannels, associatedStreamChannels); - - JsonDocument audioDevice = new Fetcher().Provide("audioDevices/" + deviceId); - - string name = audioDevice.RootElement.GetProperty("friendlyName").GetString(); - DataFlow dataFlow = (DataFlow)DataFlowExtensions.FromDictKey(audioDevice.RootElement.GetProperty("dataFlow").GetString()); - - return new PlaybackDevice(deviceId, name, dataFlow, associatedClassicChannels, associatedStreamChannels); + throw new PlaybackDeviceNotFoundException("Could not find the device"); } - - private void GetAssociatedChannels(string deviceId, List associatedClassicDevices, ArrayList associatedStreamDevices) + + private void GetChannelsAndMixes(string deviceId, List> channels, List mixes) { - JsonDocument classicRedirections = new Fetcher().Provide("classicRedirections"); - JsonDocument streamRedirections = new Fetcher().Provide("streamRedirections"); + JsonElement classicRedirections = new Fetcher().Provide("classicRedirections").RootElement; - foreach (var element in classicRedirections.RootElement.EnumerateArray()) + foreach (JsonElement redirection in classicRedirections.EnumerateArray()) { - if (element.GetProperty("deviceId").GetString() == deviceId) + if (redirection.GetProperty("deviceId").GetString() == deviceId) { - associatedClassicDevices.Add((Channel)ChannelExtensions.FromDictKey(element.GetProperty("id").GetString(), ChannelMapChoice.ChannelDict)); + channels.Add(new Tuple((Channel)ChannelExtensions.FromDictKey(redirection.GetProperty("id").GetString()!, ChannelMapChoice.ChannelDict)!, Mode.CLASSIC)); } } - foreach (var element in streamRedirections.RootElement.EnumerateArray()) + JsonElement streamRedirections = new Fetcher().Provide("streamRedirections").RootElement; + + foreach (JsonElement redirection in streamRedirections.EnumerateArray()) { - if (element.GetProperty("deviceId").GetString() == deviceId) + if (redirection.GetProperty("deviceId").GetString() == deviceId) { - if (element.GetProperty("streamRedirectionId").GetString() == "mic") + var id = redirection.GetProperty("streamRedirectionId").GetString()!; + if (id == "mic") { - associatedStreamDevices.Add((Channel)ChannelExtensions.FromDictKey(element.GetProperty("streamRedirectionId").GetString(), ChannelMapChoice.ChannelDict)); + channels.Add(new Tuple(Channel.MIC, Mode.STREAMER)); } else { - associatedStreamDevices.Add((Mix)MixExtensions.FromDictKey(element.GetProperty("streamRedirectionId").GetString())); + mixes.Add((Mix)MixExtensions.FromDictKey(id)!); } } } } - public void SetClassicPlaybackDevice(string deviceId, Channel channel) + public void SetPlaybackDevice(string deviceId, Channel channel) { - new Fetcher().Put("classicRedirections/" + channel.ToDictKey(ChannelMapChoice.ChannelDict) +"/deviceId/" + deviceId); + JsonElement audioDevices = new Fetcher().Provide("audioDevices").RootElement; + + foreach (JsonElement device in audioDevices.EnumerateArray()) + { + if (device.GetProperty("id").GetString() == deviceId) + { + string dataFlow = device.GetProperty("dataFlow").GetString()!; + if ((dataFlow == "render" && channel == Channel.MIC) + || (dataFlow == "capture" && channel != Channel.MIC)) + { + throw new PlaybackDeviceDataFlowException(); + } + + new Fetcher().Put("classicRedirections/" + channel.ToDictKey(ChannelMapChoice.ChannelDict) +"/deviceId/" + deviceId); + return; + } + } + + throw new PlaybackDeviceNotFoundException("Could not find the device"); } - public void SetStreamerPlaybackDevice(string deviceId, Mix mix) + public void SetPlaybackDevice(string deviceId, Channel channel, Mode mode) { - new Fetcher().Put("streamRedirections/" + mix.ToDictKey() +"/deviceId/" + deviceId); + if (mode == Mode.CLASSIC) + { + SetPlaybackDevice(deviceId, channel); + } + + if (mode == Mode.STREAMER && channel != Channel.MIC) + { + throw new ChannelNoStreamerSupportException(); + } + + JsonElement audioDevices = new Fetcher().Provide("audioDevices").RootElement; + + foreach (JsonElement device in audioDevices.EnumerateArray()) + { + if (device.GetProperty("id").GetString() == deviceId) + { + string dataFlow = device.GetProperty("dataFlow").GetString()!; + if (dataFlow == "capture" && channel != Channel.MIC) + { + throw new PlaybackDeviceDataFlowException(); + } + + new Fetcher().Put("streamRedirections/" + channel.ToDictKey(ChannelMapChoice.ChannelDict) +"/deviceId/" + deviceId); + return; + } + } + + throw new PlaybackDeviceNotFoundException("Could not find the device"); } - public void SetStreamerPlaybackDevice(string deviceId, Channel channel = Channel.MIC) + public void SetPlaybackDevice(string deviceId, Mix mix) { - if (channel != Channel.MIC) + JsonElement audioDevices = new Fetcher().Provide("audioDevices").RootElement; + + foreach (JsonElement device in audioDevices.EnumerateArray()) { - throw new MicChannelSupportOnlyException(); + if (device.GetProperty("id").GetString() == deviceId) + { + string dataFlow = device.GetProperty("dataFlow").GetString()!; + if (dataFlow == "capture") + { + throw new PlaybackDeviceDataFlowException(); + } + + new Fetcher().Put("streamRedirections/" + mix.ToDictKey() +"/deviceId/" + deviceId); + return; + } } - new Fetcher().Put("streamRedirections/" + channel.ToDictKey(ChannelMapChoice.ChannelDict) +"/deviceId/" + deviceId); + throw new PlaybackDeviceNotFoundException("Could not find the device"); } - public void SetClassicPlaybackDevice(PlaybackDevice playbackDevice, Channel channel) + public void SetPlaybackDevice(PlaybackDevice device, Channel channel) { - SetClassicPlaybackDevice(playbackDevice.Id, channel); + SetPlaybackDevice(device.Id, channel); } - public void SetStreamerPlaybackDevice(PlaybackDevice playbackDevice, Mix mix) + public void SetPlaybackDevice(PlaybackDevice device, Channel channel, Mode mode) { - SetStreamerPlaybackDevice(playbackDevice.Id, mix); + SetPlaybackDevice(device.Id, channel, mode); } - public void SetStreamerPlaybackDevice(PlaybackDevice playbackDevice, Channel channel = Channel.MIC) + public void SetPlaybackDevice(PlaybackDevice device, Mix mix) { - SetStreamerPlaybackDevice(playbackDevice.Id, channel); + SetPlaybackDevice(device.Id, mix); } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Models/PlaybackDevice.cs b/SteelSeriesAPI/Sonar/Models/PlaybackDevice.cs index 6ff6ed3..9104b24 100644 --- a/SteelSeriesAPI/Sonar/Models/PlaybackDevice.cs +++ b/SteelSeriesAPI/Sonar/Models/PlaybackDevice.cs @@ -1,6 +1,6 @@ +using SteelSeriesAPI.Sonar.Enums; using System.Collections; -using SteelSeriesAPI.Sonar.Enums; namespace SteelSeriesAPI.Sonar.Models; -public record PlaybackDevice(string Id, string Name, DataFlow DataFlow, List? AssociatedClassicChannels, ArrayList? AssociatedStreamChannels); \ No newline at end of file +public record PlaybackDevice(string Id, string Name, DataFlow DataFlow, List> Channels, List Mixes); \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index e90ba4c..0158247 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -19,7 +19,7 @@ public class SonarBridge : ISonarBridge public readonly IVolumeSettingsManager VolumeSettings; public readonly IChatMixManager ChatMix; public readonly IConfigurationManager Configurations; - public readonly PlaybackDeviceManager PlaybackDevices; + public readonly IPlaybackDeviceManager PlaybackDevices; public readonly IRoutedProcessManager RoutedProcesses; public readonly IMixManager Mix; public readonly IAudienceMonitoringManager AudienceMonitoring; From f2775962b64cfa2faa8b1c531a029706ff45a3df Mon Sep 17 00:00:00 2001 From: DataNext Date: Mon, 28 Apr 2025 01:20:11 +0200 Subject: [PATCH 35/47] renamed volumesettings volume variables --- .../Interfaces/Managers/IVolumeSettingsManager.cs | 8 ++++---- .../Sonar/Managers/VolumeSettingsManager.cs | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IVolumeSettingsManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IVolumeSettingsManager.cs index e782cf0..99f6d38 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/Managers/IVolumeSettingsManager.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IVolumeSettingsManager.cs @@ -40,17 +40,17 @@ public interface IVolumeSettingsManager /// /// Set the volume of a Sonar /// - /// The volume you want to set, between 1 and 0 + /// The volume you want to set, between 1 and 0 /// The you want to change the volume of - void SetVolume(double vol, Channel channel); + void SetVolume(double volume, Channel channel); /// /// Set the volume of a Streamer mode Sonar /// - /// The volume you want to set, between 1 and 0 + /// The volume you want to set, between 1 and 0 /// The of the you want to change the volume of /// The you want to change the volume of - void SetVolume(double vol, Channel channel, Mix mix); + void SetVolume(double volume, Channel channel, Mix mix); /// /// Mute or unmute a Sonar diff --git a/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs b/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs index 8a72511..0b4d394 100644 --- a/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs @@ -46,16 +46,16 @@ public bool GetMute(Channel channel, Mix mix) return volumeSettings.RootElement.GetProperty("devices").GetProperty(channel.ToDictKey()).GetProperty("stream").GetProperty(mix.ToDictKey()).GetProperty("muted").GetBoolean(); } - public void SetVolume(double vol, Channel channel) + public void SetVolume(double volume, Channel channel) { - string _vol = vol.ToString("0.00", CultureInfo.InvariantCulture); - new Fetcher().Put("volumeSettings/classic/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/Volume/" + _vol); + string vol = volume.ToString("0.00", CultureInfo.InvariantCulture); + new Fetcher().Put("volumeSettings/classic/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/Volume/" + vol); } - public void SetVolume(double vol, Channel channel, Mix mix) + public void SetVolume(double volume, Channel channel, Mix mix) { - string _vol = vol.ToString("0.00", CultureInfo.InvariantCulture); - new Fetcher().Put("volumeSettings/streamer/" + mix.ToDictKey() + "/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/volume/" + _vol); + string vol = volume.ToString("0.00", CultureInfo.InvariantCulture); + new Fetcher().Put("volumeSettings/streamer/" + mix.ToDictKey() + "/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/volume/" + vol); } public void SetMute(bool mute, Channel channel) From 3c47ec2ff1bc65f8ac03b97fc15c525023813e68 Mon Sep 17 00:00:00 2001 From: DataNext Date: Mon, 28 Apr 2025 04:31:12 +0200 Subject: [PATCH 36/47] Added XML Doc and made the listerner windows only (since it is windows only for now) --- .../Sonar/Interfaces/ISonarBridge.cs | 3 ++ .../Interfaces/Managers/IChatMixManager.cs | 3 ++ SteelSeriesAPI/Sonar/SonarBridge.cs | 53 +++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarBridge.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarBridge.cs index 23cc498..4091bbc 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarBridge.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarBridge.cs @@ -1,5 +1,8 @@ namespace SteelSeriesAPI.Sonar.Interfaces; +/// +/// Manage Sonar +/// public interface ISonarBridge { /// diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs index 6e3dc1f..8ee2b79 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs @@ -1,5 +1,8 @@ namespace SteelSeriesAPI.Sonar.Interfaces.Managers; +/// +/// Manage the balance of ChatMix +/// public interface IChatMixManager { /// diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index 0158247..1311eb2 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -1,8 +1,10 @@ using SteelSeriesAPI.Sonar.Interfaces; using SteelSeriesAPI.Sonar.Interfaces.Managers; using SteelSeriesAPI.Sonar.Managers; +using SteelSeriesAPI.Sonar.Enums; using System.Security.Principal; +using System.Runtime.Versioning; namespace SteelSeriesAPI.Sonar; @@ -11,20 +13,61 @@ namespace SteelSeriesAPI.Sonar; /// public class SonarBridge : ISonarBridge { + /// + /// The running state of Sonar + /// public bool IsRunning => SonarRetriever.Instance is { IsEnabled: true, IsReady: true, IsRunning: true }; private ISonarSocket _sonarSocket; + /// + /// Manage the Sonar + /// public readonly IModeManager Mode; + + /// + /// Manage the volumes and muted state of each + /// public readonly IVolumeSettingsManager VolumeSettings; + + /// + /// Manage the balance of ChatMix + /// public readonly IChatMixManager ChatMix; + + /// + /// Manage audio configurations for each + /// public readonly IConfigurationManager Configurations; + + /// + /// Manage the playback device of each + /// public readonly IPlaybackDeviceManager PlaybackDevices; + + /// + /// Manage routed audio processes + /// public readonly IRoutedProcessManager RoutedProcesses; + + /// + /// Manage the personal and stream mix for each channel + /// public readonly IMixManager Mix; + + /// + /// Manage the Audience Monitoring feature of the streamer mode + /// public readonly IAudienceMonitoringManager AudienceMonitoring; + + /// + /// Manage the different Sonar Events + /// public readonly EventManager Events; + /// + /// The Sonar object, to control Sonar
Allow you to listen for event, get or set volumes, muted states, ... + ///
public SonarBridge() { Mode = new ModeManager(); @@ -40,6 +83,11 @@ public SonarBridge() #region Listener + /// + /// Start listening to events happening on Sonar, such as changing volume... + /// + /// The state of the listener (false if it didn't start) + [SupportedOSPlatform("windows")] public bool StartListener() { if (!IsRunAsAdmin()) @@ -69,11 +117,16 @@ public bool StartListener() return true; } + /// + /// Stop the listener + /// + [SupportedOSPlatform("windows")] public void StopListener() { _sonarSocket.CloseSocket(); } + [SupportedOSPlatform("windows")] private bool IsRunAsAdmin() { WindowsIdentity id = WindowsIdentity.GetCurrent(); From 4abbd88545b3e6ab096ba35d95c7898aae9cc093 Mon Sep 17 00:00:00 2001 From: DataNext Date: Mon, 28 Apr 2025 04:35:06 +0200 Subject: [PATCH 37/47] Made so there is only one instance of sonar socket --- SteelSeriesAPI/Sonar/SonarBridge.cs | 6 +++--- SteelSeriesAPI/Sonar/SonarSocket.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index 1311eb2..19c7cca 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -79,6 +79,8 @@ public SonarBridge() Mix = new MixManager(); AudienceMonitoring = new AudienceMonitoringManager(); Events = new EventManager(); + + _sonarSocket = new SonarSocket(Events); } #region Listener @@ -95,13 +97,11 @@ public bool StartListener() throw new ApplicationException("Listener requires Administrator rights to be used"); } - if (_sonarSocket != null && _sonarSocket.IsConnected) + if (_sonarSocket.IsConnected) { throw new Exception("Listener already started"); } - _sonarSocket = new SonarSocket(Events); - var connected = _sonarSocket.Connect(); if (!connected) { diff --git a/SteelSeriesAPI/Sonar/SonarSocket.cs b/SteelSeriesAPI/Sonar/SonarSocket.cs index 4d28201..5c8d5f2 100644 --- a/SteelSeriesAPI/Sonar/SonarSocket.cs +++ b/SteelSeriesAPI/Sonar/SonarSocket.cs @@ -13,21 +13,21 @@ public class SonarSocket : ISonarSocket public bool IsConnected => _socket?.IsBound ?? false; private readonly Thread _listenerThread; - private readonly Uri _sonarWebServerAddress; private readonly EventManager _eventManager; + private Uri _sonarWebServerAddress; private Socket _socket; private bool _isClosing; public SonarSocket(EventManager eventManager) { - _sonarWebServerAddress = new Uri(SonarRetriever.Instance.WebServerAddress()); _listenerThread = new Thread(ListenerThreadSync) { IsBackground = false }; _eventManager = eventManager; } public bool Connect() { + _sonarWebServerAddress = new Uri(SonarRetriever.Instance.WebServerAddress()); _socket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP); try { From a25d9c05c63cda60f24a07b2a59db393707a7791 Mon Sep 17 00:00:00 2001 From: DataNext Date: Mon, 28 Apr 2025 15:38:21 +0200 Subject: [PATCH 38/47] Made the _sonarSocket readonly --- SteelSeriesAPI/Sonar/SonarBridge.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index 19c7cca..c92c9b5 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -18,7 +18,7 @@ public class SonarBridge : ISonarBridge ///
public bool IsRunning => SonarRetriever.Instance is { IsEnabled: true, IsReady: true, IsRunning: true }; - private ISonarSocket _sonarSocket; + private readonly ISonarSocket _sonarSocket; /// /// Manage the Sonar From ef9734267d88d13720334228d323f3170b4d11d8 Mon Sep 17 00:00:00 2001 From: DataNext Date: Mon, 28 Apr 2025 17:19:07 +0200 Subject: [PATCH 39/47] Made the RoutedProcess State internally mutable so it can follow its api state. Also made the GetActiveRoutedProcessesById() method return an IEnumerable since 2 active process can have the same id (e.g. discord in chat and mic) --- SteelSeriesAPI.Tests/Program.cs | 260 ++++-------------- .../Managers/IRoutedProcessManager.cs | 2 +- .../Sonar/Managers/RoutedProcessManager.cs | 13 +- SteelSeriesAPI/Sonar/Models/RoutedProcess.cs | 20 +- 4 files changed, 89 insertions(+), 206 deletions(-) diff --git a/SteelSeriesAPI.Tests/Program.cs b/SteelSeriesAPI.Tests/Program.cs index 85b529d..87f10a1 100644 --- a/SteelSeriesAPI.Tests/Program.cs +++ b/SteelSeriesAPI.Tests/Program.cs @@ -13,226 +13,77 @@ static void Main(string[] args) sonarManager.WaitUntilSteelSeriesStarted(); sonarManager.WaitUntilSonarStarted(); Console.WriteLine(SonarRetriever.Instance.WebServerAddress()); - + // sonarManager.StartListener(); // Thread.Sleep(1000); // sonarManager.StopListener(); - + // sonarManager.Events.OnSonarModeChange += OnModeChangeHandler; // sonarManager.Events.OnSonarVolumeChange += OnVolumeChangeHandler; // sonarManager.Events.OnSonarMuteChange += OnMuteChangeHandler; // sonarManager.Events.OnSonarConfigChange += OnConfigChangeHandler; // sonarManager.Events.OnSonarChatMixChange += OnChatMixChangeHandler; // sonarManager.Events.OnSonarPlaybackDeviceChange += OnPlaybackDeviceChangeHandler; - // sonarManager.Events.OnSonarRedirectionStateChange += OnRedirectionStateChangeHandler; + // sonarManager.Events.OnSonarRoutedProcessChange += OnRoutedProcessChangeHandler; + // sonarManager.Events.OnSonarMixChange += OnMixChangeHandler; // sonarManager.Events.OnSonarAudienceMonitoringChange += OnAudienceMonitoringChangeHandler; - // new Program().GetTest(sonarManager); - // new Program().SetTest(sonarManager); - // new Program().TestMaster(sonarManager); - } - - void TestMaster(SonarBridge sonarManager) - { - - // Classic - sonarManager.SetMode(Mode.CLASSIC); - Console.WriteLine("------ Classic Master Test ------"); - Console.WriteLine(sonarManager.VolumeSettings.GetVolume(Channel.MASTER)); - Console.WriteLine(sonarManager.VolumeSettings.GetMute(Channel.MASTER)); - sonarManager.VolumeSettings.SetVolume(0.25f, Channel.MASTER); - sonarManager.VolumeSettings.SetVolume(1, Channel.MASTER); - sonarManager.VolumeSettings.SetMute(true, Channel.MASTER); - sonarManager.VolumeSettings.SetMute(false, Channel.MASTER); - - // Streamer - sonarManager.SetMode(Mode.STREAMER); - Console.WriteLine("------ Streamer Master Test ------"); - Console.WriteLine(sonarManager.VolumeSettings.GetVolume(Channel.MASTER, Mix.MONITORING)); - Console.WriteLine(sonarManager.VolumeSettings.GetVolume(Channel.MASTER, Mix.STREAM)); - Console.WriteLine(sonarManager.VolumeSettings.GetMute(Channel.MASTER, Mix.MONITORING)); - Console.WriteLine(sonarManager.VolumeSettings.GetMute(Channel.MASTER, Mix.STREAM)); - sonarManager.VolumeSettings.SetVolume(0.25f, Channel.MASTER, Mix.MONITORING); - sonarManager.VolumeSettings.SetVolume(0.25f, Channel.MASTER, Mix.STREAM); - sonarManager.VolumeSettings.SetVolume(1, Channel.MASTER, Mix.MONITORING); - sonarManager.VolumeSettings.SetVolume(1, Channel.MASTER, Mix.STREAM); - sonarManager.VolumeSettings.SetMute(true, Channel.MASTER, Mix.MONITORING); - sonarManager.VolumeSettings.SetMute(true, Channel.MASTER, Mix.STREAM); - sonarManager.VolumeSettings.SetMute(false, Channel.MASTER, Mix.MONITORING); - sonarManager.VolumeSettings.SetMute(false, Channel.MASTER, Mix.STREAM); + var _testChannel = Channel.MEDIA; + // Save current settings + var _mode = sonarManager.Mode.Get(); + var _chatmix = sonarManager.ChatMix.GetBalance(); - sonarManager.SetMode(Mode.CLASSIC); - } - - void GetTest(SonarBridge sonarManager) - { - - Console.WriteLine(sonarManager.GetMode()); - Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.MASTER) + " " + sonarManager.VolumeSettings.GetMute(Channel.MASTER)); - Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.GAME) + " " + sonarManager.VolumeSettings.GetMute(Channel.GAME)); - Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.CHAT) + " " + sonarManager.VolumeSettings.GetMute(Channel.CHAT)); - Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.MEDIA) + " " + sonarManager.VolumeSettings.GetMute(Channel.MEDIA)); - Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.AUX) + " " + sonarManager.VolumeSettings.GetMute(Channel.AUX)); - Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.MIC) + " " + sonarManager.VolumeSettings.GetMute(Channel.MIC)); - Console.WriteLine("-----------------Streamer-Monitoring-------------"); - Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.MASTER, Mix.MONITORING) + " " + sonarManager.VolumeSettings.GetMute(Channel.MASTER, Mix.MONITORING)); - Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.GAME, Mix.MONITORING) + " " + sonarManager.VolumeSettings.GetMute(Channel.GAME, Mix.MONITORING)); - Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.CHAT, Mix.MONITORING) + " " + sonarManager.VolumeSettings.GetMute(Channel.CHAT, Mix.MONITORING)); - Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.MEDIA, Mix.MONITORING) + " " + sonarManager.VolumeSettings.GetMute(Channel.MEDIA, Mix.MONITORING)); - Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.AUX, Mix.MONITORING) + " " + sonarManager.VolumeSettings.GetMute(Channel.AUX, Mix.MONITORING)); - Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.MIC, Mix.MONITORING) + " " + sonarManager.VolumeSettings.GetMute(Channel.MIC, Mix.MONITORING)); - Console.WriteLine("-----------------Streamer-Stream-------------"); - Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.MASTER, Mix.STREAM) + " " + sonarManager.VolumeSettings.GetMute(Channel.MASTER, Mix.STREAM)); - Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.GAME, Mix.STREAM) + " " + sonarManager.VolumeSettings.GetMute(Channel.GAME, Mix.STREAM)); - Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.CHAT, Mix.STREAM) + " " + sonarManager.VolumeSettings.GetMute(Channel.CHAT, Mix.STREAM)); - Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.MEDIA, Mix.STREAM) + " " + sonarManager.VolumeSettings.GetMute(Channel.MEDIA, Mix.STREAM)); - Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.AUX, Mix.STREAM) + " " + sonarManager.VolumeSettings.GetMute(Channel.AUX, Mix.STREAM)); - Console.WriteLine("" + sonarManager.VolumeSettings.GetVolume(Channel.MIC, Mix.STREAM) + " " + sonarManager.VolumeSettings.GetMute(Channel.MIC, Mix.STREAM)); - Console.WriteLine("----AudioConfigs----------"); - foreach (var config in sonarManager.Configurations.GetAllAudioConfigurations()) - { - Console.WriteLine(config.Id + ", " + config.Name + ", " + config.AssociatedChannel); - } + var _volume = sonarManager.VolumeSettings.GetVolume(_testChannel); + var _mute = sonarManager.VolumeSettings.GetMute(_testChannel); + var _config = sonarManager.Configurations.GetSelectedAudioConfiguration(_testChannel); + var _playbackDevice = sonarManager.PlaybackDevices.GetPlaybackDevice(_testChannel); + var _routedProcesses = new List(sonarManager.RoutedProcesses.GetActiveRoutedProcesses(_testChannel)); - Console.WriteLine("----Media-Configs----------"); - foreach (var config in sonarManager.Configurations.GetAudioConfigurations(Channel.MEDIA)) - { - Console.WriteLine(config.Id + ", " + config.Name); - } - - Console.WriteLine("----Mic-Configs----------"); - foreach (var config in sonarManager.Configurations.GetAudioConfigurations(Channel.MIC)) - { - Console.WriteLine(config.Id + ", " + config.Name); - } - - Console.WriteLine("----Current Media Config----------"); - Console.WriteLine(sonarManager.Configurations.GetSelectedAudioConfiguration(Channel.MEDIA).Name); - Console.WriteLine("----Channel from config ID----------"); - Console.WriteLine(sonarManager.Configurations.GetAudioConfiguration("29ae2c02-792b-4487-863c-dc3e11a7a469").AssociatedChannel); - Console.WriteLine("--------ChatMix---------"); - Console.WriteLine(sonarManager.ChatMix.GetBalance()); - Console.WriteLine(sonarManager.ChatMix.GetState()); - - Console.WriteLine("-----Redirection Devices-----------"); - Console.WriteLine("---Output---"); - foreach (var rDevice in sonarManager.PlaybackDevices.GetPlaybackDevices(DataFlow.OUTPUT)) - { - Console.WriteLine(rDevice.Id + ", " + rDevice.Name); - foreach (var device in rDevice.AssociatedClassicChannels) - { - Console.WriteLine("...." + device); - } - - foreach (var channel in rDevice.AssociatedStreamChannels) - { - Console.WriteLine("...." + channel); - } - } - - Console.WriteLine("---Input---"); - foreach (var rDevice in sonarManager.PlaybackDevices.GetPlaybackDevices(DataFlow.INPUT)) - { - Console.WriteLine(rDevice.Id + ", " + rDevice.Name); - foreach (var device in rDevice.AssociatedClassicChannels) - { - Console.WriteLine("...." + device); - } - - foreach (var channel in rDevice.AssociatedStreamChannels) - { - Console.WriteLine("...." + channel); - } - } - - Console.WriteLine("-----Classic Playback Devices------------"); - PlaybackDevice reDevice = sonarManager.PlaybackDevices.GetClassicPlaybackDevice(Channel.GAME); - Console.WriteLine(reDevice.Id + ", " + reDevice.Name); - foreach (var device in reDevice.AssociatedClassicChannels) - { - Console.WriteLine("...." + device); - } - - foreach (var channel in reDevice.AssociatedStreamChannels) - { - Console.WriteLine("...." + channel); - } - - Console.WriteLine("-----Stream Playback Devices------------"); - PlaybackDevice reDeviceS = sonarManager.PlaybackDevices.GetStreamerPlaybackDevice(Channel.MIC); // sonarManager.GetStreamPlaybackDevice(Mix.MONITORING); - Console.WriteLine(reDeviceS.Id + ", " + reDeviceS.Name); - foreach (var device in reDeviceS.AssociatedClassicChannels) - { - Console.WriteLine("...." + device); - } - - foreach (var channel in reDeviceS.AssociatedStreamChannels) - { - Console.WriteLine("...." + channel); - } - - Console.WriteLine("-----Redirection Channel From Id"); - // PlaybackDevice someDevice = sonarManager.GetPlaybackDeviceFromId("{0.0.0.00000000}.{453f6e2f-375e-4b36-97b2-2aa55691ab3c}"); - // Console.WriteLine(someDevice.Id + ", " + someDevice.Name + ", " + someDevice.DataFlow); - // foreach (var associatedClassicDevice in someDevice.AssociatedClassicChannels) + // Console.WriteLine("Volume test..."); + // sonarManager.VolumeSettings.SetVolume(_volume + 0.2, _testChannel); + // Thread.Sleep(1000); + // sonarManager.VolumeSettings.SetVolume(_volume, _testChannel); + // + // Thread.Sleep(500); + // + // Console.WriteLine("Mute test..."); + // sonarManager.VolumeSettings.SetMute(!_mute, _testChannel); + // Thread.Sleep(1000); + // sonarManager.VolumeSettings.SetMute(_mute, _testChannel); + // + // Thread.Sleep(500); + // + // Console.WriteLine("Config test..."); + // sonarManager.Configurations.SetConfig(sonarManager.Configurations.GetAudioConfigurations(_testChannel).First()); + // Thread.Sleep(1000); + // sonarManager.Configurations.SetConfig(_config); + // + // Thread.Sleep(500); + // + // Console.WriteLine("Playback Device test..."); + // if (_testChannel == Channel.MIC) // { - // Console.WriteLine("...." + associatedClassicDevice); + // sonarManager.PlaybackDevices.SetPlaybackDevice(sonarManager.PlaybackDevices.GetInputPlaybackDevices().First(), _testChannel); // } - // - // foreach (var associatedStreamDevice in someDevice.AssociatedStreamChannels) + // else // { - // Console.WriteLine("...." + associatedStreamDevice); + // sonarManager.PlaybackDevices.SetPlaybackDevice(sonarManager.PlaybackDevices.GetOutputPlaybackDevices().First(), _testChannel); // } + // Thread.Sleep(1000); + // sonarManager.PlaybackDevices.SetPlaybackDevice(_playbackDevice, _testChannel); - Console.WriteLine("-----Redirection States---------"); - Console.WriteLine(sonarManager.GetRedirectionState(Channel.GAME, Mix.MONITORING)); - Console.WriteLine(sonarManager.GetRedirectionState(Channel.CHAT, Mix.MONITORING)); - Console.WriteLine(sonarManager.GetRedirectionState(Channel.MEDIA, Mix.MONITORING)); - Console.WriteLine(sonarManager.GetRedirectionState(Channel.AUX, Mix.MONITORING)); - Console.WriteLine(sonarManager.GetRedirectionState(Channel.MIC, Mix.MONITORING)); - Console.WriteLine(sonarManager.GetRedirectionState(Channel.GAME, Mix.STREAM)); - Console.WriteLine(sonarManager.GetRedirectionState(Channel.CHAT, Mix.STREAM)); - Console.WriteLine(sonarManager.GetRedirectionState(Channel.MEDIA, Mix.STREAM)); - Console.WriteLine(sonarManager.GetRedirectionState(Channel.AUX, Mix.STREAM)); - Console.WriteLine(sonarManager.GetRedirectionState(Channel.MIC, Mix.STREAM)); - Console.WriteLine("-----Audience Monitoring-------"); - Console.WriteLine(sonarManager.GetAudienceMonitoringState()); - Console.WriteLine("-----Routed Processes-----------"); - foreach (Channel device in (Channel[])Enum.GetValues(typeof(Channel))) + Console.WriteLine("Routed Processes test..."); + foreach (var r in _routedProcesses) { - if (device == Channel.MASTER) - { - continue; - } - - Console.WriteLine("-- " + device); - foreach (var routed in sonarManager.RoutedProcesses.GetRoutedProcesses(device)) - { - Console.WriteLine(routed.Id + ", " + routed.ProcessName + ", " + routed.PId + ", " + routed.State + - ", " + routed.DisplayName); - } + sonarManager.RoutedProcesses.RouteProcessToChannel(r, Channel.GAME); + } + Thread.Sleep(1000); + foreach (var r in _routedProcesses) + { + sonarManager.RoutedProcesses.RouteProcessToChannel(r, _testChannel); } - } - - void SetTest(SonarBridge sonarManager){ - - sonarManager.SetMode(Mode.CLASSIC); - sonarManager.VolumeSettings.SetVolume(0.4, Channel.MEDIA); - sonarManager.VolumeSettings.SetMute(false, Channel.MEDIA); - string configId = sonarManager.Configurations.GetAudioConfigurations(Channel.MEDIA).FirstOrDefault(config => config.Name == "Default")?.Id; - sonarManager.Configurations.SetConfig(configId); - sonarManager.Configurations.SetConfigByName(Channel.MEDIA, "Default"); - sonarManager.ChatMix.SetBalance(0.5); - - var redirectionDevices = sonarManager.PlaybackDevices.GetPlaybackDevices(DataFlow.INPUT); - redirectionDevices.GetEnumerator().MoveNext(); - sonarManager.PlaybackDevices.SetClassicPlaybackDevice(redirectionDevices.GetEnumerator().Current.Id, Channel.MIC); - sonarManager.PlaybackDevices.SetStreamerPlaybackDevice(redirectionDevices.GetEnumerator().Current.Id, Channel.MIC); - sonarManager.SetRedirectionState(true, Channel.MEDIA, Mix.STREAM); - sonarManager.SetAudienceMonitoringState(false); - sonarManager.RoutedProcesses.RouteProcessToChannel(19152, Channel.MIC); } static void OnModeChangeHandler(object? sender, SonarModeEvent eventArgs) @@ -262,16 +113,21 @@ static void OnChatMixChangeHandler(object? sender, SonarChatMixEvent eventArgs) static void OnPlaybackDeviceChangeHandler(object? sender, SonarPlaybackDeviceEvent eventArgs) { - Console.WriteLine("Received Redirection Channel Event : " + eventArgs.RedirectionDeviceId + ", " + eventArgs.Mode + ", " + eventArgs.Device + ", " + eventArgs.Channel); + Console.WriteLine("Received Redirection Channel Event : " + eventArgs.PlaybackDeviceId + ", " + eventArgs.Mode + ", " + eventArgs.Device + ", " + eventArgs.Channel); + } + + static void OnRoutedProcessChangeHandler(object? sender, SonarRoutedProcessEvent eventArgs) + { + Console.WriteLine("Received Routed Process Event : " + eventArgs.ProcessId + ", " + eventArgs.NewChannel); } - static void OnRedirectionStateChangeHandler(object? sender, SonarRedirectionStateEvent eventArgs) + static void OnMixChangeHandler(object? sender, SonarMixEvent eventArgs) { - Console.WriteLine("Received Redirection State Event : " + eventArgs.State + ", " + eventArgs.Channel + ", " + eventArgs.Mix); + Console.WriteLine("Received Redirection State Event : " + eventArgs.NewState + ", " + eventArgs.Channel + ", " + eventArgs.Mix); } static void OnAudienceMonitoringChangeHandler(object? sender, SonarAudienceMonitoringEvent eventArgs) { - Console.WriteLine("Received Audience Monitoring Event : " + eventArgs.AudienceMonitoringState); + Console.WriteLine("Received Audience Monitoring Event : " + eventArgs.NewState); } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs index 2c6f95c..af010e0 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs @@ -46,7 +46,7 @@ public interface IRoutedProcessManager /// /// The id of the process /// - RoutedProcess GetActiveRoutedProcessesById(int processId); + IEnumerable GetActiveRoutedProcessesById(int processId); /// /// Route an audio process to a specific diff --git a/SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs b/SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs index 11b157c..1ca7017 100644 --- a/SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs @@ -156,7 +156,7 @@ public IEnumerable GetRoutedProcessesById(int processId) } } - public RoutedProcess GetActiveRoutedProcessesById(int processId) + public IEnumerable GetActiveRoutedProcessesById(int processId) { JsonElement audioDeviceRouting = new Fetcher().Provide("AudioDeviceRouting").RootElement; @@ -175,7 +175,7 @@ public RoutedProcess GetActiveRoutedProcessesById(int processId) Channel channel = (Channel)ChannelExtensions.FromDictKey(role)!; string processPath = session.GetProperty("id").GetString()!.Split("|")[1].Replace('\\', '/'); - return new RoutedProcess(processId, processName, displayName, state, channel, processPath); + yield return new RoutedProcess(processId, processName, displayName, state, channel, processPath); } } } @@ -212,5 +212,14 @@ public void RouteProcessToChannel(int processId, Channel channel) public void RouteProcessToChannel(RoutedProcess process, Channel channel) { RouteProcessToChannel(process.ProcessId, channel); + + if (process.Channel == channel) + { + process.State = RoutedProcessState.ACTIVE; + } + else + { + process.State = RoutedProcessState.INACTIVE; + } } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Models/RoutedProcess.cs b/SteelSeriesAPI/Sonar/Models/RoutedProcess.cs index 09c8c97..beae57f 100644 --- a/SteelSeriesAPI/Sonar/Models/RoutedProcess.cs +++ b/SteelSeriesAPI/Sonar/Models/RoutedProcess.cs @@ -2,4 +2,22 @@ namespace SteelSeriesAPI.Sonar.Models; -public record RoutedProcess(int ProcessId, string ProcessName, string DisplayName, RoutedProcessState State, Channel Channel, string ProcessPath); \ No newline at end of file +public record RoutedProcess +{ + public int ProcessId { get; init; } + public string ProcessName { get; init; } + public string DisplayName { get; init; } + public RoutedProcessState State { get; internal set; } + public Channel Channel { get; init; } + public string ProcessPath { get; init; } + + public RoutedProcess(int processId, string processName, string displayName, RoutedProcessState state, Channel channel, string processPath) + { + ProcessId = processId; + ProcessName = processName; + DisplayName = displayName; + State = state; + Channel = channel; + ProcessPath = processPath; + } +}; \ No newline at end of file From f20a8c94c19d77368125f1cd502d90e3139c1e75 Mon Sep 17 00:00:00 2001 From: DataNext Date: Mon, 28 Apr 2025 17:44:23 +0200 Subject: [PATCH 40/47] Renamed Monitoring mix to Personal mix --- SteelSeriesAPI.Tests/Program.cs | 146 +++++++++++++++++++++--------- SteelSeriesAPI/Sonar/Enums/Mix.cs | 4 +- 2 files changed, 103 insertions(+), 47 deletions(-) diff --git a/SteelSeriesAPI.Tests/Program.cs b/SteelSeriesAPI.Tests/Program.cs index 87f10a1..36cc63d 100644 --- a/SteelSeriesAPI.Tests/Program.cs +++ b/SteelSeriesAPI.Tests/Program.cs @@ -29,61 +29,117 @@ static void Main(string[] args) // sonarManager.Events.OnSonarMixChange += OnMixChangeHandler; // sonarManager.Events.OnSonarAudienceMonitoringChange += OnAudienceMonitoringChangeHandler; - var _testChannel = Channel.MEDIA; // Save current settings var _mode = sonarManager.Mode.Get(); var _chatmix = sonarManager.ChatMix.GetBalance(); - var _volume = sonarManager.VolumeSettings.GetVolume(_testChannel); - var _mute = sonarManager.VolumeSettings.GetMute(_testChannel); - var _config = sonarManager.Configurations.GetSelectedAudioConfiguration(_testChannel); - var _playbackDevice = sonarManager.PlaybackDevices.GetPlaybackDevice(_testChannel); - var _routedProcesses = new List(sonarManager.RoutedProcesses.GetActiveRoutedProcesses(_testChannel)); + sonarManager.Mode.Set(Mode.CLASSIC); - // Console.WriteLine("Volume test..."); - // sonarManager.VolumeSettings.SetVolume(_volume + 0.2, _testChannel); - // Thread.Sleep(1000); - // sonarManager.VolumeSettings.SetVolume(_volume, _testChannel); - // - // Thread.Sleep(500); - // - // Console.WriteLine("Mute test..."); - // sonarManager.VolumeSettings.SetMute(!_mute, _testChannel); - // Thread.Sleep(1000); - // sonarManager.VolumeSettings.SetMute(_mute, _testChannel); - // - // Thread.Sleep(500); - // - // Console.WriteLine("Config test..."); - // sonarManager.Configurations.SetConfig(sonarManager.Configurations.GetAudioConfigurations(_testChannel).First()); - // Thread.Sleep(1000); - // sonarManager.Configurations.SetConfig(_config); - // - // Thread.Sleep(500); - // - // Console.WriteLine("Playback Device test..."); - // if (_testChannel == Channel.MIC) - // { - // sonarManager.PlaybackDevices.SetPlaybackDevice(sonarManager.PlaybackDevices.GetInputPlaybackDevices().First(), _testChannel); - // } - // else - // { - // sonarManager.PlaybackDevices.SetPlaybackDevice(sonarManager.PlaybackDevices.GetOutputPlaybackDevices().First(), _testChannel); - // } - // Thread.Sleep(1000); - // sonarManager.PlaybackDevices.SetPlaybackDevice(_playbackDevice, _testChannel); - - Console.WriteLine("Routed Processes test..."); - foreach (var r in _routedProcesses) + foreach (Channel channel in (Channel[])Enum.GetValues(typeof(Channel))) { - sonarManager.RoutedProcesses.RouteProcessToChannel(r, Channel.GAME); + Console.WriteLine("------ " + channel + " ------"); + if (channel == Channel.MASTER) + { + var _volume = sonarManager.VolumeSettings.GetVolume(channel); + var _mute = sonarManager.VolumeSettings.GetMute(channel); + + Console.WriteLine("Volume test..."); + sonarManager.VolumeSettings.SetVolume(_volume + 0.2, channel); + Thread.Sleep(1000); + sonarManager.VolumeSettings.SetVolume(_volume, channel); + + Thread.Sleep(500); + + Console.WriteLine("Mute test..."); + sonarManager.VolumeSettings.SetMute(!_mute, channel); + Thread.Sleep(1000); + sonarManager.VolumeSettings.SetMute(_mute, channel); + } + else + { + var _volume = sonarManager.VolumeSettings.GetVolume(channel); + var _mute = sonarManager.VolumeSettings.GetMute(channel); + var _config = sonarManager.Configurations.GetSelectedAudioConfiguration(channel); + var _playbackDevice = sonarManager.PlaybackDevices.GetPlaybackDevice(channel); + var _routedProcesses = new List(sonarManager.RoutedProcesses.GetActiveRoutedProcesses(channel)); + + Console.WriteLine("Volume test..."); + sonarManager.VolumeSettings.SetVolume(_volume + 0.2, channel); + Thread.Sleep(1000); + sonarManager.VolumeSettings.SetVolume(_volume, channel); + + Thread.Sleep(500); + + Console.WriteLine("Mute test..."); + sonarManager.VolumeSettings.SetMute(!_mute, channel); + Thread.Sleep(1000); + sonarManager.VolumeSettings.SetMute(_mute, channel); + + Thread.Sleep(500); + + Console.WriteLine("Config test..."); + sonarManager.Configurations.SetConfig(sonarManager.Configurations.GetAudioConfigurations(channel).ToList()[4]); + Thread.Sleep(1000); + sonarManager.Configurations.SetConfig(_config); + + Thread.Sleep(500); + + Console.WriteLine("Playback Device test..."); + if (channel == Channel.MIC) + { + sonarManager.PlaybackDevices.SetPlaybackDevice(sonarManager.PlaybackDevices.GetInputPlaybackDevices().First(), channel); + } + else + { + sonarManager.PlaybackDevices.SetPlaybackDevice(sonarManager.PlaybackDevices.GetOutputPlaybackDevices().First(), channel); + } + Thread.Sleep(1000); + sonarManager.PlaybackDevices.SetPlaybackDevice(_playbackDevice, channel); + + Console.WriteLine("Routed Processes test..."); + foreach (var r in _routedProcesses) + { + if (channel == Channel.GAME) + { + sonarManager.RoutedProcesses.RouteProcessToChannel(r, Channel.AUX); + } + else + { + sonarManager.RoutedProcesses.RouteProcessToChannel(r, Channel.GAME); + } + } + Thread.Sleep(1000); + foreach (var r in _routedProcesses) + { + sonarManager.RoutedProcesses.RouteProcessToChannel(r, channel); + } + } } - Thread.Sleep(1000); - foreach (var r in _routedProcesses) + + if (sonarManager.ChatMix.GetState()) { - sonarManager.RoutedProcesses.RouteProcessToChannel(r, _testChannel); + Console.WriteLine("Chat Mix Test..."); + sonarManager.ChatMix.SetBalance(_chatmix + 0.2); + Thread.Sleep(1000); + sonarManager.ChatMix.SetBalance(_chatmix); } + sonarManager.Mode.Set(Mode.STREAMER); + + foreach (Channel channel in (Channel[])Enum.GetValues(typeof(Channel))) + { + foreach (Mix mix in (Mix[])Enum.GetValues(typeof(Mix))) + { + if (channel == Channel.MASTER) + { + + } + else + { + + } + } + } } static void OnModeChangeHandler(object? sender, SonarModeEvent eventArgs) diff --git a/SteelSeriesAPI/Sonar/Enums/Mix.cs b/SteelSeriesAPI/Sonar/Enums/Mix.cs index 0c817a0..6203d9d 100644 --- a/SteelSeriesAPI/Sonar/Enums/Mix.cs +++ b/SteelSeriesAPI/Sonar/Enums/Mix.cs @@ -2,7 +2,7 @@ namespace SteelSeriesAPI.Sonar.Enums; public enum Mix { - MONITORING, + PERSONAL, STREAM } @@ -10,7 +10,7 @@ public static class MixExtensions { private static readonly Dictionary MixMap = new Dictionary { - { Mix.MONITORING, "monitoring" }, + { Mix.PERSONAL, "monitoring" }, { Mix.STREAM, "streaming" } }; From fd5521d827168af9f575eb158a0c800322e203f0 Mon Sep 17 00:00:00 2001 From: DataNext Date: Mon, 28 Apr 2025 18:36:37 +0200 Subject: [PATCH 41/47] Remade an entire test script usable by everyone --- SteelSeriesAPI.Tests/Program.cs | 146 ++++++++++++++++++++++++-------- 1 file changed, 112 insertions(+), 34 deletions(-) diff --git a/SteelSeriesAPI.Tests/Program.cs b/SteelSeriesAPI.Tests/Program.cs index 36cc63d..6871763 100644 --- a/SteelSeriesAPI.Tests/Program.cs +++ b/SteelSeriesAPI.Tests/Program.cs @@ -1,6 +1,7 @@ using SteelSeriesAPI.Sonar; using SteelSeriesAPI.Sonar.Events; using SteelSeriesAPI.Sonar.Enums; +using SteelSeriesAPI.Sonar.Exceptions; using SteelSeriesAPI.Sonar.Models; namespace SteelSeriesAPI.Tests; @@ -14,24 +15,25 @@ static void Main(string[] args) sonarManager.WaitUntilSonarStarted(); Console.WriteLine(SonarRetriever.Instance.WebServerAddress()); - // sonarManager.StartListener(); + sonarManager.StartListener(); // Thread.Sleep(1000); // sonarManager.StopListener(); - // sonarManager.Events.OnSonarModeChange += OnModeChangeHandler; - // sonarManager.Events.OnSonarVolumeChange += OnVolumeChangeHandler; - // sonarManager.Events.OnSonarMuteChange += OnMuteChangeHandler; - // sonarManager.Events.OnSonarConfigChange += OnConfigChangeHandler; - // sonarManager.Events.OnSonarChatMixChange += OnChatMixChangeHandler; - // sonarManager.Events.OnSonarPlaybackDeviceChange += OnPlaybackDeviceChangeHandler; - // sonarManager.Events.OnSonarRoutedProcessChange += OnRoutedProcessChangeHandler; - // sonarManager.Events.OnSonarMixChange += OnMixChangeHandler; - // sonarManager.Events.OnSonarAudienceMonitoringChange += OnAudienceMonitoringChangeHandler; + sonarManager.Events.OnSonarModeChange += OnModeChangeHandler; + sonarManager.Events.OnSonarVolumeChange += OnVolumeChangeHandler; + sonarManager.Events.OnSonarMuteChange += OnMuteChangeHandler; + sonarManager.Events.OnSonarConfigChange += OnConfigChangeHandler; + sonarManager.Events.OnSonarChatMixChange += OnChatMixChangeHandler; + sonarManager.Events.OnSonarPlaybackDeviceChange += OnPlaybackDeviceChangeHandler; + sonarManager.Events.OnSonarRoutedProcessChange += OnRoutedProcessChangeHandler; + sonarManager.Events.OnSonarMixChange += OnMixChangeHandler; + sonarManager.Events.OnSonarAudienceMonitoringChange += OnAudienceMonitoringChangeHandler; // Save current settings - var _mode = sonarManager.Mode.Get(); - var _chatmix = sonarManager.ChatMix.GetBalance(); + var mode = sonarManager.Mode.Get(); + var chatmix = sonarManager.ChatMix.GetBalance(); + var audienceMonitoring = sonarManager.AudienceMonitoring.GetState(); sonarManager.Mode.Set(Mode.CLASSIC); @@ -40,47 +42,47 @@ static void Main(string[] args) Console.WriteLine("------ " + channel + " ------"); if (channel == Channel.MASTER) { - var _volume = sonarManager.VolumeSettings.GetVolume(channel); - var _mute = sonarManager.VolumeSettings.GetMute(channel); + var volume = sonarManager.VolumeSettings.GetVolume(channel); + var mute = sonarManager.VolumeSettings.GetMute(channel); Console.WriteLine("Volume test..."); - sonarManager.VolumeSettings.SetVolume(_volume + 0.2, channel); + sonarManager.VolumeSettings.SetVolume(volume + 0.2, channel); Thread.Sleep(1000); - sonarManager.VolumeSettings.SetVolume(_volume, channel); + sonarManager.VolumeSettings.SetVolume(volume, channel); Thread.Sleep(500); Console.WriteLine("Mute test..."); - sonarManager.VolumeSettings.SetMute(!_mute, channel); + sonarManager.VolumeSettings.SetMute(!mute, channel); Thread.Sleep(1000); - sonarManager.VolumeSettings.SetMute(_mute, channel); + sonarManager.VolumeSettings.SetMute(mute, channel); } else { - var _volume = sonarManager.VolumeSettings.GetVolume(channel); - var _mute = sonarManager.VolumeSettings.GetMute(channel); - var _config = sonarManager.Configurations.GetSelectedAudioConfiguration(channel); - var _playbackDevice = sonarManager.PlaybackDevices.GetPlaybackDevice(channel); - var _routedProcesses = new List(sonarManager.RoutedProcesses.GetActiveRoutedProcesses(channel)); + var volume = sonarManager.VolumeSettings.GetVolume(channel); + var mute = sonarManager.VolumeSettings.GetMute(channel); + var config = sonarManager.Configurations.GetSelectedAudioConfiguration(channel); + var playbackDevice = sonarManager.PlaybackDevices.GetPlaybackDevice(channel); + var routedProcesses = new List(sonarManager.RoutedProcesses.GetActiveRoutedProcesses(channel)); Console.WriteLine("Volume test..."); - sonarManager.VolumeSettings.SetVolume(_volume + 0.2, channel); + sonarManager.VolumeSettings.SetVolume(volume + 0.2, channel); Thread.Sleep(1000); - sonarManager.VolumeSettings.SetVolume(_volume, channel); + sonarManager.VolumeSettings.SetVolume(volume, channel); Thread.Sleep(500); Console.WriteLine("Mute test..."); - sonarManager.VolumeSettings.SetMute(!_mute, channel); + sonarManager.VolumeSettings.SetMute(!mute, channel); Thread.Sleep(1000); - sonarManager.VolumeSettings.SetMute(_mute, channel); + sonarManager.VolumeSettings.SetMute(mute, channel); Thread.Sleep(500); Console.WriteLine("Config test..."); sonarManager.Configurations.SetConfig(sonarManager.Configurations.GetAudioConfigurations(channel).ToList()[4]); Thread.Sleep(1000); - sonarManager.Configurations.SetConfig(_config); + sonarManager.Configurations.SetConfig(config); Thread.Sleep(500); @@ -94,10 +96,10 @@ static void Main(string[] args) sonarManager.PlaybackDevices.SetPlaybackDevice(sonarManager.PlaybackDevices.GetOutputPlaybackDevices().First(), channel); } Thread.Sleep(1000); - sonarManager.PlaybackDevices.SetPlaybackDevice(_playbackDevice, channel); + sonarManager.PlaybackDevices.SetPlaybackDevice(playbackDevice, channel); Console.WriteLine("Routed Processes test..."); - foreach (var r in _routedProcesses) + foreach (var r in routedProcesses) { if (channel == Channel.GAME) { @@ -109,7 +111,7 @@ static void Main(string[] args) } } Thread.Sleep(1000); - foreach (var r in _routedProcesses) + foreach (var r in routedProcesses) { sonarManager.RoutedProcesses.RouteProcessToChannel(r, channel); } @@ -119,9 +121,13 @@ static void Main(string[] args) if (sonarManager.ChatMix.GetState()) { Console.WriteLine("Chat Mix Test..."); - sonarManager.ChatMix.SetBalance(_chatmix + 0.2); + sonarManager.ChatMix.SetBalance(chatmix + 0.2); Thread.Sleep(1000); - sonarManager.ChatMix.SetBalance(_chatmix); + sonarManager.ChatMix.SetBalance(chatmix); + } + else + { + Console.WriteLine("Chat Mix disabled. Can't do test"); } sonarManager.Mode.Set(Mode.STREAMER); @@ -130,16 +136,88 @@ static void Main(string[] args) { foreach (Mix mix in (Mix[])Enum.GetValues(typeof(Mix))) { + Console.WriteLine("------ " + channel + " - " + mix + " ------"); if (channel == Channel.MASTER) { - + var volume = sonarManager.VolumeSettings.GetVolume(channel, mix); + var mute = sonarManager.VolumeSettings.GetMute(channel, mix); + + Console.WriteLine("Volume test..."); + sonarManager.VolumeSettings.SetVolume(volume - 0.2, channel, mix); + Thread.Sleep(1000); + sonarManager.VolumeSettings.SetVolume(volume, channel, mix); + + Thread.Sleep(500); + + Console.WriteLine("Mute test..."); + sonarManager.VolumeSettings.SetMute(!mute, channel, mix); + Thread.Sleep(1000); + sonarManager.VolumeSettings.SetMute(mute, channel, mix); } else { + var volume = sonarManager.VolumeSettings.GetVolume(channel, mix); + var mute = sonarManager.VolumeSettings.GetMute(channel, mix); + var redirection = sonarManager.Mix.GetState(channel, mix); + Console.WriteLine("Volume test..."); + sonarManager.VolumeSettings.SetVolume(volume - 0.2, channel, mix); + Thread.Sleep(1000); + sonarManager.VolumeSettings.SetVolume(volume, channel, mix); + + Thread.Sleep(500); + + Console.WriteLine("Mute test..."); + sonarManager.VolumeSettings.SetMute(!mute, channel, mix); + Thread.Sleep(1000); + sonarManager.VolumeSettings.SetMute(mute, channel, mix); + + Console.WriteLine("Mix test..."); + sonarManager.Mix.SetState(!redirection, channel, mix); + Thread.Sleep(1000); + sonarManager.Mix.SetState(redirection, channel, mix); } } } + + Console.WriteLine("Playback Device test..."); + foreach (Mix mix in (Mix[])Enum.GetValues(typeof(Mix))) + { + try + { + Console.WriteLine(mix); + var playbackDevice = sonarManager.PlaybackDevices.GetPlaybackDevice(mix); + sonarManager.PlaybackDevices.SetPlaybackDevice(sonarManager.PlaybackDevices.GetOutputPlaybackDevices().First(), mix); + Thread.Sleep(1000); + sonarManager.PlaybackDevices.SetPlaybackDevice(playbackDevice, mix); + } + catch (PlaybackDeviceNotFoundException e) + { + Console.WriteLine(e); + Console.WriteLine("No playback device set for : " + mix); + } + } + + try + { + Console.WriteLine(Channel.MIC + " " + Mode.STREAMER); + var micPlaybackDevice = sonarManager.PlaybackDevices.GetPlaybackDevice(Channel.MIC, Mode.STREAMER); + sonarManager.PlaybackDevices.SetPlaybackDevice(sonarManager.PlaybackDevices.GetOutputPlaybackDevices().First(), Channel.MIC, Mode.STREAMER); + Thread.Sleep(1000); + sonarManager.PlaybackDevices.SetPlaybackDevice(micPlaybackDevice, Channel.MIC, Mode.STREAMER); + } + catch (PlaybackDeviceNotFoundException e) + { + Console.WriteLine(e); + Console.WriteLine("No playback device set for : " + Channel.MIC + Mode.STREAMER); + } + + Console.WriteLine("Audience Monitoring Test..."); + sonarManager.AudienceMonitoring.SetState(!audienceMonitoring); + Thread.Sleep(1000); + sonarManager.AudienceMonitoring.SetState(audienceMonitoring); + + sonarManager.Mode.Set(mode); } static void OnModeChangeHandler(object? sender, SonarModeEvent eventArgs) From 2fb0c3db8d7f4eb3496f75ed512fa9070a10dd6e Mon Sep 17 00:00:00 2001 From: DataNext Date: Mon, 28 Apr 2025 19:23:38 +0200 Subject: [PATCH 42/47] Revamped Sample project --- SteelSeriesAPI.Sample/Program.cs | 96 +++++++++++++++++++------------- 1 file changed, 58 insertions(+), 38 deletions(-) diff --git a/SteelSeriesAPI.Sample/Program.cs b/SteelSeriesAPI.Sample/Program.cs index 005cbae..175d60e 100644 --- a/SteelSeriesAPI.Sample/Program.cs +++ b/SteelSeriesAPI.Sample/Program.cs @@ -12,25 +12,28 @@ static void Main(string[] args) // Create a Sonar Object to control Sonar SonarBridge sonarManager = new SonarBridge(); + // Wait until GG is started before continuing + sonarManager.WaitUntilSteelSeriesStarted(); // Wait until GG and Sonar are both started before continuing sonarManager.WaitUntilSonarStarted(); - // If I want to detect changes made on GG, I can use the listener (require admin rights) + // If you want to detect changes made on GG, you can use the listener (require admin rights) sonarManager.StartListener(); - // Then I register the events I want (I've put them all to demonstrate) - sonarManager.Events.OnSonarModeChange += OnModeChangeHandler; // When the mode is change - sonarManager.Events.OnSonarVolumeChange += OnVolumeChangeHandler; // When the volume of a Sonar Channel or Mix is changed - sonarManager.Events.OnSonarMuteChange += OnMuteChangeHandler; // When a Sonar Channel or Mix is muted or unmuted + // Then you register the events you need (I've put them all to demonstrate) + sonarManager.Events.OnSonarModeChange += OnModeChangeHandler; // When the mode gets changed + sonarManager.Events.OnSonarVolumeChange += OnVolumeChangeHandler; // When the volume of a Sonar Channel or Mix gets changed + sonarManager.Events.OnSonarMuteChange += OnMuteChangeHandler; // When a Sonar Channel or Mix gets muted or unmuted sonarManager.Events.OnSonarConfigChange += OnConfigChangeHandler; // When a new config is set to a Sonar Channel - sonarManager.Events.OnSonarChatMixChange += OnChatMixChangeHandler; // When the ChatMix value is changed + sonarManager.Events.OnSonarChatMixChange += OnChatMixChangeHandler; // When the ChatMix value gets changed sonarManager.Events.OnSonarPlaybackDeviceChange += OnPlaybackDeviceChangeHandler; // When the Redirection Channel of a Sonar Channel is changed - sonarManager.Events.OnSonarRedirectionStateChange += OnRedirectionStateChangeHandler; // When the Redirection of a Sonar Mix is muted or unmuted - sonarManager.Events.OnSonarAudienceMonitoringChange += OnAudienceMonitoringChangeHandler; // When the Audience Monitoring is muted or unmuted + sonarManager.Events.OnSonarRoutedProcessChange += OnRoutedProcessChangeHandler; // When a routed process gets routed to a new Sonar Channel + sonarManager.Events.OnSonarMixChange += OnMixChangeHandler; // When the Mix of a Sonar Channem gets activated or deactivated + sonarManager.Events.OnSonarAudienceMonitoringChange += OnAudienceMonitoringChangeHandler; // When the Audience Monitoring gets muted or unmuted // Get current sonar mode - Mode mode = sonarManager.GetMode(); + Mode mode = sonarManager.Mode.Get(); // Change sonar mode to Streamer - sonarManager.SetMode(Mode.STREAMER); + sonarManager.Mode.Set(Mode.STREAMER); // Get current volume of a Sonar Channel double vol = sonarManager.VolumeSettings.GetVolume(Channel.MEDIA); @@ -39,11 +42,11 @@ static void Main(string[] args) // Set the volume of a Sonar Channel sonarManager.VolumeSettings.SetVolume(0.75, Channel.GAME); // Set the volume of a Sonar Mix - sonarManager.VolumeSettings.SetVolume(0.1, Channel.MEDIA, Mix.MONITORING); + sonarManager.VolumeSettings.SetVolume(0.1, Channel.MEDIA, Mix.PERSONAL); // Get the current mute state of a Sonar Channel bool state = sonarManager.VolumeSettings.GetMute(Channel.CHAT); - bool state2 = sonarManager.VolumeSettings.GetMute(Channel.MASTER, Mix.MONITORING); + bool state2 = sonarManager.VolumeSettings.GetMute(Channel.MASTER, Mix.PERSONAL); // Set the current mute state of a Sonar Channel sonarManager.VolumeSettings.SetMute(true, Channel.CHAT); // Mute chat @@ -53,8 +56,8 @@ static void Main(string[] args) SonarAudioConfiguration currentConfig = sonarManager.Configurations.GetSelectedAudioConfiguration(Channel.MEDIA); // Return the currently used config of a Sonar Channel // Set the config of a Sonar Channel sonarManager.Configurations.SetConfigByName(Channel.MEDIA, "Podcast"); // Using its name - sonarManager.Configurations.SetConfig(currentConfig.Id); // Using its id (no need to precise which Sonar Channel, one id goes to one Sonar Channel) - sonarManager.Configurations.SetConfig(currentConfig); // Or you can just directly give the config + sonarManager.Configurations.SetConfig(currentConfig); // Using directly the config object + sonarManager.Configurations.SetConfig(currentConfig.Id); // Or Using its id (no need to precise which Sonar Channel, one id = one config = one Sonar Channel) // Get ChatMix info double chatMixBalance = sonarManager.ChatMix.GetBalance(); // The ChatMix value between -1 and 1 @@ -63,31 +66,43 @@ static void Main(string[] args) sonarManager.ChatMix.SetBalance(0.5); // 0.5 is halfway to Chat // Get playback devices (Windows devices) - List inputDevices = sonarManager.PlaybackDevices.GetPlaybackDevices(DataFlow.INPUT).ToList(); // Input devices (Mics...) - sonarManager.PlaybackDevices.GetPlaybackDevices(DataFlow.OUTPUT); // Output devices (headset, speakers...) - sonarManager.PlaybackDevices.GetPlaybackDevice("{0.0.0.00000000}.{192b4f5b-9cc1-4eb2-b752-c5e15b99d548}"); // Get a redirection channel from its id - PlaybackDevice gameRDevice = sonarManager.PlaybackDevices.GetClassicPlaybackDevice(Channel.GAME); // Give currently used Redirection Channel for classic mode - sonarManager.PlaybackDevices.GetStreamerPlaybackDevice(Mix.MONITORING); // Give currently used Redirection Channel for Streamer mode - sonarManager.PlaybackDevices.GetStreamerPlaybackDevice(Channel.MIC); // Give currently used Redirection Channel for Mic in streamer mode - // Change playback devices using their id - sonarManager.PlaybackDevices.SetClassicPlaybackDevice(gameRDevice.Id, Channel.GAME); - sonarManager.PlaybackDevices.SetStreamerPlaybackDevice(gameRDevice.Id, Mix.MONITORING); - sonarManager.PlaybackDevices.SetStreamerPlaybackDevice(inputDevices[0].Id, Channel.MIC); + List playbackDevices = sonarManager.PlaybackDevices.GetAllPlaybackDevices().ToList(); // All playback devices + List inputDevices = sonarManager.PlaybackDevices.GetInputPlaybackDevices().ToList(); // Input devices (Mics...) + List outputDevices = sonarManager.PlaybackDevices.GetOutputPlaybackDevices().ToList(); // Output devices (headset, speakers...) + PlaybackDevice gameDevice = sonarManager.PlaybackDevices.GetPlaybackDevice(Channel.GAME); // Get the currently used Playback device of a Channel + sonarManager.PlaybackDevices.GetPlaybackDevice(Mix.STREAM); // Get the currently used Playback device of a Mix + sonarManager.PlaybackDevices.GetPlaybackDevice(Channel.MIC, Mode.STREAMER); // Get the currently used Playback device of the streamer mode Mic + sonarManager.PlaybackDevices.GetPlaybackDevice("{0.0.0.00000000}.{192b4f5b-9cc1-4eb2-b752-c5e15b99d548}"); // Get a playback device from its id + // Change playback devices + sonarManager.PlaybackDevices.SetPlaybackDevice(gameDevice, Channel.GAME); // Using the playback device object + sonarManager.PlaybackDevices.SetPlaybackDevice("{0.0.0.00000000}.{192b4f5b-9cc1-4eb2-b752-c5e15b99d548}", Channel.AUX); // Using the playback device ID - // Get the redirections states - sonarManager.GetRedirectionState(Channel.MEDIA, Mix.MONITORING); - // Change the redirections states - sonarManager.SetRedirectionState(false, Channel.MEDIA, Mix.MONITORING); + // Get the mixes states + sonarManager.Mix.GetState(Channel.MEDIA, Mix.PERSONAL); + // Change the mixes states + sonarManager.Mix.Activate(Channel.MEDIA, Mix.PERSONAL); + sonarManager.Mix.Deactivate(Channel.CHAT, Mix.STREAM); + sonarManager.Mix.SetState(false, Channel.MEDIA, Mix.PERSONAL); // Same as deactivating here // Get Audience Monitoring state - sonarManager.GetAudienceMonitoringState(); + sonarManager.AudienceMonitoring.GetState(); // Change Audience Monitoring state - sonarManager.SetAudienceMonitoringState(false); - - // Get routed processes of a Sonar Channel - List mediaProcesses = sonarManager.GetRoutedProcess(Channel.MEDIA).ToList(); // Will surely return apps like Google Chrome or Spotify + sonarManager.AudienceMonitoring.SetState(false); + + // Get all routed processes whether they are active, inactive or expired + List allProcesses = sonarManager.RoutedProcesses.GetAllRoutedProcesses().ToList(); + // Get all active routed processes (currently in use) + List allActiveProcesses = sonarManager.RoutedProcesses.GetAllActiveRoutedProcesses().ToList(); + // Same but for a specific channel + List gameProcesses = sonarManager.RoutedProcesses.GetRoutedProcesses(Channel.GAME).ToList(); // Will surely return apps like Minecraft... + List mediaActiveProcesses = sonarManager.RoutedProcesses.GetActiveRoutedProcesses(Channel.MEDIA).ToList(); // Will surely return apps like Google Chrome or Spotify + // Same idea but by giving the ID of an audio process + sonarManager.RoutedProcesses.GetRoutedProcessesById(2063); + sonarManager.RoutedProcesses.GetActiveRoutedProcessesById(10548); + // Route a process to a Sonar Channel using the RoutedProcess object + sonarManager.RoutedProcesses.RouteProcessToChannel(mediaActiveProcesses[0], Channel.AUX); // Route a process to a Sonar Channel using its process ID (pid) - sonarManager.SetProcessToDeviceRouting(mediaProcesses[0].PId, Channel.MEDIA); + sonarManager.RoutedProcesses.RouteProcessToChannel(15482, Channel.MEDIA); } static void OnModeChangeHandler(object? sender, SonarModeEvent eventArgs) @@ -117,16 +132,21 @@ static void OnChatMixChangeHandler(object? sender, SonarChatMixEvent eventArgs) static void OnPlaybackDeviceChangeHandler(object? sender, SonarPlaybackDeviceEvent eventArgs) { - Console.WriteLine("Received Redirection Channel Event : " + eventArgs.RedirectionDeviceId + ", " + eventArgs.Mode + ", " + eventArgs.Device + ", " + eventArgs.Channel); + Console.WriteLine("Received Redirection Channel Event : " + eventArgs.PlaybackDeviceId + ", " + eventArgs.Mode + ", " + eventArgs.Device + ", " + eventArgs.Channel); + } + + static void OnRoutedProcessChangeHandler(object? sender, SonarRoutedProcessEvent eventArgs) + { + Console.WriteLine("Received Routed Process Event : " + eventArgs.ProcessId + ", " + eventArgs.NewChannel); } - static void OnRedirectionStateChangeHandler(object? sender, SonarRedirectionStateEvent eventArgs) + static void OnMixChangeHandler(object? sender, SonarMixEvent eventArgs) { - Console.WriteLine("Received Redirection State Event : " + eventArgs.State + ", " + eventArgs.Channel + ", " + eventArgs.Mix); + Console.WriteLine("Received Redirection State Event : " + eventArgs.NewState + ", " + eventArgs.Channel + ", " + eventArgs.Mix); } static void OnAudienceMonitoringChangeHandler(object? sender, SonarAudienceMonitoringEvent eventArgs) { - Console.WriteLine("Received Audience Monitoring Event : " + eventArgs.AudienceMonitoringState); + Console.WriteLine("Received Audience Monitoring Event : " + eventArgs.NewState); } } \ No newline at end of file From 298c4b821da7225e929d26dd91124447bd591e94 Mon Sep 17 00:00:00 2001 From: DataNext Date: Mon, 28 Apr 2025 19:39:31 +0200 Subject: [PATCH 43/47] Update README.md --- README.md | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index ac5d6d3..79beca7 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,21 @@ > This library is **NOT** affiliated in any way with **SteelSeries** > I've made it because it was interesting and funny to do, also I wanted to share this project for people to use it for their own projects -This library allows you to take control over the SteelSeries GG app. +This library allows you to take control over the SteelSeries GG app (only Sonar for now). -The API is available via a [nuget package](https://www.nuget.org/packages/Steelseries-NET-API). +The library is available via a [nuget package](https://www.nuget.org/packages/Steelseries-NET-API). It is also available in the [Releases](https://github.com/mpaperno/SteelSeries-NET-API/releases) tab as a .zip archive for each supported .NET version. ## Features - Full Sonar control + - Mode + - Volume + - Mute + - ChatMix + - Configs (Can't edit a config) + - Playback Devices + - Streamer mode Personal & Stream Mixes + - Streamer mode Audience Monitoring ## Getting Started To get started, you only need to create a Sonar Object. @@ -25,6 +33,9 @@ To get started, you only need to create a Sonar Object. // Create Sonar object SonarBridge sonarManager = new SonarBridge(); +// Wait for GG to start before continuing +sonarManager.WaitUntilSteelSeriesStarted(); + // Wait for sonar to start before continuing sonarManager.WaitUntilSonarStarted(); @@ -32,23 +43,15 @@ sonarManager.WaitUntilSonarStarted(); sonarManager.StartListener(); sonarManager.SonarEventManager.OnSonarModeChange += OnModeChangeHandler; // Register event -Mode currentMode = sonarManager.GetMode(); // Returns the current mode -sonarManager.SetVolume(0.5, Device.Game); // Set the Game Device volume +Mode currentMode = sonarManager.Mode.Get(); // Returns the current mode +sonarManager.VolumeSettings.SetVolume(0.5, Device.Game); // Set the Game Device volume ... ````` -For more example, you can check the [Tests](https://github.com/DataNext27/SteelSeries-NET-API/tree/main/SteelSeriesAPI.Tests) and the [Sample](https://github.com/DataNext27/SteelSeries-NET-API/tree/main/SteelSeriesAPI.Sample) folders. +For more example, you can check the [Sample](SteelSeriesAPI.Sample/Program.cs) and the [Tests](SteelSeriesAPI.Tests/Program.cs) folders. If you need any sort of Documentation, go check the [Repo's Wiki](https://github.com/DataNext27/SteelSeries-NET-API/wiki) for more information. -### Some Vocabulary -- Mode : Classic/Stream -- Device : Master/Game/Chat/Media/Aux/Mic -- Channel : *(Streamer mode)* Monitoring/Stream -- Audio Configs : It's in the name -- Redirection States : *(Streamer mode)* Button above sliders to un/mute a channel of a device -- Redirection Device : Device where the sound got by GG is redirected (your headset for example) - ## Todo -(Actually not possible, maybe one day i guess :/ ) +(Actually not planned as not possible, maybe one day I guess :/ ) - Moments - Engine - Settings From b99eaf2be5aa0cbc2b6b2f0e8cca5cda1ba55507 Mon Sep 17 00:00:00 2001 From: DataNext Date: Tue, 29 Apr 2025 01:20:53 +0200 Subject: [PATCH 44/47] Removed unused Exception --- .../Sonar/Exceptions/NoStreamRedirectionSetException.cs | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 SteelSeriesAPI/Sonar/Exceptions/NoStreamRedirectionSetException.cs diff --git a/SteelSeriesAPI/Sonar/Exceptions/NoStreamRedirectionSetException.cs b/SteelSeriesAPI/Sonar/Exceptions/NoStreamRedirectionSetException.cs deleted file mode 100644 index 467c7de..0000000 --- a/SteelSeriesAPI/Sonar/Exceptions/NoStreamRedirectionSetException.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace SteelSeriesAPI.Sonar.Exceptions; - -public class NoStreamRedirectionSetException : Exception -{ - public NoStreamRedirectionSetException() : base("No redirection was set. Check the playback devices of the streamer mode") { } - public NoStreamRedirectionSetException(string message) : base("No redirection was set. Check the playback devices of the streamer mode\n" + message) { } - public NoStreamRedirectionSetException(string message, Exception innerException) : base("No redirection was set. Check the playback devices of the streamer mode\n" + message, innerException) { } -} \ No newline at end of file From 51f8f3f3f29958604a5039a34f3e059b8a69c0fd Mon Sep 17 00:00:00 2001 From: DataNext Date: Tue, 29 Apr 2025 01:59:47 +0200 Subject: [PATCH 45/47] Some event variable weren't renamed --- SteelSeriesAPI/Sonar/Events/SonarPlaybackDeviceEvent.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SteelSeriesAPI/Sonar/Events/SonarPlaybackDeviceEvent.cs b/SteelSeriesAPI/Sonar/Events/SonarPlaybackDeviceEvent.cs index 5ef3a9a..28692bc 100644 --- a/SteelSeriesAPI/Sonar/Events/SonarPlaybackDeviceEvent.cs +++ b/SteelSeriesAPI/Sonar/Events/SonarPlaybackDeviceEvent.cs @@ -11,7 +11,7 @@ public class SonarPlaybackDeviceEvent : EventArgs public Mode Mode { get; set; } - public Channel? Device { get; set; } + public Channel? Channel { get; set; } - public Mix? Channel { get; set; } + public Mix? Mix { get; set; } } \ No newline at end of file From 938631f8f12d721f541feef9ba2241630edf6607 Mon Sep 17 00:00:00 2001 From: DataNext Date: Tue, 29 Apr 2025 02:01:23 +0200 Subject: [PATCH 46/47] Renamed event var correctly --- SteelSeriesAPI.Sample/Program.cs | 2 +- SteelSeriesAPI.Tests/Program.cs | 2 +- SteelSeriesAPI/Sonar/Managers/EventManager.cs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/SteelSeriesAPI.Sample/Program.cs b/SteelSeriesAPI.Sample/Program.cs index 175d60e..22f5b93 100644 --- a/SteelSeriesAPI.Sample/Program.cs +++ b/SteelSeriesAPI.Sample/Program.cs @@ -132,7 +132,7 @@ static void OnChatMixChangeHandler(object? sender, SonarChatMixEvent eventArgs) static void OnPlaybackDeviceChangeHandler(object? sender, SonarPlaybackDeviceEvent eventArgs) { - Console.WriteLine("Received Redirection Channel Event : " + eventArgs.PlaybackDeviceId + ", " + eventArgs.Mode + ", " + eventArgs.Device + ", " + eventArgs.Channel); + Console.WriteLine("Received Redirection Channel Event : " + eventArgs.PlaybackDeviceId + ", " + eventArgs.Mode + ", " + eventArgs.Channel + ", " + eventArgs.Mix); } static void OnRoutedProcessChangeHandler(object? sender, SonarRoutedProcessEvent eventArgs) diff --git a/SteelSeriesAPI.Tests/Program.cs b/SteelSeriesAPI.Tests/Program.cs index 6871763..cb3c195 100644 --- a/SteelSeriesAPI.Tests/Program.cs +++ b/SteelSeriesAPI.Tests/Program.cs @@ -247,7 +247,7 @@ static void OnChatMixChangeHandler(object? sender, SonarChatMixEvent eventArgs) static void OnPlaybackDeviceChangeHandler(object? sender, SonarPlaybackDeviceEvent eventArgs) { - Console.WriteLine("Received Redirection Channel Event : " + eventArgs.PlaybackDeviceId + ", " + eventArgs.Mode + ", " + eventArgs.Device + ", " + eventArgs.Channel); + Console.WriteLine("Received Redirection Channel Event : " + eventArgs.PlaybackDeviceId + ", " + eventArgs.Mode + ", " + eventArgs.Channel + ", " + eventArgs.Mix); } static void OnRoutedProcessChangeHandler(object? sender, SonarRoutedProcessEvent eventArgs) diff --git a/SteelSeriesAPI/Sonar/Managers/EventManager.cs b/SteelSeriesAPI/Sonar/Managers/EventManager.cs index e20a657..4ab738d 100644 --- a/SteelSeriesAPI/Sonar/Managers/EventManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/EventManager.cs @@ -160,7 +160,7 @@ private EventArgs PathResolver(string path) { PlaybackDeviceId = subs[4].Replace("%7B", "{").Replace("%7D", "}"), Mode = Mode.CLASSIC, - Device = (Channel)ChannelExtensions.FromDictKey(subs[2], ChannelMapChoice.ChannelDict)! + Channel = (Channel)ChannelExtensions.FromDictKey(subs[2], ChannelMapChoice.ChannelDict)! }; break; case "streamRedirections": @@ -179,7 +179,7 @@ private EventArgs PathResolver(string path) { PlaybackDeviceId = subs[4].Replace("%7B", "{").Replace("%7D", "}"), Mode = Mode.STREAMER, - Device = Channel.MIC + Channel = Channel.MIC }; break; } @@ -188,7 +188,7 @@ private EventArgs PathResolver(string path) { PlaybackDeviceId = subs[4].Replace("%7B", "{").Replace("%7D", "}"), Mode = Mode.STREAMER, - Channel = (Mix)MixExtensions.FromDictKey(subs[2])! + Mix = (Mix)MixExtensions.FromDictKey(subs[2])! }; break; case "redirections": From b797aef41f7631cd7d54598fc3645af8bed9f02a Mon Sep 17 00:00:00 2001 From: DataNext Date: Tue, 29 Apr 2025 04:05:07 +0200 Subject: [PATCH 47/47] Changed the version --- SteelSeriesAPI/SteelSeriesAPI.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SteelSeriesAPI/SteelSeriesAPI.csproj b/SteelSeriesAPI/SteelSeriesAPI.csproj index cee74ab..05b5235 100644 --- a/SteelSeriesAPI/SteelSeriesAPI.csproj +++ b/SteelSeriesAPI/SteelSeriesAPI.csproj @@ -4,7 +4,7 @@ enable enable net8.0;net9.0;net7.0 - 1.0.5 + 1.1.0 Steelseries-NET-API Steelseries-NET-API SteelSeries .NET API Client