It is currently April 19th, 2024, 1:29 pm

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: August 13th, 2021, 8:37 pm Well while waiting, I tried to get death.crafter's code working in my skin. But simply adding 3 Sections and 2 Variables seems to be a problem as nothing is displayed?! :confused:
Did you copy the Addons and Scripts subfolders in your @Resources folder?
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 »

Yes, it's all set up and working as expected now, thank you :thumbup:

The only thing is the error dc already stated there's nothing can be done about.

One other minor issue is that when you click around the 1% and 3% mark (and maybe others?) you get this:
Image 002.png
Image 001.png
can this be fixed?

EDIT: Simple substitute worked here:

Code: Select all

[MicVolume]
Measure=Plugin
Plugin=PowershellRM
ScriptFile=#@#Scripts\MicVolume.ps1
Substitute="1.000001":"1","2.999999":"2","9.000001":"9"
You do not have the required permissions to view the files attached to this post.
- MuLab -
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Adjust Mic Volume Level?

Post by jsmorley »

Here we go.

PSVolume_5.0.rmskin

1.jpg


You can either drag the indicator or scrub with the mouse wheel to change the volume(s). The icons toggle mute. Right-click for a menu item to load Windows Sound Settings.

Mouse plugin credit to NighthawkSLO - https://github.com/NighthawkSLO/Mouse.dll
Credit for Powershell cmdlet .dll to frgnca - https://github.com/frgnca/AudioDeviceCmdlets
Credit for Powershell code to death.crafter - https://forum.rainmeter.net/viewtopic.php?f=5&t=38135#p195694

Skin:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
ContextTitle=Open Windows Sound Settings
ContextAction=["ms-settings:sound"]

[Metadata]
Name=PSVolume
Author=JSMorley
Information=Demonstrates using the Mouse plugin and Powershell to control output (speakers) and input (microphone) volume.||Credits in the skin .ini file.
License=Creative Commons Attribution-Non-Commercial-Share Alike 3.0
Version=Aug 13, 2021
; Mouse plugin credit to NighthawkSLO - https://github.com/NighthawkSLO/Mouse.dll
; Credit for Powershell cmdlet .dll to frgnca - https://github.com/frgnca/AudioDeviceCmdlets
; Credit for Powershell code to death.crafter - https://forum.rainmeter.net/viewtopic.php?f=5&t=38135#p195694

[Variables]
OutputVolume=0
InputVolume=0

[DeviceVolume]
Measure=Plugin
Plugin=PowershellRM
ScriptFile=#@#Scripts\DeviceVolume.ps1

[OutputVolume]
Measure=Plugin
Plugin=PowershellRM
Parent=DeviceVolume
Line=Get-Volume -Type Output
IfCondition=OutputVolume = -1
IfTrueAction=[!SetOption MeterOutputMuteIcon ImageName "volume_mute.png"][!SetOption MeterOutputPercent Text "Output: Muted"][!UpdateMeter *][!Redraw]
IfFalseAction=[!SetOption MeterOutputSlider X "(([OutputVolume:] * (200 - 20) / 100) + 20)"][!SetOption MeterOutputPercent Text "Output: [*MeasureOutputPercent:%,0*]%"][!UpdateMeter *][!Redraw]
IfCondition2=OutputVolume = 0
IfTrueAction2=[!SetOption MeterOutputMuteIcon ImageName "volume_0.png"]
IfCondition3=(OutputVolume > 0) && (OutputVolume <= 34)
IfTrueAction3=[!SetOption MeterOutputMuteIcon ImageName "volume_1.png"]
IfCondition4=(OutputVolume > 34) && (OutputVolume <= 67)
IfTrueAction4=[!SetOption MeterOutputMuteIcon ImageName "volume_2.png"]
IfCondition5=OutputVolume > 67
IfTrueAction5=[!SetOption MeterOutputMuteIcon ImageName "volume_3.png"]
IfConditionMode=1

