Exemplo n.º 1
0
        public async void GenerateBeatmap()
        {
            if (State != EditorState.READY)
            {
                return;
            }

            // pre
            SetState(EditorState.GENERATING_BEATMAP);

            // main phase
            Beatmap exportBeatmap = NewBeatmap.Copy();

            ModifyBeatmapMetadata(exportBeatmap, BpmMultiplier, ChangePitch);
            if (!File.Exists(JunUtils.GetBeatmapDirectoryName(OriginalBeatmap) + "\\" + exportBeatmap.AudioFilename))
            {
                string inFile  = $"{Path.GetDirectoryName(OriginalBeatmap.Filename)}\\{OriginalBeatmap.AudioFilename}";
                string outFile = $"{Path.GetDirectoryName(exportBeatmap.Filename)}\\{exportBeatmap.AudioFilename}";
                await Task.Run(() => SongSpeedChanger.GenerateAudioFile(inFile, outFile, BpmMultiplier, ChangePitch));

                // take note of this mp3 in a text file, so we can clean it up later
                string mp3ManifestFile = Properties.Settings.Default.SongsFolder + "\\modified_mp3_list.txt";
                using (var writer = File.AppendText(mp3ManifestFile))
                {
                    string beatmapFolder   = Path.GetDirectoryName(exportBeatmap.Filename).Replace(Properties.Settings.Default.SongsFolder + "\\", "");
                    string mp3RelativePath = beatmapFolder + "\\" + exportBeatmap.AudioFilename;
                    writer.WriteLine(mp3RelativePath + " | " + exportBeatmap.Filename);
                }
            }
            exportBeatmap.Save();

            // post
            form.PlayDoneSound();
            SetState(EditorState.READY);
        }
Exemplo n.º 2
0
        public void GenerateBeatmap()
        {
            if (State != EditorState.READY)
            {
                return;
            }

            SetState(EditorState.GENERATING_BEATMAP);

            bool compensateForDT = (NewBeatmap.ApproachRate > 10 || NewBeatmap.OverallDifficulty > 10);

            // Set metadata
            Beatmap exportBeatmap = new Beatmap(NewBeatmap);

            ModifyBeatmapMetadata(exportBeatmap, BpmMultiplier, ChangePitch, compensateForDT);
            if (NoSpinners)
            {
                exportBeatmap.RemoveSpinners();
            }

            // Slow down map by 1.5x
            if (compensateForDT)
            {
                exportBeatmap.ApproachRate      = DifficultyCalculator.CalculateMultipliedAR(NewBeatmap, 1 / 1.5M);
                exportBeatmap.OverallDifficulty = DifficultyCalculator.CalculateMultipliedOD(NewBeatmap, 1 / 1.5M);
                decimal compensatedRate = (NewBeatmap.Bpm / OriginalBeatmap.Bpm) / 1.5M;
                exportBeatmap.SetRate(compensatedRate);
            }

            // Generate new mp3
            var audioFilePath = Path.Combine(JunUtils.GetBeatmapDirectoryName(OriginalBeatmap), exportBeatmap.AudioFilename);
            var newMp3        = "";

            if (!File.Exists(audioFilePath))
            {
                string inFile  = Path.Combine(Path.GetDirectoryName(OriginalBeatmap.Filename), OriginalBeatmap.AudioFilename);
                string outFile = Path.Combine(Path.GetTempPath(), exportBeatmap.AudioFilename);

                SongSpeedChanger.GenerateAudioFile(inFile, outFile, BpmMultiplier, mainform.BackgroundWorker, ChangePitch, compensateForDT);
                newMp3 = outFile;

                // take note of this mp3 in a text file, so we can clean it up later
                string        mp3ManifestFile = GetMp3ListFilePath();
                List <string> manifest        = File.ReadAllLines(mp3ManifestFile).ToList();
                string        beatmapFolder   = Path.GetDirectoryName(exportBeatmap.Filename).Replace(Properties.Settings.Default.SongsFolder + "\\", "");
                string        mp3RelativePath = Path.Combine(beatmapFolder, exportBeatmap.AudioFilename);
                manifest.Add(mp3RelativePath + " | " + exportBeatmap.Filename);
                File.WriteAllLines(mp3ManifestFile, manifest);
            }
            // save file to temp location (do not directly put into any song folder)
            exportBeatmap.Filename = Path.Combine(Path.GetTempPath(), Path.GetFileName(exportBeatmap.Filename));
            exportBeatmap.Save();

            // create and execute osz
            AddNewBeatmapToSongFolder(Path.GetDirectoryName(OriginalBeatmap.Filename), exportBeatmap.Filename, newMp3);

            // post
            SetState(EditorState.READY);
        }