private string Make_Hitsounds(HitsoundStudioVm arg, BackgroundWorker worker, DoWorkEventArgs _) { string result = string.Empty; if (arg.HitsoundExportModeSetting == HitsoundStudioVm.HitsoundExportMode.Standard) { // Convert the multiple layers into packages that have the samples from all the layers at one specific time List <SamplePackage> samplePackages = HitsoundConverter.ZipLayers(arg.HitsoundLayers, arg.DefaultSample); UpdateProgressBar(worker, 10); // Balance the volume between greenlines and samples HitsoundConverter.BalanceVolumes(samplePackages, 0, false); UpdateProgressBar(worker, 20); // Load the samples so validation can be done HashSet <SampleGeneratingArgs> allSampleArgs = new HashSet <SampleGeneratingArgs>(); foreach (SamplePackage sp in samplePackages) { allSampleArgs.UnionWith(sp.Samples.Select(o => o.SampleArgs)); } var loadedSamples = SampleImporter.ImportSamples(allSampleArgs); UpdateProgressBar(worker, 30); // Convert the packages to hitsounds that fit on an osu standard map CompleteHitsounds completeHitsounds = HitsoundConverter.GetCompleteHitsounds(samplePackages, loadedSamples); UpdateProgressBar(worker, 60); if (arg.ShowResults) { // Count the number of samples int samples = completeHitsounds.CustomIndices.SelectMany(ci => ci.Samples.Values) .Count(h => h.Any(SampleImporter.ValidateSampleArgs)); // Count the number of changes of custom index int greenlines = 0; int lastIndex = -1; foreach (var hit in completeHitsounds.Hitsounds.Where(hit => hit.CustomIndex != lastIndex)) { lastIndex = hit.CustomIndex; greenlines++; } result = $"Number of sample indices: {completeHitsounds.CustomIndices.Count}, " + $"Number of samples: {samples}, Number of greenlines: {greenlines}"; } if (arg.DeleteAllInExportFirst && (arg.ExportSamples || arg.ExportMap)) { // Delete all files in the export folder before filling it again DirectoryInfo di = new DirectoryInfo(arg.ExportFolder); foreach (FileInfo file in di.GetFiles()) { file.Delete(); } } UpdateProgressBar(worker, 70); // Export the hitsound map and sound samples if (arg.ExportMap) { HitsoundExporter.ExportHitsounds(completeHitsounds.Hitsounds, arg.BaseBeatmap, arg.ExportFolder); } UpdateProgressBar(worker, 80); if (arg.ExportSamples) { HitsoundExporter.ExportCustomIndices(completeHitsounds.CustomIndices, arg.ExportFolder, loadedSamples); } UpdateProgressBar(worker, 99); } else if (arg.HitsoundExportModeSetting == HitsoundStudioVm.HitsoundExportMode.Coinciding) { List <SamplePackage> samplePackages = HitsoundConverter.ZipLayers(arg.HitsoundLayers, arg.DefaultSample, 0, false); HitsoundConverter.BalanceVolumes(samplePackages, 0, false, true); UpdateProgressBar(worker, 20); Dictionary <SampleGeneratingArgs, SampleSoundGenerator> loadedSamples = null; Dictionary <SampleGeneratingArgs, string> sampleNames = null; Dictionary <SampleGeneratingArgs, Vector2> samplePositions = null; var hitsounds = HitsoundConverter.GetHitsounds(samplePackages, ref loadedSamples, ref sampleNames, ref samplePositions); // Load the samples so validation can be done UpdateProgressBar(worker, 50); if (arg.ShowResults) { result = "Number of sample indices: 0, " + $"Number of samples: {loadedSamples.Count}, Number of greenlines: 0"; } if (arg.DeleteAllInExportFirst && (arg.ExportSamples || arg.ExportMap)) { // Delete all files in the export folder before filling it again DirectoryInfo di = new DirectoryInfo(arg.ExportFolder); foreach (FileInfo file in di.GetFiles()) { file.Delete(); } } UpdateProgressBar(worker, 60); if (arg.ExportMap) { HitsoundExporter.ExportHitsounds(hitsounds, arg.BaseBeatmap, arg.ExportFolder, false); } UpdateProgressBar(worker, 70); if (arg.ExportSamples) { HitsoundExporter.ExportLoadedSamples(loadedSamples, arg.ExportFolder, sampleNames); } } else if (arg.HitsoundExportModeSetting == HitsoundStudioVm.HitsoundExportMode.Storyboard) { List <SamplePackage> samplePackages = HitsoundConverter.ZipLayers(arg.HitsoundLayers, arg.DefaultSample, 0, false); HitsoundConverter.BalanceVolumes(samplePackages, 0, false, true); UpdateProgressBar(worker, 20); Dictionary <SampleGeneratingArgs, SampleSoundGenerator> loadedSamples = null; Dictionary <SampleGeneratingArgs, string> sampleNames = null; Dictionary <SampleGeneratingArgs, Vector2> samplePositions = null; var hitsounds = HitsoundConverter.GetHitsounds(samplePackages, ref loadedSamples, ref sampleNames, ref samplePositions); // Load the samples so validation can be done UpdateProgressBar(worker, 50); if (arg.ShowResults) { result = "Number of sample indices: 0, " + $"Number of samples: {loadedSamples.Count}, Number of greenlines: 0"; } if (arg.DeleteAllInExportFirst && (arg.ExportSamples || arg.ExportMap)) { // Delete all files in the export folder before filling it again DirectoryInfo di = new DirectoryInfo(arg.ExportFolder); foreach (FileInfo file in di.GetFiles()) { file.Delete(); } } UpdateProgressBar(worker, 60); if (arg.ExportMap) { HitsoundExporter.ExportHitsounds(hitsounds, arg.BaseBeatmap, arg.ExportFolder, false, true); } UpdateProgressBar(worker, 70); if (arg.ExportSamples) { HitsoundExporter.ExportLoadedSamples(loadedSamples, arg.ExportFolder, sampleNames); } } // Open export folder if (arg.ExportSamples || arg.ExportMap) { System.Diagnostics.Process.Start(arg.ExportFolder); } // Collect garbage GC.Collect(); UpdateProgressBar(worker, 100); return(result); }
private string Make_Hitsounds(HitsoundStudioVm arg, BackgroundWorker worker, DoWorkEventArgs _) { string result = string.Empty; bool validateSampleFile = !(arg.SingleSampleExportFormat == HitsoundExporter.SampleExportFormat.MidiChords || arg.MixedSampleExportFormat == HitsoundExporter.SampleExportFormat.MidiChords); var comparer = new SampleGeneratingArgsComparer(validateSampleFile); if (arg.HitsoundExportModeSetting == HitsoundStudioVm.HitsoundExportMode.Standard) { // Convert the multiple layers into packages that have the samples from all the layers at one specific time // Don't add default sample when exporting midi files because that's not a final export. List <SamplePackage> samplePackages = HitsoundConverter.ZipLayers(arg.HitsoundLayers, arg.DefaultSample, arg.ZipLayersLeniency, validateSampleFile); UpdateProgressBar(worker, 10); // Balance the volume between greenlines and samples HitsoundConverter.BalanceVolumes(samplePackages, 0, false); UpdateProgressBar(worker, 20); // Load the samples so validation can be done HashSet <SampleGeneratingArgs> allSampleArgs = new HashSet <SampleGeneratingArgs>(comparer); foreach (SamplePackage sp in samplePackages) { allSampleArgs.UnionWith(sp.Samples.Select(o => o.SampleArgs)); } var loadedSamples = SampleImporter.ImportSamples(allSampleArgs, comparer); UpdateProgressBar(worker, 30); // Convert the packages to hitsounds that fit on an osu standard map CompleteHitsounds completeHitsounds = HitsoundConverter.GetCompleteHitsounds(samplePackages, loadedSamples, arg.UsePreviousSampleSchema ? arg.PreviousSampleSchema.GetCustomIndices() : null, arg.AllowGrowthPreviousSampleSchema, arg.FirstCustomIndex, validateSampleFile, comparer); UpdateProgressBar(worker, 60); // Save current sample schema if (!arg.UsePreviousSampleSchema) { arg.PreviousSampleSchema = new SampleSchema(completeHitsounds.CustomIndices); } else if (arg.AllowGrowthPreviousSampleSchema) { arg.PreviousSampleSchema.MergeWith(new SampleSchema(completeHitsounds.CustomIndices)); } if (arg.ShowResults) { // Count the number of samples int samples = completeHitsounds.CustomIndices.SelectMany(ci => ci.Samples.Values) .Count(h => h.Any(o => SampleImporter.ValidateSampleArgs(o, loadedSamples, validateSampleFile))); // Count the number of changes of custom index int greenlines = 0; int lastIndex = -1; foreach (var hit in completeHitsounds.Hitsounds.Where(hit => hit.CustomIndex != lastIndex)) { lastIndex = hit.CustomIndex; greenlines++; } result = $"Number of sample indices: {completeHitsounds.CustomIndices.Count}, " + $"Number of samples: {samples}, Number of greenlines: {greenlines}"; } if (arg.DeleteAllInExportFirst && (arg.ExportSamples || arg.ExportMap)) { // Delete all files in the export folder before filling it again DirectoryInfo di = new DirectoryInfo(arg.ExportFolder); foreach (FileInfo file in di.GetFiles()) { file.Delete(); } } UpdateProgressBar(worker, 70); // Export the hitsound map and sound samples if (arg.ExportMap) { HitsoundExporter.ExportHitsounds(completeHitsounds.Hitsounds, arg.BaseBeatmap, arg.ExportFolder, arg.HitsoundDiffName, arg.HitsoundExportGameMode, true, false); } UpdateProgressBar(worker, 80); if (arg.ExportSamples) { HitsoundExporter.ExportCustomIndices(completeHitsounds.CustomIndices, arg.ExportFolder, loadedSamples, arg.SingleSampleExportFormat, arg.MixedSampleExportFormat, comparer); } UpdateProgressBar(worker, 99); } else if (arg.HitsoundExportModeSetting == HitsoundStudioVm.HitsoundExportMode.Coinciding) { List <SamplePackage> samplePackages = HitsoundConverter.ZipLayers(arg.HitsoundLayers, arg.DefaultSample, 0, false); HitsoundConverter.BalanceVolumes(samplePackages, 0, false, true); UpdateProgressBar(worker, 20); Dictionary <SampleGeneratingArgs, SampleSoundGenerator> loadedSamples = null; Dictionary <SampleGeneratingArgs, string> sampleNames = arg.UsePreviousSampleSchema ? arg.PreviousSampleSchema?.GetSampleNames(comparer) : null; Dictionary <SampleGeneratingArgs, Vector2> samplePositions = null; var hitsounds = HitsoundConverter.GetHitsounds(samplePackages, ref loadedSamples, ref sampleNames, ref samplePositions, arg.HitsoundExportGameMode == GameMode.Mania, arg.AddCoincidingRegularHitsounds, arg.AllowGrowthPreviousSampleSchema, validateSampleFile, comparer); // Save current sample schema if (!arg.UsePreviousSampleSchema || arg.PreviousSampleSchema == null) { arg.PreviousSampleSchema = new SampleSchema(sampleNames); } else if (arg.AllowGrowthPreviousSampleSchema) { arg.PreviousSampleSchema.MergeWith(new SampleSchema(sampleNames)); } // Load the samples so validation can be done UpdateProgressBar(worker, 50); if (arg.ShowResults) { result = "Number of sample indices: 0, " + $"Number of samples: {loadedSamples.Count}, Number of greenlines: 0"; } if (arg.DeleteAllInExportFirst && (arg.ExportSamples || arg.ExportMap)) { // Delete all files in the export folder before filling it again DirectoryInfo di = new DirectoryInfo(arg.ExportFolder); foreach (FileInfo file in di.GetFiles()) { file.Delete(); } } UpdateProgressBar(worker, 60); if (arg.ExportMap) { HitsoundExporter.ExportHitsounds(hitsounds, arg.BaseBeatmap, arg.ExportFolder, arg.HitsoundDiffName, arg.HitsoundExportGameMode, false, false); } UpdateProgressBar(worker, 70); if (arg.ExportSamples) { HitsoundExporter.ExportLoadedSamples(loadedSamples, arg.ExportFolder, sampleNames, arg.SingleSampleExportFormat, comparer); } } else if (arg.HitsoundExportModeSetting == HitsoundStudioVm.HitsoundExportMode.Storyboard) { List <SamplePackage> samplePackages = HitsoundConverter.ZipLayers(arg.HitsoundLayers, arg.DefaultSample, 0, false); HitsoundConverter.BalanceVolumes(samplePackages, 0, false, true); UpdateProgressBar(worker, 20); Dictionary <SampleGeneratingArgs, SampleSoundGenerator> loadedSamples = null; Dictionary <SampleGeneratingArgs, string> sampleNames = arg.UsePreviousSampleSchema ? arg.PreviousSampleSchema?.GetSampleNames(comparer) : null; Dictionary <SampleGeneratingArgs, Vector2> samplePositions = null; var hitsounds = HitsoundConverter.GetHitsounds(samplePackages, ref loadedSamples, ref sampleNames, ref samplePositions, false, false, arg.AllowGrowthPreviousSampleSchema, validateSampleFile, comparer); // Save current sample schema if (!arg.UsePreviousSampleSchema || arg.PreviousSampleSchema == null) { arg.PreviousSampleSchema = new SampleSchema(sampleNames); } else if (arg.AllowGrowthPreviousSampleSchema) { arg.PreviousSampleSchema.MergeWith(new SampleSchema(sampleNames)); } // Load the samples so validation can be done UpdateProgressBar(worker, 50); if (arg.ShowResults) { result = "Number of sample indices: 0, " + $"Number of samples: {loadedSamples.Count}, Number of greenlines: 0"; } if (arg.DeleteAllInExportFirst && (arg.ExportSamples || arg.ExportMap)) { // Delete all files in the export folder before filling it again DirectoryInfo di = new DirectoryInfo(arg.ExportFolder); foreach (FileInfo file in di.GetFiles()) { file.Delete(); } } UpdateProgressBar(worker, 60); if (arg.ExportMap) { HitsoundExporter.ExportHitsounds(hitsounds, arg.BaseBeatmap, arg.ExportFolder, arg.HitsoundDiffName, arg.HitsoundExportGameMode, false, true); } UpdateProgressBar(worker, 70); if (arg.ExportSamples) { HitsoundExporter.ExportLoadedSamples(loadedSamples, arg.ExportFolder, sampleNames, arg.SingleSampleExportFormat, comparer); } } // Open export folder if (arg.ExportSamples || arg.ExportMap) { System.Diagnostics.Process.Start("explorer.exe", arg.ExportFolder); } // Collect garbage GC.Collect(); UpdateProgressBar(worker, 100); return(result); }