internal override void Read(MidiReader reader, ReadingSettings settings, int size)
        {
            var data = reader.ReadByte();

            var midiTimeCodeComponent = (byte)data.GetHead();

            if (!Enum.IsDefined(typeof(MidiTimeCodeComponent), midiTimeCodeComponent))
            {
                throw new InvalidMidiTimeCodeComponentException("Invalid MIDI Time Code component.", midiTimeCodeComponent);
            }

            Component = (MidiTimeCodeComponent)midiTimeCodeComponent;

            var componentValue = data.GetTail();

            if (componentValue > ComponentValueMasks[Component])
            {
                switch (settings.InvalidSystemCommonEventParameterValuePolicy)
                {
                case InvalidSystemCommonEventParameterValuePolicy.Abort:
                    throw new InvalidSystemCommonEventParameterValueException($"{componentValue} is invalid value for the {nameof(ComponentValue)} of {Component} of a MIDI Time Code event.", componentValue);

                case InvalidSystemCommonEventParameterValuePolicy.SnapToLimits:
                    componentValue = (FourBitNumber)ComponentValueMasks[Component];
                    break;
                }
            }

            ComponentValue = componentValue;
        }
Пример #2
0
        // Token: 0x0600332D RID: 13101 RVA: 0x00147E64 File Offset: 0x00146064
        protected override void ReadContent(MidiReader reader, ReadingSettings settings, int size)
        {
            InvalidMetaEventParameterValuePolicy invalidMetaEventParameterValuePolicy = settings.InvalidMetaEventParameterValuePolicy;

            this.Key   = (sbyte)KeySignatureEvent.ProcessValue((int)reader.ReadSByte(), "Key", -7, 7, invalidMetaEventParameterValuePolicy);
            this.Scale = (byte)KeySignatureEvent.ProcessValue((int)reader.ReadByte(), "Scale", 0, 1, invalidMetaEventParameterValuePolicy);
        }
Пример #3
0
 // Token: 0x0600333E RID: 13118 RVA: 0x0001725C File Offset: 0x0001545C
 protected override void ReadContent(MidiReader reader, ReadingSettings settings, int size)
 {
     if (size >= 1)
     {
         this.Port = reader.ReadByte();
     }
 }
Пример #4
0
        /// <summary>
        /// Reads content of a <see cref="TrackChunk"/>.
        /// </summary>
        /// <remarks>
        /// Content of a <see cref="TrackChunk"/> is collection of MIDI events.
        /// </remarks>
        /// <param name="reader">Reader to read the chunk's content with.</param>
        /// <param name="settings">Settings according to which the chunk's content must be read.</param>
        /// <param name="size">Expected size of the content taken from the chunk's header.</param>
        /// <exception cref="ObjectDisposedException">Method was called after the writer's underlying stream
        /// was disposed.</exception>
        /// <exception cref="IOException">An I/O error occurred on the writer's underlying stream.</exception>
        /// <exception cref="UnexpectedRunningStatusException">Unexpected running status is encountered.</exception>
        /// <exception cref="UnknownChannelEventException">Reader has encountered an unknown channel event.</exception>
        /// <exception cref="NotEnoughBytesException">Not enough bytes to read an event.</exception>
        /// <exception cref="InvalidChannelEventParameterValueException">Value of a channel event's parameter just
        /// read is invalid.</exception>
        /// <exception cref="MissedEndOfTrackEventException">Track chunk doesn't end with End Of Track event.</exception>
        protected override void ReadContent(MidiReader reader, ReadingSettings settings, uint size)
        {
            var endReaderPosition   = reader.Position + size;
            var endOfTrackPresented = false;

            byte?currentChannelEventStatusByte = null;

            //

            while (reader.Position < endReaderPosition && !reader.EndReached)
            {
                var midiEvent = ReadEvent(reader, settings, ref currentChannelEventStatusByte);
                if (midiEvent is EndOfTrackEvent)
                {
                    endOfTrackPresented = true;
                    break;
                }

                Events.Add(midiEvent);
            }

            //

            if (settings.MissedEndOfTrackPolicy == MissedEndOfTrackPolicy.Abort && !endOfTrackPresented)
            {
                throw new MissedEndOfTrackEventException();
            }
        }
