It is currently March 28th, 2024, 6:48 pm

Reducing CPU usage?

Get help with creating, editing & fixing problems with skins
User avatar
Active Colors
Moderator
Posts: 1251
Joined: February 16th, 2012, 3:32 am
Location: Berlin, Germany

Re: Reducing CPU usage?

Post by Active Colors »

balala wrote: March 1st, 2023, 1:57 pm Not a viable option, because the images are cover arts, as get by a NowPlaying measure. So those images are different sized and additionally can't even be manually edited.
I was talking about these images:
ItsJustRyan wrote: February 23rd, 2023, 8:52 pm

Code: Select all

[VinylRotate]
Meter=Rotator
ImageName=vinyl_bg_edit5MidLarger.png
W=450
H=450

[CoverRotate]
Meter=Image
MaskImageName=vinyl_mask_small_full.png
W=186
H=186
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Reducing CPU usage?

Post by balala »

Active Colors wrote: March 2nd, 2023, 8:51 pm I was talking about these images:
Sorry, my bad, it seems...
ItsJustRyan
Posts: 81
Joined: October 25th, 2019, 1:20 am

Re: Reducing CPU usage?

Post by ItsJustRyan »

Hi!

Update: Have been trying to do the two rotator meters thing, but an issue with having the album cover be a rotator meter is the varying image sizes and inability to scale them (to my knowledge). Any ideas?
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Reducing CPU usage?

Post by balala »

