예제 #1
0
		//private int length;

		/// <summary>
		/// Reads a sysex message from a MIDI stream
		/// </summary>
		/// <param name="br">Stream of MIDI data</param>
		/// <returns>a new sysex message</returns>
		public static SysexEvent ReadSysexEvent(BinaryReader br)
		{
			var se = new SysexEvent();
			//se.length = ReadVarInt(br);
			//se.data = br.ReadBytes(se.length);

			var sysexData = new List<byte>();
			bool loop = true;
			while (loop)
			{
				byte b = br.ReadByte();
				if (b == 0xF7)
				{
					loop = false;
				}
				else
				{
					sysexData.Add(b);
				}
			}

			se.data = sysexData.ToArray();

			return se;
		}
예제 #2
0
        //private int length;

        /// <summary>
        /// Reads a sysex message from a MIDI stream
        /// </summary>
        /// <param name="br">Stream of MIDI data</param>
        /// <returns>a new sysex message</returns>
        public static SysexEvent ReadSysexEvent(BinaryReader br)
        {
            SysexEvent se = new SysexEvent();
            //se.length = ReadVarInt(br);
            //se.data = br.ReadBytes(se.length);

            List <byte> sysexData = new List <byte>();
            bool        loop      = true;

            while (loop)
            {
                byte b = br.ReadByte();
                if (b == 0xF7)
                {
                    loop = false;
                }
                else
                {
                    sysexData.Add(b);
                }
            }

            se.data = sysexData.ToArray();

            return(se);
        }
예제 #3
0
        public static SysexEvent ReadSysexEvent(BinaryReader br)
        {
            SysexEvent  sysexEvent = new SysexEvent();
            List <byte> list       = new List <byte>();
            bool        flag       = true;

            while (flag)
            {
                byte b = br.ReadByte();
                if (b == 247)
                {
                    flag = false;
                }
                else
                {
                    list.Add(b);
                }
            }
            sysexEvent.data = list.ToArray();
            return(sysexEvent);
        }
예제 #4
0
        /// <summary>
        /// Constructs a MidiEvent from a BinaryStream
        /// </summary>
        /// <param name="br">The binary stream of MIDI data</param>
        /// <param name="previous">The previous MIDI event (pass null for first event)</param>
        /// <returns>A new MidiEvent</returns>
        public static MidiEvent ReadNextEvent(BinaryReader br, MidiEvent previous)
        {
            int             deltaTime = MidiEvent.ReadVarInt(br);
            MidiCommandCode commandCode;
            int             channel = 1;
            byte            b       = br.ReadByte();

            if ((b & 0x80) == 0)
            {
                // a running command - command & channel are same as previous
                commandCode = previous.CommandCode;
                channel     = previous.Channel;
                br.BaseStream.Position--; // need to push this back
            }
            else
            {
                if ((b & 0xF0) == 0xF0)
                {
                    // both bytes are used for command code in this case
                    commandCode = (MidiCommandCode)b;
                }
                else
                {
                    commandCode = (MidiCommandCode)(b & 0xF0);
                    channel     = (b & 0x0F) + 1;
                }
            }

            MidiEvent me;

            switch (commandCode)
            {
            case MidiCommandCode.NoteOn:
                me = new NoteOnEvent(br);
                break;

            case MidiCommandCode.NoteOff:
            case MidiCommandCode.KeyAfterTouch:
                me = new NoteEvent(br);
                break;

            case MidiCommandCode.ControlChange:
                me = new ControlChangeEvent(br);
                break;

            case MidiCommandCode.PatchChange:
                me = new PatchChangeEvent(br);
                break;

            case MidiCommandCode.ChannelAfterTouch:
                me = new ChannelAfterTouchEvent(br);
                break;

            case MidiCommandCode.PitchWheelChange:
                me = new PitchWheelChangeEvent(br);
                break;

            case MidiCommandCode.TimingClock:
            case MidiCommandCode.StartSequence:
            case MidiCommandCode.ContinueSequence:
            case MidiCommandCode.StopSequence:
                me = new MidiEvent();
                break;

            case MidiCommandCode.Sysex:
                me = SysexEvent.ReadSysexEvent(br);
                break;

            case MidiCommandCode.MetaEvent:
                me = MetaEvent.ReadMetaEvent(br);
                break;

            default:
                throw new FormatException(String.Format("Unsupported MIDI Command Code {0:X2}", (byte)commandCode));
            }
            me.channel     = channel;
            me.deltaTime   = deltaTime;
            me.commandCode = commandCode;
            return(me);
        }
예제 #5
0
        /// <summary>
        /// Constructs a MidiEvent from a BinaryStream
        /// </summary>
        /// <param name="br">The binary stream of MIDI data</param>
        /// <param name="previous">The previous MIDI event (pass null for first event)</param>
        /// <returns>A new MidiEvent</returns>
        // Token: 0x060004C8 RID: 1224 RVA: 0x0000FF78 File Offset: 0x0000E178
        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;
                br.BaseStream.Position -= 1L;
            }
            else if ((b & 240) == 240)
            {
                midiCommandCode = (MidiCommandCode)b;
            }
            else
            {
                midiCommandCode = (MidiCommandCode)(b & 240);
                num2            = (int)((b & 15) + 1);
            }
            MidiCommandCode midiCommandCode2 = midiCommandCode;
            MidiEvent       midiEvent;

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

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