Help with changing notes in a track

,

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

My removeNote function works okay. Leaving this here in case there's a better way.

sequencer_betterer

1 Like

I have track:removeNote() and track:clearNotes() implemented for the next update. Looks like that MR got kicked back to me to approve. We try not to do that, but I guess I'm the only one who knows how the sequencer code is supposed to work. :stuck_out_tongue:

I'll double-check that in the morning and get it in the queue.

2 Likes

Thanks Dave, that’s awesome! Did you make the sequencer for Pulp too? It’s a great little tool, and the reason I want something similar to play with on the Playdate itself.

nope, that was all Shaun Inman :slight_smile:

1 Like