diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e3ff273 --- /dev/null +++ b/LICENSE @@ -0,0 +1,18 @@ +Microsoft Public License (Ms-PL) + +This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software. + +Definitions +The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law. +A "contribution" is the original software, or any additions or changes to the software. +A "contributor" is any person that distributes its contribution under this license. +"Licensed patents" are a contributor's patent claims that read directly on its contribution. +Grant of Rights +(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create. +(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software. +Conditions and Limitations +(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. +(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically. +(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software. +(D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license. +(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees, or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement. diff --git a/README.md b/README.md index a21fd76..a7e2b5a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,48 @@ -# AudioSwitcher.PowerShell -Powershell Module wrapper around AudioSwitcher Api +Core Audio Powershell Module +---- + +Installation +------ + +Using PsGet enter the following command. + +``` +Install-Module -ModuleUrl https://github.com/xenolightning/AudioSwitcher/releases/download/Module-1.0.0.1/AudioSwitcher.zip +``` + +Alternatively: + +1. Download the latest zip package +2. Extract to %User%\Documents\WindowsPowershell\Modules\AudioSwitcher + +3. Run `Install-Module AudioSwitcher` +``` +\---Modules + +---AudioSwitcher + | AudioSwitcher.AudioApi.CoreAudio.dll + | AudioSwitcher.AudioApi.dll + | AudioSwitcher.PowerShell.CoreAudio.dll + | AudioSwitcher.psd1 +``` + + +Usage +------ + +Currently three commands are available: + + +Returns a reference to an audiocontroller object. This audio controller can do everything! +``` +Get-AudioController +``` + +Returns a list of devices in the system +``` +Get-AudioDevices [-Type All|Playback|Capture] +``` + +Returns a specific device in the system +``` +Get-AudioDevice [-Id (Guid)] [-Name (string - support wildcards)] +``` diff --git a/src/AudioSwitcher.PowerShell.CoreAudio.sln b/src/AudioSwitcher.PowerShell.CoreAudio.sln new file mode 100644 index 0000000..1ff23f5 --- /dev/null +++ b/src/AudioSwitcher.PowerShell.CoreAudio.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AudioSwitcher.PowerShell.CoreAudio", "AudioSwitcher.PowerShell.CoreAudio\AudioSwitcher.PowerShell.CoreAudio.csproj", "{9A82713C-6B21-4312-9294-454C50FAC5ED}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9A82713C-6B21-4312-9294-454C50FAC5ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9A82713C-6B21-4312-9294-454C50FAC5ED}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9A82713C-6B21-4312-9294-454C50FAC5ED}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9A82713C-6B21-4312-9294-454C50FAC5ED}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/src/AudioSwitcher.PowerShell.CoreAudio/AudioSwitcher.PowerShell.CoreAudio.csproj b/src/AudioSwitcher.PowerShell.CoreAudio/AudioSwitcher.PowerShell.CoreAudio.csproj new file mode 100644 index 0000000..43fa357 --- /dev/null +++ b/src/AudioSwitcher.PowerShell.CoreAudio/AudioSwitcher.PowerShell.CoreAudio.csproj @@ -0,0 +1,75 @@ + + + + + Debug + AnyCPU + {9A82713C-6B21-4312-9294-454C50FAC5ED} + Library + Properties + AudioSwitcher.PowerShell.CoreAudio + AudioSwitcher.PowerShell.CoreAudio + v4.5.2 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\AudioSwitcher.AudioApi.3.0.0\lib\net40\AudioSwitcher.AudioApi.dll + True + + + ..\packages\AudioSwitcher.AudioApi.CoreAudio.3.0.0.1\lib\net40\AudioSwitcher.AudioApi.CoreAudio.dll + True + + + + + True + ..\packages\System.Management.Automation.6.1.7601.17515\lib\net45\System.Management.Automation.dll + + + + + + + + + + + + + + + + PreserveNewest + + + + + + + \ No newline at end of file diff --git a/src/AudioSwitcher.PowerShell.CoreAudio/AudioSwitcher.psd1 b/src/AudioSwitcher.PowerShell.CoreAudio/AudioSwitcher.psd1 new file mode 100644 index 0000000..bafcd9e Binary files /dev/null and b/src/AudioSwitcher.PowerShell.CoreAudio/AudioSwitcher.psd1 differ diff --git a/src/AudioSwitcher.PowerShell.CoreAudio/GetAudioController.cs b/src/AudioSwitcher.PowerShell.CoreAudio/GetAudioController.cs new file mode 100644 index 0000000..ab7baa4 --- /dev/null +++ b/src/AudioSwitcher.PowerShell.CoreAudio/GetAudioController.cs @@ -0,0 +1,45 @@ +using System; +using System.Management.Automation; +using AudioSwitcher.AudioApi; +using AudioSwitcher.AudioApi.CoreAudio; + +namespace AudioSwitcher.PowerShell.CoreAudio +{ + + [Cmdlet(VerbsCommon.Get, "AudioController")] + public class GetAudioController : Cmdlet + { + private IAudioController _controller; + + [Parameter] + public Guid? Id + { + get; + set; + } + + [Parameter] + public string Name + { + get; + set; + } + + protected override void BeginProcessing() + { + //lazy setup of the controll + _controller = new CoreAudioController(); + } + + protected override void ProcessRecord() + { + WriteObject(_controller); + } + + protected override void EndProcessing() + { + if (_controller != null) + _controller.Dispose(); + } + } +} diff --git a/src/AudioSwitcher.PowerShell.CoreAudio/GetAudioDevice.cs b/src/AudioSwitcher.PowerShell.CoreAudio/GetAudioDevice.cs new file mode 100644 index 0000000..0c1c435 --- /dev/null +++ b/src/AudioSwitcher.PowerShell.CoreAudio/GetAudioDevice.cs @@ -0,0 +1,57 @@ +using System; +using System.Linq; +using System.Management.Automation; +using AudioSwitcher.AudioApi; +using AudioSwitcher.AudioApi.CoreAudio; + +namespace AudioSwitcher.PowerShell.CoreAudio +{ + + [Cmdlet(VerbsCommon.Get, "AudioDevice")] + public class GetAudioDevice : Cmdlet + { + private IAudioController _controller; + + [Parameter] + public Guid? Id + { + get; + set; + } + + [Parameter] + public string Name + { + get; + set; + } + + protected override void BeginProcessing() + { + _controller = new CoreAudioController(); + } + + protected override void ProcessRecord() + { + if (Id.HasValue) + { + WriteObject(_controller.GetDevice(Id.Value)); + } + else + { + var wildCard = new WildcardPattern(Name, WildcardOptions.IgnoreCase); + + WriteObject( + _controller.GetDevices() + .FirstOrDefault(x => wildCard.IsMatch(x.Name))); + } + } + + protected override void EndProcessing() + { + if (_controller != null) + _controller.Dispose(); + } + + } +} diff --git a/src/AudioSwitcher.PowerShell.CoreAudio/GetAudioDevices.cs b/src/AudioSwitcher.PowerShell.CoreAudio/GetAudioDevices.cs new file mode 100644 index 0000000..0221985 --- /dev/null +++ b/src/AudioSwitcher.PowerShell.CoreAudio/GetAudioDevices.cs @@ -0,0 +1,55 @@ +using System.Collections.Generic; +using System.Management.Automation; +using AudioSwitcher.AudioApi; +using AudioSwitcher.AudioApi.CoreAudio; + +namespace AudioSwitcher.PowerShell.CoreAudio +{ + + [Cmdlet(VerbsCommon.Get, "AudioDevices")] + public class GetAudioDevices : Cmdlet + { + private IAudioController _controller; + + [Parameter] + public DeviceType Type + { + get; + set; + } + + + protected override void BeginProcessing() + { + _controller = new CoreAudioController(); + } + + protected override void ProcessRecord() + { + IEnumerable devices; + + switch (Type) + { + default: + devices = _controller.GetDevices(); + break; + case DeviceType.Playback: + devices = _controller.GetPlaybackDevices(); + break; + case DeviceType.Capture: + devices = _controller.GetCaptureDevices(); + break; + } + + foreach (var device in devices) + WriteObject(device); + } + + protected override void EndProcessing() + { + if (_controller != null) + _controller.Dispose(); + } + + } +} diff --git a/src/AudioSwitcher.PowerShell.CoreAudio/Properties/AssemblyInfo.cs b/src/AudioSwitcher.PowerShell.CoreAudio/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..e21531c --- /dev/null +++ b/src/AudioSwitcher.PowerShell.CoreAudio/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("AudioSwitcher.PowerShell.CoreAudio")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Forty One")] +[assembly: AssemblyProduct("AudioSwitcher.PowerShell.CoreAudio")] +[assembly: AssemblyCopyright("Copyright © Forty One 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("94543dd4-f7bd-4272-b8f7-09af1c7644f1")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.2")] +[assembly: AssemblyFileVersion("1.0.0.2")] diff --git a/src/AudioSwitcher.PowerShell.CoreAudio/app.config b/src/AudioSwitcher.PowerShell.CoreAudio/app.config new file mode 100644 index 0000000..f3235f8 --- /dev/null +++ b/src/AudioSwitcher.PowerShell.CoreAudio/app.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/AudioSwitcher.PowerShell.CoreAudio/packages.config b/src/AudioSwitcher.PowerShell.CoreAudio/packages.config new file mode 100644 index 0000000..6c95957 --- /dev/null +++ b/src/AudioSwitcher.PowerShell.CoreAudio/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file