It is currently March 29th, 2024, 12:59 am

Adjust Mic Volume Level?

Get help with creating, editing & fixing problems with skins
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 »

Sorry for the delay!

Here's the IfCondition I added:

Code: Select all

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

IfCondition=#InputMute# = 1
IfTrueAction=[!SetOption MicIcon Text "[\xEC54]"][!SetOption InputVolumeText Text "Muted"][!UpdateMeter *][!Redraw]
IfFalseAction=[!SetOption MicIcon Text "[\xE720]"][!SetOption InputVolumeText Text "#InputVolume#"][!UpdateMeter *][!Redraw]
IfConditionMode=1
DynamicVariables=1
I would like to keep the Text change behaviour, maybe, it does work ok if I remove that part of the Mouse Action. :D
One thing I have also found, when you unplug the Mic, the skin uses the next default device, which in this case is Stereo Mix, is there a way to stop this?
- MuLab -
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Adjust Mic Volume Level?

Post by Yincognito »

sl23 wrote: May 8th, 2022, 6:15 pm Sorry for the delay!

Here's the IfCondition I added:

Code: Select all

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

IfCondition=#InputMute# = 1
IfTrueAction=[!SetOption MicIcon Text "[\xEC54]"][!SetOption InputVolumeText Text "Muted"][!UpdateMeter *][!Redraw]
IfFalseAction=[!SetOption MicIcon Text "[\xE720]"][!SetOption InputVolumeText Text "#InputVolume#"][!UpdateMeter *][!Redraw]
IfConditionMode=1
DynamicVariables=1
I would like to keep the Text change behaviour, maybe, it does work ok if I remove that part of the Mouse Action. :D
One thing I have also found, when you unplug the Mic, the skin uses the next default device, which in this case is Stereo Mix, is there a way to stop this?
As a quick and untested solution to the code above, you should try testing the measure instead of the variable in the if condition. The variable only gets its value at the end of the update cycle via OnUpdate, while the measure should have the needed value (albeit as a numerical string) right after the substitute. If the susbtitute happens before the if condition, then it will work. If not, you can try using an if match instead, and test the "1" string value.

Regarding the mic unplugging, I'm not sure yet. Both getting and setting the "active" recording device can be done using AudioDeviceCmdlets, but I don't know if it's healthy to force a certain device at all times, like you seem to suggest. Theoretically, on the get part, the .PS1 script could be edited to do something like:

Code: Select all

if (Get-AudioDevice -Recording -like "*NameOfYourMicDevice*") {return Get-AudioDevice -RecordingVolume} else {return "0%"}
in the Get-InputVolume function, which should return the recording volume only if the said mic is the active recording device, otherwise it would yield "0%". You'd have to try and see if it works.
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 »

My only concern is that there's no indication which device you are editing and once a mic is plugged in, you can't change the Stereo Mix settings without unplugging or going into windows settings.

I'll give that a try though, see what happens, thanks...
- MuLab -
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Adjust Mic Volume Level?

Post by Yincognito »

sl23 wrote: May 8th, 2022, 6:15 pmOne thing I have also found, when you unplug the Mic, the skin uses the next default device, which in this case is Stereo Mix, is there a way to stop this?
sl23 wrote: May 9th, 2022, 7:03 amMy only concern is that there's no indication which device you are editing and once a mic is plugged in, you can't change the Stereo Mix settings without unplugging or going into windows settings.
Ok, a correct syntax to get or set the volume only if the active / default device looks like "...Microphone..." would be (you can add the else part if you want to return other things otherwise):

Code: Select all

function Get-InputVolume
{
  if ($(Get-AudioDevice -Recording).Name -like "*Microphone*") {return Get-AudioDevice -RecordingVolume}
}

...

function Set-InputVolume
{
  [CmdletBinding()]param([Parameter(Mandatory)][float]$Volume)
  if ($(Get-AudioDevice -Recording).Name -like "*Microphone*") {Set-AudioDevice -RecordingVolume $Volume}
}
You could, of course, test if the recording device is not stereo mix instead, by changing the if part(s) to something like:

Code: Select all

if ($(Get-AudioDevice -Recording).Name -ne "Stereo Mix") ...
obviously making sure the name corresponds exactly to what you have (e.g. for me, the Name field is "Stereo Mix (Realtek (R) Audio)" - you can see that via Import-Module -Name "[PathToTheDLL]\AudioDeviceCmdlets" and then Get-AudioDevice -List in a PS window).

