Example #1
0
        protected TextTagEditSection()
        {
            // create list of text-tag text-box if bindable changed.
            TextTags.BindValueChanged(e =>
            {
                Content.RemoveAll(x => x is LabelledTextTagTextBox);
                Content.AddRange(e.NewValue?.Select(x =>
                {
                    var relativeToLyricText = TextTagUtils.GetTextFromLyric(x, Lyric?.Text);
                    var range = TextTagUtils.PositionFormattedString(x);
                    return(new LabelledTextTagTextBox(x)
                    {
                        Label = relativeToLyricText,
                        Description = range,
                        OnDeleteButtonClick = () =>
                        {
                            LyricUtils.RemoveTextTag(Lyric, x);
                        },
                        TabbableContentContainer = this
                    });
                }));
            });

            // add create button.
            AddCreateButton();
        }
Example #2
0
        [TestCase("[1,0]:ka", 1, "[2,1]:ka")]   // do not check order in here.
        public void TestShifting(string textTag, int shifting, string actualTag)
        {
            // test ruby tag.
            var rubyTag       = TestCaseTagHelper.ParseRubyTag(textTag);
            var actualRubyTag = TestCaseTagHelper.ParseRubyTag(actualTag);

            Assert.AreEqual(TextTagUtils.Shifting(rubyTag, shifting), actualRubyTag);

            // test romaji tag.
            var romajiTag    = TestCaseTagHelper.ParseRubyTag(textTag);
            var actualRomaji = TestCaseTagHelper.ParseRubyTag(actualTag);

            Assert.AreEqual(TextTagUtils.Shifting(romajiTag, shifting), actualRomaji);
        }
Example #3
0
        [TestCase("[3,-1]:ka", "[-1,3]:ka")] // fix but ignore negative index.
        public void TestFixTimeTagPosition(string textTag, string actualTag)
        {
            // test ruby tag.
            var rubyTag       = TestCaseTagHelper.ParseRubyTag(textTag);
            var actualRubyTag = TestCaseTagHelper.ParseRubyTag(actualTag);

            Assert.AreEqual(TextTagUtils.FixTimeTagPosition(rubyTag), actualRubyTag);

            // test romaji tag.
            var romajiTag    = TestCaseTagHelper.ParseRubyTag(textTag);
            var actualRomaji = TestCaseTagHelper.ParseRubyTag(actualTag);

            Assert.AreEqual(TextTagUtils.FixTimeTagPosition(romajiTag), actualRomaji);
        }
