It is currently April 25th, 2024, 5:36 pm

Refresh Skin on audio output change

Get help with creating, editing & fixing problems with skins
Raiyani
Posts: 2
Joined: September 22nd, 2019, 1:26 pm

Refresh Skin on audio output change

Post by Raiyani »

Hi All,

I just found and used Rainmeter for the the first time today and it's amazing.
This is primarily for a 5inch screen on the side of my PC and so far it looks fantastic.

The current problem I'm having and don't yet have the knowledge and couldn't find the right answer is that I am using the Simplon Skin and in particular the Visualizer skin, it works but when I switch between audio outputs ( headset and speakers(using a hotkey combo usually)) it stops working until I refresh the skin.

My question is, it is possible to set this to auto refresh on a hotkey combo press or to somehow detect the change?

Many thanks!

config below.

Code: Select all

----------------------------
[Rainmeter]
Update=0
Author=Connect-R
DynamicWindowSize=1

[Variables]
@include=#@#Variables.inc
AverageSize=5
Size=2.60
Space=5
BarWidth=#Size#
BarHeight=150
Color=#VisualizerColor#

;-------------------------------------------------------------
;-------------------------------------------------------------

[MeasureAudioOutput]
Measure=Plugin
Plugin=AudioLevel
Port=Output
FFTSize=4096
FFTOverlap=2048
FFTAttack=100
FFTDecay=80
FreqMin=30
FreqMax=16500
Sensitivity=25
Bands=61

-------------------------
Last edited by balala on September 22nd, 2019, 3:22 pm, edited 1 time in total.
Reason: Please use <code> tags whenever are you posting code snippets. It's the </> button.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5406
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Refresh Skin on audio output change

Post by eclectic-tech »

THe Win7AudioPlugin can be used to detect the current device and take an action when it changes.

Code: Select all

; Returns the current device name as the 'String' value and current volume level as the 'Number' value
[MeasureWin7Audio]
Measure=Plugin
Plugin=Win7AudioPlugin

; Checks the current sound device name and refreshes 'Simplon/Visualizer' skin when it changes
[MeasureDeviceName]
Measure=String
String=[MeasureWin7Audio]
OnChangeAction=[!Refresh "Simplon\Visualizer"]
DynamicVariables=1

; All skins must have a meter to be valid. This will run in the background (invisible).
[DummyMeter]
Meter=String
User avatar
balala
Rainmeter Sage
Posts: 16169
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Refresh Skin on audio output change

Post by balala »

Raiyani wrote: September 22nd, 2019, 1:36 pm My question is, it is possible to set this to auto refresh on a hotkey combo press or to somehow detect the change?
Beside eclectic-tech's very good reply (as usual), note that if you'd like to use a hotkey to refresh the skin this is also possible, but it requires to install a plugin, the HotKey.
If interested on how this does work, first download and install the HotKey_1.0.0.12.rmskin skin on the link above. This, beside installing the config, also installs the HotKey plugin, which from now on can be used.
Now add the following measure to your code:

Code: Select all

[MeasureMoveLeft]
Measure=Plugin
Plugin=HotKey
HotKey=CTRL R
KeyDownAction=[!Refresh]
When adding this measure it refreshes the skin whenever are you pressing the CTRL and R keys. Obviously you can apply any key combination needed / desired. On the HotKey plugin link you can find a description on how and which keys can be used.
This is another approach to refresh the skin, this time when certain key combination is pressed. I suppose eclectic-tech's solution is better then this one, however never know...

Two comments about the original code:
  • The Update set in the [Rainmeter] section can't be 0! Its lowest possible value is 16. The visualizer skins by definition must use low values, however 0 isn't possible. With a such value the skin uses the lowest possible value, 16.
  • The Author option doesn't belong long time ago to the [Rainmeter] section, but to [Metadata]. Although once it indeed belonged to [Rainmeter], in the meantime it was deprecated there and moved to [Metadata].
