Esempio n. 1
0
        public void TestGetTimeTagDisplayRubyText(int indexOfTimeTag, string actual)
        {
            var lyric = new Lyric
            {
                Text     = "カラオケ",
                TimeTags = TestCaseTagHelper.ParseTimeTags(new[]
                {
                    "[0,start]:1000",
                    "[0,start]:1000",
                    "[0,end]:1000",
                    "[1,start]:2000",
                    "[1,start]:2000",
                    "[1,end]:2000",
                    "[2,start]:3000",
                    "[2,start]:3000",
                    "[3,start]:4000",
                    "[3,end]:5000",
                }),
                RubyTags = TestCaseTagHelper.ParseRubyTags(new[]
                {
                    "[0,1]:か",
                    "[2,4]:おけ",
                })
            };
            var timeTag = lyric.TimeTags[indexOfTimeTag];

            Assert.AreEqual(LyricUtils.GetTimeTagDisplayRubyText(lyric, timeTag), actual);
        }
Esempio n. 2
0
        public void TestGetTimeTagIndexDisplayText(string text, string textIndexStr, string actual)
        {
            var lyric     = TestCaseTagHelper.ParseLyricWithTimeTag(text);
            var textIndex = TestCaseTagHelper.ParseTextIndex(textIndexStr);

            Assert.AreEqual(LyricUtils.GetTimeTagIndexDisplayText(lyric, textIndex), actual);
        }
Esempio n. 3
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();
        }
Esempio n. 4
0
        public void TestCheckIsEndTimeInvalid(string lyricText, string[] timeTags, bool actual)
        {
            var lyric = TestCaseTagHelper.ParseLyric(lyricText);

            lyric.TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags);
            Assert.AreEqual(LyricUtils.CheckIsEndTimeInvalid(lyric), actual);
        }
Esempio n. 5
0
        private void load(TimeTagEditor timeline, OsuColour colours)
        {
            // todo : should be able to let user able to select show from ruby or main text.
            timeTagText.Text              = LyricUtils.GetTimeTagDisplayRubyText(timeline.HitObject, Item);
            timeTagPiece.Colour           = colours.BlueLight;
            timeTagWithNoTimePiece.Colour = colours.Red;
            startTime.BindValueChanged(e =>
            {
                var hasValue = hasTime();

                // update show time-tag style.
                switch (hasValue)
                {
                case true:
                    timeTagPiece.Show();
                    timeTagWithNoTimePiece.Hide();
                    break;

                case false:
                    timeTagPiece.Hide();
                    timeTagWithNoTimePiece.Show();
                    break;
                }

                Schedule(() =>
                {
                    // should wait until all time-tag time has been modified.
                    X = (float)timeline.GetPreviewTime(Item);
                });
            }, true);
        }
Esempio n. 6
0
 public TimeTagInfo(Lyric lyric)
     : base(lyric)
 {
     lyric.TimeTagsBindable.BindValueChanged(value =>
     {
         BadgeText = LyricUtils.TimeTagTimeFormattedString(Lyric);
     }, true);
 }
Esempio n. 7
0
        public void TestGetTimeTagDisplayText(string text, string textIndexStr, string actual)
        {
            var lyric     = TestCaseTagHelper.ParseLyricWithTimeTag(text);
            var textIndex = TestCaseTagHelper.ParseTextIndex(textIndexStr);
            var timeTag   = lyric.TimeTags?.Where(x => x.Index == textIndex).FirstOrDefault();

            Assert.AreEqual(LyricUtils.GetTimeTagDisplayText(lyric, timeTag), actual);
        }
Esempio n. 8
0
        public void TestAddTextText(string text, int position, string addedText, string actualText)
        {
            var lyric = new Lyric {
                Text = text
            };

            LyricUtils.AddText(lyric, position, addedText);
            Assert.AreEqual(lyric.Text, actualText);
        }
Esempio n. 9
0
        public void TestTimeTagTimeFormattedString(string[] timeTags, string format)
        {
            var lyric = new Lyric
            {
                TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags),
            };

            Assert.AreEqual(LyricUtils.TimeTagTimeFormattedString(lyric), format);
        }
