コード例 #1
0
        /// <summary>
        /// Write a key region.
        /// </summary>
        /// <param name="bw">The writer.</param>
        /// <param name="key">Key region.</param>
        public void WriteKeyRegion(BinaryDataWriter bw, IKeyRegion key, FileWriter FileWriter)
        {
            //Instrument is a new structure.
            FileWriter.StartStructure(bw);

            //Key region type reference.
            FileWriter.InitReference(bw, "VelType");

            //Get the type of reference.
            switch (key.GetKeyRegionType())
            {
            //Direct.
            case KeyRegionType.Direct:
                FileWriter.CloseReference(bw, ReferenceTypes.BNK_RefTable_Direct, "VelType");
                break;

            //Index.
            case KeyRegionType.Index:
                FileWriter.CloseReference(bw, ReferenceTypes.BNK_RefTable_Index, "VelType");
                break;

            //Range.
            case KeyRegionType.Range:
                FileWriter.CloseReference(bw, ReferenceTypes.BNK_RefTable_Range, "VelType");
                break;
            }

            //Key region is a new structure.
            FileWriter.StartStructure(bw);

            //Switch the type of reference.
            switch (key.GetKeyRegionType())
            {
            //Direct.
            case KeyRegionType.Direct:

                //Direct.
                DirectKeyRegion d = (DirectKeyRegion)key;

                //Write velocity region reference.
                FileWriter.InitReference(bw, "VelRegion");

                //Null region.
                if (d.VelocityRegion == null)
                {
                    FileWriter.CloseNullReference(bw, "VelRegion");
                }

                //Not null.
                else
                {
                    //Close the reference.
                    FileWriter.CloseReference(bw, ReferenceTypes.BNK_Info_VelocityRegion, "VelRegion");

                    //Write velocity region.
                    WriteVelocityInfo(bw, d.VelocityRegion);
                }
                break;

            //Ranged.
            case KeyRegionType.Range:

                //Set range info.
                RangeKeyRegion ran = (RangeKeyRegion)key;

                //Write stuff.
                bw.Write((byte)ran.StartVelocity);
                bw.Write((byte)ran.EndVelocity);
                bw.Write((UInt16)0);

                //Init each reference.
                for (int j = 0; j < ran.VelocityCount; j++)
                {
                    FileWriter.InitReference(bw, "RanKey" + j);
                }

                //Write each key region.
                for (int j = 0; j < ran.VelocityCount; j++)
                {
                    //Null region.
                    if (ran[j] == null)
                    {
                        FileWriter.CloseNullReference(bw, "RanKey" + j);
                    }

                    //Write key region.
                    else
                    {
                        //Velocity region reference.
                        FileWriter.CloseReference(bw, ReferenceTypes.BNK_Info_VelocityRegion, "RanKey" + j);

                        //Write the velocity region.
                        WriteVelocityInfo(bw, ran[j]);
                    }
                }
                break;

            //Index.
            case KeyRegionType.Index:

                //Set index info.
                IndexKeyRegion ind = (IndexKeyRegion)key;

                //Write the table of indices.
                bw.Write((uint)ind.Count);
                for (int j = 0; j < ind.Count; j++)
                {
                    bw.Write((byte)ind.Keys.ElementAt(j));
                }

                //Write padding.
                FileWriter.Align(bw, 4);

                //Init each index reference.
                for (int j = 0; j < ind.Count; j++)
                {
                    FileWriter.InitReference(bw, "IndKey" + j);
                }

                //Write each index.
                for (int j = 0; j < ind.Count; j++)
                {
                    //Null index.
                    if (ind.Values.ElementAt(j) == null)
                    {
                        FileWriter.CloseNullReference(bw, "IndKey" + j);
                    }

                    //Index exist.
                    else
                    {
                        //Close reference.
                        FileWriter.CloseReference(bw, ReferenceTypes.BNK_Info_VelocityRegion, "IndKey" + j);

                        //Write the velocity region.
                        WriteVelocityInfo(bw, ind.Values.ElementAt(j));
                    }
                }
                break;
            }

            //End the key region.
            FileWriter.EndStructure();

            //End the key region structure.
            FileWriter.EndStructure();
        }
