Ejemplo n.º 1
0
        public void ReadFXP(BinaryFile bf)
        {
            ChunkMagic = bf.ReadString(4);
            if (ChunkMagic != "CcnK")
            {
                Console.Out.WriteLine("Error reading file. Missing preset header information.");
            }

            ByteSize = bf.ReadInt32();
            FxMagic  = bf.ReadString(4);

            if (FxMagic == "FBCh")
            {
                // Bank with Chunk Data
                Version      = bf.ReadInt32();
                FxID         = bf.ReadString(4);
                FxVersion    = bf.ReadInt32();
                ProgramCount = bf.ReadInt32();
                Future       = bf.ReadString(128);
                ChunkSize    = bf.ReadInt32();

                // Even though the main FXP is BigEndian format the preset chunk is saved in LittleEndian format
                chunkDataByteArray = new byte[ChunkSize];
                chunkDataByteArray = bf.ReadBytes(0, ChunkSize, BinaryFile.ByteOrder.LittleEndian);
                chunkData          = BinaryFile.ByteArrayToString(chunkDataByteArray);
            }
            else if (FxMagic == "FPCh")
            {
                // Preset with Chunk Data
                Version      = bf.ReadInt32();
                FxID         = bf.ReadString(4);
                FxVersion    = bf.ReadInt32();
                ProgramCount = bf.ReadInt32();
                Name         = bf.ReadString(28);
                ChunkSize    = bf.ReadInt32();

                // Even though the main FXP is BigEndian format the preset chunk is saved in LittleEndian format
                chunkDataByteArray = new byte[ChunkSize];
                chunkDataByteArray = bf.ReadBytes(0, ChunkSize, BinaryFile.ByteOrder.LittleEndian);
                chunkData          = BinaryFile.ByteArrayToString(chunkDataByteArray);
            }
            else if (FxMagic == "FxCk")
            {
                // For Preset (Program) (.fxp) without chunk (magic = 'FxCk')
                Version        = bf.ReadInt32();
                FxID           = bf.ReadString(4);
                FxVersion      = bf.ReadInt32();
                ParameterCount = bf.ReadInt32();
                Name           = bf.ReadString(28);

                // variable no. of parameters
                Parameters = new float[ParameterCount];
                for (int i = 0; i < ParameterCount; i++)
                {
                    Parameters[i] = bf.ReadSingle();
                }
            }

            bf.Close();

            // read the xml chunk into memory
            XmlDocument = new XmlDocument();
            try {
                if (chunkData != null)
                {
                    XmlDocument.LoadXml(chunkData);
                }
            } catch (XmlException) {
                //Console.Out.WriteLine("No XML found");
            }
        }