AddEvent() public method

public AddEvent ( int delta, MidiEvent midiEvent ) : void
delta int
midiEvent MidiEvent
return void
Beispiel #1
0
        static MidiTrack ReadTrack(MidiDataStreamReader reader)
        {
            var track = new MidiTrack();

            // Chunk type.
            if (new string (reader.ReadChars(4)) != "MTrk")
            {
                throw new System.FormatException("Can't find track chunk.");
            }

            // Chunk length.
            var chunkEnd = reader.ReadBEInt32();

            chunkEnd += reader.Offset;

            // Read delta-time and event pairs.
            byte ev = 0;

            while (reader.Offset < chunkEnd)
            {
                // Delta time.
                var delta = reader.ReadMultiByteValue();

                // Event type.
                if ((reader.PeekByte() & 0x80) != 0)
                {
                    ev = reader.ReadByte();
                }

                if (ev == 0xff)
                {
                    // 0xff: Meta event (unused).
                    reader.Advance(1);
                    reader.Advance(reader.ReadMultiByteValue());
                }
                else if (ev == 0xf0)
                {
                    // 0xf0: SysEx (unused).
                    while (reader.ReadByte() != 0xf7)
                    {
                    }
                }
                else
                {
                    // MIDI event
                    byte data1 = reader.ReadByte();
                    byte data2 = ((ev & 0xe0) == 0xc0) ? (byte)0 : reader.ReadByte();
                    //CHANGES HEREE______________________________________________________________________________________________

                    track.AddEvent(delta, new MidiEvent(ev, data1, data2, Time.time));
                }
            }

            return(track);
        }
        static MidiTrack ReadTrack(MidiDataStreamReader reader)
        {
            var track = new MidiTrack ();

            // Chunk type.
            if (new string (reader.ReadChars (4)) != "MTrk") {
                throw new System.FormatException ("Can't find track chunk.");
            }

            // Chunk length.
            var chunkEnd = reader.ReadBEInt32 ();
            chunkEnd += reader.Offset;

            // Read delta-time and event pairs.
            byte ev = 0;
            while (reader.Offset < chunkEnd) {
                // Delta time.
                var delta = reader.ReadMultiByteValue ();

                // Event type.
                if ((reader.PeekByte () & 0x80) != 0) {
                    ev = reader.ReadByte ();
                }

                if (ev == 0xff) {
                    // 0xff: Meta event (unused).
                    reader.Advance (1);
                    reader.Advance (reader.ReadMultiByteValue ());
                } else if (ev == 0xf0) {
                    // 0xf0: SysEx (unused).
                    while (reader.ReadByte() != 0xf7) {
                    }
                } else {
                    // MIDI event
                    byte data1 = reader.ReadByte ();
                    byte data2 = ((ev & 0xe0) == 0xc0) ? (byte)0 : reader.ReadByte ();
                    track.AddEvent (delta, new MidiEvent (ev, data1, data2));
                }
            }

            return track;
        }