[InputVolume]
Measure=Plugin
Plugin=PowershellRM
Parent=DeviceVolume
Line=Get-Volume -Type Input
IfCondition=InputVolume = -1
IfTrueAction=[!SetOption MeterInputMuteIcon ImageName "volume_mute.png"][!SetOption MeterInputPercent Text "Input: Muted"][!UpdateMeter *][!Redraw]
IfFalseAction=[!SetOption MeterInputSlider X "(([InputVolume:] * (200 - 20) / 100) + 20)"][!SetOption MeterInputPercent Text "Input: [*MeasureInputPercent:%,0*]%"][!UpdateMeter *][!Redraw]
IfCondition2=InputVolume = 0
IfTrueAction2=[!SetOption MeterInputMuteIcon ImageName "volume_0.png"]
IfCondition3=(InputVolume > 0) && (InputVolume <= 34)
IfTrueAction3=[!SetOption MeterInputMuteIcon ImageName "volume_1.png"]
IfCondition4=(InputVolume > 34) && (InputVolume <= 67)
IfTrueAction4=[!SetOption MeterInputMuteIcon ImageName "volume_2.png"]
IfCondition5=InputVolume > 67
IfTrueAction5=[!SetOption MeterInputMuteIcon ImageName "volume_3.png"]
IfConditionMode=1

[MeasureOutputMouse]
Measure=Plugin
Plugin=Mouse
LeftMouseDragAction=[!SetOption MeterOutputSlider X "(Clamp($MouseX$,20,200))"][!UpdateMeasure MeasureOutputPercent][!UpdateMeter *][!Redraw]
LeftMouseUpAction=[!CommandMeasure MeasureOutputMouse "Stop"][PLAY "#@#Windows Notify System Generic.wav"]
RelativeToSkin=1
RequireDragging=1
DynamicVariables=1

[MeasureInputMouse]
Measure=Plugin
Plugin=Mouse
LeftMouseDragAction=[!SetOption MeterInputSlider X "(Clamp($MouseX$,20,200))"][!UpdateMeasure MeasureInputPercent][!UpdateMeter *][!Redraw]
LeftMouseUpAction=[!CommandMeasure MeasureInputMouse "Stop"]
RelativeToSkin=1
RequireDragging=1
DynamicVariables=1

[MeasureOutputPercent]
Measure=Calc
Formula=[MeterOutputSlider:X]
MinValue=20
MaxValue=200
DynamicVariables=1
OnChangeAction=[!SetVariable OutputVolume "([MeasureOutputPercent:%,0])"][!CommandMeasure DeviceVolume "Set-OutputVolume"]

[MeasureInputPercent]
Measure=Calc
Formula=[MeterInputSlider:X]
MinValue=20
MaxValue=200
DynamicVariables=1
OnChangeAction=[!SetVariable InputVolume "([MeasureInputPercent:%,0])"][!CommandMeasure DeviceVolume "Set-InputVolume"]

[MeterSkinBack]
Meter=Shape
Shape=Rectangle 0.5,0.5,238,140,12 | Fill Color 0,0,0,255 | StrokeWidth 1.5 | Stroke Color 150,150,150,255
W=251
H=141
UpdateDivider=-1

[MeterOuputSlideBack]
Meter=Shape
X=20
Y=20
Shape=Rectangle 0,0,200,10,5 | Fill Color 150,150,150,255 | StrokeWidth 0
DynamicVariables=1
MouseActionCursor=0
MouseScrollUpAction=[!SetVariable OutputVolume "(Clamp(#OutputVolume#-1,0,100))"][!CommandMeasure DeviceVolume "Set-OutputVolume"][!Update]
MouseScrollDownAction=[!SetVariable OutputVolume "(Clamp(#OutputVolume#+1,0,100))"][!CommandMeasure DeviceVolume "Set-OutputVolume"][!Update]

[MeterOutputSlideBar]
Meter=Shape
X=20
Y=20
Shape=Rectangle 0,0,[MeterOutputSlider:X],10,5 | Fill Color 56,150,51,255 | StrokeWidth 0
DynamicVariables=1

[MeterOutputSlider]
Meter=Shape
Y=15
Shape=Ellipse 10,10,10,10 | Fill Color 106,222,100,255 | StrokeWidth 0
LeftMouseDownAction=[!CommandMeasure MeasureOutputMouse "Start"]

[MeterOutputPercent]
Meter=String
X=22
Y=45
FontSize=11
FontWeight=700
FontColor=255,255,255,255
Percentual=1
NumOfDecimals=0
AntiAlias=1
DynamicVariables=1

[MeterOutputMuteIcon]
Meter=Image
X=193
Y=41
W=20
PreserveAspectRatio=1
ImagePath=#@#
LeftMouseUpAction=[!CommandMeasure OutputVolume "OutputToggle-Mute"]

