Well, challenge it was. Now it's up to you to adapt stuff to your case.
The PS1 script now has all the functions you could need: Get-[Input/Output]List to get all the device names, Get-[Input/Output]Device to get the current device name, Set-[Input/Output]Device to set the current device name (using the -Name parameter), Set-[Input/Output]Index to set the current device via an offset applied to its index (using the -Offset parameter, e.g. -Offset -1 for the previous index, -Offset 1 for the next index, etc, can jump by any number):
Code: Select all
Import-Module -Name "$($RmAPI.VariableStr('@'))Addons\AudioDeviceCmdlets"
function Get-OutputList
{
return $($(Get-AudioDevice -List | where Type -eq "Playback" | sort Index).Name -join "`n") + "`n"
}
function Get-InputList
{
return $($(Get-AudioDevice -List | where Type -eq "Recording" | sort Index).Name -join "`n") + "`n"
}
function Get-OutputDevice
{
return $(Get-AudioDevice -Playback).Name
}
function Get-InputDevice
{
return $(Get-AudioDevice -Recording).Name
}
function Get-OutputVolume
{
return Get-AudioDevice -PlaybackVolume
}
function Get-InputVolume
{
return Get-AudioDevice -RecordingVolume
}
function Get-OutputMute
{
if (Get-AudioDevice -PlaybackMute) {return 1} else {return 0}
}
function Get-InputMute
{
if (Get-AudioDevice -RecordingMute) {return 1} else {return 0}
}
function Set-OutputIndex
{
[CmdletBinding()]param([Parameter(Mandatory)][int]$Offset)
if ($(Get-AudioDevice -Index $($($(Get-AudioDevice -Playback).Index) + $Offset)).Type -eq "Playback") {Set-AudioDevice -Index $($($(Get-AudioDevice -Playback).Index) + $Offset)}
}
function Set-InputIndex
{
[CmdletBinding()]param([Parameter(Mandatory)][int]$Offset)
if ($(Get-AudioDevice -Index $($($(Get-AudioDevice -Recording).Index) + $Offset)).Type -eq "Recording") {Set-AudioDevice -Index $($($(Get-AudioDevice -Recording).Index) + $Offset)}
}
function Set-OutputDevice
{
[CmdletBinding()]param([Parameter(Mandatory)][string]$Name)
Set-AudioDevice -ID $(Get-AudioDevice -List | where {$_.Type -eq "Playback" -and $_.Name -eq $Name}).ID
}
function Set-InputDevice
{
[CmdletBinding()]param([Parameter(Mandatory)][string]$Name)
Set-AudioDevice -ID $(Get-AudioDevice -List | where {$_.Type -eq "Recording" -and $_.Name -eq $Name}).ID
}
function Set-OutputVolume
{
[CmdletBinding()]param([Parameter(Mandatory)][float]$Volume)
Set-AudioDevice -PlaybackVolume $Volume
}
function Set-InputVolume
{
[CmdletBinding()]param([Parameter(Mandatory)][float]$Volume)
Set-AudioDevice -RecordingVolume $Volume
}
function Set-OutputMute
{
[CmdletBinding()]param([Parameter(Mandatory)][byte]$State)
switch($State)
{
0 {Set-AudioDevice -PlaybackMute $false}
1 {Set-AudioDevice -PlaybackMute $true}
}
}
function Set-InputMute
{
[CmdletBinding()]param([Parameter(Mandatory)][byte]$State)
switch($State)
{
0 {Set-AudioDevice -RecordingMute $false}
1 {Set-AudioDevice -RecordingMute $true}
}
}
Code: Select all
[Variables]
FastUpdate=25
SlowUpdate=2000
OutputVolume=0
InputVolume=0
OutputMute=0
InputMute=0
OutputStep=1
InputStep=1
InputDevice=0
Changed=0
[Rainmeter]
Update=25
DynamicWindowSize=1
AccurateText=1
[Metadata]
Name=AudioManager
Author=Yincognito & Other Credited Authors
; Credit for the AudioDeviceCmdlets .dll module to frgnca - https://github.com/frgnca/AudioDeviceCmdlets
; Credit for the initial Powershell code to death.crafter - https://forum.rainmeter.net/viewtopic.php?f=5&t=38135#p195694
; Credit for the supplemental Powershell code to jsmorley - https://forum.rainmeter.net/viewtopic.php?t=38135&start=30#p195744
; Other adjustments and improvements to keep the AudioDeviceCmdlets memory leak under control by Yincognito
---Measures---
[DeviceVolume]
Measure=Plugin
Plugin=PowershellRM
ScriptFile=#@#DeviceVolume.ps1
UpdateDivider=-1
[SetAudio]
Measure=String
String=#Changed#
RegExpSubstitute=1
Substitute="^0$":"","^1$":"Set-OutputVolume -Volume #OutputVolume#; Set-InputVolume -Volume #InputVolume#; Set-OutputMute -State #OutputMute#; Set-InputMute -State #InputMute#;"
UpdateDivider=(#SlowUpdate#/#FastUpdate#)
OnUpdateAction=[!SetVariable #CURRENTSECTION# [#CURRENTSECTION#]]
DynamicVariables=1
[GetAudio]
Measure=Plugin
Plugin=PowershellRM
Parent=DeviceVolume
Line=#SetAudio#$(Get-OutputVolume), $(Get-InputVolume), $(Get-OutputMute), $(Get-InputMute), "" -join "`n"
UpdateDivider=(#SlowUpdate#/#FastUpdate#)
DynamicVariables=1
[OutputVolume]
Measure=String
String=[GetAudio]
RegExpSubstitute=1
Substitute="(?siU)^.*(\N*\R)(\N*\R)(\N*\R)(\N*\R).*$":"\1","^\\\d+$":"","^(\d+).*$":"\1","^\\\d+$":""
UpdateDivider=(#SlowUpdate#/#FastUpdate#)
OnUpdateAction=[!SetVariable #CURRENTSECTION# [#CURRENTSECTION#]][!SetVariable Changed 0]
DynamicVariables=1
[InputVolume]
Measure=String
String=[GetAudio]
RegExpSubstitute=1
Substitute="(?siU)^.*(\N*\R)(\N*\R)(\N*\R)(\N*\R).*$":"\2","^\\\d+$":"","^(\d+).*$":"\1","^\\\d+$":""
UpdateDivider=(#SlowUpdate#/#FastUpdate#)
OnUpdateAction=[!SetVariable #CURRENTSECTION# [#CURRENTSECTION#]][!SetVariable Changed 0]
DynamicVariables=1
[OutputMute]
Measure=String
String=[GetAudio]
RegExpSubstitute=1
Substitute="(?siU)^.*(\N*\R)(\N*\R)(\N*\R)(\N*\R).*$":"\3","^\\\d+$":"","^(\d+).*$":"\1","^\\\d+$":""
UpdateDivider=(#SlowUpdate#/#FastUpdate#)
OnUpdateAction=[!SetVariable #CURRENTSECTION# [#CURRENTSECTION#]][!SetVariable Changed 0]
DynamicVariables=1
[InputMute]
Measure=String
String=[GetAudio]
RegExpSubstitute=1
Substitute="(?siU)^.*(\N*\R)(\N*\R)(\N*\R)(\N*\R).*$":"\4","^\\\d+$":"","^(\d+).*$":"\1","^\\\d+$":""
UpdateDivider=(#SlowUpdate#/#FastUpdate#)
OnUpdateAction=[!SetVariable #CURRENTSECTION# [#CURRENTSECTION#]][!SetVariable Changed 0]
DynamicVariables=1
---Neasures Devices---
[InputDevice]
Measure=Plugin
Plugin=PowershellRM
Parent=DeviceVolume
Line=Get-InputDevice
UpdateDivider=-1
RegExpSubstitute=1
Substitute="^0$":"None"
OnUpdateAction=[!SetVariable #CURRENTSECTION# [#CURRENTSECTION#]]
DynamicVariables=1
[PrevInputIndex]
Measure=Plugin
Plugin=PowershellRM
Parent=DeviceVolume
Line=Set-InputIndex -Offset -1
UpdateDivider=-1
;DynamicVariables=1
[NextInputIndex]
Measure=Plugin
Plugin=PowershellRM
Parent=DeviceVolume
Line=Set-InputIndex -Offset 1
UpdateDivider=-1
;DynamicVariables=1
---Meters---
[OutputVolumeText]
Meter=String
Y=5R
SolidColor=47,47,47,255
FontColor=255,255,255,255
FontFace=Consolas
FontSize=16
AntiAlias=1
Text=Output Volume: #OutputVolume#
MouseScrollUpAction=[!SetVariable OutputVolume (Clamp(#OutputVolume#+#OutputStep#,0,100))][!SetVariable Changed 1][!Update]
MouseScrollDownAction=[!SetVariable OutputVolume (Clamp(#OutputVolume#-#OutputStep#,0,100))][!SetVariable Changed 1][!Update]
DynamicVariables=1
[OutputMuteText]
Meter=String
Y=5R
SolidColor=47,47,47,255
FontColor=255,255,255,255
FontFace=Consolas
FontSize=16
AntiAlias=1
Text=Output Mute: #OutputMute#
LeftMouseUpAction=[!SetVariable OutputMute (1-#OutputMute#)][!SetVariable Changed 1][!Update]
DynamicVariables=1
[InputVolumeText]
Meter=String
Y=5R
SolidColor=47,47,47,255
FontColor=255,255,255,255
FontFace=Consolas
FontSize=16
AntiAlias=1
Text=Input Volume: #InputVolume#
MouseScrollUpAction=[!SetVariable InputVolume (Clamp(#InputVolume#+#InputStep#,0,100))][!SetVariable Changed 1][!Update]
MouseScrollDownAction=[!SetVariable InputVolume (Clamp(#InputVolume#-#InputStep#,0,100))][!SetVariable Changed 1][!Update]
DynamicVariables=1
[InputMuteText]
Meter=String
Y=5R
SolidColor=47,47,47,255
FontColor=255,255,255,255
FontFace=Consolas
FontSize=16
AntiAlias=1
Text=Input Mute: #InputMute#
LeftMouseUpAction=[!SetVariable InputMute (1-#InputMute#)][!SetVariable Changed 1][!Update]
DynamicVariables=1
[InputDeviceText]
Meter=String
Y=5R
SolidColor=47,47,47,255
FontColor=255,255,255,255
FontFace=Consolas
FontSize=16
AntiAlias=1
Text=Input Device: #InputDevice#
MouseScrollUpAction=[!UpdateMeasure PrevInputIndex][!UpdateMeasure InputDevice][!UpdateMeter #CURRENTSECTION#]
MouseScrollDownAction=[!UpdateMeasure NextInputIndex][!UpdateMeasure InputDevice][!UpdateMeter #CURRENTSECTION#]
LeftMouseUpAction=[!UpdateMeasure InputDevice][!UpdateMeter #CURRENTSECTION#]
DynamicVariables=1
Anyway, now you have getting and setting of both input and output devices, mute states and volumes - at least in the PS script - so the implementation is left to the skin designer in the INI code. Feel free to experiment with it.