Esempio n. 10
0
        public void TestLyricTimeFormattedString(double startTime, double endTime, string format)
        {
            var lyric = new Lyric
            {
                StartTime = startTime,
                Duration  = endTime - startTime
            };

            Assert.AreEqual(LyricUtils.LyricTimeFormattedString(lyric), format);
        }
Esempio n. 11
0
        public void TestHasTimedTimeTags(string[] timeTags, bool hasTimedTimeTag)
        {
            var lyric = new Lyric
            {
                Text     = "カラオケ",
                TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags),
            };

            Assert.AreEqual(LyricUtils.HasTimedTimeTags(lyric), hasTimedTimeTag);
        }
Esempio n. 12
0
        public void TestOnlyContainsSingers(string[] existSingers, string[] compareSingers, bool isContain)
        {
            var singers = TestCaseTagHelper.ParseSingers(compareSingers).ToList();
            var lyric   = new Lyric
            {
                Singers = TestCaseTagHelper.ParseSingers(existSingers)?.Select(x => x.ID).ToArray()
            };

            Assert.AreEqual(LyricUtils.OnlyContainsSingers(lyric, singers), isContain);
        }
Esempio n. 13
0
        public void TextAddTextRuby(string[] rubies, int position, string addedText, string[] targetRubies)
        {
            var lyric = new Lyric
            {
                Text     = "カラオケ",
                RubyTags = TestCaseTagHelper.ParseRubyTags(rubies),
            };

            LyricUtils.AddText(lyric, position, addedText);
            Assert.AreEqual(lyric.RubyTags, TestCaseTagHelper.ParseRubyTags(targetRubies));
        }
Esempio n. 14
0
        public void TextAddTextRomaji(string[] romajies, int position, string addedText, string[] targetRomajies)
        {
            var lyric = new Lyric
            {
                Text       = "カラオケ",
                RomajiTags = TestCaseTagHelper.ParseRomajiTags(romajies),
            };

            LyricUtils.AddText(lyric, position, addedText);
            TextTagAssert.ArePropertyEqual(lyric.RomajiTags, TestCaseTagHelper.ParseRomajiTags(targetRomajies));
        }
Esempio n. 15
0
        public void TestRemoveTextRuby(string[] rubies, int position, int count, string[] targetRubies)
        {
            var lyric = new Lyric
            {
                Text     = "カラオケ",
                RubyTags = TestCaseTagHelper.ParseRubyTags(rubies),
            };

            LyricUtils.RemoveText(lyric, position, count);
            TextTagAssert.ArePropertyEqual(lyric.RubyTags, TestCaseTagHelper.ParseRubyTags(targetRubies));
        }
Esempio n. 16
0
        public void TestRemoveTextRomaji(string[] romajies, int position, int count, string[] targetRomajies)
        {
            var lyric = new Lyric
            {
                Text       = "カラオケ",
                RomajiTags = TestCaseTagHelper.ParseRomajiTags(romajies),
            };

            LyricUtils.RemoveText(lyric, position, count);
            Assert.AreEqual(lyric.RomajiTags, TestCaseTagHelper.ParseRomajiTags(targetRomajies));
        }
Esempio n. 17
0
        public void TestRemoveTextTimeTag(string[] timeTags, int position, int count, string[] actualTimeTags)
        {
            var lyric = new Lyric
            {
                Text     = "カラオケ",
                TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags),
            };

            LyricUtils.RemoveText(lyric, position, count);
            TimeTagAssert.AreEqual(lyric.TimeTags, TestCaseTagHelper.ParseTimeTags(actualTimeTags));
        }
Esempio n. 18
0
        public void TestAddTextTimeTag(string[] timeTags, int position, string addedText, string[] actualTimeTags)
        {
            var lyric = new Lyric
            {
                Text     = "カラオケ",
                TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags),
            };

            LyricUtils.AddText(lyric, position, addedText);
            TimeTagAssert.ArePropertyEqual(lyric.TimeTags, TestCaseTagHelper.ParseTimeTags(actualTimeTags));
        }