Пример #5
0
        /// <summary>
        /// Reads content of a MIDI meta event.
        /// </summary>
        /// <param name="reader">Reader to read the content with.</param>
        /// <param name="settings">Settings according to which the event's content must be read.</param>
        /// <param name="size">Size of the event's content.</param>
        protected override void ReadContent(MidiReader reader, ReadingSettings settings, int size)
        {
            var invalidMetaEventParameterValuePolicy = settings.InvalidMetaEventParameterValuePolicy;

            var formatAndHours = reader.ReadByte();

            Format = GetFormat(formatAndHours);
            Hours  = ProcessValue(GetHours(formatAndHours),
                                  nameof(Hours),
                                  MaxHours,
                                  invalidMetaEventParameterValuePolicy);
            Minutes = ProcessValue(reader.ReadByte(),
                                   nameof(Minutes),
                                   MaxMinutes,
                                   invalidMetaEventParameterValuePolicy);
            Seconds = ProcessValue(reader.ReadByte(),
                                   nameof(Seconds),
                                   MaxSeconds,
                                   invalidMetaEventParameterValuePolicy);
            Frames = ProcessValue(reader.ReadByte(),
                                  nameof(Frames),
                                  MaxFrames[Format],
                                  invalidMetaEventParameterValuePolicy);
            SubFrames = ProcessValue(reader.ReadByte(),
                                     nameof(SubFrames),
                                     MaxSubFrames,
                                     invalidMetaEventParameterValuePolicy);
        }
        /// <summary>
        /// Reads content of a MIDI event.
        /// </summary>
        /// <param name="reader">Reader to read the content with.</param>
        /// <param name="settings">Settings according to which the event's content must be read.</param>
        /// <param name="size">Size of the event's content.</param>
        /// <exception cref="InvalidChannelEventParameterValueException">An invalid value for channel
        /// event's parameter was encountered.</exception>
        internal sealed override void Read(MidiReader reader, ReadingSettings settings, int size)
        {
            for (int i = 0; i < _parameters.Length; i++)
            {
                var parameter = reader.ReadByte();
                if (parameter > SevenBitNumber.MaxValue)
                {
                    switch (settings.InvalidChannelEventParameterValuePolicy)
                    {
                    case InvalidChannelEventParameterValuePolicy.Abort:
                        throw new InvalidChannelEventParameterValueException($"{parameter} is invalid value for channel event's parameter.", parameter);

                    case InvalidChannelEventParameterValuePolicy.ReadValid:
                        parameter &= SevenBitNumber.MaxValue;
                        break;

                    case InvalidChannelEventParameterValuePolicy.SnapToLimits:
                        parameter = SevenBitNumber.MaxValue;
                        break;
                    }
                }

                _parameters[i] = (SevenBitNumber)parameter;
            }
        }
Пример #7
0
        public MidiEvent Read(MidiReader reader, ReadingSettings settings, byte currentStatusByte)
        {
            var statusByte = reader.ReadByte();
            var size       = reader.ReadVlqNumber();

            //

            Type eventType;
            var  midiEvent = TryGetEventType(settings.CustomMetaEventTypes, statusByte, out eventType)
                ? (MetaEvent)Activator.CreateInstance(eventType)
                : new UnknownMetaEvent(statusByte);

            //

            var readerPosition = reader.Position;

            midiEvent.Read(reader, settings, size);

            var bytesRead   = reader.Position - readerPosition;
            var bytesUnread = size - bytesRead;

            if (bytesUnread > 0)
            {
                reader.Position += bytesUnread;
            }

            return(midiEvent);
        }
Пример #8
0
        // Token: 0x06003230 RID: 12848 RVA: 0x00146DC0 File Offset: 0x00144FC0
        protected override void ReadContent(MidiReader reader, ReadingSettings settings, uint size)
        {
            long num  = reader.Position + (long)((ulong)size);
            bool flag = false;
            byte?b    = null;

            this.onEvents = new List <int>(1);
            while (reader.Position < num && !reader.EndReached)
            {
                MidiEvent midiEvent = this.ReadEvent(reader, settings, ref b);
                if (midiEvent != null)
                {
                    if (midiEvent is EndOfTrackEvent)
                    {
                        flag = true;
                        break;
                    }
                    this.Events.Add(midiEvent);
                }
            }
            if (settings.MissedEndOfTrackPolicy == MissedEndOfTrackPolicy.Abort && !flag)
            {
                throw new MissedEndOfTrackEventException();
            }
        }
