Пример #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();
        }
Пример #2
0
        public void WriteFile(string filePath)
        {
            BinaryFile bf = new BinaryFile(filePath, BinaryFile.ByteOrder.BigEndian, true);

            if (ChunkMagic != "CcnK")
            {
                Console.Out.WriteLine("Cannot save the preset file. Missing preset header information.");
                return;
            }

            bf.Write(ChunkMagic); // chunkMagic, 4

            // check what preset type we are saving
            if (FxMagic == "FBCh")
            {
                // Bank with Chunk Data
                ByteSize = 152 + ChunkSize;

                bf.Write(ByteSize);     // byteSize = 4
                bf.Write(FxMagic);      // fxMagic, 4
                bf.Write(Version);      // version, 4
                bf.Write(FxID);         // fxID, 4
                bf.Write(FxVersion);    // fxVersion, 4
                bf.Write(ProgramCount); // numPrograms, 4
                bf.Write(Future, 128);  // future, 128
                bf.Write(ChunkSize);    // chunkSize, 4


                // Even though the main FXP is BigEndian format the preset chunk is saved in LittleEndian format
                bf.Write(chunkDataByteArray, BinaryFile.ByteOrder.LittleEndian);
            }
            else if (FxMagic == "FPCh")
            {
                // Preset with Chunk Data
                ByteSize = 52 + ChunkSize;

                bf.Write(ByteSize);     // byteSize = 4
                bf.Write(FxMagic);      // fxMagic, 4
                bf.Write(Version);      // version, 4
                bf.Write(FxID);         // fxID, 4
                bf.Write(FxVersion);    // fxVersion, 4
                bf.Write(ProgramCount); // numPrograms, 4
                bf.Write(Name, 28);     // name, 28
                bf.Write(ChunkSize);    // chunkSize, 4


                // Even though the main FXP is BigEndian format the preset chunk is saved in LittleEndian format
                bf.Write(chunkDataByteArray, BinaryFile.ByteOrder.LittleEndian);
            }
            else if (FxMagic == "FxCk")
            {
                // For Preset (Program) (.fxp) without chunk (magic = 'FxCk')
                // Bank with Chunk Data
                ByteSize = 48 + (4 * ParameterCount);

                bf.Write(ByteSize);       // byteSize = 4
                bf.Write(FxMagic);        // fxMagic, 4
                bf.Write(Version);        // version, 4
                bf.Write(FxID);           // fxID, 4
                bf.Write(FxVersion);      // fxVersion, 4
                bf.Write(ParameterCount); // numParameters, 4
                bf.Write(Name, 28);       // name, 28

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

            bf.Close();
        }