forked from esluyter/super-bufrd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SuperPoll.cpp
executable file
·191 lines (156 loc) · 4.72 KB
/
SuperPoll.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include "SC_PlugIn.hpp"
// InterfaceTable contains pointers to functions in the host (server).
static InterfaceTable *ft;
//////////////////////////////////////////////////////////////////
// SUPERPOLL
//////////////////////////////////////////////////////////////////
struct SuperPoll : public SCUnit{
public:
SuperPoll()
{
// 1. initialize the unit generator state variables.
m_trig = in0(0);
const int idSize = (int)in0(4); // number of chars in the id string
m_id_string = (char*)RTAlloc(mWorld, (idSize + 1) * sizeof(char));
if (!m_id_string) {
Print("SuperPoll: RT memory allocation failed\n");
set_calc_function<SuperPoll,&SuperPoll::next_nop>();
return;
}
for(int i = 0; i < idSize; i++)
m_id_string[i] = (char)in0(5+i);
m_id_string[idSize] = '\0';
m_mayprint = mWorld->mVerbosity >= -1;
// 2. set calc function
if (isAudioRateIn(0)) {
if (isAudioRateIn(1)) {
if (isAudioRateIn(2)) {
set_calc_function<SuperPoll,&SuperPoll::next_aaa>();
} else {
set_calc_function<SuperPoll,&SuperPoll::next_aak>();
}
} else {
set_calc_function<SuperPoll,&SuperPoll::next_ak>();
}
} else {
set_calc_function<SuperPoll,&SuperPoll::next_kk>();
}
}
~SuperPoll()
{
RTFree(mWorld, m_id_string);
}
private:
int m_samplesRemain, m_intervalSamples;
float m_trig;
float m_lastPoll;
char *m_id_string;
bool m_mayprint;
//////////////////////////////////////////////////////////////////
void next_nop(int inNumSamples)
{
}
void next_aaa(int inNumSamples)
{
const float *trig = in(0);
const float *msdBlock = in(1);
const float *lsdBlock = in(2);
float lasttrig = m_trig;
/*
float *msdOut = out(0);
float *lsdOut = out(1);
*/
for (int i=0; i < inNumSamples; ++i)
{
double msd = msdBlock[i];
double lsd = lsdBlock[i];
double value = msd + lsd;
/*
float valueMsd = (float)value;
float valueLsd = (float)(value - valueMsd);
msdOut[i] = valueMsd;
lsdOut[i] = valueLsd;
Print("%f\n", trig[i]);
*/
if((lasttrig <= 0.0) && (trig[i] > 0.0)){
if (m_mayprint)
Print("%s: %f\n", m_id_string, value);
/*
if (in0(3) >= 0.0)
SendTrigger(&mParent->mNode, (int)in0(3), msd);
*/
}
lasttrig = trig[i];
}
m_trig = lasttrig;
}
void next_aak(int inNumSamples)
{
const float *trig = in(0);
const float *msdBlock = in(1);
double lsd = in0(2);
float lasttrig = m_trig;
for (int i=0; i < inNumSamples; ++i)
{
double msd = msdBlock[i];
double value = msd + lsd;
if((lasttrig <= 0.0) && (trig[i] > 0.0)){
if (m_mayprint)
Print("%s: %f\n", m_id_string, value);
/*
if (in0(3) >= 0.0)
SendTrigger(&mParent->mNode, (int)in0(3), msd);
*/
}
lasttrig = trig[i];
}
m_trig = lasttrig;
}
void next_ak(int inNumSamples)
{
const float *trig = in(0);
double msd = in0(1);
double lsd = in0(2);
double value = msd + lsd;
float lasttrig = m_trig;
for (int i=0; i < inNumSamples; ++i)
{
if((lasttrig <= 0.0) && (trig[i] > 0.0)){
if (m_mayprint)
Print("%s: %f\n", m_id_string, value);
/*
if (in0(3) >= 0.0)
SendTrigger(&mParent->mNode, (int)in0(3), msd);
*/
}
lasttrig = trig[i];
}
m_trig = lasttrig;
}
void next_kk(int inNumSamples)
{
const float trig = in0(0);
double msd = in0(1);
double lsd = in0(2);
double value = msd + lsd;
if((m_trig <= 0.0) && (trig > 0.0)){
if (m_mayprint)
Print("%s: %f\n", m_id_string, value);
/*
if (in0(3) >= 0.0)
SendTrigger(&mParent->mNode, (int)in0(3), msd);
*/
}
m_trig = trig;
}
};
// the entry point is called by the host when the plug-in is loaded
PluginLoad(SuperBufRdUGens)
{
// InterfaceTable *inTable implicitly given as argument to the load function
ft = inTable; // store pointer to InterfaceTable
// registerUnit takes the place of the Define*Unit functions. It automatically checks for the presence of a
// destructor function.
// However, it does not seem to be possible to disable buffer aliasing with the C++ header.
registerUnit<SuperPoll>(ft, "SuperPoll");
}