It is currently April 26th, 2024, 9:46 pm

Substitute issue

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

Substitute issue

Post by sl23 »

After completing my suite, this 8 year old issue has finally got to a point where it can't be ignored!

So, after doing the same thing for the Mic Input and finding it actually worked, I did a little research into why it won't work on the speaker output. You know what I found out? Naf all! At least nothing that helps me solve this problem. So if anyone can help, please put me out of my misery!! :?

This Substitute works:

Code: Select all

[InputVolume]
Measure=Plugin
Plugin=PowershellRM
Parent=DeviceVolume
Line=Get-Volume -Type Input
IfCondition=InputVolume = -1
IfTrueAction=[!SetOption MicIcon Text "[\xEC54]"][!UpdateMeter *][!Redraw]
IfFalseAction=[!SetOption MicVolumeText Text ""][!UpdateMeter *][!Redraw]
IfCondition2=InputVolume = 0
IfTrueAction2=[!SetOption MicIcon Text "[\xE720]"][!UpdateMeter *][!Redraw]
IfCondition3=(InputVolume > 0) && (InputVolume <= 35)
IfTrueAction3=[!SetOption MicIcon Text "[\xE720]"][!UpdateMeter *][!Redraw]
IfCondition4=(InputVolume > 35) && (InputVolume <= 65)
IfTrueAction4=[!SetOption MicIcon Text "[\xE720]"][!UpdateMeter *][!Redraw]
IfCondition5=InputVolume > 65
IfTrueAction5=[!SetOption MicIcon Text "[\xF12E]"][!UpdateMeter *][!Redraw]
IfConditionMode=1
Substitute="-1":"Muted","1.000001":"1","2.999999":"3","9.000001":"9"
MinValue=0
MaxValue=100
But this Substitute doesn't:

Code: Select all

[mOutput]
Measure=Plugin
Plugin=Win7AudioPlugin
DynamicVariables=1
IfCondition=mOutput = -1
IfTrueAction=[!SetOption SpeakerIcon Text "[\xE74F]"][!UpdateMeter *][!Redraw]
IfCondition2=mOutput = 0
IfTrueAction2=[!SetOption SpeakerIcon Text "[\xE992]"][!UpdateMeter *][!Redraw]
IfCondition3=(mOutput > 0) && (mOutput <= 35)
IfTrueAction3=[!SetOption SpeakerIcon Text "[\xE993]"]
IfCondition4=(mOutput > 35) && (mOutput <= 65)
IfTrueAction4=[!SetOption SpeakerIcon Text "[\xE994]"]
IfCondition5=mOutput > 65
IfTrueAction5=[!SetOption SpeakerIcon Text "[\xE995]"]
IfConditionMode=1
Substitute="-1":"Muted","0.00":""
It's not just the "Muted" part, the whole command doesn't work, and for some reason never has on this Measure.
And yet there are two things that I don't understand:
  • 1. The first IfCondition works and replaces the icon correctly, in both Measures.
    2. In the "About" window, under the "Skins" tab, I have 3 skins using the volume code, all say Number = -1, String = LG TV.
Yet the Substitute command works on none of them,why is that?
Last edited by sl23 on August 15th, 2021, 2:45 pm, edited 1 time in total.
- MuLab -
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: Substitute issue

Post by death.crafter »

sl23 wrote: August 15th, 2021, 10:27 am
Substitute works on string value of the measure. You are trying to substitute -1 but the value is the name of your audio device.

What you can do is have another string measure and use Substitute there, with String=[mOutput:] .
from the Realm of Death
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Substitute issue

Post by sl23 »

That makes no sense! :???: I thought what was shown in About/Skins was the value returned by Rainmeter? This doesn't show the name of my audio device, it shows -1. Wouldn't it show the device name?

Also, how does the IfCondition work as it is based on detecting -1 as well. :confused:

