It is currently April 19th, 2024, 3:49 am

Adjust Mic Volume Level?

Get help with creating, editing & fixing problems with skins
User avatar
Yincognito
Rainmeter Sage
Posts: 7125
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Adjust Mic Volume Level?

Post by Yincognito »

sl23 wrote: May 11th, 2022, 12:35 pmThat's not a request, but I wouldn't complain if you wanted that challenge. :Whistle
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}
  }
}
I added a minimal getting the current input device via clicking on the last line, and setting it via a Prev - Next system on mouse scroll:

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

It isn't better integrated (for example, inserted into [GetAudio] and ran every couple of seconds for an automated realtime feeling) because it's a CPU intensive task to run all those commands together, thus I added only as an "on demand" job via click or scroll. Like this wasn't enough, apparently PowershellRM has an issue with the combination between dynamic variables and a negative update rate, so I had to comment out the dynamic variables lines and split a nice dynamic measure into 2 parts, one for prev and one for next index. I let those commented lines so you can see what happens when you uncomment them: iteration through indexes goes wild, jumping multiple indexes at a time. This doesn't happen in a PS window, just like the memory leak doesn't either, so not only AudioDeviceCmdlets or AudioLevel are buggy, but PowerShellRM too (which is why I'm usually reluctant to use all kinds of plugins and addons in the first place).

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. ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Adjust Mic Volume Level?

Post by sl23 »

Wow! Thanks for writing that code, be content in the knowledge that it is humbly appreciated :bow: :thumbup:
I haven't the time to test it yet, hopefully over the weekend :D
- MuLab -
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Adjust Mic Volume Level?

Post by sl23 »

I've created a new folder especially to test this code as a new skin, works fine.
Volume up/down works on all in/out devices.
Mute works on all in/out devices.
Selects InputDevice and changes Mute/Volume states.

But.... I created this in an existing Suite folder, and it is affecting the controls of other skins, even those NOT in this Suite!
Basically, I cannot control anything to do with Output from any other skin except this one.

I have attempted to remove all reference to Output Devices, like you said to do before, but it has stopped functioning. I can select Input devices, but not control their Volumes or Mutes. Also, I still cannot control the Output Devices from other skins using the standard AudioLevel plugin Method. :???:

I want to stick with AudioLevel as it works without any issues or delays.

Powershell Edit:

Code: Select all

Import-Module -Name "$($RmAPI.VariableStr('@'))Volume\AudioDeviceCmdlets"

function Get-InputList
{
  return $($(Get-AudioDevice -List | where Type -eq "Recording" | sort Index).Name -join "`n") + "`n"
}

function Get-InputDevice
{
  return $(Get-AudioDevice -Recording).Name
}

function Get-InputVolume
{
  return Get-AudioDevice -RecordingVolume
}

function Get-InputMute
{
  if (Get-AudioDevice -RecordingMute) {return 1} else {return 0}
}

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-InputDevice
{
  [CmdletBinding()]param([Parameter(Mandatory)][string]$Name)
  Set-AudioDevice -ID $(Get-AudioDevice -List | where {$_.Type -eq "Recording" -and $_.Name -eq $Name}).ID
}

function Set-InputVolume
{
  [CmdletBinding()]param([Parameter(Mandatory)][float]$Volume)
  Set-AudioDevice -RecordingVolume $Volume
}

function Set-InputMute
{
  [CmdletBinding()]param([Parameter(Mandatory)][byte]$State)
  switch($State)
  {
    0 {Set-AudioDevice -RecordingMute $false}
    1 {Set-AudioDevice -RecordingMute $true}
  }
}
Skin INI Edit:

Code: Select all

