It is currently April 19th, 2024, 9:24 am

Help in programming

Get help with creating, editing & fixing problems with skins
ItsJustRyan
Posts: 81
Joined: October 25th, 2019, 1:20 am

Help in programming

Post by ItsJustRyan »

Hi!

I've been trying to modify a skin that I downloaded. Basically, it reads the volume of the computer and puts it on a scale thing. Right now, all of it is working fine exceot when it is muted, it displays the volume as -1%, and I have been trying to program it so that when it is at "-1%', it changes it to 0% but to no success.
I've tried many different ways, but the latest attempt is in the variable section of [PercentageCalc]. Any help please? Thanks!

Code: Select all

[Rainmeter]
Author=Seahorse (AKA Osric Wuscfrea) mr.seahorse@gmail.com
Update=1000
BackgroundMode=2
SolidColor=0,0,0,1

[Metadata]
Name=Neon Volume Control Horizontal Bottom
Version=1.1
License=Creative Commons BY-NC-SA 3.0
Information=Description: Volume control and output device toggle. | Instructions: Click the left & right arrows to toggle through available audio devices, click on the bar to adjust volume. | Credits: Nil.

;1.1 - Increase hot zones for volume.
;1.0.1 - Added 0 reading ind increase click area.
;1.0 - Base version

;===============================================================================================
;Variables
;===============================================================================================

[Variables]

;===============================================================================================
;Measures
;===============================================================================================

[MeasureWin7Audio]
Measure=Plugin
Plugin=Win7AudioPlugin.dll


;Add & subtract 1 to force a numeric output.
[PercentageCalca]
Measure=Calc
Formula=(MeasureWin7Audio)


[PercentageCalc]
Measure=Calc
x=(MeasureWin7Audio)
IfCondition=x < 0
IfTrueAction=[!SetVariable x "0"]
IfCondition=x>0
IfTrueAction=[!SetVariable x "MeasureWin7Audio"]
Formula=(x)



;===============================================================================================
;Meters
;===============================================================================================

[MeterBarBackground]
Meter=Image
X=5
Y=0
ImageName=#ROOTCONFIGPATH#Images\HBar.png

[MeterVolumePercent]
Meter=String
MeasureName=PercentageCalc
X=R
Y=0
H=15
FontColor=255,255,255,255
StringAlign=left
StringEffect=Shadow
StringStyle=Bold
Antialias=1
Noclip=1
Text="%1%"

[MeterPointer]
Meter=Image
X=(4+[PercentageCalc])
Y=0
Imagename=#ROOTCONFIGPATH#\Images\PointerD.png
DynamicVariables=1

;-----------------------------------------------------------------------------------------------
;Volume !Bangs - invisible boxes matching the grid (A digital frontier)
;-----------------------------------------------------------------------------------------------

[MeterVolume0]
Meter=Image
X=0
Y=0
H=10
W=10
LeftMouseUpAction=!CommandMeasure "MeasureWin7Audio" "SetVolume 0"

[MeterVolume10]
Meter=Image
X=10r
Y=r
H=10
W=10
LeftMouseUpAction=!CommandMeasure "MeasureWin7Audio" "SetVolume 10"

[MeterVolume20]
Meter=Image
X=10r
Y=r
H=10
W=10
LeftMouseUpAction=!CommandMeasure "MeasureWin7Audio" "SetVolume 20"

[MeterVolume30]
Meter=Image
X=10r
Y=r
H=10
W=10
LeftMouseUpAction=!CommandMeasure "MeasureWin7Audio" "SetVolume 30"

[MeterVolume40]
Meter=Image
X=10r
Y=r
H=10
W=10
LeftMouseUpAction=!CommandMeasure "MeasureWin7Audio" "SetVolume 40"

[MeterVolume50]
Meter=Image
X=10r
Y=r
H=10
W=10
LeftMouseUpAction=!CommandMeasure "MeasureWin7Audio" "SetVolume 50"

[MeterVolume60]
Meter=Image
X=10r
Y=r
H=10
W=10
LeftMouseUpAction=!CommandMeasure "MeasureWin7Audio" "SetVolume 60"

[MeterVolume70]
Meter=Image
X=10r
Y=r
H=10
W=10
LeftMouseUpAction=!CommandMeasure "MeasureWin7Audio" "SetVolume 70"

[MeterVolume80]
Meter=Image
X=10r
Y=r
H=10
W=10
LeftMouseUpAction=!CommandMeasure "MeasureWin7Audio" "SetVolume 80"

