/// <summary> /// Write a key region. /// </summary> /// <param name="k">Key region.</param> /// <param name="a">Sound archive.</param> /// <param name="b">Bank entry.</param> /// <param name="start">Starting note.</param> /// <param name="end">Ending note.</param> /// <param name="x">The writer.</param> public static void WriteKeyRegion(IKeyRegion k, SoundArchive a, BankEntry b, int start, int end, XmlTextWriter x) { //Key region. x.WriteStartElement("KeyRegion"); //Parameters. StartUselessParameters(x); x.WriteElementString("KeyMin", start + ""); x.WriteElementString("KeyMax", end + ""); EndUselessParameters(x); //Items. x.WriteStartElement("Items"); //Write velocity regions. switch (k.GetKeyRegionType()) { //Direct. case KeyRegionType.Direct: var d = k as DirectKeyRegion; WriteVelocityRegion(d.VelocityRegion, a, b, 0, 127, x); break; //Index. case KeyRegionType.Index: var ind = k as IndexKeyRegion; int last = 0; foreach (var v in ind) { if (v.Value != null) { WriteVelocityRegion(v.Value, a, b, last, v.Key, x); } last = v.Key + 1; } break; //Range. case KeyRegionType.Range: var r = k as RangeKeyRegion; int next = 0; foreach (var v in r) { if (v != null) { WriteVelocityRegion(v, a, b, next, next, x); } next++; } break; } //End items. x.WriteEndElement(); //End key region. x.WriteEndElement(); }
/// <summary> /// If a sound archive supports prefetch info. /// </summary> /// <param name="a">Sound archive.</param> /// <returns>If prefetch info is supported.</returns> public static bool SupportsPrefetchInfo(SoundArchive a) { //F type. if (FileWriter.GetWriteModeChar(a.WriteMode) == 'F') { return(a.Version >= FVersions.StreamPrefetch); } //C type. else { return(a.Version >= CVersions.StreamPrefetch); } }
/// <summary> /// If the extra stream info is supported and is non-legacy mode. /// </summary> /// <param name="a">Sound archive.</param> /// <returns>If extra stream info is supported.</returns> public static bool SupportsExtraStreamInfo(SoundArchive a) { //F type. if (FileWriter.GetWriteModeChar(a.WriteMode) == 'F') { return(a.Version >= FVersions.StreamSendAndFilter); } //C type. else { return(a.Version >= CVersions.StreamExtraInfo); } }
/// <summary> /// Get file name of wave to use. /// </summary> /// <param name="v"></param> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static string GetWaveFileName(VelocityRegion v, SoundArchive a, BankEntry b) { //Base path. string path = "../Wave Archives"; //Get entry. var e = (b.File.File as SoundBank).Waves[v.WaveIndex]; //Get folder name. path += "/" + Path.GetFileNameWithoutExtension(a.WaveArchives[e.WarIndex].File.FileName); //Get file name. path += "/" + e.WaveIndex + ".wav"; //Return the path. return(path); }
/// <summary> /// Write a velocity region. /// </summary> /// <param name="v">Velocity region.</param> /// <param name="a">Sound archive.</param> /// <param name="b">Bank entry.</param> /// <param name="start">Starting note.</param> /// <param name="end">Ending note.</param> /// <param name="x">The writer.</param> public static void WriteVelocityRegion(VelocityRegion v, SoundArchive a, BankEntry b, int start, int end, XmlTextWriter x) { //Velocity region. x.WriteStartElement("VelocityRegion"); //Parameters. StartUselessParameters(x); x.WriteElementString("FilePath", GetWaveFileName(v, a, b)); x.WriteElementString("WaveEncoding", "Adpcm"); x.WriteElementString("OriginalKey", v.OriginalKey + ""); x.WriteStartElement("Envelope"); x.WriteStartElement("Parameters"); x.WriteElementString("Attack", v.Attack + ""); x.WriteElementString("Decay", v.Decay + ""); x.WriteElementString("Sustain", v.Sustain + ""); x.WriteElementString("Hold", v.Hold + ""); x.WriteElementString("Release", v.Release + ""); x.WriteEndElement(); //Parameters. x.WriteEndElement(); //Envelope. x.WriteElementString("VelocityMin", start + ""); x.WriteElementString("VelocityMax", end + ""); x.WriteElementString("Volume", v.Volume + ""); x.WriteElementString("Pan", v.Pan + ""); Pitch pitch = new Pitch(v.Pitch); x.WriteElementString("PitchSemitones", pitch.Semitones + ""); x.WriteElementString("PitchCents", pitch.Cents + ""); x.WriteElementString("KeyGroup", v.KeyGroup + ""); switch (v.InterPolationType) { case VelocityRegion.EInterPolationType.PolyPhase: x.WriteElementString("InterpolationType", "Polyphase"); break; case VelocityRegion.EInterPolationType.Linear: x.WriteElementString("InterpolationType", "Linear"); break; } x.WriteElementString("InstrumentNoteOffMode", v.PercussionMode ? "Ignore" : "Release"); //End parameters. EndUselessParameters(x); //End velocity region. x.WriteEndElement(); }
/// <summary> /// Write banks. /// </summary> /// <param name="a">Sound archive.</param> /// <param name="mode"></param> /// <param name="x">The writer.</param> public static void WriteBanks(SoundArchive a, WriteMode mode, XmlTextWriter x) { //Start folder. string name = "SoundSetBank"; x.WriteStartElement("SoundSetItemFolder"); x.WriteAttributeString("Name", "@" + name + "s"); //Parameters. WriteUselessParameters(x); //Items. x.WriteStartElement("Items"); //Write actual data. foreach (var d in a.Banks) { //Start item. x.WriteStartElement(name); x.WriteAttributeString("Name", d.Name); //Start parameters. StartUselessParameters(x); //Write actual data. x.WriteElementString("FilePath", "Files/Banks/" + Path.GetFileNameWithoutExtension(d.File.FileName) + "." + (mode == WriteMode.CTR ? "c" : "f") + "bnk"); x.WriteStartElement("WaveArchiveReference"); var h = d.WaveArchives; x.WriteAttributeString("Target", h.Count == 0 ? "(AutoShared)" : d.WaveArchives[0].Name); x.WriteEndElement(); //End parameters. EndUselessParameters(x); //End item. x.WriteEndElement(); } //End items. x.WriteEndElement(); //End folder. x.WriteEndElement(); }
/// <summary> /// Write project file. /// </summary> /// <param name="folderPath">Directory to write files.</param> /// <param name="a">Sound archive.</param> /// <param name="mode">How to export it.</param> public static void WriteFiles(string folderPath, SoundArchive a, WriteMode mode) { //Write wave archives. /*foreach (var war in a.WaveArchives) { * * //File is not null. * if (war.File != null) { * var folderName = Path.GetFileNameWithoutExtension(war.File.FileName); * Directory.CreateDirectory(folderPath + "/Files/Wave Archives/" + folderName); * int count = 0; * foreach (var w in war.File.File as SoundWaveArchive) { * File.WriteAllBytes(folderPath + "/Files/Wave Archives/" + folderName + "/" + count++ + ".wav", w.Riff.ToBytes()); * } * } * * }*/ //Write banks. foreach (var bnk in a.Banks) { //File is not null. if (bnk.File != null) { var fileName = Path.GetFileNameWithoutExtension(bnk.File.FileName); Directory.CreateDirectory(folderPath + "/Files/Banks"); WriteBnk(folderPath, a, bnk, mode); } } //Write sequences. /*foreach (var seq in a.Sequences) { * * //File is not null. * if (seq.File != null) { * var fileName = Path.GetFileNameWithoutExtension(seq.File.FileName); * Directory.CreateDirectory(folderPath + "/Files/Sequences"); * File.WriteAllLines(folderPath + "/Files/Sequences/" + fileName + "." + (mode == WriteMode.CTR ? "c" : "f") + "seq", (seq.File.File as SoundSequence).SequenceData.ToSeqFile(fileName, mode == WriteMode.CTR ? "C" : "F")); * } * * }*/ }
/// <summary> /// Write wave archives. /// </summary> /// <param name="a">Sound archive.</param> /// <param name="mode"></param> /// <param name="x">The writer.</param> public static void WriteWaveArchives(SoundArchive a, WriteMode mode, XmlTextWriter x) { //Start folder. string name = "WaveArchive"; x.WriteStartElement("SoundSetItemFolder"); x.WriteAttributeString("Name", "@" + name + "s"); //Parameters. WriteUselessParameters(x); //Items. x.WriteStartElement("Items"); //Write actual data. int num = 0; foreach (var d in a.WaveArchives) { //Start item. x.WriteStartElement(name); x.WriteAttributeString("Name", d.Name == null ? "WARC_NULL_" + num++ : d.Name); //Start parameters. StartUselessParameters(x); //Write actual data. x.WriteElementString("WaveArchiveLoadType", d.LoadIndividually ? "Individual" : "Whole"); //End parameters. EndUselessParameters(x); //End item. x.WriteEndElement(); } //End items. x.WriteEndElement(); //End folder. x.WriteEndElement(); }
/// <summary> /// Write players. /// </summary> /// <param name="a">Sound archive.</param> /// <param name="mode"></param> /// <param name="x">The writer.</param> public static void WritePlayers(SoundArchive a, WriteMode mode, XmlTextWriter x) { //Start folder. string name = "Player"; x.WriteStartElement("SoundSetItemFolder"); x.WriteAttributeString("Name", "@" + name + "s"); //Parameters. WriteUselessParameters(x); //Items. x.WriteStartElement("Items"); //Write actual data. foreach (var d in a.Players) { //Start item. x.WriteStartElement(name); x.WriteAttributeString("Name", d.Name); //Start parameters. StartUselessParameters(x); //Write actual data. x.WriteElementString("PlayerSoundLimit", d.SoundLimit + ""); x.WriteElementString("PlayerHeapSize", d.IncludeHeapSize ? d.PlayerHeapSize + "" : 0 + ""); //End parameters. EndUselessParameters(x); //End item. x.WriteEndElement(); } //End items. x.WriteEndElement(); //End folder. x.WriteEndElement(); }
/// <summary> /// Write project file. /// </summary> /// <param name="folderPath">Directory to write SST.</param> /// <param name="projectName">Name of the project.</param> /// <param name="a">Sound archive.</param> /// <param name="mode">How to export it.</param> public static void WriteSst(string folderPath, string projectName, SoundArchive a, WriteMode mode) { using (FileStream fileStream = new FileStream(folderPath + "/" + projectName + "." + (mode == WriteMode.CTR ? "c" : "f") + "sst", FileMode.Create)) using (StreamWriter sw = new StreamWriter(fileStream)) using (XmlTextWriter x = new XmlTextWriter(sw)) { //Start data. x.Formatting = Formatting.Indented; x.Indentation = 2; x.WriteStartDocument(); x.WriteStartElement("SoundSet"); x.WriteAttributeString(new XAttribute(XNamespace.Xmlns + "xsi", "h").ToString().Trim("=\"h\"".ToCharArray()), "http://www.w3.org/2001/XMLSchema-instance"); x.WriteAttributeString(new XAttribute(XNamespace.Xmlns + "xsd", "h").ToString().Trim("=\"h\"".ToCharArray()), "http://www.w3.org/2001/XMLSchema"); //Get version. string version = "1."; switch (mode) { case WriteMode.Cafe: version += "3"; break; case WriteMode.CTR: version += "2"; break; case WriteMode.NX: version += "0"; break; } version += ".0.0"; x.WriteAttributeString("Version", version); //Get platform. string platform = "Any"; switch (mode) { case WriteMode.Cafe: platform = "Cafe"; break; case WriteMode.CTR: platform = "Ctr"; break; } x.WriteAttributeString("Platform", platform); x.WriteAttributeString(new XAttribute(XNamespace.Xmlns + "h", "h").ToString().Trim(":=\"hh\"".ToCharArray()), "NintendoWare.SoundFoundation.FileFormats.NintendoWare"); //Write head. x.WriteStartElement("Head"); //Head. x.WriteElementString("Title", projectName); x.WriteEndElement(); //Head. //Write body. x.WriteStartElement("Body"); //Write sound set. x.WriteStartElement("SoundSet"); //Write items. x.WriteStartElement("Items"); WriteTempItem("StreamSound", x); WriteTempItem("WaveSoundSet", x); WriteSequences(a, mode, x); WriteTempItem("SequenceSoundSet", x); WriteBanks(a, mode, x); WriteWaveArchives(a, mode, x); WriteTempItem("WaveArchive", x); WriteTempItem("Group", x); WritePlayers(a, mode, x); //End project. x.WriteEndElement(); //SoundSet. x.WriteEndElement(); //Body. x.WriteEndElement(); //SoundSet. x.WriteEndDocument(); //Flush. x.Flush(); } }
/// <summary> /// Write sequences /// </summary> /// <param name="a">Sound archive.</param> /// <param name="mode"></param> /// <param name="x">The writer.</param> public static void WriteSequences(SoundArchive a, WriteMode mode, XmlTextWriter x) { //Start folder. string name = "SequenceSound"; x.WriteStartElement("SoundSetItemFolder"); x.WriteAttributeString("Name", "@" + name + "s"); //Parameters. WriteUselessParameters(x); //Items. x.WriteStartElement("Items"); //Write actual data. foreach (var d in a.Sequences) { //Start item. x.WriteStartElement(name); x.WriteAttributeString("Name", d.Name); //Start parameters. StartUselessParameters(x); //Write actual data. x.WriteElementString("FilePath", "Files/Sequences/" + Path.GetFileNameWithoutExtension(d.File.FileName) + "." + (mode == WriteMode.CTR ? "c" : "f") + "seq"); x.WriteElementString("Volume", d.Volume + ""); x.WriteElementString("PlayerPriority", d.PlayerPriority + ""); x.WriteStartElement("PlayerReference"); x.WriteAttributeString("Target", d.Player.Name); x.WriteEndElement(); x.WriteElementString("ActorPlayer", d.PlayerActorId + ""); x.WriteElementString("UserParameter", d.UserParameter[0] + ""); x.WriteElementString("UserParameter1", d.UserParameter[1] + ""); x.WriteElementString("UserParameter2", d.UserParameter[2] + ""); x.WriteElementString("UserParameter3", d.UserParameter[3] + ""); //SOUND 3D. x.WriteStartElement("Sound3D"); x.WriteStartElement("Parameters"); if (d.Sound3dInfo == null) { x.WriteElementString("DecayCurve3D", "Log"); x.WriteElementString("DecayRatio3D", "0.5"); x.WriteElementString("DopplerFactor3D", "0"); x.WriteElementString("Enable3DVolume", "True"); x.WriteElementString("Enable3DPan", "True"); x.WriteElementString("Enable3DSurroundPan", "True"); x.WriteElementString("Enable3DPriority", "True"); x.WriteElementString("Enable3DFilter", "False"); } else { x.WriteElementString("DecayCurve3D", d.Sound3dInfo.AttenuationCurve == Sound3dInfo.EAttenuationCurve.Logarithmic ? "Log" : "Linear"); x.WriteElementString("DecayRatio3D", d.Sound3dInfo.AttenuationRate + ""); x.WriteElementString("DopplerFactor3D", d.Sound3dInfo.DopplerFactor + ""); x.WriteElementString("Enable3DVolume", d.Sound3dInfo.Volume ? "True" : "False"); x.WriteElementString("Enable3DPan", d.Sound3dInfo.Pan ? "True" : "False"); x.WriteElementString("Enable3DSurroundPan", d.Sound3dInfo.Span ? "True" : "False"); x.WriteElementString("Enable3DPriority", d.Sound3dInfo.Priority ? "True" : "False"); x.WriteElementString("Enable3DFilter", d.Sound3dInfo.Filter ? "True" : "False"); } x.WriteEndElement(); x.WriteEndElement(); x.WriteElementString("SequenceSoundFileType", "Text"); x.WriteElementString("StartPosition", (d.File.File as SoundSequence).SequenceData.GetClosestLabel((int)d.StartOffset)); x.WriteStartElement("SoundSetBankReferences"); x.WriteStartElement("SoundSetBankReference"); x.WriteAttributeString("Target", d.Banks[0] == null ? "" : d.Banks[0].Name); x.WriteEndElement(); x.WriteStartElement("SoundSetBankReference"); x.WriteAttributeString("Target", d.Banks[1] == null ? "" : d.Banks[1].Name); x.WriteEndElement(); x.WriteStartElement("SoundSetBankReference"); x.WriteAttributeString("Target", d.Banks[2] == null ? "" : d.Banks[2].Name); x.WriteEndElement(); x.WriteStartElement("SoundSetBankReference"); x.WriteAttributeString("Target", d.Banks[3] == null ? "" : d.Banks[3].Name); x.WriteEndElement(); x.WriteEndElement(); x.WriteElementString("ChannelPriority", d.ChannelPriority + ""); x.WriteElementString("ReleasePriorityFixed", d.IsReleasePriority ? "True" : "False"); x.WriteElementString("FrontBypass", d.IsFrontBypass ? "True" : "False"); if (mode != WriteMode.CTR) { x.WriteElementString("RemoteFilter", d.RemoteFilter + ""); } //End parameters. EndUselessParameters(x); //End item. x.WriteEndElement(); } //End items. x.WriteEndElement(); //End folder. x.WriteEndElement(); }
/// <summary> /// Write the sound info. /// </summary> /// <param name="bw">The writer.</param> /// <param name="w">File writer.</param> /// <param name="a">The sound archive.</param> /// <param name="strings">Strings.</param> public void WriteSoundInfo(BinaryDataWriter bw, FileWriter w, SoundArchive a, List <string> strings) { //Keep track of position. long pos = bw.Position; //Write data. if (File != null) { bw.Write((uint)File.FileId); } else { bw.Write((uint)0xFFFFFFFF); } new Id(SoundTypes.Player, (uint)a.Players.IndexOf(Player)).Write(ref bw); bw.Write(Volume); bw.Write(RemoteFilter); bw.Write((ushort)0); w.InitReference(bw, "ToDetRef"); //3d info offset. long threeDeeInfoOffOff = bw.Position; //New flags. Dictionary <int, uint> f = new Dictionary <int, uint>(); //Write string data. if (a.CreateStrings && Name != null) { f.Add(0, (uint)strings.IndexOf(Name)); } //Other flags. f.Add(1, (uint)(((byte)PanCurve << 8) | (byte)PanMode)); f.Add(2, (uint)(((byte)PlayerActorId << 8) | (byte)PlayerPriority)); //Get 3d info offset offset. threeDeeInfoOffOff += (a.CreateStrings && Name != null ? 0x10 : 0xC); if (Sound3dInfo != null) { f.Add(8, 0); } //Front bypass. f.Add(17, (uint)(IsFrontBypass ? 1 : 0)); //User parameters. if (UserParamsEnabled[0]) { f.Add(31, UserParameter[0]); } if (UserParamsEnabled[1]) { f.Add(30, UserParameter[1]); } if (UserParamsEnabled[2]) { f.Add(29, UserParameter[2]); } if (UserParamsEnabled[3]) { f.Add(28, UserParameter[3]); } //Write the flags. new FlagParameters(f).Write(ref bw); //Write the 3d info. if (Sound3dInfo != null) { long newPos = bw.Position; bw.Position = threeDeeInfoOffOff; bw.Write((uint)(newPos - pos)); bw.Position = newPos; //Flags. uint tDFlags = 0; tDFlags += (uint)(Sound3dInfo.Volume ? 0b1 : 0); tDFlags += (uint)(Sound3dInfo.Priority ? 0b10 : 0); tDFlags += (uint)(Sound3dInfo.Pan ? 0b100 : 0); tDFlags += (uint)(Sound3dInfo.Span ? 0b1000 : 0); tDFlags += (uint)(Sound3dInfo.Filter ? 0b10000 : 0); bw.Write(tDFlags); //Other info. bw.Write(Sound3dInfo.AttenuationRate); bw.Write((byte)Sound3dInfo.AttenuationCurve); bw.Write(Sound3dInfo.DopplerFactor); bw.Write((ushort)0); bw.Write((uint)0); //For 'F' type. if (FileWriter.GetWriteModeChar(a.WriteMode) == 'F') { bw.Write((uint)(Sound3dInfo.UnknownFlag ? 1 : 0)); } } }
/// <summary> /// Write project file. /// </summary> /// <param name="folderPath">Directory to write SPJ.</param> /// <param name="projectName">Name of the project.</param> /// <param name="a">Sound archive.</param> /// <param name="mode">How to export it.</param> public static void WriteSpj(string folderPath, string projectName, SoundArchive a, WriteMode mode) { using (FileStream fileStream = new FileStream(folderPath + "/" + projectName + "." + (mode == WriteMode.CTR ? "c" : "f") + "spj", FileMode.Create)) using (StreamWriter sw = new StreamWriter(fileStream)) using (XmlTextWriter x = new XmlTextWriter(sw)) { x.Formatting = Formatting.Indented; x.Indentation = 2; x.WriteStartDocument(); x.WriteStartElement("SoundProject"); x.WriteAttributeString(new XAttribute(XNamespace.Xmlns + "xsi", "h").ToString().Trim("=\"h\"".ToCharArray()), "http://www.w3.org/2001/XMLSchema-instance"); x.WriteAttributeString(new XAttribute(XNamespace.Xmlns + "xsd", "h").ToString().Trim("=\"h\"".ToCharArray()), "http://www.w3.org/2001/XMLSchema"); //Get version. string version = "1."; switch (mode) { case WriteMode.Cafe: version += "4"; break; case WriteMode.CTR: version += "6"; break; case WriteMode.NX: version += "1"; break; } version += ".0.0"; x.WriteAttributeString("Version", version); //Get platform. string platform = "Any"; switch (mode) { case WriteMode.Cafe: platform = "Cafe"; break; case WriteMode.CTR: platform = "Ctr"; break; } x.WriteAttributeString("Platform", platform); x.WriteAttributeString(new XAttribute(XNamespace.Xmlns + "h", "h").ToString().Trim(":=\"hh\"".ToCharArray()), "NintendoWare.SoundFoundation.FileFormats.NintendoWare"); //Write head with title. x.WriteStartElement("Head"); x.WriteElementString("Title", projectName + "SoundProject"); x.WriteEndElement(); //Head. //Body. x.WriteStartElement("Body"); //Sound project. x.WriteStartElement("SoundProject"); //Project sound sets. x.WriteStartElement("ProjectSoundSets"); x.WriteStartElement("ProjectSoundSet"); x.WriteAttributeString("Name", projectName); x.WriteStartElement("Parameters"); x.WriteElementString("FilePath", projectName + "." + (mode == WriteMode.CTR ? "c" : "f") + "sst"); x.WriteEndElement(); //Parameters. x.WriteEndElement(); //Project sound set. x.WriteEndElement(); //Project sound sets. //Sound archive player. x.WriteStartElement("SoundArchivePlayer"); x.WriteStartElement("Parameters"); x.WriteElementString("SoundArchivePlayerSequenceSoundCount", "" + a.MaxSequences); x.WriteElementString("SoundArchivePlayerSequenceTrackCount", "" + a.MaxSequenceTracks); x.WriteElementString("SoundArchivePlayerStreamChannelCount", "" + a.MaxStreamChannels); x.WriteElementString("SoundArchivePlayerStreamBufferTimes", "" + a.StreamBufferTimes); x.WriteElementString("SoundArchivePlayerStreamSoundCount", "" + a.MaxStreamSounds); x.WriteElementString("SoundArchivePlayerWaveSoundCount", "" + a.MaxWaveSounds); x.WriteEndElement(); //Parameters. x.WriteEndElement(); //Sound archive player. //Convert. x.WriteStartElement("Convert"); x.WriteStartElement("Parameters"); x.WriteElementString("DoWarnUnreferencedItems", "False"); x.WriteElementString("DoWarnDisableGroupItemTargets", "False"); if (mode != WriteMode.CTR) { x.WriteElementString("DoWarnPCBinariesForAACNotFound", "True"); } x.WriteElementString("ExcludeStringTable", "False"); if (mode != WriteMode.CTR) { x.WriteElementString("DoOutputPCBinariesForAAC", "True"); } x.WriteElementString("ExternalFileDirectoryPath", "stream"); x.WriteElementString("UserManagementFileOutputDirectoryPath", "userManagementFiles"); x.WriteElementString("IntermediateOutputDirectoryPath", "cache"); x.WriteElementString("InGameEditCacheOutputDirectoryPath", "editCache"); x.WriteElementString("IsPreConvertCommandsEnabled", "True"); x.WriteElementString("IsPostConvertCommandsEnabled", "True"); x.WriteElementString("KeepIntermediateTextSequence", "True"); x.WriteElementString("OutputLabel", "False"); x.WriteElementString("OutputDirectoryPath", "output"); x.WriteElementString("SmfTimebase", "96"); x.WriteEndElement(); //Parameters. x.WriteStartElement("PreConvertCommands"); x.WriteEndElement(); x.WriteStartElement("PostConvertCommands"); x.WriteEndElement(); x.WriteEndElement(); //Convert. //Item naming. x.WriteStartElement("ItemNaming"); x.WriteStartElement("Parameters"); x.WriteElementString("BankNamePrefix", "BANK_"); x.WriteElementString("CaseChange", "ToUpper"); x.WriteElementString("GroupNamePrefix", "GROUP_"); x.WriteElementString("HasPrefix", "True"); x.WriteElementString("InstrumentNamePrefix", "INST_"); x.WriteElementString("InvalidCharChange", "ReplaceToUnderscore"); x.WriteElementString("PlayerNamePrefix", "PLAYER_"); x.WriteElementString("SequenceSoundNamePrefix", "SEQ_"); x.WriteElementString("SequenceSoundSetNamePrefix", "SEQSET_"); x.WriteElementString("StreamSoundNamePrefix", "STRM_"); x.WriteElementString("WaveArchiveNamePrefix", "WARC_"); x.WriteElementString("WaveSoundNamePrefix", "WSD_"); x.WriteElementString("WaveSoundSetNamePrefix", "WSDSET_"); x.WriteElementString("ItemPastePostfix", "_copy"); x.WriteElementString("EnabledNameDelimiter", "True"); x.WriteElementString("NameDelimiter", "."); x.WriteEndElement(); //Parameters. x.WriteEndElement(); //Item naming. //Comment column text. x.WriteStartElement("CommentColumnText"); x.WriteStartElement("Parameters"); x.WriteElementString("CommentColumnText", "Comments"); x.WriteElementString("Comment1ColumnText", "Comment 1"); x.WriteElementString("Comment2ColumnText", "Comment 2"); x.WriteElementString("Comment3ColumnText", "Comment 3"); x.WriteElementString("Comment4ColumnText", "Comment 4"); x.WriteElementString("Comment5ColumnText", "Comment 5"); x.WriteElementString("Comment6ColumnText", "Comment 6"); x.WriteElementString("Comment7ColumnText", "Comment 7"); x.WriteElementString("Comment8ColumnText", "Comment 8"); x.WriteElementString("Comment9ColumnText", "Comment 9"); x.WriteEndElement(); //Parameters. x.WriteEndElement(); //Comment column text. //Color comment. x.WriteStartElement("ColorComment"); x.WriteStartElement("Parameters"); x.WriteStartElement("ColorComment0"); x.WriteEndElement(); x.WriteStartElement("ColorComment1"); x.WriteEndElement(); x.WriteStartElement("ColorComment2"); x.WriteEndElement(); x.WriteStartElement("ColorComment3"); x.WriteEndElement(); x.WriteStartElement("ColorComment4"); x.WriteEndElement(); x.WriteStartElement("ColorComment5"); x.WriteEndElement(); x.WriteStartElement("ColorComment6"); x.WriteEndElement(); x.WriteStartElement("ColorComment7"); x.WriteEndElement(); x.WriteStartElement("ColorComment8"); x.WriteEndElement(); x.WriteEndElement(); //Parameters. x.WriteEndElement(); //Color comment. //User commands. x.WriteStartElement("UserCommands"); x.WriteStartElement("UserCommand"); x.WriteAttributeString("Name", ""); x.WriteAttributeString("Command", ""); x.WriteAttributeString("IconFilePath", ""); x.WriteEndElement(); x.WriteStartElement("UserCommand"); x.WriteAttributeString("Name", ""); x.WriteAttributeString("Command", ""); x.WriteAttributeString("IconFilePath", ""); x.WriteEndElement(); x.WriteStartElement("UserCommand"); x.WriteAttributeString("Name", ""); x.WriteAttributeString("Command", ""); x.WriteAttributeString("IconFilePath", ""); x.WriteEndElement(); x.WriteStartElement("UserCommand"); x.WriteAttributeString("Name", ""); x.WriteAttributeString("Command", ""); x.WriteAttributeString("IconFilePath", ""); x.WriteEndElement(); x.WriteStartElement("UserCommand"); x.WriteAttributeString("Name", ""); x.WriteAttributeString("Command", ""); x.WriteAttributeString("IconFilePath", ""); x.WriteEndElement(); x.WriteStartElement("UserCommand"); x.WriteAttributeString("Name", ""); x.WriteAttributeString("Command", ""); x.WriteAttributeString("IconFilePath", ""); x.WriteEndElement(); x.WriteStartElement("UserCommand"); x.WriteAttributeString("Name", ""); x.WriteAttributeString("Command", ""); x.WriteAttributeString("IconFilePath", ""); x.WriteEndElement(); x.WriteStartElement("UserCommand"); x.WriteAttributeString("Name", ""); x.WriteAttributeString("Command", ""); x.WriteAttributeString("IconFilePath", ""); x.WriteEndElement(); x.WriteEndElement(); //User commands. x.WriteStartElement("SoundListOutputs"); x.WriteEndElement(); //User parameter settings. x.WriteStartElement("UserParameterSettings"); x.WriteStartElement("UserParameterSetting"); x.WriteAttributeString("Enabled", "true"); x.WriteStartElement("UserParameterStructures"); x.WriteEndElement(); x.WriteEndElement(); x.WriteStartElement("UserParameterSetting"); x.WriteAttributeString("Enabled", "true"); x.WriteStartElement("UserParameterStructures"); x.WriteEndElement(); x.WriteEndElement(); x.WriteStartElement("UserParameterSetting"); x.WriteAttributeString("Enabled", "true"); x.WriteStartElement("UserParameterStructures"); x.WriteEndElement(); x.WriteEndElement(); x.WriteStartElement("UserParameterSetting"); x.WriteAttributeString("Enabled", "true"); x.WriteStartElement("UserParameterStructures"); x.WriteEndElement(); x.WriteEndElement(); x.WriteEndElement(); //Project setting. x.WriteStartElement("ProjectSetting"); x.WriteStartElement("Parameters"); x.WriteStartElement("ProjectComment"); x.WriteEndElement(); x.WriteEndElement(); x.WriteEndElement(); //File event. x.WriteStartElement("FileEvent"); x.WriteStartElement("Parameters"); x.WriteElementString("IsFileSavePreCommandEnabled", "False"); x.WriteElementString("IsFileSavePostCommandEnabled", "False"); x.WriteStartElement("FileSavePreCommandPath"); x.WriteEndElement(); x.WriteStartElement("FileSavePostCommandPath"); x.WriteEndElement(); x.WriteEndElement(); x.WriteEndElement(); //Snd edit. x.WriteStartElement("SndEdit"); x.WriteStartElement("Parameters"); x.WriteElementString("SyncPort", mode == WriteMode.CTR ? "10" : "54086"); x.WriteElementString("SyncPort", mode == WriteMode.CTR ? "11" : "54087"); x.WriteElementString("SyncPort", mode == WriteMode.CTR ? "12" : "54088"); x.WriteEndElement(); x.WriteEndElement(); x.WriteEndElement(); //Sound project. x.WriteEndElement(); //Body. x.WriteEndElement(); //SoundProject. x.WriteEndDocument(); x.Flush(); } }
/// <summary> /// Write bank file. /// </summary> /// <param name="folderPath">Directory to write BNK.</param> /// <param name="a">Sound archive.</param> /// <param name="b">Bank to export.</param> /// <param name="mode">Write mode.</param> public static void WriteBnk(string folderPath, SoundArchive a, BankEntry b, WriteMode mode) { using (FileStream fileStream = new FileStream(folderPath + "/Files/Banks/" + Path.GetFileNameWithoutExtension(b.File.FileName) + "." + (mode == WriteMode.CTR ? "c" : "f") + "bnk", FileMode.Create)) using (StreamWriter sw = new StreamWriter(fileStream)) using (XmlTextWriter x = new XmlTextWriter(sw)) { x.Formatting = Formatting.Indented; x.Indentation = 2; x.WriteStartDocument(); x.WriteStartElement("Bank"); x.WriteAttributeString(new XAttribute(XNamespace.Xmlns + "xsi", "h").ToString().Trim("=\"h\"".ToCharArray()), "http://www.w3.org/2001/XMLSchema-instance"); x.WriteAttributeString(new XAttribute(XNamespace.Xmlns + "xsd", "h").ToString().Trim("=\"h\"".ToCharArray()), "http://www.w3.org/2001/XMLSchema"); //Get version. string version = "1."; switch (mode) { case WriteMode.Cafe: version += "0"; break; case WriteMode.CTR: version += "0"; break; case WriteMode.NX: version += "0"; break; } version += ".0.0"; x.WriteAttributeString("Version", version); //Get platform. string platform = "Any"; switch (mode) { case WriteMode.Cafe: platform = "Cafe"; break; case WriteMode.CTR: platform = "Ctr"; break; } x.WriteAttributeString("Platform", platform); x.WriteAttributeString(new XAttribute(XNamespace.Xmlns + "h", "h").ToString().Trim(":=\"hh\"".ToCharArray()), "NintendoWare.SoundFoundation.FileFormats.NintendoWare"); //Write head with title. x.WriteStartElement("Head"); x.WriteElementString("Title", b.Name); x.WriteEndElement(); //Head. //Body. x.WriteStartElement("Body"); //Bank. x.WriteStartElement("Bank"); //Items. x.WriteStartElement("Items"); //Write each instrument. List <string> refs = new List <string>(); var file = (b.File.File as SoundBank); int count = 1; int num = -1; foreach (var i in file.Instruments) { //Increment number. num++; if (i == null) { continue; } //Start instrument. x.WriteStartElement("Instrument"); x.WriteAttributeString("Name", "INST_" + (count - 1)); //Useless parameters. StartUselessParameters(x); x.WriteElementString("ProgramNo", num + ""); x.WriteElementString("Volume", "127"); x.WriteElementString("PitchSemitones", "0"); x.WriteElementString("PitchCents", "0"); x.WriteStartElement("Envelope"); x.WriteStartElement("Parameters"); x.WriteElementString("Attack", "127"); x.WriteElementString("Decay", "127"); x.WriteElementString("Sustain", "127"); x.WriteElementString("Hold", "0"); x.WriteElementString("Release", "127"); x.WriteEndElement(); //Parameters. x.WriteEndElement(); //Envelope. //Envelope mode. x.WriteElementString("InstrumentEnvelopeMode", (i as DirectInstrument) == null ? "VelocityRegion" : "Instrument"); //End parameters. EndUselessParameters(x); //Items. x.WriteStartElement("Items"); //Switch type. switch (i.GetInstrumentType()) { //Direct. case InstrumentType.Direct: var d = i as DirectInstrument; WriteKeyRegion(d.KeyRegion, a, b, 0, 127, x); break; //Index. case InstrumentType.Index: var ind = i as IndexInstrument; int last = 0; foreach (var k in ind) { if (k.Value != null) { WriteKeyRegion(k.Value, a, b, last, k.Key, x); } last = k.Key + 1; } break; //Range. case InstrumentType.Range: var r = i as RangeInstrument; int next = r.StartNote; foreach (var k in r) { if (k != null) { WriteKeyRegion(k, a, b, next, next, x); } next++; } break; } //End items. x.WriteEndElement(); //Add the program number to the list. refs.Add("#define INST_" + (count - 1) + "\t" + count++); //End instrument. x.WriteEndElement(); } File.WriteAllLines(folderPath + "/Files/Banks/" + Path.GetFileNameWithoutExtension(b.File.FileName) + "." + (mode == WriteMode.CTR ? "c" : "f") + "inl", refs.ToArray()); //End it. x.WriteEndElement(); //Items. x.WriteEndElement(); //Bank. x.WriteEndElement(); //Body. x.WriteEndElement(); //Bank. x.WriteEndDocument(); x.Flush(); } }