-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuxObjectWrapperNodes.cs
157 lines (142 loc) · 4.92 KB
/
AuxObjectWrapperNodes.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using md.stdl.Coding;
using mp.pddn;
using Notui;
using VVVV.Hosting.Graph;
using VVVV.PluginInterfaces.V2;
using VVVV.PluginInterfaces.V2.NonGeneric;
namespace Notuiv
{
public class VAuxObject : AuxiliaryObject
{
public object Object { get; set; }
public override IAuxiliaryObject Copy()
{
return new VAuxObject { Object = Object };
}
public override void UpdateFrom(IAuxiliaryObject other)
{
if (other is VAuxObject vaux)
Object = vaux.Object;
}
}
[PluginInfo(
Name = "Wrap",
Category = "Notui.Auxiliary",
Author = "microdee",
AutoEvaluate = true
)]
public class AuxObjectWrapNode : IPluginEvaluate, IPartImportsSatisfiedNotification
{
[Import] protected IPluginHost2 FPluginHost;
[Import] protected IIOFactory FIOFactory;
[Import] protected IHDEHost Hde;
private ConfigurableTypePinGroup PinGroup;
private bool _typeChanged;
private bool _init = true;
private DiffSpreadPin _input;
private bool _prevvalid = false;
[Output("Output")] public ISpread<IAuxiliaryObject> FOut;
public void OnImportsSatisfied()
{
PinGroup = new ConfigurableTypePinGroup(FPluginHost, FIOFactory, Hde.MainLoop, "Input");
PinGroup.OnTypeChangeEnd += (sender, args) =>
{
_typeChanged = true;
if (!_init) return;
PinGroup.AddInput(new InputAttribute("Input"));
_input = PinGroup.Pd.InputPins["Input"];
_init = false;
};
}
public void Evaluate(int SpreadMax)
{
FOut.Stream.IsChanged = false;
var valid = _input != null;
if (valid) valid = _input.Spread.SliceCount > 0;
if (valid) valid = _input[0] != null;
if (valid)
{
if (!_input.Spread.IsChanged && !_typeChanged) return;
FOut.ResizeAndDismiss(_input.Spread.SliceCount, i => null);
for (int i = 0; i < _input.Spread.SliceCount; i++)
{
if (FOut[i] == null) FOut[i] = new VAuxObject {Object = _input[i]};
var vaux = (VAuxObject) FOut[i];
vaux.Object = _input[i];
}
_typeChanged = false;
FOut.Stream.IsChanged = true;
}
else
{
FOut.Stream.IsChanged = _prevvalid;
FOut.SliceCount = 0;
}
_prevvalid = valid;
}
}
[PluginInfo(
Name = "Unwrap",
Category = "Notui.Auxiliary",
Author = "microdee",
AutoEvaluate = true
)]
public class AuxObjectUnwrapNode : IPluginEvaluate, IPartImportsSatisfiedNotification
{
[Import] protected IPluginHost2 FPluginHost;
[Import] protected IIOFactory FIOFactory;
[Import] protected IHDEHost Hde;
private ConfigurableTypePinGroup PinGroup;
private bool _typeChanged;
private bool _init = true;
private SpreadPin _output;
[Input("Input")] public Pin<IAuxiliaryObject> Input;
public void OnImportsSatisfied()
{
PinGroup = new ConfigurableTypePinGroup(FPluginHost, FIOFactory, Hde.MainLoop, "Output");
PinGroup.OnTypeChangeEnd += (sender, args) =>
{
_typeChanged = true;
if (!_init) return;
PinGroup.AddOutputBinSized(new OutputAttribute("Output"));
_output = PinGroup.Pd.OutputPins["Output"];
_init = false;
};
}
public void Evaluate(int SpreadMax)
{
var valid = Input.IsConnected;
if (valid) valid = _output != null;
if (valid) valid = Input.SliceCount > 0;
if (valid)
{
if(!Input.IsChanged && !_typeChanged) return;
_output.Spread.SliceCount = Input.SliceCount;
for (int i = 0; i < Input.SliceCount; i++)
{
var cspread = (ISpread)_output[i];
if (Input[i] is VAuxObject vaux)
{
if(PinGroup.GroupType.IsInstanceOfType(vaux.Object))
{
cspread.SliceCount = 1;
cspread[0] = vaux.Object;
}
else cspread.SliceCount = 0;
}
else cspread.SliceCount = 0;
}
_typeChanged = false;
}
else
{
if(_output != null) _output.Spread.SliceCount = 0;
}
}
}
}