#include "MIDItestMinMax.h"
#include "message.h"
namespace MIDItestMinMax {
Noise noise;
static const int GENLIB_LOOPCOUNT_BAIL = 100000;
typedef struct State {
CommonState __commonstate;
SineCycle __m_cycle_5;
SineData __sinedata;
int __exception;
int vectorsize;
t_sample m_gain_1;
t_sample m_bend_4;
t_sample m_freq_3;
t_sample samplerate;
t_sample m_gate_2;
inline void reset(t_param __sr, int __vs) {
__exception = 0;
vectorsize = __vs;
samplerate = __sr;
m_gain_1 = ((int)0);
m_gate_2 = ((int)0);
m_freq_3 = ((int)440);
m_bend_4 = ((int)1);
__m_cycle_5.reset(samplerate, 0);
genlib_reset_complete(this);
};
inline int perform(t_sample ** __ins, t_sample ** __outs, int __n) {
vectorsize = __n;
const t_sample * __in1 = __ins[0];
t_sample * __out1 = __outs[0];
if (__exception) {
return __exception;
} else if (( (__in1 == 0) || (__out1 == 0) )) {
__exception = GENLIB_ERR_NULL_BUFFER;
return __exception;
};
t_sample mul_6 = (m_freq_3 * m_bend_4);
debugMessage("fp", m_freq_3, m_bend_4, mul_6);
while ((__n--)) {
const t_sample in1 = (*(__in1++));
__m_cycle_5.freq(mul_6);
t_sample cycle_3 = __m_cycle_5(__sinedata);
t_sample cycleindex_4 = __m_cycle_5.phase();
t_sample mul_5 = (cycle_3 * m_gain_1);
t_sample mul_2 = (mul_5 * m_gate_2);
t_sample tanh_1 = tanh(mul_2);
t_sample out1 = tanh_1;
(*(__out1++)) = out1;
};
return __exception;
};
inline void set_gain(t_param _value) {
m_gain_1 = (_value < 0 ? 0 : (_value > 1 ? 1 : _value));
};
inline void set_gate(t_param _value) {
m_gate_2 = (_value < 0 ? 0 : (_value > 1 ? 1 : _value));
};
inline void set_freq(t_param _value) {
m_freq_3 = (_value < 20 ? 20 : (_value > 20000 ? 20000 : _value));
};
inline void set_bend(t_param _value) {
m_bend_4 = (_value < 0.25 ? 0.25 : (_value > 2 ? 2 : _value));
};
} State;
int gen_kernel_numins = 1;
int gen_kernel_numouts = 1;
int num_inputs() { return gen_kernel_numins; }
int num_outputs() { return gen_kernel_numouts; }
int num_params() { return 4; }
const char *gen_kernel_innames[] = { "in1" };
const char *gen_kernel_outnames[] = { "out1" };
int perform(CommonState *cself, t_sample **ins, long numins, t_sample **outs, long numouts, long n) {
State* self = (State *)cself;
return self->perform(ins, outs, n);
}
void reset(CommonState *cself) {
State* self = (State *)cself;
self->reset(cself->sr, cself->vs);
}
void setparameter(CommonState *cself, long index, t_param value, void *ref) {
State *self = (State *)cself;
switch (index) {
case 0: self->set_bend(value); break;
case 1: self->set_freq(value); break;
case 2: self->set_gain(value); break;
case 3: self->set_gate(value); break;
default: break;
}
}
void getparameter(CommonState *cself, long index, t_param *value) {
State *self = (State *)cself;
switch (index) {
case 0: *value = self->m_bend_4; break;
case 1: *value = self->m_freq_3; break;
case 2: *value = self->m_gain_1; break;
case 3: *value = self->m_gate_2; break;
default: break;
}
}
const char *getparametername(CommonState *cself, long index) {
if (index >= 0 && index < cself->numparams) {
return cself->params[index].name;
}
return 0;
}
t_param getparametermin(CommonState *cself, long index) {
if (index >= 0 && index < cself->numparams) {
return cself->params[index].outputmin;
}
return 0;
}
t_param getparametermax(CommonState *cself, long index) {
if (index >= 0 && index < cself->numparams) {
return cself->params[index].outputmax;
}
return 0;
}
char getparameterhasminmax(CommonState *cself, long index) {
if (index >= 0 && index < cself->numparams) {
return cself->params[index].hasminmax;
}
return 0;
}
const char *getparameterunits(CommonState *cself, long index) {
if (index >= 0 && index < cself->numparams) {
return cself->params[index].units;
}
return 0;
}
size_t getstatesize(CommonState *cself) {
return genlib_getstatesize(cself, &getparameter);
}
short getstate(CommonState *cself, char *state) {
return genlib_getstate(cself, state, &getparameter);
}
short setstate(CommonState *cself, const char *state) {
return genlib_setstate(cself, state, &setparameter);
}
void *create(t_param sr, long vs) {
State *self = new State;
self->reset(sr, vs);
ParamInfo *pi;
self->__commonstate.inputnames = gen_kernel_innames;
self->__commonstate.outputnames = gen_kernel_outnames;
self->__commonstate.numins = gen_kernel_numins;
self->__commonstate.numouts = gen_kernel_numouts;
self->__commonstate.sr = sr;
self->__commonstate.vs = vs;
self->__commonstate.params = (ParamInfo *)genlib_sysmem_newptr(4 * sizeof(ParamInfo));
self->__commonstate.numparams = 4;
pi = self->__commonstate.params + 0;
pi->name = "bend";
pi->paramtype = GENLIB_PARAMTYPE_FLOAT;
pi->defaultvalue = self->m_bend_4;
pi->defaultref = 0;
pi->hasinputminmax = false;
pi->inputmin = 0;
pi->inputmax = 1;
pi->hasminmax = true;
pi->outputmin = 0.25;
pi->outputmax = 2;
pi->exp = 0;
pi->units = ""; pi = self->__commonstate.params + 1;
pi->name = "freq";
pi->paramtype = GENLIB_PARAMTYPE_FLOAT;
pi->defaultvalue = self->m_freq_3;
pi->defaultref = 0;
pi->hasinputminmax = false;
pi->inputmin = 0;
pi->inputmax = 1;
pi->hasminmax = true;
pi->outputmin = 20;
pi->outputmax = 20000;
pi->exp = 0;
pi->units = ""; pi = self->__commonstate.params + 2;
pi->name = "gain";
pi->paramtype = GENLIB_PARAMTYPE_FLOAT;
pi->defaultvalue = self->m_gain_1;
pi->defaultref = 0;
pi->hasinputminmax = false;
pi->inputmin = 0;
pi->inputmax = 1;
pi->hasminmax = true;
pi->outputmin = 0;
pi->outputmax = 1;
pi->exp = 0;
pi->units = ""; pi = self->__commonstate.params + 3;
pi->name = "gate";
pi->paramtype = GENLIB_PARAMTYPE_FLOAT;
pi->defaultvalue = self->m_gate_2;
pi->defaultref = 0;
pi->hasinputminmax = false;
pi->inputmin = 0;
pi->inputmax = 1;
pi->hasminmax = true;
pi->outputmin = 0;
pi->outputmax = 1;
pi->exp = 0;
pi->units = "";
return self;
}
void destroy(CommonState *cself) {
State *self = (State *)cself;
genlib_sysmem_freeptr(cself->params);
delete self;
}
}