Esempio n. 19
0
 private Drawable createTimeDrawable(Lyric lyric)
 {
     return(new OsuSpriteText
     {
         Text = LyricUtils.LyricTimeFormattedString(lyric),
         Anchor = Anchor.CentreLeft,
         Origin = Anchor.CentreLeft,
         Margin = new MarginPadding {
             Left = row_inner_spacing
         },
         Font = OsuFont.GetFont(size: 18, fixedWidth: true),
         AllowMultiline = false
     });
 }
Esempio n. 20
0
        public bool DeleteLyricText(Lyric lyric, int index)
        {
            if (index <= 0)
            {
                return(false);
            }

            changeHandler?.BeginChange();

            LyricUtils.RemoveText(lyric, index - 1);

            changeHandler?.EndChange();

            return(true);
        }
Esempio n. 21
0
 public void TestRemoveTextText(string text, int position, int count, string actualText)
 {
     try
     {
         var lyric = new Lyric {
             Text = text
         };
         LyricUtils.RemoveText(lyric, position, count);
         Assert.AreEqual(lyric.Text, actualText);
     }
     catch
     {
         Assert.Null(actualText);
     }
 }
Esempio n. 22
0
        public void TestRemoveTextTag(string[] textTags, string removeTextTag, bool actual)
        {
            var lyric = new Lyric
            {
                Text       = "からおけ",
                RubyTags   = TestCaseTagHelper.ParseRubyTags(textTags),
                RomajiTags = TestCaseTagHelper.ParseRomajiTags(textTags)
            };

            var fromIndex = textTags?.IndexOf(removeTextTag) ?? -1;

            // test ruby and romaji at the same test.
            var removeRubyTag   = fromIndex >= 0 ? lyric.RubyTags[fromIndex] : TestCaseTagHelper.ParseRubyTag(removeTextTag);
            var removeRomajiTag = fromIndex >= 0 ? lyric.RomajiTags[fromIndex] : TestCaseTagHelper.ParseRomajiTag(removeTextTag);

            Assert.AreEqual(LyricUtils.RemoveTextTag(lyric, removeRubyTag), actual);
            Assert.AreEqual(LyricUtils.RemoveTextTag(lyric, removeRomajiTag), actual);
        }
Esempio n. 23
0
        [TestCase(new[] { "[1]name:Singer1" }, "[0]name:Singer0", false, null)] // should not remove invalid singer.
        public void TestRemoveSinger(string[] existSingers, string removeSinger, bool isAdded, int[] actualSingers)
        {
            var singer = TestCaseTagHelper.ParseSinger(removeSinger);
            var lyric  = new Lyric
            {
                Singers = TestCaseTagHelper.ParseSingers(existSingers)?.Select(x => x.ID).ToArray()
            };

            try
            {
                Assert.AreEqual(LyricUtils.RemoveSinger(lyric, singer), isAdded);
                Assert.AreEqual(lyric.Singers, actualSingers);
            }
            catch
            {
                Assert.IsNull(actualSingers);
            }
        }
Esempio n. 24
0
        public bool DeleteLyricText(Lyric lyric, int index)
        {
            if (index <= 0)
            {
                return(false);
            }

            changeHandler?.BeginChange();

            LyricUtils.RemoveText(lyric, index - 1);

            if (string.IsNullOrEmpty(lyric.Text))
            {
                OrderUtils.ShiftingOrder(Lyrics.Where(x => x.Order > lyric.Order).ToArray(), -1);
                beatmap.Remove(lyric);
            }

            changeHandler?.EndChange();

            return(true);
        }
Esempio n. 25
0
        private TimeInvalid[] checkInvalidLyricTime(Lyric lyric)
        {
            var result = new List <TimeInvalid>();

            if (LyricUtils.CheckIsTimeOverlapping(lyric))
            {
                result.Add(TimeInvalid.Overlapping);
            }

            if (LyricUtils.CheckIsStartTimeInvalid(lyric))
            {
                result.Add(TimeInvalid.StartTimeInvalid);
            }

            if (LyricUtils.CheckIsEndTimeInvalid(lyric))
            {
                result.Add(TimeInvalid.EndTimeInvalid);
            }

            return(result.ToArray());
        }
