Ejemplo n.º 1
0
        public override void Apply(AssLine line, AssSection section, float t)
        {
            if (t <= 0 || t >= 1 || line.Position == null)
            {
                return;
            }

            line.Position = new PointF(
                line.Position.Value.X + Radius.Width * ((float)_random.NextDouble() * 2 - 1.0f),
                line.Position.Value.Y + Radius.Height * ((float)_random.NextDouble() * 2 - 1.0f)
                );
        }
Ejemplo n.º 2
0
 public override void Apply(AssLine line, AssSection section, float t)
 {
     if (t > 0 && t < 1)
     {
         line.Position = new PointF(
             Center.X + Radius.Width * ((float)_random.NextDouble() * 2 - 1.0f),
             Center.Y + Radius.Height * ((float)_random.NextDouble() * 2 - 1.0f)
             );
     }
     else
     {
         line.Position = Center;
     }
 }
Ejemplo n.º 3
0
        public override void Apply(AssLine line, AssSection section, float t)
        {
            int alpha = Interpolate(StartAlpha, EndAlpha, t);

            switch (line)
            {
            case AssLine assLine:
                assLine.Alpha = alpha;
                break;

            default:
                throw new NotSupportedException();
            }
        }
        private static void HandleTransformFontSizeTag(AssTagContext context, DateTime startTime, DateTime endTime, int accel, string arg)
        {
            if (!TryParseFloat(arg, out float size))
            {
                return;
            }

            AssSection     section    = context.Section;
            ScaleAnimation prevAnim   = section.Animations.OfType <ScaleAnimation>().LastOrDefault();
            float          startScale = prevAnim?.EndScale ?? context.Section.Scale;
            float          endScale   = size / context.Document.DefaultFontSize;

            context.Section.Animations.Add(new ScaleAnimation(startTime, startScale, endTime, endScale));
        }
        private static void HandleTransformFontSizeTag(AssTagContext context, DateTime startTime, DateTime endTime, float accel, string arg)
        {
            if (!TryParseFloat(arg, out float lineHeight))
            {
                return;
            }

            AssSection section = context.Section;

            section.Animations.RemoveAll(a => a is ScaleAnimation && a.StartTime >= startTime);

            ScaleAnimation prevAnim   = section.Animations.OfType <ScaleAnimation>().LastOrDefault();
            float          startScale = prevAnim?.EndScale ?? context.Section.Scale;
            float          endScale   = lineHeight / context.Document.DefaultStyle.LineHeight;

            context.Section.Animations.Add(new ScaleAnimation(startTime, startScale, endTime, endScale, accel));
        }
Ejemplo n.º 6
0
        public override IEnumerable <AssLine> Apply(AssKaraokeStepContext context)
        {
            AssSection singingSection = context.SingingSections.LastOrDefault(s => s.RubyPart == RubyPart.None || s.RubyPart == RubyPart.Text);

            if (singingSection == null || singingSection.Text.Length == 0)
            {
                return new List <AssLine> {
                           context.StepLine
                }
            }
            ;

            base.Apply(context);
            DateTime glitchEndTime = TimeUtil.FrameToEndTime(TimeUtil.StartTimeToFrame(context.StepLine.Start) + 1);

            CharacterRange[] charRanges = GetGlitchKaraokeCharacterRanges(singingSection.Text[0]);
            singingSection.Animations.Add(new GlitchingCharAnimation(context.StepLine.Start, glitchEndTime, charRanges));
            return(new[] { context.StepLine });
        }
        private List <Section> GenerateCursor(AssDocument doc, AssSection initialFormatting, string cursor)
        {
            AssSection section = (AssSection)initialFormatting.Clone();

            section.Text = string.Empty;

            AssLine       line    = new AssLine(SubtitleDocument.TimeBase, SubtitleDocument.TimeBase);
            AssTagContext context =
                new AssTagContext
            {
                Document = doc,
                Line     = line,
                Section  = section
            };

            doc.CreateTagSections(line, cursor, context);

            return(line.Sections);
        }
