Beispiel #1
0
 public static IServiceCollection AddHygouServices(this IServiceCollection sc, EnvironmentType envType)
 {
     sc.AddSetting <HygouSetting>();
     sc.AddInitializer("data", "初始化Hygou数据", sp => SystemInitializer.Initialize(sp, envType));
     sc.AddInitializer("product", "初始化Hygou产品", sp => SampleImporter.ImportSamples(sp));
     sc.InitServices("初始化服务", NewSerivces);
     return(sc);
 }
        private void Make_Hitsounds(Arguments arg, BackgroundWorker worker, DoWorkEventArgs _)
        {
            if (arg.Debug)
            {
                // 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, new VolumeBalancingArgs(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, 40);

                // Convert the packages to hitsounds that fit on an osu standard map
                CompleteHitsounds completeHitsounds = HitsoundConverter.GetCompleteHitsounds(samplePackages, loadedSamples);
                UpdateProgressBar(worker, 60);

                int samples = completeHitsounds.CustomIndices.SelectMany(ci => ci.Samples.Values).Count(h => h.Any(SampleImporter.ValidateSampleArgs));
                UpdateProgressBar(worker, 80);

                int greenlines = 0;
                int lastIndex  = -1;
                foreach (var hit in completeHitsounds.Hitsounds.Where(hit => hit.CustomIndex != lastIndex))
                {
                    lastIndex = hit.CustomIndex;
                    greenlines++;
                }
                UpdateProgressBar(worker, 100);

                MessageBox.Show(
                    $"Number of sample indices: {completeHitsounds.CustomIndices.Count}, Number of samples: {samples}, Number of greenlines: {greenlines}");
            }
            else
            {
                // 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, new VolumeBalancingArgs(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);

                // 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, 80);

                // Export the hitsound .osu and sound samples
                HitsoundExporter.ExportCompleteHitsounds(arg.ExportFolder, arg.BaseBeatmap, completeHitsounds, loadedSamples);
                UpdateProgressBar(worker, 99);

                // Open export folder
                System.Diagnostics.Process.Start(arg.ExportFolder);
            }
            // Collect garbage
            GC.Collect();

            UpdateProgressBar(worker, 100);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }