moved vst to cross platform defs (still untested on other platforms
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
#include "vsthostwin.h"
|
||||
#include "vsthost.h"
|
||||
|
||||
// adapted from http://teragonaudio.com/article/How-to-make-your-own-VST-host.html
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QDialog>
|
||||
#include <QMessageBox>
|
||||
@@ -52,20 +50,22 @@ typedef VstInt32 (*processEventsFuncPtr)(VstEvents *events);
|
||||
// Plugin's process() method
|
||||
typedef void (*processFuncPtr)(AEffect *effect, float **inputs, float **outputs, VstInt32 sampleFrames);
|
||||
|
||||
void VSTHostWin::loadPlugin() {
|
||||
void VSTHost::loadPlugin() {
|
||||
QString dll_fn = file_field->get_filename(0, true);
|
||||
LPCWSTR dll_fn_w = reinterpret_cast<const wchar_t*>(dll_fn.utf16());
|
||||
|
||||
modulePtr = LoadLibrary(dll_fn_w);
|
||||
modulePtr = LibLoad(dll_fn);
|
||||
if(modulePtr == nullptr) {
|
||||
DWORD dll_err = GetLastError();
|
||||
qCritical() << "Failed to load VST" << dll_fn_w << "-" << dll_err;
|
||||
qCritical() << "Failed to load VST" << dll_fn << "-" << dll_err;
|
||||
|
||||
#ifdef _WIN32
|
||||
QString msg_err = tr("Failed to load VST plugin \"%1\": %2").arg(dll_fn, QString::number(dll_err));
|
||||
if (dll_err == 193) {
|
||||
#ifdef _WIN64
|
||||
msg_err += "\n\n" + tr("NOTE: You can't load 32-bit VST plugins into a 64-bit build of Olive. Please find a 64-bit version of this plugin or switch to a 32-bit build of Olive.");
|
||||
#elif _WIN32
|
||||
msg_err += "\n\n" + tr("NOTE: You can't load 64-bit VST plugins into a 32-bit build of Olive. Please find a 32-bit version of this plugin or switch to a 64-bit build of Olive.");
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
QMessageBox::critical(mainWindow, tr("Error loading VST plugin"), msg_err);
|
||||
@@ -73,20 +73,20 @@ void VSTHostWin::loadPlugin() {
|
||||
}
|
||||
|
||||
vstPluginFuncPtr mainEntryPoint =
|
||||
reinterpret_cast<vstPluginFuncPtr>(GetProcAddress(modulePtr, "VSTPluginMain"));
|
||||
reinterpret_cast<vstPluginFuncPtr>(LibAddress(modulePtr, "VSTPluginMain"));
|
||||
// Instantiate the plugin
|
||||
plugin = mainEntryPoint(hostCallback);
|
||||
}
|
||||
|
||||
void VSTHostWin::freePlugin() {
|
||||
void VSTHost::freePlugin() {
|
||||
if (plugin != nullptr) {
|
||||
stopPlugin();
|
||||
FreeLibrary(modulePtr);
|
||||
LibClose(modulePtr);
|
||||
plugin = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool VSTHostWin::configurePluginCallbacks() {
|
||||
bool VSTHost::configurePluginCallbacks() {
|
||||
// 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.
|
||||
@@ -107,7 +107,7 @@ bool VSTHostWin::configurePluginCallbacks() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void VSTHostWin::startPlugin() {
|
||||
void VSTHost::startPlugin() {
|
||||
dispatcher(plugin, effOpen, 0, 0, nullptr, 0.0f);
|
||||
|
||||
// Set some default properties
|
||||
@@ -117,25 +117,25 @@ void VSTHostWin::startPlugin() {
|
||||
resumePlugin();
|
||||
}
|
||||
|
||||
void VSTHostWin::stopPlugin() {
|
||||
void VSTHost::stopPlugin() {
|
||||
suspendPlugin();
|
||||
|
||||
dispatcher(plugin, effClose, 0, 0, nullptr, 0);
|
||||
}
|
||||
|
||||
void VSTHostWin::resumePlugin() {
|
||||
void VSTHost::resumePlugin() {
|
||||
dispatcher(plugin, effMainsChanged, 0, 1, nullptr, 0.0f);
|
||||
}
|
||||
|
||||
void VSTHostWin::suspendPlugin() {
|
||||
void VSTHost::suspendPlugin() {
|
||||
dispatcher(plugin, effMainsChanged, 0, 0, nullptr, 0.0f);
|
||||
}
|
||||
|
||||
bool VSTHostWin::canPluginDo(char *canDoString) {
|
||||
bool VSTHost::canPluginDo(char *canDoString) {
|
||||
return (dispatcher(plugin, effCanDo, 0, 0, static_cast<void*>(canDoString), 0.0f) > 0);
|
||||
}
|
||||
|
||||
void VSTHostWin::initializeIO() {
|
||||
void VSTHost::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).
|
||||
@@ -147,7 +147,7 @@ void VSTHostWin::initializeIO() {
|
||||
}
|
||||
}
|
||||
|
||||
void VSTHostWin::processAudio(long numFrames) {
|
||||
void VSTHost::processAudio(long numFrames) {
|
||||
// Always reset the output array before processing.
|
||||
for (int i=0;i<CHANNEL_COUNT;i++) {
|
||||
memset(outputs[i], 0, BLOCK_SIZE*sizeof(float));
|
||||
@@ -156,7 +156,7 @@ void VSTHostWin::processAudio(long numFrames) {
|
||||
plugin->processReplacing(plugin, inputs, outputs, numFrames);
|
||||
}
|
||||
|
||||
VSTHostWin::VSTHostWin(Clip* c, const EffectMeta *em) : Effect(c, em) {
|
||||
VSTHost::VSTHost(Clip* c, const EffectMeta *em) : Effect(c, em) {
|
||||
plugin = nullptr;
|
||||
|
||||
initializeIO();
|
||||
@@ -178,11 +178,11 @@ VSTHostWin::VSTHostWin(Clip* c, const EffectMeta *em) : Effect(c, em) {
|
||||
connect(dialog, SIGNAL(finished(int)), this, SLOT(uncheck_show_button()));
|
||||
}
|
||||
|
||||
VSTHostWin::~VSTHostWin() {
|
||||
VSTHost::~VSTHost() {
|
||||
freePlugin();
|
||||
}
|
||||
|
||||
void VSTHostWin::process_audio(double, double, quint8* samples, int nb_bytes, int) {
|
||||
void VSTHost::process_audio(double, double, quint8* samples, int nb_bytes, int) {
|
||||
if (plugin != nullptr) {
|
||||
int interval = BLOCK_SIZE*4;
|
||||
for (int i=0;i<nb_bytes;i+=interval) {
|
||||
@@ -218,7 +218,7 @@ void VSTHostWin::process_audio(double, double, quint8* samples, int nb_bytes, in
|
||||
}
|
||||
}
|
||||
|
||||
void VSTHostWin::custom_load(QXmlStreamReader &stream) {
|
||||
void VSTHost::custom_load(QXmlStreamReader &stream) {
|
||||
if (stream.name() == "plugindata") {
|
||||
stream.readNext();
|
||||
QByteArray b = QByteArray::fromBase64(stream.text().toUtf8());
|
||||
@@ -228,7 +228,7 @@ void VSTHostWin::custom_load(QXmlStreamReader &stream) {
|
||||
}
|
||||
}
|
||||
|
||||
void VSTHostWin::save(QXmlStreamWriter &stream) {
|
||||
void VSTHost::save(QXmlStreamWriter &stream) {
|
||||
Effect::save(stream);
|
||||
if (plugin != nullptr) {
|
||||
char* p = nullptr;
|
||||
@@ -238,15 +238,15 @@ void VSTHostWin::save(QXmlStreamWriter &stream) {
|
||||
}
|
||||
}
|
||||
|
||||
void VSTHostWin::show_interface(bool show) {
|
||||
void VSTHost::show_interface(bool show) {
|
||||
dialog->setVisible(show);
|
||||
}
|
||||
|
||||
void VSTHostWin::uncheck_show_button() {
|
||||
void VSTHost::uncheck_show_button() {
|
||||
show_interface_btn->setChecked(false);
|
||||
}
|
||||
|
||||
void VSTHostWin::change_plugin() {
|
||||
void VSTHost::change_plugin() {
|
||||
freePlugin();
|
||||
loadPlugin();
|
||||
if (plugin != nullptr) {
|
||||
@@ -258,7 +258,7 @@ void VSTHostWin::change_plugin() {
|
||||
dialog->setFixedWidth(eRect->right);
|
||||
dialog->setFixedHeight(eRect->bottom);
|
||||
} else {
|
||||
FreeLibrary(modulePtr);
|
||||
LibClose(modulePtr);
|
||||
plugin = nullptr;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#include "project/effect.h"
|
||||
|
||||
#include "io/crossplatformlib.h"
|
||||
|
||||
#include <vst/aeffectx.h>
|
||||
|
||||
// Plugin's dispatcher function
|
||||
@@ -11,11 +13,11 @@ typedef VstIntPtr (*dispatcherFuncPtr)(AEffect *effect, VstInt32 opCode, VstInt3
|
||||
struct AEffect;
|
||||
class QDialog;
|
||||
|
||||
class VSTHostWin : public Effect {
|
||||
class VSTHost : public Effect {
|
||||
Q_OBJECT
|
||||
public:
|
||||
VSTHostWin(Clip* c, const EffectMeta* em);
|
||||
~VSTHostWin();
|
||||
VSTHost(Clip* c, const EffectMeta* em);
|
||||
~VSTHost();
|
||||
void process_audio(double timecode_start, double timecode_end, quint8* samples, int nb_bytes, int channel_count);
|
||||
|
||||
void custom_load(QXmlStreamReader& stream);
|
||||
@@ -43,7 +45,7 @@ private:
|
||||
float** outputs;
|
||||
QDialog* dialog;
|
||||
QPushButton* show_interface_btn;
|
||||
HMODULE modulePtr;
|
||||
ModulePtr modulePtr;
|
||||
};
|
||||
|
||||
#endif // VSTHOSTWIN_H
|
||||
Reference in New Issue
Block a user