crap/template/vst.cpp

240 lines
4.6 KiB
C++
Raw Normal View History

//#INCLUDE
//#REDEFINE
2015-12-07 04:54:47 -08:00
#include <stdio.h>
#include "public.sdk/source/vst2.x/audioeffectx.h"
2014-01-29 17:55:11 -08:00
// 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);
2015-12-10 11:18:51 -08:00
virtual ~plugin();
void resume();
void suspend();
void processReplacing(float **, float **, VstInt32);
void processDoubleReplacing(double **, double **, VstInt32);
bool setProcessPrecision(VstInt32 precision);
void setSampleRate(float);
2014-02-03 15:00:17 -08:00
void setProgramName(char *);
void getProgramName(char *);
bool getProgramNameIndexed(VstInt32, VstInt32, char *);
bool getEffectName(char *);
bool getVendorString(char *);
bool getProductString(char *);
//VstInt32 getVendorVersion();
2014-01-29 17:55:11 -08:00
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
2015-12-10 11:18:51 -08:00
char programName[kVstMaxProgNameLen + 1];
2014-02-03 15:00:17 -08:00
Param *params;
2015-06-10 20:48:07 -07:00
Crap *crap;
};
AudioEffect *
2014-02-05 23:47:16 -08:00
createEffectInstance(audioMasterCallback audioMaster)
{
2015-06-10 20:48:07 -07:00
// TODO: return new plugin<CrapPlug>(audioMaster);
return new plugin(audioMaster);
}
plugin::plugin(audioMasterCallback audioMaster)
: AudioEffectX(audioMaster, 1, CrapPlug::parameters)
{
2015-06-10 20:48:07 -07:00
crap = new CrapPlug();
if (CrapPlug::parameters)
params = new Param[CrapPlug::parameters];
setNumInputs(2);
setNumOutputs(2);
setUniqueID(CrapPlug::id);
canProcessReplacing();
2014-02-03 15:00:17 -08:00
canDoubleReplacing();
vst_strncpy(programName, "Init", kVstMaxProgNameLen);
CrapPlug::construct_params(params);
}
plugin::~plugin()
{
2015-06-10 20:48:07 -07:00
delete crap;
if (CrapPlug::parameters)
delete[] params;
}
void
2014-02-05 23:47:16 -08:00
plugin::resume()
{
2015-06-10 20:48:07 -07:00
crap->resume();
AudioEffectX::resume();
}
void
2014-02-05 23:47:16 -08:00
plugin::suspend()
{
AudioEffectX::suspend();
2015-06-10 20:48:07 -07:00
crap->pause();
}
void
2014-02-05 23:47:16 -08:00
plugin::processReplacing(
float **inputs, float **outputs, VstInt32 count)
{
2015-06-10 20:48:07 -07:00
crap->process(
inputs[0], inputs[1],
outputs[0], outputs[1],
count);
}
void
2014-02-05 23:47:16 -08:00
plugin::processDoubleReplacing(
double **inputs, double **outputs, VstInt32 count)
{
2015-06-10 20:48:07 -07:00
crap->process(
inputs[0], inputs[1],
outputs[0], outputs[1],
count);
}
bool
2014-02-05 23:47:16 -08:00
plugin::setProcessPrecision(VstInt32 precision)
{
2014-01-29 17:55:11 -08:00
return true;
}
void
2014-02-05 23:47:16 -08:00
plugin::setSampleRate(float fs)
{
AudioEffectX::setSampleRate(fs);
2015-06-10 20:48:07 -07:00
crap->adjust(params, (unsigned long) fs);
2013-12-22 16:23:57 -08:00
#ifdef DELAY
setInitialDelay(global_delay);
#endif
}
bool
2014-02-05 23:47:16 -08:00
plugin::getEffectName(char *name)
{
vst_strncpy(name, CrapPlug::label, kVstMaxEffectNameLen);
2014-01-29 17:55:11 -08:00
return true;
}
bool
plugin::getProductString(char *text)
{
vst_strncpy(text, CrapPlug::name, kVstMaxProductStrLen);
2014-01-29 17:55:11 -08:00
return true;
}
bool
plugin::getVendorString(char *text)
{
vst_strncpy(text, CrapPlug::author, kVstMaxVendorStrLen);
2014-01-29 17:55:11 -08:00
return true;
}
2014-02-03 15:00:17 -08:00
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;
}
2014-01-29 17:55:11 -08:00
void
plugin::setParameter(VstInt32 index, float value)
{
if (index >= CrapPlug::parameters) return;
params[index].set(value);
2015-06-10 20:48:07 -07:00
crap->adjust_one(params, index);
2014-01-29 17:55:11 -08:00
}
float
plugin::getParameter(VstInt32 index)
{
if (index >= CrapPlug::parameters) return 0;
return params[index].get();
2014-01-29 17:55:11 -08:00
}
void
plugin::getParameterName(VstInt32 index, char *text)
{
if (index >= CrapPlug::parameters) return;
2014-01-29 17:55:11 -08:00
vst_strncpy(text, params[index].name, MAX_PARAM_LEN);
}
void
plugin::getParameterDisplay(VstInt32 index, char *text)
{
if (index >= CrapPlug::parameters) return;
2014-01-29 17:55:11 -08:00
Param *p = &params[index];
2015-12-10 11:36:08 -08:00
char display[MAX_PARAM_LEN + 1];
2014-01-29 17:55:11 -08:00
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");
2014-01-29 17:55:11 -08:00
break;
default:
sprintf(display, "error");
}
vst_strncpy(text, display, MAX_PARAM_LEN);
}
void
plugin::getParameterLabel(VstInt32 index, char *text)
{
if (index >= CrapPlug::parameters) return;
2014-01-29 17:55:11 -08:00
Param *p = &params[index];
2015-12-10 11:36:08 -08:00
char display[MAX_PARAM_LEN + 1];
2014-01-29 17:55:11 -08:00
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);
}