Esempio n. 26
0
        protected override bool ApplySnapResult(SelectionBlueprint <ITextTag>[] blueprints, SnapResult result)
        {
            if (!base.ApplySnapResult(blueprints, result))
            {
                return(false);
            }

            // handle lots of ruby / romaji drag position changed.
            var items = blueprints.Select(x => x.Item).ToArray();

            if (!items.Any())
            {
                return(false);
            }

            var leftPosition = ToLocalSpace(result.ScreenSpacePosition).X;
            var startIndex   = TextIndexUtils.ToStringIndex(editorLyricPiece.GetHoverIndex(leftPosition));
            var diff         = startIndex - items.First().StartIndex;

            if (diff == 0)
            {
                return(false);
            }

            foreach (var item in items)
            {
                var newStartIndex = item.StartIndex + diff;
                var newEndIndex   = item.EndIndex + diff;
                if (!LyricUtils.AbleToInsertTextTagAtIndex(Lyric, newStartIndex) || !LyricUtils.AbleToInsertTextTagAtIndex(Lyric, newEndIndex))
                {
                    continue;
                }

                item.StartIndex = newStartIndex;
                item.EndIndex   = newEndIndex;
            }

            return(true);
        }
        private void processNotes(Beatmap beatmap, IList <string> lines)
        {
            // Remove all karaoke note
            beatmap.HitObjects.RemoveAll(x => x is Note);

            var lyrics = beatmap.HitObjects.OfType <Lyric>().ToList();

            for (int l = 0; l < lyrics.Count; l++)
            {
                var lyric = lyrics[l];
                var line  = lines.ElementAtOrDefault(l)?.Split('=').Last();

                // Create default note if not exist
                if (string.IsNullOrEmpty(line))
                {
                    beatmap.HitObjects.AddRange(LyricUtils.CreateDefaultNotes(lyric));
                    continue;
                }

                var notes         = line.Split(',');
                var defaultNotes  = LyricUtils.CreateDefaultNotes(lyric).ToList();
                var minNoteNumber = Math.Min(notes.Length, defaultNotes.Count);

                // Process each note
                for (int i = 0; i < minNoteNumber; i++)
                {
                    var note        = notes[i];
                    var defaultNote = defaultNotes[i];

                    // Support multi note in one time tag, format like ([1;0.5;か]|1#|...)
                    if (!note.StartsWith("(", StringComparison.Ordinal) || !note.EndsWith(")", StringComparison.Ordinal))
                    {
                        // Process and add note
                        applyNote(defaultNote, note);
                        beatmap.HitObjects.Add(defaultNote);
                    }
                    else
                    {
                        float startPercentage = 0;
                        var   rubyNotes       = note.Replace("(", "").Replace(")", "").Split('|');

                        for (int j = 0; j < rubyNotes.Length; j++)
                        {
                            string rubyNote = rubyNotes[j];

                            string tone;
                            float  percentage = (float)Math.Round((float)1 / rubyNotes.Length, 2, MidpointRounding.AwayFromZero);
                            string ruby       = defaultNote.AlternativeText?.ElementAtOrDefault(j).ToString();

                            // Format like [1;0.5;か]
                            if (note.StartsWith("[", StringComparison.Ordinal) && note.EndsWith("]", StringComparison.Ordinal))
                            {
                                var rubyNoteProperty = note.Replace("[", "").Replace("]", "").Split(';');

                                // Copy tome property
                                tone = rubyNoteProperty[0];

                                // Copy percentage property
                                if (rubyNoteProperty.Length >= 2)
                                {
                                    float.TryParse(rubyNoteProperty[1], out percentage);
                                }

                                // Copy text property
                                if (rubyNoteProperty.Length >= 3)
                                {
                                    ruby = rubyNoteProperty[2];
                                }
                            }
                            else
                            {
                                tone = rubyNote;
                            }

                            // Split note and apply them
                            var splitDefaultNote = NoteUtils.SliceNote(defaultNote, startPercentage, percentage);
                            startPercentage += percentage;
                            if (!string.IsNullOrEmpty(ruby))
                            {
                                splitDefaultNote.Text = ruby;
                            }

                            // Process and add note
                            applyNote(splitDefaultNote, tone);
                            beatmap.HitObjects.Add(splitDefaultNote);
                        }
                    }
                }
            }

            void applyNote(Note note, string noteStr, string ruby = null, double?duration = null)
            {
                if (noteStr == "-")
                {
                    note.Display = false;
                }
                else
                {
                    note.Display = true;
                    note.Tone    = convertTone(noteStr);
                }

                if (!string.IsNullOrEmpty(ruby))
                {
                    note.Text = ruby;
                }

                if (duration != null)
                {
                    note.Duration = duration.Value;
                }

                //Support format : 1  1.  1.5  1+  1#
                Tone convertTone(string tone)
                {
                    var half = false;

                    if (tone.Contains(".") || tone.Contains("#"))
                    {
                        half = true;

                        // only get digit part
                        tone = tone.Split('.').FirstOrDefault()?.Split('#').FirstOrDefault();
                    }

                    if (!int.TryParse(tone, out int scale))
                    {
                        throw new ArgumentOutOfRangeException($"{tone} does not support in {nameof(KaraokeLegacyBeatmapDecoder)}");
                    }

                    return(new Tone
                    {
                        Scale = scale,
                        Half = half
                    });
                }
            }
        }
