It is currently June 30th, 2024, 7:24 am

[!Refreshapp] when skin loaded?

Get help with creating, editing & fixing problems with skins
User avatar
sl23
Posts: 1233
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

[!Refreshapp] when skin loaded?

Post by sl23 »

Hi again :)
I need a little help! :oops: :Whistle
So, I finally got myself a microphone and now will be using the Mic skin I made a few years ago. :jawdrop

Trouble is, I have two skins:
A Volume/VUmetre skin
The Mic skin.

I've got it working, though probably not the best way, where when you plug in the mic, it's a USB lead, the Volume skin detects the Mic Volume and loads the Mic config. Unplug, and the config is deactivated. So far so good. Is there a better way to detect the mic is connected/disconnected?

However, The Volume skin needs updating as it doesn't react to the volume input of the mic until that skin is refreshed.

So I set up this code in the volume app to load and unload, but refreshing the app causes a 'Refresh' loop:

Code: Select all

[DeviceVolume]
Measure=Plugin
Plugin=PowershellRM
ScriptFile=DeviceVolume.ps1

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

IfCondition=InputVolume = 100
IfTrueAction=[!ActivateConfig "RM\Mic" "Mic.ini"][!RefreshApp]
IfFalseAction=[!DeactivateConfig "RM\Mic" "Mic.ini"]
So I then checked the manual to see if there was an option to do something similar to OnRefreshAction=[RefreshApp] in the Mic skin. Obviously using that would create another loop. So I wondered if there's a way to have something like OnStart=[RefreshApp] or OnLoad=[RefreshApp].

Any ideas? Thanks. :thumbup:
- MuLab -
User avatar
Yincognito
Rainmeter Sage
Posts: 7576
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [!Refreshapp] when skin loaded?

Post by Yincognito »

Why would you even try to refresh the Mic skin if you're already activating it in the first place (which, assuming it was previously deactivated, does more or less the same thing)? Also, why would you even try to refresh the app (aka the whole Rainmeter and all active skins, plus rescanning the skins folder) if you only need the Mic skin to be "refreshed"?

Lastly, if I recall correctly, I suppose the skin made for the Mic is one of the many variants in this thread?
https://forum.rainmeter.net/viewtopic.php?t=38135
Now, it's been a long time since then and I probably forgot most of the things there, but it would have helped if you indicated which variant it is, or if you remade it yourself in a different way. As far as I remember, the PS variants didn't need refreshing, only AudioLevel ones, even though the PS ones had other drawbacks.

P.S. The subject has been investigated thoroughly (by you as well) in that thread, so I won't touch again whether detecting if the Mic is connected in your code above is the best way, but if all you need is a refresh and there's a way to stop whatever that skin is doing when the Mic is disconnected (for performance reasons or similar), you could simply hide and show that skin instead of deactivating and activating it, and refresh it from the main skin when needed. That would avoid a refresh loop entirely since the Mic skin would, in theory, always be active (or, at least, once the main skin is loaded, if you add the corresponding bang in the OnRefreshAction of the main skin, and add the opposite in its OnCloseAction).
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
sl23
Posts: 1233
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: [!Refreshapp] when skin loaded?

Post by sl23 »

Sorry, I was tired and explained poorly.
Essentially it's one skin that needs refreshing, the Volume skin. Because the Volume skin doesn't know that the Mic has been connected. Until it is refreshed. So the Mic skin doesn't need refreshing on load, just the Volume skin. After I posted last night, I turned off my PC and then realised that loading and refreshing would likely create another loop!

Correct, it is one from that thread, though, to be honest I don't remember which one! :oops:
Probably the latest, but not certain. I did think about that thread when I posted, but had forgotten I had asked about how to detect when Mic is connected. Sorry about that. I have been looking through it again, only got page 4, but will look through the whole thread again to see what can be done.

As the ps1 version I'm using is a massive memory hog over time, I would prefer the skin to be loaded only when needed. But thinking about that thread, I may have already exhausted that possibility. I'll check it out, but if you have no idea how to achieve it then I have very little chance! Though, I'm wondering about using the volume as some way, perhaps set to 100 on load skin, as the mic isn't loud enough at lower volumes anyway. Then set to 0 on unload. sort of work some way like that? if not, I'll set up a button to control, just trying to integrate it into my taskbar set of skins so would prefer not to.