I've never had to create a String Measure before, I couldn't understand how to translate it to what I needed! :(
But I just had another idea, and it worked! Finally, after 8 years!!! :D

Code: Select all

[mOutput]
Measure=Plugin
Plugin=Win7AudioPlugin
IfCondition=mOutput = -1
IfTrueAction=[!SetOption SpeakerIcon Text "[\xE74F]"][!SetOption OutputLevel Text "Muted"]
IfFalseAction=[!SetOption OutputLevel Text "[mOutput:]"]
- MuLab -
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Substitute issue

Post by jsmorley »

sl23 wrote: August 15th, 2021, 11:10 am That makes no sense! :???: I thought what was shown in About/Skins was the value returned by Rainmeter? This doesn't show the name of my audio device, it shows -1. Wouldn't it show the device name?

Also, how does the IfCondition work as it is based on detecting -1 as well. :confused:

I've never had to create a String Measure before, I couldn't understand how to translate it to what I needed! :(
But I just had another idea, and it worked! Finally, after 8 years!!! :D

Code: Select all

[mOutput]
Measure=Plugin
Plugin=Win7AudioPlugin
IfCondition=mOutput = -1
IfTrueAction=[!SetOption SpeakerIcon Text "[\xE74F]"][!SetOption OutputLevel Text "Muted"]
IfFalseAction=[!SetOption OutputLevel Text "[mOutput:]"]
I would set:

IfFalseAction=[!SetOption OutputLevel Text "[*mOutput:*]"]

https://docs.rainmeter.net/manual/variables/#Escape

You want to "escape" the measure name when you set it, so the literal measure section variable will be set, and not the current value of the measure. You don't want the value on the meter to be "static" for the duration of however long the device is not muted. Don't forget that IfFalseAction won't be fired again until the value of the condition changes from true to false. It won't fire when it just stays false. Be sure to set DyanmicVariables=1 on the meter.
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Substitute issue

Post by sl23 »

Ok thanks for the tip :D
I think I get it :oops: It took me ages to understand the importance of [Variables] :lol:
- MuLab -
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: Substitute issue

Post by death.crafter »

sl23 wrote: August 15th, 2021, 11:10 am That makes no sense! :???: I thought what was shown in About/Skins was the value returned by Rainmeter? This doesn't show the name of my audio device, it shows -1. Wouldn't it show the device name?

Also, how does the IfCondition work as it is based on detecting -1 as well. :confused:

I've never had to create a String Measure before, I couldn't understand how to translate it to what I needed! :(
But I just had another idea, and it worked! Finally, after 8 years!!! :D

Code: Select all

[mOutput]
Measure=Plugin
Plugin=Win7AudioPlugin
IfCondition=mOutput = -1
IfTrueAction=[!SetOption SpeakerIcon Text "[\xE74F]"][!SetOption OutputLevel Text "Muted"]
IfFalseAction=[!SetOption OutputLevel Text "[mOutput:]"]
Plugin=Win7AudioPlugin controls the sound device and volume.

The measure will return different "string" and "number" values.

String: The name of the current sound device. This will be used when the measure is bound to a String meter, or if the string [SectionVariable] value of the measure is used.

If there is a problem detecting or interacting with the sound device, the following error strings are possible:
ERROR - Getting Device Description
ERROR - Getting Property
ERROR - Getting Default Device

Number: The percentage (0-100) of current volume level. This will be used when the measure is bound to a meter which requires a percentage. This numeric value can also be used in a String meter, by setting the Text option of the meter to the numeric [SectionVariable:] value of the measure.
Source: Docs
from the Realm of Death
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Substitute issue

Post by sl23 »

Sorry, but it still makes no sense.

Why does this IfCondition=mOutput = -1 work then?

For that to work, there needs to be a number value of exactly -1. So that if that number exists, the condition is proved true and executes the IfTrueAction.

It stands to reason that if that can work by detecting -1 the Substitute should also work by detecting the very same thing, does it not?

Logic's a bitch some times! :? :rofl:
- MuLab -
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Substitute issue

Post by jsmorley »

sl23 wrote: August 15th, 2021, 12:36 pm Sorry, but it still makes no sense.

Why does this IfCondition=mOutput = -1 work then?

For that to work, there needs to be a number value of exactly -1. So that if that number exists, the condition is proved true and executes the IfTrueAction.

It stands to reason that if that can work by detecting -1 the Substitute should also work by detecting the very same thing, does it not?

Logic's a bitch some times! :? :rofl:
No, Substitute ONLY works on the string value of a measure. In this case, you have a number value of -1 but a string value of "speakers" or whatever. This is one of only a few measures that return both a number and a string value that are different, and it must be handled a bit differently. Any Substitute on the measure is going to be acting on the string value of "speakers", not the number value of -1.

The approach you ended up with, using IfCondition to test for the -1 number value, is the right one.

IfCondition ONLY works with the number value of a measure.
Substitute and IfMatch ONLY work on the string value of a measure.
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Substitute issue

Post by sl23 »

Oh ok, nooow it makes sense, :D

Sorry, I just had to ask... What is the reason for the String value of Speakers though? Is that used for something?
- MuLab -
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Substitute issue

Post by jsmorley »

sl23 wrote: August 15th, 2021, 12:45 pm Oh ok, nooow it makes sense, :D

Sorry, I just had to ask... What is the reason for the String value of Speakers though? Is that used for something?
Well, presumably the thinking is that you are going to want both. The name of the device being measured as a string value like "speakers" and the numeric volume value like "-1" or "100". Why would you want to have to have two separate measures to return them, when you can do it with one?