using System; using System.Collections.Generic; using System.Linq; using System.Text; using Crestron.SimplSharp; using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Config; using Serilog.Events; namespace PepperDash.Essentials.Devices.Common { /// /// Represents and audio endpoint /// public class GenericAudioOut : EssentialsDevice, IRoutingSink { public RoutingInputPort CurrentInputPort => AnyAudioIn; public event SourceInfoChangeHandler CurrentSourceChange; public string CurrentSourceInfoKey { get; set; } public SourceListItem CurrentSourceInfo { get { return _CurrentSourceInfo; } set { if (value == _CurrentSourceInfo) return; var handler = CurrentSourceChange; if (handler != null) handler(_CurrentSourceInfo, ChangeType.WillChange); _CurrentSourceInfo = value; if (handler != null) handler(_CurrentSourceInfo, ChangeType.DidChange); } } SourceListItem _CurrentSourceInfo; /// /// Gets or sets the AnyAudioIn /// public RoutingInputPort AnyAudioIn { get; private set; } public GenericAudioOut(string key, string name) : base(key, name) { AnyAudioIn = new RoutingInputPort(RoutingPortNames.AnyAudioIn, eRoutingSignalType.Audio, eRoutingPortConnectionType.LineAudio, null, this); } #region IRoutingInputs Members public RoutingPortCollection InputPorts { get { return new RoutingPortCollection { AnyAudioIn }; } } #endregion } /// /// Represents a GenericAudioOutWithVolume /// public class GenericAudioOutWithVolume : GenericAudioOut, IHasVolumeDevice { public string VolumeDeviceKey { get; private set; } public uint VolumeZone { get; private set; } public IBasicVolumeControls VolumeDevice { get { var dev = DeviceManager.GetDeviceForKey(VolumeDeviceKey); if (dev is IAudioZones) return (dev as IAudioZones).Zone[VolumeZone]; else return dev as IBasicVolumeControls; } } /// /// Constructor - adds the name to the attached audio device, if appropriate. /// /// /// /// /// public GenericAudioOutWithVolume(string key, string name, string audioDevice, uint zone) : base(key, name) { VolumeDeviceKey = audioDevice; VolumeZone = zone; } } public class GenericAudioOutWithVolumeFactory : EssentialsDeviceFactory { public GenericAudioOutWithVolumeFactory() { TypeNames = new List() { "genericaudiooutwithvolume" }; } /// /// BuildDevice method /// /// public override EssentialsDevice BuildDevice(DeviceConfig dc) { Debug.LogMessage(LogEventLevel.Debug, "Factory Attempting to create new GenericAudioOutWithVolumeFactory Device"); var zone = dc.Properties.Value("zone"); return new GenericAudioOutWithVolume(dc.Key, dc.Name, dc.Properties.Value("volumeDeviceKey"), zone); } } }