public override Verb CreateVerb(string[] tokens) { var variable = tokens[3]; Color(position, tokens[1].Length, Whitespaces); Color(tokens[2].Length, Structures); Color(variable.Length, Variables); Color(tokens[4].Length, Structures); if (GetExpression(source, NextPosition, Comma()).If(out var init, out var i) && GetExpression(source, i, CommaOrCloseParenthesis()).If(out var condition, out var j)) { var index = j; Block increment; if (freeParser.Scan(source, index, "^ |sp| ','")) { freeParser.ColorAll(Structures); index = freeParser.Position; var pIncrement = GetExpression(source, index, Comma()); if (!pIncrement.If(out increment, out index)) { return(null); } if (freeParser.Scan(source, index, "^ |sp| ')'")) { freeParser.ColorAll(Structures); index = freeParser.Position; } else { return(null); } } else { if (freeParser.Scan(source, index, "^ |sp| ')'")) { freeParser.ColorAll(Structures); index = freeParser.Position; var builder = new CodeBuilder(); builder.Variable(variable); builder.Verb(new Add()); builder.Value(1); increment = builder.Block; } else { return(null); } } overridePosition = index; var value = new LoopRange(variable, init, true, condition, increment, none <Block>()); result.Value = value; return(value.PushedVerb); } return(null); }
public ForLoopNode(BlockNode block, LoopRange range, bool decreasing, string index, int byAmount = 1) { Block = block; Range = range; Decreasing = decreasing; Index = index; ByAmount = byAmount; }
partial void UpdateImpl(ref TimeSpan elapsed) { if (videoOutputSurface == null || PlayState == PlayState.Stopped) { return; } //Transfer frame if a new one is available if (mediaEngine.OnVideoStreamTick(out var presentationTimeTicks)) { CurrentTime = TimeSpan.FromTicks(presentationTimeTicks); // Check end of media var endOfMedia = reachedEOF; if (!endOfMedia) { //check the video loop and play range if (PlayRange.IsValid() && CurrentTime > PlayRange.End) { endOfMedia = true; } else if (IsLooping && LoopRange.IsValid() && CurrentTime > LoopRange.End) { endOfMedia = true; } } if (endOfMedia) { if (IsLooping) { //Restart the video at LoopRangeStart Seek(LoopRange.Start); } else { //stop the video Stop(); return; } } if (videoComponent.Target != null && videoOutputSurface != null && videoOutputTexture != null) { videoTexture.SetTargetContentToVideoStream(videoComponent.Target); // Now update the video texture with data of the new video frame: var graphicsContext = services.GetSafeServiceAs <GraphicsContext>(); mediaEngine.TransferVideoFrame(videoOutputSurface, null, new SharpDX.Mathematics.Interop.RawRectangle(0, 0, videoWidth, videoHeight), null); videoTexture.CopyDecoderOutputToTopLevelMipmap(graphicsContext, videoOutputTexture); videoTexture.GenerateMipMaps(graphicsContext); } } }
void InitDate(int y, int m, int w, int h) { _year = y; _month = new LoopRange(1, 13); _month.Value = m; _week = new LoopRange(1, 5); _week.Value = w; _hour = new LoopRange(0, 24); _hour.Value = h; }
public override Verb CreateVerb(string[] tokens) { var variable = tokens[4]; Color(position, tokens[1].Length, Whitespaces); Color(tokens[2].Length, Structures); Color(tokens[3].Length, KeyWords); Color(variable.Length, Variables); Color(tokens[5].Length, Structures); var index = NextPosition; if (GetExpression(source, index, LoopWhile()).If(out var init, out index)) { if (parser.Scan(source, index, "^ /(' '*) /('while' | 'until') /b")) { var direction = parser.Tokens[2]; var positive = direction == "while"; parser.Colorize(Whitespaces, KeyWords); index = parser.Position; if (GetExpression(source, index, LoopThen()).If(out var condition, out index)) { condition.Expression = false; if (GetExpression(source, index, Yield()).If(out var increment, out index) && GetExpression(source, index, CloseParenthesis()).If(out var yielding, out index)) { overridePosition = index; var someYielding = maybe(yielding.Count > 0, () => yielding); var value = new LoopRange(variable, init, positive, condition, increment, someYielding); result.Value = value; return(value.PushedVerb); } } } } return(null); }
partial void UpdateImpl(ref TimeSpan elapsed) { if (stream == null) { return; } if (PlayState == PlayState.Stopped) { return; } var speedFactor = SpeedFactor; if (PlayState == PlayState.Paused) { speedFactor = 0; } // Compare elapsed time with video framerate var frameDurationTicks = stream.FrameDuration.Ticks; adjustedTicksSinceLastFrame += (long)(elapsed.Ticks * speedFactor); if (adjustedTicksSinceLastFrame < frameDurationTicks) { return; } var frameCount = (int)(adjustedTicksSinceLastFrame / frameDurationTicks); if (frameCount == 0) { // Note: in case of slow speed factor, we might not need to update at each draw return; } if (frameCount > 4) { // Reading more than a few frames can be expensive, better seek. // FIXME: we might need a heuristic here to auto-adapt. It is probably dependent on the video being played (e.g. resolution, codec, file size, etc.) Seek(CurrentTime + TimeSpan.FromTicks(frameDurationTicks * frameCount)); frameCount = 1; } // Extract the frames var extractedFrameCount = media.ExtractFrames(stream, frameCount); if (extractedFrameCount > 0) { adjustedTicksSinceLastFrame = adjustedTicksSinceLastFrame % stream.FrameDuration.Ticks; } // Get the last one var streamInfo = media.GetStreamInfo(stream); if (streamInfo?.Image == null) { return; } // Check end of media bool endOfMedia = streamInfo.ReachedEnd; if (!endOfMedia) { if (extractedFrameCount > 0) { CurrentTime = stream.TimestampToTime(streamInfo.Image.Timestamp); } //check the video loop and play range if (PlayRange.IsValid() && CurrentTime > PlayRange.End) { endOfMedia = true; } else if (IsLooping && LoopRange.IsValid() && CurrentTime > LoopRange.End) { endOfMedia = true; } } if (endOfMedia) { if (IsLooping) { //Restart the video at LoopRangeStart //(ToCheck: is there a better way to do this (directly updating CurrentTime does not seem good, but if not doing, it will not work)) CurrentTime = LoopRange.Start; Seek(LoopRange.Start); return; } else { //stop the video Stop(); return; } } // return if the frame extraction failed and didn't reached and of the video if (extractedFrameCount == 0) { return; } if (videoComponent.Target != null) { videoTexture.SetTargetContentToVideoStream(videoComponent.Target); // Now update the video texture with data of the new video frame: var graphicsContext = services.GetSafeServiceAs <GraphicsContext>(); if (streamInfo.Codec.IsHardwareAccelerated && streamInfo.Image == null) { videoTexture.CopyDecoderOutputToTopLevelMipmap(graphicsContext, streamInfo.Codec.DecoderOutputTexture); } else { videoTexture.UpdateTopLevelMipmapFromData(graphicsContext, streamInfo.Image); } videoTexture.GenerateMipMaps(graphicsContext); } }