public static Completion Calculate(IValue leftValue, ShiftOperator shiftOperator, IValue rightValue) { var lnumComp = leftValue.ToNumber(); if (lnumComp.IsAbrupt()) { return(lnumComp); } var rnumComp = rightValue.ToNumber(); if (rnumComp.IsAbrupt()) { return(rnumComp); } int lnum = (int)(lnumComp.value as NumberValue) !.number; uint rnum = (uint)(rnumComp.value as NumberValue) !.number; var shiftCount = (int)(rnum & 0x1F); return(Completion.NormalCompletion(new NumberValue(shiftOperator switch { ShiftOperator.ShiftRight => lnum >> shiftCount, ShiftOperator.ShiftRightUnsigned => ((uint)lnum >> shiftCount) & (0b1 << shiftCount), ShiftOperator.ShiftLeft => lnum << shiftCount, _ => throw new InvalidOperationException($"ShiftExpression.Evaluate: unknown ShiftOperator enum value {(int)shiftOperator}") })));
/* Private Members */ private Boolean ShiftTimesAll() { if (Base.Document.Subtitles.Count == 0) { return(false); } ShiftOperator shiftOp = new ShiftOperator(Base.Document.Subtitles); shiftOp.Shift(time); time = time.Negate(); return(true); }
private Boolean ShiftFramesAll() { if (Base.Document.Subtitles.Count == 0) { return(false); } ShiftOperator shiftOp = new ShiftOperator(Base.Document.Subtitles); shiftOp.Shift(frames); frames = -frames; return(true); }
private Boolean ShiftFramesRange() { if ((Paths == null) || (Paths.Length == 0)) { return(false); } int firstSubtitle = Util.PathToInt(FirstPath); int lastSubtitle = Util.PathToInt(LastPath); ShiftOperator shiftOp = new ShiftOperator(Base.Document.Subtitles); shiftOp.Shift(frames, firstSubtitle, lastSubtitle); frames = -frames; return(true); }
/// <summary>Auto syncs a range of subtitles given their first and last correct times.</summary> /// <remarks>The subtitles are first shifted to the first subtitle's correct time, and then proportionally /// adjusted using the last subtitle's correct time.</remarks> /// <param name="subtitles">The subtitles to sync.</param> /// <param name="startIndex">The subtitle index to start the adjustment with.</param> /// <param name="startTime">The correct start time for the first subtitle.</param> /// <param name="endIndex">The subtitle index to end the adjustment with.</param> /// <param name="endTime">The correct start time for the last subtitle.</param> /// <param name="syncLast">Whether to sync the last subtitle.</param> /// <returns>Whether the subtitles could be adjusted.</returns> public static bool Sync (Subtitles subtitles, int startIndex, TimeSpan startTime, int endIndex, TimeSpan endTime, bool syncLast) { if (!AreSyncArgsValid(subtitles, startIndex, startTime, endIndex, endTime)) return false; /* Perform initial calculations */ int syncEndIndex = (syncLast ? endIndex : endIndex - 1); Subtitle startSubtitle = subtitles.Collection.Get(startIndex); TimeSpan shift = startTime - startSubtitle.Times.PreciseStart; Subtitle endSubtitle = subtitles.Collection.Get(endIndex); double factor = (endTime - startTime).TotalMilliseconds / (endSubtitle.Times.PreciseStart - startSubtitle.Times.PreciseStart).TotalMilliseconds; /* Shift subtitles to the start point */ if (shift != TimeSpan.Zero) { ShiftOperator shiftOp = new ShiftOperator(subtitles); shiftOp.Shift(shift, startIndex, syncEndIndex); } /* Sync timings with proportion */ for (int index = startIndex ; index <= syncEndIndex ; index++) { Subtitle subtitle = subtitles.Collection.Get(index); subtitle.Times.Scale(factor, startTime); } return true; }
private void ShiftTimesRange () { int firstSubtitle = Util.PathToInt(FirstPath); int lastSubtitle = Util.PathToInt(LastPath); ShiftOperator shiftOp = new ShiftOperator(Base.Document.Subtitles); shiftOp.Shift(time, firstSubtitle, lastSubtitle); time = time.Negate(); }
private void ShiftFramesAll () { ShiftOperator shiftOp = new ShiftOperator(Base.Document.Subtitles); shiftOp.Shift(frames); frames = -frames; }
/* Private Members */ private void ShiftTimesAll () { ShiftOperator shiftOp = new ShiftOperator(Base.Document.Subtitles); shiftOp.Shift(time); time = time.Negate(); }
private void ShiftFramesRange () { int firstSubtitle = Util.PathToInt(FirstPath); int lastSubtitle = Util.PathToInt(LastPath); ShiftOperator shiftOp = new ShiftOperator(Base.Document.Subtitles); shiftOp.Shift(frames, firstSubtitle, lastSubtitle); frames = -frames; }
/// <summary> 解释位移运算 /// </summary> /// <param name="val1">操作数1</param> /// <param name="val2">操作数2</param> /// <param name="opt">按位操作符</param> protected virtual string ShiftOperation(string val1, string val2, ShiftOperator opt) { throw new NotImplementedException("不支持当前操作,或请重新实现 ShiftOperation"); }
public ShiftExpression(AbstractShiftExpression shiftExpression, ShiftOperator shiftOperator, AbstractAdditiveExpression additiveExpression, bool isStrictMode) : base(isStrictMode) { this.shiftExpression = shiftExpression; this.shiftOperator = shiftOperator; this.additiveExpression = additiveExpression; }
/// <summary>Auto syncs a range of subtitles given their first and last correct frames.</summary> /// <remarks>The subtitles are first shifted to the first subtitle's correct frame, and then proportionally /// adjusted using the last subtitle's correct frame.</remarks> /// <param name="subtitles">The subtitles to sync.</param> /// <param name="startIndex">The subtitle index to start the adjustment with.</param> /// <param name="startFrame">The correct start frame for the first subtitle.</param> /// <param name="endIndex">The subtitle index to end the adjustment with.</param> /// <param name="endFrame">The correct start frame for the last subtitle.</param> /// <param name="syncLast">Whether to sync the last subtitle.</param> /// <returns>Whether the subtitles could be adjusted.</returns> public static bool Sync (Subtitles subtitles, int startIndex, int startFrame, int endIndex, int endFrame, bool syncLast) { if (!AreSyncArgsValid(subtitles, startIndex, startFrame, endIndex, endFrame)) return false; /* Perform initial calculations */ int syncEndIndex = (syncLast ? endIndex : endIndex - 1); Subtitle startSubtitle = subtitles.Collection.Get(startIndex); int shift = (int)(startFrame - startSubtitle.Frames.PreciseStart); Subtitle endSubtitle = subtitles.Collection.Get(endIndex); double factor = (endFrame - startFrame) / (endSubtitle.Frames.PreciseStart - startFrame); /* Shift subtitles to the start point */ if (shift != 0) { ShiftOperator shiftOp = new ShiftOperator(subtitles); shiftOp.Shift(shift, startIndex, syncEndIndex); } /* Auto adjust timings with proportion */ for (int index = startIndex ; index <= syncEndIndex ; index++) { Subtitle subtitle = subtitles.Collection.Get(index); subtitle.Frames.Scale(factor, startFrame); } return true; }