Skip to content

How to Keep Only the Longest Notes at Specific Note-On Times #305

Answered by melanchall
Jenix-Park asked this question in Q&A
Discussion options

You must be logged in to vote

Hi!

Well, if you don't worry about performance, this approach should work:

foreach (var trackChunk in midiFile.GetTrackChunks())
{
    using (var notesManager = trackChunk.ManageNotes())
    {
        var notesGroups = notesManager
            .Objects
            .GroupBy(n => (n.Time, n.NoteNumber, n.Channel));

        foreach (var notesGroup in notesGroups)
        {
            var maxLength = notesGroup.Max(n => n.Length);
            var singleMaxLengthNote = notesGroup.First(n => n.Length == maxLength);

            foreach (var note in notesGroup)
            {
                if (note != singleMaxLengthNote)
                    notesManager.Objects.Remove(note);
            }

Replies: 1 comment 11 replies

Comment options

You must be logged in to vote
11 replies
@Jenix-Park
Comment options

@melanchall
Comment options

@Jenix-Park
Comment options

@melanchall
Comment options

@Jenix-Park
Comment options

Answer selected by Jenix-Park
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Just question about the library
2 participants