Beispiel #1
0
 internal Iterator(FastList <T> ll)
 {
     _ilist = ll;
     Reset();
 }
Beispiel #2
0
 public static IEnumerable <Note> ExtractNotes(this IEnumerable <MIDIEvent> seq, FastList <MIDIEvent> otherEvents)
 {
     return(NoteConversion.ExtractNotes(seq, otherEvents));
 }
Beispiel #3
0
 public static IEnumerable <MIDIEvent> ExtractEvents(this IEnumerable <Note> seq, FastList <MIDIEvent> buffer)
 {
     return(Mergers.MergeWithBuffer(NoteConversion.EncodeNotes(seq), buffer));
 }
Beispiel #4
0
 public static IEnumerable <MIDIEvent> MergeBuffer(this IEnumerable <MIDIEvent> seq, FastList <MIDIEvent> buffer)
 {
     return(Mergers.MergeWithBuffer(seq, buffer));
 }
Beispiel #5
0
        public static IEnumerable <Note> ExtractNotes(IEnumerable <MIDIEvent> sequence, FastList <MIDIEvent> otherEvents = null)
        {
            double time = 0;

            FastList <DecodedNote>[] unendedNotes = new FastList <DecodedNote> [256 * 16];
            FastList <DecodedNote>   notesQueue   = new FastList <DecodedNote>();

            for (int i = 0; i < unendedNotes.Length; i++)
            {
                unendedNotes[i] = new FastList <DecodedNote>();
            }
            double delta = 0;

            foreach (var e in sequence)
            {
                time += e.DeltaTime;
                if (e is NoteOnEvent)
                {
                    var n    = e as NoteOnEvent;
                    var note = new DecodedNote()
                    {
                        note = new Note(n.Channel, n.Key, n.Velocity, time, double.PositiveInfinity)
                    };
                    unendedNotes[n.Key * 16 + n.Channel].Add(note);
                    notesQueue.Add(note);
                    delta += e.DeltaTime;
                }
                else if (e is NoteOffEvent)
                {
                    var n   = e as NoteOffEvent;
                    var arr = unendedNotes[n.Key * 16 + n.Channel];
                    if (arr.ZeroLen)
                    {
                        continue;
                    }
                    var note = arr.Pop();
                    note.ended    = true;
                    note.note.End = time;
                    delta        += e.DeltaTime;
                }
                else
                {
                    if (otherEvents != null)
                    {
                        var ev = e.Clone();
                        ev.DeltaTime += delta;
                        delta         = 0;
                        otherEvents.Add(ev);
                    }
                }
                if (notesQueue.First != null && notesQueue.First.ended)
                {
                    yield return(notesQueue.Pop().note);
                }
            }
            foreach (DecodedNote un in notesQueue)
            {
                if (!un.ended)
                {
                    un.note.End = time;
                }
                yield return(un.note);
            }
            notesQueue.Unlink();
            foreach (var s in unendedNotes)
            {
                s.Unlink();
            }
        }