[Variables]
FastUpdate=25
SlowUpdate=2000
InputVolume=0
InputMute=0
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-InputVolume -Volume #InputVolume#; Set-InputMute -State #InputMute#;"
UpdateDivider=(#SlowUpdate#/#FastUpdate#)
OnUpdateAction=[!SetVariable #CURRENTSECTION# [#CURRENTSECTION#]]
DynamicVariables=1

[GetAudio]
Measure=Plugin
Plugin=PowershellRM
Parent=DeviceVolume
Line=#SetAudio#$$(Get-InputVolume), $(Get-InputMute), "" -join "`n"
UpdateDivider=(#SlowUpdate#/#FastUpdate#)
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

[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---

[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

I guess I've missed something, but have no idea what is going on!

I've just Unloaded that skin, removed it from Rainmeter/Skins and then restarted Rainmeter, I have lost control of my Output device switching completely!!! :o :o :o
EDIT: After opening Windows Sound Settings, Output Device switching started working again! Very odd!!!
Reloaded the skin, which only has Input controls, however it doesn't work as stated above.
- MuLab -
User avatar
Yincognito
Rainmeter Sage
Posts: 7125
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Adjust Mic Volume Level?

Post by Yincognito »

sl23 wrote: May 14th, 2022, 10:09 amBut.... I created this in an existing Suite folder, and it is affecting the controls of other skins, even those NOT in this Suite!
Basically, I cannot control anything to do with Output from any other skin except this one.

I guess I've missed something, but have no idea what is going on!

I've just Unloaded that skin, removed it from Rainmeter/Skins and then restarted Rainmeter, I have lost control of my Output device switching completely!!! :o :o :o
EDIT: After opening Windows Sound Settings, Output Device switching started working again! Very odd!!!
Don't tell me you panicked... :rofl: Joking aside, relax, this is normal and expected to happen. Generally, when someone, anyone, posts some code or designs a skin, he is responsible only for that skin, and not for the interactions the skin might have with other skins (and how the other skins are organized) the users might load on their systems. Now, with that in mind, I advised you to have a basic understanding of what this skin (or earlier versions and approaches) does, before proceeding with general usage. I understand that real life and TLDR considerations makes it easier to just download or copy paste the code and expecting it to just work, but given the particularities of this approach, it can lead to having different expectations compared to what the skin actually does.

In short, what the skin does is not just GET, but also SET mute states and volumes of BOTH input and output default devices PERIODICALLY and on an AUTOMATED basis, or on certain CONDITIONS. It will not set the default devices themselves like that, since due to resource consumption I designed those to act only on demand. In the case of mute states and volumes though, doing so would have caused the desired near realtime control to freeze or crash Rainmeter, as we both noticed.

What this means in practice is that this skin will OVERRIDE mute states and volumes of the default devices IF the adjustment is done at the EXACT same time from other skins. Normally, this is a one in a million chance, because of the low frequency in the skin and the fact that SETTING the mute states or volumes is done ONLY IF there is a mouse action that should trigger a change (i.e. #Changed#=1) in the skin, which means that given different adjustment times here compared to other skins, the skin will adapt and accept settings from other skins or Windows controls (since #Changed#=0).

Basically, this skin should seamlessly integrate with other audio skins, like it does with mine as well (mine is at top left, displaying the audio in RMS, the audio out volume and audio in bands) - here, I set the audio output volume at 85% from my skin, and this "audio manager" skin happily accepted the setting without interfering in any way. Obviously, if I change the audio out or in DEVICE from the "audio manager" skin, the corresponding AudioLevel display from other skins will NOT match without refreshing those skins, but that's because of the AudioLevel bug we both mentioned earlier, not the code in this one:
Side By Side Audio Skins.jpg
sl23 wrote: May 14th, 2022, 10:09 amI have attempted to remove all reference to Output Devices, like you said to do before, but it has stopped functioning. I can select Input devices, but not control their Volumes or Mutes. Also, I still cannot control the Output Devices from other skins using the standard AudioLevel plugin Method. :???:

Reloaded the skin, which only has Input controls, however it doesn't work as stated above.
The output device adjustments in other skins are done using Win7Audio, not AudioLevel - in other words, Win7Audio is GET & SET for output, while AudioLevel is only GET for both. Everything works as stated, but maybe there is a misunderstanding, wrong code, or different expectations compared to what it happens. In this case, it's probably the 2nd of those (make sure the paths are correct in the 1st line of the .PS1 and in the ScriptFile option from the DeviceVolume measure in the .INI)...

Code: Select all

Import-Module -Name "$($RmAPI.VariableStr('@'))Volume\AudioDeviceCmdlets"

function Get-InputList
{
  return $($(Get-AudioDevice -List | where Type -eq "Recording" | sort Index).Name -join "`n") + "`n"
}

function Get-InputDevice
{
  return $(Get-AudioDevice -Recording).Name
}

function Get-InputVolume
{
  return Get-AudioDevice -RecordingVolume
}

function Get-InputMute
{
  if (Get-AudioDevice -RecordingMute) {return 1} else {return 0}
}

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-InputDevice
{
  [CmdletBinding()]param([Parameter(Mandatory)][string]$Name)
  Set-AudioDevice -ID $(Get-AudioDevice -List | where {$_.Type -eq "Recording" -and $_.Name -eq $Name}).ID
}

function Set-InputVolume
{
  [CmdletBinding()]param([Parameter(Mandatory)][float]$Volume)
  Set-AudioDevice -RecordingVolume $Volume
}

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
InputVolume=0
InputMute=0
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-InputVolume -Volume #InputVolume#; Set-InputMute -State #InputMute#;"
UpdateDivider=(#SlowUpdate#/#FastUpdate#)
OnUpdateAction=[!SetVariable #CURRENTSECTION# [#CURRENTSECTION#]]
DynamicVariables=1

[GetAudio]
Measure=Plugin
Plugin=PowershellRM
Parent=DeviceVolume
Line=#SetAudio#$(Get-InputVolume), $(Get-InputMute), "" -join "`n"
UpdateDivider=(#SlowUpdate#/#FastUpdate#)
DynamicVariables=1

[InputVolume]
Measure=String
String=[GetAudio]
RegExpSubstitute=1
Substitute="(?siU)^.*(\N*\R)(\N*\R).*$":"\1","^\\\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).*$":"\2","^\\\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---

[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
Seriously now, I can't be held responsible for you forgetting to delete a $ in GetAudio, or for - again - failing to adjust the Substitutes to only 2 output lines instead of the original 4. I already mentioned that earlier as a prerequisite to make things work, and it's not PS, not astronomy, just basic Rainmeter and logical thinking, really. :confused:
sl23 wrote: May 14th, 2022, 10:09 amI want to stick with AudioLevel as it works without any issues or delays.
Again, if it's about setting the output mute states or volume, it's Win7Audio that does that, not AudioLevel. If you're talking about detecting the mic status with AudioLevel, good luck with that, considering the bug of it not adjusting after the device is changed / unplugged / plugged in. Also, if you wanted to stick with the AudioLevel / Win7Audio combo for everything, you wouldn't have been able to achieve what the PS script skin did, because of the plugins' limitations. It's you who wanted full control over things and asked for help with the PS part and I imagine I responded pretty well on both, given the fact that using a memory leaking system is unfortunately one of only 2 solutions that allow full control over the audio part, and can simulate near realtime illusion on the user. :D
You do not have the required permissions to view the files attached to this post.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Adjust Mic Volume Level?

Post by sl23 »

Don't tell me you panicked... :rofl:
:phhht Might have! :rolmfao:
TLDR
??
Obviously, if I change the audio out or in DEVICE from the "audio manager" skin, the corresponding AudioLevel display from other skins will NOT match without refreshing those skins, but that's because of the AudioLevel bug we both mentioned earlier, not the code in this one:
Actually, I'm not seeing that! My Volume skin is updating, with your previous code mind, when I change the Input Device from this Audio Manager skin.
The output device adjustments in other skins are done using Win7Audio, not AudioLevel
Yes, sorry, That is what I have, but forgot it used that plugin.
make sure the paths are correct in the 1st line of the .PS1 and...
Yeah, I had trouble at first cos I forgot that I'd changed the paths to tidy everything up. As I'm still using the SoundVolumeView for Mic Boost adjustment. But now I have set the paths correctly, before posting about all the issues I'm having.
Seriously now, I can't be held responsible for you forgetting to delete a $ in GetAudio
Sorry for the typo, I have to admit, my eyes aren't as good as they used to be! :oops:
failing to adjust the Substitutes to only 2 output lines instead of the original 4. I already mentioned that earlier as a prerequisite to make things work
Again, sorry, but I really don't know what you are referring to. I remember you saying about the this before, but RegEx is beyond me. I can't tell what any of it is doing, I have looked up about RegEx before but only very simple things, even that wasn't easy to figure out.
Again, if it's about setting the output mute states or volume, it's Win7Audio that does that, not AudioLevel.
Yeah, just a mistake on my part!
I imagine I responded pretty well on both
Yes you did! Please don't think I'm being critical of anything you've done! Not at all! It's just that the Win7Audio works pretty well doing what I want. So I just needed the Input side to do the same, which you have done, and I really appreciate. I know the errors are mine, clearly, I just couldn't understand what's wrong with it. After all, as I said before, I have no idea what a $ is used for, or what brackets do, or anything else. Even Rainmeter code can be strange to understand when you have no idea about code. I imagine learning this stuff in school/college/university is far easier as it's taught to you WHY you need to use a symbol. What that symbols functions are, maybe even if that symbol is used in different circumstances.

Believe me, I have tried to learn HTML, XYplorer scripting, RegEx and even looked at Python. But the trouble is that without a teacher it is very difficult on your own, especially at 50!! lol
- MuLab -
User avatar
Yincognito
Rainmeter Sage
Posts: 7125
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Adjust Mic Volume Level?

Post by Yincognito »

sl23 wrote: May 14th, 2022, 4:01 pmAfter all, as I said before, I have no idea what a $ is used for, or what brackets do, or anything else. Even Rainmeter code can be strange to understand when you have no idea about code. I imagine learning this stuff in school/college/university is far easier as it's taught to you WHY you need to use a symbol. What that symbols functions are, maybe even if that symbol is used in different circumstances.

Believe me, I have tried to learn HTML, XYplorer scripting, RegEx and even looked at Python. But the trouble is that without a teacher it is very difficult on your own, especially at 50!! lol
Actually, in this case, you didn't even need to know what $ is used for in PS (for the record, $ is the "identifier" of a variable in PS and brackets "enclose" the function so it is treated like a variable, somewhat similar to how the # pairs work in Rainmeter) or what the regexes did (not that it was complicated, after all there were just 2 classes in \N and \R there, and I already explained what they meant), it was a logical decision to write a repeating pattern like $(SomePSFunction), or (\N*\R) the same way as the other similar ones and the number of times corresponding to the circumstances - hence my comments. :D

P.S. I learned most of what I know without a teacher as well, and I'm not that much younger compared to you. All things seem difficult in the beginning, it takes a bit of attention, persistence and desire to wrap your head around them. I guess my point was that while I fully understand if you stumble on more complex things where you need help, I'd imagine you're no longer a beginner when it comes to Rainmeter and how stuff works in the code, after almost a year of using it - not to mention that I explained most of the things you needed to know about the skin beforehand. ;-)

P.S.S. So, to make things clear, it does work as you expect it to do now, right? :???:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Adjust Mic Volume Level?

Post by sl23 »

All things seem difficult in the beginning...
Indeed. It's knowing where you need to start and the need to have a reason to keep at it. I only dabble with these things so get to a point like with this Suite, get totally stuck as things get too advanced too quickly, then grind to a halt! But I'll keep trying :D

Thanks so much for your help though. :thumbup: I never thought this was a possibility!

And as far as I can tell, yes, it works fine so far. Now to integrate it all... :welcome:
Last edited by sl23 on May 14th, 2022, 8:38 pm, edited 1 time in total.
- MuLab -
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Adjust Mic Volume Level?

Post by sl23 »

Assimilation complete! Everything works too! :o

Thank you again for making this happen :thumbup: :thumbup: :thumbup:

Now, onto that power issue...
- MuLab -
User avatar
Yincognito
Rainmeter Sage
Posts: 7125
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Adjust Mic Volume Level?

Post by Yincognito »

sl23 wrote: May 14th, 2022, 6:55 pm Indeed. It's knowing where you need to start and the need to have a reason to keep at it. I only dabble with these things so get to a point like with this Suite, get totally stuck as things get too advanced too quickly, then grind to a halt! But I'll keep trying :D

Thanks so much for your help though. :thumbup: I never thought this was a possibility!

And as far as I can tell, yes, it works fine so far. Now to integrate it all... :welcome:
sl23 wrote: May 14th, 2022, 8:27 pm Assimilation complete! Everything works too! :o

Thank you again for making this happen :thumbup: :thumbup: :thumbup:

Now, onto that power issue...
Nice! :great: It's always a possibility if you have the tools for it and the will to make it work - the knowledge is not a problem, as this generally evolves in time and it's not limited to a single individual. But yeah, small and sure steps are indeed recommended against large and shaky ones, from things like this here all the way to the moon landing, LOL.

Just keep in mind that due to the unfortunate memory leak issue that is only alleviated as much as possible in this approach, the skin, while perfectly distributable, should contain a heads up about the problem and why the solution was implemented anyway, so the user knows what to expect (and possibly how to workaround, adjust or reset it). ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Adjust Mic Volume Level?

Post by sl23 »

Too true.

I'll leave a note on the download page regarding the issues and why it's been done this way. :thumbup:
- MuLab -