[MeterVolume90]
Meter=Image
X=10r
Y=r
H=10
W=10
LeftMouseUpAction=!CommandMeasure "MeasureWin7Audio" "SetVolume 90"

[MeterVolume100]
Meter=Image
X=10r
Y=r
H=10
W=10
LeftMouseUpAction=!CommandMeasure "MeasureWin7Audio" "SetVolume 100"
Last edited by eclectic-tech on October 25th, 2019, 1:38 am, edited 1 time in total.
Reason: Please use code tags. It is the </> symbol.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5391
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Help in programming

Post by eclectic-tech »

Here is one way to accomplish that...modified IfCondition actions in [PercentageCalc] section to change the 'Text' value of the string meter to 0% when the sound is muted; when [MeasureWin7Audio] = -1

Code: Select all

[PercentageCalc]
Measure=Calc
Formula=MeasureWin7Audio
IfCondition=(MeasureWin7Audio = -1)
IfTrueAction=[!SetOption MeterVolumePercent Text "0%"][!UpdateMeter MeterVolumePercent][!Redraw]
IfFalseAction=[!SetOption MeterVolumePercent Text "%1%"][!UpdateMeter MeterVolumePercent][!Redraw]
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help in programming

Post by balala »

ItsJustRyan wrote: October 25th, 2019, 1:25 am I've tried many different ways, but the latest attempt is in the variable section of [PercentageCalc]. Any help please? Thanks!
Besides eclectic-tech's solution note that there are a few errors in the original code:
  • In Rainmeter you can't define a variable as you do in programing languages. I mean that the x=(MeasureWin7Audio) option of the [PercentageCalc] measure isn't valide, you can't use it (not being a valid Rainmeter option) and you can't use later the x variable (for instance in the Formula or IfCondition options of the same measure). A "variable" section of a measure doesn't exist.
  • You can't use two IfCondition / IfTrueAction options on a single measure. You have to number them. This means that if would be valid, the second IfCondition / IfTrueAction should be IfCondition2 / IfTrueAction2:

    Code: Select all

    IfCondition=x < 0
    IfTrueAction=[!SetVariable x "0"]
    IfCondition2=x>0
    IfTrueAction2=[!SetVariable x "MeasureWin7Audio"]
I also propose another solution behind eclectic-tech's measure. You could use the following [PercentageCalc] measure, instead of eclectic-tech's one, which makes the IfCondition useless:

Code: Select all

[PercentageCalc]
Measure=Calc
Formula=( Clamp ( MeasureWin7Audio, 0, 100 ))
Don't misunderstand me, eclectic-tech's solution is perfect (as usually), this is just another approach of the same question.
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Help in programming

Post by sl23 »

I've had that issue for years lol but ignored it as I never really use the Mute.
I thought you could just use Substitute="-1":"MUTED" or something similar?
- MuLab -
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Help in programming

Post by sl23 »

Out of curiosity, does anyone have a solution to this?
- MuLab -
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help in programming

Post by balala »

sl23 wrote: November 8th, 2019, 10:00 pm does anyone have a solution to this?
To what? Not sure...
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5391
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Help in programming

Post by eclectic-tech »

sl23 wrote: October 30th, 2019, 11:28 pm I've had that issue for years lol but ignored it as I never really use the Mute.
I thought you could just use Substitute="-1":"MUTED" or something similar?
A measure has 2 values NUMBER and STRING; substitution only affects the STRING value, the NUMBER value is not changed by substitution. It depends on where you are using the measure value that determines what method to use.

In the case of Win7AudioPlugin, the STRING value is the current sound device name, while the NUMBER value is the current volume level. You are dealing with 2 completely different values.

Substitute="-1":"MUTED" will not work because the STRING value (that substitution affects) will never be "-1".
One way to deal with this could be to use an IfCondition action to test the NUMBER value of the measure and change your display meter to "Muted" when the value is "-1".

Code: Select all

[MeasureVolume]
Measure=Plugin
Plugin=Win7AudioPlugin

IfCondition=(MeasureVolume = -1)
IfTrueAction=[!HideMeter Volume][!ShowMeter Muted][!UpdateMeter *][!Redraw]
IfFalseAction=[!ShowMeter Volume][!HideMeter Muted][!UpdateMeter *][!Redraw]
DynamicVariables=1

[Volume]
Meter=String
Text=[MeasureVolume:]
DynamicVariables=1
Hidden=0

[Muted]
Meter=String
X=r
Y=r
Text=MUTED
Hidden=1
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help in programming