Пример #9
0
 /// <summary>
 /// Reads a MIDI file specified by its full path.
 /// </summary>
 /// <param name="filePath">Path to the file to read.</param>
 /// <param name="settings">Settings according to which the file must be read.</param>
 /// <returns>An instance of the <see cref="MidiFile"/> representing a MIDI file.</returns>
 /// <exception cref="ArgumentException"><paramref name="filePath"/> is a zero-length string,
 /// contains only white space, or contains one or more invalid characters as defined by
 /// <see cref="Path.InvalidPathChars"/>.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="filePath"/> is null.</exception>
 /// <exception cref="PathTooLongException">The specified path, file name, or both exceed the system-defined
 /// maximum length. For example, on Windows-based platforms, paths must be less than 248 characters,
 /// and file names must be less than 260 characters.</exception>
 /// <exception cref="DirectoryNotFoundException">The specified path is invalid, (for example,
 /// it is on an unmapped drive).</exception>
 /// <exception cref="IOException">An I/O error occurred while reading the file.</exception>
 /// <exception cref="NotSupportedException"><paramref name="filePath"/> is in an invalid format.</exception>
 /// <exception cref="UnauthorizedAccessException">This operation is not supported on the current platform.-or-
 /// <paramref name="filePath"/> specified a directory.-or- The caller does not have the required permission.</exception>
 /// <exception cref="NoHeaderChunkException">There is no header chunk in a file.</exception>
 /// <exception cref="InvalidChunkSizeException">Actual header or track chunk's size differs from the one declared
 /// in its header and that should be treated as error according to the <paramref name="settings"/>.</exception>
 /// <exception cref="UnknownChunkException">Chunk to be read has unknown ID and that
 /// should be treated as error accordng to the <paramref name="settings"/>.</exception>
 /// <exception cref="UnexpectedTrackChunksCountException">Actual track chunks
 /// count differs from the expected one and that should be treated as error according to
 /// the specified <paramref name="settings"/>.</exception>
 /// <exception cref="UnknownFileFormatException">The header chunk contains unknown file format and
 /// <see cref="ReadingSettings.UnknownFileFormatPolicy"/> property of the <paramref name="settings"/> set to
 /// <see cref="UnknownFileFormatPolicy.Abort"/>.</exception>
 /// <exception cref="InvalidChannelEventParameterValueException">Value of a channel event's parameter
 /// just read is invalid.</exception>
 /// <exception cref="InvalidMetaEventParameterValueException">Value of a meta event's parameter
 /// just read is invalid.</exception>
 /// <exception cref="UnknownChannelEventException">Reader has encountered an unknown channel event.</exception>
 /// <exception cref="NotEnoughBytesException">MIDI file cannot be read since the reader's underlying stream doesn't
 /// have enough bytes.</exception>
 /// <exception cref="UnexpectedRunningStatusException">Unexpected running status is encountered.</exception>
 /// <exception cref="MissedEndOfTrackEventException">Track chunk doesn't end with End Of Track event and that
 /// should be treated as error accordng to the specified <paramref name="settings"/>.</exception>
 public static MidiFile Read(string filePath, ReadingSettings settings = null)
 {
     using (var fileStream = FileUtilities.OpenFileForRead(filePath))
     {
         return(Read(fileStream, settings));
     }
 }
Пример #10
0
 // Token: 0x0600334B RID: 13131 RVA: 0x000172E4 File Offset: 0x000154E4
 protected override void ReadContent(MidiReader reader, ReadingSettings settings, int size)
 {
     if (size < 2)
     {
         return;
     }
     this.Number = reader.ReadWord();
 }
Пример #11
0
        /// <summary>
        /// Reads content of a MIDI event.
        /// </summary>
        /// <param name="reader">Reader to read the content with.</param>
        /// <param name="settings">Settings according to which the event's content must be read.</param>
        /// <param name="size">Size of the event's content.</param>
        internal sealed override void Read(MidiReader reader, ReadingSettings settings, int size)
        {
            ThrowIfArgument.IsNegative(nameof(size),
                                       size,
                                       "Non-negative size have to be specified in order to read SysEx event.");

            Data = reader.ReadBytes(size);
        }
