It is currently February 5th, 2023, 3:00 pm

Substituting data returned by the Win7AudioPlugin

Get help with creating, editing & fixing problems with skins
jn_meter
Posts: 121
Joined: December 27th, 2016, 12:04 pm

Substituting data returned by the Win7AudioPlugin

Post by jn_meter »

Hi all

The Win7AudioPlugin returns both a string and text (which - strangely, it seems to me - is normal for Rainmeter measures). The number is the volume level, as a percentage, and the string is the name of the audio device. Sometimes the number can be -1. When it is, I want a corresponding meter to output the character 'x'.

Here is the problem. I want to use Substitute (is there another way?) to turn the -1 into 'x'. Yet, Substitute works only on strings. Thus, in the present case, that operation is set to operate upon . . the name of the audio device. I have tried various workarounds but to no avail. Here is my current code (with the failed workarounds removed).

Code: Select all

[measure_volume]
Measure=Plugin
Plugin=Win7AudioPlugin
UpdateDivider=1
; The following substitution operates upon the wrong value . .
Substitute="-1":"x"

[meter_volume_value]
MeasureName=measure_volume
Meter=String
Text=%1
W=20
X=92r
I note that originally I was using a meter of type Bar, which worked well except that, for some reason, the background of the bar stretched always beyond where 100% was, such that I had a half-filled bar when the volume was 100%.

Thanks in advance for any help. Apologies if I miss something obvious.
Last edited by jn_meter on January 15th, 2023, 5:33 pm, edited 1 time in total.
User avatar
balala
Rainmeter Sage
Posts: 14936
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Substituting data returned by the Win7AudioPlugin

Post by balala »

jn_meter wrote: January 15th, 2023, 12:17 pm The Win7AudioPlugin returns both a string and text (which - strangely, it seems to me - is normal for Rainmeter measures). The number is the volume level, as a percentage, and the string is the name of the audio device. Sometimes the number can be -1. When it is, I want a corresponding meter to output the character 'x'.

Here is the problem. I want to use Substitute (is there another way?) to turn the -1 into 'x'. Yet, Substitute works only on strings. Thus, in the present case, that operation is set to operate upon . . the name of the audio device. I have tried various workarounds but to no avail. Here is my current code (with the failed workarounds removed).
You can't really use substitution in this case, exactly due to the thing you've described: it is applied to the string value of the measure. So you'll need another way to achieve this. The simplest way is to use an IfCondition on the [measure_volume] measure, in a way to get "x" or the volume level to be shown on the String meter, in the appropriate cases. So, remove the Substitute option from the [measure_volume] and add the following options:

Code: Select all

[measure_volume]
...
IfCondition=(#CURRENTSECTION#<0)
IfTrueAction=[!SetOption meter_volume_value Text "x"][!UpdateMeter "meter_volume_value"][!Redraw]
IfFalseAction=[!SetOption meter_volume_value Text "[measure_volume:]%"][!UpdateMeter "meter_volume_value"][!Redraw]
As you can see the IfTrueAction and IfFalseAction options set different Text option to be shown on the [meter_volume_value] meter:
  • x when the sistem is muted.
  • The volume level as percentage, in other cases.
If you did all this, you can completely remove the Text option of the [meter_volume_value] meter, along with the MeasureName, because the MeasureName is not needed anymore, and the Text option is dynamically set by the above IfTrueAction and IfFalseAction options, so it's not needed explicitly on the meter.
jn_meter
Posts: 121
Joined: December 27th, 2016, 12:04 pm

Re: Substituting data returned by the Win7AudioPlugin

Post by jn_meter »

balala,

Wonderful stuff, as usual. I would have had terrible trouble working that out for myself.

The setup now works as intended, expect - one wrinkle - the meter does not update, even if I add DynamicVariables=1 to the measure.
User avatar
balala
Rainmeter Sage
Posts: 14936
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Substituting data returned by the Win7AudioPlugin

Post by balala »

jn_meter wrote: January 15th, 2023, 3:44 pm The setup now works as intended, expect - one wrinkle - the meter does not update, even if I add DynamicVariables=1 to the measure.
You're perfectly right ( :? ), it doesn't update this way, because I forgot something extremely important. Replace the parameter which sets the value which has to be shown by the meter when the system is not muted (so the parameter used into the !SetOption bang of the IfFalseAction option), by "escaping" it with *: [!SetOption meter_volume_value Text "[*measure_volume:*]%"].
Maybe is better to repost the whole involved options. Here they are:

Code: Select all

[measure_volume]
...
IfCondition=(#CURRENTSECTION#<0)
IfTrueAction=[!SetOption meter_volume_value Text "x"][!UpdateMeter "meter_volume_value"][!Redraw]
IfFalseAction=[!SetOption meter_volume_value Text "[*measure_volume:*]%"][!UpdateMeter "meter_volume_value"][!Redraw]
This solution requires the DynamicVariables=1 option to be added to the [meter_volume_value] meter (not to the [measure_volume] measure. Make sure you added it.
Sorry, definitely my mistake. And my bad...
jn_meter
Posts: 121
Joined: December 27th, 2016, 12:04 pm

Re: Substituting data returned by the Win7AudioPlugin

Post by jn_meter »

That is tip-top and dandy. Thank you very much.
User avatar
balala
Rainmeter Sage
Posts: 14936
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Substituting data returned by the Win7AudioPlugin

Post by balala »

jn_meter wrote: January 15th, 2023, 5:33 pm That is tip-top and dandy. Thank you very much.
And does it work now as expected? Hope it does.
jn_meter
Posts: 121
Joined: December 27th, 2016, 12:04 pm

Re: Substituting data returned by the Win7AudioPlugin

Post by jn_meter »

It does work as expected (else it would not be tip-top!).
User avatar
balala
Rainmeter Sage
Posts: 14936
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Substituting data returned by the Win7AudioPlugin

Post by balala »

jn_meter wrote: January 15th, 2023, 7:33 pm It does work as expected (else it would not be tip-top!).
:thumbup: