Skip to content

Commit

Permalink
Added Sift nodes operating on Element instances too
Browse files Browse the repository at this point in the history
  • Loading branch information
microdee committed Jun 1, 2018
1 parent 54daeb8 commit 28d7445
Show file tree
Hide file tree
Showing 26 changed files with 2,323 additions and 256 deletions.
5 changes: 5 additions & 0 deletions ContextNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class ContextNode : IPluginEvaluate, IPartImportsSatisfiedNotification, I
[Import] public IPluginHost2 PluginHost;
[Import] public IHDEHost Host;

[Config("Thread Count", DefaultValue = 4)]
public IDiffSpread<int> FThreads;

[Input("Element Prototypes")]
public Pin<ElementPrototype> FElements;

Expand Down Expand Up @@ -112,6 +115,8 @@ public void Evaluate(int SpreadMax)
Context.ConsiderReleasedAfter = FConsiderReleased[0];
Context.MinimumForce = FMinForce[0];

if (FThreads.IsChanged) Context.ParallelThreads = FThreads[0];

var touchcount = FAuxTouches.SliceCount;
var touches = Enumerable.Empty<(Vector2, int, float)>();

Expand Down
6 changes: 3 additions & 3 deletions Filters/ContextElementFilterNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected void HandleElementChange(object sender, EventArgs args)
Version = "String",
Author = "microdee"
)]
public class StringElementFilterNode : ContextElementFilterNode, IPartImportsSatisfiedNotification
public class StringContextElementFilterNode : ContextElementFilterNode, IPartImportsSatisfiedNotification
{
[Input("Query Flattened", Order = 100)]
public IDiffSpread<bool> FQueryFlattened;
Expand Down Expand Up @@ -127,7 +127,7 @@ bool CompareType(NotuiElement el)
Version = "Type",
Author = "microdee"
)]
public class TypeElementFilterNode : ContextElementFilterNode, IPartImportsSatisfiedNotification
public class TypeContextElementFilterNode : ContextElementFilterNode, IPartImportsSatisfiedNotification
{
[Input("Query Flattened", Order = 100)]
public IDiffSpread<bool> FQueryFlattened;
Expand Down Expand Up @@ -167,7 +167,7 @@ bool CompareType(NotuiElement el)
Version = "Opaq",
Author = "microdee"
)]
public class OpaqElementFilterNode : ContextElementFilterNode, IPartImportsSatisfiedNotification
public class OpaqContextElementFilterNode : ContextElementFilterNode, IPartImportsSatisfiedNotification
{
[Input("Separator", Order = 100, DefaultString = "/")]
public IDiffSpread<string> FSeparator;
Expand Down
233 changes: 233 additions & 0 deletions Filters/ElementFilterNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Notui;
using VVVV.PluginInterfaces.V2;
using VVVV.Utils.Reflection;

namespace Notuiv.Filters
{
public abstract class ElementFilterNode : IPluginEvaluate
{
[Input("Context")]
public Pin<NotuiElement> FElement;

private Spread<NotuiElement> _prevElements = new Spread<NotuiElement>();

[Input("Query")]
public IDiffSpread<ISpread<string>> FQuery;

[Output("Output")]
public ISpread<ISpread<NotuiElement>> FOut;

protected abstract void Filter(int ei, int qi, NotuiElement element, string filter);

private int _elementsChanged = 0;

public void Evaluate(int SpreadMax)
{
//FOut.Stream.IsChanged = false;
if (FQuery.IsChanged) HandleElementChange(this, EventArgs.Empty);
if (FElement.IsConnected && FElement.SliceCount > 0 && FElement[0] != null && FQuery.SliceCount > 0)
{
FOut.SliceCount = FElement.SliceCount;
int ii = 0;
if(FElement.SliceCount != _prevElements.SliceCount) HandleElementChange(this, EventArgs.Empty);
for (int i = 0; i < FElement.SliceCount; i++)
{
ii = i;
var prevValid = i < _prevElements.SliceCount;
if(FElement[i] == null)
{
if (prevValid && _prevElements[i] != null)
{
_prevElements[i].OnChildrenUpdated -= HandleElementChange;
}
continue;
}
if (!prevValid)
{
FElement[i].OnChildrenUpdated += HandleElementChange;
continue;
}

if (_prevElements[i] == null || FElement[i].GetHashCode() != _prevElements[i]?.GetHashCode())
{
if (_prevElements[i] != null)
{
_prevElements[i].OnChildrenUpdated -= HandleElementChange;
}
FElement[i].OnChildrenUpdated += HandleElementChange;
}
}

if(FElement.SliceCount < _prevElements.SliceCount)
{
for (int i = ii; i < _prevElements.SliceCount; i++)
{
if (_prevElements[i] != null)
{
_prevElements[i].OnChildrenUpdated -= HandleElementChange;
}
}
}
_prevElements.AssignFrom(FElement);
}
else
{
FOut.SliceCount = 0;
for (int i = 0; i < _prevElements.SliceCount; i++)
{
if (_prevElements[i] != null)
{
_prevElements[i].OnChildrenUpdated -= HandleElementChange;
}
}
}

if (_elementsChanged > 0)
{
FOut.SliceCount = FElement.SliceCount;
for (int i = 0; i < FElement.SliceCount; i++)
{
FOut[i].SliceCount = 0;
for (int j = 0; j < FQuery[i].SliceCount; j++)
{
Filter(i, j, FElement[i], FQuery[i][j]);
}
}
//FOut.Stream.IsChanged = true;
_elementsChanged--;
}
}

protected void HandleElementChange(object sender, EventArgs args)
{
_elementsChanged = 2;
}
}

[PluginInfo(
Name = "Sift",
Category = "Notui.Element",
Version = "String",
Author = "microdee"
)]
public class StringElementFilterNode : ElementFilterNode, IPartImportsSatisfiedNotification
{
[Input("Contains", Order = 101)]
public IDiffSpread<bool> FContains;
[Input("Use Name", Order = 102, DefaultBoolean = true)]
public IDiffSpread<bool> FUseName;

public void OnImportsSatisfied()
{
FContains.Changed += spread => HandleElementChange(this, EventArgs.Empty);
FUseName.Changed += spread => HandleElementChange(this, EventArgs.Empty);
}

protected override void Filter(int ei, int qi, NotuiElement element, string filter)
{
if (string.IsNullOrWhiteSpace(filter) || FContains.SliceCount == 0 || FUseName.SliceCount == 0)
return;
else
{
if (FOut.SliceCount == 0) return;
if (FUseName[ei])
{
FOut[ei].AddRange(
element.Children.Values
.Where(
el => FContains[ei] ?
el.Name.Contains(filter) :
el.Name.Equals(filter, StringComparison.InvariantCulture)
)
);
}
else
{
if (FContains[ei])
{
foreach (var child in element.Children.Keys)
{
if (child.Contains(filter)) FOut[ei].Add(element.Children[child]);
}
}
else
{
if (element.Children.ContainsKey(filter)) FOut[ei].Add(element.Children[filter]);
}
}
}
}
}

[PluginInfo(
Name = "Sift",
Category = "Notui.Element",
Version = "Type",
Author = "microdee"
)]
public class TypeElementFilterNode : ElementFilterNode, IPartImportsSatisfiedNotification
{
[Input("Contains", Order = 101)]
public IDiffSpread<bool> FContains;

public void OnImportsSatisfied()
{
FContains.Changed += spread => HandleElementChange(this, EventArgs.Empty);
}

protected override void Filter(int ei, int qi, NotuiElement element, string filter)
{
bool CompareType(NotuiElement el)
{
if (el.EnvironmentObject is VEnvironmentData venvdat)
return FContains[ei] ? venvdat.TypeCSharpName.Contains(filter) : venvdat.TypeCSharpName == filter;
return FContains[ei] ? el.GetType().GetCSharpName().Contains(filter) : el.GetType().GetCSharpName() == filter;
}

if (string.IsNullOrWhiteSpace(filter) || FContains.SliceCount == 0)
return;
else
{
if (FOut.SliceCount == 0) return;
FOut[ei].AddRange(element.Children.Values.Where(CompareType));
}
}
}

[PluginInfo(
Name = "Sift",
Category = "Notui.Element",
Version = "Opaq",
Author = "microdee"
)]
public class OpaqElementFilterNode : ElementFilterNode, IPartImportsSatisfiedNotification
{
[Input("Separator", Order = 100, DefaultString = "/")]
public IDiffSpread<string> FSeparator;

[Input("Use Name", Order = 101, DefaultBoolean = true)]
public IDiffSpread<bool> FUseName;

public void OnImportsSatisfied()
{
FSeparator.Changed += spread => HandleElementChange(this, EventArgs.Empty);
FUseName.Changed += spread => HandleElementChange(this, EventArgs.Empty);
}

protected override void Filter(int ei, int qi, NotuiElement element, string filter)
{
if (string.IsNullOrWhiteSpace(filter) || FUseName.SliceCount == 0 || FSeparator.SliceCount == 0) return;
else
{
if (FOut.SliceCount == 0) return;
FOut[ei].AddRange(element.Opaq(filter, FSeparator[ei], FUseName[ei]));
}
}
}
}
13 changes: 7 additions & 6 deletions Notuiv.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
<HintPath>dlls\FeralTic.dll</HintPath>
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="md.stdl, Version=0.2.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\md-stdl.0.2.1-beta\lib\Net47\md.stdl.dll</HintPath>
<Reference Include="md.stdl, Version=0.2.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\md-stdl.0.2.3-beta\lib\Net47\md.stdl.dll</HintPath>
</Reference>
<Reference Include="mp.pddn, Version=1.1.28.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\mp.pddn.1.1.28\lib\net47\mp.pddn.dll</HintPath>
<Reference Include="mp.pddn, Version=1.1.31.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\mp.pddn.1.1.31\lib\net47\mp.pddn.dll</HintPath>
</Reference>
<Reference Include="Notui, Version=0.2.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Notui.0.2.1-beta\lib\Net47\Notui.dll</HintPath>
<Reference Include="Notui, Version=0.2.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Notui.0.2.2-beta\lib\Net47\Notui.dll</HintPath>
</Reference>
<Reference Include="SevenZip, Version=9.20.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\LZMA-SDK.9.20\lib\net20\SevenZip.dll</HintPath>
Expand Down Expand Up @@ -174,6 +174,7 @@
<Compile Include="ElementInfoNode.cs" />
<Compile Include="EventsSplit.cs" />
<Compile Include="Filters\ContextElementFilterNode.cs" />
<Compile Include="Filters\ElementFilterNode.cs" />
<Compile Include="Generic\GenericAuxiliaryObjectNodes.cs" />
<Compile Include="Generic\GenericBehaviorNodes.cs" />
<Compile Include="Generic\GenericContextSpreadNodes.cs" />
Expand Down
18 changes: 12 additions & 6 deletions deploy/Notuiv/girlpower/AppStructure/Buttons.v4p
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!DOCTYPE PATCH SYSTEM "http://vvvv.org/versions/vvvv50alpha35.18.dtd" >
<!DOCTYPE PATCH SYSTEM "http://vvvv.org/versions/vvvv50alpha36.1.dtd" >
<PATCH nodename="D:\local\vvvv-gp\packs\Notuiv\girlpower\AppStructure\Buttons.v4p" systemname="Buttons" filename="D:\local\vvvv-gp\packs\Notuiv\girlpower\AppStructure\Buttons.v4p" scrollx="0" scrolly="0">
<BOUNDS type="Window" left="17580" top="8520" width="13830" height="17100">
<BOUNDS type="Window" left="8670" top="0" width="12945" height="13800">
</BOUNDS>
<PACK Name="dx11" Version="1.2">
<PACK Name="dx11" Version="1.3.0.1">
</PACK>
<PACK Name="KeyboardUI" Version="1.1.1">
</PACK>
Expand Down Expand Up @@ -47,6 +47,8 @@
</BOUNDS>
<PIN pinname="Input Value" visible="1">
</PIN>
<PIN pinname="Receive String" slicecount="1" values="Notui.Context">
</PIN>
</NODE>
<NODE systemname="Sift (Notui.Context String)" filename="%VVVV%\packs\Notuiv\nodes\plugins\Notuiv.dll" nodename="Sift (Notui.Context String)" componentmode="Hidden" id="4">
<BOUNDS type="Node" left="7110" top="2265" width="100" height="100">
Expand All @@ -57,7 +59,7 @@
</PIN>
<PIN pinname="Use Name" slicecount="1" visible="1" values="0">
</PIN>
<PIN pinname="Context" visible="1">
<PIN pinname="Context" visible="1" slicecount="1" values="||">
</PIN>
<PIN pinname="Output" visible="1">
</PIN>
Expand Down Expand Up @@ -91,7 +93,7 @@
<LINK srcnodeid="3" srcpinname="Input Value" dstnodeid="4" dstpinname="Context">
</LINK>
<NODE systemname="AND (Boolean)" nodename="AND (Boolean)" componentmode="Hidden" id="8">
<BOUNDS type="Node" left="7290" top="3390" width="100" height="100">
<BOUNDS type="Node" left="6675" top="3420" width="100" height="100">
</BOUNDS>
<PIN pinname="Input 1" visible="1" slicecount="4" values="0,0,0,0">
</PIN>
Expand Down Expand Up @@ -423,6 +425,8 @@
</PIN>
<PIN pinname="Behavior" slicecount="1" values="Toggle">
</PIN>
<PIN pinname="X Input Value" slicecount="1" values="0">
</PIN>
</NODE>
<LINK srcnodeid="27" srcpinname="Y Output Value" dstnodeid="4" dstpinname="Use Name">
</LINK>
Expand Down Expand Up @@ -673,7 +677,7 @@
</PIN>
</NODE>
<NODE systemname="OR (Boolean Spectral)" nodename="OR (Boolean Spectral)" componentmode="Hidden" id="46">
<BOUNDS type="Node" left="7290" top="3930" width="100" height="100">
<BOUNDS type="Node" left="7515" top="3900" width="100" height="100">
</BOUNDS>
<PIN pinname="Input" visible="1" slicecount="2" values="0,0">
</PIN>
Expand Down Expand Up @@ -818,4 +822,6 @@
</LINK>
<LINK srcnodeid="49" srcpinname="Transform Out" dstnodeid="17" dstpinname="Transform In">
</LINK>
<PACK Name="vvvv-ZeroMQ" Version="0.5.7">
</PACK>
</PATCH>
Loading

0 comments on commit 28d7445

Please sign in to comment.