static public void Convert(string[] inArgs, long unitNumerator, long unitDenominator) { // configuration Configuration config = LoadConfig(); Configuration db = LoadDB(); int quantizeMeasure = config["BMS"].GetValue("QuantizeMeasure"); int quantizeNotes = config["BMS"].GetValue("QuantizeNotes"); // splash Splash.Show("Bemani to BeMusic Script"); Console.WriteLine("Timing: " + unitNumerator.ToString() + "/" + unitDenominator.ToString()); Console.WriteLine("Measure Quantize: " + quantizeMeasure.ToString()); // args string[] args; if (inArgs.Length > 0) { args = Subfolder.Parse(inArgs); } else { args = inArgs; } // debug args (if applicable) if (System.Diagnostics.Debugger.IsAttached && args.Length == 0) { Console.WriteLine(); Console.WriteLine("Debugger attached. Input file name:"); args = new string[] { Console.ReadLine() }; } // show usage if no args provided if (args.Length == 0) { Console.WriteLine(); Console.WriteLine("Usage: BemaniToBMS <input file>"); Console.WriteLine(); Console.WriteLine("Drag and drop with files and folders is fully supported for this application."); Console.WriteLine(); Console.WriteLine("Supported formats:"); Console.WriteLine("1, 2DX, CS, SD9, SSP"); } // process files for (int i = 0; i < args.Length; i++) { if (File.Exists(args[i])) { Console.WriteLine(); Console.WriteLine("Processing File: " + args[i]); string filename = args[i]; string IIDXDBName = Path.GetFileNameWithoutExtension(filename); while (IIDXDBName.StartsWith("0")) { IIDXDBName = IIDXDBName.Substring(1); } byte[] data = File.ReadAllBytes(args[i]); switch (Path.GetExtension(args[i]).ToUpper()) { case @".1": using (MemoryStream source = new MemoryStream(data)) { Bemani1 archive = Bemani1.Read(source, unitNumerator, unitDenominator); if (db[IIDXDBName]["TITLE"] != "") { for (int j = 0; j < archive.ChartCount; j++) { Chart chart = archive.Charts[j]; if (chart != null) { chart.Tags["TITLE"] = db[IIDXDBName]["TITLE"]; chart.Tags["ARTIST"] = db[IIDXDBName]["ARTIST"]; chart.Tags["GENRE"] = db[IIDXDBName]["GENRE"]; if (j < 6) { chart.Tags["PLAYLEVEL"] = db[IIDXDBName]["DIFFICULTYSP" + config["IIDX"]["DIFFICULTY" + j.ToString()]]; } else if (j < 12) { chart.Tags["PLAYLEVEL"] = db[IIDXDBName]["DIFFICULTYDP" + config["IIDX"]["DIFFICULTY" + j.ToString()]]; } } } } ConvertArchive(archive, config, args[i]); } break; case @".2DX": using (MemoryStream source = new MemoryStream(data)) { Console.WriteLine("Converting Samples"); Bemani2DX archive = Bemani2DX.Read(source); ConvertSounds(archive.Sounds, filename, 0.6f); } break; case @".CS": using (MemoryStream source = new MemoryStream(data)) ConvertChart(BeatmaniaIIDXCSNew.Read(source), config, filename, -1, null); break; case @".CS2": using (MemoryStream source = new MemoryStream(data)) ConvertChart(BeatmaniaIIDXCSOld.Read(source), config, filename, -1, null); break; case @".CS5": using (MemoryStream source = new MemoryStream(data)) ConvertChart(Beatmania5Key.Read(source), config, filename, -1, null); break; case @".CS9": break; case @".SD9": using (MemoryStream source = new MemoryStream(data)) { Sound sound = BemaniSD9.Read(source); string targetFile = Path.GetFileNameWithoutExtension(filename); string targetPath = Path.Combine(Path.GetDirectoryName(filename), targetFile) + ".wav"; sound.WriteFile(targetPath, 1.0f); } break; case @".SSP": using (MemoryStream source = new MemoryStream(data)) ConvertSounds(BemaniSSP.Read(source).Sounds, filename, 1.0f); break; } } } // wrap up Console.WriteLine("BemaniToBMS finished."); }
static public void RenderWAV(string[] inArgs, long unitNumerator, long unitDenominator) { Splash.Show("Render"); Console.WriteLine("Timing: " + unitNumerator.ToString() + "/" + unitDenominator.ToString()); string[] args; if (inArgs.Length > 0) { args = Subfolder.Parse(inArgs); } else { args = inArgs; } if (System.Diagnostics.Debugger.IsAttached && args.Length == 0) { Console.WriteLine(); Console.WriteLine("Debugger attached. Input file name:"); args = new string[] { Console.ReadLine() }; } if (args.Length == 0) { Console.WriteLine(); Console.WriteLine("Usage: Render2DX <files..>"); Console.WriteLine(); Console.WriteLine("Drag and drop with files and folders is fully supported for this application."); Console.WriteLine(); Console.WriteLine("You must have both the chart file (.1) and the sound file (.2dx)."); Console.WriteLine("Supported formats:"); Console.WriteLine("1, 2DX"); } Sound[] sounds = null; Chart[] charts = null; bool cancel = false; string outFile = null; foreach (string filename in args) { if (cancel) { break; } if (File.Exists(filename)) { switch (Path.GetExtension(filename).ToUpper()) { case @".1": if (charts == null) { Console.WriteLine(); Console.WriteLine("Valid charts:"); outFile = Path.Combine(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename)); using (MemoryStream mem = new MemoryStream(File.ReadAllBytes(filename))) { charts = Bemani1.Read(mem, unitNumerator, unitDenominator).Charts; for (int i = 0; i < charts.Length; i++) { if (charts[i] != null) { Console.Write(i.ToString() + " "); } } } Console.WriteLine(); } break; case @".2DX": if (sounds == null) { using (MemoryStream mem = new MemoryStream(File.ReadAllBytes(filename))) { sounds = Bemani2DX.Read(mem).Sounds; } } break; } } } if (!cancel && (sounds != null) && (charts != null)) { List <byte[]> rendered = new List <byte[]>(); List <int> renderedIndex = new List <int>(); for (int k = 0; k < charts.Length; k++) { Chart chart = charts[k]; if (chart == null) { continue; } Console.WriteLine("Rendering " + k.ToString()); byte[] data = ChartRenderer.Render(chart, sounds); int renderedCount = rendered.Count; int matchIndex = -1; bool match = false; for (int i = 0; i < renderedCount; i++) { int renderedLength = rendered[i].Length; if (renderedLength == data.Length) { byte[] renderedBytes = rendered[i]; match = true; for (int j = 0; j < renderedLength; j++) { if (renderedBytes[j] != data[j]) { match = false; break; } } if (match) { matchIndex = i; break; } } } if (!match) { Console.WriteLine("Writing unique " + k.ToString()); File.WriteAllBytes(outFile + "-" + Util.ConvertToDecimalString(k, 2) + ".wav", data); rendered.Add(data); renderedIndex.Add(k); } else { Console.WriteLine("Matches " + renderedIndex[matchIndex].ToString()); } } } }
static public void RenderWAV(string[] inArgs, long unitNumerator, long unitDenominator, bool idUseRenderAutoTip) { // configuration Configuration config = Configuration.LoadIIDXConfig(Common.configFileName); Configuration db = Common.LoadDB(); if (config["BMS"].GetBool("ForceRenderAutoTip")) { idUseRenderAutoTip = true; } Dictionary <int, int> ignore = new Dictionary <int, int>(); if (idUseRenderAutoTip) { ignore.Add(1, 1); ignore.Add(2, 2); } Splash.Show("Render"); Console.WriteLine("Timing: " + unitNumerator.ToString() + "/" + unitDenominator.ToString()); string output = config["BMS"]["Output"]; string[] args; if (inArgs.Length > 0) { args = Subfolder.Parse(inArgs); } else { args = inArgs; } if (System.Diagnostics.Debugger.IsAttached && args.Length == 0) { Console.WriteLine(); Console.WriteLine("Debugger attached. Input file name:"); args = new string[] { Console.ReadLine() }; } if (args.Length == 0) { Console.WriteLine(); Console.WriteLine("Usage: Render2DX <files..>"); Console.WriteLine(); Console.WriteLine("Drag and drop with files and folders is fully supported for this application."); Console.WriteLine(); Console.WriteLine("You must have both the chart file (.1) and the sound file (.2dx)."); Console.WriteLine("Supported formats:"); Console.WriteLine("1, 2DX"); } Dictionary <string, Sound[]> sounds = new Dictionary <string, Sound[]>(); Chart[] charts = null; bool cancel = false; string outFile = "0001"; string targetPath = null; string IIDXDBName = Path.GetFileNameWithoutExtension(args[0]); string title = IIDXDBName; string version = IIDXDBName.Substring(0, 2); if (IIDXDBName.Contains("pre")) { IIDXDBName = IIDXDBName.Substring(0, 5); } if (IIDXDBName.Length > 5) { IIDXDBName = IIDXDBName.Substring(0, 5); } while (IIDXDBName.StartsWith("0")) { IIDXDBName = IIDXDBName.Substring(1); } if (db[IIDXDBName]["TITLE"] != "") { title = db[IIDXDBName]["TITLE"]; title = Common.nameReplace(title); } foreach (string filename in args) { if (cancel) { break; } string tmp = Path.GetFileNameWithoutExtension(filename); string INDEX = "0"; if (tmp.Contains("pre")) { continue; } if (tmp.Length > 5) { INDEX = tmp.Substring(5); } if (File.Exists(filename)) { switch (Path.GetExtension(filename).ToUpper()) { case @".1": if (charts == null) { Console.WriteLine(); Console.WriteLine("Valid charts:"); if (!idUseRenderAutoTip) { outFile = Path.Combine(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename)); } using (MemoryStream mem = new MemoryStream(File.ReadAllBytes(filename))) { charts = Bemani1.Read(mem, unitNumerator, unitDenominator, ignore).Charts; for (int i = 0; i < charts.Length; i++) { if (charts[i] != null) { Console.Write(i.ToString() + " "); } } } Console.WriteLine(); } break; case @".2DX": if (!sounds.ContainsKey(INDEX)) { using (MemoryStream mem = new MemoryStream(File.ReadAllBytes(filename))) { sounds.Add(INDEX, Bemani2DX.Read(mem).Sounds); } } break; case @".S3P": if (!sounds.ContainsKey(INDEX)) { using (MemoryStream mem = new MemoryStream(File.ReadAllBytes(filename))) { sounds.Add(INDEX, BemaniS3P.Read(mem).Sounds); } } break; } } } if (!cancel && (sounds != null) && (charts != null)) { List <byte[]> rendered = new List <byte[]>(); List <int> renderedIndex = new List <int>(); for (int k = 0; k < charts.Length; k++) { string keySet = "0"; if (k < 6) { keySet = db[IIDXDBName]["KEYSETSP" + config["IIDX"]["DIFFICULTY" + k.ToString()]]; } else if (k < 12) { keySet = db[IIDXDBName]["KEYSETDP" + config["IIDX"]["DIFFICULTY" + k.ToString()]]; } Chart chart = charts[k]; if (chart == null) { continue; } //Console.WriteLine(""); Console.WriteLine("Rendering " + k.ToString()); //Console.WriteLine("Use keySet " + keySet); Sound[] tmpSound; if (!sounds.TryGetValue(keySet, out tmpSound)) { Console.WriteLine("not found keySet"); if (!sounds.TryGetValue("0", out tmpSound)) { Console.WriteLine("not found sounds \n continue"); continue; } } byte[] data = ChartRenderer.Render(chart, tmpSound); int renderedCount = rendered.Count; int matchIndex = -1; bool match = false; for (int i = 0; i < renderedCount; i++) { int renderedLength = rendered[i].Length; if (renderedLength == data.Length) { byte[] renderedBytes = rendered[i]; match = true; for (int j = 0; j < renderedLength; j++) { if (renderedBytes[j] != data[j]) { match = false; break; } } if (match) { matchIndex = i; break; } } } if (idUseRenderAutoTip) { string targetFolder = "sounds"; if (keySet != "0") { targetFolder = "sounds_" + keySet; } targetPath = Path.Combine(output, version, title, targetFolder); match = false; } if (!match) { if (idUseRenderAutoTip) { Console.WriteLine("Writing unique " + (k < 6 ? 1 : 3) + config["IIDX"].GetValue("DIFFICULTY" + k.ToString())); Common.SafeCreateDirectory(targetPath); File.WriteAllBytes(targetPath + "\\" + outFile + "-" + (k < 6 ? 1 : 3) + config["IIDX"].GetValue("DIFFICULTY" + k.ToString()) + ".wav", data); } else { Console.WriteLine("Writing unique " + k.ToString()); File.WriteAllBytes(outFile + " -" + Util.ConvertToDecimalString(k, 2) + ".wav", data); } rendered.Add(data); renderedIndex.Add(k); } else { Console.WriteLine("Matches " + renderedIndex[matchIndex].ToString()); } } } }
static public void Convert(string[] inArgs, long unitNumerator, long unitDenominator, bool idUseRenderAutoTip = false) { // configuration Configuration config = Configuration.LoadIIDXConfig(Common.configFileName); Configuration db = Common.LoadDB(); int quantizeMeasure = config["BMS"].GetValue("QuantizeMeasure"); int quantizeNotes = config["BMS"].GetValue("QuantizeNotes"); // splash Splash.Show("Bemani to BeMusic Script"); Console.WriteLine("Timing: " + unitNumerator.ToString() + "/" + unitDenominator.ToString()); Console.WriteLine("Measure Quantize: " + quantizeMeasure.ToString()); // args string[] args; if (inArgs.Length > 0) { args = Subfolder.Parse(inArgs); } else { args = inArgs; } // debug args (if applicable) if (System.Diagnostics.Debugger.IsAttached && args.Length == 0) { Console.WriteLine(); Console.WriteLine("Debugger attached. Input file name:"); args = new string[] { Console.ReadLine() }; } // show usage if no args provided if (args.Length == 0) { Console.WriteLine(); Console.WriteLine("Usage: BemaniToBMS <input file>"); Console.WriteLine(); Console.WriteLine("Drag and drop with files and folders is fully supported for this application."); Console.WriteLine(); Console.WriteLine("Supported formats:"); Console.WriteLine("1, 2DX, S3P, CS, SD9, SSP"); } string output = config["BMS"]["Output"]; // process files for (int i = 0; i < args.Length; i++) { try { if (File.Exists(args[i])) { Console.WriteLine(); Console.WriteLine("Processing File: " + args[i]); string filename = args[i]; if (output == "") { output = Path.GetDirectoryName(filename) + "\\"; } string IIDXDBName = Path.GetFileNameWithoutExtension(filename); string version = IIDXDBName.Substring(0, 2); bool isPre2DX = false; string INDEX = null; if (IIDXDBName.Contains("pre")) { isPre2DX = true; IIDXDBName = IIDXDBName.Substring(0, 5); } if (IIDXDBName.Length > 5) { INDEX = IIDXDBName.Substring(5); IIDXDBName = IIDXDBName.Substring(0, 5); } while (IIDXDBName.StartsWith("0")) { IIDXDBName = IIDXDBName.Substring(1); } byte[] data = File.ReadAllBytes(args[i]); switch (Path.GetExtension(args[i]).ToUpper()) { case @".1": using (MemoryStream source = new MemoryStream(data)) { Dictionary <int, int> ignore = new Dictionary <int, int>(); if (idUseRenderAutoTip) { Console.WriteLine("Convert AutoTips"); Console.WriteLine(args[i].Remove(args[i].Length - 8)); string[] files = System.IO.Directory.GetFiles(args[i].Remove(args[i].Length - 8), "*", SearchOption.AllDirectories); Render.RenderWAV(files, 1, 1000, true); ignore.Add(3, 3); } Bemani1 archive = Bemani1.Read(source, unitNumerator, unitDenominator, ignore); if (db[IIDXDBName]["TITLE"] != "") { for (int j = 0; j < archive.ChartCount; j++) { Chart chart = archive.Charts[j]; if (chart != null) { chart.Tags["TITLE"] = db[IIDXDBName]["TITLE"]; chart.Tags["ARTIST"] = db[IIDXDBName]["ARTIST"]; chart.Tags["GENRE"] = db[IIDXDBName]["GENRE"]; chart.Tags["VIDEO"] = db[IIDXDBName]["VIDEO"]; chart.Tags["VIDEODELAY"] = db[IIDXDBName]["VIDEODELAY"]; if (j < 6) { chart.Tags["PLAYLEVEL"] = db[IIDXDBName]["DIFFICULTYSP" + config["IIDX"]["DIFFICULTY" + j.ToString()]]; chart.Tags["KEYSET"] = db[IIDXDBName]["KEYSETSP" + config["IIDX"]["DIFFICULTY" + j.ToString()]]; chart.Tags["ISUSERENDERAUTOTIP"] = idUseRenderAutoTip.ToString(); } else if (j < 12) { chart.Tags["PLAYLEVEL"] = db[IIDXDBName]["DIFFICULTYDP" + config["IIDX"]["DIFFICULTY" + j.ToString()]]; chart.Tags["KEYSET"] = db[IIDXDBName]["KEYSETDP" + config["IIDX"]["DIFFICULTY" + j.ToString()]]; chart.Tags["ISUSERENDERAUTOTIP"] = idUseRenderAutoTip.ToString(); } } } } ConvertArchive(archive, config, args[i], version, idUseRenderAutoTip); } break; case @".2DX": using (MemoryStream source = new MemoryStream(data)) { Console.WriteLine("Converting Samples"); Bemani2DX archive = Bemani2DX.Read(source); float volume = 0.6f; string title = ""; if (db[IIDXDBName]["TITLE"] != "") { volume = float.Parse(db[IIDXDBName]["VOLUME"]) / 127.0f; title = db[IIDXDBName]["TITLE"]; } ConvertSounds(archive.Sounds, filename, volume, INDEX, output, title, isPre2DX, version); } break; case @".S3P": using (MemoryStream source = new MemoryStream(data)) { Console.WriteLine("Converting Samples"); BemaniS3P archive = BemaniS3P.Read(source); float volume = 0.6f; string title = ""; if (db[IIDXDBName]["TITLE"] != "") { volume = float.Parse(db[IIDXDBName]["VOLUME"]) / 127.0f; title = db[IIDXDBName]["TITLE"]; } ConvertSounds(archive.Sounds, filename, volume, INDEX, output, title, isPre2DX, version); } break; case @".CS": using (MemoryStream source = new MemoryStream(data)) ConvertChart(BeatmaniaIIDXCSNew.Read(source), config, filename, -1, null); break; case @".CS2": using (MemoryStream source = new MemoryStream(data)) ConvertChart(BeatmaniaIIDXCSOld.Read(source), config, filename, -1, null); break; case @".CS5": using (MemoryStream source = new MemoryStream(data)) ConvertChart(Beatmania5Key.Read(source), config, filename, -1, null); break; case @".CS9": break; case @".SD9": using (MemoryStream source = new MemoryStream(data)) { Sound sound = BemaniSD9.Read(source); string targetFile = Path.GetFileNameWithoutExtension(filename); string targetPath = Path.Combine(Path.GetDirectoryName(filename), targetFile) + ".wav"; sound.WriteFile(targetPath, 1.0f); } break; case @".SSP": using (MemoryStream source = new MemoryStream(data)) ConvertSounds(BemaniSSP.Read(source).Sounds, filename, 1.0f); break; } } } catch (Exception e) { Console.WriteLine("{0} Exception caught." + args[i], e); } } // wrap up Console.WriteLine("BemaniToBMS finished."); }