Display Syncronized Waveform in Strict Time


Wassup JUCE Community,
I have a question regarding to drawing syncronized waveforms by bars into my GUI. Drawing the waveform of the current signal is no problem at all. I checked some LFO plugins and they display the waveform perfectly syncronized to the bar in strict time so I was wondering if anyone has an idea of how to implement it? I already implemented a Ring Buffer which is supposed to hold one quarter note lenths of the signal. I am pretty sure I have to calculate some kind of a factor of the CurrentPositionInfo. So i tried to calculate Samples per Bar but it does not really work and my bars also get inaccurate over time.

const double bpm = info.bpm;
const double timeInSeconds = info.timeInSeconds;
const double sampleRate = processor.getSampleRate();
const int samplesPerBlock = processor.getBlockSize();
const int64 timeInSamples = info.timeInSamples;
const double bps = bpm / 60.00;
double barDouble = timeInSeconds * bps / 4.0;
double barDoubleRounded = roundf(barDouble * 100000) / 100000;
const int bar = (int) barDoubleRounded + 1; // calc with not rounded values
const int subBar = (int)(fmod(barDoubleRounded, 1.0) * 4.0 + 1.0);
double barsPerSecond = 1.0 / (bps / 4.0);
const int samplesPerBar = sampleRate / barsPerSecond;

Has anyone done something similar and can help me out?


I reckoned, that a waveform would move too fast to give useful information if scrolling in realtime. I created this plot buffer instead, it collects blocks of audio and displays a min/max outline:

Maybe that gives some inspiration…

It looks like this:


Thanks for the fast reply.

I never meant the audio to be scrolling in realtime. I was thinking about showing a static frame fitting to the bars of the DAW which updates, something like this:

Of couse it there is less rhymic information, it will look kind of weird. I like your outline buffer! In your Exampe, the ms Slider, I would like that to be calculated automatically by the DAW BPM that the current bar (4/4) always gets displayed in the window. Any ideas on how to implement it?


Nice, that looks pretty cool!

Well, I think it should be straight forward, you retrieve the BPM information from the host via AudioProcessor::getPlayHead(), and together with the sampleRate you should be able to figure out, how many samples you need to fit into your window…
Just make sure to use atomics, if you set variables in processBlock, that the drawing relies on…