forked from t3kt/DistThresholdCHOP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDistThresholdCHOP.cpp
176 lines (155 loc) · 4.25 KB
/
DistThresholdCHOP.cpp
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include "DistThresholdCHOP.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// These functions are basic C function, which the DLL loader can find
// much easier than finding a C++ Class.
// The DLLEXPORT prefix is needed so the compile exports these functions from the .dll
// you are creating
extern "C"
{
DLLEXPORT int GetCHOPAPIVersion(void)
{
// Always return CHOP_CPLUSPLUS_API_VERSION in this function.
return CHOP_CPLUSPLUS_API_VERSION;
}
DLLEXPORT CHOP_CPlusPlusBase* CreateCHOPInstance(const CHOP_NodeInfo *info)
{
// Return a new instance of your class every time this is called.
// It will be called once per CHOP that is using the .dll
return new DistThresholdCHOP(info);
}
DLLEXPORT void DestroyCHOPInstance(CHOP_CPlusPlusBase *instance)
{
// Delete the instance here, this will be called when
// Touch is shutting down, when the CHOP using that instance is deleted, or
// if the CHOP loads a different DLL
delete (DistThresholdCHOP*)instance;
}
};
void DistThresholdCHOP::getGeneralInfo(CHOP_GeneralInfo *ginfo)
{
// This will cause the node to cook every frame
ginfo->cookEveryFrameIfAsked = true;
//ginfo->timeslice = true;
ginfo->timeslice = false;
ginfo->inputMatchIndex = 0;
}
void DistThresholdCHOP::loadSettings( const CHOP_FloatInput *inputs )
{
for( int setting = 0; setting < NUM_SETTINGS; setting++ )
{
settings[setting] = inputs[setting].values[0];
}
}
bool DistThresholdCHOP::getOutputInfo(CHOP_OutputInfo *info)
{
if( info->numChannels == 0 || info->length == 0 )
{
return false;
}
info->numChannels = NUM_OUTS;
loadSettings(info->inputArrays->floatInputs);
const int maxLines = (int)settings[SETTING_MAXLINES];
const float distMin = settings[SETTING_DISTMIN];
const float distMax = settings[SETTING_DISTMAX];
const bool useSeparateSource = settings[SETTING_SEPARATESOURCE] != 0;
//float fade = info->inputArrays->floatInputs[0].values[1];
lines.reset( maxLines );
const CHOP_CHOPInput input0 = info->inputArrays->CHOPInputs[0];
const int input0len = input0.length;
if (useSeparateSource && info->inputArrays->numCHOPInputs >= 2)
{
const int maxLinesPerSource = (int)settings[SETTING_MAXLINESPERSOURCE];
const CHOP_CHOPInput input1 = info->inputArrays->CHOPInputs[1];
const int input1len = input1.length;
for(int i = 0; i < input0len && lines.canFitMore(); i++)
{
InputPoint p1(input0.channels, i);
int linesForSource = 0;
for(int j = 0; j < input1len; j++)
{
InputPoint p2(input1.channels, j);
float sqrdist = p1.squareDist(p2);
if (sqrdist<distMax && sqrdist >=distMin)
{
if(!lines.addLine( p1, p2, sqrdist ))
break;
linesForSource++;
if(linesForSource >= maxLinesPerSource)
break;
}
}
}
}
else if (info->inputArrays->numCHOPInputs >= 1)
{
for (int i = 0; i < input0len && lines.canFitMore(); i++)
{
const InputPoint p1(input0.channels, i);
for (int j = i+1; j < input0len; j++)
{
InputPoint p2(input0.channels, j);
float sqrdist = p1.squareDist(p2);
if (sqrdist<distMax && sqrdist >=distMin)
{
if(!lines.addLine(p1, p2, sqrdist))
break;
}
}
}
}
info->length = max(1, lines.getNumLines());
return true;
}
void DistThresholdCHOP::execute(const CHOP_Output* output, const CHOP_InputArrays* inputs, void* reserved)
{
if (inputs->numCHOPInputs > 0 && inputs->CHOPInputs[0].length > 0 && inputs->CHOPInputs[0].numChannels > 0)
{
if( lines.getNumLines() > 0 )
lines.copyTo(output);
else
{
for( int part = 0; part < NUM_OUTS; part++ )
output->channels[part][0] = 0;
}
}
}
enum
{
INFO_NUMLINES = NUM_SETTINGS,
NUM_INFO
};
int DistThresholdCHOP::getNumInfoCHOPChans()
{
return NUM_INFO;
}
void DistThresholdCHOP::getInfoCHOPChan( int index, CHOP_InfoCHOPChan *chan )
{
switch( index )
{
case SETTING_DISTMAX:
chan->name = "distmax";
break;
case SETTING_MAXLINES:
chan->name = "maxlines";
break;
case SETTING_MAXLINESPERSOURCE:
chan->name = "maxlinespersource";
break;
case SETTING_DISTMIN:
chan->name = "distmin";
break;
case SETTING_SEPARATESOURCE:
chan->name = "separatesource";
break;
case INFO_NUMLINES:
chan->name = "numlines";
chan->value = (float)lines.getNumLines();
break;
}
if( index < NUM_SETTINGS )
{
chan->value = settings[index];
}
}