Guest User

nodes and their slices

a guest
May 7th, 2012
126
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #region usings
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel.Composition;
  5.  
  6. using VVVV.PluginInterfaces.V1;
  7. using VVVV.PluginInterfaces.V2;
  8. using VVVV.Utils.VColor;
  9. using VVVV.Utils.VMath;
  10.  
  11. using VVVV.Core.Logging;
  12. #endregion usings
  13.  
  14. namespace VVVV.Nodes
  15. {
  16. public class Foo
  17. {
  18. private double FSomeThingToRemember;
  19.  
  20. public double Step(double a, double b)
  21. {
  22. var c = a*b+(FSomeThingToRemember/10000);
  23. FSomeThingToRemember += c;
  24. return c;
  25. }
  26. }
  27.  
  28. [PluginInfo(Name = "Template", Category = "Value")]
  29. public class FooNode : IPluginEvaluate
  30. {
  31. [Input("Input")] ISpread<double> FInput;
  32. [Input("Input2")] ISpread<double> FInput2;
  33.  
  34. [Output("Output")] ISpread<double> FOutput;
  35.  
  36. int FSliceCount;
  37. List<Foo> Slices = new List<Foo>();
  38.  
  39. public void Evaluate(int SpreadMax)
  40. {
  41. SpreadMax = 1;
  42. SpreadMax = SpreadMax.CombineWith(FInput);
  43. SpreadMax = SpreadMax.CombineWith(FInput2);
  44.  
  45. if (SpreadMax > FSliceCount)
  46. for (int i = FSliceCount; i < SpreadMax; i++)
  47. Slices.Add(new Foo());
  48.  
  49. if (SpreadMax < FSliceCount)
  50. for (int i = FSliceCount-1; i >= SpreadMax; i--)
  51. Slices.RemoveAt(i);
  52.  
  53. FOutput.SliceCount = SpreadMax;
  54. FSliceCount = SpreadMax;
  55.  
  56. for (int i = 0; i < SpreadMax; i++)
  57. {
  58. var slice = Slices[i];
  59. FOutput[i] = slice.Step(FInput[i], FInput2[i]);
  60. }
  61. }
  62. }
  63. }
RAW Paste Data