Thanks for the reply, and again sorry for being forgetful! :lol: I blame insomnia! O.O
- MuLab -
User avatar
Yincognito
Rainmeter Sage
Posts: 7576
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [!Refreshapp] when skin loaded?

Post by Yincognito »

sl23 wrote: June 13th, 2024, 3:31 pmEssentially it's one skin that needs refreshing, the Volume skin. Because the Volume skin doesn't know that the Mic has been connected. Until it is refreshed. [...] As the ps1 version I'm using is a massive memory hog over time, I would prefer the skin to be loaded only when needed. But thinking about that thread, I may have already exhausted that possibility. I'll check it out, but if you have no idea how to achieve it then I have very little chance!
I never said that I have no idea how to achieve something, I only said that I won't bother with the things in that thread anymore, especially the volume part - since, like you said, I also exhausted those possibilities back then, not to mention the drawbacks of the said PS solution which I can't do anything about, given that the .DLL is at fault for it as far as I recall.

That being said, if it's only about reacting to when the mic has been connected (whether it's about refreshing or activating some other skin, based on your needs), this might be possible via a single Registry measure (the path of which I deducted after exporting the entire registry with my headset connected and unconnected, and then using my Total Commander to automatically compare the exported files by content):

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

---Measures---

[MMDevicesAudioCaptureList]
Measure=Registry
RegHKey=HKEY_LOCAL_MACHINE
RegKey=Software\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture
RegValue=
OutputType=SubKeyList

[MMDevicesAudioCaptureName]
Measure=Registry
RegHKey=HKEY_LOCAL_MACHINE
RegKey=Software\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture\{1ef40053-eec3-46f1-9bfe-7e1f209407af}\Properties
RegValue={a45c254e-df1c-4efd-8020-67d146a850e0},2
OutputType=Value

[MMDevicesAudioCaptureState]
Measure=Registry
RegHKey=HKEY_LOCAL_MACHINE
RegKey=Software\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture\{1ef40053-eec3-46f1-9bfe-7e1f209407af}
RegValue=DeviceState
OutputType=Value
OnChangeAction=[!Refresh]

[AudioLevelInput]
Measure=Plugin
Plugin=AudioLevel
Port=Input

[AudioLevelInputDeviceList]
Measure=Plugin
Plugin=AudioLevel
Parent=AudioLevelInput
Type=DeviceList

[AudioLevelInputDeviceName]
Measure=Plugin
Plugin=AudioLevel
Parent=AudioLevelInput
Type=DeviceName

[AudioLevelOutput]
Measure=Plugin
Plugin=AudioLevel
Port=Output

[AudioLevelOutputDeviceList]
Measure=Plugin
Plugin=AudioLevel
Parent=AudioLevelOutput
Type=DeviceList

[AudioLevelOutputDeviceName]
Measure=Plugin
Plugin=AudioLevel
Parent=AudioLevelOutput
Type=DeviceName

---Meters---

[Devices]
Meter=String
FontFace=Consolas
FontSize=12
FontColor=160,160,160,255
SolidColor=0,0,0,128
AntiAlias=1
InlineSetting=Color | 255,255,255,255
InlinePattern=(.* = )
MeasureName =AudioLevelInputDeviceName
MeasureName2=AudioLevelOutputDeviceName
MeasureName3=AudioLevelInputDeviceList
MeasureName4=AudioLevelOutputDeviceList
MeasureName5=MMDevicesAudioCaptureName
MeasureName6=MMDevicesAudioCaptureState
MeasureName7=MMDevicesAudioCaptureList
Text=Audio  Input Name = %1#CRLF#Audio Output Name = %2#CRLF##CRLF#Audio  Input List = #CRLF#%3#CRLF#Audio Output List = #CRLF#%4#CRLF##CRLF#Registry Name  = %5#CRLF#Registry State = %6#CRLF##CRLF#Registry List  = #CRLF#%7
DynamicVariables=1
Mic Detection.jpg
The only truly required measure above is MMDevicesAudioCaptureState, the others being included mainly for reference. Note that the {...-...-...-...-...} parts can be different from computer to computer and even Windows installation to Windows installation on the same computer, so you'll have to run regedit.exe and look for the corresponding parts in your registry, or use CTRL+F to search for stuff there. The other option was to put together some .lua or .ps1 script to iterate through the MMDevicesAudioCaptureList items via a FOR loop (or even use a self updating measure in plain Rainmeter) in order to make the whole thing more compatible with various devices, but was too lazy for that this time. I don't know if the above will suit your USB mic, but it works for my audio jack headphones, where the Registry State displays 1 if connected and 8 if not.
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: 1233
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: [!Refreshapp] when skin loaded?

