//called when data for any output pin is requested public void Evaluate(int SpreadMax) { try { FId.AssignFrom(FParameter.Select(p => p.Id)); FDatatype.AssignFrom(FParameter.Select(p => p.Datatype)); FTypeDefinition.AssignFrom(FParameter.Select(p => p.TypeDefinition)); FValue.AssignFrom(FParameter.Select(p => p.Value)); FLabel.AssignFrom(FParameter.Select(p => p.Label)); FWidget.AssignFrom(FParameter.Select(p => p.Widget)); FGroup.AssignFrom(FParameter.Select(p => p.Group)); FUserdata.AssignFrom(FParameter.Select(p => p.Userdata)); } catch {} }
public ISpread <Frame> Preload( ISpread <int> visibleFrameIndices, ISpread <int> preloadFrameNrs, int bufferSize, EX9.Format preferedFormat, out int frameCount, out double durationIO, out double durationTexture, out int unusedFrames, ref ISpread <bool> loadedFrames) { var files = FFiles; frameCount = files.Length; durationIO = 0.0; durationTexture = 0.0; unusedFrames = 0; // Nothing to do if (files.Length == 0) { loadedFrames.SliceCount = 0; return(new Spread <Frame>(0)); } // Map frame numbers to file names var preloadFiles = preloadFrameNrs.Select( frameNr => { var fileName = files[VMath.Zmod(frameNr, files.Length)]; return(CreateFrameInfo(fileName, bufferSize, preferedFormat)); }) .ToArray(); // Dispose previously loaded frames foreach (var file in FPreloadedFrames.Keys.ToArray()) { if (!preloadFiles.Contains(file)) { var frame = FPreloadedFrames[file]; Dispose(frame); } } // Ensure that there are as much dequeues as enqueues (or we'll run out of memory) while (FScheduledFrameInfos.Count > preloadFrameNrs.SliceCount) { var frame = Dequeue(); var frameInfo = frame.Metadata; if (!preloadFiles.Contains(frameInfo) || frameInfo.IsCanceled) { // Not needed anymore Dispose(frame); unusedFrames++; } else { FPreloadedFrames.Add(frameInfo, frame); } } // Cancel unused scheduled frames foreach (var frameInfo in FScheduledFrameInfos.Where(fi => !fi.IsCanceled)) { if (!preloadFiles.Contains(frameInfo)) { frameInfo.Cancel(); } } // Schedule new frames foreach (var file in preloadFiles) { if (!IsScheduled(file) && !IsPreloaded(file)) { Enqueue(file); } } // Write the "is loaded" state loadedFrames.SliceCount = preloadFrameNrs.SliceCount; for (int i = 0; i < loadedFrames.SliceCount; i++) { var file = preloadFiles[i]; if (!IsPreloaded(file)) { var frameInfo = FScheduledFrameInfos.First(fi => fi == file); loadedFrames[i] = frameInfo.IsLoaded; } else { loadedFrames[i] = true; } } // Wait for the visible frames (and dipose unused ones) var visibleFrames = new Spread <Frame>(0); // Map frame numbers to file names var visibleFiles = preloadFiles.Length > 0 ? visibleFrameIndices.Select(i => preloadFiles[VMath.Zmod(i, preloadFiles.Length)]) : Enumerable.Empty <FrameInfo>(); foreach (var file in visibleFiles) { while (!IsPreloaded(file)) { var frame = Dequeue(); var frameInfo = frame.Metadata; if (!preloadFiles.Contains(frameInfo) || frameInfo.IsCanceled) { // Not needed anymore Dispose(frame); unusedFrames++; } else { FPreloadedFrames.Add(frameInfo, frame); } } var visibleFrame = FPreloadedFrames[file]; var visibleFrameInfo = visibleFrame.Metadata; durationIO += visibleFrameInfo.DurationIO; durationTexture += visibleFrameInfo.DurationTexture; visibleFrames.Add(visibleFrame); } // Release textures of non visible frames foreach (var frame in FPreloadedFrames.Values.Where(f => !visibleFrames.Contains(f))) { frame.Dispose(); } return(visibleFrames); }
public void Evaluate(int SpreadMax) { //return null if one of the control inputs is null if (FDoInsert.IsAnyEmpty(FReset)) { FOutput.SliceCount = 0; return; } if (FReset[0]) { FBuffer.Clear(); FFramesRecorded.SliceCount = 0; } if (FRemove[0]) { if (FFramesRecorded.SliceCount > 0) { foreach (int i in FIndex.Select(x => x % FFramesRecorded.SliceCount).Distinct().OrderByDescending(x => x)) { int offset = 0; for (int j = 0; j < i; j++) { offset += FFramesRecorded[j]; } if (FFramesRecorded.SliceCount > 1) { FBuffer.RemoveRange(offset, FFramesRecorded[i]); } else { FBuffer.RemoveRange(0, FFramesRecorded[i]); } FFramesRecorded.RemoveAt(i); } } } if (FDoInsert[0]) { // is empty, so insert new slice if (FFramesRecorded.SliceCount < 1) { FFramesRecorded.Insert(0, 0); } // new slice for FFramesRecorded reqested else if (FDoSplit[0]) { // duplicate current slice and insert in old queue if (FSplitDuplicate[0]) { if (!FAppend[0]) { FBuffer.Insert(0, FCopier.CopySpread(FInput)); FFramesRecorded[0]++; } else { // search beginning of last queue int count = 0; for (int i = 0; i < FFramesRecorded.SliceCount - 1; i++) { count += FFramesRecorded[i]; } FBuffer.Insert(count, FCopier.CopySpread(FInput)); FFramesRecorded[FFramesRecorded.SliceCount - 1]++; } } if (!FAppend[0]) { FFramesRecorded.Insert(0, 0); } else { FFramesRecorded.Add(0); } } if (!FAppend[0]) { FBuffer.Insert(0, FCopier.CopySpread(FInput)); FFramesRecorded[0]++; } else { // search beginning of last queue int count = 0; for (int i = 0; i < FFramesRecorded.SliceCount - 1; i++) { count += FFramesRecorded[i]; } FBuffer.Insert(count, FCopier.CopySpread(FInput)); FFramesRecorded[FFramesRecorded.SliceCount - 1]++; } } FOutput.AssignFrom(FBuffer); if (FOutput.SliceCount == 0) { FFramesRecorded.SliceCount = 0; } // combines all recorded queues to one big queue if (FConsolidate[0] == true) { int count = 0; foreach (int current in FFramesRecorded) { count += current; } FFramesRecorded.SliceCount = 1; FFramesRecorded[0] = count; } }
protected override void Evaluate(int spreadMax, bool enabled) { if (enabled) { // To support old keyboard node if (FLegacyKeyStringIn.SliceCount > 0) { var keys = FLegacyKeyStringIn.Select(keyAsString => LegacyKeyboardHelper.StringToVirtualKeycode(keyAsString)); FKeyboardIn.SliceCount = 1; FKeyboardIn[0] = new KeyboardState(keys); } if (FKeyboardIn.SliceCount > 0) { var currentKeyboardIn = FKeyboardIn[0] ?? KeyboardState.Empty; if (currentKeyboardIn != FLastKeyboardIn) { var modifierKeys = currentKeyboardIn.ModifierKeys.Select(k => (VirtualKeyCode)k); var keys = currentKeyboardIn.KeyCodes.Select(k => (VirtualKeyCode)k).Except(modifierKeys); InputSimulator.SimulateModifiedKeyStroke(modifierKeys, keys); } FLastKeyboardIn = currentKeyboardIn; } // Works when we call GetKeyState before calling GetKeyboardState ?! //if (FHost.IsRunningInBackground) // FKeysOut[0] = KeyboardState.CurrentAsync; //else var keyboard = KeyboardState.Current; if (keyboard != KeyboardState.Empty && keyboard == FLastKeyboard) { // Keyboard stayed the same if (FStopwatch.ElapsedMilliseconds > 500) { // Simulate key repeat by generating a new keyboard with different time code var time = FStopwatch.ElapsedMilliseconds / 50; var isNewKeyDown = time != FKeyboardOut[0].Time; FKeyboardOut[0] = new KeyboardState(keyboard.KeyCodes, keyboard.CapsLock, (int)time); // Simulate legacy output if (isNewKeyDown) { FLegacyKeyBufferOut.AssignFrom(FKeyDowns); } else { FLegacyKeyBufferOut.SliceCount = 1; FLegacyKeyBufferOut[0] = string.Empty; } // Evaluate our split plugin FKeyboardSplitNode.Evaluate(spreadMax); } else { // Simulate legacy output FLegacyKeyBufferOut.SliceCount = 1; FLegacyKeyBufferOut[0] = string.Empty; } } else { FStopwatch.Restart(); FKeyboardOut[0] = keyboard; // Simulate legacy output FLegacyKeyStringOut.AssignFrom(keyboard.KeyCodes.Select(k => LegacyKeyboardHelper.VirtualKeycodeToString(k))); FKeyDowns = keyboard.KeyCodes .Except(FLastKeyboard.KeyCodes) .Select(k => LegacyKeyboardHelper.VirtualKeycodeToString(k)) .ToList(); if (FKeyDowns.Count > 0) { FLegacyKeyBufferOut.AssignFrom(FKeyDowns); } else { FLegacyKeyBufferOut.SliceCount = 1; FLegacyKeyBufferOut[0] = string.Empty; } // Evaluate our split plugin FKeyboardSplitNode.Evaluate(spreadMax); } FLastKeyboard = keyboard; } }
protected override void Evaluate(int spreadMax, bool enabled) { if (enabled) { Keyboard inputKeyboard; if (FKeyboardIn.SliceCount > 0 && FKeyboardIn[0] != null) { inputKeyboard = FKeyboardIn[0]; } else { // To support old keyboard node var keys = FLegacyKeyStringIn.Select(keyAsString => LegacyKeyboardHelper.StringToVirtualKeycode(keyAsString)) .ToList(); var keyDowns = keys.Except(FLastLegacyInputKeys); foreach (var keyDown in keyDowns) { FLegacyInputKeyboardSubject.OnNext(new KeyDownNotification(keyDown)); } var keyUps = FLastLegacyInputKeys.Except(keys); foreach (var keyUp in keyUps) { FLegacyInputKeyboardSubject.OnNext(new KeyUpNotification(keyUp)); } FLastLegacyInputKeys = keys; inputKeyboard = FLegacyInputKeyboard; } FInputKeyboardSubscription.Update(inputKeyboard); // Works when we call GetKeyState before calling GetKeyboardState ?! //if (FHost.IsRunningInBackground) // FKeysOut[0] = KeyboardState.CurrentAsync; //else var keyboardState = KeyboardState.Current; if (keyboardState != KeyboardState.Empty && keyboardState == FLastKeyboardState) { // Keyboard stayed the same if (FStopwatch.ElapsedMilliseconds > 500) { // Simulate key repeat by generating a new keyboard with different time code var time = FStopwatch.ElapsedMilliseconds / 50; var isNewKeyDown = time != FLastTime; // Simulate legacy output if (isNewKeyDown) { foreach (var keyDown in FKeyDowns) { FKeyNotificationSubject.OnNext(new KeyDownNotification(keyDown)); } FLegacyKeyBufferOut.AssignFrom(FKeyDowns.Select(k => LegacyKeyboardHelper.VirtualKeycodeToString(k))); } else { FLegacyKeyBufferOut.SliceCount = 1; FLegacyKeyBufferOut[0] = string.Empty; } FLastTime = time; // Evaluate our split plugin FKeyboardSplitNode.Evaluate(spreadMax); } else { // Simulate legacy output FLegacyKeyBufferOut.SliceCount = 1; FLegacyKeyBufferOut[0] = string.Empty; } } else { FStopwatch.Restart(); var keyDowns = keyboardState.KeyCodes.Except(FLastKeyboardState.KeyCodes); foreach (var keyDown in keyDowns) { FKeyNotificationSubject.OnNext(new KeyDownNotification(keyDown)); } var keyUps = FLastKeyboardState.KeyCodes.Except(keyboardState.KeyCodes); foreach (var keyUp in keyUps) { FKeyNotificationSubject.OnNext(new KeyUpNotification(keyUp)); } FKeyboardOut[0].CapsLock = Control.IsKeyLocked(Keys.CapsLock); // Simulate legacy output FLegacyKeyStringOut.AssignFrom(keyboardState.KeyCodes.Select(k => LegacyKeyboardHelper.VirtualKeycodeToString(k))); FKeyDowns = keyboardState.KeyCodes .Except(FLastKeyboardState.KeyCodes) .ToList(); if (FKeyDowns.Count > 0) { FLegacyKeyBufferOut.AssignFrom(FKeyDowns.Select(k => LegacyKeyboardHelper.VirtualKeycodeToString(k))); } else { FLegacyKeyBufferOut.SliceCount = 1; FLegacyKeyBufferOut[0] = string.Empty; } // Evaluate our split plugin FKeyboardSplitNode.Evaluate(spreadMax); } FLastKeyboardState = keyboardState; } }
public ISpread <Frame> Preload( ISpread <int> visibleFrameIndices, ISpread <int> preloadFrameNrs, int bufferSize, out int frameCount, out double durationIO, out double durationTexture, out int unusedFrames, ref ISpread <bool> loadedFrames) { frameCount = FFiles.Length; durationIO = 0.0; durationTexture = 0.0; unusedFrames = 0; // Nothing to do if (FFiles.Length == 0) { loadedFrames.SliceCount = 0; return(new Spread <Frame>(0)); } // Map frame numbers to file names var preloadFiles = preloadFrameNrs.Select(frameNr => FFiles[VMath.Zmod(frameNr, FFiles.Length)]).ToArray(); // Dispose previously loaded frames foreach (var file in FPreloadedFrames.Keys.ToArray()) { if (!preloadFiles.Contains(file)) { var frame = FPreloadedFrames[file]; Dispose(frame); } } // Ensure that there are as much dequeues as enqueues (or we'll run out of memory) while (FScheduledFrameInfos.Count > preloadFrameNrs.SliceCount) { var frame = Dequeue(); var frameInfo = frame.Metadata; if (!preloadFiles.Contains(frameInfo.Filename) || frameInfo.IsCanceled) { // Not needed anymore Dispose(frame); unusedFrames++; } else { FPreloadedFrames.Add(frameInfo.Filename, frame); } } // Cancel unused scheduled frames foreach (var frameInfo in FScheduledFrameInfos.Where(fi => !fi.IsCanceled)) { if (!preloadFiles.Contains(frameInfo.Filename)) { frameInfo.Cancel(); } } // Free resources if there're no frames to preload and we didn't free them yet if (preloadFiles.Length == 0 && !FClearedMemoryPool) { FMemoryPool.Clear(); // Remember that we cleared the pool FClearedMemoryPool = true; } // Schedule new frames foreach (var file in preloadFiles) { if (!IsScheduled(file) && !IsPreloaded(file)) { var frameInfo = CreateFrameInfo(file, bufferSize); Enqueue(frameInfo); } // We're back using resources from the pool -> not clean anymore FClearedMemoryPool = false; } // Write the "is loaded" state loadedFrames.SliceCount = preloadFrameNrs.SliceCount; for (int i = 0; i < loadedFrames.SliceCount; i++) { var file = preloadFiles[i]; if (!IsPreloaded(file)) { var frameInfo = FScheduledFrameInfos.First(fi => fi.Filename == file); loadedFrames[i] = frameInfo.IsLoaded; } else { loadedFrames[i] = true; } } // Wait for the visible frames (and dipose unused ones) var visibleFrames = new Spread <Frame>(0); // Map frame numbers to file names var visibleFiles = preloadFiles.Length > 0 ? visibleFrameIndices.Select(i => preloadFiles[VMath.Zmod(i, preloadFiles.Length)]) : Enumerable.Empty <string>(); foreach (var file in visibleFiles) { while (!IsPreloaded(file)) { var frame = Dequeue(); var frameInfo = frame.Metadata; if (!preloadFiles.Contains(frameInfo.Filename) || frameInfo.IsCanceled) { // Not needed anymore Dispose(frame); unusedFrames++; } else { FPreloadedFrames.Add(frameInfo.Filename, frame); } } var visibleFrame = FPreloadedFrames[file]; var visibleFrameInfo = visibleFrame.Metadata; durationIO += visibleFrameInfo.DurationIO; durationTexture += visibleFrameInfo.DurationTexture; visibleFrames.Add(visibleFrame); } // Release textures of non visible frames foreach (var frame in FPreloadedFrames.Values.Where(f => !visibleFrames.Contains(f))) { frame.Dispose(); } return(visibleFrames); }