Пример #12
0
        /// <summary>
        /// Reads content of a MIDI meta event.
        /// </summary>
        /// <param name="reader">Reader to read the content with.</param>
        /// <param name="settings">Settings according to which the event's content must be read.</param>
        /// <param name="size">Size of the event's content.</param>
        /// <exception cref="ArgumentOutOfRangeException">Unknown meta event cannot be read since the size is
        /// negative number.</exception>
        protected override void ReadContent(MidiReader reader, ReadingSettings settings, int size)
        {
            ThrowIfArgument.IsNegative(nameof(size),
                                       size,
                                       "Unknown meta event cannot be read since the size is negative number.");

            Data = reader.ReadBytes(size);
        }
        public MidiEvent Read(MidiReader reader, ReadingSettings settings, byte currentStatusByte)
        {
            Type eventType;
            StandardEventTypes.SystemCommon.TryGetType(currentStatusByte, out eventType);
            var systemCommonEvent = (SystemCommonEvent)Activator.CreateInstance(eventType);

            systemCommonEvent.Read(reader, settings, MidiEvent.UnknownContentSize);
            return systemCommonEvent;
        }
Пример #14
0
        /// <summary>
        /// Reads an event from the reader's underlying stream.
        /// </summary>
        /// <param name="reader">Reader to read an event.</param>
        /// <param name="settings">Settings according to which an event must be read.</param>
        /// <param name="channelEventStatusByte">Current channel event status byte used as running status.</param>
        /// <returns>Instance of the <see cref="MidiEvent"/> representing a MIDI event.</returns>
        /// <exception cref="ObjectDisposedException">Method was called after the writer's underlying stream
        /// was disposed.</exception>
        /// <exception cref="IOException">An I/O error occurred on the writer's underlying stream.</exception>
        /// <exception cref="UnexpectedRunningStatusException">Unexpected running status is encountered.</exception>
        /// <exception cref="UnknownChannelEventException">Reader has encountered an unknown channel event.</exception>
        /// <exception cref="NotEnoughBytesException">Not enough bytes to read an event.</exception>
        /// <exception cref="InvalidChannelEventParameterValueException">Value of a channel event's parameter just
        /// read is invalid.</exception>
        private MidiEvent ReadEvent(MidiReader reader, ReadingSettings settings, ref byte?channelEventStatusByte)
        {
            var deltaTime = reader.ReadVlqLongNumber();

            if (deltaTime < 0)
            {
                deltaTime = 0;
            }

            //

            var statusByte = reader.ReadByte();

            if (statusByte <= SevenBitNumber.MaxValue)
            {
                if (channelEventStatusByte == null)
                {
                    throw new UnexpectedRunningStatusException();
                }

                statusByte = channelEventStatusByte.Value;
                reader.Position--;
            }

            //

            var eventReader = EventReaderFactory.GetReader(statusByte);
            var midiEvent   = eventReader.Read(reader, settings, statusByte);

            //

            if (settings.SilentNoteOnPolicy == SilentNoteOnPolicy.NoteOff)
            {
                var noteOnEvent = midiEvent as NoteOnEvent;
                if (noteOnEvent?.Velocity == 0)
                {
                    midiEvent = new NoteOffEvent
                    {
                        DeltaTime  = noteOnEvent.DeltaTime,
                        Channel    = noteOnEvent.Channel,
                        NoteNumber = noteOnEvent.NoteNumber
                    };
                }
            }

            //

            if (midiEvent is ChannelEvent)
            {
                channelEventStatusByte = statusByte;
            }

            //

            midiEvent.DeltaTime = deltaTime;
            return(midiEvent);
        }
Пример #15
0
        // Token: 0x060033A7 RID: 13223 RVA: 0x00148610 File Offset: 0x00146810
        public MidiEvent Read(MidiReader reader, ReadingSettings settings, byte currentStatusByte)
        {
            int        size = reader.ReadVlqNumber();
            string     typeName;
            SysExEvent sysExEvent = StandardEventTypes.SysEx.TryGetType(currentStatusByte, out typeName) ? this.GetEvent(typeName) : null;

            sysExEvent.Read(reader, settings, size);
            return(sysExEvent);
        }
