Remove Midi Notes From Sequence

In my paint routine I draw notes with the following;

auto& sequence{ midiClip->getSequence() };
for (auto note : sequence.getNotes())
     // draw the notes

for each Midi clip.

If I select one of the midi clips, and choose delete, the clip goes away, including the notes, as expected.

However, if I then select a midi clip, and use te::splitClips() to split it, I get two clips, as expected. But, if I then delete one those split clips, the notes remain from the deleted clip. The notes no longer play. But they are there when the screen repaints, meaning they are still in the sequence.

What is the proper way to update the sequence?

Are you sure you’re taking in to account the offset property of the new clip when drawing?

Yes, the clips are drawn properly. And, after the split, they are still drawn properly. However, if I delete one of those split clips, the notes from the deleted clip are still drawn where they were, even though they no longer play. So, they are still part of the sequence. How do we update the sequence to remove those notes?

Also, if I look at the “MyTracks.tracktionedit” file, the notes are still listed there. In fact, I just did a test. If I split a midi clip using te::splitClips(), then save the edit, both new clips are listed in the “myTracks.tracktionedit” file with all the notes from the original clip. So, that is suggestive that the problem is occurring in te::splitClips(). It seems that te::splitClips() is not dividing the notes between the two split clips.

Have a look at ClipPosition::getOffset(). When you split a clip it doesn’t change the sequence, it effectively moves the left edge of the clip to the right to cut off the left bit of the sequence.

You might also need to take in to account looping getLoopStartBeats. Have a look at createLoopRangeDefinesAllRepetitionsSequence for how w looped sequence is created from a standard sequence. I think this function also takes in to account the clip offset.

Let me try to explain myself better.

I have created a new edit. It has one track. And contains one clip. The clip contains eight midi notes. I save that.

I inspect the “MyTracks.tracktionedit” file. The file shows the eight midi notes.

Now, I select the clip, and use te::splitClips() to cut it in half. There are now two clips. The notes are still displayed correctly as before. I save that.

When I inspect the “MyTracks.tracktionedit” file, I see the two clips. One with offset zero, the other with offset where the split occurred. However, now both clips show all of the notes! In other words, both clips have all eight notes listed, whereas they should have four notes in the zero offset clip, and four notes in the clip with offset.

Further, if I select one of the split clips, and delete it. The notes from that clip no longer play (as expected). But they are still displayed as before. And when I save the edit and inspect the file, all eight notes are still listed in the remaining clip.

So, somewhere along the line, notes are not being deleted.

How do I assure the notes are deleted when the clip is deleted?

Sorry, that’s just not how the split operation works. It simply moves the end of the first clip and creates a new clip with the offset of the split position.

You can see this fairly obviously if you try it in Waveform, you’ll be able to move the end of the first split clip and the start of the second split clip to reveal the notes that were hidden during the split.

But you’ll need to be able to deal with clip offsets anyway. If you create a MIDI clip, add some notes, set the offset to say 2s, the notes will still be there (imagine if you set the offset back to 0s, you’d expect those notes in the first 2s to be visible again). So you’ll need to account for this in your drawing and editing code.

Ah, OK. Thank you! That answers my question.

I simply need to account for the not-to-be-displayed notes in my paint routine. So, in that regard, the clips work just like with audio wave files and thumbnails. And, it will be a simple matter not to paint the notes outside of the clip bounds.

So everything is working as expected—I just did not realize how it worked! So, thank you so much for bringing me up to speed.