Beispiel #1
0
 internal FastIterator(FastList<T> ll)
 {
     _ilist = ll;
     Reset();
 }
Beispiel #2
0
        public void FirstPassParse()
        {
            int firstKey = 255;
            int lastKey  = 0;

            UnendedNotes = new FastList <UnendedNote> [256 * 16];
            for (int i = 0; i < 256 * 16; i++)
            {
                UnendedNotes[i] = new FastList <UnendedNote>();
            }
            byte eventThresh = settings.EventVelocityThreshold;
            byte noteThresh  = settings.NoteVelocityThreshold;

            if (noteThresh > eventThresh)
            {
                noteThresh = eventThresh;
            }
            try
            {
                while (true)
                {
                    uint delta = ReadVariableLenP1();
                    trackTimep1 += delta;
                    byte command = reader.ReadFast();
                    if (command < 0x80)
                    {
                        reader.Pushback = command;
                        command         = prevCommand;
                    }
                    prevCommand = command;
                    byte comm = (byte)(command & 0b11110000);
                    if (comm == 0b10010000)
                    {
                        byte channel = (byte)(command & 0b00001111);
                        byte note    = reader.Read();
                        byte vel     = reader.ReadFast();
                        if (vel != 0)
                        {
                            if (vel >= noteThresh)
                            {
                                noteCount++;
                                noteCounts[note]++;
                                if (firstKey > note)
                                {
                                    firstKey = note;
                                }
                                if (lastKey < note)
                                {
                                    lastKey = note;
                                }
                            }
                            if (vel >= eventThresh)
                            {
                                midiNoteEventCount++;
                            }
                            UnendedNotes[note * 16 + channel].Add(new UnendedNote()
                            {
                                vel = vel
                            });
                        }
                        else
                        {
                            var un = UnendedNotes[note * 16 + channel];
                            if (!un.ZeroLen)
                            {
                                if (un.Pop().vel >= eventThresh)
                                {
                                    midiNoteEventCount++;
                                }
                            }
                        }
                        continue;
                    }
                    else if (comm == 0b10000000)
                    {
                        byte channel = (byte)(command & 0b00001111);
                        byte note    = reader.Read();
                        byte vel     = reader.ReadFast();
                        var  un      = UnendedNotes[note * 16 + channel];
                        if (!un.ZeroLen)
                        {
                            if (un.Pop().vel >= eventThresh)
                            {
                                midiNoteEventCount++;
                            }
                        }
                        continue;
                    }
                    else if (comm == 0b10100000)
                    {
                        byte channel = (byte)(command & 0b00001111);
                        byte note    = reader.Read();
                        byte vel     = reader.Read();
                        midiNoteEventCount++;
                    }
                    else if (comm == 0b10110000)
                    {
                        byte channel    = (byte)(command & 0b00001111);
                        byte controller = reader.Read();
                        byte value      = reader.Read();
                        midiControlEventCount++;
                    }
                    else if (comm == 0b11000000)
                    {
                        byte program = reader.Read();
                        midiControlEventCount++;
                    }
                    else if (comm == 0b11010000)
                    {
                        byte pressure = reader.Read();
                        midiControlEventCount++;
                    }
                    else if (comm == 0b11100000)
                    {
                        byte var1 = reader.Read();
                        byte var2 = reader.Read();
                        midiControlEventCount++;
                    }
                    else if (comm == 0b10110000)
                    {
                        byte cc = reader.Read();
                        byte vv = reader.Read();
                        midiControlEventCount++;
                    }
                    else if (command == 0b11110000)
                    {
                        List <byte> data = new List <byte>()
                        {
                            command
                        };
                        byte b = 0;
                        while (b != 0b11110111)
                        {
                            b = reader.Read();
                            data.Add(b);
                        }
                    }
                    else if (command == 0b11110100 || command == 0b11110001 || command == 0b11110101 || command == 0b11111001 || command == 0b11111101)
                    {
                    }
                    else if (command == 0b11110010)
                    {
                        byte var1 = reader.Read();
                        byte var2 = reader.Read();
                    }
                    else if (command == 0b11110011)
                    {
                        byte pos = reader.Read();
                    }
                    else if (command == 0b11110110)
                    {
                    }
                    else if (command == 0b11110111)
                    {
                    }
                    else if (command == 0b11111000)
                    {
                    }
                    else if (command == 0b11111010)
                    {
                    }
                    else if (command == 0b11111100)
                    {
                    }
                    else if (command == 0b11111110)
                    {
                    }
                    else if (command == 0xFF)
                    {
                        command = reader.Read();
                        if (command == 0x00)
                        {
                            if (reader.Read() != 2)
                            {
                                throw new Exception("Corrupt Track");
                            }
                            reader.Read();
                            reader.Read();
                        }
                        else if ((command >= 0x01 && command <= 0x0A) || command == 0x7F)
                        {
                            int size = (int)ReadVariableLenP1();
                            if (command == 0x0A &&
                                (size == 8 || size == 12))
                            {
                                if (reader.Read() == 0x00)
                                {
                                    if (reader.Read() == 0x0F)
                                    {
                                        byte channel = reader.Read();
                                        if (channel < 16 || channel == 0x7F)
                                        {
                                            if (reader.Read() == 0x00)
                                            {
                                                if (size == 8)
                                                {
                                                    reader.Skip(4);
                                                }
                                                else if (size == 12)
                                                {
                                                    reader.Skip(8);
                                                }
                                                if (channel == 0x7F)
                                                {
                                                    for (int i = 0; i < 16; i++)
                                                    {
                                                        colorEventCounts[i]++;
                                                    }
                                                }
                                                else
                                                {
                                                    colorEventCounts[channel]++;
                                                }
                                            }
                                            else
                                            {
                                                reader.Skip(size - 4);
                                            }
                                        }
                                        else
                                        {
                                            reader.Skip(size - 3);
                                        }
                                    }
                                    else
                                    {
                                        reader.Skip(size - 2);
                                    }
                                }
                                else
                                {
                                    reader.Skip(size - 1);
                                }
                            }
                            else
                            {
                                reader.Skip(size);
                            }
                        }
                        else if (command == 0x20)
                        {
                            command = reader.Read();
                            if (command != 1)
                            {
                                throw new Exception("Corrupt Track");
                            }
                            reader.Read();
                        }
                        else if (command == 0x21)
                        {
                            command = reader.Read();
                            if (command != 1)
                            {
                                throw new Exception("Corrupt Track");
                            }
                            reader.Read();
                        }
                        else if (command == 0x2F)
                        {
                            command = reader.Read();
                            if (command != 0)
                            {
                                throw new Exception("Corrupt Track");
                            }
                            break;
                        }
                        else if (command == 0x51)
                        {
                            command = reader.Read();
                            if (command != 3)
                            {
                                throw new Exception("Corrupt Track");
                            }
                            int btempo = 0;
                            for (int i = 0; i != 3; i++)
                            {
                                btempo = (int)((btempo << 8) | reader.Read());
                            }
                            Tempos.Add(new TempoEvent()
                            {
                                time = trackTimep1, tempo = btempo
                            });
                        }
                        else if (command == 0x54)
                        {
                            command = reader.Read();
                            if (command != 5)
                            {
                                throw new Exception("Corrupt Track");
                            }
                            byte hr = reader.Read();
                            byte mn = reader.Read();
                            byte se = reader.Read();
                            byte fr = reader.Read();
                            byte ff = reader.Read();
                        }
                        else if (command == 0x58)
                        {
                            command = reader.Read();
                            if (command != 4)
                            {
                                throw new Exception("Corrupt Track");
                            }
                            byte nn = reader.Read();
                            byte dd = reader.Read();
                            byte cc = reader.Read();
                            byte bb = reader.Read();
                        }
                        else if (command == 0x59)
                        {
                            command = reader.Read();
                            if (command != 2)
                            {
                                throw new Exception("Corrupt Track");
                            }
                            byte sf = reader.Read();
                            byte mi = reader.Read();
                        }
                        else
                        {
                            throw new Exception("Corrupt Track");
                        }
                    }
                    else
                    {
                        throw new Exception("Corrupt Track");
                    }
                }