Пример #16
0
 // Token: 0x0600338E RID: 13198 RVA: 0x001480A0 File Offset: 0x001462A0
 protected override void ReadContent(MidiReader reader, ReadingSettings settings, int size)
 {
     this.Numerator   = reader.ReadByte();
     this.Denominator = (byte)Math.Pow(2.0, (double)reader.ReadByte());
     if (size >= 4)
     {
         this.ClocksPerClick           = reader.ReadByte();
         this.NumberOf32ndNotesPerBeat = reader.ReadByte();
     }
 }
Пример #17
0
        // Token: 0x0600323F RID: 12863 RVA: 0x00147394 File Offset: 0x00145594
        protected override void ReadContent(MidiReader reader, ReadingSettings settings, uint size)
        {
            long num = reader.Length - reader.Position;

            byte[] array = reader.ReadBytes((int)((num < (long)((ulong)size)) ? num : ((long)((ulong)size))));
            if ((long)array.Length < (long)((ulong)size) && settings.NotEnoughBytesPolicy == NotEnoughBytesPolicy.Abort)
            {
                throw new NotEnoughBytesException("Chunk's data cannot be read since the reader's underlying stream doesn't have enough bytes.", (long)((ulong)size), (long)array.Length);
            }
            this.Data = array;
        }
Пример #18
0
        /// <summary>
        /// Reads content of a MIDI meta event.
        /// </summary>
        /// <param name="reader">Reader to read the content with.</param>
        /// <param name="settings">Settings according to which the event's content must be read.</param>
        /// <param name="size">Size of the event's content.</param>
        protected override void ReadContent(MidiReader reader, ReadingSettings settings, int size)
        {
            Numerator   = reader.ReadByte();
            Denominator = (byte)Math.Pow(2, reader.ReadByte());

            if (size >= 4)
            {
                ClocksPerClick           = reader.ReadByte();
                ThirtySecondNotesPerBeat = reader.ReadByte();
            }
        }
Пример #19
0
        // Token: 0x06003216 RID: 12822 RVA: 0x00146C5C File Offset: 0x00144E5C
        protected override void ReadContent(MidiReader reader, ReadingSettings settings, uint size)
        {
            ushort num = reader.ReadWord();

            if (settings.UnknownFileFormatPolicy == UnknownFileFormatPolicy.Abort && !Enum.IsDefined(typeof(MidiFileFormat), (int)num))
            {
                throw new UnknownFileFormatException(string.Format("File format {0} is unknown.", num), num);
            }
            this.FileFormat   = num;
            this.TracksNumber = reader.ReadWord();
            this.TimeDivision = TimeDivisionFactory.GetTimeDivision(reader.ReadInt16());
        }
Пример #20
0
        // Token: 0x06003378 RID: 13176 RVA: 0x00147F08 File Offset: 0x00146108
        protected override void ReadContent(MidiReader reader, ReadingSettings settings, int size)
        {
            InvalidMetaEventParameterValuePolicy invalidMetaEventParameterValuePolicy = settings.InvalidMetaEventParameterValuePolicy;
            byte formatAndHours = reader.ReadByte();

            this.Format    = SmpteOffsetEvent.GetFormat(formatAndHours);
            this.Hours     = SmpteOffsetEvent.ProcessValue(SmpteOffsetEvent.GetHours(formatAndHours), "Hours", 23, invalidMetaEventParameterValuePolicy);
            this.Minutes   = SmpteOffsetEvent.ProcessValue(reader.ReadByte(), "Minutes", 59, invalidMetaEventParameterValuePolicy);
            this.Seconds   = SmpteOffsetEvent.ProcessValue(reader.ReadByte(), "Seconds", 59, invalidMetaEventParameterValuePolicy);
            this.Frames    = SmpteOffsetEvent.ProcessValue(reader.ReadByte(), "Frames", SmpteOffsetEvent.MaxFrames[this.Format], invalidMetaEventParameterValuePolicy);
            this.SubFrames = SmpteOffsetEvent.ProcessValue(reader.ReadByte(), "SubFrames", 99, invalidMetaEventParameterValuePolicy);
        }
