I'm writing a plugin to pure C.
I have a problem with the translation of some code with C++ for GUI.
Who can set an example to create a code for the plug-in window?
I know how to write code for Windows standalone programm, only plug I Do not know how and where to call a function createwindow ()
Here my example code in C
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <windows.h>
#include "aeffect.h"
#include "aeffectx.h"
__declspec(dllexport) AEffect* VSTPluginMain(audioMasterCallback audioMaster);
typedef struct ERect ERect;
typedef struct VstEvents VstEvents;
typedef struct VstMidiEvent VstMidiEvent;
typedef struct VstParameterProperties VstParameterProperties;
const int channels = 2;
const int NumParams = 2;
float sampleRate;
int blockSize;
float param_volume = 0.5f;
float mode_value;
float sample(float in)
{
return in * (param_volume * 4.0f);
}
void int2string(VstInt32 value, char *string) { sprintf(string, "%d", value); }
void float2string(float value, char *string) { sprintf(string, "%.2f", value); }
VstInt32 float2int(float number) { return (VstInt32)(1000.0f * number); }
void setSampleRate(float sampleRate) { sampleRate = sampleRate; }
void setBlockSize(VstInt32 blockSize) { blockSize = blockSize; }
VstInt32 processEvents(VstEvents* ev) {
for (int i = 0; i < ev->numEvents; i++) {
VstEvent* event = ev->events[i];
if (event->type == kVstMidiType) {
VstMidiEvent* midiEvent = (VstMidiEvent*) event;
VstInt8 status = midiEvent->midiData[0];
VstInt8 data1 = midiEvent->midiData[0];
VstInt8 data2 = midiEvent->midiData[0];
printf("MIDI: %02x %02x %02x\n", status, data1, data2); } }
return 0; }
enum ParamNames {
parameter1,
parameter2 };
bool getVendorString(char* ptr) {
strncpy((char*)ptr, "Alex Longard", kVstMaxVendorStrLen);
return true; }
void getParameterName(VstInt32 index, char* text) {
switch (index) {
case parameter1:
strncpy((char*)text, "Volume", kVstMaxParamStrLen);
break;
case parameter2:
strncpy((char*)text, "Mode", kVstMaxParamStrLen);
break; } }
void getParameterLabel(VstInt32 index, char *label) {
switch (index) {
case parameter1:
float2string(param_volume, label);
break;
case parameter2: switch (float2int(mode_value)) {
case 0:
strncpy((char*)label, "Left", kVstMaxParamStrLen);
break;
case 1:
strncpy((char*)label, "Center", kVstMaxParamStrLen);
break;
case 2:
strncpy((char*)label, "Right", kVstMaxParamStrLen);
break;
default:
strncpy((char*)label, "Empty", kVstMaxParamStrLen);
break; } } }
void getParameterDisplay (VstInt32 index, char* text) {
*text = 0; }
bool getParameterProperties(VstInt32 index, VstParameterProperties* p) {
return false; }
VstIntPtr Dispatcher(AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt)
{
VstIntPtr result = 0;
switch (opcode)
{
case effSetSampleRate:
setSampleRate(opt);
break;
case effSetBlockSize:
setBlockSize((VstInt32)value);
break;
case effProcessEvents:
result = processEvents((VstEvents*)ptr);
break;
case effGetPlugCategory:
result = kPlugCategEffect | kPlugCategAnalysis;
break;
case effGetVendorString:
result = getVendorString(ptr);
break;
case effGetEffectName:
strncpy((char*)ptr, "VST test plugin", kVstMaxEffectNameLen);
break;
case effGetProductString:
strncpy((char*)ptr, "magic plugin", kVstMaxEffectNameLen);
break;
case effGetParamName:
getParameterName(index, (char*)ptr);
break;
case effGetParamDisplay:
getParameterDisplay(index, (char*)ptr);
break;
case effGetParamLabel:
getParameterLabel(index, (char*)ptr);
break;
case effGetParameterProperties:
result = getParameterProperties(index, (VstParameterProperties*)ptr);
break;
case effClose:
free(effect);
free(ptr);
break;
default:
break;
}
return result;
}
void process32(AEffect* effect, float** inputs, float** outputs, VstInt32 sampleframes)
{
float* ileft = inputs[0]; float* iright = inputs[1];
float* oleft = outputs[0]; float* oright = outputs[1];
while (--sampleframes >= 0) {
(*oleft) = sample((*ileft));
(*oright) = sample((*iright));
ileft++; iright++;
oleft++; oright++; } }
void setparam(AEffect* effect, VstInt32 index, float value)
{
switch (index) {
case parameter1:
param_volume = value;
break;
case parameter2:
mode_value = value;
break;
} }
float getparam(AEffect* effect, VstInt32 index)
{
float result = 0;
switch (index) {
case parameter1:
result = param_volume;
break;
case parameter2:
result = mode_value;
break; }
return result;
}
AEffect* VSTPluginMain(audioMasterCallback audioMaster)
{
AEffect* effect = (AEffect*) malloc(sizeof(AEffect));
memset(effect, 0, sizeof(AEffect));
effect->magic = kEffectMagic;
effect->dispatcher = &Dispatcher;
effect->setParameter = &setparam;
effect->getParameter = &getparam;
effect->numParams = NumParams;
effect->numInputs = channels;
effect->numOutputs = channels;
effect->flags = effFlagsCanReplacing;
effect->processReplacing = &process32;
effect->uniqueID = 1987;
effect->version = 1;
effect->object = 0;
return effect;
}