Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
S+H and save
Drop in replacement for S+H (Spreads)
But this node saves the current state in its own config pin
So when you reload the patch, S+H returns to the same state when you closed the patch.
This likely works a little different from the existing s+h node in edge cases, but in most situations it should be identical.
Also it's super simple
To use:
clone Template (Value) with Ctrl+enter, and paste this code into the code window
Hit save
If your node turns red, then check again in NodeBrowser for the new node :)
#region usings
using System;
using System.ComponentModel.Composition;
using VVVV.PluginInterfaces.V1;
using VVVV.PluginInterfaces.V2;
using VVVV.Utils.VColor;
using VVVV.Utils.VMath;
using VVVV.Core.Logging;
#endregion usings
namespace VVVV.Nodes
#region PluginInfo
[PluginInfo(Name = "S+H", Category = "Value", Version = "Save", AutoEvaluate=true, Author="elliotwoods", Help = "S+H that saves state into the patch", Tags = "")]
#endregion PluginInfo
public class SaveValueS_HNode : IPluginEvaluate
#region fields & pins
IDiffSpread<string> FSave;
[Input("Input", DefaultValue = 1.0)]
ISpread<double> FInput;
ISpread<bool> FSet;
ISpread<double> FOutput;
ILogger FLogger;
#endregion fields & pins
//called when data for any output pin is requested
public void Evaluate(int SpreadMax)
if (FSave.IsChanged)
FOutput.SliceCount = SpreadMax;
bool save = false;
for (int i = 0; i < SpreadMax; i++)
if (FSet[i])
FOutput[i] = FInput[i];
save = true;
if (save)
void Load()
string[] values = FSave[0].Split(new char[]{','});
int count = values.Length;
FOutput.SliceCount = count;
double v;
for (int i=0; i<count; i++)
if (Double.TryParse(values[i], out v))
FOutput[i] = v;
FOutput[i] = 0;
//FLogger.Log(LogType.Debug, "Load");
void Save()
string o = "";
int count = FOutput.SliceCount;
for (int i=0; i<count; i++)
o += Convert.ToString(FOutput[i]) + ",";
FSave[0] = o;
//FLogger.Log(LogType.Debug, "Save");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment