Esempio n. 1
0
        public override IEnumerable <Issue> GetIssues(BeatmapSet beatmapSet)
        {
            if (beatmapSet.GetAudioFilePath() != null)
            {
                foreach (Issue issue in GetIssue(beatmapSet, beatmapSet.GetAudioFilePath()))
                {
                    yield return(issue);
                }
            }

            foreach (string hitSoundFile in beatmapSet.hitSoundFiles)
            {
                string hitSoundPath = Path.Combine(beatmapSet.songPath, hitSoundFile);
                ManagedBass.ChannelType hitSoundFormat = AudioBASS.GetFormat(hitSoundPath);
                if ((hitSoundFormat & ManagedBass.ChannelType.OGG) != 0 &&
                    (hitSoundFormat & ManagedBass.ChannelType.MP3) != 0)
                {
                    continue;
                }

                foreach (Issue issue in GetIssue(beatmapSet, hitSoundPath, true))
                {
                    yield return(issue);
                }
            }
        }
Esempio n. 2
0
        public override IEnumerable <Issue> GetIssues(BeatmapSet beatmapSet)
        {
            if (beatmapSet.hitSoundFiles == null)
            {
                yield break;
            }

            foreach (string hitSoundFile in beatmapSet.hitSoundFiles)
            {
                string fullPath = Path.Combine(beatmapSet.songPath, hitSoundFile);

                ManagedBass.ChannelType actualFormat = 0;
                Exception exception = null;
                try
                {
                    actualFormat = AudioBASS.GetFormat(fullPath);
                }
                catch (Exception ex)
                {
                    exception = ex;
                }

                if (exception != null)
                {
                    yield return(new Issue(GetTemplate("Exception"), null,
                                           hitSoundFile, Common.ExceptionTag(exception)));

                    continue;
                }

                // The .mp3 format includes inherent delays and are as such not fit for active hit sounding.
                if (actualFormat == ManagedBass.ChannelType.MP3)
                {
                    HitObject hitObjectActiveAt = GetHitObjectActiveAt(beatmapSet, hitSoundFile);
                    if (hitObjectActiveAt != null)
                    {
                        yield return(new Issue(GetTemplate("mp3"), null,
                                               hitSoundFile, Timestamp.Get(hitObjectActiveAt), hitObjectActiveAt.beatmap));
                    }
                }
                else
                {
                    if ((ManagedBass.ChannelType.Wave & actualFormat) == 0 &&
                        (ManagedBass.ChannelType.OGG & actualFormat) == 0)
                    {
                        yield return(new Issue(GetTemplate("Unexpected Format"), null,
                                               hitSoundFile, AudioBASS.EnumToString(actualFormat)));
                    }
                    else if (!hitSoundFile.ToLower().EndsWith(".wav") && !hitSoundFile.ToLower().EndsWith(".ogg"))
                    {
                        yield return(new Issue(GetTemplate("Incorrect Extension"), null,
                                               hitSoundFile, AudioBASS.EnumToString(actualFormat)));
                    }
                }
            }
        }