Esempio n. 28
0
        public void TestAbleToInsertTextTagAtIndex(string text, int index, bool actual)
        {
            var lyric = TestCaseTagHelper.ParseLyricWithTimeTag(text);

            Assert.AreEqual(LyricUtils.AbleToInsertTextTagAtIndex(lyric, index), actual);
        }
Esempio n. 29
0
            public InfoControl(Lyric lyric)
            {
                Lyric = lyric;

                Children = new Drawable[]
                {
                    background = new Box
                    {
                        RelativeSizeAxes = Axes.X,
                        Height           = max_height,
                    },
                    new FillFlowContainer
                    {
                        Direction        = FillDirection.Vertical,
                        RelativeSizeAxes = Axes.X,
                        AutoSizeAxes     = Axes.Y,
                        Anchor           = Anchor.TopRight,
                        Origin           = Anchor.TopRight,
                        Spacing          = new Vector2(5),
                        Children         = new Drawable[]
                        {
                            new Container
                            {
                                RelativeSizeAxes = Axes.X,
                                Height           = 36,
                                Children         = new Drawable[]
                                {
                                    headerBackground = new Box
                                    {
                                        RelativeSizeAxes = Axes.Both
                                    },
                                    timeRange = new OsuSpriteText
                                    {
                                        Anchor = Anchor.CentreLeft,
                                        Origin = Anchor.CentreLeft,
                                        Font   = OsuFont.GetFont(size: 16, fixedWidth: true),
                                        Margin = new MarginPadding(10),
                                    },
                                    new InvalidInfo(lyric)
                                    {
                                        Anchor = Anchor.CentreRight,
                                        Origin = Anchor.CentreRight,
                                        Margin = new MarginPadding(10),
                                        Scale  = new Vector2(1.3f),
                                        Y      = 1,
                                    },
                                }
                            },
                            new GridContainer
                            {
                                RelativeSizeAxes = Axes.X,
                                AutoSizeAxes     = Axes.Y,
                                ColumnDimensions = new[]
                                {
                                    new Dimension(),
                                    new Dimension(GridSizeMode.Absolute, 28),
                                },
                                Content = new[]
                                {
                                    new Drawable[]
                                    {
                                        subInfoContainer = new Container
                                        {
                                            RelativeSizeAxes = Axes.X
                                        },
                                        new FillFlowContainer
                                        {
                                            RelativeSizeAxes = Axes.X,
                                            AutoSizeAxes     = Axes.Y,
                                            Direction        = FillDirection.Vertical,
                                            Spacing          = new Vector2(5),
                                            Children         = new Drawable[]
                                            {
                                                new OrderInfo(lyric),
                                                new LockInfo(lyric),
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                };

                timeRange.Text = LyricUtils.LyricTimeFormattedString(lyric);

                bindableMode.BindValueChanged(e =>
                {
                    CreateBadge(e.NewValue);
                });
            }
Esempio n. 30
0
        public void TestCheckIsTimeOverlapping(string lyricText, bool actual)
        {
            var lyric = TestCaseTagHelper.ParseLyric(lyricText);

            Assert.AreEqual(LyricUtils.CheckIsTimeOverlapping(lyric), actual);
        }