private void processBeatmap(int beatmapId, List <Ruleset> rulesets) { try { var localBeatmap = BeatmapLoader.GetBeatmap(beatmapId, Verbose, ForceDownload); if (localBeatmap == null) { reporter.Warn($"Beatmap {beatmapId} skipped (beatmap file not found)."); return; } using (var conn = MasterDatabase.GetConnection()) { if (Converts && localBeatmap.BeatmapInfo.RulesetID == 0) { foreach (var ruleset in rulesets) { computeDifficulty(beatmapId, localBeatmap, ruleset, conn); } } else if (rulesets.Any(r => r.RulesetInfo.ID == localBeatmap.BeatmapInfo.RulesetID)) { computeDifficulty(beatmapId, localBeatmap, localBeatmap.BeatmapInfo.Ruleset.CreateInstance(), conn); } } reporter.Verbose($"Difficulty updated for beatmap {beatmapId}."); } catch (Exception e) { reporter.Error($"{beatmapId} failed with: {e}"); } Interlocked.Increment(ref processedBeatmaps); }
public void SetSong(int id, string path) { string extension = IO.Path.GetExtension(path); bool isAudio = BeatmapLoader.SupportedAudioFormats.Contains <string>(extension); bool isBeatmap = (extension == BeatmapLoader.BeatmapFileFormat); if (isAudio || isBeatmap) { string audioFile; string sourceFile; if (isAudio) { BeatmapContainer = BeatmapLoader.CreateBeatmapFromAudio(path); audioFile = sourceFile = path; } else { BeatmapContainer = BeatmapLoader.LoadBeatmapFile(path); audioFile = IO.Path.Combine(BeatmapContainer.directory, BeatmapContainer.bm.AudioFile); sourceFile = BeatmapContainer.sourceFile; } this.id = id; Thumbnail.sprite = null; TagLib.File tfile = TagLib.File.Create(audioFile); SongName = tfile.Tag.Title != null ? tfile.Tag.Title : IO.Path.GetFileNameWithoutExtension(sourceFile); ArtistName = tfile.Tag.FirstPerformer; DifficultyText.text = "N/A"; //Difficulty.text = Math.Round(BeatmapContainer.bm.Metadata.Difficulty, 1).ToString(); //Difficulty.color = Color.Lerp(Color.green, Color.red, BeatmapContainer.bm.Metadata.Difficulty / 5f); DurationText.text = tfile.Properties.Duration.ToString(@"mm\:ss"); } }
private void StartRecording() { if (audioPlayer.clip == null) { BeatmapLoader.SelectAudioFile(); } bm = new Beatmap(); audioPlayer.Stop(); audioPlayer.PlayDelayed(1); }
private void LoadBeatmap() { string path = BeatmapLoader.SelectBeatmapFile(); if (path != null) { BeatmapContainer bmc = BeatmapLoader.LoadBeatmapFile(path); AudioClipData cd = BeatmapLoader.LoadBeatmapAudio(bmc); audioPlayer.clip = BeatmapLoader.CreateAudioClipFromData(cd); bm = bmc.bm; } }
private void processBeatmap(int beatmapId, List <Ruleset> rulesets) { try { reporter.Verbose($"Processing difficulty for beatmap {beatmapId}."); var localBeatmap = BeatmapLoader.GetBeatmap(beatmapId, Verbose, ForceDownload, reporter); if (localBeatmap == null) { reporter.Error($"Beatmap {beatmapId} skipped (beatmap file not found)."); return; } if (localBeatmap.Beatmap.HitObjects.Count == 0) { using (var conn = Database.GetSlaveConnection()) { if (conn?.QuerySingleOrDefault <int>("SELECT `approved` FROM `osu_beatmaps` WHERE `beatmap_id` = @BeatmapId", new { BeatmapId = beatmapId }) > 0) { reporter.Error($"Ranked beatmap {beatmapId} has 0 hitobjects!"); } } } using (var conn = Database.GetConnection()) { if (Converts && localBeatmap.BeatmapInfo.RulesetID == 0) { foreach (var ruleset in rulesets) { computeDifficulty(beatmapId, localBeatmap, ruleset, conn); } } else if (rulesets.Any(r => r.RulesetInfo.ID == localBeatmap.BeatmapInfo.RulesetID)) { computeDifficulty(beatmapId, localBeatmap, localBeatmap.BeatmapInfo.Ruleset.CreateInstance(), conn); } } reporter.Verbose($"Difficulty updated for beatmap {beatmapId}."); } catch (Exception e) { reporter.Error($"{beatmapId} failed with: {e.Message}"); } Interlocked.Increment(ref processedBeatmaps); }
protected override void ProcessResult(BeatmapItem item) { using (var db = GetDatabaseConnection()) { var beatmaps = db.Query <long>("SELECT beatmap_id FROM osu_beatmaps WHERE beatmapset_id = @beatmapset_id AND deleted_at IS NULL", item); foreach (long beatmapId in beatmaps) { var working = BeatmapLoader.GetBeatmap((int)beatmapId); if (working == null) { throw new Exception($"Couldn't download beatmap for {beatmapId}"); } // ensure the correct online id is set working.BeatmapInfo.OnlineBeatmapID = (int)beatmapId; calculator.ProcessBeatmap(working); } } }
public void OnExecute(CommandLineApplication app, IConsole console) { reporter = new Reporter(console, LogFile) { IsQuiet = Quiet, IsVerbose = Verbose }; if (Concurrency < 1) { reporter.Error("Concurrency level must be above 1."); return; } threadBeatmapIds = new int[Concurrency]; if (AppSettings.RUN_AS_SANDBOX_DOCKER) { reporter.Output("Waiting for database..."); while (true) { try { bool initialised = false; using (var conn = Database.GetConnection()) { if (conn.QuerySingle <int>("SELECT `count` FROM `osu_counts` WHERE `name` = 'docker_db_step'") >= 1) { initialised = true; } } if (initialised) { break; } } catch { } Thread.Sleep(1000); } } var beatmaps = new ConcurrentQueue <int>(GetBeatmaps() ?? Enumerable.Empty <int>()); totalBeatmaps = beatmaps.Count; var tasks = new Task[Concurrency]; for (int i = 0; i < Concurrency; i++) { int tmp = i; tasks[i] = Task.Factory.StartNew(() => { var calc = new ServerDifficultyCalculator(Rulesets, Converts, DryRun); while (beatmaps.TryDequeue(out int beatmapId)) { threadBeatmapIds[tmp] = beatmapId; reporter.Verbose($"Processing difficulty for beatmap {beatmapId}."); try { var beatmap = BeatmapLoader.GetBeatmap(beatmapId, Verbose, ForceDownload, reporter); // ensure the correct online id is set beatmap.BeatmapInfo.OnlineID = beatmapId; calc.ProcessBeatmap(beatmap); reporter.Verbose($"Difficulty updated for beatmap {beatmapId}."); } catch (Exception e) { reporter.Error($"{beatmapId} failed with {e}"); } Interlocked.Increment(ref processedBeatmaps); } }); } reporter.Output($"Processing {totalBeatmaps} beatmaps."); using (new Timer(_ => outputProgress(), null, 1000, 1000)) using (new Timer(_ => outputHealth(), null, 5000, 5000)) Task.WaitAll(tasks); if (AppSettings.RUN_AS_SANDBOX_DOCKER) { using (var conn = Database.GetConnection()) { conn.Execute("INSERT INTO `osu_counts` (`name`, `count`) VALUES (@Name, @Count) ON DUPLICATE KEY UPDATE `count` = @Count", new { Name = "docker_db_step", Count = 2 }); } } outputProgress(); reporter.Output("Done."); }