Raiyani
Posts: 2
Joined: September 22nd, 2019, 1:26 pm

Re: Refresh Skin on audio output change

Post by Raiyani »

Thank you eclectic-tech and balala,

I decided to go with eclectic-tech's method as it gave me the flexibility if I were to ever change audio output using means other than a key combo,
It works great but the only thing I had to change was the / to a \ when pointing to the skin to refresh.

I also changed to refresh to 16 for correctness sake and to remind me in the future should I ever need.

Thank you for your help and advice!
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5406
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Refresh Skin on audio output change

Post by eclectic-tech »

Happy to help. :great:
User avatar
balala
Rainmeter Sage
Posts: 16169
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Refresh Skin on audio output change

Post by balala »

Raiyani wrote: September 23rd, 2019, 9:23 am I decided to go with eclectic-tech's method as it gave me the flexibility if I were to ever change audio output using means other than a key combo,
Obviously eclectic-tech's solution is much more versatile and better. Ia admit and know this.
Raiyani wrote: September 23rd, 2019, 9:23 am It works great but the only thing I had to change was the / to a \ when pointing to the skin to refresh.
Slash (/) is never working in paths in Rainmeter, just backslash (\) does. A small mistake eclectic-tech made in his code, but this happens to all of us from time to time, I think.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Refresh Skin on audio output change

Post by jsmorley »

balala wrote: September 23rd, 2019, 12:50 pm Obviously eclectic-tech's solution is much more versatile and better. Ia admit and know this.

Slash (/) is never working in paths in Rainmeter, just backslash (\) does. A small mistake eclectic-tech made in his code, but this happens to all of us from time to time, I think.
To be clear, in "paths" in Rainmeter, both \ and / will work. However, when defining a "config name", which looks a bit like a path, but really isn't, you need to use the \ only. It's really a good habit to use the Windows \ character in paths rather than the Unix / character in any case.

I just have a general rule that the separators in URL's, which started in the Unix world, are /, and the separators for paths, which in Rainmeter are always based on Windows, are \.
User avatar
balala
Rainmeter Sage
Posts: 16169
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Refresh Skin on audio output change

Post by balala »

jsmorley wrote: September 23rd, 2019, 12:54 pm To be clear, in "paths" in Rainmeter, both \ and / will work. However, when defining a "config name", which looks a bit like a path, but really isn't, you need to use the \ only. It's really a good habit to use the Windows \ character in paths rather than the Unix / character in any case.
Right. Sorry, my bad. Struck out my reply.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Refresh Skin on audio output change

Post by jsmorley »

balala wrote: September 23rd, 2019, 1:06 pm Right. Sorry, my bad. Struck out my reply.
No problem. To be honest, "config names" should probably be "forgiving" of the difference between \ and / as well, just to be consistent with how "paths" are evaluated. This would be a tad complex in the code though, as Rainmeter keeps track of what configs are loaded based on their Windows path from the ..Skins\ folder, then just does a simple text compare between that list and the "config name" being addressed. So it would take a fair amount of code to first do a "search / replace" on the separator character before comparing them. Likely not worth the extra code and tiny bit of CPU.
User avatar
balala
Rainmeter Sage
Posts: 16169
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Refresh Skin on audio output change

Post by balala »

jsmorley wrote: September 23rd, 2019, 1:12 pm No problem. To be honest, "config names" should probably be "forgiving" of the difference between \ and / as well, just to be consistent with how "paths" are evaluated. This would be a tad complex in the code though, as Rainmeter keeps track of what configs are loaded based on their Windows path from the ..Skins\ folder, then just does a simple text compare between that list and the "config name" being addressed. So it would take a fair amount of code to first do a "search / replace" on the separator character before comparing them. Likely not worth the extra code and tiny bit of CPU.
Agree. Probably indeed doesn't worth.
My habbit is to always use \ in every path, never /. As Rainmeter runs only on Windows and in Windows the appropriate path separator character is \, this seems the best practice, at least in my view.