Esempio n. 3
0
        public override IEnumerable <Issue> GetIssues(BeatmapSet beatmapSet)
        {
            string audioPath = beatmapSet.GetAudioFilePath();
            string audioName = beatmapSet.GetAudioFileName();

            if (audioPath == null)
            {
                yield break;
            }

            ManagedBass.ChannelType actualFormat = 0;
            Exception exception = null;

            try
            {
                actualFormat = AudioBASS.GetFormat(audioPath);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            if (exception != null)
            {
                yield return(new Issue(GetTemplate("Exception"), null,
                                       audioName, Common.ExceptionTag(exception)));
            }

            else if ((ManagedBass.ChannelType.MP3 & actualFormat) != ManagedBass.ChannelType.MP3 &&
                     (ManagedBass.ChannelType.OGG & actualFormat) != ManagedBass.ChannelType.OGG)
            {
                yield return(new Issue(GetTemplate("Incorrect Format"), null,
                                       audioName, AudioBASS.EnumToString(actualFormat)));
            }

            else if (!audioName.ToLower().EndsWith(".mp3") && (ManagedBass.ChannelType.MP3 & actualFormat) == ManagedBass.ChannelType.MP3)
            {
                yield return(new Issue(GetTemplate("Incorrect Extension"), null,
                                       audioName, AudioBASS.EnumToString(actualFormat), ".mp3"));
            }

            else if (!audioName.ToLower().EndsWith(".ogg") && (ManagedBass.ChannelType.OGG & actualFormat) == ManagedBass.ChannelType.OGG)
            {
                yield return(new Issue(GetTemplate("Incorrect Extension"), null,
                                       audioName, AudioBASS.EnumToString(actualFormat), ".ogg"));
            }
        }
Esempio n. 4
0
        public override IEnumerable <Issue> GetIssues(BeatmapSet beatmapSet)
        {
            if (beatmapSet.GetAudioFilePath() != null)
            {
                foreach (var issue in GetIssue(beatmapSet, beatmapSet.GetAudioFilePath()))
                {
                    yield return(issue);
                }
            }

            foreach (string hitSoundFile in beatmapSet.hitSoundFiles)
            {
                string hitSoundPath = Path.Combine(beatmapSet.songPath, hitSoundFile);

                ManagedBass.ChannelType hitSoundFormat = 0;
                Issue errorIssue = null;
                try
                {
                    hitSoundFormat = AudioBASS.GetFormat(hitSoundPath);
                }
                catch (Exception exception)
                {
                    errorIssue = new Issue(GetTemplate("Exception"), null,
                                           PathStatic.RelativePath(hitSoundPath, beatmapSet.songPath),
                                           Common.ExceptionTag(exception));
                }

                if (errorIssue != null)
                {
                    yield return(errorIssue);

                    continue;
                }

                if ((hitSoundFormat & ManagedBass.ChannelType.OGG) != 0 &&
                    (hitSoundFormat & ManagedBass.ChannelType.MP3) != 0)
                {
                    continue;
                }

                foreach (var issue in GetIssue(beatmapSet, hitSoundPath, true))
                {
                    yield return(issue);
                }
            }
        }
Esempio n. 5
0
        public override IEnumerable <Issue> GetIssues(BeatmapSet beatmapSet)
        {
            if (beatmapSet.hitSoundFiles != null)
            {
                foreach (string hitSoundFile in beatmapSet.hitSoundFiles)
                {
                    string fullPath = Path.Combine(beatmapSet.songPath, hitSoundFile);

                    ManagedBass.ChannelType actualFormat = 0;
                    Exception exception = null;
                    try
                    { actualFormat = AudioBASS.GetFormat(fullPath); }
                    catch (Exception ex)
                    { exception = ex; }

                    if (exception != null)
                    {
                        yield return(new Issue(GetTemplate("Exception"), null,
                                               hitSoundFile, Common.ExceptionTag(exception)));

                        continue;
                    }

                    // The .mp3 format includes inherent delays and are as such not fit for active hit sounding.
                    if (actualFormat == ManagedBass.ChannelType.MP3)
                    {
                        bool foundActiveMp3 = false;
                        foreach (Beatmap beatmap in beatmapSet.beatmaps)
                        {
                            foreach (HitObject hitObject in beatmap.hitObjects)
                            {
                                if (hitObject is Spinner)
                                {
                                    continue;
                                }

                                // Only the hit sound edge at which the object is clicked is considered active.
                                if (hitObject.usedHitSamples.Any(sample =>
                                                                 sample.time == hitObject.time &&
                                                                 sample.hitSource == HitSample.HitSource.Edge &&
                                                                 sample.SameFileName(hitSoundFile)))
                                {
                                    yield return(new Issue(GetTemplate("mp3"), null,
                                                           hitSoundFile, Timestamp.Get(hitObject), beatmap));

                                    foundActiveMp3 = true;
                                    break;
                                }
                            }
                            if (foundActiveMp3)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        if ((ManagedBass.ChannelType.Wave & actualFormat) == 0 &&
                            (ManagedBass.ChannelType.OGG & actualFormat) == 0)
                        {
                            yield return(new Issue(GetTemplate("Unexpected Format"), null,
                                                   hitSoundFile, AudioBASS.EnumToString(actualFormat)));
                        }
                        else if (!hitSoundFile.ToLower().EndsWith(".wav") && !hitSoundFile.ToLower().EndsWith(".ogg"))
                        {
                            yield return(new Issue(GetTemplate("Incorrect Extension"), null,
                                                   hitSoundFile, AudioBASS.EnumToString(actualFormat)));
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        private static string RenderResources(BeatmapSet aBeatmapSet)
        {
            string RenderFloat(List <string> aFiles, Func <string, string> aFunc)
            {
                string content =
                    String.Join("<br>",
                                aFiles.Select(aFile =>
                {
                    string path =
                        aBeatmapSet.hitSoundFiles.FirstOrDefault(anOtherFile =>
                                                                 anOtherFile.StartsWith(aFile + "."));
                    if (path == null)
                    {
                        return(null);
                    }

                    return(aFunc(path));
                }).Where(aValue => aValue != null)
                                );

                if (content.Length == 0)
                {
                    return("");
                }

                return(Div("overview-float", content));
            }

            Dictionary <string, int> hsUsedCount = new Dictionary <string, int>();

            return
                (RenderContainer("Resources",
                                 RenderBeatmapContent(aBeatmapSet, "Used Hit Sound File(s)", aBeatmap =>
            {
                List <string> usedHitSoundFiles =
                    aBeatmap.hitObjects.SelectMany(anObject => anObject.GetUsedHitSoundFileNames()).ToList();

                List <string> distinctSortedFiles =
                    usedHitSoundFiles.Distinct().OrderByDescending(aFile => aFile).ToList();

                return
                RenderFloat(distinctSortedFiles, aPath => Encode(aPath)) +
                RenderFloat(distinctSortedFiles, aPath =>
                {
                    int count = usedHitSoundFiles.Where(anOtherFile => aPath.StartsWith(anOtherFile + ".")).Count();

                    // Used for total hit sound usage overview
                    if (hsUsedCount.ContainsKey(aPath))
                    {
                        hsUsedCount[aPath] += count;
                    }
                    else
                    {
                        hsUsedCount[aPath] = count;
                    }

                    return $"× {count}";
                });
            }, false),
                                 RenderField("Total Used Hit Sound File(s)",
                                             (hsUsedCount.Any() ?
                                              Div("overview-float",
                                                  String.Join("<br>",
                                                              hsUsedCount.Select(aPair => aPair.Key)
                                                              )
                                                  ) +
                                              Div("overview-float",
                                                  String.Join("<br>",
                                                              hsUsedCount.Select(aPair =>
                                                                                 Try(() =>
            {
                string fullPath = Path.Combine(aBeatmapSet.songPath, aPair.Key);

                return Encode(RenderFileSize(fullPath));
            },
                                                                                     noteIfError: "Could not get hit sound file size"
                                                                                     )
                                                                                 )
                                                              )
                                                  ) +
                                              Div("overview-float",
                                                  String.Join("<br>",
                                                              hsUsedCount.Select(aPair =>
                                                                                 Try(() =>
            {
                string fullPath = Path.Combine(aBeatmapSet.songPath, aPair.Key);
                double duration = AudioBASS.GetDuration(fullPath);

                if (duration < 0)
                {
                    return "0 ms";
                }

                return $"{duration:0.##} ms";
            },
                                                                                     noteIfError: "Could not get hit sound duration"
                                                                                     )
                                                                                 )
                                                              )
                                                  ) +
                                              Div("overview-float",
                                                  String.Join("<br>",
                                                              hsUsedCount.Select(aPair =>
                                                                                 Try(() =>
            {
                string fullPath = Path.Combine(aBeatmapSet.songPath, aPair.Key);

                return Encode(AudioBASS.EnumToString(AudioBASS.GetFormat(fullPath)));
            },
                                                                                     noteIfError: "Could not get hit sound file path"
                                                                                     )
                                                                                 )
                                                              )
                                                  ) +
                                              Div("overview-float",
                                                  String.Join("<br>",
                                                              hsUsedCount.Select(aPair => "× " + aPair.Value)
                                                              )
                                                  )
                        : "")
                                             ),
                                 RenderBeatmapContent(aBeatmapSet, "Background File(s)", aBeatmap =>
            {
                if (aBeatmap.backgrounds.Any())
                {
                    string fullPath = Path.Combine(aBeatmap.songPath, aBeatmap.backgrounds.First().path);
                    if (!File.Exists(fullPath))
                    {
                        return "";
                    }

                    string error = null;
                    TagLib.File tagFile = null;
                    try
                    { tagFile = new FileAbstraction(fullPath).GetTagFile(); }
                    catch (Exception exception)
                    {
                        error = exception.Message;
                    }

                    return
                    Div("overview-float",
                        Try(() =>
                            Encode(aBeatmap.backgrounds.First().path),
                            noteIfError: "Could not get background file path"
                            )
                        ) +
                    Div("overview-float",
                        Try(() =>
                            Encode(RenderFileSize(fullPath)),
                            noteIfError: "Could not get background file size"
                            )
                        ) +
                    ((error != null || tagFile == null) ?
                     Div("overview-float",
                         Try(() =>
                             Encode(tagFile.Properties.PhotoWidth + " x " + tagFile.Properties.PhotoHeight),
                             noteIfError: "Could not get background resolution"
                             )
                         ) :
                     Div("overview-float",
                         Encode($"(failed getting proprties; {error})")
                         ));
                }
                else
                {
                    return "";
                }
            }, false),
                                 RenderBeatmapContent(aBeatmapSet, "Video File(s)", aBeatmap =>
            {
                if (aBeatmap.videos.Any() || (aBeatmapSet.osb?.videos.Any() ?? false))
                {
                    string fullPath = Path.Combine(aBeatmap.songPath, aBeatmap.videos.First().path);
                    if (!File.Exists(fullPath))
                    {
                        return "";
                    }

                    string error = null;
                    TagLib.File tagFile = null;
                    try
                    { tagFile = new FileAbstraction(fullPath).GetTagFile(); }
                    catch (Exception exception)
                    { error = exception.Message; }

                    return
                    Div("overview-float",
                        Try(() =>
                            Encode(aBeatmap.videos.First().path),
                            noteIfError: "Could not get video file path"
                            )
                        ) +
                    Div("overview-float",
                        Try(() =>
                            Encode(RenderFileSize(fullPath)),
                            noteIfError: "Could not get video file size"
                            )
                        ) +
                    ((error != null || tagFile == null) ?
                     Div("overview-float",
                         Try(() =>
                             FormatTimestamps(Encode(Timestamp.Get(tagFile.Properties.Duration.TotalMilliseconds))),
                             noteIfError: "Could not get video duration"
                             )
                         ) +
                     Div("overview-float",
                         Try(() =>
                             Encode(tagFile.Properties.VideoWidth + " x " + tagFile.Properties.VideoHeight),
                             noteIfError: "Could not get video resolution"
                             )
                         ) :
                     Div("overview-float",
                         Encode($"(failed getting proprties; {error})")
                         ));
                }
                else
                {
                    return "";
                }
            }, false),
                                 RenderBeatmapContent(aBeatmapSet, "Audio File(s)", aBeatmap =>
            {
                string path = aBeatmap.GetAudioFilePath();
                if (path == null)
                {
                    return "";
                }

                return
                Div("overview-float",
                    Try(() =>
                        Encode(PathStatic.RelativePath(path, aBeatmap.songPath)),
                        noteIfError: "Could not get audio file path"
                        )
                    ) +
                Div("overview-float",
                    Try(() =>
                        Encode(RenderFileSize(path)),
                        noteIfError: "Could not get audio file size"
                        )
                    ) +
                Div("overview-float",
                    Try(() =>
                        FormatTimestamps(Encode(Timestamp.Get(AudioBASS.GetDuration(path)))),
                        noteIfError: "Could not get audio duration"
                        )
                    ) +
                Div("overview-float",
                    Try(() =>
                        Encode(AudioBASS.EnumToString(AudioBASS.GetFormat(path))),
                        noteIfError: "Could not get audio format"
                        )
                    );
            }, false),
                                 RenderBeatmapContent(aBeatmapSet, "Audio Bitrate", aBeatmap =>
            {
                string path = aBeatmap.GetAudioFilePath();
                if (path == null)
                {
                    return "N/A";
                }

                return
                Div("overview-float",
                    $"average {Math.Round(AudioBASS.GetBitrate(path))} kbps"
                    );
            }, false),
                                 RenderField("Has .osb",
                                             Encode((aBeatmapSet.osb?.IsUsed() ?? false).ToString())
                                             ),
                                 RenderBeatmapContent(aBeatmapSet, "Has .osu Specific Storyboard", aBeatmap =>
                                                      aBeatmap.HasDifficultySpecificStoryboard().ToString()),
                                 RenderBeatmapContent(aBeatmapSet, "Song Folder Size", aBeatmap =>
                                                      RenderDirectorySize(aBeatmap.songPath))
                                 ));
        }