# AudioThumbnail::drawChannels() question

**URL:** <https://forum.juce.com/t/audiothumbnail-drawchannels-question/12485>\
**Category:** General JUCE discussion\
**Created:** [March 4, 2014, 5:46pm UTC](https://forum.juce.com/t/audiothumbnail-drawchannels-question/12485 "2014-03-04T17:46:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rory](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rory/32/534_2.png) [@rory](https://forum.juce.com/u/rory)\
**Post date:** [March 4, 2014, 5:46pm UTC](https://forum.juce.com/t/audiothumbnail-drawchannels-question/12485/1 "2014-03-04T17:46:26Z")

</div>

I'm trying to draw a vertical line denoting play position(scrubber?) on top of my waveform but the constant calls to drawChannels() are cranking up my CPU.&nbsp;

```
        if (thumbnail->getTotalLength() > 0){
                    thumbnail->drawChannels (g, getLocalBounds(), startTime, endTime, 2.0f);
            }
        if(regionWidth>1){
                g.setColour(colour.contrasting(.5f).withAlpha(.7f));
                g.fillRect(timeToX(currentPlayPosition), 0.f, regionWidth, (float)getHeight());    
             }
        if(scrubberPosition>0){
                g.setColour(colour.contrasting(.8f));
                g.drawVerticalLine(timeToX(scrubberPosition), 0.f, getHeight());        
             }
        }
```

I also tried grabbing the waveform image first, and then calling Graphics::drawImage() in my paint routines but didn't help much at all. I could create a simple scrubber component and move it around on top of my waveform, but the underlying component Paint()'s method would still be called or?

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [March 4, 2014, 6:09pm UTC](https://forum.juce.com/t/audiothumbnail-drawchannels-question/12485/2 "2014-03-04T18:09:32Z")

</div>

Almost certainly better to make your playhead a separate component and then set its bounds based on the playback time.

drawChannels shouldn't be too intensive as long as the zoom level is sufficient that it doesn't have to re-read from the source file and you are only repainting the area that needs to i.e. don't call repaint() which will re-draw the whole waveform.

If you use a separate component for the playhead only the area it covers will be repainted which is likely to only be a few pixels. Use JUCE\_ENABLE\_DEBUG\_REPAINTING to be sure.

---

<div class="post-metadata">

**Author:** ![rory](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rory/32/534_2.png) [@rory](https://forum.juce.com/u/rory)\
**Post date:** [March 4, 2014, 6:50pm UTC](https://forum.juce.com/t/audiothumbnail-drawchannels-question/12485/3 "2014-03-04T18:50:15Z")

</div>

Thanks Dave, that works a lot better, and I no longer constantly redraw the waveform. That was just silly on my part. One thing though, when you say only repaint() the areas I need to? How does I go about that? Pardon my ignorance. You can see the problem here:

![](http://www.juce.com/sites/default/files/forum/attachments/Screenshot%20-%2003042014%20-%2006%3A45%3A01%20PM.png)

The scrubber jumps a few samples each time, I know I should redraw whatever was under the scrubber and not the entire waveform. Any pointers as to how I go about that? Thanks again for the prompt reply.&nbsp;

---

<div class="post-metadata">

**Author:** ![rory](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rory/32/534_2.png) [@rory](https://forum.juce.com/u/rory)\
**Post date:** [March 4, 2014, 6:53pm UTC](https://forum.juce.com/t/audiothumbnail-drawchannels-question/12485/4 "2014-03-04T18:53:50Z")

</div>

Component::repaint (int x, int y, int width, int height), Ok, let me try it out..

---

<div class="post-metadata">

**Author:** ![rory](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rory/32/534_2.png) [@rory](https://forum.juce.com/u/rory)\
**Post date:** [March 4, 2014, 6:59pm UTC](https://forum.juce.com/t/audiothumbnail-drawchannels-question/12485/5 "2014-03-04T18:59:00Z")

</div>

Perfect. Thanks Dave.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 4, 2014, 8:32pm UTC](https://forum.juce.com/t/audiothumbnail-drawchannels-question/12485/6 "2014-03-04T20:32:45Z")

</div>

If you actually follow Dave's advice and use a component for the playhead, then you don't need to worry about repainting anything manually, you&nbsp;just move the component and it'll all work.

---

<div class="post-metadata">

**Author:** ![rory](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rory/32/534_2.png) [@rory](https://forum.juce.com/u/rory)\
**Post date:** [March 4, 2014, 9:35pm UTC](https://forum.juce.com/t/audiothumbnail-drawchannels-question/12485/7 "2014-03-04T21:35:13Z")

</div>

That's true. At present everything is housed in the one parent, so calling paint() on it, calls paint on its children. For now I'm happy to continue as is. Still can't believe I hadn't come across the paint only-part-of method before!

---

<div class="post-metadata">

**Author:** ![rory](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rory/32/534_2.png) [@rory](https://forum.juce.com/u/rory)\
**Post date:** [March 4, 2014, 9:59pm UTC](https://forum.juce.com/t/audiothumbnail-drawchannels-question/12485/8 "2014-03-04T21:59:13Z")

</div>

And following your demo now, it all makes sense!