コード例 #2
0
ファイル: SoundSequence.cs プロジェクト: nnn1590/Audinfo
        /// <summary>
        /// Write the sequence file.
        /// </summary>
        /// <param name="writeMode">Write mode.</param>
        /// <param name="bw">The writer.</param>
        public void Write(WriteMode writeMode, BinaryDataWriter bw)
        {
            //Update sequence data if write mode changed.
            if (this.writeMode != writeMode)
            {
                UpdateSeqData(writeMode);
            }

            //Set write mode.
            this.writeMode = writeMode;

            //Init file.
            FileWriter FileWriter = new FileWriter();

            FileWriter.InitFile(bw, writeMode, "SEQ", 2, Version);

            //Data block.
            FileWriter.InitBlock(bw, ReferenceTypes.SEQ_Block_Data, "DATA");

            //Write sequence data.
            Syroot.BinaryData.ByteOrder bo = Syroot.BinaryData.ByteOrder.BigEndian;
            if (writeMode == WriteMode.NX || writeMode == WriteMode.C_BE)
            {
                bo = Syroot.BinaryData.ByteOrder.LittleEndian;
            }
            //bw.Write(SequenceData.ToBytes(bo));
            bw.Write(goodData);

            //Align.
            FileWriter.Align(bw, 0x20);

            //Close data block.
            FileWriter.CloseBlock(bw);

            //Label block.
            FileWriter.InitBlock(bw, ReferenceTypes.SEQ_Block_Label, "LABL");

            //Label table.
            FileWriter.InitReferenceTable(bw, Labels.Count, "Labels");

            //Write each label.
            foreach (SequenceLabel l in Labels)
            {
                //Label is null.
                if (l == null)
                {
                    FileWriter.AddReferenceTableNullReference("Labels");
                }

                //Not null.
                else
                {
                    //Add reference.
                    FileWriter.AddReferenceTableReference(bw, ReferenceTypes.SEQ_LabelInfo, "Labels");

                    //Write data.
                    bw.Write(ReferenceTypes.General);
                    bw.Write((UInt16)0);
                    bw.Write(l.Offset);
                    bw.Write((UInt32)l.Label.Length);
                    bw.Write(l.Label.ToCharArray());

                    //Add null terminator.
                    bw.Write('\0');

                    //Align to 4 bytes.
                    FileWriter.Align(bw, 4);
                }
            }

            //Close labels.
            FileWriter.CloseReferenceTable(bw, "Labels");

            //Align.
            FileWriter.Align(bw, 0x20);

            //Close label block.
            FileWriter.CloseBlock(bw);

            //Close file.
            FileWriter.CloseFile(bw);
        }
