コード例 #1
0
        public void Build_ReturnsContext()
        {
            var ctx = new ChunkFileContextBuilder()
                      .Build();

            ctx.Should().NotBeNull();
            ctx.Services.Should().NotBeNull();

            // we did not call ForReading/Writing
            ctx.ChunkFile.Should().BeNull();
        }
コード例 #2
0
        internal FileChunkWriter CreateWriter(string filePath)
        {
            var context = new ChunkFileContextBuilder()
                          .Endianness(Endianness.LittleEndian)
                          .ByteAllign(2)
                          .ForWriting(filePath)
                          .Discover(GetType().Assembly)
                          .Build();

            var writer = new FileChunkWriter(context);

            return(writer);
        }
コード例 #3
0
        /// <summary>
        /// Read event data of a Midi file stream.
        /// </summary>
        /// <param name="stream">Must not be null.</param>
        /// <returns>Never returns null.</returns>
        /// <remarks>Closes the file when done. May throw exceptions.</remarks>
        public static MidiFile Read(Stream stream)
        {
            Check.IfArgumentNull(stream, nameof(stream));

            using (var context = new ChunkFileContextBuilder()
                                 .BigEndian()
                                 .ForReading(stream)
                                 .Discover(typeof(MTrkChunkHandler).Assembly)
                                 .Build())
            {
                return(Read(context));
            }
        }
コード例 #4
0
        /// <summary>
        /// Read event data of a Midi file.
        /// </summary>
        /// <param name="filePath">Must not be null or empty.</param>
        /// <returns>Never returns null.</returns>
        /// <remarks>Closes the file when done. May throw exceptions.</remarks>
        public static MidiFile Read(string filePath)
        {
            Check.IfArgumentNullOrEmpty(filePath, nameof(filePath));

            using (var context = new ChunkFileContextBuilder()
                                 .BigEndian()
                                 .ForReading(filePath)
                                 .Discover(typeof(MTrkChunkHandler).Assembly)
                                 .Build())
            {
                return(Read(context));
            }
        }
コード例 #5
0
        public void Build_HasFile()
        {
            var filePath = Path.Combine(TestContext.DeploymentDirectory, TestMedia.WaveFileName);

            var ctx = new ChunkFileContextBuilder()
                      .ForReading(filePath)
                      .Build();

            ctx.ChunkFile.Should().NotBeNull();
            ctx.ChunkFile.FilePath.Should().NotBeNullOrEmpty();
            ctx.ChunkFile.BaseStream.Should().NotBeNull();
            ctx.ChunkFile.FileAccess.Should().Be(FileAccess.Read);
        }
コード例 #6
0
        public void Build_HasDefaultServices()
        {
            var ctx = new ChunkFileContextBuilder()
                      .Build();

            // default services
            ctx.Services.GetService <FileChunkHandlerManager>().Should().NotBeNull();
            ctx.Services.GetService <IChunkTypeFactory>().Should().NotBeNull();
            ctx.Services.GetService <INumberReader>().Should().NotBeNull();
            ctx.Services.GetService <INumberWriter>().Should().NotBeNull();
            ctx.Services.GetService <IStringReader>().Should().NotBeNull();
            ctx.Services.GetService <IStringWriter>().Should().NotBeNull();
        }
コード例 #7
0
        internal static FileChunkReader CreateReader(string filePath, Endianness endianness)
        {
            var context = new ChunkFileContextBuilder()
                          .Endianness(endianness)
                          .ByteAllign(2)
                          .ForReading(filePath)
                          .Discover(typeof(FileChunkReaderTests).Assembly)
                          .Build();

            var reader = new FileChunkReader(context);

            return(reader);
        }
コード例 #8
0
        /// <summary>
        /// Write event data to a Midi file stream.
        /// </summary>
        /// <param name="midiFile">The Midi file data to write. Must not be null.</param>
        /// <param name="stream">Must not be null or empty.</param>
        /// <remarks>May throw exceptions.</remarks>
        public static void Write(MidiFile midiFile, Stream stream)
        {
            Check.IfArgumentNull(midiFile, nameof(midiFile));
            Check.IfArgumentNull(stream, nameof(stream));

            using (var context = new ChunkFileContextBuilder()
                                 .BigEndian()
                                 .ForWriting(stream)
                                 .Discover(typeof(MTrkChunkHandler).Assembly)
                                 .Build())
            {
                Write(midiFile, context);
            }
        }
コード例 #9
0
        /// <summary>
        /// Write event data to a Midi file.
        /// </summary>
        /// <param name="midiFile">The Midi file data to write. Must not be null.</param>
        /// <param name="filePath">Must not be null or empty.</param>
        /// <remarks>May throw exceptions.</remarks>
        public static void Write(MidiFile midiFile, string filePath)
        {
            Check.IfArgumentNull(midiFile, nameof(midiFile));
            Check.IfArgumentNullOrEmpty(filePath, nameof(filePath));

            using (var context = new ChunkFileContextBuilder()
                                 .BigEndian()
                                 .ForWriting(filePath)
                                 .Discover(typeof(MTrkChunkHandler).Assembly)
                                 .Build())
            {
                Write(midiFile, context);
            }
        }