Drawing a moving playhead -> 100% CPU lol

So I created a separate component with an invisible background that is overlaid on top of my editing window that simply draws a yellow vertical line. The processing block of my project uses the AudioPlayHead::CurrentPositionInfo to get the position info from the host and my yellow vertical line is being drawn at 30fps using a timer callback.

I’ve searched the forums and I believe the redraw() is triggering a redraw of the parent class and possibly the entire project which is draining the CPU. Is there a way to redraw a component class without redrawing everything?? I thought that’s what I was doing…

repaint() is only repainting the parent component, if it is set to non opaque (which makes sense, since you need to paint the component behind first). At least that is how it is supposed to be.

First thing to rule out would be to call setOpaque (true); on your component.

Also using a component as playhead indicator proved to be worthwhile, just leave a little margin around to allow rounding errors (bounds are ints). In this case, make sure, that the component behind is opaque. Setting new bounds to the playhead component takes care of only painting the right area of the component behind.
It still executes the whole paint() method, but skips all paint in the backend, that would paint outside the invalidated area.

2 Likes

That interesting, we’ve had all kinds of problems with playheads trying to do minimal repaints of the previous and new areas. Problem is that the playhead sometimes moves between the call to repaint and the paint method actually getting called, resulting in a logic problem that so far has bamboozled several otherwise good programmers :wink:

1 Like

Why not add the playhead to the desktop (in a separate window). All modern OSes double buffer the window content and using the GPU for composing. (I guess Logic Pro is doing the same, you can see that the playhead appears before the arranging window)

So you can have super smooth scrolling (in theory)

3 Likes

So I think you’re onto something. This made a huge difference to CPU usage to make it opaque but now I can’t see my app behind it. It turned into a giant window and now I just see my host behind it. Which is cool but my app is gone lol.

I’m not sure I understand what you mean. I’m trying to draw the scrolling vertical line so it needs to be on top of my app, not in a separate window, no?