macOS 15 SDK 2.7.2
I’m working with a MIDI file containing a 2-bar pattern that I’m aiming to play as a loop, and so after initializing a sequence with said MIDI file, I called :setLoops(0)
on it so it repeats endlessly.
The looping itself works fine but I found that the loop skips a beat when going back to the start, the same file loops fine when played in software like Logic.
I'm sharing a small sample project that showcases the issue.
Midi-Track-Loop.zip (15.8 KB)
In order to get the result I expect, I had to use a callback passed to :play()
that uses a timer and delays the restart. You can toggle the WORKAROUND
variable to compare the results with the SDK vs my custom callback.
local WORKAROUND = false
if WORKAROUND then
-- Looping with a recursive callback that adds a 80ms delay before restarting the sequence
local playLooped
playLooped = function(midiLoop)
midiLoop:play(function(seq) pd.timer.new(80, function(seq) playLooped(seq) end, seq) end)
end
playLooped(midiLoop)
else
-- Default looping behavior provided by SDK
midiLoop:setLoops(0)
midiLoop:play()
end
What to listen for: there's a repeated kick playing once per 2-bar cycle. When letting the SDK call do the looping, the doubled kicks play too close to each other and out of rhythm.
I'm fairly new to using MIDI and the audio world so do let me know if I'm doing something silly with the setup that would be responsible for this issue.
Meanwhile, I thought I'd share in case this is indeed unexpected behavior.
PS: I'm otherwise having lots of fun playing with the audio part of the SDK, it is quite the marvel!