The logical sequel to trimming silence from a MIDI file, I hit the same problem from the other side – the amount of time between when I stop playing and when I stop the MIDI recording. As expected, this is also extremely straightforward.
MIDI files have a mandatory “end of track” meta event, and it has a time delta just like everything else. So, my Rust code just has to find the end of track event, strip the delta, and profit!
let end_of_track = track.iter().rposition(|event| {
if let TrackEventKind::Meta {
0: MetaMessage::EndOfTrack { .. },
..
} = &event.kind
{
return true;
}
false
});
let trimmed_track = match end_of_track {
Some(index) => {
trimmed_track[index].delta = 0.into();
trimmed_track
}
None => trimmed_track,
};
...
Full program I’m using is still on GitHub: https://github.com/tobymurray/midi-silence-trimmer