Bug: The metronome clicks native beats instead of time-signature divisions (wrong in `isAlwaysACrotchet` mode)

  • Type: Bug
  • TE version: pinned commit 38d5a27 (develop, 2026-10-14). The relevant code is unchanged on current develop (checked 2026-12-04, head a0d03c5).
  • Affected code: modules/tracktion_engine/playback/graph/tracktion_ClickNode.cpp: getBeatInfo() (anonymous namespace) and both click loops (MIDI and audio) in ClickGenerator::processBlock()

Problem

ClickGenerator finds the next click by flooring the native beat position and adding one native beat per click:

const auto beats = tempoPosition.getBeats().inBeats();
int beat = static_cast<int> (std::floor (beats));
const auto beatTime = sequence.toTime (BeatPosition::fromBeats (beat));
const bool isFirstBeatOfBar = tempoPosition.getBarsBeats().getWholeBeats() == 0;
...
tempoPosition.add (1_bd);
beatInfo = getBeatInfo (sequence, tempoPosition);

With LengthOfOneBeat::dependsOnTimeSignature, a native beat is one denominator division, so this works. With isAlwaysACrotchet, a native beat is always a quarter note. In 7/8 the click then sounds every quarter instead of every eighth, which is 3.5 clicks per real bar. The accent comes from a bar position that does not line up with the clicks. In 3/2 the click sounds every quarter instead of every half note.

This fix depends on correct BarsAndBeats↔time conversion in crotchet mode. See our separate post on tracktion_Tempo.h.

How to reproduce

This has not been tested as a standalone snippet. In our app we compare rendered metronome audio in both modes.

  1. Create an Edit with an EngineBehaviour whose lengthOfOneBeatDependsOnTimeSignature() returns false. This selects isAlwaysACrotchet.
  2. Set a 7/8 time signature at 120 BPM.
  3. Enable the click track, play, and render about 4 s.
  4. Look at the click onsets. We expect onsets every 0.25 s, with an accent every 1.75 s. Instead the onsets come every 0.5 s. On unmodified TE the accent comes every 3.5 s, because of the bar-length bug from the other post. With only the tempo fix applied, the accent lands on every second bar.

The same Edit in dependsOnTimeSignature mode clicks correctly. With the fix, the two renders should be identical sample for sample.

Proposed patch

This patch requires the tracktion_Tempo.h fix, so that BarsAndBeats counts denominator divisions in both modes.

--- a/modules/tracktion_engine/playback/graph/tracktion_ClickNode.cpp
+++ b/modules/tracktion_engine/playback/graph/tracktion_ClickNode.cpp
@@ namespace
+    inline tempo::BarsAndBeats getClickDivision (const tempo::Sequence::Position& position)
+    {
+        auto barsBeats = position.getBarsBeats();
+        // Round-trip arithmetic can put an exact division infinitesimally
+        // before its boundary. Snap only within 1e-9 divisions (well below
+        // one audio sample), so advancing cannot revisit the same click.
+        auto division = std::floor (barsBeats.beats.inBeats() + 1.0e-9);
+        if (division >= barsBeats.numerator)
+        {
+            ++barsBeats.bars;
+            division = 0.0;
+        }
+        barsBeats.beats = BeatDuration::fromBeats (division);
+        return barsBeats;
+    }
+
     inline BeatInfo getBeatInfo (const tempo::Sequence& sequence, tempo::Sequence::Position& tempoPosition)
     {
-        const auto beats = tempoPosition.getBeats().inBeats();
-        int beat = static_cast<int> (std::floor (beats));
-        const auto beatTime = sequence.toTime (BeatPosition::fromBeats (beat));
-        const bool isFirstBeatOfBar = tempoPosition.getBarsBeats().getWholeBeats() == 0;
+        const auto barsBeats = getClickDivision (tempoPosition);
+        const auto beatTime = sequence.toTime (barsBeats);
+        const bool isFirstBeatOfBar = barsBeats.getWholeBeats() == 0;
@@ ClickGenerator::processBlock (both the MIDI and the audio loop)
-            tempoPosition.add (1_bd);
-            beatInfo = getBeatInfo (sequence, tempoPosition);
+            auto barsBeats = getClickDivision (tempoPosition);
+            barsBeats.beats = barsBeats.beats + 1_bd;
+            tempoPosition.set (barsBeats);
+            beatInfo = getBeatInfo (sequence, tempoPosition);

How the patch works

  • Clicks are placed on whole time-signature divisions in bar/beat space, not on whole native beats. This makes the click independent of the beat-length mode. It uses the same BarsAndBeats↔time mapping as bar launch quantisation, so click and launch boundaries cannot drift apart.
  • The accent comes from the same quantised division, so it always matches the click that sounds.
  • A snap of 1e-9 divisions absorbs floating-point round-trip error, so a click exactly on a boundary is neither skipped nor played twice.
  • Everything runs on the audio thread, with no allocation and no new state.
  • In dependsOnTimeSignature mode the only change is how the next click is found: via toTime(BarsAndBeats) instead of toTime(BeatPosition). These match for whole divisions, since bar starts are rounded to whole beats in that mode.

Possible alternative: keep the current loop, but advance by the division length in native beats instead of 1_bd. That value is the nativeBeatsPerDivision field from the tempo patch.

Tests on our side

  • Rendered metronome audio at 120 and 137 BPM through 7/8 → 3/2 is compared sample for sample between both modes. It is also checked against an independently computed list of onset frames.
  • A one-bar timeline loop keeps its downbeat click across split audio blocks.