231 lines
4.4 KiB
C++
231 lines
4.4 KiB
C++
#include <stdio.h>
|
|
#include "public.sdk/source/vst2.x/audioeffectx.h"
|
|
|
|
//#INCLUDE
|
|
//#REDEFINE
|
|
|
|
// VST 2.4 by standard only holds 8 (+ 1 null) length strings,
|
|
// but this is never the case in practice. I've seen up to 24.
|
|
#define MAX_PARAM_LEN 24
|
|
|
|
struct plugin : public AudioEffectX
|
|
{
|
|
plugin(audioMasterCallback audioMaster);
|
|
~plugin();
|
|
|
|
void resume();
|
|
void suspend();
|
|
void processReplacing(float **, float **, VstInt32);
|
|
void processDoubleReplacing(double **, double **, VstInt32);
|
|
|
|
bool setProcessPrecision(VstInt32 precision);
|
|
|
|
void setSampleRate(float);
|
|
void setProgramName(char *);
|
|
void getProgramName(char *);
|
|
bool getProgramNameIndexed(VstInt32, VstInt32, char *);
|
|
bool getEffectName(char *);
|
|
bool getVendorString(char *);
|
|
bool getProductString(char *);
|
|
//VstInt32 getVendorVersion();
|
|
|
|
void setParameter(VstInt32, float);
|
|
float getParameter(VstInt32);
|
|
void getParameterName(VstInt32, char *); // eg. Gain
|
|
void getParameterDisplay(VstInt32, char *); // eg. -3.3
|
|
void getParameterLabel(VstInt32, char *); // eg. dB
|
|
|
|
char programName[kVstMaxProgNameLen];
|
|
|
|
Param params[CrapPlug::parameters];
|
|
|
|
CrapPlug crap;
|
|
};
|
|
|
|
AudioEffect *
|
|
createEffectInstance(audioMasterCallback audioMaster)
|
|
{
|
|
return new plugin(audioMaster);
|
|
}
|
|
|
|
plugin::plugin(audioMasterCallback audioMaster)
|
|
: AudioEffectX(audioMaster, 1, CrapPlug::parameters)
|
|
{
|
|
setNumInputs(2);
|
|
setNumOutputs(2);
|
|
setUniqueID(CrapPlug::id);
|
|
canProcessReplacing();
|
|
canDoubleReplacing();
|
|
vst_strncpy(programName, "Init", kVstMaxProgNameLen);
|
|
CrapPlug::construct_params(params);
|
|
}
|
|
|
|
plugin::~plugin()
|
|
{
|
|
}
|
|
|
|
void
|
|
plugin::resume()
|
|
{
|
|
crap.resume();
|
|
AudioEffectX::resume();
|
|
}
|
|
|
|
void
|
|
plugin::suspend()
|
|
{
|
|
AudioEffectX::suspend();
|
|
crap.pause();
|
|
}
|
|
|
|
void
|
|
plugin::processReplacing(
|
|
float **inputs, float **outputs, VstInt32 count)
|
|
{
|
|
crap.process(
|
|
inputs[0], inputs[1],
|
|
outputs[0], outputs[1],
|
|
count);
|
|
}
|
|
|
|
void
|
|
plugin::processDoubleReplacing(
|
|
double **inputs, double **outputs, VstInt32 count)
|
|
{
|
|
crap.process(
|
|
inputs[0], inputs[1],
|
|
outputs[0], outputs[1],
|
|
count);
|
|
}
|
|
|
|
bool
|
|
plugin::setProcessPrecision(VstInt32 precision)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
void
|
|
plugin::setSampleRate(float fs)
|
|
{
|
|
AudioEffectX::setSampleRate(fs);
|
|
crap.adjust(params, (unsigned long) fs);
|
|
#ifdef DELAY
|
|
setInitialDelay(global_delay);
|
|
#endif
|
|
}
|
|
|
|
bool
|
|
plugin::getEffectName(char *name)
|
|
{
|
|
vst_strncpy(name, CrapPlug::label, kVstMaxEffectNameLen);
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
plugin::getProductString(char *text)
|
|
{
|
|
vst_strncpy(text, CrapPlug::name, kVstMaxProductStrLen);
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
plugin::getVendorString(char *text)
|
|
{
|
|
vst_strncpy(text, CrapPlug::author, kVstMaxVendorStrLen);
|
|
return true;
|
|
}
|
|
|
|
void
|
|
plugin::setProgramName (char *text)
|
|
{
|
|
vst_strncpy(programName, text, kVstMaxProgNameLen);
|
|
}
|
|
|
|
void
|
|
plugin::getProgramName (char *text)
|
|
{
|
|
vst_strncpy(text, programName, kVstMaxProgNameLen);
|
|
}
|
|
|
|
bool
|
|
plugin::getProgramNameIndexed(VstInt32 category, VstInt32 index, char *text)
|
|
{
|
|
if (index != 0) return false;
|
|
vst_strncpy(text, programName, kVstMaxProgNameLen);
|
|
return true;
|
|
}
|
|
|
|
void
|
|
plugin::setParameter(VstInt32 index, float value)
|
|
{
|
|
if (index >= CrapPlug::parameters) return;
|
|
params[index].set(value);
|
|
crap.adjust_one(params, index);
|
|
}
|
|
|
|
float
|
|
plugin::getParameter(VstInt32 index)
|
|
{
|
|
if (index >= CrapPlug::parameters) return 0;
|
|
return params[index].get();
|
|
}
|
|
|
|
void
|
|
plugin::getParameterName(VstInt32 index, char *text)
|
|
{
|
|
if (index >= CrapPlug::parameters) return;
|
|
vst_strncpy(text, params[index].name, MAX_PARAM_LEN);
|
|
}
|
|
|
|
void
|
|
plugin::getParameterDisplay(VstInt32 index, char *text)
|
|
{
|
|
if (index >= CrapPlug::parameters) return;
|
|
|
|
Param *p = ¶ms[index];
|
|
char display[MAX_PARAM_LEN];
|
|
|
|
switch (p->scale) {
|
|
case SCALE_FLOAT:
|
|
case SCALE_LOG:
|
|
case SCALE_HZ:
|
|
case SCALE_DB:
|
|
sprintf(display, "%0.2f", p->value);
|
|
break;
|
|
case SCALE_INT:
|
|
sprintf(display, "%i", (int) p->value);
|
|
break;
|
|
case SCALE_TOGGLE:
|
|
sprintf(display, (p->get() < 0.5) ? "off" : "on");
|
|
break;
|
|
default:
|
|
sprintf(display, "error");
|
|
}
|
|
|
|
vst_strncpy(text, display, MAX_PARAM_LEN);
|
|
}
|
|
|
|
void
|
|
plugin::getParameterLabel(VstInt32 index, char *text)
|
|
{
|
|
if (index >= CrapPlug::parameters) return;
|
|
|
|
Param *p = ¶ms[index];
|
|
char display[MAX_PARAM_LEN];
|
|
|
|
switch (p->scale) {
|
|
case SCALE_HZ:
|
|
sprintf(display, "Hz");
|
|
break;
|
|
case SCALE_DB:
|
|
sprintf(display, "dB");
|
|
break;
|
|
case SCALE_FLOAT:
|
|
case SCALE_INT:
|
|
case SCALE_TOGGLE:
|
|
case SCALE_LOG:
|
|
display[0] = 0;
|
|
}
|
|
|
|
vst_strncpy(text, display, MAX_PARAM_LEN);
|
|
}
|