Skip to content

Commit

Permalink
Initial source import
Browse files Browse the repository at this point in the history
  • Loading branch information
xenolightning committed Nov 7, 2016
1 parent e86d30d commit d199669
Show file tree
Hide file tree
Showing 11 changed files with 372 additions and 2 deletions.
18 changes: 18 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
50 changes: 48 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)]
```
22 changes: 22 additions & 0 deletions src/AudioSwitcher.PowerShell.CoreAudio.sln
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9A82713C-6B21-4312-9294-454C50FAC5ED}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AudioSwitcher.PowerShell.CoreAudio</RootNamespace>
<AssemblyName>AudioSwitcher.PowerShell.CoreAudio</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="AudioSwitcher.AudioApi, Version=3.0.0.209, Culture=neutral, PublicKeyToken=fda5729e2db3a64f, processorArchitecture=MSIL">
<HintPath>..\packages\AudioSwitcher.AudioApi.3.0.0\lib\net40\AudioSwitcher.AudioApi.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="AudioSwitcher.AudioApi.CoreAudio, Version=3.0.0.209, Culture=neutral, PublicKeyToken=fda5729e2db3a64f, processorArchitecture=MSIL">
<HintPath>..\packages\AudioSwitcher.AudioApi.CoreAudio.3.0.0.1\lib\net40\AudioSwitcher.AudioApi.CoreAudio.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\System.Management.Automation.6.1.7601.17515\lib\net45\System.Management.Automation.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="GetAudioController.cs" />
<Compile Include="GetAudioDevice.cs" />
<Compile Include="GetAudioDevices.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="AudioSwitcher.psd1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
<None Include="README.md" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Binary file not shown.
45 changes: 45 additions & 0 deletions src/AudioSwitcher.PowerShell.CoreAudio/GetAudioController.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
57 changes: 57 additions & 0 deletions src/AudioSwitcher.PowerShell.CoreAudio/GetAudioDevice.cs
Original file line number Diff line number Diff line change
@@ -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();
}

}
}
55 changes: 55 additions & 0 deletions src/AudioSwitcher.PowerShell.CoreAudio/GetAudioDevices.cs
Original file line number Diff line number Diff line change
@@ -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<IDevice> 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();
}

}
}
35 changes: 35 additions & 0 deletions src/AudioSwitcher.PowerShell.CoreAudio/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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")]
11 changes: 11 additions & 0 deletions src/AudioSwitcher.PowerShell.CoreAudio/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="AudioSwitcher.AudioApi" publicKeyToken="fda5729e2db3a64f" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.2.151" newVersion="2.2.2.151" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
6 changes: 6 additions & 0 deletions src/AudioSwitcher.PowerShell.CoreAudio/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AudioSwitcher.AudioApi" version="3.0.0" targetFramework="net45" />
<package id="AudioSwitcher.AudioApi.CoreAudio" version="3.0.0.1" targetFramework="net45" />
<package id="System.Management.Automation" version="6.1.7601.17515" targetFramework="net45" />
</packages>

0 comments on commit d199669

Please sign in to comment.