How to draw beat markers

Has anyone found a nice way of drawing beat markers? I’m about to start trying to implement this and was curious if anyone has any tips or could share their approach. Mainly curious about the best way to calculate beat positions or if the engine has a quick way of getting beat times (currently I am using the snap methods in the tempo sequence to get the nearest beat for a time)

The edit.tempoSequence has some useful functions; tempoSequence.timeToBeats(), tempoSequence.beatsToTime(), tempoSequence.timeToBarsBeats(), which you can use to derive the beat markers for the currently displayed view of your edit.

That should get you started.

1 Like

Thanks I’ll take a look at those methods

Here is an example from Waveform:

        for (TimecodeDisplayIterator iter (this->editView.edit, this->xToTime (-maxTextWidth - 1), this->editView.getCurrentMinimumSnapType (true));;)
        {
            const double t = iter.next();
            const int x = this->timeToX (t);
            const int depth = iter.getCurrentResolutionLevel() - iter.getMinimumResolutionLevel();

            if (depth < 8)
            {
                for (int i = 0; i <= depth; ++i)
                {
                    if (lastX[i] > 0)
                        minWidths[i] = jmin (x - lastX[i], minWidths[i]);

                    lastX[i] = x;
                }
            }

            if (x < clipBounds.getRight())
            {
                const float tickLength = (float) jmin (maxTickLen, depth * 2 + 5);
                gridLines.add (Rectangle<float> (x - 0.5f, this->getHeight() - tickLength, 1.0f, tickLength), (float) depth);
            }
            else if (x > clipBounds.getRight() + 200)
            {
                break;
            }
        }

thanks!

Thanks for your help everyone! I got it working pretty good.