Well, the mood finally arrived, and it turned out that the matter was as simple as a few nested conditionals, no pausing, no additional time measure. This behaves both similar and slightly different than the previous code - make sure you read and understand the explanation if you want to work with this...Yincognito wrote: ↑July 10th, 2024, 10:47 pmI might think about it in the following days, if I'm in the mood.
![Wink ;-)](./images/smilies/innuendo.gif)
The code:
Code: Select all
[Variables]
Update=25
HoldTime=0
HoldMost=1000
FallStep=0.01
[Rainmeter]
Update=#Update#
AccurateText=1
DynamicWindowSize=1
BackgroundMode=2
SolidColor=128,128,128,255
---Measures---
[Rmsq]
Measure=Plugin
Plugin=AudioLevel
[Peak]
Measure=Plugin
Plugin=AudioLevel
Parent=Rmsq
Type=Peak
[Hold]
Measure=Calc
Formula=(Rmsq>Hold-#FallStep#*(#HoldTime#>#HoldMost#?1:0)?Rmsq:(#HoldTime#>#HoldMost#?Hold-#FallStep#:Hold))
OnUpdateAction=[!SetVariable HoldTime ([Hold]=[Rmsq]?0:#HoldTime#+#Update#)]
DynamicVariables=1
---Meters---
[Result]
Meter=String
FontFace=Consolas
MeasureName =Rmsq
MeasureName2=Hold
MeasureName3=Peak
NumOfDecimals=5
Text=Rmsq = %1#CRLF#Hold = %2#CRLF#Peak = %3
DynamicVariables=1
[Visual]
Meter=Shape
X=5R
Y=0r
Shape =Rectangle 0, 0, 150 ,48 | StrokeWidth 0 | Stroke Color 0,0,0,0 | Fill Color 128,128,128,255
Shape2=Rectangle 0, 0,([Rmsq]*150),16 | StrokeWidth 0 | Stroke Color 0,0,0,0 | Fill Color 255, 0, 0,255
Shape3=Rectangle 0,16,([Hold]*150),16 | StrokeWidth 0 | Stroke Color 0,0,0,0 | Fill Color 0,255, 0,255
Shape4=Rectangle 0,32,([Peak]*150),16 | StrokeWidth 0 | Stroke Color 0,0,0,0 | Fill Color 0, 0,255,255
DynamicVariables=1
- Update is the time interval in ms between updates
- HoldTime is the time counter in ms
- HoldMost is the maximum time interval in ms that Hold will keep its value
- FallStep is how fast Hold will decrease each update after HoldMost ms have passed
The measures:
- Rmsq is the standard RMS value (red color)
- Hold is the value we're interested in (green color)
- Peak is the standard Peak value (blue color)
The process:
1) we either make Hold to be Rmsq, if the latter is greater than the former - this can happen either:
- before or during the HoldMost interval, in which case we compare Rmsq with Hold normally, since Hold doesn't change otherwise
- after the HoldMost interval has passed, in which case we compare Rmsq with Hold-FallStep, since we're going to subtract FallStep from Hold later on
2) or otherwise, if Rmsq is not greater than Hold - we can safely replicate the keep and fall effect from the spectrum analyzer GIF earlier:
- decrease Hold by FallStep each update, if the HoldMost interval has passed, to gradually drop Hold as desired
- keep Hold the same, if the HoldMost interval has not yet passed, to make Hold stick for better observation
3) finally, on each Hold update - we:
- reset HoldTime to 0, if Hold is equal to Rmsq i.e. we either started, ended, or got out of the keep and decrease interval for Hold according to the 1) point
- increase HoldTime by Update, if otherwise i.e. we're during the keep and decrease interval for Hold and we need to count time
The notes:
- you'll have to duplicate and use HoldTime and Hold under different names (and optionally HoldMost and / or FallStep, if you want different keep intervals and / or decrease speeds) for every instance/value you want to make a "Hold" value for
- if curious, this keep and decrease technique can easily be applied to the standard Peak instead, by replacing all 3 occurrences of Rmsq in Hold with Peak (which is why I placed Hold after Peak in the code, despite their order in the meters)
- as in the previous code, the Peak measure is entirely optional, unless of course you want to see it keep and decrease instead of the RMS value
Hopefully everything is clear and solved now and we can close this chapter - if this is still not what you want, then this is where my help ends in this case. Next time, you'll be the one to figure it all out - seriously.
![Big Grin :D](./images/smilies/ag.gif)
EDIT: Optionally, if you want to shorten the code (at the expense of having the inherent measure benefits), you could even transform the Hold measure into a Hold variable and put it all in the OnUpdateAction of the standard measure you want to "keep and decrease" (Rmsq case illustrated below, similar approach for the standard Peak measure), once you use the [#Hold] nested syntax for the Hold variable in the 2nd bang, e.g.: