Symphonary.MidiInfo.GetNotesForAllChannels C# (CSharp) Method

GetNotesForAllChannels() private method

Gets all the notes for every used channel in the midi file
private GetNotesForAllChannels ( ) : void
return void
        private void GetNotesForAllChannels()
        {
            for (int channel = 0; channel < 16; channel++)
            {
                notesForAllChannels[channel].Clear();

                if (!a_UsedChannels[channel])
                    continue;

                Dictionary<int, long> d_NoteOnTimes = new Dictionary<int, long>();

                for (int i = 0; i < midiEventCollection[a_ExistingChannelOrder[channel]].Count; i++)
                {
                    MidiEvent midiEvent = midiEventCollection[a_ExistingChannelOrder[channel]][i];

                    if (midiEvent.CommandCode == MidiCommandCode.NoteOff ||
                        midiEvent.CommandCode == MidiCommandCode.NoteOn && ((NoteOnEvent)midiEvent).Velocity == 0) {
                        NoteEvent noteOff = (NoteEvent)midiEvent;
                        long noteOnTime;
                        if (d_NoteOnTimes.TryGetValue(noteOff.NoteNumber, out noteOnTime)) {
                            notesForAllChannels[channel].Add(new Note(noteOff.NoteNumber, noteOnTime, ActualTime(noteOff.AbsoluteTime)));
                            d_NoteOnTimes.Remove(noteOff.NoteNumber);
                        }
                        else {
                            debugConsole.AddText("Error: the NoteOff command at " + noteOff.AbsoluteTime + " does not match a previous NoteOn command");
                        }

                        if (ActualTime(noteOff.AbsoluteTime) > Duration)
                        {
                            Duration = ActualTime(noteOff.AbsoluteTime);
                        }
                    }
                    else if (midiEvent.CommandCode == MidiCommandCode.NoteOn) {
                        NoteOnEvent noteOn = (NoteOnEvent)midiEvent;
                        try {
                            d_NoteOnTimes.Add(noteOn.NoteNumber, ActualTime(noteOn.AbsoluteTime));
                        }
                        catch (ArgumentException e) {
                            debugConsole.AddText("Error: an event with NoteNumber " + noteOn.NoteNumber + " already exists");
                        }
                    }
                    else if (midiEvent.CommandCode == MidiCommandCode.MetaEvent && ((MetaEvent)midiEvent).MetaEventType == MetaEventType.EndTrack) {
                        if (ActualTime(midiEvent.AbsoluteTime) > Duration) {
                            Duration = ActualTime(midiEvent.AbsoluteTime);
                        }
                    }
                }

                if (d_NoteOnTimes.Count != 0) {
                    debugConsole.AddText("Error: there are still " + d_NoteOnTimes.Count + " NoteOn events for which there were no NoteOff event");
                }
            }
        }