Post by balala »

eclectic-tech wrote: November 9th, 2019, 2:12 am A measure has 2 values NUMBER and STRING; substitution only affects the STRING value, the NUMBER value is not changed by substitution. It depends on where you are using the measure value that determines what method to use.

In the case of Win7AudioPlugin, the STRING value is the current sound device name, while the NUMBER value is the current volume level. You are dealing with 2 completely different values.

Substitute="-1":"MUTED" will not work because the STRING value (that substitution affects) will never be "-1".
One way to deal with this could be to use an IfCondition action to test the NUMBER value of the measure and change your display meter to "Muted" when the value is "-1".
Even if not obvious, it can be done even with substitution, but there has to be added a String measure:

Code: Select all

[MeasureVolume]
Measure=Plugin
Plugin=Win7AudioPlugin

[MeasureVolumeS]
Measure=String
String=[MeasureVolume:]
Substitute="-1":"Muted"
DynamicVariables=1

[MeterVolume]
Meter=STRING
MeasureName=MeasureVolumeS
X=0
Y=0
AntiAlias=1
Text=Volume: %1
SolidColor=0,0,0,1
[MeasureVolumeS] gets the volume level returned by [MeasureVolume] as a string, makes the substitution (if needed, so if the system is muted) and returns either the volume level (if the system isn't muted), or Muted (if it is).
So as you can see, it can be done, however question is if it does worth. Probably not.

Two additional comments related to eclectic-tech's code:
  • If you hide / show meters, there is not needed to update them. Redrawing the skin is completely enough. That's why I'd remove the [!UpdateMeter *] bang from the IfTrueActin and IfFalseAction options of the [MeasureVolume] measure.
  • Instead of having two distinct meters ([Volume] and [Muted]), I'd better use one single and would set its Text option with !SetOption bangs. Just to reduce the number of sections, because the less meters we have, the better is.
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Help in programming

Post by sl23 »

This is what I have for the volume:

Code: Select all

[mVolume]
Measure=Plugin
Plugin=Win7AudioPlugin
UpdateDivider=#UD1#
Substitute="-1":"MUTED"
DynamicVariables=1

[VolLevel]
Meter=String
Text=[mVolume:]
FontFace=Corbel
StringStyle=Bold
FontSize=12
FontColor=175,175,175
SolidColor=0,0,0,1
AntiAlias=1
DynamicVariables=1
LeftMouseUpAction=[!CommandMeasure "mVolume" "SetVolume #VolLow#"] [!UpdateMeasure mVolume] [!UpdateMeter *] [!Redraw]
RightMouseUpAction=[!CommandMeasure "mVolume" "SetVolume #VolMax#"] [!UpdateMeasure mVolume] [!UpdateMeter *] [!Redraw]
MiddleMouseUpAction=ms-settings:sound
X=2
Y=15
I changed it to this:

Code: Select all

[mVolume]
Measure=Plugin
Plugin=Win7AudioPlugin

[msVolume]
Measure=String
String=[mVolume:]
UpdateDivider=#UD1#
Substitute="-1":"MUTED"
DynamicVariables=1

[VolLevel]
Meter=String
Text=[mVolume:]
FontFace=Corbel
StringStyle=Bold
FontSize=12
FontColor=175,175,175
SolidColor=0,0,0,1
AntiAlias=1
DynamicVariables=1
LeftMouseUpAction=[!CommandMeasure "mVolume" "SetVolume #VolLow#"] [!UpdateMeasure mVolume] [!UpdateMeter *] [!Redraw]
RightMouseUpAction=[!CommandMeasure "mVolume" "SetVolume #VolMax#"] [!UpdateMeasure mVolume] [!UpdateMeter *] [!Redraw]
MiddleMouseUpAction=ms-settings:sound
X=2
Y=15
This performs exactly as before. I then realised I forgot to change [VolLevel] Text=[mVolume:] to Text=msVolume. This now displays msVolume instead of the numerical volume as before. What's wrong?
- MuLab -
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help in programming

Post by balala »

sl23 wrote: November 9th, 2019, 7:17 pm This now displays msVolume instead of the numerical volume as before. What's wrong?
When you want to show the value returned by a measure (this time by [msVolume]), don't put the Text=msVolume option, because this shows msVolume, as you saw. Instead add a MeasureName=msVolume option, along with Text=%1. This way the String meter shows the value returned by the [msVolume] measure. And one more: this procedure doesn1t require to set the dynamic variables, so you can remove the DynamicVariables=1 option as well.