Ejemplo n.º 1
0
 private void ReadBytesAndAssertExpected(byte[] bytes, int expected)
 {
     using (var memoryStream = new MemoryStream(bytes))
     {
         using (BinaryReader reader = new BinaryReader(memoryStream))
         {
             var actual = reader.ReadBytesAsInt(bytes.Length);
             Assert.AreEqual(expected, actual);
         }
     }
 }
Ejemplo n.º 2
0
        public static S3MFile Parse(string path)
        {
            FileStream stream = new FileStream(path, FileMode.Open);
            using (BinaryReader reader = new BinaryReader(stream))
            {
                S3MFile file = new S3MFile();
                file.Name = ReadFileName(reader);
                CheckStreamPosition(stream, 28);
                // skip one byte (it's always 1A)
                stream.ReadByte();
                file.Type = reader.ReadBytesAsInt(1);
                CheckStreamPosition(stream, 30);
                // skip to next row
                stream.Seek(2, SeekOrigin.Current);
                CheckStreamPosition(stream, 0x20);
                //file.OrderCount = ReadByteAsInt(reader);
                file.OrderCount = reader.ReadInt16();
                file.InstrumentCount = reader.ReadInt16();
                file.PatternCount = reader.ReadInt16();
                // skip flags
                reader.ReadInt16();
                // skip version info
                reader.ReadInt16();
                // skip file format info
                reader.ReadInt16();
                ReadSCRM(reader);
                CheckStreamPosition(stream, 0x30);
                file.GlobalVolume = reader.ReadBytesAsInt(1);
                file.InitialSpeed = reader.ReadBytesAsInt(1);
                file.InitialTempo = reader.ReadBytesAsInt(1);
                file.MasterVolume = reader.ReadBytesAsInt(1);
                file.UltraClickRemoval = reader.ReadBytesAsInt(1);
                file.LoadChannelPanSettings = reader.ReadBytesAsInt(1);
                stream.Seek(0x40, SeekOrigin.Begin);
                file.ChannelSettings = ReadByteArrayAsIntArray(32, reader);
                file.Orders = ReadByteArrayAsIntArray(file.OrderCount, reader);
                file.InstrumentPointers = ReadParapointers(file.InstrumentCount, reader);
                file.PatternPointers = ReadParapointers(file.PatternCount, reader);

                file.Patterns.AddRange(ReadPatterns(file.PatternPointers, stream, reader));

                return file;
            }
        }