/// <summary> /// Initializes a new instance of the <see cref="MidiReader"/> with the specified stream. /// </summary> /// <param name="stream">Stream to read MIDI file from.</param> /// <param name="settings">Settings according to which MIDI data should be read.</param> /// <exception cref="ArgumentNullException"> /// <para>One of the following errors occured:</para> /// <list type="bullet"> /// <item> /// <description><paramref name="stream"/> is <c>null</c>.</description> /// </item> /// <item> /// <description><paramref name="settings"/> is <c>null</c>.</description> /// </item> /// </list> /// </exception> public MidiReader(Stream stream, ReaderSettings settings) { ThrowIfArgument.IsNull(nameof(stream), stream); ThrowIfArgument.IsNull(nameof(settings), settings); _settings = settings; if (!stream.CanSeek) { stream = new StreamWrapper(stream, settings.NonSeekableStreamBufferSize); _isStreamWrapped = true; } Length = stream.Length; if (settings.ReadFromMemory && !(stream is MemoryStream)) { _allDataBuffer = new MemoryStream(); stream.CopyTo(_allDataBuffer); _allDataBuffer.Position = 0; stream = _allDataBuffer; } _binaryReader = new BinaryReader(stream, SmfConstants.DefaultTextEncoding, leaveOpen: true); }
/// <summary> /// Initializes a new instance of the <see cref="MidiReader"/> with the specified stream. /// </summary> /// <param name="stream">Stream to read MIDI file from.</param> /// <param name="settings">Settings according to which MIDI data should be read.</param> /// <exception cref="ArgumentNullException"> /// <para>One of the following errors occured:</para> /// <list type="bullet"> /// <item> /// <description><paramref name="stream"/> is <c>null</c>.</description> /// </item> /// <item> /// <description><paramref name="settings"/> is <c>null</c>.</description> /// </item> /// </list> /// </exception> public MidiReader(Stream stream, ReaderSettings settings) { ThrowIfArgument.IsNull(nameof(stream), stream); ThrowIfArgument.IsNull(nameof(settings), settings); _settings = settings; if (!stream.CanSeek) { stream = new StreamWrapper(stream, settings.NonSeekableStreamBufferSize); _isStreamWrapped = true; } _stream = stream; Length = _stream.Length; _useBuffering = _settings.BufferingPolicy != BufferingPolicy.DontUseBuffering && !_isStreamWrapped && !(_stream is MemoryStream); if (_useBuffering) { PrepareBuffer(); } }