I am trying to implement the ability to split a midi clip. I started by modifying the midi recording demo a bit to simply split the selected clip at the playhead whenever the new track button is pressed:
newTrackButton.onClick = [this]
{
edit->ensureNumberOfAudioTracks (getAudioTracks (*edit).size() + 1);
auto sel = selectionManager.getSelectedObject (0);
if (auto clip = dynamic_cast<te::MidiClip*> (sel))
{
if (auto clipTrack = clip->getClipTrack())
clipTrack->splitClip(*clip, edit->getTransport().getCurrentPosition());
}
};
However I have encountered some weird UI behavior. The clip gets split, and the 2 parts of the clip are drawn in the correct places, however the midi notes are not drawn correctly. It seems like the notes of the first part of the clip get duplicatd in the second part. This is only a UI issue, the correct notes are played back by the engine, its just they dont look correct on screen. I cannot seem to figure out why this is happening. The clip component updates correctly as the clip is shown split in the correct place, and is 2 distinct clips. But the notes are not correct.
Here are some pictures of what I am describing:
Before splitting:
After splitting (notice how the notes in the first segment are duplicated in the second):
@RolandMR any ideas on why this is happening? Am I misunderstanding what splitClip does? Do I need to manually copy the midi sequence into the new, split clip? My initial thought is that the clip track only knows start and end times and doesnt know about any midi stuff since its a generic clip track. I can see that in splitClip the state of the old clip is just copied into the new clip and the start and end times are updated, which would be why the start and end times are correct in the UI. How can I correct the midi notes?