Esempio n. 1
0
        public int Compare(MidiEvent x, MidiEvent y)
        {
            long num  = x.AbsoluteTime;
            long num2 = y.AbsoluteTime;

            if (num == num2)
            {
                MetaEvent metaEvent  = x as MetaEvent;
                MetaEvent metaEvent2 = y as MetaEvent;
                if (metaEvent != null)
                {
                    if (metaEvent.MetaEventType == MetaEventType.EndTrack)
                    {
                        num = 9223372036854775807L;
                    }
                    else
                    {
                        num = -9223372036854775808L;
                    }
                }
                if (metaEvent2 != null)
                {
                    if (metaEvent2.MetaEventType == MetaEventType.EndTrack)
                    {
                        num2 = 9223372036854775807L;
                    }
                    else
                    {
                        num2 = -9223372036854775808L;
                    }
                }
            }
            return(num.CompareTo(num2));
        }
Esempio n. 2
0
 public static bool IsEndTrack(MidiEvent midiEvent)
 {
     if (midiEvent != null)
     {
         MetaEvent metaEvent = midiEvent as MetaEvent;
         if (metaEvent != null)
         {
             return(metaEvent.MetaEventType == MetaEventType.EndTrack);
         }
     }
     return(false);
 }
Esempio n. 3
0
        public static MetaEvent ReadMetaEvent(BinaryReader br)
        {
            MetaEventType metaEventType = (MetaEventType)br.ReadByte();
            int           num           = MidiEvent.ReadVarInt(br);
            MetaEvent     metaEvent     = new MetaEvent();

            if (metaEventType <= MetaEventType.SetTempo)
            {
                switch (metaEventType)
                {
                case MetaEventType.TrackSequenceNumber:
                    metaEvent = new TrackSequenceNumberEvent(br, num);
                    goto IL_E7;

                case MetaEventType.TextEvent:
                case MetaEventType.Copyright:
                case MetaEventType.SequenceTrackName:
                case MetaEventType.TrackInstrumentName:
                case MetaEventType.Lyric:
                case MetaEventType.Marker:
                case MetaEventType.CuePoint:
                case MetaEventType.ProgramName:
                case MetaEventType.DeviceName:
                    metaEvent = new TextEvent(br, num);
                    goto IL_E7;

                default:
                    if (metaEventType != MetaEventType.EndTrack)
                    {
                        if (metaEventType == MetaEventType.SetTempo)
                        {
                            metaEvent = new TempoEvent(br, num);
                            goto IL_E7;
                        }
                    }
                    else
                    {
                        if (num != 0)
                        {
                            throw new FormatException("End track length");
                        }
                        goto IL_E7;
                    }
                    break;
                }
            }
            else if (metaEventType <= MetaEventType.TimeSignature)
            {
                if (metaEventType == MetaEventType.SmpteOffset)
                {
                    metaEvent = new SmpteOffsetEvent(br, num);
                    goto IL_E7;
                }
                if (metaEventType == MetaEventType.TimeSignature)
                {
                    metaEvent = new TimeSignatureEvent(br, num);
                    goto IL_E7;
                }
            }
            else
            {
                if (metaEventType == MetaEventType.KeySignature)
                {
                    metaEvent = new KeySignatureEvent(br, num);
                    goto IL_E7;
                }
                if (metaEventType == MetaEventType.SequencerSpecific)
                {
                    metaEvent = new SequencerSpecificEvent(br, num);
                    goto IL_E7;
                }
            }
            byte[] array = br.ReadBytes(num);
            if (array.Length != num)
            {
                throw new FormatException("Failed to read metaevent's data fully");
            }
            return(new RawMetaEvent(metaEventType, 0L, array));

IL_E7:
            metaEvent.metaEvent      = metaEventType;
            metaEvent.metaDataLength = num;
            return(metaEvent);
        }
Esempio n. 4
0
        public static MidiEvent ReadNextEvent(BinaryReader br, MidiEvent previous)
        {
            int             num  = MidiEvent.ReadVarInt(br);
            int             num2 = 1;
            byte            b    = br.ReadByte();
            MidiCommandCode midiCommandCode;

            if ((b & 128) == 0)
            {
                midiCommandCode = previous.CommandCode;
                num2            = previous.Channel;
                Stream expr_2D  = br.BaseStream;
                long   position = expr_2D.Position;
                expr_2D.Position = position - 1L;
            }
            else if ((b & 240) == 240)
            {
                midiCommandCode = (MidiCommandCode)b;
            }
            else
            {
                midiCommandCode = (MidiCommandCode)(b & 240);
                num2            = (int)((b & 15) + 1);
            }
            MidiEvent midiEvent;

            if (midiCommandCode <= MidiCommandCode.ControlChange)
            {
                if (midiCommandCode <= MidiCommandCode.NoteOn)
                {
                    if (midiCommandCode != MidiCommandCode.NoteOff)
                    {
                        if (midiCommandCode != MidiCommandCode.NoteOn)
                        {
                            goto IL_154;
                        }
                        midiEvent = new NoteOnEvent(br);
                        goto IL_16A;
                    }
                }
                else if (midiCommandCode != MidiCommandCode.KeyAfterTouch)
                {
                    if (midiCommandCode != MidiCommandCode.ControlChange)
                    {
                        goto IL_154;
                    }
                    midiEvent = new ControlChangeEvent(br);
                    goto IL_16A;
                }
                midiEvent = new NoteEvent(br);
                goto IL_16A;
            }
            if (midiCommandCode <= MidiCommandCode.ChannelAfterTouch)
            {
                if (midiCommandCode == MidiCommandCode.PatchChange)
                {
                    midiEvent = new PatchChangeEvent(br);
                    goto IL_16A;
                }
                if (midiCommandCode == MidiCommandCode.ChannelAfterTouch)
                {
                    midiEvent = new ChannelAfterTouchEvent(br);
                    goto IL_16A;
                }
            }
            else
            {
                if (midiCommandCode == MidiCommandCode.PitchWheelChange)
                {
                    midiEvent = new PitchWheelChangeEvent(br);
                    goto IL_16A;
                }
                if (midiCommandCode == MidiCommandCode.Sysex)
                {
                    midiEvent = SysexEvent.ReadSysexEvent(br);
                    goto IL_16A;
                }
                switch (midiCommandCode)
                {
                case MidiCommandCode.TimingClock:
                case MidiCommandCode.StartSequence:
                case MidiCommandCode.ContinueSequence:
                case MidiCommandCode.StopSequence:
                    midiEvent = new MidiEvent();
                    goto IL_16A;

                case MidiCommandCode.MetaEvent:
                    midiEvent = MetaEvent.ReadMetaEvent(br);
                    goto IL_16A;
                }
            }
IL_154:
            throw new FormatException(string.Format("Unsupported MIDI Command Code {0:X2}", (byte)midiCommandCode));
IL_16A:
            midiEvent.channel     = num2;
            midiEvent.deltaTime   = num;
            midiEvent.commandCode = midiCommandCode;
            return(midiEvent);
        }