/// <summary> /// Read the bank. /// </summary> /// <param name="br">The reader.</param> public void Read(BinaryDataReader br) { //Open the bank file. FileReader FileReader = new FileReader(); FileReader.OpenFile(br, out writeMode, out Version); //Open info block. FileReader.OpenBlock(br, 0); //Add the reference to the wave id table. FileReader.OpenReference(br, "WaveIdTableRef"); //Add the reference to the instrument reference table. FileReader.OpenReference(br, "InstrumentReferenceTableRef"); //Jump to the wave id table. if (!FileReader.ReferenceIsNull("WaveIdTableRef")) { FileReader.JumpToReference(br, "WaveIdTableRef"); //Read the wave id table. uint waveIdCount = br.ReadUInt32(); for (int i = 0; i < waveIdCount; i++) { Id warId = new Id(ref br); uint wavId = br.ReadUInt32(); Waves.Add(new WaveArchivePair((int)warId.index, (int)wavId)); } } //Null wave ids. else { Waves = null; } //Close the wave id table reference. FileReader.CloseReference("WaveIdTableRef"); //Jump to the instrument reference table. if (!FileReader.ReferenceIsNull("InstrumentReferenceTableRef")) { FileReader.JumpToReference(br, "InstrumentReferenceTableRef"); //Reference table is a structure. FileReader.StartStructure(br); //Read the instrument reference table. FileReader.OpenReferenceTable(br, "InstrumentReferenceTable"); //Read each instrument reference. Instruments = new List <IInstrument>(); for (int i = 0; i < FileReader.ReferenceTableCount("InstrumentReferenceTable"); i++) { //If reference is null. if (FileReader.ReferenceTableReferenceIsNull(i, "InstrumentReferenceTable")) { Instruments.Add(null); } //Reference is not null. else { //New instruments list. IInstrument inst = null; //Jump to reference. FileReader.ReferenceTableJumpToReference(br, i, "InstrumentReferenceTable"); //Instrument is a new structure. FileReader.StartStructure(br); //Instrument type reference. FileReader.OpenReference(br, "InstType"); //Jump to reference if not null. if (!FileReader.ReferenceIsNull("InstType")) { //Jump to the reference. FileReader.JumpToReference(br, "InstType"); //Instrument is a new structure. FileReader.StartStructure(br); //Switch the type of reference. switch (FileReader.ReferenceGetType("InstType")) { //Direct. case ReferenceTypes.BNK_RefTable_Direct: //Create direct instrument. DirectInstrument d = new DirectInstrument(); //Reference to key region. FileReader.OpenReference(br, "KeyRegionRef"); //If key region is not null. if (!FileReader.ReferenceIsNull("KeyRegionRef")) { //Read key region. d.KeyRegion = ReadKeyRegion(br, FileReader); } else { //Add null region. d.KeyRegion = null; } //Set instrument to the direct. inst = d; //Close reference to key region. FileReader.CloseReference("KeyRegionRef"); break; //Ranged. case ReferenceTypes.BNK_RefTable_Range: //New ranged instrument. RangeInstrument ran = new RangeInstrument(); //Get count. ran.StartNote = br.ReadByte(); ran.EndNote = br.ReadByte(); br.ReadUInt16(); //Read each reference. for (int j = 0; j < ran.NoteCount; j++) { FileReader.OpenReference(br, "Ran" + j); } //Read each key region. for (int j = 0; j < ran.NoteCount; j++) { //Null region. if (FileReader.ReferenceIsNull("Ran" + j)) { ran.Add(null); } //Read key region. else { //Jump to reference. FileReader.JumpToReference(br, "Ran" + j); //Read the key region. ran.Add(ReadKeyRegion(br, FileReader)); } } //Close each reference. for (int j = 0; j < ran.NoteCount; j++) { FileReader.CloseReference("Ran" + j); } //Set the instrument to this. inst = ran; break; //Index. case ReferenceTypes.BNK_RefTable_Index: //Read the table of indices. uint numInd = br.ReadUInt32(); List <byte> indices = new List <byte>(); for (int j = 0; j < numInd; j++) { indices.Add(br.ReadByte()); } //Read padding. FileReader.SeekAlign(br, 4); //New index instrument. IndexInstrument ind = new IndexInstrument(); //Read each index reference. for (int j = 0; j < numInd; j++) { FileReader.OpenReference(br, "Ind" + j); } //Read each index. for (int j = 0; j < numInd; j++) { //Null index. if (FileReader.ReferenceIsNull("Ind" + j)) { ind.Add((sbyte)indices[j], null); } //Index exist. else { //Jump to reference. FileReader.JumpToReference(br, "Ind" + j); //Read the key region. ind.Add((sbyte)indices[j], ReadKeyRegion(br, FileReader)); } } //Close each index reference. for (int j = 0; j < numInd; j++) { FileReader.CloseReference("Ind" + j); } //Set the instrument to this. inst = ind; break; } //End the instrument. FileReader.EndStructure(); } //Add instrument. Instruments.Add(inst); //Close the instrument type reference. FileReader.CloseReference("InstType"); //End the instrument structure. FileReader.EndStructure(); } } //Close the instrument reference table. FileReader.CloseReferenceTable("InstrumentReferenceTable"); //End the instrument reference table structure. FileReader.EndStructure(); } else { Instruments = null; } //Close the instrument reference table reference. FileReader.CloseReference("InstrumentReferenceTableRef"); //Close the info block. FileReader.CloseBlock(br); //Close the bank file. FileReader.CloseFile(br); }
/// <summary> /// Return a key region. /// </summary> /// <param name="br">The reader.</param> /// <returns>A key region.</returns> public IKeyRegion ReadKeyRegion(BinaryDataReader br, FileReader FileReader) { //Key region is a structure. FileReader.StartStructure(br); //Set up key region. IKeyRegion keyRegion = null; //Get reference to the velocity type. FileReader.OpenReference(br, "KeyTypeRef"); //Reference is not null. if (!FileReader.ReferenceIsNull("KeyTypeRef")) { //Jump to the reference. FileReader.JumpToReference(br, "KeyTypeRef"); //It's a new structure. FileReader.StartStructure(br); //Switch reference type. switch (FileReader.ReferenceGetType("KeyTypeRef")) { //Direct. case ReferenceTypes.BNK_RefTable_Direct: //New direct key region. DirectKeyRegion dir = new DirectKeyRegion(); //Open reference to velocity region. FileReader.OpenReference(br, "VelRegion"); //Not null velocity region. if (!FileReader.ReferenceIsNull("VelRegion")) { //Jump to the velocity region. FileReader.JumpToReference(br, "VelRegion"); //Open the velocity region. dir.VelocityRegion = ReadVelocityInfo(br, FileReader); } //Close reference to velocity region. FileReader.CloseReference("VelRegion"); //Set the key region. keyRegion = dir; break; //Range. case ReferenceTypes.BNK_RefTable_Range: //New ranged instrument. RangeKeyRegion ran = new RangeKeyRegion(); //Get count. ran.StartVelocity = br.ReadByte(); ran.EndVelocity = br.ReadByte(); br.ReadUInt16(); //Read each reference. for (int j = 0; j < ran.VelocityCount; j++) { FileReader.OpenReference(br, "RanKey" + j); } //Read each key region. for (int j = 0; j < ran.VelocityCount; j++) { //Null region. if (FileReader.ReferenceIsNull("RanKey" + j)) { ran.Add(null); } //Read key region. else { //Jump to reference. FileReader.JumpToReference(br, "RanKey" + j); //Read the velocity region. ran.Add(ReadVelocityInfo(br, FileReader)); } } //Close each reference. for (int j = 0; j < ran.VelocityCount; j++) { FileReader.CloseReference("RanKey" + j); } //Set the key region to this. keyRegion = ran; break; //Index. case ReferenceTypes.BNK_RefTable_Index: //Read the table of indices. uint numInd = br.ReadUInt32(); List <byte> indices = new List <byte>(); for (int j = 0; j < numInd; j++) { indices.Add(br.ReadByte()); } //Read padding. FileReader.SeekAlign(br, 4); //New index key region. IndexKeyRegion ind = new IndexKeyRegion(); //Read each index reference. for (int j = 0; j < numInd; j++) { FileReader.OpenReference(br, "IndKey" + j); } //Read each index. for (int j = 0; j < numInd; j++) { //Null index. if (FileReader.ReferenceIsNull("IndKey" + j)) { ind.Add((sbyte)indices[j], null); } //Index exist. else { //Jump to reference. FileReader.JumpToReference(br, "IndKey" + j); //Read the velocity region. ind.Add((sbyte)indices[j], ReadVelocityInfo(br, FileReader)); } } //Close each index reference. for (int j = 0; j < numInd; j++) { FileReader.CloseReference("IndKey" + j); } //Set the key region to this. keyRegion = ind; break; } //End the vel type stuff. FileReader.EndStructure(); } //Close reference to velocity type. FileReader.CloseReference("KeyTypeRef"); //End the velocity region. FileReader.EndStructure(); //Return the velocity region. return(keyRegion); }