Ejemplo n.º 1
0
        public static MidiEvent FromRawMessage(int rawMessage)
        {
            long            num  = 0L;
            int             num2 = rawMessage & 255;
            int             num3 = rawMessage >> 8 & 255;
            int             num4 = rawMessage >> 16 & 255;
            int             num5 = 1;
            MidiCommandCode midiCommandCode;

            if ((num2 & 240) == 240)
            {
                midiCommandCode = (MidiCommandCode)num2;
            }
            else
            {
                midiCommandCode = (MidiCommandCode)(num2 & 240);
                num5            = (num2 & 15) + 1;
            }
            if (midiCommandCode <= MidiCommandCode.ControlChange)
            {
                MidiEvent result;
                if (midiCommandCode <= MidiCommandCode.NoteOn)
                {
                    if (midiCommandCode != MidiCommandCode.NoteOff && midiCommandCode != MidiCommandCode.NoteOn)
                    {
                        goto IL_173;
                    }
                }
                else if (midiCommandCode != MidiCommandCode.KeyAfterTouch)
                {
                    if (midiCommandCode != MidiCommandCode.ControlChange)
                    {
                        goto IL_173;
                    }
                    result = new ControlChangeEvent(num, num5, (MidiController)num3, num4);
                    return(result);
                }
                if (num4 > 0 && midiCommandCode == MidiCommandCode.NoteOn)
                {
                    result = new NoteOnEvent(num, num5, num3, num4, 0);
                    return(result);
                }
                result = new NoteEvent(num, num5, midiCommandCode, num3, num4);
                return(result);
            }
            else if (midiCommandCode <= MidiCommandCode.ChannelAfterTouch)
            {
                if (midiCommandCode == MidiCommandCode.PatchChange)
                {
                    MidiEvent result = new PatchChangeEvent(num, num5, num3);
                    return(result);
                }
                if (midiCommandCode == MidiCommandCode.ChannelAfterTouch)
                {
                    MidiEvent result = new ChannelAfterTouchEvent(num, num5, num3);
                    return(result);
                }
            }
            else
            {
                if (midiCommandCode == MidiCommandCode.PitchWheelChange)
                {
                    MidiEvent result = new PitchWheelChangeEvent(num, num5, num3 + (num4 << 7));
                    return(result);
                }
                if (midiCommandCode != MidiCommandCode.Sysex)
                {
                    switch (midiCommandCode)
                    {
                    case MidiCommandCode.TimingClock:
                    case MidiCommandCode.StartSequence:
                    case MidiCommandCode.ContinueSequence:
                    case MidiCommandCode.StopSequence:
                    case MidiCommandCode.AutoSensing:
                    {
                        MidiEvent result = new MidiEvent(num, num5, midiCommandCode);
                        return(result);
                    }
                    }
                }
            }
IL_173:
            throw new FormatException(string.Format("Unsupported MIDI Command Code for Raw Message {0}", midiCommandCode));
        }
Ejemplo n.º 2
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);
        }