Пример #21
0
        /// <summary>
        /// Reads content of a MIDI meta event.
        /// </summary>
        /// <param name="reader">Reader to read the content with.</param>
        /// <param name="settings">Settings according to which the event's content must be read.</param>
        /// <param name="size">Size of the event's content.</param>
        /// <exception cref="ArgumentOutOfRangeException">Text event cannot be read since the size is
        /// negative number.</exception>
        protected sealed override void ReadContent(MidiReader reader, ReadingSettings settings, int size)
        {
            if (size < 0)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(size),
                          size,
                          "Text event cannot be read since the size is negative number.");
            }

            Text = reader.ReadString(size);
        }
Пример #22
0
        /// <summary>
        /// Reads content of a MIDI meta event.
        /// </summary>
        /// <param name="reader">Reader to read the content with.</param>
        /// <param name="settings">Settings according to which the event's content must be read.</param>
        /// <param name="size">Size of the event's content.</param>
        /// <exception cref="ArgumentOutOfRangeException">Unknown meta event cannot be read since the size is
        /// negative number.</exception>
        protected override void ReadContent(MidiReader reader, ReadingSettings settings, int size)
        {
            if (size < 0)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(size),
                          size,
                          "Unknown meta event cannot be read since the size is negative number.");
            }

            Data = reader.ReadBytes(size);
        }
Пример #23
0
        /// <summary>
        /// Reads content of a MIDI event.
        /// </summary>
        /// <param name="reader">Reader to read the content with.</param>
        /// <param name="settings">Settings according to which the event's content must be read.</param>
        /// <param name="size">Size of the event's content.</param>
        internal sealed override void Read(MidiReader reader, ReadingSettings settings, int size)
        {
            if (size < 0)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(size),
                          size,
                          "Non-negative size have to be specified in order to read SysEx event.");
            }

            Data = reader.ReadBytes(size);
        }
        /// <summary>
        /// Reads content of a <see cref="HeaderChunk"/>.
        /// </summary>
        /// <remarks>
        /// Content of a <see cref="HeaderChunk"/> is format of the file, number of track chunks and time division.
        /// </remarks>
        /// <param name="reader">Reader to read the chunk's content with.</param>
        /// <param name="settings">Settings according to which the chunk's content must be read.</param>
        /// <param name="size">Expected size of the content taken from the chunk's header.</param>
        /// <exception cref="ObjectDisposedException">Method was called after the reader's underlying stream was disposed.</exception>
        /// <exception cref="IOException">An I/O error occurred on the reader's underlying stream.</exception>
        /// <exception cref="UnknownFileFormatException">The header chunk contains unknown file format and
        /// <see cref="ReadingSettings.UnknownFileFormatPolicy"/> property of the <paramref name="settings"/> set to
        /// <see cref="UnknownFileFormatPolicy.Abort"/>.</exception>
        protected override void ReadContent(MidiReader reader, ReadingSettings settings, uint size)
        {
            var fileFormat = reader.ReadWord();

            if (settings.UnknownFileFormatPolicy == UnknownFileFormatPolicy.Abort && !Enum.IsDefined(typeof(MidiFileFormat), fileFormat))
            {
                throw new UnknownFileFormatException($"File format {fileFormat} is unknown.", fileFormat);
            }

            FileFormat   = fileFormat;
            TracksNumber = reader.ReadWord();
            TimeDivision = TimeDivisionFactory.GetTimeDivision(reader.ReadInt16());
        }
        /// <summary>
        /// Reads content of a <see cref="UnknownChunk"/>.
        /// </summary>
        /// <remarks>
        /// Content of an <see cref="UnknownChunk"/> is array of bytes.
        /// </remarks>
        /// <param name="reader">Reader to read the chunk's content with.</param>
        /// <param name="settings">Settings according to which the chunk's content must be read.</param>
        /// <param name="size">Expected size of the content taken from the chunk's header.</param>
        /// <exception cref="ObjectDisposedException">Method was called after the reader's underlying stream was disposed.</exception>
        /// <exception cref="IOException">An I/O error occurred on the reader's underlying stream.</exception>
        protected override void ReadContent(MidiReader reader, ReadingSettings settings, uint size)
        {
            var availableSize = reader.Length - reader.Position;
            var bytes         = reader.ReadBytes((int)(availableSize < size ? availableSize : size));

            if (bytes.Length < size && settings.NotEnoughBytesPolicy == NotEnoughBytesPolicy.Abort)
            {
                throw new NotEnoughBytesException("Chunk's data cannot be read since the reader's underlying stream doesn't have enough bytes.",
                                                  size,
                                                  bytes.Length);
            }

            Data = bytes;
        }
