Skip to content

Conversation

@jsundqvist
Copy link

@x42
Copy link
Member

x42 commented Mar 10, 2025

Nice find!

now makes me wonder if end_sample < start_sample is actually an issue further up and should not happen in the first place.

@jsundqvist
Copy link
Author

jsundqvist commented Mar 11, 2025

@x42 here's another one https://github.com/Ardour/ardour/pull/967/files

EDIT: never mind. that one doesn't work with hardware, probably due to _mclk_out_latency.

@x42
Copy link
Member

x42 commented Mar 24, 2025

So it this pull-request ready to go?

I lent my only hardware device that can be sync'ed to MIDI Clock, so I cannot test myself.

@jsundqvist
Copy link
Author

No, it's accumulating a tiny bit of lag in the loop and getting out of sync, I'll convert to draft.

Other related issues:

  • Notes are cut short at the start of the loop (maybe NoteOffs from the previous lap, unrelated to MIDI clock)
  • Playback Start/Continue delayed by one beat (probably _mclk_out_latency + midi_clock_beat_at_or_after, unrelated to loops)
  • Position not reset when Stopping and Continuing.

Let's see if I can make separate changes or if they need to be here. I'm running a Roland TD-27 drum module where MIDI clock is driving the modules built-in Click track, so pretty handy testbed.

@jsundqvist jsundqvist marked this pull request as draft March 25, 2025 10:29
cldmnky added a commit to cldmnky/ardour that referenced this pull request Nov 10, 2025
This comprehensive fix addresses multiple issues with MIDI clock sync when
looping, as reported in https://tracker.ardour.org/view.php?id=9897 and
discussed in PR Ardour#966.

Issues fixed:

1. Stop/Continue events during loop wrap:
   - The discontinuity detection now recognizes loop wraps as expected
     transitions rather than real discontinuities
   - Prevents erroneous MIDI Stop events when the loop restarts
   - Uses reset() for real discontinuities to properly clear all state

2. Lag accumulation:
   - Fixed speed calculation during loop wrap to account for the actual
     distance traveled through the loop boundary
   - Improved _next_tick wrapping to prevent drift accumulation
   - Properly manages _transport_pos during loop transitions

3. Clock tick generation during wrap:
   - Generates ticks correctly in both the pre-wrap and post-wrap portions
   - Calculates proper buffer offsets for wrapped ticks
   - Handles tempo changes across loop boundaries

4. Transport position tracking:
   - _transport_pos is now correctly maintained during loop wraps
   - Prevents false discontinuity detection on subsequent cycles

The fix ensures smooth MIDI clock sync through loop boundaries without
sending spurious Stop/Continue messages that cause external devices
to skip beats and lose synchronization.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants