Hmm. I’m trying this method but it doesn’t seem to be working and I’m not sure what the problem is.
The correct values of startTime, stopTime and currentTime are being printed, but when the chord is changed while the strumming note is still ringing out, it stops all the notes and the active plates fall silent. I can’t figure out why this is. It’s like the audio.stop call is working but then not the subsequent audio.seek and audio.play. Why would this be?
When this wasn’t working with the old code structure it was because I had called play before seek, but that isn’t the case this time so I’m a bit lost.
EDIT: I’m an idiot. Changed the below to
audio.play(plates[plateNumber].sound, { channel = plateNumber + 1})
and now it works. Thanks!
-- Creates a plate table/object. function newPlate() local self = {} self.onTouch = function(event) audio.play(self.sound, { channel = self.audioChannel, duration = 2000 }) self.startTime = system.getTimer() end return self end -- Create all plates and store them to a table. local plates = {} for plateNumber=1,24 do plates[plateNumber] = newPlate() plates[plateNumber].audioChannel = plateNumber + 1 end function playC(event) audio.stop({channel=1}) audio.play(chords[4], { channel=1, loops=-1 }) plates[1].sound = strum[3] plates[2].sound = strum[7] plates[3].sound = strum[3] -- etc for plateNumber=1,24 do if audio.isChannelPlaying ( plateNumber + 1 ) then plates[plateNumber].stopTime = system.getTimer() print("start time" .. plates[plateNumber].startTime) print("stop time" .. plates[plateNumber].stopTime) plates[plateNumber].currentTime = plates[plateNumber].stopTime - plates[plateNumber].startTime print("current time " .. plates[plateNumber].currentTime) if plates[plateNumber].currentTime \< 8000 then audio.stop ( plateNumber + 1 ) audio.seek(plates[plateNumber].currentTime, { channel = plateNumber + 1}) audio.play(plates[plateNumber], { channel = plateNumber + 1}) end end end end function playG(event) audio.stop({channel=1}) audio.play(chords[5], { channel=1, loops=-1 }) plates[1].sound = strum[5] plates[2].sound = strum[8] plates[3].sound = strum[5] --etc for plateNumber=1,24 do if audio.isChannelPlaying ( plateNumber + 1 ) then plates[plateNumber].stopTime = system.getTimer() print("start time" .. plates[plateNumber].startTime) print("stop time" .. plates[plateNumber].stopTime) plates[plateNumber].currentTime = plates[plateNumber].stopTime - plates[plateNumber].startTime print("current time " .. plates[plateNumber].currentTime) if plates[plateNumber].currentTime \< 8000 then audio.stop ( plateNumber + 1 ) audio.seek(plates[plateNumber].currentTime, { channel = plateNumber + 1}) audio.play(plates[plateNumber], { channel = plateNumber + 1}) end end end end strumplate[1]:addEventListener("touch", plates[1].onTouch) strumplate[2]:addEventListener("touch", plates[2].onTouch) strumplate[3]:addEventListener("touch", plates[3].onTouch)