Hello I found out strange thing, like in subject.
I am working on my monitor class (audio level visualisation) . And my solution is to make my monitor class inherit from Timer
. I capture audio envelope in my processor AudioProcessor
, and update the monitor in timerCallback()
, and also in timerCallback()
I call repaint()
, like that:
void MyMonitor::timerCallback()
{
// Update monitor....
repaint();
}
My callbeck interval is set by startTimer(40)
, so it repaints 25 times per second.
And I tried to optimise my drawing code in paint()
. So I started bit by bit turning off individual parts from paint()
, until I found that nothing change in CPU usage even though I remove everything from paint()
.
I created some debug button which lets me turn off everything in paint()
, like that:
void MyMonitor::paint (Graphics& g)
{
if(turnOff_DEBUG)
return;
else
// painting code
}
So I can compare in the runtime. And I found out when turnOff_DEBUG == true
my CPU usage is not less than case when turnOff_DEBUG == false
. Maybe little bit less but it’s unnoticeable.
But when I remove repaint()
from timerCallback()
then CPU usage decreases distinctly.
So it looks like my code in paint()
is not problem, but calling repaint()
causes most CPU usage. Actually “problem” is wrong word. It’s not big problem, but I just try to optimise my plugin.
So I suppose I don’t need to optimise my drawing code. But I wonder maybe I can optimise in some way usage of repaint()
. Maybe I could set my timer interval bigger, but it looks like 25 per second is at least to achieve fluid/smooth visual effect.
So I have no idea how to make it more efficient. I can’t clearly understand behaviour of paint()
, repaint()
and all those things. I found out paint()
is often called even without calling repaint()
.
Could anyone give some advice?
Forgot to mention I checked all those thing in debug compilation with project optimisation set to none. And of course when I remove repaint()
from timerCallback()
, or I set turnOff_DEBUG = true
then my monitor doesn’t work, but it’s not the case. The case is CPU usage.