When I pass a finishCallback to playdate.sound.sequence:play()
, it seems to be called only when not already inside another finishCallback. My goal here was to have a repeating sound which plays itself again from within the finishCallback, in order to be able to stop the repetition from the same place. Is this a bug or am I venturing outside the intended behavior?
Here's a stripped-down example of what I'm seeing:
import 'CoreLibs/graphics'
local inst = playdate.sound.synth.new(playdate.sound.kWaveTriangle)
inst:setVolume(0.5)
local track = playdate.sound.track.new()
track:setInstrument(inst)
track:addNote(1, 'E5', 1)
track:addNote(2, 'F5', 1)
local seq = playdate.sound.sequence.new()
seq:addTrack(track)
seq:setTempo(5)
local circles_filled = {}
for i = 1,10 do
table.insert(circles_filled, false)
end
function do_next()
print('do_next')
for i = 1,10 do
if not circles_filled[i] then
print(i)
circles_filled[i] = true
seq:play(do_next)
break
end
end
end
function playdate.update()
for i, filled in ipairs(circles_filled) do
if filled then
playdate.graphics.fillCircleAtPoint(20+(i-1)*40, 120, 20)
else
playdate.graphics.drawCircleAtPoint(20+(i-1)*40, 120, 20)
end
end
end
function playdate.AButtonDown()
do_next()
end
function playdate.BButtonDown()
for i = 1,10 do
circles_filled[i] = false
end
end
When I run this example and press A, the expected behavior is for all 10 circles to light up in turn, with a sound for each one. Instead, I see the correct visuals and sound but only for 2 circles, after which do_next
seems to no longer be called. The same thing happens both on simulator (Mac x86_64) and on device.