Also, if you want it, you could get the name of the active / default recording device by adding a:

Code: Select all

function Get-InputDevice
{
  return $(Get-AudioDevice -Recording).Name
}
function to the PS1 script, and then integrate it in the skin:

Code: Select all

[GetAudio]
Measure=Plugin
Plugin=PowershellRM
Parent=DeviceVolume
Line=#SetAudio#$(Get-InputDevice), $(Get-InputVolume), $(Get-InputMute), "" -join "`n"
UpdateDivider=(#SlowUpdate#/#FastUpdate#)
DynamicVariables=1
followed by adding a corresponding String measure similar to the others, and adjusting the substitutes there accordingly, since there's now one more (\N*\R) part in the [GetAudio] string value. You could add a function to set the recording device as well, but that would be subject to different names of devices or different IDs and indexes depeding on computer, so at best one could do an "iterator" similar to Rainmeter's one for audio output, where you'd walk through or jump from device to device, setting it as default, via a "previous / next" index system.
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 »

I did try this yesterday, but was too tired to reply...

Code: Select all

function Get-InputVolume
{
  if ($(Get-AudioDevice -Recording).Name -like "*Microphone*") {return Get-AudioDevice -RecordingVolume}
}
I gave up as I'm back to square one trying to identify the device using PS code! Nothing seems to work for some reason?!

Whilst trying to get your code to work, I actually noticed by accident that I'd already achieved what I wanted without realising it!!! :oops:

Code: Select all

[mDeviceStatus]
Measure=Plugin
Plugin=AudioLevel
Parent=mMicLevel
Type=DeviceStatus
Substitute="0":"Off","1":"On"
IfCondition=mDeviceStatus = 0
IfTrueAction=[!SetOption MicTitle ToolTipTitle "Device - [mDeviceStatus]"]
IfFalseAction=[!SetOption MicTitle ToolTipTitle "[mDeviceName] - [mDeviceStatus]"]
This is using that code for DeviceList you mentioned previously by JSMorley. So job done!
It now does everything I wanted it to do, finally, I think! O.O
EDIT: This is working when you unplug the Mic, it switches to show StereoMix as the device in the ToolTipTitle ok. But it doesn't switch back when you plug the Mic back in??? What's worse, is that any adjustments are actually made to the Mic and NOT the Stereo Mix.

I can't thank you enough for all your help with this, I wouldn't have been able to get this skin to do what I wanted without it. :thumbup:
Last edited by sl23 on May 10th, 2022, 8:15 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 »

EDIT: This is working when you unplug the Mic, it switches to show StereoMix as the device in the ToolTipTitle ok. But it doesn't switch back when you plug the Mic back in???
Was thinking of using IfMatch to set the ToolTipTitle, but then I thought about using a Variable for it all to make things easier when transferring to another PC.

I'm thinking that I could Set a Variable as say Input=[mDeviceName], then:

Code: Select all

IfCondition=mDeviceStatus = 0
IfTrueAction=[!SetOption MicTitle ToolTipTitle "Device - [mDeviceStatus]"]
IfFalseAction=[!SetOption MicTitle ToolTipTitle "#Input# - [mDeviceStatus]"]
Although, in theory, this seems to work, it doesn't. I found that in the About/Skins window, the String for this doesn't change either. If the Mic is plugged in, then removed, the String changes to reflect this. But plug the Mic back in, and it doesn't trigger anything in the String, so it seems it isn't detected as a change?! Why? :? :? :?

EDIT: From what I can see, it appears to be a fault or limitation of the AudioLevel plugin. It doesn't seem to have the option to detect the Default Device. If it did, it would solve the problem, as Windows Control Panel Sound Settings Applet shows the default Device change back and forth between Mic and Stereo Mix each time you unplug/plug in the Mic.
Last edited by sl23 on May 10th, 2022, 9:02 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 »

so at best one could do an "iterator" similar to Rainmeter's one for audio output, where you'd walk through or jump from device to device, setting it as default, via a "previous / next" index system.
How did I miss that???
This was what I originally hoped for when I first designed this skin. I have to admit, I'm a bit wary about trying your code due to your previous caution...
Regarding the mic unplugging, I'm not sure yet. Both getting and setting the "active" recording device can be done using AudioDeviceCmdlets, but I don't know if it's healthy to force a certain device at all times, like you seem to suggest.
Would what you suggested just above be fine to use as a selection method? Or is this the 'forced' method you stated wasn't healthy?
- MuLab -
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Adjust Mic Volume Level?

Post by Yincognito »

sl23 wrote: May 10th, 2022, 8:11 pm Although, in theory, this seems to work, it doesn't. I found that in the About/Skins window, the String for this doesn't change either. If the Mic is plugged in, then removed, the String changes to reflect this. But plug the Mic back in, and it doesn't trigger anything in the String, so it seems it isn't detected as a change?! Why? :? :? :?

EDIT: From what I can see, it appears to be a fault or limitation of the AudioLevel plugin. It doesn't seem to have the option to detect the Default Device. If it did, it would solve the problem, as Windows Control Panel Sound Settings Applet shows the default Device change back and forth between Mic and Stereo Mix each time you unplug/plug in the Mic.
I believe you encountered the fault / limitation / bug that I also encountered here, in one of the skins of my suite. I wasn't using the device status like you did, but there were still things from the AudioLevel plugin. So yeah, it doesn't quite update things properly on switching back and forth between devices. But then, AudioDeviceCmdlets would be happy to leak some memory in helping you out with this though, I reckon... :rofl:
sl23 wrote: May 10th, 2022, 8:46 pmThis was what I originally hoped for when I first designed this skin. I have to admit, I'm a bit wary about trying your code due to your previous caution...
Would what you suggested just above be fine to use as a selection method? Or is this the 'forced' method you stated wasn't healthy?
Yeah, I meant forcing wouldn't be healthy, e.g. interfering with the 'normal' automatic switching of the active / default devices to force some particular device to always be the one to be active / default (even against other legit changes the user might operate from Settings and such).

Well, it would have been nice to describe your intentions right from the start - at least from my point of view. I mean, you probably realized by now that I'm quite open to challenges and making things work even - or better said, especially - when the odds are against that objective, but I have a slight problem in constantly adjusting the code to match ever changing goals. I prefer to aim to achieve something no matter how ambitious, instead of doing X and finding out Y is desired, then doing Y and finding out it's actually Z that's better suited, and so on. I'm sure you get the idea. :D

That being said, on a purely theoretical level, this shouldn't be too hard to achieve, though it might possibly involve some regex kung-fu and some well constructed interrogation system if it's about indexes. Basically, you'd need to:
1) get the entire list of devices in a RunCommand measure similar to what you already have in [GetAudio], but via Get-AudioDevice -List, optionally 'filtering' them to get only the indexes of the recording ones by using something like Get-AudioDevice -List | where Type -like "*Recording*" | select Index | sort Index | format-list, in order to find out the values such an index could take
2) use the output above to count how many indexes there are, by:
- duplicating the said output in a String measure similar to how [GetAudio] is duplicated in the code you already have and transforming it via a Substitute like "\s+\d+(?:\s+$)?":"+1"
- use the "+1+1...+1" string output of the previous String measure to calculate the index count in a Calc measure
3) get the index iterator by applying a Substitute like "(?siU)^.*(?:\s*\d+\s*?){0,#IndexToGetMinusOne#}+\s*(\d+)\s*?.*$":"\1" to a String measure that takes the output at 1) as the value of its String= option, while your #IndexToGetMinusOne# variable can be decremented or incremented via mouse actions within the 0 to IndexesCountMinusOne interval (the indexes count being the value given by the Calc measure at step 2) above)
4) set the device index in a RunCommand measure, via Set-AudioDevice -Index #Iterator#, where #Iterator# is the variable equivalent of the iterator measure at 3), since PowershellRM doesn't like measure or nested variable syntax aka square brackets in commands

