sequence:setLoops() isn't processing the loop amount correctly

,

Developing on Mac.

Currently I am trying to have a track within a sequence play once and then stop after a single loop. however when I attempt to call it as the following sequence:setLoops(1, 4, 1) and subsequently call sequence:play() it infinitely loops.

Here is the function that sets up the audio:

function setupAudio()
    local sawSynth = snd.synth.new(snd.kWaveSawtooth)
    
    mainInstrument = snd.instrument.new(sawSynth)
    
    
    mainChannel = snd.channel.new()
    
    mainChannel:addSource(mainInstrument)
    
    local bitcrusherEffect = snd.bitcrusher.new()
    bitcrusherEffect:setAmount(1)
    bitcrusherEffect:setUndersampling(1)
    
    mainChannel:addEffect(bitcrusherEffect)
    
    local gameStartTrack = snd.track.new()
    local gameLossTrack = snd.track.new()
    local gameWonTrack = snd.track.new()
    
    gameStartTrack:setInstrument(mainInstrument)
    gameWonTrack:setInstrument(mainInstrument)
    gameLossTrack:setInstrument(mainInstrument)
    
    gameStartTrack:addNote(1, "C4", 1)
    gameStartTrack:addNote(2, "D4", 1)
    gameStartTrack:addNote(3, "C5", 2)
    
    gameWonTrack:addNote(1, "E4", 1)
    gameWonTrack:addNote(2, "F4", 1)
    gameWonTrack:addNote(3, "E5", 2)
    
    gameLossTrack:addNote(1, "C5", 1)
    gameLossTrack:addNote(2, "D4", 1)
    gameLossTrack:addNote(3, "C3", 2)
    
    assert( gameStartTrack:getLength() == 4 )
    
    gameStartSequence = snd.sequence.new()
    gameWonSequence = snd.sequence.new()
    gameLossSequence = snd.sequence.new()
    
    gameStartSequence:addTrack(gameStartTrack)
    gameWonSequence:addTrack(gameWonTrack)
    gameLossSequence:addTrack(gameLossTrack)
    
    gameStartSequence:setTempo(6)
    gameWonSequence:setTempo(12)
    gameLossSequence:setTempo(3)
    
    gameStartSequence:setLoops(1, 4, 1)
    gameWonSequence:setLoops(1, 4, 1)
    gameLossSequence:setLoops(1, 4, 1)
end

then later we call it by calling gameStartSequence:play() resulting in an infinite loop. Any help is appreciated, thanks in advance!

Oops. Bug there. :frowning: Turns out it always loops forever if you set a loop range right now, because it decrements the loop count from 1 to 0 on the last loop. :man_facepalming: I've got that fixed for a future update. One note: loop count = 1 plays it once (which kind of defeats the purpose of setting a loop rangs..) so you'll want to set that to 2 to play it twice, once this is fixed.

As a workaround, you could remove the loop range and add the notes again

    gameStartTrack:addNote(5, "C4", 1)
    gameStartTrack:addNote(6, "D4", 1)
    gameStartTrack:addNote(7, "C5", 2)

or use the finish callback to make it repeat:

    gameStartSequence:play(function(seq) seq:play() end)

Ah I see, thank you! I'll do it manually for now then. Looking forward to the fix!

BTW slightly unrelated but I'm going to be publishing the project in question (a simple pong clone) to itch.io and am trying to avoid having Atari lawyers knock on my door. I'm between the names "POGN" and "CONG" (for crank pong). As the playdate aficionado, what is your vote?

To ensure Atari's lawyers don't bother you, I'd recommend naming it Microsoft Word for Windows

2 Likes

Great suggestion! lol