I'm working on a simple music maker and have hit a bit of a roadblock.
I've got all my logic and UI working, up until the point where I want to replace an existing note with a different note.
I can add a note like this:
track:addNote(step, new_note, length)
But that puts an additional note in the track at position (step), so track:getNotes(step)
goes from, for example:
{
{
[length] = 8,
[note] = 70.0,
[step] = 1,
[velocity] = 1.0,
}
}
to
{
{
[length] = 8,
[note] = 70.0,
[step] = 1,
[velocity] = 1.0,
}
}
{
{
[length] = 8,
[note] = 60,
[step] = 1,
[velocity] = 1.0,
}
}
There's no track:removeNote(step)
, so I tried:
local notes = track:getNotes(step)
notes[1].note = new_note
track:setNotes(notes)
which works for updating the step, but removes the rest of the notes from the track.
I think there must be a way to just update selected step/s, but Inside Playdate doesn't help. The documentation for playdate.sound.track:setNotes(list)
is mostly accidental duplication of playdate.sound.track:getNotes([step], [endstep])
.
So does anybody know if it's possible to do what I'm trying to do using the sound API? Or do I need to store all my track data separately and just update the whole track
object?
Or do something like:
function removeNote(this_step)
local notes = track:getNotes()
for i = #notes, 1, -1 do
if notes[i].step = this_step then
table.remove(notes, i)
end
end
track:setNotes(notes)
end