Пример #26
0
        /// <summary>
        /// Reads content of a MIDI meta event.
        /// </summary>
        /// <param name="reader">Reader to read the content with.</param>
        /// <param name="settings">Settings according to which the event's content must be read.</param>
        /// <param name="size">Size of the event's content.</param>
        /// <exception cref="ArgumentOutOfRangeException">Text event cannot be read since the size is
        /// negative number.</exception>
        protected sealed override void ReadContent(MidiReader reader, ReadingSettings settings, int size)
        {
            ThrowIfArgument.IsNegative(nameof(size),
                                       size,
                                       "Text event cannot be read since the size is negative number.");

            if (size == 0)
            {
                return;
            }

            var bytes    = reader.ReadBytes(size);
            var encoding = settings.TextEncoding ?? SmfUtilities.DefaultEncoding;

            Text = encoding.GetString(bytes);
        }
Пример #27
0
        /// <summary>
        /// Reads content of a MIDI meta event.
        /// </summary>
        /// <param name="reader">Reader to read the content with.</param>
        /// <param name="settings">Settings according to which the event's content must be read.</param>
        /// <param name="size">Size of the event's content.</param>
        protected override void ReadContent(MidiReader reader, ReadingSettings settings, int size)
        {
            var invalidMetaEventParameterValuePolicy = settings.InvalidMetaEventParameterValuePolicy;

            Key = (sbyte)ProcessValue(reader.ReadSByte(),
                                      nameof(Key),
                                      MinKey,
                                      MaxKey,
                                      invalidMetaEventParameterValuePolicy);

            Scale = (byte)ProcessValue(reader.ReadByte(),
                                       nameof(Scale),
                                       MinScale,
                                       MaxScale,
                                       invalidMetaEventParameterValuePolicy);
        }
Пример #28
0
        internal override void Read(MidiReader reader, ReadingSettings settings, int size)
        {
            var data = reader.ReadByte();

            var messageType = data.GetHead();

            // TODO: proper exception
            if (!Enum.IsDefined(typeof(MidiTimeCodeComponent), (byte)messageType))
            {
                throw new Exception();
            }

            Component = (MidiTimeCodeComponent)(byte)messageType;
            // TODO: check value and apply policy
            ComponentValue = data.GetTail();
        }
Пример #29
0
        // Token: 0x0600339D RID: 13213 RVA: 0x001481BC File Offset: 0x001463BC
        public MidiEvent Read(MidiReader reader, ReadingSettings settings, byte currentStatusByte)
        {
            FourBitNumber head = currentStatusByte.GetHead();
            FourBitNumber tail = currentStatusByte.GetTail();
            string        typeName;

            if (!StandardEventTypes.Channel.TryGetType(head, out typeName))
            {
                throw new UnknownChannelEventException(head, tail);
            }
            ChannelEvent @event = this.GetEvent(typeName);

            @event.Read(reader, settings, -1);
            @event.Channel = tail;
            return(@event);
        }
Пример #30
0
        // Token: 0x06003304 RID: 13060 RVA: 0x00147DE0 File Offset: 0x00145FE0
        protected sealed override void ReadContent(MidiReader reader, ReadingSettings settings, int size)
        {
            if (size <= 0)
            {
                return;
            }
            byte[]   bytes    = reader.ReadBytes(size);
            Encoding somename = SomeClass.somename;
            Encoding utf      = Encoding.UTF8;
            string   @string  = somename.GetString(bytes);

            if (@string.Contains("Ã"))
            {
                @string = utf.GetString(bytes);
            }
            this.Text = @string;
        }