コード例 #3
0
        /// <summary>
        /// Write a bank file.
        /// </summary>
        /// <param name="writeMode">Write mode.</param>
        /// <param name="bw">The writer.</param>
        public void Write(WriteMode writeMode, BinaryDataWriter bw)
        {
            //Set the write mode.
            this.writeMode = writeMode;

            //Init the bank file.
            FileWriter FileWriter = new FileWriter();

            FileWriter.InitFile(bw, writeMode, "BNK", 1, Version);

            //Init info block.
            FileWriter.InitBlock(bw, ReferenceTypes.BNK_Block_Info, "INFO");

            //Init the reference to the wave id table.
            FileWriter.InitReference(bw, "WaveIdTableRef");

            //Init the reference to the instrument reference table.
            FileWriter.InitReference(bw, "InstrumentReferenceTableRef");

            //Write the instrument reference table.
            if (Instruments != null)
            {
                //Write the reference.
                FileWriter.CloseReference(bw, ReferenceTypes.Table_Reference, "InstrumentReferenceTableRef");

                //Reference table is a structure.
                FileWriter.StartStructure(bw);

                //Init the instrument reference table.
                FileWriter.InitReferenceTable(bw, Instruments.Count, "InstrumentReferenceTable");

                //Write each instrument.
                for (int i = 0; i < Instruments.Count; i++)
                {
                    //If instrument is null.
                    if (Instruments[i] == null)
                    {
                        //Write the null reference.
                        FileWriter.AddReferenceTableNullReferenceWithType(ReferenceTypes.BNK_Info_Null, "InstrumentReferenceTable");
                    }

                    //Instrument is not null.
                    else
                    {
                        //Add reference.
                        FileWriter.AddReferenceTableReference(bw, ReferenceTypes.BNK_Info_Instrument, "InstrumentReferenceTable");

                        //Instrument is a new structure.
                        FileWriter.StartStructure(bw);

                        //Instrument type reference.
                        FileWriter.InitReference(bw, "InstType");

                        //Get the type of reference.
                        switch (Instruments[i].GetInstrumentType())
                        {
                        //Direct.
                        case InstrumentType.Direct:
                            FileWriter.CloseReference(bw, ReferenceTypes.BNK_RefTable_Direct, "InstType");
                            break;

                        //Index.
                        case InstrumentType.Index:
                            FileWriter.CloseReference(bw, ReferenceTypes.BNK_RefTable_Index, "InstType");
                            break;

                        //Range.
                        case InstrumentType.Range:
                            FileWriter.CloseReference(bw, ReferenceTypes.BNK_RefTable_Range, "InstType");
                            break;
                        }

                        //Instrument is a new structure.
                        FileWriter.StartStructure(bw);

                        //Switch the type of reference.
                        switch (Instruments[i].GetInstrumentType())
                        {
                        //Direct.
                        case InstrumentType.Direct:

                            //Direct.
                            DirectInstrument d = ((DirectInstrument)Instruments[i]);

                            //Write key region reference.
                            FileWriter.InitReference(bw, "KeyRegion");

                            //Null region.
                            if (d.KeyRegion == null)
                            {
                                FileWriter.CloseNullReference(bw, "KeyRegion");
                            }

                            //Not null.
                            else
                            {
                                //Close the reference.
                                FileWriter.CloseReference(bw, ReferenceTypes.BNK_Info_KeyRegion, "KeyRegion");

                                //Write key region.
                                WriteKeyRegion(bw, d.KeyRegion, FileWriter);
                            }
                            break;

                        //Ranged.
                        case InstrumentType.Range:

                            //Set range info.
                            RangeInstrument ran = (RangeInstrument)Instruments[i];

                            //Write stuff.
                            bw.Write((byte)ran.StartNote);
                            bw.Write((byte)ran.EndNote);
                            bw.Write((UInt16)0);

                            //Init each reference.
                            for (int j = 0; j < ran.NoteCount; j++)
                            {
                                FileWriter.InitReference(bw, "Ran" + j);
                            }

                            //Write each key region.
                            for (int j = 0; j < ran.NoteCount; j++)
                            {
                                //Null region.
                                if (ran[j] == null)
                                {
                                    FileWriter.CloseNullReference(bw, "Ran" + j);
                                }

                                //Write key region.
                                else
                                {
                                    //Key region reference.
                                    FileWriter.CloseReference(bw, ReferenceTypes.BNK_Info_KeyRegion, "Ran" + j);

                                    //Write the key region.
                                    WriteKeyRegion(bw, ran[j], FileWriter);
                                }
                            }
                            break;

                        //Index.
                        case InstrumentType.Index:

                            //Set index data.
                            IndexInstrument ind = (IndexInstrument)Instruments[i];

                            //Write the table of indices.
                            bw.Write((uint)ind.Count);
                            for (int j = 0; j < ind.Count; j++)
                            {
                                bw.Write((byte)ind.Keys.ElementAt(j));
                            }

                            //Write padding.
                            FileWriter.Align(bw, 4);

                            //Init each index reference.
                            for (int j = 0; j < ind.Count; j++)
                            {
                                FileWriter.InitReference(bw, "Ind" + j);
                            }

                            //Write each index.
                            for (int j = 0; j < ind.Count; j++)
                            {
                                //Null index.
                                if (ind.Values.ElementAt(j) == null)
                                {
                                    FileWriter.CloseNullReference(bw, "Ind" + j);
                                }

                                //Index exist.
                                else
                                {
                                    //Close reference.
                                    FileWriter.CloseReference(bw, ReferenceTypes.BNK_Info_KeyRegion, "Ind" + j);

                                    //Write the key region.
                                    WriteKeyRegion(bw, ind.Values.ElementAt(j), FileWriter);
                                }
                            }
                            break;
                        }

                        //End the instrument.
                        FileWriter.EndStructure();

                        //End the instrument structure.
                        FileWriter.EndStructure();
                    }
                }

                //Close the instrument reference table.
                FileWriter.CloseReferenceTable(bw, "InstrumentReferenceTable");

                //End the instrument reference table structure.
                FileWriter.EndStructure();
            }
            else
            {
                //Write null offset.
                FileWriter.CloseNullReference(bw, "InstrumentReferenceTableRef");
            }

            //Write the wave id table.
            if (Waves != null)
            {
                //Write the reference.
                FileWriter.CloseReference(bw, ReferenceTypes.Tables, "WaveIdTableRef");

                //Write the wave id table.
                bw.Write((uint)Waves.Count);
                for (int i = 0; i < Waves.Count; i++)
                {
                    Id warId = new Id(SoundTypes.WaveArchive, (uint)Waves[i].WarIndex);
                    warId.Write(ref bw);
                    bw.Write((uint)Waves[i].WaveIndex);
                }
            }

            //Null wave ids.
            else
            {
                FileWriter.CloseNullReference(bw, "WaveIdTableRef");
            }

            //Close the info block.
            FileWriter.CloseBlock(bw);

            //Close the bank file.
            FileWriter.CloseFile(bw);
        }
