It is currently April 25th, 2024, 6:51 am

Smooth NowPlaying Progress

Discuss the use of Lua in Script measures.
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Smooth NowPlaying Progress

Post by Kaelri »

I wrote this script for Muziko. It uses data from the NowPlaying plugin to simulate a smooth progression. It can be used on a bar, roundline, rotator, or any other meter that takes percentual values.

The script requires MeasurePosition, MeasureDuration, and MeasureState, which are NowPlaying measures with the corresponding PlayerType options. A usage template is provided at the bottom of this post.

The script accepts four settings:
- UpdatePeriod (ms): must match the Update setting in [Rainmeter]. Default is 1000.
- ResetInterval (s): at each interval, the simulated position is corrected to the "real" position. Default is 10 seconds.
- SafetyRange (s): if the simulated position and the real position ever differ by more than this value, the simulated position is automatically reset regardless of ResetInterval. This is used to detect abrupt track changes or scrubbing. Default is 2 seconds.
- Adjustment: with a very high Update setting, Rainmeter may lag a little behind what its true update rate (in milliseconds) is supposed to be. When this happens, the simulated progress may "skip" a little when it is automatically corrected. This option lets you adjust the speed of the simulated progress in order to compensate for lag and reduce skipping. For example, a value of "1.04" would be a 4% increase in speed. Default is 1 (no change).

Code: Select all

function Initialize()
	UpdatePeriod = SELF:GetNumberOption('UpdatePeriod', 1000)
	ResetInterval = SELF:GetNumberOption('ResetInterval', 10)
	SafetyRange = SELF:GetNumberOption('SafetyRange', 2)
	Adjustment = SELF:GetNumberOption('Adjustment', 1)

	mDuration = SKIN:GetMeasure('MeasureDuration')
	mPosition = SKIN:GetMeasure('MeasurePosition')
	mState = SKIN:GetMeasure('MeasureState')

	Counter = -1
	Fake = 0
end

function Update()
	local Total = mDuration:GetValue()
	local Real = mPosition:GetValue()
	local State = mState:GetValue() == 1 and 1 or 0
	local Stopped = mState:GetValue() == 0 and 1 or 0

	Counter = (Counter + 1) % (ResetInterval * (1000/UpdatePeriod))

	if Stopped == 1 then
		Fake = 0
	elseif Counter == 0 or math.abs(Fake-Real)>SafetyRange then
		Fake = Real
	else
		Fake = Fake + State * (UpdatePeriod/1000) * Adjustment
	end

	return Fake / Total
end

--by Kaelri (Kaelri@gmail.com)
Usage Template

Code: Select all

[Rainmeter]
Update=100

...

[MeasureSmoothProgress]
Measure=Script
ScriptFile=SmoothProgress.lua
UpdatePeriod=100
ResetInterval=10
SafetyRange=2
Adjustment=1.02

[MeasureState]
Measure=Plugin
Plugin=NowPlaying
PlayerName=iTunes
PlayerType=State

[MeasureDuration]
Measure=Plugin
Plugin=NowPlaying
PlayerName=[MeasureState]
PlayerType=Duration

[MeasurePosition]
Measure=Plugin
Plugin=NowPlaying
PlayerName=[MeasureState]
PlayerType=Position

[Rotator]
Meter=Rotator
MeasureName=MeasureSmoothProgress
...
This method is far from perfect, so I welcome any improvements or suggestions.
Lightz39
Posts: 98
Joined: August 1st, 2012, 12:48 am

Re: Smooth NowPlaying Progress

Post by Lightz39 »

I was looking for something like this. I will try it out and let you know how it goes. Thanks :welcome:

EDIT: Will this work with update divider? At 1000 there is an improvement on the smoothness but it still ticks every second instead of 2. I want it to just slowly draw not tick. Would increasing the update speed fix this? I don't want my entire skin to update that much though if at all possible.
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Smooth NowPlaying Progress

Post by Kaelri »