ItsJustRyan wrote: March 7th, 2023, 5:23 pm Update: Have been trying to do the two rotator meters thing, but an issue with having the album cover be a rotator meter is the varying image sizes and inability to scale them (to my knowledge). Any ideas?
The only way you can resize a Rotator meter is the TransformationMatrix. But using this, the CPU usage will be kept to the same high level as previously. No other better solution, or at least I don't see one. Sorry.
If you want to give it a try, post please the last code you have (assuming you've worked with it in meantime).
ItsJustRyan
Posts: 81
Joined: October 25th, 2019, 1:20 am

Re: Reducing CPU usage?

Post by ItsJustRyan »

This is my current version with the rotator and image meter. it only eats up 45% - 96% of my CPU when running :rolmfao:
It's also merged with a couple other things but I cut them out of the code, just stuff like a clock and buttons for opening other skins. I tried to reduce usage by doubling update time and tweaking the angle change per update so it wouldn't look jittery, but then it becomes a tradeoff between it looking jittery or barely moving at all.

I'd attach an image of what it looks like but it uses a link so I'm not sure how :/

Slightly irrelevant question, the CPU measure and the actual usage in task manager seem different for some reason. No idea why.

Code: Select all

[Rainmeter]
Update=20
;40

[Variables]
RotX=405
;450
RotY=375
;420
RotW=290
;200
RotH=290
;200

[GetMusicPlayerStatus]
Measure=Plugin
Plugin=NowPlaying
PlayerName=AIMP
PlayerType=STATUS
UpdateDivider=25

[GetMusicPlayerState]
Measure=Plugin
Plugin=NowPlaying
PlayerName=AIMP
PlayerType=STATE
UpdateDivider=10

[GetSongCover]
Measure=Plugin
Plugin=NowPlaying
PlayerName=[GetMusicPlayerState]
PlayerType=Cover
UpdateDivider=25

[MeasureRotate]
Measure=Calc
Formula=(GetMusicPlayerState = 1 ? (MeasureRotate % 360) + 0.2 : MeasureRotate)
MaxValue=360

[MeasureSinAngle]
Measure=Calc
Formula=SIN(MeasureRotate/360*2*PI)

[MeasureNegSinAngle]
Measure=Calc
Formula=-(MeasureSinAngle)

[MeasureCosAngle]
Measure=Calc
Formula=COS(MeasureRotate/360*2*PI)

[MeasureTXCover]
Measure=Calc
Formula=(#RotY#+(0.5*#RotH#))-MeasureCosAngle*(#RotY#+(0.5*#RotH#))-MeasureSinAngle*(#RotX#+(0.5*#RotW#))

[MeasureTYCover]
Measure=Calc
Formula=(#RotX#+(0.5*#RotW#))-MeasureNegSinAngle*(#RotY#+(0.5*#RotH#))-MeasureCosAngle*(#RotX#+(0.5*#RotW#))

[MeasureSongName]
Measure=NowPlaying
PlayerName=AIMP
PlayerType=Title
UpdateDivider=10

[MeasureSongArtist]
Measure=NowPlaying
PlayerName=AIMP
PlayerType=Artist
UpdateDivider=10

[MeasureProgress]
Measure=Plugin
Plugin=NowPlaying
PlayerName=AIMP
PlayerType=PROGRESS
UpdateDivider=6

[MeasurePosition]
Measure=Plugin
Plugin=NowPlaying
PlayerName=AIMP
PlayerType=POSITION
UpdateDivider=6

[MeasureDuration]
Measure=Plugin
Plugin=NowPlaying
PlayerName=AIMP
PlayerType=DURATION
UpdateDivider=25

[mVolume]
Measure=Plugin
Plugin=NowPlaying.dll
PlayerName=AIMP
PlayerType=Volume
UpdateDivider=10

[MeasureMinutesTotal]
Measure=Calc
Formula=Trunc(MeasureDuration/60)
RegExpSubstitute=1
Substitute="^(.)$":"0\1"

[MeasureSecondsTotal]
Measure=Calc
Formula=(MeasureDuration % 60)
RegExpSubstitute=1
Substitute="^(.)$":"0\1"

[ProgressSec]
Measure=Calc
Formula=(550/(MeasureSecondsTotal + MeasureMinutesTotal*60))

[Background]
Meter=Image
ImageName=#@#Wood.png
W=1920

[MeterTrack]
Meter=String
MeasureName=MeasureSongName
X=(1920)
Y=(1080-35)
FontFace=Montserrat SemiBold
FontSize=54.72
AntiAlias=1
StringAlign=RightCenter
Text=%1
FontColor=255,255,255
W=1670

[MeterArtist]
Meter=String
MeasureName=MeasureSongArtist
X=(1920)
Y=(1080-85)
FontFace=Montserrat Light
FontSize=(30.4)
AntiAlias=1
StringAlign=RightCenter
Text=%1
FontColor=255,255,255

[MeterSongLength]
Meter=String
MeasureName=MeasurePosition
MeasureName2=MeasureDuration
X=(#WorkAreaWidth#-251)
Y=(1080-160-4+23)
FontFace=Montserrat Light
FontSize=(22.8)
AntiAlias=1
StringAlign=Left
Text=%1/%2
FontColor=255,255,255

[CoverRotate]
Meter=Image
MeasureName=GetSongCover
X=#RotX#
Y=#RotY#
W=#RotW#
H=#RotH#
TransformationMatrix=[MeasureCosAngle]; [MeasureSinAngle]; [MeasureNegSinAngle]; [MeasureCosAngle]; [MeasureTYCover]; [MeasureTXCover]
AntiAlias=1
DynamicVariables=1

[VinylRotate]
Meter=Rotator
MeasureName=MeasureRotate
ImageName=Vinyl_Yellowedit1000.png
x=50
y=20
OffsetX=500
OffsetY=500
W=1000
H=1000
AntiAlias=1
LeftMouseUpAction=[!CommandMeasure GetMusicPlayerState "PlayPause"]
RightMouseUpAction=["C:\Program Files (x86)\AIMP\AIMP.exe"]
MouseScrollUpAction=[!CommandMeasure "MeasureProgress" "SetPosition +[ProgressSec]"]	
MouseScrollDownAction=[!CommandMeasure "MeasureProgress" "SetPosition -[ProgressSec]"]

[MeterRoundProgBar]
Meter=Roundline
MeasureName=MeasureProgress
DynamicVariables=1
Solid=1
AntiAlias=1
StartAngle=-1.5708
RotationAngle=(6.28*1)
X=(#RotX#+(#RotW#/2))
Y=(#RotY#+(#RotH#/2))
LineLength=430
LineStart=426
LineColor=255,255,255
MouseScrollUpAction=[!CommandMeasure "MeasureProgress" "SetPosition +[ProgressSec]"]	
MouseScrollDownAction=[!CommandMeasure "MeasureProgress" "SetPosition -[ProgressSec]"]

[AIMPVol]
Meter=Roundline
MeasureName=mVolume
Solid=1
AntiAlias=1
StartAngle=0
RotationAngle=(6.28*1)
X=5
Y=(6)
W=(2*40)
H=(2*40)
LineLength=(40*0.91)
LineStart=(40*0.55*1.14)
LineColor=255,255,255
RightMouseUpAction=[!CommandMeasure GetMusicPlayerState "TogglePlayer"]
MiddleMouseUpAction=[!CommandMeasure GetMusicPlayerState "TogglePlayer"]
MouseScrollUpAction=[!CommandMeasure GetMusicPlayerState "SetVolume +5"]	
MouseScrollDownAction=[!CommandMeasure GetMusicPlayerState "SetVolume -5"]

[CirclesAIMPVol]
Meter=Shape
Shape=Ellipse (45),(46),36 | Fill Color 255,255,255,0 | Stroke Color 255,255,255 | StrokeWidth 2
Shape2=Ellipse 45,(46),25 | Fill Color 255,255,255,0 | Stroke Color 255,255,255 | StrokeWidth 2

[subTextAIMP]
Meter=STRING
MeasureName=mVolume
Text=%1
AntiAlias=1
StringAlign=CenterCenter
FontFace=Montserrat SemiBold
FontSize=20
FontWeight=700
FontColor=255,255,255
X=45
Y=48

[Arm]
Meter=Image
ImageName=arm.png
PreserveAspectRatio=1
w=276
x=700
y=100
ItsJustRyan
Posts: 81
Joined: October 25th, 2019, 1:20 am

Re: Reducing CPU usage?

Post by ItsJustRyan »

Made a slightly less intense one that USUALLY doesnt surpass 80% by making update=40 and making the angle step 0.15. A balance between somewhat jittery if you look at it and actually still noticeably spinning. Also added to the last post, are my updatedividers values appropriate?

Code: Select all

[MeasureRotate]
Measure=Calc
Formula=(GetMusicPlayerState = 1 ? (MeasureRotate % 360) + 0.15 : MeasureRotate)
MaxValue=360
ItsJustRyan
Posts: 81
Joined: October 25th, 2019, 1:20 am

Re: Reducing CPU usage?

Post by ItsJustRyan »

Just made an insane discovery: Hardware acceleration. Offload the spinning stuff and other graphics to the GPU, and bam never surpass 3% CPU and rarely 4% GPU. Still some of my previous questions still stand :)
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Reducing CPU usage?

Post by balala »

ItsJustRyan wrote: March 8th, 2023, 4:55 pm Just made an insane discovery: Hardware acceleration. Offload the spinning stuff and other graphics to the GPU, and bam never surpass 3% CPU and rarely 4% GPU.
Good point!
ItsJustRyan wrote: March 8th, 2023, 4:55 pm Still some of my previous questions still stand :)
Which questions stand? If the one related to the UpdateDividers, here is a workaround: I rewrote a few things in the last posted code, see below the result. Note that:
  • I added a DefaultUpdateDivider=50 option beside Update=20 in the [Rainmeter] section. With this, you get all measures and meters updated once per second, unless there is something else explicitly written on the measure or meter.
  • I added an UpdateDivider=1 option to all measures and meter which need this ([GetMusicPlayerStatus], [MeasureProgress], [MeasurePosition], [MeasureRotate], [MeasureSinAngle], [MeasureNegSinAngle], [MeasureCosAngle], [MeasureTXCover], [MeasureTYCover], [MeterSongLength], [CoverRotate], [VinylRotate] and [MeterRoundProgBar]). This option ensures a proper update of those sections, while all ones not having this option, are updated once per second (due to the Update x DefaultUpdateDivider value).
  • There were more NowPlaying measures, which had not proper structure: some have been written into the proper parent - child strucure, while many others were parent measures (more of them). Now there is one single parent measure ([GetMusicPlayerStatus], which has the PlayerName=AIMP option) and all others are child measures (these have a PlayerName=[GetMusicPlayerStatus], related to the parent measure).
  • Even if a while ago, NowPlaying has been a plugin, in meantime it has been converted to an internal measure. The below code follows this: all NowPlaying plugin measures have been rewritten as NowPlaying measures (by replacing the Measure=Plugin and Plugin=NowPlaying or Plugin=NowPlaying.dll option pairs by Measure=NowPlaying).
  • I made a few other minor updates of the code. For instance I removed some parenthesis from options which didn't really need it, or rewrote the RotationAngle=(6.28*1) option of the [MeterRoundProgBar] and [AIMPVol] meters as RotationAngle=(2*PI). And so on...
So, try please the bellow code and let me know if it helped at least a little bit:

Code: Select all

[Rainmeter]
Update=20
DefaultUpdateDivider=50
;40

[Variables]
RotX=405
;450
RotY=375
;420
RotW=290
;200
RotH=290
;200

[GetMusicPlayerStatus]
Measure=NowPlaying
PlayerName=AIMP
PlayerType=STATUS
UpdateDivider=1

[GetMusicPlayerState]
Measure=NowPlaying
PlayerName=[GetMusicPlayerStatus]
PlayerType=STATE

[GetSongCover]
Measure=NowPlaying
PlayerName=[GetMusicPlayerStatus]
PlayerType=Cover

[MeasureSongName]
Measure=NowPlaying
PlayerName=[GetMusicPlayerStatus]
PlayerType=Title

[MeasureSongArtist]
Measure=NowPlaying
PlayerName=[GetMusicPlayerStatus]
PlayerType=Artist

[MeasureProgress]
Measure=NowPlaying
PlayerName=[GetMusicPlayerStatus]
PlayerType=PROGRESS
UpdateDivider=1

[MeasurePosition]
Measure=NowPlaying
PlayerName=[GetMusicPlayerStatus]
PlayerType=POSITION
UpdateDivider=1

[MeasureDuration]
Measure=NowPlaying
PlayerName=[GetMusicPlayerStatus]
PlayerType=DURATION

[mVolume]
Measure=NowPlaying
PlayerName=[GetMusicPlayerStatus]
PlayerType=Volume

[MeasureRotate]
Measure=Calc
Formula=(( GetMusicPlayerState = 1 ) ? (( MeasureRotate % 360 ) + 0.2 ) : MeasureRotate )
MaxValue=360
UpdateDivider=1

[MeasureSinAngle]
Measure=Calc
Formula=SIN(MeasureRotate/360*2*PI)
UpdateDivider=1

[MeasureNegSinAngle]
Measure=Calc
Formula=-(MeasureSinAngle)
UpdateDivider=1

[MeasureCosAngle]
Measure=Calc
Formula=COS(MeasureRotate/360*2*PI)
UpdateDivider=1

[MeasureTXCover]
Measure=Calc
Formula=(#RotY#+(0.5*#RotH#))-MeasureCosAngle*(#RotY#+(0.5*#RotH#))-MeasureSinAngle*(#RotX#+(0.5*#RotW#))
UpdateDivider=1

[MeasureTYCover]
Measure=Calc
Formula=(#RotX#+(0.5*#RotW#))-MeasureNegSinAngle*(#RotY#+(0.5*#RotH#))-MeasureCosAngle*(#RotX#+(0.5*#RotW#))
UpdateDivider=1

[MeasureMinutesTotal]
Measure=Calc
Formula=Trunc(MeasureDuration/60)
RegExpSubstitute=1
Substitute="^(.)$":"0\1"

[MeasureSecondsTotal]
Measure=Calc
Formula=(MeasureDuration % 60)
RegExpSubstitute=1
Substitute="^(.)$":"0\1"

[ProgressSec]
Measure=Calc
Formula=( 550 / ( MeasureSecondsTotal + MeasureMinutesTotal * 60 ))

[Background]
Meter=Image
ImageName=#@#Wood.png
W=1920

[MeterTrack]
Meter=String
MeasureName=MeasureSongName
X=1920
Y=(1080-35)
W=1670
FontFace=Montserrat SemiBold
FontSize=54.72
AntiAlias=1
StringAlign=RightCenter
Text=%1
FontColor=255,255,255

[MeterArtist]
Meter=String
MeasureName=MeasureSongArtist
X=1920
Y=(1080-85)
FontFace=Montserrat Light
FontSize=30
AntiAlias=1
StringAlign=RightCenter
Text=%1
FontColor=255,255,255

[MeterSongLength]
Meter=String
MeasureName=MeasurePosition
MeasureName2=MeasureDuration
X=(#WorkAreaWidth#-251)
Y=(1080-160-4+23)
FontFace=Montserrat Light
FontSize=(22.8)
AntiAlias=1
StringAlign=Left
Text=%1/%2
FontColor=255,255,255
UpdateDivider=1
SolidColor=255,0,0

[CoverRotate]
Meter=Image
MeasureName=GetSongCover
X=#RotX#
Y=#RotY#
W=#RotW#
H=#RotH#
TransformationMatrix=[MeasureCosAngle];[MeasureSinAngle];[MeasureNegSinAngle];[MeasureCosAngle];[MeasureTYCover];[MeasureTXCover]
UpdateDivider=1
AntiAlias=1
DynamicVariables=1

[VinylRotate]
Meter=Rotator
MeasureName=MeasureRotate
ImageName=Vinyl_Yellowedit1000.png
x=50
y=20
OffsetX=500
OffsetY=500
W=1000
H=1000
AntiAlias=1
LeftMouseUpAction=[!CommandMeasure GetMusicPlayerState "PlayPause"]
RightMouseUpAction=["C:\Program Files (x86)\AIMP\AIMP.exe"]
MouseScrollUpAction=[!CommandMeasure "MeasureProgress" "SetPosition +[ProgressSec]"]	
MouseScrollDownAction=[!CommandMeasure "MeasureProgress" "SetPosition -[ProgressSec]"]
UpdateDivider=1

[MeterRoundProgBar]
Meter=Roundline
MeasureName=MeasureProgress
DynamicVariables=1
Solid=1
AntiAlias=1
StartAngle=-1.5708
RotationAngle=(2*PI)
X=(#RotX#+(#RotW#/2))
Y=(#RotY#+(#RotH#/2))
LineLength=430
LineStart=426
LineColor=255,255,255
MouseScrollUpAction=[!CommandMeasure "MeasureProgress" "SetPosition +[ProgressSec]"]	
MouseScrollDownAction=[!CommandMeasure "MeasureProgress" "SetPosition -[ProgressSec]"]
UpdateDivider=1

[AIMPVol]
Meter=Roundline
MeasureName=mVolume
Solid=1
AntiAlias=1
StartAngle=0
RotationAngle=(2*PI)
X=5
Y=6
W=(2*40)
H=(2*40)
LineLength=(40*0.91)
LineStart=(40*0.55*1.14)
LineColor=255,255,255
RightMouseUpAction=[!CommandMeasure GetMusicPlayerState "TogglePlayer"]
MiddleMouseUpAction=[!CommandMeasure GetMusicPlayerState "TogglePlayer"]
MouseScrollUpAction=[!CommandMeasure GetMusicPlayerState "SetVolume +5"]	
MouseScrollDownAction=[!CommandMeasure GetMusicPlayerState "SetVolume -5"]

[CirclesAIMPVol]
Meter=Shape
Shape=Ellipse 45,46,36 | Fill Color 255,255,255,0 | Stroke Color 255,255,255 | StrokeWidth 2
Shape2=Ellipse 45,46,25 | Fill Color 255,255,255,0 | Stroke Color 255,255,255 | StrokeWidth 2

[subTextAIMP]
Meter=STRING
MeasureName=mVolume
Text=%1
AntiAlias=1
StringAlign=CenterCenter
FontFace=Montserrat SemiBold
FontSize=20
FontWeight=700
FontColor=255,255,255
X=45
Y=48

[Arm]
Meter=Image
ImageName=arm.png
PreserveAspectRatio=1
w=276
x=700
y=100
And one more recommendation: in last time, all resources used by a skin (images, fonts, sound files and so on) are required to be placed into the @Resources folder. For example, the arm.png image, used by the [Arm] meter should be rely on this @Resources folder, not in the same folder as the skins .ini file. If you move them there, replace their reference by adding the #@# variable. You did this for some of the used resources (namely the Wood.png image, used into the [Background] meter), but others are still not there (for instance the above arm.png image). Not that you couldn't use the skin with those resources not in the @Resources folder, but that's a better place for them.
ItsJustRyan
Posts: 81
Joined: October 25th, 2019, 1:20 am

Re: Reducing CPU usage?

Post by ItsJustRyan »

Cheers! Will work on fixing those, because I made some fairly substantial changes to some things on my end already.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Reducing CPU usage?

Post by balala »

ItsJustRyan wrote: March 8th, 2023, 11:35 pm Cheers! Will work on fixing those, because I made some fairly substantial changes to some things on my end already.
Alright. Please let us know if you got it working better.