Yep, I know, not that easy, but not that hard either - besides the regexes I already built for you, it's all just basic Rainmeter stuff. :sly:
sl23 wrote: May 10th, 2022, 7:47 pm I did try this yesterday, but was too tired to reply...

Code: Select all

function Get-InputVolume
{
 if ($(Get-AudioDevice -Recording).Name -like "*Microphone*") {return Get-AudioDevice -RecordingVolume}
}
I gave up as I'm back to square one trying to identify the device using PS code! Nothing seems to work for some reason?!
I have no idea why your PS is against you, since for me it works every freaking time:
AudioListNavigation.jpg
I used this slightly modified version of the script, that yields 5% or 5 if "*Microphone*" is not the default device, in order to not break or having to change the substitutes due to missing elements (which would be the case if we returned nothing):

Code: Select all

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

function Get-OutputVolume
{
  return Get-AudioDevice -PlaybackVolume
}

function Get-InputVolume
{
  # return Get-AudioDevice -RecordingVolume
  if ($(Get-AudioDevice -Recording).Name -like "*Microphone*") {return Get-AudioDevice -RecordingVolume} else {return "5%"}
}

function Get-OutputMute
{
  if (Get-AudioDevice -PlaybackMute) {return 1} else {return 0}
}

function Get-InputMute
{
  # if (Get-AudioDevice -RecordingMute) {return 1} else {return 0}
  if ($(Get-AudioDevice -Recording).Name -like "*Microphone*") {if (Get-AudioDevice -RecordingMute) {return 1} else {return 0}} else {return 5}
}

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
  [CmdletBinding()]param([Parameter(Mandatory)][float]$Volume)
  if ($(Get-AudioDevice -Recording).Name -like "*Microphone*") {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}
  # }
  [CmdletBinding()]param([Parameter(Mandatory)][byte]$State)
  if ($(Get-AudioDevice -Recording).Name -like "*Microphone*")
  {
    switch($State)
    {
      0 {Set-AudioDevice -RecordingMute $false}
      1 {Set-AudioDevice -RecordingMute $true}
    }
  }
}
As you can see in the screenshot, I just set the audio device index to my TV Tuner audio in (index 2), and the skin gladly set both the input values to 5... ;-)
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 »

