VST Host Help!!

Duarte Vinagre 60 Reputation points
2025-04-29T11:23:42.47+00:00

Hello....well...im not a coder just an enthusiast...but...im trying to make a simple VST host and i have this code but im not able to run it very well...can someone help me fix my code? Thanks!!

#include "aeffect.h"

#include "aeffectx.h"

#include "vstfxstore.h"

#include <stdio.h>

#include <iostream>

// C callbacks

using namespace std;

extern "C" {

// Main host callback

VstIntPtr VSTCALLBACK hostCallback(AEffect* effect, VstInt32 opcode,

	VstInt32 index, VstInt32 value, void* ptr, float opt);

}

extern "C" {

VstIntPtr VSTCALLBACK hostCallback(AEffect* effect, VstInt32 opcode, VstInt32 index,

	VstInt32 value, void* ptr, float opt) {

	switch (opcode) {

	case audioMasterVersion:

		return 2400;

	case audioMasterIdle:

		effect->dispatcher(effect, effEditIdle, 0, 0, 0, 0);

		// Handle other opcodes here... there will be lots of them

	default:

		printf("Plugin requested value of opcode %d\n", opcode);

		break;

	}

}

}

// Plugin's entry point

typedef AEffect* (*vstPluginFuncPtr)(audioMasterCallback host);

// Plugin's dispatcher function

typedef VstIntPtr(dispatcherFuncPtr)(AEffect effect, VstInt32 opCode,

VstInt32 index, VstInt32 value, void* ptr, float opt);

// Plugin's getParameter() method

typedef float (getParameterFuncPtr)(AEffect effect, VstInt32 index);

// Plugin's setParameter() method

typedef void (setParameterFuncPtr)(AEffect effect, VstInt32 index, float value);

// Plugin's processEvents() method

typedef VstInt32(processEventsFuncPtr)(VstEvents events);

// Plugin's process() method

typedef void (processFuncPtr)(AEffect effect, float** inputs,

float** outputs, VstInt32 sampleFrames);

AEffect* loadPlugin() {

AEffect* plugin = NULL;

char* vstPath = "C:\Nasty\;

modulePtr = LoadLibrary(vstPath);

if (modulePtr == NULL) {

	printf("Failed trying to load VST from '%s', error %d\n", vstPath, GetLastError());

	return NULL;

}

vstPluginFuncPtr mainEntryPoint =

	(vstPluginFuncPtr)GetProcAddress(modulePtr, "VSTPluginMain");

// Instantiate the plugin

plugin = mainEntryPoint(hostCallback);

return plugin;

}

int configurePluginCallbacks(AEffect* plugin) {

// Check plugin's magic number

// If incorrect, then the file either was not loaded properly, is not a

// real VST plugin, or is otherwise corrupt.

if (plugin->magic != kEffectMagic) {

	printf("Plugin's magic number is bad\n");

	return -1;

}

// Create dispatcher handle

dispatcherFuncPtr dispatcher = (dispatcherFuncPtr)(plugin->dispatcher);

// Set up plugin callback functions

plugin->getParameter = (getParameterFuncPtr)plugin->getParameter;

plugin->processReplacing = (processFuncPtr)plugin->processReplacing;

plugin->setParameter = (setParameterFuncPtr)plugin->setParameter;

}

void suspendPlugin(AEffect * plugin) {

	dispatcher(plugin, effMainsChanged, 0, 0, NULL, 0.0f);

}

void resumePlugin(AEffect * plugin) {

	dispatcher(plugin, effMainsChanged, 0, 1, NULL, 0.0f);

}



bool canPluginDo(char* canDoString) {

	return (dispatcher(plugin, effCanDo, 0, 0, (void*)canDoString, 0.0f) > 0);

}

void initializeIO() {

	// inputs and outputs are assumed to be float** and are declared elsewhere,

	// most likely the are fields owned by this class. numChannels and blocksize

	// are also fields, both should be size_t (or unsigned int, if you prefer).

	inputs = (float**)malloc(sizeof(float**) * numChannels);

	outputs = (float**)malloc(sizeof(float**) * numChannels);

	for (int channel = 0; channel < numChannels; channel++) {

		inputs[i] = (float*)malloc(sizeof(float*) * blocksize);

		outputs[i] = (float*)malloc(sizeof(float*) * blocksize);

	}

}

void processAudio(AEffect * plugin, float** inputs, float** outputs,

	long numFrames) {

	// Always reset the output array before processing.

	silenceChannel(outputs, numChannels, numFrames);

	// Note: If you are processing an instrument, you should probably zero

	// out the input channels first to avoid any accidental noise. If you

	// are processing an effect, you should probably zero the values in the

	// output channels. See the silenceChannel() function below.

	// However, if you are reading input data from file (or elsewhere), this

	// step is not necessary.

	silenceChannel(inputs, numChannels, numFrames);

	plugin->processReplacing(plugin, inputs, outputs, numFrames);

}

void silenceChannel(float** channelData, int numChannels, long numFrames) {

	for (int channel = 0; channels < numChannels; ++channel) {

		for (long frame = 0; frame < numFrames; ++frame) {

			channelData[channel][frame] = 0.0f;

		}

	}

}

void processMidi(AEffect* plugin, VstEvents* events) {

	dispatcher(plugin, effProcessEvents, 0, 0, events, 0.0f);

}
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,925 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.