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)
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
...