I believe you encountered the fault / limitation / bug that I also encountered here,
Aha! I was right then... :D
Who made the plug in? Is there any chance of a fix?
Is AudioDeviceCmdlet the only alternative?
forcing wouldn't be healthy, e.g. interfering with the 'normal' automatic switching of the active / default devices
Even if it just disabled all mouse actions and meters when there's no mic would at least stop you inadvertently changing the wrong device volume.
Well, it would have been nice to describe your intentions right from the start 
I understand, I'm not trying to mess you about. Thing is, it states in the forum rules NOT to make skin requests. So I I didn't ask.

Originally, I asked for how to get mic volume control and if that could be done and death. crafter came up with the solution, but it had quite a major flaw that needed solving, hence where we're at. I settled for that solution but it kept bugging me if there were another way and also to fix the current issues like not switching to stereo mix when unplugged.

But I am literally dependant on your generosity, and any others that have joined in, as to whether this is achieved.

Ideally, I would like the ability to select a device and control it with a tool tip over the volume percentage that shows the current device. This is how the output device is setup and is perfect, for me anyway. But it would need to be suited to any pc, I have three!

That's not a request, but I wouldn't complain if you wanted that challenge. :Whistle I just thought that's way too much work, I mean, look at just this bit you're doing now!! O.O
Yep, I know, not that easy, but not that hard either - besides the regexes I already built for you, it's all just basic Rainmeter stuff. 
Thanks, I'll take a look tomorrow, I'm taking my son to cinema tonight to see the new Dr strange film :D
I have no idea why your PS is against you, since for me it works every freaking time:
Possibly my fault cos I'm doing it wrong? :oops:

Thank you for all your help. Will get back to you soon as I get a chance to try all this out, or more likely, get stuck! Lol
- MuLab -
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Adjust Mic Volume Level?

Post by Yincognito »

OK, so if it's the same limitation I encountered, the approach I mentioned won't make AudioLevel correct its detection, only a refresh will. That, if you want to base the detection on AudioLevel, that is. If you want to base it on AudioDeviceCmdlets, you have two choices: stick with just the detection in which case you let Windows handle switching between devices and you use PS just to get the device name and display it somewhere in your skin, OR use PS to do both the detection of the device name or index and navigating through indexes. The approach above handles the index setting of the latter, with the implementation of the former being much easier.

So, you have to decide what you want, and the decision to be final. You would be able to take action based on the device name in either case via simple Rainmeter abilities like an IfMatch, but of course this will be subject to the frequency at which the GetAudio measure is updating, meaning that if you change mute states or volumes before GetAudio is able to provide the current device every 1, 2 or whatever number of seconds it updates, the changes will be done on possibly the wrong device from your point of view (but on the right one from a technical point of view).

As for selecting the audio device, didn't death.crafter do something along those lines earlier?
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth