frgnca / AudioDeviceCmdlets

AudioDeviceCmdlets is a suite of PowerShell Cmdlets to control audio devices on Windows
MIT License
737 stars 92 forks source link

Add -DefaultOnly and -CommunicationOnly parameter to Set-AudioDevice #48

Closed ThreePinkApples closed 2 years ago

ThreePinkApples commented 2 years ago

These parameters provide an additional option to the AudioDevice/ID/Index parameters to only set default playback or communication device and not the other. Very useful when you have headsets that have two audio devices, one for communication and one for normal playback.

Ghost-Terms commented 2 years ago

While I'm aware there is #30, I think it would be prudent to include a -CommunicationOnly parameter in your PR so that the implementations are consistent and there's no merge conflicts.

frgnca commented 2 years ago

I'll be honest, I haven't tried to compile this project for quite some time. I will try to do just that in the following days after I install Visual Studio back on my computer, and then I'll come back to you. In any case, thank you in advance for your contribution.

ThreePinkApples commented 2 years ago

I'll be honest, I haven't tried to compile this project for quite some time. I will try to do just that in the following days after I install Visual Studio back on my computer, and then I'll come back to you. In any case, thank you in advance for your contribution.

I used Visual Studio Community 2022 and build it with both .NET Framework 4.8 and .NET 6.0 (used a conversion tool to test it out, no code changes needed)

Ghost-Terms commented 2 years ago

I'll be honest, I haven't tried to compile this project for quite some time. I will try to do just that in the following days after I install Visual Studio back on my computer, and then I'll come back to you. In any case, thank you in advance for your contribution.

No need for all that, just use this workflow. Push it to .github/workflows/CI.yml and it'll start working automatically.

name: CI

on: [push]

jobs:
  build:
    runs-on: windows-latest
    steps:
    - uses: actions/checkout@v1
      name: Checkout Code

    - name: Setup NuGet
      uses: NuGet/setup-nuget@v1.0.5

    - name: Add MSBuild to PATH
      uses: microsoft/setup-msbuild@v1.1

    - name: Build
      working-directory: SOURCE
      run: |
        (Get-ChildItem $pwd\* -Include *.cs | &{process{'  <Compile Include="'+$_.Name+'" />'}}) -join "`n" | & {
        @"
        <Project ToolsVersion="12.0" DefaultTargets="Build">
        <PropertyGroup>
          <OutputType>Library</OutputType>
          <AssemblyName>AudioDeviceCmdlets</AssemblyName>
          <RootNamespace>AudioDeviceCmdlets</RootNamespace>
          <TargetFrameworks>net48</TargetFrameworks>
          <DebugSymbols>false</DebugSymbols>
          <Optimize>true</Optimize>
          <OutputPath>bin\</OutputPath>
          <IntermediateOutputPath>obj\</IntermediateOutputPath>
        </PropertyGroup>
        <ItemDefinitionGroup><Reference><Private>False</Private></Reference></ItemDefinitionGroup>
        <ItemGroup>
          <Reference Include="Microsoft.CSharp" />
          <Reference Include="System" />
          <Reference Include="System.Core" />
          <Reference Include="System.Data" />
          <Reference Include="System.Data.DataSetExtensions" />
          <Reference Include="System.Management.Automation">
            <HintPath>packages\Microsoft.PowerShell.5.1.ReferenceAssemblies.1.0.0\lib\net461\System.Management.Automation.dll</HintPath>
          </Reference>
          <Reference Include="System.Xml" />
          <Reference Include="System.Xml.Linq" />
        </ItemGroup>
        <ItemGroup>
        $Input
        </ItemGroup>
        <Import Project="`$(MSBuildToolsPath)\Microsoft.CSHARP.Targets" />
        </Project>
        "@
        } | Out-File AudioDeviceCmdlets.csproj
        Install-Package Microsoft.PowerShell.5.1.ReferenceAssemblies -Destination $pwd\packages -Force
        msbuild

    - name: Upload Artifact
      uses: actions/upload-artifact@v1.0.0
      with:
        name: AudioDeviceCmdlets
        path: SOURCE\bin\
frgnca commented 2 years ago

I used Visual Studio Community 2022 and build it with [...] .NET Framework 4.8

@ThreePinkApples I still want to think through and verify a few things before I merge this code and update the package. But I wanted to let you know that I was able to build it (while targeting as low as .NET Framework 4.6.1) and at first glance it seems to be working as intended.

frgnca commented 2 years ago

I think the -PlaybackOnly parameter should be renamed to -DefaultOnly because it can be used to set a playback device as well as a recording device. What do you guys think about seeking something like that as an end result?

Set-AudioDevice <AudioDevice>               # Set the given playback/recording device as both the default device and the default communication device, for its type
Set-AudioDevice <AudioDevice> -CommunicationOnly    # Set the given playback/recording device as the default communication device and not the default device, for its type
Set-AudioDevice <AudioDevice> -DefaultOnly      # Set the given playback/recording device as the default device and not the default communication device, for its type
Set-AudioDevice -ID <string>                # Set the device with the ID corresponding to the given <string> as both the default device and the default communication device, for its type
Set-AudioDevice -ID <string> -CommunicationOnly     # Set the device with the ID corresponding to the given <string> as the default communication device and not the default device, for its type
Set-AudioDevice -ID <string> -DefaultOnly       # Set the device with the ID corresponding to the given <string> as the default device and not the default communication device, for its type
Set-AudioDevice -Index <int>                # Set the device with the Index corresponding to the given <int> as both the default device and the default communication device, for its type
Set-AudioDevice -Index <int> -CommunicationOnly     # Set the device with the Index corresponding to the given <int> as the default communication device and not the default device, for its type
Set-AudioDevice -Index <int> -DefaultOnly       # Set the device with the Index corresponding to the given <int> as the default device and not the default communication device, for its type
Set-AudioDevice -PlaybackCommunicationMuteToggle    # Set the default communication playback device's mute state to the opposite of its current mute state
Set-AudioDevice -PlaybackCommunicationMute <bool>   # Set the default communication playback device's mute state to the given <bool>
Set-AudioDevice -PlaybackCommunicationVolume <float>    # Set the default communication playback device's volume level on 100 to the given <float>
Set-AudioDevice -PlaybackMuteToggle         # Set the default playback device's mute state to the opposite of its current mute state
Set-AudioDevice -PlaybackMute <bool>            # Set the default playback device's mute state to the given <bool>
Set-AudioDevice -PlaybackVolume <float>         # Set the default playback device's volume level on 100 to the given <float>
Set-AudioDevice -RecordingCommunicationMuteToggle   # Set the default communication recording device's mute state to the opposite of its current mute state
Set-AudioDevice -RecordingCommunicationMute <bool>  # Set the default communication recording device's mute state to the given <bool>
Set-AudioDevice -RecordingCommunicationVolume <float>   # Set the default communication recording device's volume level on 100 to the given <float>
Set-AudioDevice -RecordingMuteToggle            # Set the default recording device's mute state to the opposite of its current mute state
Set-AudioDevice -RecordingMute <bool>           # Set the default recording device's mute state to the given <bool>
Set-AudioDevice -RecordingVolume <float>        # Set the default recording device's volume level on 100 to the given <float>
Ghost-Terms commented 2 years ago

I think the -PlaybackOnly parameter should be renamed to -DefaultOnly because it can be used to set a playback device as well as a recording device. What do you guys think about seeking something like that as an end result?

Set-AudioDevice   <AudioDevice>               # Set the given playback/recording device as both the default device and the default communication device, for its type
Set-AudioDevice <AudioDevice> -CommunicationOnly  # Set the given playback/recording device as the default communication device and not the default device, for its type
Set-AudioDevice <AudioDevice> -DefaultOnly        # Set the given playback/recording device as the default device and not the default communication device, for its type
Set-AudioDevice -ID <string>              # Set the device with the ID corresponding to the given <string> as both the default device and the default communication device, for its type
Set-AudioDevice -ID <string> -CommunicationOnly       # Set the device with the ID corresponding to the given <string> as the default communication device and not the default device, for its type
Set-AudioDevice -ID <string> -DefaultOnly     # Set the device with the ID corresponding to the given <string> as the default device and not the default communication device, for its type
Set-AudioDevice -Index <int>              # Set the device with the Index corresponding to the given <int> as both the default device and the default communication device, for its type
Set-AudioDevice -Index <int> -CommunicationOnly       # Set the device with the Index corresponding to the given <int> as the default communication device and not the default device, for its type
Set-AudioDevice -Index <int> -DefaultOnly     # Set the device with the Index corresponding to the given <int> as the default device and not the default communication device, for its type
Set-AudioDevice -PlaybackCommunicationMuteToggle  # Set the default communication playback device's mute state to the opposite of its current mute state
Set-AudioDevice -PlaybackCommunicationMute <bool> # Set the default communication playback device's mute state to the given <bool>
Set-AudioDevice -PlaybackCommunicationVolume <float>  # Set the default communication playback device's volume level on 100 to the given <float>
Set-AudioDevice -PlaybackMuteToggle           # Set the default playback device's mute state to the opposite of its current mute state
Set-AudioDevice -PlaybackMute <bool>          # Set the default playback device's mute state to the given <bool>
Set-AudioDevice -PlaybackVolume <float>           # Set the default playback device's volume level on 100 to the given <float>
Set-AudioDevice -RecordingCommunicationMuteToggle # Set the default communication recording device's mute state to the opposite of its current mute state
Set-AudioDevice -RecordingCommunicationMute <bool>    # Set the default communication recording device's mute state to the given <bool>
Set-AudioDevice -RecordingCommunicationVolume <float> # Set the default communication recording device's volume level on 100 to the given <float>
Set-AudioDevice -RecordingMuteToggle          # Set the default recording device's mute state to the opposite of its current mute state
Set-AudioDevice -RecordingMute <bool>         # Set the default recording device's mute state to the given <bool>
Set-AudioDevice -RecordingVolume <float>      # Set the default recording device's volume level on 100 to the given <float>

Could always just do a parameter alias, then we can have both.

ThreePinkApples commented 2 years ago

I think the -PlaybackOnly parameter should be renamed to -DefaultOnly because it can be used to set a playback device as well as a recording device. What do you guys think about seeking something like that as an end result?

I agree on -DefaultOnly being a better name for it

frgnca commented 2 years ago

@ThreePinkApples Could you please open a different Pull Request targeting the dev_v3.0.1_communicationdevice branch instead of the master branch?

Everything seems in order so I intend to merge your code right away then.

ThreePinkApples commented 2 years ago

New PR #51

frgnca commented 2 years ago

Tusen takk @ThreePinkApples