-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathBasicGeneratorCHOP.cpp
More file actions
169 lines (142 loc) · 4.58 KB
/
BasicGeneratorCHOP.cpp
File metadata and controls
169 lines (142 loc) · 4.58 KB
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
/* Shared Use License: This file is owned by Derivative Inc. (Derivative)
* and can only be used, and/or modified for use, in conjunction with
* Derivative's TouchDesigner software, and only if you are a licensee who has
* accepted Derivative's TouchDesigner license or assignment agreement
* (which also govern the use of this file). You may share or redistribute
* a modified version of this file provided the following conditions are met:
*
* 1. The shared file or redistribution must retain the information set out
* above and this list of conditions.
* 2. Derivative's name (Derivative Inc.) or its trademarks may not be used
* to endorse or promote products derived from this file without specific
* prior written permission from Derivative.
*/
#include "BasicGeneratorCHOP.h"
#include "Parameters.h"
#include <string>
#include <array>
#include <cassert>
#include <cmath>
// 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
void
FillCHOPPluginInfo(CHOP_PluginInfo *info)
{
// For more information on CHOP_PluginInfo see CHOP_CPlusPlusBase.h
// Always set this to CHOPCPlusPlusAPIVersion.
info->apiVersion = CHOPCPlusPlusAPIVersion;
// For more information on OP_CustomOPInfo see CPlusPlus_Common.h
OP_CustomOPInfo& customInfo = info->customOPInfo;
// Unique name of the node which starts with an upper case letter, followed by lower case letters or numbers
customInfo.opType->setString("Basicgenerator");
// English readable name
customInfo.opLabel->setString("Basic Generator");
// Information of the author of the node
customInfo.authorName->setString("Author Name");
customInfo.authorEmail->setString("email@email");
// This CHOP takes no inputs
customInfo.minInputs = 0;
customInfo.maxInputs = 0;
}
DLLEXPORT
CHOP_CPlusPlusBase*
CreateCHOPInstance(const OP_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 BasicGeneratorCHOP(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 (BasicGeneratorCHOP*)instance;
}
};
BasicGeneratorCHOP::BasicGeneratorCHOP(const OP_NodeInfo*)
{
}
BasicGeneratorCHOP::~BasicGeneratorCHOP()
{
}
void
BasicGeneratorCHOP::getGeneralInfo(CHOP_GeneralInfo* ginfo, const OP_Inputs*, void*)
{
// This chop doesn't need to cook every frame
ginfo->cookEveryFrameIfAsked = false;
// Note: To disable timeslicing you'll need to turn this off, as well as ensure that
// getOutputInfo() returns true, and likely also set the info->numSamples to how many
// samples you want to generate for this CHOP. Otherwise it'll take on length of the
// input CHOP, which may be timesliced.
ginfo->timeslice = false;
}
bool
BasicGeneratorCHOP::getOutputInfo(CHOP_OutputInfo* info, const OP_Inputs* inputs, void*)
{
info->numChannels = inputs->getParInt("Numberofchannels");
info->numSamples = inputs->getParInt("Length");
info->startIndex = 0;
return true;
}
void
BasicGeneratorCHOP::getChannelName(int32_t index, OP_String *name, const OP_Inputs*, void*)
{
std::string channelName = "chan" + std::to_string(index);
name->setString(channelName.c_str());
}
void
BasicGeneratorCHOP::execute(CHOP_Output* output,
const OP_Inputs* inputs,
void*)
{
// Get all Parameters
bool applyScale = myParms.evalApplyscale(inputs);
double scale = myParms.evalScale(inputs);
OperationMenuItems operation = myParms.evalOperation(inputs);
inputs->enablePar(ScaleName, applyScale);
// Get length and channels from the output since they first need to be set to the current size
int length = output->numSamples;
int channels = output->numChannels;
// Calculate scale*(channel operation sample)
double curValue;
for (int i = 0; i < channels; ++i)
{
for (int j = 0; j < length; ++j)
{
switch (operation)
{
case OperationMenuItems::Add:
{
curValue = (double)i + j;
break;
}
case OperationMenuItems::Multiply:
{
curValue = (double)i * j;
break;
}
case OperationMenuItems::Power:
default:
{
curValue = std::pow((double)i, (double)j);
break;
}
}
curValue *= scale;
output->channels[i][j] = (float)curValue;
}
}
}
void
BasicGeneratorCHOP::setupParameters(OP_ParameterManager* manager, void*)
{
myParms.setup(manager);
}