[MeterInputSlideBack]
Meter=Shape
X=20
Y=80
Shape=Rectangle 0,0,200,10,5 | Fill Color 150,150,150,255 | StrokeWidth 0
DynamicVariables=1
MouseActionCursor=0
MouseScrollUpAction=[!SetVariable InputVolume "(Clamp(#InputVolume#-1,0,100))"][!CommandMeasure DeviceVolume "Set-InputVolume"][!Update]
MouseScrollDownAction=[!SetVariable InputVolume "(Clamp(#InputVolume#+1,0,100))"][!CommandMeasure DeviceVolume "Set-InputVolume"][!Update]

[MeterInputSlideBar]
Meter=Shape
X=20
Y=80
Shape=Rectangle 0,0,[MeterInputSlider:X],10,5 | Fill Color 56,150,51,255 | StrokeWidth 0
DynamicVariables=1

[MeterInputSlider]
Meter=Shape
Y=75
Shape=Ellipse 10,10,10,10 | Fill Color 106,222,100,255 | StrokeWidth 0
LeftMouseDownAction=[!CommandMeasure MeasureInputMouse "Start"]

[MeterInputPercent]
Meter=String
X=22
Y=108
FontSize=11
FontWeight=700
FontColor=255,255,255,255
Percentual=1
NumOfDecimals=0
AntiAlias=1
DynamicVariables=1

[MeterInputMuteIcon]
Meter=Image
X=193
Y=104
W=20
PreserveAspectRatio=1
ImagePath=#@#
LeftMouseUpAction=[!CommandMeasure DeviceVolume "InputToggle-Mute"]
DeviceVolume.ps1:

Code: Select all

$env:PSModulePath+="$([System.IO.Path]::PathSeparator)$($RmAPI.VariableStr('@'))Addons"

Import-Module AudioDeviceCmdlets

function Get-Volume {
    param(
        [Parameter(Mandatory)]
        [string]
        $Type
    )
    switch($Type) {
        'Output' {
            if (Get-AudioDevice -PlaybackMute) {
                return -1
            } else {
                return $((Get-AudioDevice -PlaybackVolume) -replace '%', '')
            }
        }
        'Input' {
            if (Get-AudioDevice -RecordingMute) {
                return -1
            } else {
                return $((Get-AudioDevice -RecordingVolume) -replace '%', '')
            }
        }
    }
}

function Set-OutputVolume {
    Set-AudioDevice -PlaybackVolume $RmAPI.Variable('OutputVolume')
}

function OutputToggle-Mute {
	Set-AudioDevice -PlaybackMuteToggle
}	

function Set-InputVolume {
    Set-AudioDevice -RecordingVolume $RmAPI.Variable('InputVolume')
}

function InputToggle-Mute {
	Set-AudioDevice -RecordingMuteToggle
}
You do not have the required permissions to view the files attached to this post.
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 »

jsmorley wrote: August 13th, 2021, 10:01 pmHere we go. [...]
Hehe, nice trick to round the fractional values (screenshot 1) and avoid the "other" errors in death.crafter's version (screenshot 2), but you have to be careful how you use the measure's value(s):
Volumes.jpg
Volume.jpg
Excellent work though! :great:
EDIT: By the way, the fractional part can be eliminated by doing a:

Code: Select all

return $((Get-AudioDevice -RecordingVolume) -replace '([.,].*)?%', '')
or similar, but unfortunately on strings this is problematic. Not sure if it would work if converted / rounded to a number first, from PowerShell... :???:
You do not have the required permissions to view the files attached to this post.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Adjust Mic Volume Level?

Post by jsmorley »

I'm never getting a fractional number when I use it...

I am getting some errors in the log though, from PowerShellRM I suspect.

Code: Select all

