From b5d7754a26dab0bc49f0bc710c298ad41f1bba0a Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 24 Oct 2022 06:14:26 +0200 Subject: [PATCH] Fix MIDI Clock generator MIDI clock start at the next beat (round_up_to_beat), so here we have to round the current tick, rather than fall back to a tick that is not yet complete, as 14da117bc88 does. Reproduced with the Session from #9027 Start loop at bar 40 with MClk generator enabled. ``` #3 in __GI___assert_fail (assertion=0x7fedd86c4fd5 "clk_pos >= pos", file=0x7fedd86c38b7 "../libs/temporal/tempo.cc", line=3336, function=0x7fedd86c4f60 "void Temporal::TempoMap::midi_clock_beat_at_or_after(Temporal::samplepos_t, Temporal::samplepos_t&, uint32_t&) const") at assert.c:101 #4 in Temporal::TempoMap::midi_clock_beat_at_or_after(long, long&, unsigned int&) const (this= 0x560187e92c00, pos=20691033, clk_pos=@0x7fedc02178b8: 20691032, clk_beat=@0x7fedc02178c4: 11472) at ../libs/temporal/tempo.cc:3336 #5 in ARDOUR::MidiClockTicker::tick(long, long, unsigned int, long) (this=0x56018eed6db0, start_sample=20691033, end_sample=20692057, n_samples=1024, pre_roll=0) at ../libs/ardour/ticker.cc:170 #6 in ARDOUR::Session::send_mclk_for_cycle(long, long, unsigned int, long) (this=0x56018a216340, start_sample=20691033, end_sample=20692057, n_samples=1024, pre_roll=0) at ../libs/ardour/session.cc:7495 #7 in ARDOUR::AudioEngine::process_callback(unsigned int) (this=0x5601881a4f20, nframes=1024) at ../libs/ardour/audioengine.cc:563 ``` --- libs/temporal/tempo.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libs/temporal/tempo.cc b/libs/temporal/tempo.cc index eda3ebbfd2..4771df6223 100644 --- a/libs/temporal/tempo.cc +++ b/libs/temporal/tempo.cc @@ -3330,7 +3330,13 @@ TempoMap::midi_clock_beat_at_or_after (samplepos_t const pos, samplepos_t& clk_p Temporal::Beats b = (quarters_at_sample (pos)).round_up_to_beat (); - clk_pos = sample_at (b); + /* We cannot use + * clk_pos = sample_at (b); + * because in this case we have to round up to the start + * of the next tick, not round to to the current tick. + * (compare to 14da117bc88) + */ + clk_pos = PBD::muldiv_round (superclock_at (b), TEMPORAL_SAMPLE_RATE, superclock_ticks_per_second ()); clk_beat = b.get_beats () * 24; assert (clk_pos >= pos);