Post by sl23 »

Thanks for the help :)

I'll check that out tomorrow, as off to catch some z's now! :yawn:

I did find a way to check when I looked at my first RoundVolume skin. I messed about with that and came up with this:

Code: Select all

[Rainmeter]
Update=50
AccurateText=1
DynamicWindowSize=1

[Metadata]
Name=RoundVolume
Author=sl23
Information=Adjust Mic volume.||Credits:||Adapted from "SimplyRound" Suite by Krzysztof "gronostaj" Smialek||Mouse plugin by NighthawkSLO.||Powershell cmdlet .dll by frgnca.||Powershell code by death.crafter.||Help via forum: JSMorley, death.crafter, Yincognito.||Thanks to JSMorley for the AudioDeviceList skin.
; 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
Version=2022.5.7
License=CC BY 3.0

[Variables]
Aqua=0,255,255
AquaDark=64,191,167,200
AquaDark2=0,255,255,150
Green=128,255,0,220
Red=255,100,100
Trans=0,0,0,1
White=255,255,255,200
White20=255,255,255,20
White60=255,255,255,60
Yellow=255,255,0,150

BgFill=0,0,0,150
VolBar=64,191,167,200

VolLow=25
VolMax=80

NAME1=Low
NAME2=Mute
NAME3=Hi

; CmdFriendlyID=Realtek(R) Audio\Subunit\Microphone Boost
Timeout=300
RunEach=10

; For Mic Volume Control:
FastUpdate=25
SlowUpdate=1000
InputVolume=0
InputMute=0
InputStep=5
InputDevice=Mic
Changed=0

========================================
; Background
========================================
[Bg]
Meter=Shape
Shape=Rectangle 0,0,130,70,35 | Fill Color #BgFill# | StrokeWidth 2 | Extend StrokeAlpha
StrokeAlpha=Stroke Color #White60#
DynamicVariables=1
X=2
Y=2

[Bg1]
Meter=Shape
Shape=Ellipse 0,0,30,30 | Fill Color 0,0,0,50 | StrokeWidth 2 | Extend StrokeAlpha
Shape2=Ellipse 0,0,21,21 | Fill Color #Trans# | StrokeWidth 2 | Extend StrokeAlpha2
Shape3=Ellipse 0,0,25,25 | Fill Color #Trans# | StrokeWidth 10 | Stroke Color #White20#
StrokeAlpha=Stroke Color #White60#
StrokeAlpha2=Stroke Color #White60#

