コード例 #1
0
ファイル: Event.cs プロジェクト: Seabass992/MusicStuff
        public MetaEvent(BinaryReader reader)
        {
            EventType     = Event.Type.Meta;
            EventTypeByte = reader.ReadByte();
            Type          = (MetaEventType)EventTypeByte;
            var length = new VLQ(reader);

            Length      = length.Value;
            LengthBytes = length.Bytes.ToArray();
            DataBytes   = reader.ReadBytes(Convert.ToInt32(Length));
        }
コード例 #2
0
ファイル: Event.cs プロジェクト: Seabass992/MusicStuff
        public EventData(BinaryReader reader)
        {
            _deltaTime = reader.ReadVLQ();

            var type = reader.ReadByte();

            if (type == 0xFF)
            {
                Event = new MetaEvent(reader);
            }
            else if (Enum.IsDefined(typeof(SysexEvent.SysexEventType), type))
            {
                reader.BaseStream.Position -= 1;
                Event = new SysexEvent(reader);
            }
            else if (Enum.IsDefined(typeof(MidiEvent.MidiEventType), (byte)(type & 0xF0)))
            {
                reader.BaseStream.Position -= 1;
                Event = new MidiEvent(reader);
            }
            else if (type < 0x80)
            {
                if (lastEvent != null && lastEvent.GetType() == typeof(MidiEvent))
                {
                    reader.BaseStream.Position -= 1;
                    Event = MidiEvent.Extend((MidiEvent)lastEvent, reader);
                }
                else
                {
                    throw new ArgumentException($"{type} is not a valid Event Type and there was no previous running MidiEvent. Last event was of type {lastEvent?.GetType()}");
                }
            }
            else
            {
                throw new ArgumentOutOfRangeException($"{type} is not a valid Event Type");
            }

            lastEvent = Event;
        }