This is actually a question I had myself. I saw this was how it was done in https://github.com/mixxxdj/mixxx/blob/7905a7e6454d77f635b97f94758f269ba0e911fb/src/widget/wwaveformviewer.cpp#L169