I popped into the IRC channel yesterday to ask if there was a node for something I needed but couldn’t stick around to see the answers so now I’m postin here instead to ask if there already is a node for this purpose or if there’s a need for it and in that case what it should be called.
My input is a spread of consed sub-spreads all having the same number of slices. The output spread should have the number of slices as one sub spread where each slice is the sum of the n:th slice of every subspread of the input
For me it was easier to write a quick plugin than trying to figure out how to patch it in a tidy way. Below is the plugin code:
namespace VVVV.Nodes
{
#region PluginInfo
[PluginInfo(Name = "SumNthSlices", Category = "Value", Help = "Basic template with one value in/out", Tags = "")](PluginInfo(Name = "SumNthSlices", Category = "Value", Help = "Basic template with one value in/out", Tags = ""))
#endregion PluginInfo
public class ValueSumNthSlicesNode : IPluginEvaluate
{
#region fields & pins
[Input("Input", DefaultValue = 1.0)](Input("Input", DefaultValue = 1.0))
public IDiffSpread<double> FInput;
[Input("Elements", DefaultValue = 1.0)](Input("Elements", DefaultValue = 1.0))
public IDiffSpread<int> FElements;
[Output("Output")](Output("Output"))
public ISpread<double> FOutput;
[Import()](Import())
public ILogger FLogger;
#endregion fields & pins
double[]() result = null;
int elements = 1;
//called when data for any output pin is requested
public void Evaluate(int SpreadMax)
{
if( result == null || FElements.IsChanged ) {
elements = FElements[0](0);
if( elements <= 0 ) elements = 1;
result = new double[ elements ]( elements );
}
if( FInput.IsChanged || FElements.IsChanged ) {
Array.Clear( result, 0, result.Length);
for (int i = 0; i < SpreadMax; i++) {
int index = i % elements;
result[ index ]( index ) += FInput[i](i);
}
FOutput.AssignFrom( result );
}
}
}
}
Is there already any node for this, or a simple way to patch it with a few nodes? The number of slices per sub spread/output and the number of sub spreads must be dynamic.
If not is there a need for it and if so what should it be called?
(I know the code could/should be re-factored a bit since for example now the array will be cleared when it doesn’t need to be after the number of elements changed…)