It is currently June 25th, 2019, 6:29 am

Audio Switch

Help with creating, editing & fixing problems with skins
Tony Ryan
Posts: 17
Joined: December 7th, 2016, 2:27 pm

Audio Switch

Tony Ryan » March 11th, 2019, 9:28 pm

Hi I have a little problem with this skin, what i mean is it works ok until the skin gets refreshed,then the icons change.
so if i am on headet then it shows headset icon,then if i switch to speaker it shows the speaker icon, but if i refresh the skin
the speaker changes back to the headset icon while it is still in speaker mode,is there a workaround to stop the icon changing when its refrrshed.
thanks.

Code: Select all

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

[MeasureAudioDevice]
Measure=Plugin
Plugin=Win7AudioPlugin

[MeterHeadset]
Meter=Image
ImageName=Headphone.png
X=0
Y=0
;W=36
;H=36
LeftMouseUpAction=[!CommandMeasure MeasureAudioDevice "ToggleNext"][!HideMeter MeterHeadset][!ShowMeter MeterSpeakers][!Redraw]
Hidden=0

[MeterSpeakers]
Meter=Image
ImageName=Speaker.png
X=r
Y=r
;W=36
;H=36
LeftMouseUpAction=[!CommandMeasure MeasureAudioDevice "TogglePrevious"][!HideMeter MeterSpeakers][!ShowMeter MeterHeadset][!Redraw]
Hidden=1
User avatar
eclectic-tech
Rainmeter Sage
Posts: 3371
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Audio Switch

eclectic-tech » March 12th, 2019, 4:58 am

In order to maintain skin changes when refreshed you need to use !WriteKeyValue to make the change permanent.

The string value of Win7Audio can vary from system to system, so creating a variable and writing the new value on each change is the simplest solution. DeviceNum will toggle between 0 and 1. The new value will be written to the [Variables] section so it is maintained on refresh and also set in the skin. A conditional statement controls the visibility of the meters. This also let's you eliminate skin updates; mouse clicks take care of the updates.

Here is a modified version of your skin:

Code: Select all

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

[Variables]
DeviceNum=0

[MeasureAudioDevice]
Measure=Plugin
Plugin=Win7AudioPlugin

[MeterHeadset]
Meter=Image
ImageName=Headphone.png
X=0
Y=0
;W=36
;H=36
LeftMouseUpAction=[!CommandMeasure MeasureAudioDevice "ToggleNext"][!WriteKeyValue Variables DeviceNum (1-#DeviceNum#)][!SetVariable DeviceNum (1-#DeviceNum#)][!UpdateMeter *][!Redraw]
DynamicVariables=1
Hidden=(#DeviceNum#=1?)

[MeterSpeakers]
Meter=Image
ImageName=Speaker.png
X=r
Y=r
;W=36
;H=36
LeftMouseUpAction=[!CommandMeasure MeasureAudioDevice "TogglePrevious"][!WriteKeyValue Variables DeviceNum (1-#DeviceNum#)][!SetVariable DeviceNum (1-#DeviceNum#)][!UpdateMeter *][!Redraw]
DynamicVariables=1
Hidden=(#DeviceNum#=0?)
User avatar
balala
Rainmeter Sage
Posts: 8308
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Audio Switch

balala » March 12th, 2019, 10:33 am

My recommendation is almost similar to eclectic-tech's one, with a small difference. I'd put a Substitute option in the [MeasureAudioDevice] measure, replacing the strings with numbers, then would use an IfCondition statement, to show / hide the appropriate meters. The only bangs which have to be left on the LeftMouseUpAction options of the [MeterHeadset] and [MeterSpeakers] meters are the !CommendMeasures. Also in this case you can hide both meters (adding a Hidden=1 option to them) from start, because the !ShowMeter / !HideMeter bangs added to the IfTrueAction / IfFalseAction options will show up the right meter:

Code: Select all

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

[MeasureAudioDevice]
Measure=Plugin
Plugin=Win7AudioPlugin
Substitute="Speaker/Headphone":"1"
IfCondition=(#CURRENTSECTION#=0)
IfTrueAction=[!HideMeter "MeterHeadset"][!ShowMeter "MeterSpeakers"][!Redraw]
IfFalseAction=[!ShowMeter "MeterHeadset"][!HideMeter "MeterSpeakers"][!Redraw]

[MeterHeadset]
Meter=Image
ImageName=Headphone.png
X=0
Y=0
;W=36
;H=36
LeftMouseUpAction=[!CommandMeasure MeasureAudioDevice "ToggleNext"]
Hidden=1

[MeterSpeakers]
Meter=Image
ImageName=Speaker.png
X=r
Y=r
;W=36
;H=36
LeftMouseUpAction=[!CommandMeasure MeasureAudioDevice "TogglePrevious"]
Hidden=1
Note that you have to complete the Substitute option of the [MeasureAudioDevice] measure, according to the strings returned by the measure on your computer, in both situations.
If you have to use the string values returned by the [MeasureAudioDevice] measure anywhere else in the code, you can add a suplimentar String measure, to can use the IfConditions (or IfMatch) there. Let me know if you want to try my code and don't know how to do this.
eclectic-tech wrote:
March 12th, 2019, 4:58 am
This also let's you eliminate skin updates; mouse clicks take care of the updates.
Not too useful for example with my above code, because this prevents the skin to react if you're making a change manually, not by clicking the skin. That's why I used the default Update=1000.
Tony Ryan
Posts: 17
Joined: December 7th, 2016, 2:27 pm

Re: Audio Switch

Tony Ryan » March 12th, 2019, 12:58 pm

Thanks eclectic-tech it works perfectly.
and thanks balala for your code but i will stay with eclectics
thanks to you both....
User avatar
balala
Rainmeter Sage
Posts: 8308
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Audio Switch

balala » March 12th, 2019, 1:06 pm

Tony Ryan wrote:
March 12th, 2019, 12:58 pm
and thanks balala for your code but i will stay with eclectics
As you wish...