Lightz39 wrote:Will this work with update divider? At 1000 there is an improvement on the smoothness but it still ticks every second instead of 2. I want it to just slowly draw not tick. Would increasing the update speed fix this? I don't want my entire skin to update that much though if at all possible.
Yes, it does work with update divider. In fact, it's meant to. Set your skin's Update speed to something low, like 50 or 100, and make sure the "UpdatePeriod" option on the script measure matches that. The script measure and the meter that displays the progress both need to update at the maximum rate for the skin, but all other meters can have an UpdateDivider to relieve the pressure.
Lightz39
Posts: 98
Joined: August 1st, 2012, 12:48 am

Re: Smooth NowPlaying Progress

Post by Lightz39 »

Very good. Works like a charm. Thank you!
apit23
Posts: 43
Joined: August 17th, 2012, 9:06 am

Re: Smooth NowPlaying Progress

Post by apit23 »

hey, great work Kaelri.

hey, can the progressbar limit/length be adjusted?
I mean we can adjust the where will it start, but can we set where it will end?

and can we add knob to it? :D
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Smooth NowPlaying Progress

Post by Kaelri »

apit23 wrote:hey, great work Kaelri.

hey, can the progressbar limit/length be adjusted?
I mean we can adjust the where will it start, but can we set where it will end?

and can we add knob to it? :D
Sure. If you're using a roundline or rotator meter, just use the RotationAngle option to control the direction and limit of rotation. Using a bar, then, of course, just change the width or height of the meter.
TheFlyingFish
Posts: 10
Joined: November 11th, 2012, 7:38 am

Re: Smooth NowPlaying Progress

Post by TheFlyingFish »

Can this script (or a modification thereof) be used more generally, such as to simulate smooth progress for a meter that jumps around a lot? For instance, I want to make a speedometer-type gadget to measure my CPU clock frequency, which varies from 1100 or so MHz to 3300, but makes big jumps a lot. could I use this script to smooth the transition? That is, if the meter starts at 1100, but then jumps to 2200 on the next update, will this script give me a simulated progress from 1100 to 2200?
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Smooth NowPlaying Progress

Post by Kaelri »

TheFlyingFish wrote:Can this script (or a modification thereof) be used more generally, such as to simulate smooth progress for a meter that jumps around a lot? For instance, I want to make a speedometer-type gadget to measure my CPU clock frequency, which varies from 1100 or so MHz to 3300, but makes big jumps a lot. could I use this script to smooth the transition? That is, if the meter starts at 1100, but then jumps to 2200 on the next update, will this script give me a simulated progress from 1100 to 2200?
I'm not sure this script would be the best template for that. It assumes that the value is always moving forward, in real-time, at a constant rate - three things that you probably can't assume when you're dealing with a CPU or other measure type.

The easiest "general" way to do this is with an AverageSize option, either on the measure itself, or (if you don't want to retrieve data that often) on a separate Calc measure that updates faster than the source measure.

Here's a simple example:

Code: Select all

[Rainmeter]
Update=20

[CPU]
Measure=CPU
UpdateDivider=50

[Calc]
Measure=Calc
Formula=CPU
AverageSize=35
MaxValue=100

[Roundline]
Meter=Roundline
MeasureName=Calc
W=300
H=300
LineColor=255,255,255
LineStart=100
LineLength=150
RotationAngle=(-2*PI)
AntiAlias=1
Solid=1

[RoundlineBack]
Meter=Roundline
MeterStyle=Roundline
MeasureName=
LineColor=255,255,255,64

[String]
Meter=String
MeasureName=CPU
Postfix=%
FontFace=Segoe UI
FontColor=255,255,255
FontSize=20
SolidColor=0,0,0,1
StringAlign=CenterCenter
AntiAlias=1
X=150
Y=150
I also have a slightly more sophisticated Lua-based method using the Universal Transitions script:
Smooth Transition Test_1.0.rmskin
You do not have the required permissions to view the files attached to this post.
dv-ent
Posts: 62
Joined: November 13th, 2011, 11:43 am

Re: Smooth NowPlaying Progress

Post by dv-ent »

smooooooth script - how would i go about measuring ram with it ?
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Smooth NowPlaying Progress

Post by Kaelri »

dv-ent wrote:smooooooth script - how would i go about measuring ram with it ?
See my post above yours. ;) RAM, like CPU, does not change in a linear progression, so making it "smooth" requires a different approach.