using System.Collections.Generic;
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
{
///
/// Gets the current input port
///
public RoutingInputPort CurrentInputPort => AnyAudioIn;
///
/// Event fired when the current source changes
///
public event SourceInfoChangeHandler CurrentSourceChange;
///
/// Gets or sets the current source info key
///
public string CurrentSourceInfoKey { get; set; }
///
/// Gets or sets the current source info
///
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; }
///
/// Constructor for GenericAudioOut
///
/// Device key
/// Device name
public GenericAudioOut(string key, string name)
: base(key, name)
{
AnyAudioIn = new RoutingInputPort(RoutingPortNames.AnyAudioIn, eRoutingSignalType.Audio,
eRoutingPortConnectionType.LineAudio, null, this);
}
#region IRoutingInputs Members
///
/// Gets the collection of input ports
///
public RoutingPortCollection InputPorts
{
get { return new RoutingPortCollection { AnyAudioIn }; }
}
#endregion
}
///
/// Represents a GenericAudioOutWithVolume
///
public class GenericAudioOutWithVolume : GenericAudioOut, IHasVolumeDevice
{
///
/// Gets the volume device key
///
public string VolumeDeviceKey { get; private set; }
///
/// Gets the volume zone
///
public uint VolumeZone { get; private set; }
///
/// Gets the volume device
///
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;
}
}
///
/// Factory for creating GenericAudioOutWithVolume devices
///
public class GenericAudioOutWithVolumeFactory : EssentialsDeviceFactory
{
///
/// Constructor for GenericAudioOutWithVolumeFactory
///
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);
}
}
}