Ejemplo n.º 8
0
        private static List <AnimationWithSectionIndex> GetAnimationsWithSectionIndex(AssLine line)
        {
            List <AnimationWithSectionIndex> animations = new List <AnimationWithSectionIndex>();

            foreach (Animation anim in line.Animations)
            {
                animations.Add(new AnimationWithSectionIndex(anim, -1));
            }

            for (int i = 0; i < line.Sections.Count; i++)
            {
                AssSection section = (AssSection)line.Sections[i];
                foreach (Animation anim in section.Animations)
                {
                    animations.Add(new AnimationWithSectionIndex(anim, i));
                }
            }

            return(animations);
        }
        private static T FetchColorAnimation <T>(
            AssTagContext context,
            DateTime startTime,
            DateTime endTime,
            Func <T, bool> predicate,
            Func <AssSection, Color> getSectionColor,
            Func <DateTime, DateTime, Color, T> createAnim
            )
            where T : ColorAnimation
        {
            context.Section.Animations.RemoveAll(a => a is T && a.StartTime > startTime);

            AssSection      section       = context.Section;
            IEnumerable <T> existingAnims = section.Animations.OfType <T>().Where(a => a.StartTime == startTime && a.EndTime == endTime);

            if (predicate != null)
            {
                existingAnims = existingAnims.Where(predicate);
            }

            T anim = existingAnims.FirstOrDefault();

            if (anim == null)
            {
                IEnumerable <T> prevAnims = section.Animations.OfType <T>();
                if (predicate != null)
                {
                    prevAnims = prevAnims.Where(predicate);
                }

                T prevAnim = prevAnims.LastOrDefault();
                anim = createAnim(startTime, endTime, prevAnim?.EndColor ?? getSectionColor(section));
                section.Animations.Add(anim);
            }

            return(anim);
        }
        private static void ApplyFadeOutKaraokeEffect(AssLine originalLine, AssLine stepLine, SortedList <TimeSpan, int> activeSectionsPerStep, int stepIdx)
        {
            int stepFirstSectionIdx = 0;

            for (int prevStepIdx = 0; prevStepIdx < stepIdx; prevStepIdx++)
            {
                DateTime fadeStartTime      = originalLine.Start + activeSectionsPerStep.Keys[prevStepIdx + 1];
                DateTime fadeEndTime        = fadeStartTime.AddMilliseconds(1000);
                int      stepLastSectionIdx = activeSectionsPerStep.Values[prevStepIdx] - 1;
                for (int sectionIdx = stepFirstSectionIdx; sectionIdx <= stepLastSectionIdx; sectionIdx++)
                {
                    AssSection section = (AssSection)stepLine.Sections[sectionIdx];
                    if (!section.CurrentWordForeColor.IsEmpty && section.CurrentWordForeColor != section.ForeColor)
                    {
                        section.Animations.Add(new ForeColorAnimation(fadeStartTime, section.CurrentWordForeColor, fadeEndTime, section.ForeColor, 1));
                    }

                    if (!section.CurrentWordShadowColor.IsEmpty)
                    {
                        foreach (KeyValuePair <ShadowType, Color> shadowColor in section.ShadowColors)
                        {
                            if (section.CurrentWordShadowColor != shadowColor.Value)
                            {
                                section.Animations.Add(new ShadowColorAnimation(shadowColor.Key, fadeStartTime, section.CurrentWordShadowColor, fadeEndTime, shadowColor.Value, 1));
                            }
                        }
                    }

                    if (!section.CurrentWordOutlineColor.IsEmpty && section.CurrentWordOutlineColor != section.ShadowColors.GetOrDefault(ShadowType.Glow))
                    {
                        section.Animations.Add(new ShadowColorAnimation(ShadowType.Glow, fadeStartTime, section.CurrentWordOutlineColor, fadeEndTime, section.ShadowColors[ShadowType.Glow], 1));
                    }
                }

                stepFirstSectionIdx = stepLastSectionIdx + 1;
            }
        }
 public override void Apply(AssLine line, AssSection section, float t)
 {
     section.ShadowColors[ShadowType] = GetColor(t);
 }
Ejemplo n.º 12
0
 public override void Apply(AssLine line, AssSection section, float t)
 {
     line.Alpha = Interpolate(StartAlpha, EndAlpha, t);
 }
Ejemplo n.º 13
0
 public override void Apply(AssLine line, AssSection section, float t)
 {
     section.Scale = Interpolate(StartScale, EndScale, t);
 }
Ejemplo n.º 14
0
 public override void Apply(AssLine line, AssSection section, float t)
 {
     section.BackColor = GetColor(t);
 }
Ejemplo n.º 15
0
 public abstract void Apply(AssLine line, AssSection section, float t);