From 1df8d3f6177efb7d5eecad054e1b0b8f6f86768e Mon Sep 17 00:00:00 2001 From: jkdevito Date: Thu, 2 Nov 2023 11:54:44 -0500 Subject: [PATCH 1/8] feat: create branch to add volume control --- .../Chassis/HdPsXxxController.cs | 35 +++++++++++++++++-- .../Config/HdPsXxxPropertiesConfig.cs | 3 ++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs index 36e99bc6..f676c80c 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs @@ -16,9 +16,11 @@ using PepperDash_Essentials_DM.Config; namespace PepperDash_Essentials_DM.Chassis { [Description("Wrapper class for all HdPsXxx switchers")] - public class HdPsXxxController : CrestronGenericBridgeableBaseDevice, IRoutingNumericWithFeedback, IRoutingHasVideoInputSyncFeedbacks + public class HdPsXxxController : CrestronGenericBridgeableBaseDevice, IRoutingNumericWithFeedback, IRoutingHasVideoInputSyncFeedbacks, IHasVolumeControlWithFeedback { private readonly HdPsXxx _chassis; + private readonly string _defaultAudioKey = ""; + public RoutingPortCollection InputPorts { get; private set; } public RoutingPortCollection OutputPorts { get; private set; } @@ -82,6 +84,9 @@ namespace PepperDash_Essentials_DM.Chassis OutputNames = props.Outputs; SetupOutputs(OutputNames); + + if (!string.IsNullOrEmpty(props.DefaultAudioKey)) + _defaultAudioKey = props.DefaultAudioKey; } // get input priorities @@ -413,6 +418,31 @@ Selector: {4} _chassis.AutoRouteOff(); } + #region IHasVolumeWithFeedback Members + + public void VolumeUp(bool pressRelease) + { + + } + + public void VolumeDown(bool pressRelease) + { + throw new NotImplementedException(); + } + + public void SetVolume(ushort level) + { + throw new NotImplementedException(); + } + + public IntFeedback VolumeLevelFeedback { get; private set; } + + + + #endregion + + + #region Events @@ -517,6 +547,7 @@ Selector: {4} #endregion + #region Factory @@ -571,7 +602,7 @@ Selector: {4} } - #endregion + #endregion } diff --git a/essentials-framework/Essentials DM/Essentials_DM/Config/HdPsXxxPropertiesConfig.cs b/essentials-framework/Essentials DM/Essentials_DM/Config/HdPsXxxPropertiesConfig.cs index 576b74f0..9b988dd1 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Config/HdPsXxxPropertiesConfig.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Config/HdPsXxxPropertiesConfig.cs @@ -15,6 +15,9 @@ namespace PepperDash_Essentials_DM.Config [JsonProperty("outputs")] public Dictionary Outputs { get; set; } + [JsonProperty("defaultAudioKey")] + public string DefaultAudioKey { get; set; } + // "inputPriorities": "1,4,3,2" [JsonProperty("inputPriorities")] public string InputPriorities { get; set; } From 355e9cde12b76b0433018f98652cff4aa96b0be8 Mon Sep 17 00:00:00 2001 From: jkdevito Date: Thu, 2 Nov 2023 11:55:48 -0500 Subject: [PATCH 2/8] chore(wip): save updates --- .../Essentials_DM/Chassis/HdPsXxxController.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs index f676c80c..9a2a17f4 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; +using System.Runtime.InteropServices; using Crestron.SimplSharpPro; using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.DM; @@ -207,6 +208,14 @@ namespace PepperDash_Essentials_DM.Chassis VideoOutputRouteFeedbacks.Add(new IntFeedback(index.ToString(CultureInfo.InvariantCulture), () => output.VideoOutFeedback == null ? 0 : (int)output.VideoOutFeedback.Number)); + + var audioKey = string.Format("audioOut{0}", index); + var audioPort = new RoutingOutputPort(audioKey, eRoutingSignalType.Audio, eRoutingPortConnectionType.DigitalAudio, + output, this) + { + FeedbackMatchObject = output, + Port = output.OutputPort.AudioOutput; + }; } _chassis.DMOutputChange += _chassis_OutputChange; From c528fecb9a9ead1631a68303c59308fb9171af8f Mon Sep 17 00:00:00 2001 From: Jason DeVito Date: Thu, 2 Nov 2023 17:52:27 -0500 Subject: [PATCH 3/8] feat(wip): add HdPsXxx audio control --- .../HdPsXxxAnalogAuxMixerController.cs | 98 +++++++++++++++++++ .../Chassis/HdPsXxxController.cs | 50 +++------- .../Config/HdPsXxxPropertiesConfig.cs | 4 +- .../PepperDash_Essentials_DM.csproj | 1 + 4 files changed, 114 insertions(+), 39 deletions(-) create mode 100644 essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs new file mode 100644 index 00000000..3fac2cf7 --- /dev/null +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs @@ -0,0 +1,98 @@ +using System; +using Crestron.SimplSharpPro.DM; +using PepperDash.Core; +using PepperDash.Essentials.Core; + +namespace PepperDash_Essentials_DM.Chassis +{ + public class HdPsXxxAnalogAuxMixerController : IKeyed, IBasicVolumeWithFeedback + { + public string Key { get; private set; } + + public HdPsXxxAnalogAuxMixer Mixer { get; set; } + + public HdPsXxxAnalogAuxMixerController(string parent, uint mixer, HdPsXxx chassis) + { + Key = string.Format("{0}-analogMixer{1}", parent, mixer); + + Mixer = chassis.AnalogAuxiliaryMixer[mixer]; + + VolumeLevelFeedback = new IntFeedback(VolumeFeedbackFunc); + MuteFeedback = new BoolFeedback(MuteFeedbackFunc); + } + + #region Volume + + public IntFeedback VolumeLevelFeedback { get; private set; } + + protected Func VolumeFeedbackFunc + { + get { return () => Mixer.VolumeFeedback.UShortValue; } + } + + public void SetVolume(ushort level) + { + Mixer.Volume.UShortValue = level; + } + + public void VolumeUp(bool pressRelease) + { + if (pressRelease) + { + var remainingRatio = (65535 - Mixer.Volume.UShortValue)/65535; + Mixer.Volume.CreateRamp(65535, 400); + } + else + { + Mixer.Volume.StopRamp(); + } + } + + public void VolumeDown(bool pressRelease) + { + if (pressRelease) + { + var remainingRatio = Mixer.Volume.UShortValue/65535; + Mixer.Volume.CreateRamp(0, (uint)(400 * remainingRatio)); + } + else + { + Mixer.Volume.StopRamp(); + } + } + + #endregion + + + #region Mute + + private bool _isMuted; + + public BoolFeedback MuteFeedback { get; private set; } + + protected Func MuteFeedbackFunc + { + get { return () => _isMuted = Mixer.AuxiliaryMuteControl.MuteOnFeedback.BoolValue; } + } + + public void MuteOn() + { + Mixer.AuxiliaryMuteControl.MuteOn(); + } + + public void MuteOff() + { + Mixer.AuxiliaryMuteControl.MuteOff(); + } + + public void MuteToggle() + { + if (_isMuted) + MuteOff(); + else + MuteOn(); + } + + #endregion + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs index 9a2a17f4..1cece4e4 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; -using System.Runtime.InteropServices; using Crestron.SimplSharpPro; using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.DM; @@ -17,11 +16,9 @@ using PepperDash_Essentials_DM.Config; namespace PepperDash_Essentials_DM.Chassis { [Description("Wrapper class for all HdPsXxx switchers")] - public class HdPsXxxController : CrestronGenericBridgeableBaseDevice, IRoutingNumericWithFeedback, IRoutingHasVideoInputSyncFeedbacks, IHasVolumeControlWithFeedback + public class HdPsXxxController : CrestronGenericBridgeableBaseDevice, IRoutingNumericWithFeedback, IRoutingHasVideoInputSyncFeedbacks { private readonly HdPsXxx _chassis; - private readonly string _defaultAudioKey = ""; - public RoutingPortCollection InputPorts { get; private set; } public RoutingPortCollection OutputPorts { get; private set; } @@ -86,8 +83,11 @@ namespace PepperDash_Essentials_DM.Chassis OutputNames = props.Outputs; SetupOutputs(OutputNames); - if (!string.IsNullOrEmpty(props.DefaultAudioKey)) - _defaultAudioKey = props.DefaultAudioKey; + foreach (var mixer in _chassis.AnalogAuxiliaryMixer) + { + var mixerDevice = new HdPsXxxAnalogAuxMixerController(Key, mixer.MixerNumber, _chassis); + DeviceManager.AddDevice(mixerDevice); + } } // get input priorities @@ -208,14 +208,13 @@ namespace PepperDash_Essentials_DM.Chassis VideoOutputRouteFeedbacks.Add(new IntFeedback(index.ToString(CultureInfo.InvariantCulture), () => output.VideoOutFeedback == null ? 0 : (int)output.VideoOutFeedback.Number)); + } - var audioKey = string.Format("audioOut{0}", index); - var audioPort = new RoutingOutputPort(audioKey, eRoutingSignalType.Audio, eRoutingPortConnectionType.DigitalAudio, - output, this) - { - FeedbackMatchObject = output, - Port = output.OutputPort.AudioOutput; - }; + Debug.Console(0, this, "----> AnalogAuxillaryMixer.Count-{0}", _chassis.AnalogAuxiliaryMixer.Count); + foreach (var item in _chassis.AnalogAuxiliaryMixer) + { + Debug.Console(0, this, "----> AnalogAuxillaryMixer[{0}].LineMuteVolumeControl.Count-{1}", item.MixerNumber, item.LineMuteVolumeControl.Count); + Debug.Console(0, this, "----> AnalogAuxillaryMixer[{0}].SourceMuteVolumeControl.Count-{1}", item.MixerNumber, item.SourceMuteVolumeControl.Count); } _chassis.DMOutputChange += _chassis_OutputChange; @@ -427,29 +426,6 @@ Selector: {4} _chassis.AutoRouteOff(); } - #region IHasVolumeWithFeedback Members - - public void VolumeUp(bool pressRelease) - { - - } - - public void VolumeDown(bool pressRelease) - { - throw new NotImplementedException(); - } - - public void SetVolume(ushort level) - { - throw new NotImplementedException(); - } - - public IntFeedback VolumeLevelFeedback { get; private set; } - - - - #endregion - #region Events @@ -564,7 +540,7 @@ Selector: {4} { public HdSp401ControllerFactory() { - TypeNames = new List() { "hdps401", "hdps402", "hdps621", "hdps622" }; + TypeNames = new List { "hdps401", "hdps402", "hdps621", "hdps622" }; } public override EssentialsDevice BuildDevice(DeviceConfig dc) { diff --git a/essentials-framework/Essentials DM/Essentials_DM/Config/HdPsXxxPropertiesConfig.cs b/essentials-framework/Essentials DM/Essentials_DM/Config/HdPsXxxPropertiesConfig.cs index 9b988dd1..f5eb9d39 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Config/HdPsXxxPropertiesConfig.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Config/HdPsXxxPropertiesConfig.cs @@ -15,8 +15,8 @@ namespace PepperDash_Essentials_DM.Config [JsonProperty("outputs")] public Dictionary Outputs { get; set; } - [JsonProperty("defaultAudioKey")] - public string DefaultAudioKey { get; set; } + [JsonProperty("volumeMixerId")] + public uint VolumeMixerId { get; set; } // "inputPriorities": "1,4,3,2" [JsonProperty("inputPriorities")] diff --git a/essentials-framework/Essentials DM/Essentials_DM/PepperDash_Essentials_DM.csproj b/essentials-framework/Essentials DM/Essentials_DM/PepperDash_Essentials_DM.csproj index 0011c305..5840945f 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/PepperDash_Essentials_DM.csproj +++ b/essentials-framework/Essentials DM/Essentials_DM/PepperDash_Essentials_DM.csproj @@ -104,6 +104,7 @@ + From a64b5240ad2b385eb6141bcdd2eaab8d07edc942 Mon Sep 17 00:00:00 2001 From: Jason DeVito Date: Fri, 3 Nov 2023 18:14:53 -0500 Subject: [PATCH 4/8] feat: add output audio controller --- .../HdPsXxxAnalogAuxMixerController.cs | 13 ++- .../Chassis/HdPsXxxController.cs | 19 ++-- .../Chassis/HdPsXxxOutputAudioController.cs | 99 +++++++++++++++++++ .../PepperDash_Essentials_DM.csproj | 1 + 4 files changed, 123 insertions(+), 9 deletions(-) create mode 100644 essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxOutputAudioController.cs diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs index 3fac2cf7..bd6893ee 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs @@ -1,15 +1,17 @@ using System; +using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.DM; using PepperDash.Core; using PepperDash.Essentials.Core; namespace PepperDash_Essentials_DM.Chassis { - public class HdPsXxxAnalogAuxMixerController : IKeyed, IBasicVolumeWithFeedback + public class HdPsXxxAnalogAuxMixerController : IKeyed, + IHasVolumeControlWithFeedback, IHasMuteControlWithFeedback // || IBasicVolumeWithFeedback { public string Key { get; private set; } - public HdPsXxxAnalogAuxMixer Mixer { get; set; } + public HdPsXxxAnalogAuxMixer Mixer { get; private set; } public HdPsXxxAnalogAuxMixerController(string parent, uint mixer, HdPsXxx chassis) { @@ -17,10 +19,17 @@ namespace PepperDash_Essentials_DM.Chassis Mixer = chassis.AnalogAuxiliaryMixer[mixer]; + Mixer.AuxMixerPropertyChange += OnAuxMixerPropertyChange; + VolumeLevelFeedback = new IntFeedback(VolumeFeedbackFunc); MuteFeedback = new BoolFeedback(MuteFeedbackFunc); } + private void OnAuxMixerPropertyChange(object sender, GenericEventArgs args) + { + Debug.Console(2, this, "AuxMixerPropertyChange: {0} > Index-{1}, EventId-{2}", sender.ToString(), args.Index, args.EventId); + } + #region Volume public IntFeedback VolumeLevelFeedback { get; private set; } diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs index 1cece4e4..a4bef385 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs @@ -83,10 +83,15 @@ namespace PepperDash_Essentials_DM.Chassis OutputNames = props.Outputs; SetupOutputs(OutputNames); - foreach (var mixer in _chassis.AnalogAuxiliaryMixer) + foreach (var item in _chassis.HdmiDmLiteOutputs) { - var mixerDevice = new HdPsXxxAnalogAuxMixerController(Key, mixer.MixerNumber, _chassis); - DeviceManager.AddDevice(mixerDevice); + var audioDevice = new HdPsXxxOutputAudioController(Key, item.Number, _chassis); + DeviceManager.AddDevice(audioDevice); + } + foreach (var item in _chassis.AnalogAuxiliaryMixer) + { + var audioDevice = new HdPsXxxAnalogAuxMixerController(Key, item.MixerNumber, _chassis); + DeviceManager.AddDevice(audioDevice); } } @@ -180,7 +185,7 @@ namespace PepperDash_Essentials_DM.Chassis var output = item; var index = item.Number; var name = string.IsNullOrEmpty(OutputNames[index]) - ? string.Format("Output {0}", index) + ? string.Format("Port {0}", index) : OutputNames[index]; output.Name.StringValue = name; @@ -191,7 +196,7 @@ namespace PepperDash_Essentials_DM.Chassis FeedbackMatchObject = output, Port = output.HdmiOutput.HdmiOutputPort }; - Debug.Console(1, this, "Adding Output port: {0} - {1}", hdmiPort.Key, name); + Debug.Console(1, this, "Adding Port port: {0} - {1}", hdmiPort.Key, name); OutputPorts.Add(hdmiPort); var dmLiteKey = string.Format("dmLiteOut{0}", index); @@ -200,7 +205,7 @@ namespace PepperDash_Essentials_DM.Chassis FeedbackMatchObject = output, Port = output.DmLiteOutput.DmLiteOutputPort }; - Debug.Console(1, this, "Adding Output port: {0} - {1}", dmLitePort.Key, name); + Debug.Console(1, this, "Adding Port port: {0} - {1}", dmLitePort.Key, name); OutputPorts.Add(dmLitePort); OutputRouteNameFeedback.Add(new StringFeedback(index.ToString(CultureInfo.InvariantCulture), @@ -237,7 +242,7 @@ Selector: {4} foreach (var port in OutputPorts) { - Debug.Console(0, this, @"Output Port Key: {0} + Debug.Console(0, this, @"Port Port Key: {0} Port: {1} Type: {2} ConnectionType: {3} diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxOutputAudioController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxOutputAudioController.cs new file mode 100644 index 00000000..9716ba1e --- /dev/null +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxOutputAudioController.cs @@ -0,0 +1,99 @@ +using System; +using Crestron.SimplSharpPro.DM; +using PepperDash.Core; +using PepperDash.Essentials.Core; + +namespace PepperDash_Essentials_DM.Chassis +{ + public class HdPsXxxOutputAudioController : IKeyed, + IHasVolumeControlWithFeedback, IHasMuteControlWithFeedback // || IBasicVolumeWithFeedback + { + public string Key { get; private set; } + + public HdPsXxxOutputPort Port { get; private set; } + + public HdPsXxxOutputAudioController(string parent, uint output, HdPsXxx chassis) + { + Key = string.Format("{0}-audioOut{1}", parent, output); + + Port = chassis.HdmiDmLiteOutputs[output].OutputPort; + + VolumeLevelFeedback = new IntFeedback(VolumeFeedbackFunc); + MuteFeedback = new BoolFeedback(MuteFeedbackFunc); + } + + #region Volume + + public IntFeedback VolumeLevelFeedback { get; private set; } + + protected Func VolumeFeedbackFunc + { + get { return () => Port.AudioOutput.VolumeFeedback.UShortValue; } + } + + public void SetVolume(ushort level) + { + Port.AudioOutput.Volume.UShortValue = level; + } + + public void VolumeUp(bool pressRelease) + { + if (pressRelease) + { + var remainingRatio = (65535 - Port.AudioOutput.Volume.UShortValue)/65535; + Port.AudioOutput.Volume.CreateRamp(65535, 400); + } + else + { + Port.AudioOutput.Volume.StopRamp(); + } + } + + public void VolumeDown(bool pressRelease) + { + if (pressRelease) + { + var remainingRatio = Port.AudioOutput.Volume.UShortValue/65535; + Port.AudioOutput.Volume.CreateRamp(0, (uint)(400 * remainingRatio)); + } + else + { + Port.AudioOutput.Volume.StopRamp(); + } + } + + #endregion + + + #region Mute + + private bool _isMuted; + + public BoolFeedback MuteFeedback { get; private set; } + + protected Func MuteFeedbackFunc + { + get { return () => _isMuted = Port.MuteOnFeedback.BoolValue; } + } + + public void MuteOn() + { + Port.MuteOn(); + } + + public void MuteOff() + { + Port.MuteOff(); + } + + public void MuteToggle() + { + if (_isMuted) + MuteOff(); + else + MuteOn(); + } + + #endregion + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials DM/Essentials_DM/PepperDash_Essentials_DM.csproj b/essentials-framework/Essentials DM/Essentials_DM/PepperDash_Essentials_DM.csproj index 5840945f..41136d0d 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/PepperDash_Essentials_DM.csproj +++ b/essentials-framework/Essentials DM/Essentials_DM/PepperDash_Essentials_DM.csproj @@ -106,6 +106,7 @@ + From d713abf614dd8e3ccf330c260e2c1dbcd962bb34 Mon Sep 17 00:00:00 2001 From: Jason DeVito Date: Thu, 9 Nov 2023 23:36:54 -0600 Subject: [PATCH 5/8] fix: update hd-ps audio controllers to resolve control issues --- .../HdPsXxxAnalogAuxMixerController.cs | 105 ++++++++++++++---- .../Chassis/HdPsXxxOutputAudioController.cs | 80 +++++++++---- 2 files changed, 143 insertions(+), 42 deletions(-) diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs index bd6893ee..fc8ed0e2 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs @@ -1,4 +1,4 @@ -using System; +using Crestron.SimplSharp; using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.DM; using PepperDash.Core; @@ -20,36 +20,72 @@ namespace PepperDash_Essentials_DM.Chassis Mixer = chassis.AnalogAuxiliaryMixer[mixer]; Mixer.AuxMixerPropertyChange += OnAuxMixerPropertyChange; + Mixer.AuxiliaryMuteControl.MuteAndVolumeControlPropertyChange += OnMuteAndVolumeControlPropertyChange; - VolumeLevelFeedback = new IntFeedback(VolumeFeedbackFunc); - MuteFeedback = new BoolFeedback(MuteFeedbackFunc); - } + VolumeLevelFeedback = new IntFeedback(() => VolumeLevel); + MuteFeedback = new BoolFeedback(() => IsMuted); - private void OnAuxMixerPropertyChange(object sender, GenericEventArgs args) - { - Debug.Console(2, this, "AuxMixerPropertyChange: {0} > Index-{1}, EventId-{2}", sender.ToString(), args.Index, args.EventId); + VolumeLevel = Mixer.VolumeFeedback.ShortValue; + IsMuted = Mixer.AuxiliaryMuteControl.MuteOnFeedback.BoolValue; } #region Volume - public IntFeedback VolumeLevelFeedback { get; private set; } - - protected Func VolumeFeedbackFunc + private void OnAuxMixerPropertyChange(object sender, GenericEventArgs args) { - get { return () => Mixer.VolumeFeedback.UShortValue; } + Debug.Console(2, this, "AuxMixerPropertyChange: {0} > Index-{1}, EventId-{2}", sender.GetType().ToString(), args.Index, args.EventId); + + switch (args.EventId) + { + case (3): + { + VolumeLevel = Mixer.VolumeFeedback.ShortValue; + break; + } + } } + private const ushort CrestronLevelMin = 0; + private const ushort CrestronLevelMax = 65535; + + private const int DeviceLevelMin = -800; + private const int DeviceLevelMax = 200; + + private const int RampTime = 5000; + + private int _volumeLevel; + + public int VolumeLevel + { + get { return _volumeLevel; } + set + { + var level = value; + _volumeLevel = CrestronEnvironment.ScaleWithLimits(level, DeviceLevelMax, DeviceLevelMin, CrestronLevelMax, CrestronLevelMin); + + Debug.Console(1, this, "VolumeFeedback: level-'{0}', scaled-'{1}'", level, _volumeLevel); + + VolumeLevelFeedback.FireUpdate(); + } + } + + public IntFeedback VolumeLevelFeedback { get; private set; } + public void SetVolume(ushort level) { - Mixer.Volume.UShortValue = level; + var scaled = CrestronEnvironment.ScaleWithLimits(level, CrestronLevelMax, CrestronLevelMin, DeviceLevelMax, + DeviceLevelMin); + + Debug.Console(1, this, "SetVolume: level-'{0}', scaled-'{1}'", level, scaled); + + Mixer.Volume.ShortValue = (short)scaled; } public void VolumeUp(bool pressRelease) { if (pressRelease) { - var remainingRatio = (65535 - Mixer.Volume.UShortValue)/65535; - Mixer.Volume.CreateRamp(65535, 400); + Mixer.Volume.CreateSignedRamp(DeviceLevelMax, RampTime); } else { @@ -61,8 +97,10 @@ namespace PepperDash_Essentials_DM.Chassis { if (pressRelease) { - var remainingRatio = Mixer.Volume.UShortValue/65535; - Mixer.Volume.CreateRamp(0, (uint)(400 * remainingRatio)); + //var remainingRatio = Mixer.Volume.UShortValue/CrestronLevelMax; + //Mixer.Volume.CreateRamp(CrestronLevelMin, (uint)(RampTime * remainingRatio)); + + Mixer.Volume.CreateSignedRamp(DeviceLevelMin, RampTime); } else { @@ -73,17 +111,42 @@ namespace PepperDash_Essentials_DM.Chassis #endregion + + #region Mute + private void OnMuteAndVolumeControlPropertyChange(MuteControl device, GenericEventArgs args) + { + Debug.Console(2, this, "OnMuteAndVolumeControlPropertyChange: {0} > Index-{1}, EventId-{2}", device.ToString(), args.Index, args.EventId); + + switch (args.EventId) + { + case (1): + case (2): + { + IsMuted = Mixer.AuxiliaryMuteControl.MuteOnFeedback.BoolValue; + break; + } + } + } + private bool _isMuted; - public BoolFeedback MuteFeedback { get; private set; } - - protected Func MuteFeedbackFunc + public bool IsMuted { - get { return () => _isMuted = Mixer.AuxiliaryMuteControl.MuteOnFeedback.BoolValue; } + get { return _isMuted; } + set + { + _isMuted = value; + + Debug.Console(1, this, "IsMuted: _isMuted-'{0}'", _isMuted); + + MuteFeedback.FireUpdate(); + } } + public BoolFeedback MuteFeedback { get; private set; } + public void MuteOn() { Mixer.AuxiliaryMuteControl.MuteOn(); @@ -96,7 +159,7 @@ namespace PepperDash_Essentials_DM.Chassis public void MuteToggle() { - if (_isMuted) + if (IsMuted) MuteOff(); else MuteOn(); diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxOutputAudioController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxOutputAudioController.cs index 9716ba1e..d8583f19 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxOutputAudioController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxOutputAudioController.cs @@ -1,47 +1,76 @@ -using System; +using Crestron.SimplSharp; using Crestron.SimplSharpPro.DM; using PepperDash.Core; using PepperDash.Essentials.Core; namespace PepperDash_Essentials_DM.Chassis { - public class HdPsXxxOutputAudioController : IKeyed, + public class HdPsXxxOutputAudioController : IKeyed, IHasVolumeControlWithFeedback, IHasMuteControlWithFeedback // || IBasicVolumeWithFeedback { public string Key { get; private set; } - + public HdPsXxxOutputPort Port { get; private set; } - + public HdPsXxxOutputAudioController(string parent, uint output, HdPsXxx chassis) { Key = string.Format("{0}-audioOut{1}", parent, output); - + Port = chassis.HdmiDmLiteOutputs[output].OutputPort; - VolumeLevelFeedback = new IntFeedback(VolumeFeedbackFunc); - MuteFeedback = new BoolFeedback(MuteFeedbackFunc); + VolumeLevelFeedback = new IntFeedback(() => VolumeLevel); + MuteFeedback = new BoolFeedback(() => IsMuted); + + //if(Port.AudioOutput.Volume != null) + // VolumeLevel = Port.AudioOutput.VolumeFeedback.UShortValue; + + IsMuted = Port.MuteOnFeedback.BoolValue; } #region Volume - public IntFeedback VolumeLevelFeedback { get; private set; } + private const ushort CrestronLevelMin = 0; + private const ushort CrestronLevelMax = 65535; - protected Func VolumeFeedbackFunc + private const int DeviceLevelMin = -800; + private const int DeviceLevelMax = 200; + + private const int RampTime = 5000; + + private int _volumeLevel; + + public int VolumeLevel { - get { return () => Port.AudioOutput.VolumeFeedback.UShortValue; } + get { return _volumeLevel; } + set + { + var level = value; + //_volumeLevel = CrestronEnvironment.ScaleWithLimits(level, DeviceLevelMax, DeviceLevelMin, CrestronLevelMax, CrestronLevelMin); + _volumeLevel = CrestronEnvironment.ScaleWithLimits(level, CrestronLevelMax, CrestronLevelMin, DeviceLevelMax, DeviceLevelMin); + + Debug.Console(2, this, "VolumeFeedback: level-'{0}', scaled-'{1}'", level, _volumeLevel); + + VolumeLevelFeedback.FireUpdate(); + } } + public IntFeedback VolumeLevelFeedback { get; private set; } + public void SetVolume(ushort level) { - Port.AudioOutput.Volume.UShortValue = level; + var scaled = CrestronEnvironment.ScaleWithLimits(level, CrestronLevelMax, CrestronLevelMin, DeviceLevelMax, + DeviceLevelMin); + + Debug.Console(1, this, "SetVolume: level-'{0}', scaled-'{1}'", level, scaled); + + Port.AudioOutput.Volume.ShortValue = (short)scaled; } public void VolumeUp(bool pressRelease) { if (pressRelease) { - var remainingRatio = (65535 - Port.AudioOutput.Volume.UShortValue)/65535; - Port.AudioOutput.Volume.CreateRamp(65535, 400); + Port.AudioOutput.Volume.CreateSignedRamp(DeviceLevelMax, RampTime); } else { @@ -52,9 +81,8 @@ namespace PepperDash_Essentials_DM.Chassis public void VolumeDown(bool pressRelease) { if (pressRelease) - { - var remainingRatio = Port.AudioOutput.Volume.UShortValue/65535; - Port.AudioOutput.Volume.CreateRamp(0, (uint)(400 * remainingRatio)); + { + Port.AudioOutput.Volume.CreateSignedRamp(DeviceLevelMin, RampTime); } else { @@ -65,17 +93,27 @@ namespace PepperDash_Essentials_DM.Chassis #endregion + + #region Mute private bool _isMuted; - public BoolFeedback MuteFeedback { get; private set; } + public bool IsMuted + { + get { return _isMuted; } + set + { + _isMuted = value; - protected Func MuteFeedbackFunc - { - get { return () => _isMuted = Port.MuteOnFeedback.BoolValue; } + Debug.Console(1, this, "IsMuted: _isMuted-'{0}'", _isMuted); + + MuteFeedback.FireUpdate(); + } } + public BoolFeedback MuteFeedback { get; private set; } + public void MuteOn() { Port.MuteOn(); @@ -88,7 +126,7 @@ namespace PepperDash_Essentials_DM.Chassis public void MuteToggle() { - if (_isMuted) + if (IsMuted) MuteOff(); else MuteOn(); From 1c5aca03d295c0cb07fc509a65675a3d1adab181 Mon Sep 17 00:00:00 2001 From: Jason DeVito Date: Wed, 13 Dec 2023 12:36:45 -0600 Subject: [PATCH 6/8] fix: resolves hdPsXxx audio controllers scaleWithLimits exception --- .../Chassis/HdPsXxxAnalogAuxMixerController.cs | 7 +++++-- .../Essentials_DM/Chassis/HdPsXxxController.cs | 4 +++- .../Chassis/HdPsXxxOutputAudioController.cs | 12 ++++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs index fc8ed0e2..694dbb21 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs @@ -61,6 +61,9 @@ namespace PepperDash_Essentials_DM.Chassis set { var level = value; + Debug.Console(1, this, "VolumeLevel: value-'{0}', level-'{1}'", value, level); + + // ScaleWithLimits(inputValue, InputUpperBound, InputLowerBound, OutputUpperBound, OutputLowerBound) _volumeLevel = CrestronEnvironment.ScaleWithLimits(level, DeviceLevelMax, DeviceLevelMin, CrestronLevelMax, CrestronLevelMin); Debug.Console(1, this, "VolumeFeedback: level-'{0}', scaled-'{1}'", level, _volumeLevel); @@ -73,8 +76,8 @@ namespace PepperDash_Essentials_DM.Chassis public void SetVolume(ushort level) { - var scaled = CrestronEnvironment.ScaleWithLimits(level, CrestronLevelMax, CrestronLevelMin, DeviceLevelMax, - DeviceLevelMin); + // ScaleWithLimits(inputValue, InputUpperBound, InputLowerBound, OutputUpperBound, OutputLowerBound) + var scaled = CrestronEnvironment.ScaleWithLimits(level, CrestronLevelMax, CrestronLevelMin, DeviceLevelMax, DeviceLevelMin); Debug.Console(1, this, "SetVolume: level-'{0}', scaled-'{1}'", level, scaled); diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs index a4bef385..defe9c02 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs @@ -86,11 +86,13 @@ namespace PepperDash_Essentials_DM.Chassis foreach (var item in _chassis.HdmiDmLiteOutputs) { var audioDevice = new HdPsXxxOutputAudioController(Key, item.Number, _chassis); + Debug.Console(0, this, "HdPsXxxController: created HdPsXxxOutputAudioController Key-{0}', Output-'{1}'", audioDevice.Key, item.Number); DeviceManager.AddDevice(audioDevice); } foreach (var item in _chassis.AnalogAuxiliaryMixer) { - var audioDevice = new HdPsXxxAnalogAuxMixerController(Key, item.MixerNumber, _chassis); + var audioDevice = new HdPsXxxAnalogAuxMixerController(Key, item.MixerNumber, _chassis); + Debug.Console(0, this, "HdPsXxxController: created HdPsXxAnalogAuxMixerCOntorller Key-{0}', Output-'{1}'", audioDevice.Key, item.MixerNumber); DeviceManager.AddDevice(audioDevice); } } diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxOutputAudioController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxOutputAudioController.cs index d8583f19..608f2465 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxOutputAudioController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxOutputAudioController.cs @@ -45,8 +45,10 @@ namespace PepperDash_Essentials_DM.Chassis set { var level = value; - //_volumeLevel = CrestronEnvironment.ScaleWithLimits(level, DeviceLevelMax, DeviceLevelMin, CrestronLevelMax, CrestronLevelMin); - _volumeLevel = CrestronEnvironment.ScaleWithLimits(level, CrestronLevelMax, CrestronLevelMin, DeviceLevelMax, DeviceLevelMin); + Debug.Console(1, this, "VolumeLevel: value-'{0}', level-'{1}'", value, level); + + // ScaleWithLimits(inputValue, InputUpperBound, InputLowerBound, OutputUpperBound, OutputLowerBound) + _volumeLevel = CrestronEnvironment.ScaleWithLimits(level, DeviceLevelMax, DeviceLevelMin, CrestronLevelMax, CrestronLevelMin); Debug.Console(2, this, "VolumeFeedback: level-'{0}', scaled-'{1}'", level, _volumeLevel); @@ -58,8 +60,10 @@ namespace PepperDash_Essentials_DM.Chassis public void SetVolume(ushort level) { - var scaled = CrestronEnvironment.ScaleWithLimits(level, CrestronLevelMax, CrestronLevelMin, DeviceLevelMax, - DeviceLevelMin); + // ScaleWithLimits(inputValue, InputUpperBound, InputLowerBound, OutputUpperBound, OutputLowerBound) + var scaled = CrestronEnvironment.ScaleWithLimits(level, + CrestronLevelMax, CrestronLevelMin, + DeviceLevelMax, DeviceLevelMin); Debug.Console(1, this, "SetVolume: level-'{0}', scaled-'{1}'", level, scaled); From 67e037880657831838d70230fc130a81da453360 Mon Sep 17 00:00:00 2001 From: Jason DeVito Date: Wed, 13 Dec 2023 12:41:45 -0600 Subject: [PATCH 7/8] fix: cleanup debug statements --- .../Chassis/HdPsXxxAnalogAuxMixerController.cs | 1 - .../Essentials_DM/Chassis/HdPsXxxController.cs | 14 +++++++------- .../Chassis/HdPsXxxOutputAudioController.cs | 5 +---- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs index 694dbb21..c6829c9b 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs @@ -61,7 +61,6 @@ namespace PepperDash_Essentials_DM.Chassis set { var level = value; - Debug.Console(1, this, "VolumeLevel: value-'{0}', level-'{1}'", value, level); // ScaleWithLimits(inputValue, InputUpperBound, InputLowerBound, OutputUpperBound, OutputLowerBound) _volumeLevel = CrestronEnvironment.ScaleWithLimits(level, DeviceLevelMax, DeviceLevelMin, CrestronLevelMax, CrestronLevelMin); diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs index defe9c02..c0363387 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs @@ -86,13 +86,13 @@ namespace PepperDash_Essentials_DM.Chassis foreach (var item in _chassis.HdmiDmLiteOutputs) { var audioDevice = new HdPsXxxOutputAudioController(Key, item.Number, _chassis); - Debug.Console(0, this, "HdPsXxxController: created HdPsXxxOutputAudioController Key-{0}', Output-'{1}'", audioDevice.Key, item.Number); + Debug.Console(2, this, "Adding HdPsXxxOutputAudioController '{0}' for output '{1}'", audioDevice.Key, item.Number); DeviceManager.AddDevice(audioDevice); } foreach (var item in _chassis.AnalogAuxiliaryMixer) { var audioDevice = new HdPsXxxAnalogAuxMixerController(Key, item.MixerNumber, _chassis); - Debug.Console(0, this, "HdPsXxxController: created HdPsXxAnalogAuxMixerCOntorller Key-{0}', Output-'{1}'", audioDevice.Key, item.MixerNumber); + Debug.Console(2, this, "Adding HdPsXxAnalogAuxMixerCOntorller '{0}' for output '{1}'", audioDevice.Key, item.MixerNumber); DeviceManager.AddDevice(audioDevice); } } @@ -216,14 +216,14 @@ namespace PepperDash_Essentials_DM.Chassis VideoOutputRouteFeedbacks.Add(new IntFeedback(index.ToString(CultureInfo.InvariantCulture), () => output.VideoOutFeedback == null ? 0 : (int)output.VideoOutFeedback.Number)); } - - Debug.Console(0, this, "----> AnalogAuxillaryMixer.Count-{0}", _chassis.AnalogAuxiliaryMixer.Count); + /* + Debug.Console(2, this, "----> AnalogAuxillaryMixer.Count-{0}", _chassis.AnalogAuxiliaryMixer.Count); foreach (var item in _chassis.AnalogAuxiliaryMixer) { - Debug.Console(0, this, "----> AnalogAuxillaryMixer[{0}].LineMuteVolumeControl.Count-{1}", item.MixerNumber, item.LineMuteVolumeControl.Count); - Debug.Console(0, this, "----> AnalogAuxillaryMixer[{0}].SourceMuteVolumeControl.Count-{1}", item.MixerNumber, item.SourceMuteVolumeControl.Count); + Debug.Console(2, this, "----> AnalogAuxillaryMixer[{0}].LineMuteVolumeControl.Count-{1}", item.MixerNumber, item.LineMuteVolumeControl.Count); + Debug.Console(2, this, "----> AnalogAuxillaryMixer[{0}].SourceMuteVolumeControl.Count-{1}", item.MixerNumber, item.SourceMuteVolumeControl.Count); } - + */ _chassis.DMOutputChange += _chassis_OutputChange; } diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxOutputAudioController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxOutputAudioController.cs index 608f2465..3f28d91f 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxOutputAudioController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxOutputAudioController.cs @@ -45,7 +45,6 @@ namespace PepperDash_Essentials_DM.Chassis set { var level = value; - Debug.Console(1, this, "VolumeLevel: value-'{0}', level-'{1}'", value, level); // ScaleWithLimits(inputValue, InputUpperBound, InputLowerBound, OutputUpperBound, OutputLowerBound) _volumeLevel = CrestronEnvironment.ScaleWithLimits(level, DeviceLevelMax, DeviceLevelMin, CrestronLevelMax, CrestronLevelMin); @@ -61,9 +60,7 @@ namespace PepperDash_Essentials_DM.Chassis public void SetVolume(ushort level) { // ScaleWithLimits(inputValue, InputUpperBound, InputLowerBound, OutputUpperBound, OutputLowerBound) - var scaled = CrestronEnvironment.ScaleWithLimits(level, - CrestronLevelMax, CrestronLevelMin, - DeviceLevelMax, DeviceLevelMin); + var scaled = CrestronEnvironment.ScaleWithLimits(level, CrestronLevelMax, CrestronLevelMin, DeviceLevelMax, DeviceLevelMin); Debug.Console(1, this, "SetVolume: level-'{0}', scaled-'{1}'", level, scaled); From 5530c91b75fb907ce6033bd10f2f2758c2928cd0 Mon Sep 17 00:00:00 2001 From: Jason DeVito Date: Wed, 13 Dec 2023 16:01:15 -0600 Subject: [PATCH 8/8] refactor: HdPsXxxOutputAudioController & HdPsXxxAnalogAuxMixerController - Updated audio controllers to implement `Volume(Feedback).ShortValue` per documentation for set and get - Changed `VolumeLevel` set to private set - Removed `VolumeLevel` and `IsMuted` set from constructors --- .../HdPsXxxAnalogAuxMixerController.cs | 77 +++++++++++-------- .../Chassis/HdPsXxxController.cs | 2 +- .../Chassis/HdPsXxxOutputAudioController.cs | 67 +++++++++++----- 3 files changed, 94 insertions(+), 52 deletions(-) diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs index c6829c9b..7d27d35b 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs @@ -7,39 +7,47 @@ using PepperDash.Essentials.Core; namespace PepperDash_Essentials_DM.Chassis { public class HdPsXxxAnalogAuxMixerController : IKeyed, - IHasVolumeControlWithFeedback, IHasMuteControlWithFeedback // || IBasicVolumeWithFeedback + IHasVolumeControlWithFeedback, IHasMuteControlWithFeedback { public string Key { get; private set; } - public HdPsXxxAnalogAuxMixer Mixer { get; private set; } + private readonly HdPsXxxAnalogAuxMixer _mixer; public HdPsXxxAnalogAuxMixerController(string parent, uint mixer, HdPsXxx chassis) { Key = string.Format("{0}-analogMixer{1}", parent, mixer); - Mixer = chassis.AnalogAuxiliaryMixer[mixer]; + _mixer = chassis.AnalogAuxiliaryMixer[mixer]; - Mixer.AuxMixerPropertyChange += OnAuxMixerPropertyChange; - Mixer.AuxiliaryMuteControl.MuteAndVolumeControlPropertyChange += OnMuteAndVolumeControlPropertyChange; + _mixer.AuxMixerPropertyChange += OnAuxMixerPropertyChange; + _mixer.AuxiliaryMuteControl.MuteAndVolumeControlPropertyChange += OnMuteAndVolumeControlPropertyChange; VolumeLevelFeedback = new IntFeedback(() => VolumeLevel); MuteFeedback = new BoolFeedback(() => IsMuted); - - VolumeLevel = Mixer.VolumeFeedback.ShortValue; - IsMuted = Mixer.AuxiliaryMuteControl.MuteOnFeedback.BoolValue; } #region Volume private void OnAuxMixerPropertyChange(object sender, GenericEventArgs args) { - Debug.Console(2, this, "AuxMixerPropertyChange: {0} > Index-{1}, EventId-{2}", sender.GetType().ToString(), args.Index, args.EventId); + Debug.Console(2, this, "OnAuxMixerPropertyChange: {0} > Index-{1}, EventId-{2}", sender.ToString(), args.Index, args.EventId); switch (args.EventId) { - case (3): + case MuteAndVolumeContorlEventIds.VolumeFeedbackEventId: { - VolumeLevel = Mixer.VolumeFeedback.ShortValue; + VolumeLevel = _mixer.VolumeFeedback.ShortValue; + break; + } + case MuteAndVolumeContorlEventIds.MuteOnEventId: + case MuteAndVolumeContorlEventIds.MuteOffEventId: + { + IsMuted = _mixer.AuxiliaryMuteControl.MuteOnFeedback.BoolValue; + break; + } + default: + { + Debug.Console(1, this, "OnAuxMixerPropertyChange: {0} > Index-{1}, EventId-{2} - unhandled eventId", sender.ToString(), args.Index, args.EventId); break; } } @@ -58,13 +66,12 @@ namespace PepperDash_Essentials_DM.Chassis public int VolumeLevel { get { return _volumeLevel; } - set + private set { var level = value; - // ScaleWithLimits(inputValue, InputUpperBound, InputLowerBound, OutputUpperBound, OutputLowerBound) _volumeLevel = CrestronEnvironment.ScaleWithLimits(level, DeviceLevelMax, DeviceLevelMin, CrestronLevelMax, CrestronLevelMin); - + Debug.Console(1, this, "VolumeFeedback: level-'{0}', scaled-'{1}'", level, _volumeLevel); VolumeLevelFeedback.FireUpdate(); @@ -72,26 +79,25 @@ namespace PepperDash_Essentials_DM.Chassis } public IntFeedback VolumeLevelFeedback { get; private set; } - + public void SetVolume(ushort level) { - // ScaleWithLimits(inputValue, InputUpperBound, InputLowerBound, OutputUpperBound, OutputLowerBound) - var scaled = CrestronEnvironment.ScaleWithLimits(level, CrestronLevelMax, CrestronLevelMin, DeviceLevelMax, DeviceLevelMin); + var levelScaled = CrestronEnvironment.ScaleWithLimits(level, CrestronLevelMax, CrestronLevelMin, DeviceLevelMax, DeviceLevelMin); - Debug.Console(1, this, "SetVolume: level-'{0}', scaled-'{1}'", level, scaled); - - Mixer.Volume.ShortValue = (short)scaled; + Debug.Console(1, this, "SetVolume: level-'{0}', levelScaled-'{1}'", level, levelScaled); + + _mixer.Volume.ShortValue = (short)levelScaled; } public void VolumeUp(bool pressRelease) { if (pressRelease) { - Mixer.Volume.CreateSignedRamp(DeviceLevelMax, RampTime); + _mixer.Volume.CreateSignedRamp(DeviceLevelMax, RampTime); } else { - Mixer.Volume.StopRamp(); + _mixer.Volume.StopRamp(); } } @@ -99,14 +105,11 @@ namespace PepperDash_Essentials_DM.Chassis { if (pressRelease) { - //var remainingRatio = Mixer.Volume.UShortValue/CrestronLevelMax; - //Mixer.Volume.CreateRamp(CrestronLevelMin, (uint)(RampTime * remainingRatio)); - - Mixer.Volume.CreateSignedRamp(DeviceLevelMin, RampTime); + _mixer.Volume.CreateSignedRamp(DeviceLevelMin, RampTime); } else { - Mixer.Volume.StopRamp(); + _mixer.Volume.StopRamp(); } } @@ -123,12 +126,22 @@ namespace PepperDash_Essentials_DM.Chassis switch (args.EventId) { - case (1): - case (2): + case MuteAndVolumeContorlEventIds.VolumeFeedbackEventId: { - IsMuted = Mixer.AuxiliaryMuteControl.MuteOnFeedback.BoolValue; + VolumeLevel = _mixer.VolumeFeedback.ShortValue; break; } + case MuteAndVolumeContorlEventIds.MuteOnEventId: + case MuteAndVolumeContorlEventIds.MuteOffEventId: + { + IsMuted = _mixer.AuxiliaryMuteControl.MuteOnFeedback.BoolValue; + break; + } + default: + { + Debug.Console(1, this, "OnMuteAndVolumeControlPropertyChange: {0} > Index-{1}, EventId-{2} - unhandled eventId", device.ToString(), args.Index, args.EventId); + break; + } } } @@ -151,12 +164,12 @@ namespace PepperDash_Essentials_DM.Chassis public void MuteOn() { - Mixer.AuxiliaryMuteControl.MuteOn(); + _mixer.AuxiliaryMuteControl.MuteOn(); } public void MuteOff() { - Mixer.AuxiliaryMuteControl.MuteOff(); + _mixer.AuxiliaryMuteControl.MuteOff(); } public void MuteToggle() diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs index c0363387..6b0f8520 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxController.cs @@ -88,7 +88,7 @@ namespace PepperDash_Essentials_DM.Chassis var audioDevice = new HdPsXxxOutputAudioController(Key, item.Number, _chassis); Debug.Console(2, this, "Adding HdPsXxxOutputAudioController '{0}' for output '{1}'", audioDevice.Key, item.Number); DeviceManager.AddDevice(audioDevice); - } + } foreach (var item in _chassis.AnalogAuxiliaryMixer) { var audioDevice = new HdPsXxxAnalogAuxMixerController(Key, item.MixerNumber, _chassis); diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxOutputAudioController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxOutputAudioController.cs index 3f28d91f..57067bde 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxOutputAudioController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxOutputAudioController.cs @@ -6,25 +6,56 @@ using PepperDash.Essentials.Core; namespace PepperDash_Essentials_DM.Chassis { public class HdPsXxxOutputAudioController : IKeyed, - IHasVolumeControlWithFeedback, IHasMuteControlWithFeedback // || IBasicVolumeWithFeedback + IHasVolumeControlWithFeedback, IHasMuteControlWithFeedback { public string Key { get; private set; } - public HdPsXxxOutputPort Port { get; private set; } + private readonly HdPsXxxHdmiDmLiteOutputMixer _mixer; // volume/volumeFeedback + private readonly HdPsXxxOutputPort _port; // mute/muteFeedback public HdPsXxxOutputAudioController(string parent, uint output, HdPsXxx chassis) { Key = string.Format("{0}-audioOut{1}", parent, output); - Port = chassis.HdmiDmLiteOutputs[output].OutputPort; + _port = chassis.HdmiDmLiteOutputs[output].OutputPort; + _mixer = chassis.HdmiDmLiteOutputs[output].Mixer; + + chassis.DMOutputChange += ChassisOnDmOutputChange; VolumeLevelFeedback = new IntFeedback(() => VolumeLevel); MuteFeedback = new BoolFeedback(() => IsMuted); + } - //if(Port.AudioOutput.Volume != null) - // VolumeLevel = Port.AudioOutput.VolumeFeedback.UShortValue; + private void ChassisOnDmOutputChange(Switch device, DMOutputEventArgs args) + { + switch (args.EventId) + { + case (DMOutputEventIds.VolumeEventId): + { + Debug.Console(2, this, "HdPsXxxOutputAudioController: {0} > Index-{1}, Number-{3}, EventId-{2} - AudioMute/UnmuteEventId", + device.ToString(), args.Index, args.EventId, args.Number); - IsMuted = Port.MuteOnFeedback.BoolValue; + VolumeLevel = _mixer.VolumeFeedback.ShortValue; + + break; + } + case DMOutputEventIds.MuteOnEventId: + case DMOutputEventIds.MuteOffEventId: + { + Debug.Console(2, this, "HdPsXxxOutputAudioController: {0} > Index-{1}, Number-{3}, EventId-{2} - MuteOnEventId/MuteOffEventId", + device.ToString(), args.Index, args.EventId, args.Number); + + IsMuted = _port.MuteOnFeedback.BoolValue; + + break; + } + default: + { + Debug.Console(1, this, "HdPsXxxOutputAudioController: {0} > Index-{1}, Number-{3}, EventId-{2} - unhandled eventId", + device.ToString(), args.Index, args.EventId, args.Number); + break; + } + } } #region Volume @@ -42,11 +73,10 @@ namespace PepperDash_Essentials_DM.Chassis public int VolumeLevel { get { return _volumeLevel; } - set + private set { var level = value; - - // ScaleWithLimits(inputValue, InputUpperBound, InputLowerBound, OutputUpperBound, OutputLowerBound) + _volumeLevel = CrestronEnvironment.ScaleWithLimits(level, DeviceLevelMax, DeviceLevelMin, CrestronLevelMax, CrestronLevelMin); Debug.Console(2, this, "VolumeFeedback: level-'{0}', scaled-'{1}'", level, _volumeLevel); @@ -59,23 +89,22 @@ namespace PepperDash_Essentials_DM.Chassis public void SetVolume(ushort level) { - // ScaleWithLimits(inputValue, InputUpperBound, InputLowerBound, OutputUpperBound, OutputLowerBound) - var scaled = CrestronEnvironment.ScaleWithLimits(level, CrestronLevelMax, CrestronLevelMin, DeviceLevelMax, DeviceLevelMin); + var levelScaled = CrestronEnvironment.ScaleWithLimits(level, CrestronLevelMax, CrestronLevelMin, DeviceLevelMax, DeviceLevelMin); - Debug.Console(1, this, "SetVolume: level-'{0}', scaled-'{1}'", level, scaled); + Debug.Console(1, this, "SetVolume: level-'{0}', levelScaled-'{1}'", level, levelScaled); - Port.AudioOutput.Volume.ShortValue = (short)scaled; + _mixer.Volume.ShortValue = (short)levelScaled; } public void VolumeUp(bool pressRelease) { if (pressRelease) { - Port.AudioOutput.Volume.CreateSignedRamp(DeviceLevelMax, RampTime); + _mixer.Volume.CreateSignedRamp(DeviceLevelMax, RampTime); } else { - Port.AudioOutput.Volume.StopRamp(); + _mixer.Volume.StopRamp(); } } @@ -83,11 +112,11 @@ namespace PepperDash_Essentials_DM.Chassis { if (pressRelease) { - Port.AudioOutput.Volume.CreateSignedRamp(DeviceLevelMin, RampTime); + _mixer.Volume.CreateSignedRamp(DeviceLevelMin, RampTime); } else { - Port.AudioOutput.Volume.StopRamp(); + _mixer.Volume.StopRamp(); } } @@ -117,12 +146,12 @@ namespace PepperDash_Essentials_DM.Chassis public void MuteOn() { - Port.MuteOn(); + _port.MuteOn(); } public void MuteOff() { - Port.MuteOff(); + _port.MuteOff(); } public void MuteToggle()