System.Management.Automation.PSInvalidOperationException: The pipeline was not run because a pipeline is already running. Pipelines cannot be run concurrently.
   at System.Management.Automation.Runspaces.PipelineBase.DoConcurrentCheck(Boolean syncCall, Object syncObject, Boolean isInLock)
   at System.Management.Automation.Runspaces.RunspaceBase.DoConcurrentCheckAndAddToRunningPipelines(PipelineBase pipeline, Boolean syncCall)
   at System.Management.Automation.Runspaces.PipelineBase.CoreInvoke(IEnumer (PSVolume\PSVolume.ini - [InputVolume])
Might need to adjust this so there is only ever one PowerShellRM plugin measure active.
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: Adjust Mic Volume Level?

Post by death.crafter »

jsmorley wrote: August 13th, 2021, 10:01 pm
Since you don't need two power shell sessions, you might want to use child measure to get mute state.

Like

Code: Select all

[AudioParent]
Measure=Plugin
Plugin=PowershellRM
; All the code go here
ScriptFile=#@#Scripts\AudioDevices.ps1

[OutputVolume]
Measure=Plugin
Plugin=PowershellRM
Parent=AudioParent
Line=Get-Volume -Type Output

[InputVolume]
Measure=Plugin
Plugin=PowershellRM
Parent=AudioParent
Line=Get-Volume -Type Input

Code: Select all

function Get-Volume {
    param(
        [Parameter(Mandatory)]
        [string]
        $Type
    )
    switch($Type) {
        'Output' {
            if (Get-AudioDevice -PlaybackMute) {
                return -1
            } else {
                return $((Get-AudioDevice -PlaybackVolume) -replace '%', '')
            }
        }
        'Input' {
            if (Get-AudioDevice -RecordingMute) {
                return -1
            } else {
                return $((Get-AudioDevice -RecordingVolume) -replace '%', '')
            }
        }
    }
}
from the Realm of Death
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Adjust Mic Volume Level?

Post by jsmorley »

death.crafter wrote: August 13th, 2021, 10:54 pm Since you don't need two power shell sessions, you might want to use child measure to get mute state.
Yeah, that's the ticket... I'll make that adjustment and repost in a bit.
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 »

jsmorley wrote: August 13th, 2021, 10:47 pm I'm never getting a fractional number when I use it...

I am getting some errors in the log though, from PowerShellRM I suspect.

Code: Select all

System.Management.Automation.PSInvalidOperationException: The pipeline was not run because a pipeline is already running. Pipelines cannot be run concurrently.
   at System.Management.Automation.Runspaces.PipelineBase.DoConcurrentCheck(Boolean syncCall, Object syncObject, Boolean isInLock)
   at System.Management.Automation.Runspaces.RunspaceBase.DoConcurrentCheckAndAddToRunningPipelines(PipelineBase pipeline, Boolean syncCall)
   at System.Management.Automation.Runspaces.PipelineBase.CoreInvoke(IEnumer (PSVolume\PSVolume.ini - [InputVolume])
Yeah, I didn't mean those errors, since for that apparently there isn't a solution. I meant the [InputVolume]'s string value, when trying to set the mic volume to 1%. Of course, it's more obvious in death.crafter's version, as it's based on click and doesn't "refine" the return value through something like [*MeasureInputPercent:%,0*]. I was curious how you handled that, but it seems the refinement is done after the fractional value is received in the skin, as you can see from the log. I was trying to fix that from the PowerShell script itself (see my EDIT above).

Anyway, the fact that you don't get fractional values might have something to do with the pixels and how they divide to the total. For example, sl23 got that for both 1% and 3%, but I only get it for 1%... :???:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Adjust Mic Volume Level?

Post by jsmorley »

Yincognito wrote: August 13th, 2021, 11:01 pm Yeah, I didn't mean those errors, since for that apparently there isn't a solution. I meant the [InputVolume]'s string value, when trying to set the mic volume to 1%. Of course, it's more obvious in death.crafter's version, as it's based on click and doesn't "refine" the return value through something like [*MeasureInputPercent:%,0*]. I was curious how you handled that, but it seems the refinement is done after the fractional value is received in the skin, as you can see from the log. I was trying to fix that from the PowerShell script itself (see my EDIT above).

Anyway, the fact that you don't get fractional values might have something to do with the pixels and how they divide to the total. For example, sl23 got that for both 1% and 3%, but I only get it for 1%... :???:
Dunno. I just never get a fractional value as the volume, as that is not supported in Windows sound settings.
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: Adjust Mic Volume Level?

Post by death.crafter »

jsmorley wrote: August 13th, 2021, 11:04 pm Dunno. I just never get a fractional value as the volume, as that is not supported in Windows sound settings.
Same here. I use floor(), so even if you could, you can't possibly set a double value in the first place. I wonder why they end up getting fractional values.

About that error, PowershellRM gives that error sometimes. Every time I faced it, it got solved automatically. So I really don't know what causes it. It happens at random. Khan is busy with uni stuff so I don't think he can look into it anytime soon.
from the Realm of Death