コード例 #4
0
        /// <summary>
        /// Write the file.
        /// </summary>
        /// <param name="writeMode">Write mode.</param>
        /// <param name="bw">The writer.</param>
        public void Write(WriteMode writeMode, BinaryDataWriter bw)
        {
            //Set write mode.
            this.writeMode = writeMode;

            //Init file.
            FileWriter FileWriter = new FileWriter();

            FileWriter.InitFile(bw, writeMode, "GRP", Version > new FileWriter.Version(1, 0, 0) ? 3 : 2, Version);

            //Info block.
            FileWriter.InitBlock(bw, ReferenceTypes.GRP_Block_Info, "INFO");

            //Reference table to group items.
            FileWriter.InitReferenceTable(bw, SoundFiles.Count, "FileRefs");

            //Write each sound thing.
            for (int i = 0; i < SoundFiles.Count; i++)
            {
                //Null.
                if (SoundFiles[i] == null)
                {
                    FileWriter.AddReferenceTableNullReference("FileRefs");
                }

                //Exists.
                else
                {
                    //Add reference.
                    FileWriter.AddReferenceTableReference(bw, ReferenceTypes.GRP_Info_Item, "FileRefs");

                    //Write data.
                    bw.Write((uint)SoundFiles[i].FileId);
                    FileWriter.InitSizedReference(bw, "FileRef" + i);
                }
            }

            //Align.
            FileWriter.Align(bw, 0x20);

            //Close reference table.
            FileWriter.CloseReferenceTable(bw, "FileRefs");

            //Close info block.
            FileWriter.CloseBlock(bw);

            //File block.
            FileWriter.InitBlock(bw, ReferenceTypes.GRP_Block_File, "FILE");

            //Align to 0x20 bytes.
            FileWriter.Align(bw, 0x20);

            //Write each file and align.
            for (int i = 0; i < SoundFiles.Count; i++)
            {
                //Null.
                if (SoundFiles[i] == null)
                {
                    FileWriter.CloseSizedNullReference(bw, "FileRef" + i);
                }

                //Not null.
                else
                {
                    //If the file is embedded.
                    if (SoundFiles[i].Embed)
                    {
                        //Keep track of position.
                        long pos = bw.Position;

                        //Write file.
                        FileWriter.WriteFile(bw, SoundFiles[i].File, 0x20, writeMode);

                        //Close reference.
                        FileWriter.CloseSizedReference(bw, ReferenceTypes.General, (uint)(bw.Position - pos), "FileRef" + i);
                    }

                    //Don't write data.
                    else
                    {
                        FileWriter.CloseSizedNullReference(bw, "FileRef" + i);
                    }
                }
            }

            //Close file block.
            FileWriter.CloseBlock(bw);

            //Extra info exists if the version is greater than one.
            if (Version > new FileWriter.Version(1, 0, 0))
            {
                //Extra info block.
                FileWriter.InitBlock(bw, ReferenceTypes.GRP_Block_Infx, "INFX");

                //Ex table.
                FileWriter.InitReferenceTable(bw, ExtraInfo.Count, "Ex");

                //Write each info entry.
                for (int i = 0; i < ExtraInfo.Count; i++)
                {
                    //Null.
                    if (ExtraInfo[i] == null)
                    {
                        FileWriter.AddReferenceTableNullReference("Ex");
                    }

                    //Not null.
                    else
                    {
                        //Add reference.
                        FileWriter.AddReferenceTableReference(bw, ReferenceTypes.GRP_Infx_Item, "Ex");

                        //Write the data.
                        InfoExEntry e     = ExtraInfo[i];
                        UInt32      flags = 0;
                        switch (e.LoadFlags)
                        {
                        case InfoExEntry.ELoadFlags.All:
                            flags = 0xFFFFFFFF;
                            break;

                        case InfoExEntry.ELoadFlags.Bank:
                            flags = 0b100;
                            break;

                        case InfoExEntry.ELoadFlags.BankAndWarc:
                            flags = 0b1100;
                            break;

                        case InfoExEntry.ELoadFlags.Seq:
                            flags = 0b1;
                            break;

                        case InfoExEntry.ELoadFlags.SeqAndBank:
                            flags = 0b101;
                            break;

                        case InfoExEntry.ELoadFlags.SeqAndWarc:
                            flags = 0b1100;
                            break;

                        case InfoExEntry.ELoadFlags.Warc:
                            flags = 0b1000;
                            break;

                        case InfoExEntry.ELoadFlags.Wsd:
                            flags = 0b10;
                            break;
                        }

                        //Get type.
                        byte type = 0;
                        switch (e.ItemType)
                        {
                        case InfoExEntry.EItemType.Bank:
                            type = SoundTypes.Bank;
                            break;

                        case InfoExEntry.EItemType.Sound:
                            type = SoundTypes.Sound;
                            break;

                        case InfoExEntry.EItemType.SequenceSetOrWaveData:
                            type = SoundTypes.SoundGroup;
                            break;

                        case InfoExEntry.EItemType.WaveArchive:
                            type = SoundTypes.WaveArchive;
                            break;
                        }

                        //Item id.
                        Id id = new Id(type, (uint)e.ItemIndex);
                        id.Write(ref bw);

                        //Write flags.
                        bw.Write(flags);
                    }
                }

                //Close Ex table.
                FileWriter.CloseReferenceTable(bw, "Ex");

                //Close extra info block.
                FileWriter.CloseBlock(bw);
            }

            //Close file.
            FileWriter.CloseFile(bw);
        }