Example #4
0
        public override bool SetContent(object content)
        {
            if (!(content is LyricCheckReport report))
            {
                return(false);
            }

            // clear exist warning.
            invalidMessage.Clear();

            // Print time invalid message
            foreach (var invalid in report.TimeInvalid.EmptyIfNull())
            {
                createTimeInvalidMessage(invalid);
            }

            // Print time-tag invalid message
            foreach (var invalidTimeTags in report.InvalidTimeTags.EmptyIfNull())
            {
                createTimeTagInvalidMessage(invalidTimeTags.Key, invalidTimeTags.Value);
            }

            // Print ruby invalid message
            foreach (var invalidRubyTags in report.InvalidRubyTags.EmptyIfNull())
            {
                createRubyInvalidMessage(invalidRubyTags.Key, invalidRubyTags.Value);
            }

            // Print romaji invalid message
            foreach (var invalidRomajiTags in report.InvalidRomajiTags.EmptyIfNull())
            {
                createRomajiInvalidMessage(invalidRomajiTags.Key, invalidRomajiTags.Value);
            }

            // show no problem message
            if (report.IsValid)
            {
                invalidMessage.AddSuccessParagraph("Seems no issue in this lyric.");
            }

            return(true);

            void createTimeInvalidMessage(TimeInvalid timeInvalid)
            {
                switch (timeInvalid)
                {
                case TimeInvalid.Overlapping:
                    invalidMessage.AddAlertParagraph("Start time larger then end time in lyric.");
                    break;

                case TimeInvalid.StartTimeInvalid:
                    invalidMessage.AddAlertParagraph("Start time is larger than minimux time tag's time.");
                    break;

                case TimeInvalid.EndTimeInvalid:
                    invalidMessage.AddAlertParagraph("End time is smaller than maximum time tag's time.");
                    break;
                }
            }

            void createTimeTagInvalidMessage(TimeTagInvalid invalid, TimeTag[] timeTags)
            {
                switch (invalid)
                {
                case TimeTagInvalid.OutOfRange:
                    invalidMessage.AddAlertParagraph("Time tag(s) is out of lyric text size at position ");
                    break;

                case TimeTagInvalid.Overlapping:
                    invalidMessage.AddAlertParagraph("Time tag(s) is invalid at position ");
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(invalid));
                }

                displayInvalidTag(timeTags, tag => invalidMessage.AddHighlightText(TextIndexUtils.PositionFormattedString(tag.Index)));
            }

            void createRubyInvalidMessage(RubyTagInvalid invalid, RubyTag[] rubyTags)
            {
                switch (invalid)
                {
                case RubyTagInvalid.OutOfRange:
                    invalidMessage.AddAlertParagraph("Ruby tag(s) is out of lyric text size at position ");
                    break;

                case RubyTagInvalid.Overlapping:
                    invalidMessage.AddAlertParagraph("Ruby tag(s) is overlapping to others at position ");
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(invalid));
                }

                displayInvalidTag(rubyTags, tag => invalidMessage.AddHighlightText(TextTagUtils.PositionFormattedString(tag)));
            }

            void createRomajiInvalidMessage(RomajiTagInvalid invalid, RomajiTag[] romajiTags)
            {
                switch (invalid)
                {
                case RomajiTagInvalid.OutOfRange:
                    invalidMessage.AddAlertParagraph("Romaji tag(s) is out of lyric text size at position ");
                    break;

                case RomajiTagInvalid.Overlapping:
                    invalidMessage.AddAlertParagraph("Romaji tag(s) is overlapping to others at position ");
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(invalid));
                }

                displayInvalidTag(romajiTags, tag => invalidMessage.AddHighlightText(TextTagUtils.PositionFormattedString(tag)));
            }

            void displayInvalidTag <T>(T[] tags, Action <T> action)
            {
                if (tags == null)
                {
                    throw new ArgumentNullException(nameof(tags));
                }

                // e.g: ka(-2~-1), ra(4~6), and ke(6~7)
                for (int i = 0; i < tags.Length; i++)
                {
                    action?.Invoke(tags[i]);

                    if (i == tags.Length - 2 && tags.Length > 1)
                    {
                        invalidMessage.AddText(" and ");
                    }
                    else if (i >= 0 && tags.Length > 1)
                    {
                        invalidMessage.AddText(", ");
                    }
                    else
                    {
                        invalidMessage.AddText(".");
                    }
                }
            }
        }
        public override bool SetContent(object content)
        {
            if (!(content is Issue[] issues))
            {
                return(false);
            }

            // clear exist warning.
            invalidMessage.Clear();

            foreach (var issue in issues)
            {
                switch (issue)
                {
                // Print time invalid message
                case LyricTimeIssue lyricTimeIssue:
                    lyricTimeIssue.InvalidLyricTime?.ForEach(createTimeInvalidMessage);
                    break;

                // Print time-tag invalid message
                case TimeTagIssue timeTagIssue:
                    if (timeTagIssue.MissingStartTimeTag)
                    {
                        invalidMessage.AddAlertParagraph("Missing start time tag at the start of lyric.");
                    }

                    if (timeTagIssue.MissingEndTimeTag)
                    {
                        invalidMessage.AddAlertParagraph("Missing end time tag at the end of lyric.");
                    }

                    timeTagIssue.InvalidTimeTags?.ForEach(x => createTimeTagInvalidMessage(x.Key, x.Value));
                    break;

                // Print ruby invalid message
                case RubyTagIssue rubyTagIssue:
                    rubyTagIssue.InvalidRubyTags?.ForEach(x => createRubyInvalidMessage(x.Key, x.Value));
                    break;

                // Print romaji invalid message
                case RomajiTagIssue romajiTagIssue:
                    romajiTagIssue.InvalidRomajiTags?.ForEach(x => createRomajiInvalidMessage(x.Key, x.Value));
                    break;

                // print normal message
                case Issue _:
                    invalidMessage.AddAlertParagraph(issue.Template.GetMessage());
                    break;

                // Should throw exception because every issue message should be printed.
                default:
                    throw new ArgumentOutOfRangeException(nameof(issue));
                }
            }

            // show no problem message
            if (issues.Length == 0)
            {
                invalidMessage.AddSuccessParagraph("Seems no issue in this lyric.");
            }

            return(true);

            void createTimeInvalidMessage(TimeInvalid timeInvalid)
            {
                switch (timeInvalid)
                {
                case TimeInvalid.Overlapping:
                    invalidMessage.AddAlertParagraph("Start time larger then end time in lyric.");
                    break;

                case TimeInvalid.StartTimeInvalid:
                    invalidMessage.AddAlertParagraph("Start time is larger than minimum time tag's time.");
                    break;

                case TimeInvalid.EndTimeInvalid:
                    invalidMessage.AddAlertParagraph("End time is smaller than maximum time tag's time.");
                    break;
                }
            }

            void createTimeTagInvalidMessage(TimeTagInvalid invalid, TimeTag[] timeTags)
            {
                switch (invalid)
                {
                case TimeTagInvalid.OutOfRange:
                    invalidMessage.AddAlertParagraph("Time tag(s) is out of lyric text size at position ");
                    break;

                case TimeTagInvalid.Overlapping:
                    invalidMessage.AddAlertParagraph("Time tag(s) is invalid at position ");
                    break;

                case TimeTagInvalid.EmptyTime:
                    invalidMessage.AddAlertParagraph("Time tag(s) is missing time at position ");
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(invalid));
                }

                displayInvalidTag(timeTags, tag => invalidMessage.AddHighlightText(TextIndexUtils.PositionFormattedString(tag.Index)));
            }

            void createRubyInvalidMessage(RubyTagInvalid invalid, RubyTag[] rubyTags)
            {
                switch (invalid)
                {
                case RubyTagInvalid.OutOfRange:
                    invalidMessage.AddAlertParagraph("Ruby tag(s) is out of lyric text size at position ");
                    break;

                case RubyTagInvalid.Overlapping:
                    invalidMessage.AddAlertParagraph("Ruby tag(s) is overlapping to others at position ");
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(invalid));
                }

                displayInvalidTag(rubyTags, tag => invalidMessage.AddHighlightText(TextTagUtils.PositionFormattedString(tag)));
            }

            void createRomajiInvalidMessage(RomajiTagInvalid invalid, RomajiTag[] romajiTags)
            {
                switch (invalid)
                {
                case RomajiTagInvalid.OutOfRange:
                    invalidMessage.AddAlertParagraph("Romaji tag(s) is out of lyric text size at position ");
                    break;

                case RomajiTagInvalid.Overlapping:
                    invalidMessage.AddAlertParagraph("Romaji tag(s) is overlapping to others at position ");
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(invalid));
                }

                displayInvalidTag(romajiTags, tag => invalidMessage.AddHighlightText(TextTagUtils.PositionFormattedString(tag)));
            }

            void displayInvalidTag <T>(T[] tags, Action <T> action)
            {
                if (tags == null)
                {
                    throw new ArgumentNullException(nameof(tags));
                }

                // e.g: ka(-2~-1), ra(4~6), and ke(6~7)
                for (int i = 0; i < tags.Length; i++)
                {
                    action?.Invoke(tags[i]);

                    if (i == tags.Length - 2 && tags.Length > 1)
                    {
                        invalidMessage.AddText(" and ");
                    }
                    else if (i >= 0 && tags.Length > 1)
                    {
                        invalidMessage.AddText(", ");
                    }
                    else
                    {
                        invalidMessage.AddText(".");
                    }
                }
            }
        }
Example #6
0
        public void TestPositionFormattedString(string textTag, string actual)
        {
            var rubyTag = TestCaseTagHelper.ParseRubyTag(textTag);

            Assert.AreEqual(TextTagUtils.PositionFormattedString(rubyTag), actual);
        }
Example #7
0
        [TestCase("[0,0]:ka", null, true)] // should be counted as out of range if lyric is null
        public void TestOutOfRange(string textTag, string lyric, bool outOfRange)
        {
            var rubyTag = TestCaseTagHelper.ParseRubyTag(textTag);

            Assert.AreEqual(TextTagUtils.OutOfRange(rubyTag, lyric), outOfRange);
        }
Example #8
0
        public void TestGetTextFromLyric(string textTag, string lyric, string actual)
        {
            var rubyTag = TestCaseTagHelper.ParseRubyTag(textTag);

            Assert.AreEqual(TextTagUtils.GetTextFromLyric(rubyTag, lyric), actual);
        }