LeftMouseUpAction=[!SetVariable InputVolume 25][!SetVariable Changed 1][!Update]
MiddleMouseUpAction=[!SetVariable InputMute (1-#InputMute#)][!SetVariable Changed 1][!Update]
RightMouseUpAction=[!SetVariable InputVolume 80][!SetVariable Changed 1][!Update]

TooltipIcon=Info
ToolTipTitle=[InputDevice]
ToolTipText=L - #NAME1##CRLF#M - #NAME2##CRLF#R - #NAME3#

MouseOverAction=[!SetOption #CURRENTSECTION# StrokeAlpha "Stroke Color #AquaDark2#"][!SetOption MicdbLevel FontColor "#Green#"][!HideMeter MicIcon][!ShowMeterGroup Input] [!UpdateMeter *][!Redraw]
MouseLeaveAction=[!SetOption #CURRENTSECTION# StrokeAlpha "Stroke Color #White60#"][!SetOption MicdbLevel FontColor "#White#"][!ShowMeter MicIcon][!HideMeterGroup Input] [!UpdateMeter *][!Redraw]

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
X=37
Y=37

========================================
; STYLES
========================================
[sAllText]
FontFace=Trebuchet MS
StringStyle=Bold
StringAlign=CenterCenter
FontSize=12
FontColor=#White#
AntiAlias=1
DynamicVariables=1

[sHighlight]
MouseOverAction=[!SetOption #CURRENTSECTION# FontColor "#Green#"] [!UpdateMeter #CURRENTSECTION#] [!Redraw]
MouseLeaveAction=[!SetOption #CURRENTSECTION# FontColor ""] [!UpdateMeter #CURRENTSECTION#] [!Redraw]

[sRoundBar]
LineStart=22
LineLength=28
LineWidth=4
StartAngle=(Rad(270))
Antialias=1
Solid=1

[MicTitle]
Meter=String
MeterStyle=sAllText | sHighlight
FontSize=8
Text=INPUT

LeftMouseUpAction=[Play "#@#Volume\Copy.wav"][!SetClip "; Windows Default Input Device:#CRLF##CRLF#; Device Name:	[mDeviceName]#CRLF#; Device ID:		[mDeviceID]#CRLF#; Device Format:	[mDeviceFormat]#CRLF#; Device Status:	[mDeviceStatus]#CRLF##CRLF#; Device List:#CRLF##CRLF#[mDeviceList]"]
MiddleMouseUpAction=[!Refresh]
RightMouseUpAction=

X1MouseUpAction=ms-settings:sound
X2MouseUpAction=[control mmsys.cpl]

MouseScrollUpAction=[!UpdateMeasure PrevInputIndex][!UpdateMeasure InputDevice][!UpdateMeter #CURRENTSECTION#]
MouseScrollDownAction=[!UpdateMeasure NextInputIndex][!UpdateMeasure InputDevice][!UpdateMeter #CURRENTSECTION#]

ToolTipIcon=Info
ToolTipTitle=[mDeviceName] - [mDeviceStatus]
ToolTipText=L - Copy Device List#CRLF#M - Refresh#CRLF#R - #CRLF#X1 - CP Sound Settings#CRLF#X2 - Main Sound Settings
X=95
Y=25

; Windows Default Input Device:

; Device Name:	Microphone (USB Audio)
; Device ID:		{7fb35683-1fea-4fa1-be4a-a3e49b15aeeb}
; Device Format:	48000Hz PCM 32b 1ch
; Device Status:	On

; Device List:

; {0.0.1.00000000}.{0633eb3a-04b7-4232-bc8f-5a95f6d9a8f5}		Line In (Realtek(R) Audio)
; {0.0.1.00000000}.{6dafb858-c2ee-4689-b842-0e6976194cdc}		Microphone (Realtek(R) Audio)
; {0.0.1.00000000}.{7fb35683-1fea-4fa1-be4a-a3e49b15aeeb}		Microphone (USB Audio)

========================================
; Microphone Response
========================================
[mMicdbLevel]
Measure=Plugin
Plugin=AudioLevel
Port=Input
RMSAttack=50
RMSDecay=300
;Set your desired Mic-response here--------------------
RMSGain=10

[mDeviceStatus]
Measure=Plugin
Plugin=AudioLevel
Parent=mMicdbLevel
Type=DeviceStatus
Substitute="0":"Off","1":"On"
IfCondition=mDeviceStatus = 0
IfTrueAction=[!SetOption MicTitle ToolTipTitle "[mDeviceName] - [mDeviceStatus]"]
IfFalseAction=[!SetOption MicTitle ToolTipTitle "[mDeviceName] - [mDeviceStatus]"]

[mDeviceList]
Measure=Plugin
Plugin=AudioLevel
Parent=mMicdbLevel
Type=DeviceList
Substitute="}: ":"}		"
OnChangeAction=[!Refresh]

[mDeviceName]
Measure=Plugin
Plugin=AudioLevel
Parent=mMicdbLevel
Type=DeviceName

[mDeviceID]
Measure=Plugin
Plugin=AudioLevel
Parent=mMicdbLevel
Type=DeviceID
RegExpSubstitute=1
Substitute="{.*}\.":""

[mDeviceFormat]
Measure=Plugin
Plugin=AudioLevel
Parent=mMicdbLevel
Type=Format

[MicdbLevel]
Meter=String
MeterStyle=sAllText
MeasureName=mMicdbLevel
NumOfDecimals=2
Percentual=1
Text=%1
X=95
Y=50

[MicRoundBar]
Meter=Roundline
MeasureName=mMicdbLevel
MeterStyle=sRoundBar
LineColor=#Yellow#
X=37
Y=37

[MicIcon]
Meter=String
MeterStyle=sAllText
FontFace=Segoe Fluent Icons
FontSize=16
Text=[\xE720]
X=38
Y=38

========================================
; Mic Volume Control
========================================
[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
MinValue=0
MaxValue=100

[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

IfCondition=#InputMute# = 1
IfTrueAction=[!SetOption MicIcon Text "[\xEC54]"][!SetOption MicIcon FontColor "#Red#"][!UpdateMeter *][!Redraw]
IfFalseAction=[!SetOption MicIcon Text "[\xE720]"][!SetOption MicIcon FontColor "#White#"][!UpdateMeter *][!Redraw]
IfConditionMode=1

;---Neasures Devices---

[InputDevice]
Measure=Plugin
Plugin=PowershellRM
Parent=DeviceVolume
Line=Get-InputDevice
UpdateDivider=-1
;RegExpSubstitute=1
;Substitute="^0$":"None"
;Substitute="0":"","(Realtek(R) Audio)":"(R)"
;OnUpdateAction=[!SetVariable #CURRENTSECTION# [#CURRENTSECTION#]]
DynamicVariables=1

[PrevInputIndex]
Measure=Plugin
Plugin=PowershellRM
Parent=DeviceVolume
Line=Set-InputIndex -Offset -1
UpdateDivider=-1

[NextInputIndex]
Measure=Plugin
Plugin=PowershellRM
Parent=DeviceVolume
Line=Set-InputIndex -Offset 1
UpdateDivider=-1

=== Meters

[SetInputVolumeText]
Meter=String
MeterStyle=sAllText
FontColor=#Green#
Text=#InputVolume#
Hidden=1
Group=Input
DynamicVariables=1
X=37
Y=37

[SetInputVolRoundBar]
Meter=Roundline
MeasureName=InputVolume
MeterStyle=sRoundBar
LineColor=#Green#
Solid=0
X=37
Y=37
This part was where I was working towards, but I think yours may be better?

Code: Select all

[mDeviceList]
Measure=Plugin
Plugin=AudioLevel
Parent=mMicdbLevel
Type=DeviceList
Substitute="}: ":"}		"
OnChangeAction=[!Refresh]
I had an issue with it detecting removal of the Mic but not connection. So used the OnChangeAction, which will Refresh the Volume skin I need refreshing too! Now it's just a matter of disabling that dll for reducing that memory leak, though in this version of the skin, it isn't too bad.

There is a minor issue with this skin though. The percentage text keeps moving. I'll explain tomorrow.
:thumbup:
- MuLab -
User avatar
Yincognito
Rainmeter Sage
Posts: 7576
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [!Refreshapp] when skin loaded?

Post by Yincognito »

sl23 wrote: June 13th, 2024, 9:20 pmI did find a way to check when I looked at my first RoundVolume skin. I messed about with that and came up with this
Well, if the list changes when connecting or disconnecting the mic, then it should work indeed. For me, only the active device changes, but I guess that's different with a separate USB mic. :thumbup:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
sl23
Posts: 1233
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: [!Refreshapp] when skin loaded?

Post by sl23 »

So I have the Mic skin ToolTip working correctly and when the Mic is connected/disconnected, the ToolTip now works perfectly. Adjusting it's name to match the Mic or Line In. Trouble is, no matter what I do, I can't get my other skin, Volume skin, to activate/deactivate the Mic skin when the name changes.

As a test, I made a temporary button on the Mic skin to change colour when the name changes. So if "Microphone" is in the name, it lights green, and red for not connected. But it just stays red! In the About window, the Mic skin shows [mDeviceName] and [mDeviceID] change with each connect/disconnect. But the [mDeviceList] always shows Line In Name and ID. How do I get that to change? But when I monitor the [mDeviceName] to change the colour of [TempButton] it doesn't work. Even though the ToolTip changes.

EDIT: After reading 10 pages of the original thread, I found out about the RegEx:
  • @Yincognito: The * are just wildcards, so *Microphone* can mean SomePrefixHere Microphone or Microphone SomeSuffixHere, or just plain Microphone without any pre- or post- additional characters. It's the simpler equivalent of .* from regex, basically.
But no matter what I tried, just the * alone never worked, until I used .* and RegExpSubstitute=1. Now the Button changes colour and the ToolTip works perfectly using:

Code: Select all

Substitute="(Realtek(R) Audio)":"(R)","(USB Audio)":"USB",".*Microphone":"Mic"
IfMatch="Mic"
IfMatchAction=[!SetOption TempButton FillAlpha "FillColor #Green#"][!UpdateMeter *] [!Redraw]
IfNotMatchAction=[!SetOption TempButton FillAlpha "FillColor #Red#"][!UpdateMeter *] [!Redraw]
This part of the problem finally solved!!! :D :D :D :great:
I'm also getting a problem now with the Mic volume percentage. It always shows zero. If you scroll to increase, it constantly resets to zero. It was working perfect until recent, I have no idea what's going on with it.
EDIT: I realised that the Mic skin I was working on was the old RoundVolume one which had both Input and Output combined into one skin and also the Powershell script. But now I've removed the Output code from the skin and script, all good with this! :D
In JSMorley's Input/Output skin, I am getting an output device shown as Speakers (USB Audio) when connecting Mic, why is this?

Thanks for your help. :thumbup:
Full Code
EDIT: Latest code after finding RegEx

Code: Select all

[Rainmeter]
Update=50
AccurateText=1
DynamicWindowSize=1

[Metadata]
Name=RoundVolume
Author=sl23
Information=Adjust Mic volume.||Credits:||Adapted from "SimplyRound" Suite by Krzysztof "gronostaj" Smialek||Mouse plugin by NighthawkSLO.||Powershell cmdlet .dll by frgnca.||Powershell code by death.crafter.||Help via forum: JSMorley, death.crafter, Yincognito.||Thanks to JSMorley for the AudioDeviceList skin.
; 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
Version=2024.06.15
License=CC BY 3.0

[Variables]
Aqua=0,255,255
AquaDark=64,191,167,200
AquaDark2=0,255,255,150
Green=128,255,0,220
Red=255,100,100
Trans=0,0,0,1
White=255,255,255,200
White20=255,255,255,20
White60=255,255,255,60
Yellow=255,255,0,150

BgFill=0,0,0,150
VolBar=64,191,167,200

VolLow=25
VolMax=80

NAME1=Low
NAME2=Mute
NAME3=Hi

; CmdFriendlyID=Realtek(R) Audio\Subunit\Microphone Boost
Timeout=300
RunEach=10

; For Mic Volume Control:
FastUpdate=25
SlowUpdate=1000
InputVolume=0
InputMute=0
InputStep=5
InputDevice=Mic
Changed=0

========================================
; Background
========================================
[Bg]
Meter=Shape
Shape=Rectangle 0,0,130,70,35 | FillColor #BgFill# | StrokeWidth 2 | Extend StrokeAlpha
StrokeAlpha=Stroke Color #White60#
DynamicVariables=1
X=2
Y=2

[Bg1]
Meter=Shape
Shape=Ellipse 0,0,30,30 | FillColor 0,0,0,50 | StrokeWidth 2 | Extend StrokeAlpha
Shape2=Ellipse 0,0,21,21 | FillColor #Trans# | StrokeWidth 2 | Extend StrokeAlpha2
Shape3=Ellipse 0,0,25,25 | FillColor #Trans# | StrokeWidth 10 | StrokeColor #White20#
StrokeAlpha=StrokeColor #White60#
StrokeAlpha2=StrokeColor #White60#

LeftMouseUpAction=[!SetVariable InputVolume 25][!SetVariable Changed 1][!Update]
MiddleMouseUpAction=[!SetVariable InputMute (1-#InputMute#)][!SetVariable Changed 1][!Update]
RightMouseUpAction=[!SetVariable InputVolume 80][!SetVariable Changed 1][!Update]

TooltipIcon=Info
ToolTipTitle=[mDeviceName]
ToolTipText=L - #NAME1##CRLF#M - #NAME2##CRLF#R - #NAME3#

MouseOverAction=[!SetOption #CURRENTSECTION# StrokeAlpha "StrokeColor #AquaDark2#"][!SetOption MicdbLevel FontColor "#Green#"][!HideMeter MicIcon][!ShowMeterGroup Input] [!UpdateMeter *][!Redraw]
MouseLeaveAction=[!SetOption #CURRENTSECTION# StrokeAlpha "StrokeColor #White60#"][!SetOption MicdbLevel FontColor "#White#"][!ShowMeter MicIcon][!HideMeterGroup Input] [!UpdateMeter *][!Redraw]

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
X=37
Y=37

========================================
; STYLES
========================================
[sAllText]
FontFace=Trebuchet MS
StringStyle=Bold
StringAlign=CenterCenter
FontSize=12
FontColor=#White#
AntiAlias=1
DynamicVariables=1

[sHighlight]
MouseOverAction=[!SetOption #CURRENTSECTION# FontColor "#Green#"] [!UpdateMeter #CURRENTSECTION#] [!Redraw]
MouseLeaveAction=[!SetOption #CURRENTSECTION# FontColor ""] [!UpdateMeter #CURRENTSECTION#] [!Redraw]

[sRoundBar]
LineStart=22
LineLength=28
LineWidth=4
StartAngle=(Rad(270))
Antialias=1
Solid=1

========================================
; Microphone Response
========================================
[mMicdbLevel]
Measure=Plugin
Plugin=AudioLevel
Port=Input
RMSAttack=50
RMSDecay=300
;Set your desired Mic-response here--------------------
RMSGain=10

[mDeviceStatus]
Measure=Plugin
Plugin=AudioLevel
Parent=mMicdbLevel
Type=DeviceStatus
Substitute="0":"Off","1":"On"

[mDeviceList]
Measure=Plugin
Plugin=AudioLevel
Parent=mMicdbLevel
Type=DeviceList
Substitute="}: ":"}		"
OnChangeAction=[!Refresh]

[mDeviceName]
Measure=Plugin
Plugin=AudioLevel
Parent=mMicdbLevel
Type=DeviceName
RegExpSubstitute=1
Substitute="(Realtek(R) Audio)":"(R)","(USB Audio)":"USB",".*Microphone":"Mic"

IfMatch="Mic"
IfMatchAction=[!SetOption Button StrokeAlpha "StrokeColor #Green#"][!UpdateMeter *] [!Redraw]
IfNotMatchAction=[!SetOption Button StrokeAlpha "StrokeColor #Red#"][!UpdateMeter *] [!Redraw]

[Button]
Meter=Shape
Shape=Rectangle 0,0,10,10,5 | FillColor #Trans# | StrokeWidth 2 | Extend StrokeAlpha
StrokeAlpha=StrokeColor #White60#

LeftMouseUpAction=[Play "#@#Volume\Copy.wav"][!SetClip "; Windows Default Input Device:#CRLF##CRLF#; Device Name:      [mDeviceName]#CRLF#; Device ID:        [mDeviceID]#CRLF#; Device Format:    [mDeviceFormat]#CRLF#; Device Status:    [mDeviceStatus]#CRLF##CRLF#; Device List:#CRLF##CRLF#[mDeviceList]"]
MiddleMouseUpAction=[!Refresh]
RightMouseUpAction=

X1MouseUpAction=ms-settings:sound
X2MouseUpAction=[control mmsys.cpl]

ToolTipIcon=Info
ToolTipTitle=[mDeviceName] - [mDeviceStatus]
ToolTipText=L - Copy Device List#CRLF#M - Refresh#CRLF#R - #CRLF#X1 - CP Sound Settings#CRLF#X2 - Main Sound Settings

DynamicVariables=1
X=75
Y=5

[mDeviceID]
Measure=Plugin
Plugin=AudioLevel
Parent=mMicdbLevel
Type=DeviceID
RegExpSubstitute=1
Substitute="{.*}\.":""

[mDeviceFormat]
Measure=Plugin
Plugin=AudioLevel
Parent=mMicdbLevel
Type=Format

[MicRoundBar]
Meter=Roundline
MeasureName=mMicdbLevel
MeterStyle=sRoundBar
LineColor=#Yellow#
X=37
Y=37

[MicIcon]
Meter=String
MeterStyle=sAllText
FontFace=Segoe Fluent Icons
FontSize=16
Text=[\xE720]
X=38
Y=38

========================================
; Mic Volume Control via PS1
========================================
[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
MinValue=0
MaxValue=100

[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

IfCondition=#InputMute# = 1
IfTrueAction=[!SetOption MicIcon Text "[\xEC54]"][!SetOption MicIcon FontColor "#Red#"][!UpdateMeter *][!Redraw]
IfFalseAction=[!SetOption MicIcon Text "[\xE720]"][!SetOption MicIcon FontColor "#White#"][!UpdateMeter *][!Redraw]
IfConditionMode=1

;---Neasures Devices---

[InputDevice]
Measure=Plugin
Plugin=PowershellRM
Parent=DeviceVolume
Line=Get-InputDevice
UpdateDivider=-1
DynamicVariables=1

=== Meters

[SetInputVolumeText]
Meter=String
MeterStyle=sAllText | sHighlight
StringAlign=Center
FontColor=#White#
Text=#InputVolume#
Hidden=1
Group=Input
DynamicVariables=1
X=37
Y=27

[SetInputVolRoundBar]
Meter=Roundline
MeasureName=InputVolume
MeterStyle=sRoundBar
LineColor=#Green#
Solid=0
X=37
Y=37

Last edited by sl23 on June 15th, 2024, 10:36 pm, edited 3 times in total.
- MuLab -
User avatar
sl23
Posts: 1233
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: [!Refreshapp] when skin loaded?

Post by sl23 »

Now, the question is, how do I Activate/deactivate the AudioDeviceCmdlet.dll? :confused:
- MuLab -
User avatar
Yincognito
Rainmeter Sage
Posts: 7576
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [!Refreshapp] when skin loaded?

Post by Yincognito »

sl23 wrote: June 15th, 2024, 10:33 pm Now, the question is, how do I Activate/deactivate the AudioDeviceCmdlet.dll? :confused:
As long as the Changed variable and the measure references are handled properly for the duration of the deactivation to also be properly set when you activate things again, I believe that simply disabling and enabling a measure group made of all those PowerShellRM related measures should lead you in the right direction. Didn't work much with such measures so I don't know for sure if that's the case, but typically when you disable a measure, the things / processes / whatever it uses are unloaded from memory (similar to unloading the entire skin but without actually affecting the skin itself).

Another somewhat simpler approach would be to put those measures into an .inc that you @include in the same location in the skin, make another .inc with similar but dummy (String?) measures as deactivation replacements, and then selectively !WriteKeyValue the corresponding @include and !Refresh the skin whenever you need to activate or deactivate using the PS script. You could even make 2 variants of the skin and activate the needed one when desired.

Your choice will depend on whether you consider reloading / refreshing the skin as a disadvantage or not.

As for the * vs .* quote, I was most likely explaining the syntax in the WHERE clause in the PS script when talking about the * wildcards, as the regexes are not related to them and use the .* patterns to refer to any number of characters.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
sl23
Posts: 1233
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: [!Refreshapp] when skin loaded?

Post by sl23 »

Well, after getting this far with the PS1 script and AudioDeviceCmdlet.dll I have been wanting to try the NirSoft approach to see what works better. So far, I'm liking the NirSoft way as it adjusts volume instantly. No hassles, just works! :D

My only issue with it is getting any kind of data from the SoundVolumeView.exe into Rainmeter. I've literally tried everything I can think of. I've looked entensively at Rainmeter, NirCmd, NirGet and SoundVolumeView manuals. Tried so many combinations and variations and the only command that gives something back is a list of the entire content from SoundVolumeView window!

Code: Select all

[mRun]
Measure=Plugin
Plugin=RunCommand
Program="#SKINSPATH#RM\Mic\SoundVolumeView.exe /stab """
Parameter= | GetNir "Volume Percent" "Name=Microphone && Type=Device"
State=Hide
;OutputType=ANSI
OutputFile=#CURRENTPATH#SoundValue.txt
;FinishAction=[!SetVariable aMicVolume "[mRun]"]
FinishAction=[!SetOption MicPercent Text "[mRun]"]

[MicPercent]
Meter=String
MeterStyle=sAllText
Percentual=1
NumOfDecimals=0
Text=X
DynamicVariables=1
X=130
Y=20
I am completely stuck as to why I can't get one piece of info from this tool!!! There are no errors from this skin, and no info shows in the [mRun] measure in the About window.
Any help would be great, thanks.
- MuLab -