completed winvst frontend

This commit is contained in:
itsmattkc
2019-01-09 00:04:20 +11:00
parent b8bc25d408
commit db2815ce09
11 changed files with 228 additions and 60 deletions
+65 -39
View File
@@ -6,6 +6,7 @@
#include <QPushButton>
#include <QDialog>
#include <QMessageBox>
#include "playback/audio.h"
#include "mainwindow.h"
@@ -48,17 +49,22 @@ typedef VstInt32 (*processEventsFuncPtr)(VstEvents *events);
typedef void (*processFuncPtr)(AEffect *effect, float **inputs, float **outputs, VstInt32 sampleFrames);
void VSTHostWin::loadPlugin() {
plugin = NULL;
QString dll_fn = file_field->get_filename(0, true);
LPCWSTR dll_fn_w = reinterpret_cast<const wchar_t*>(dll_fn.utf16());
const char* vst_path = "C:\\Program Files\\VSTPlugins\\ReaPlugs\\reaeq-standalone.dll";
wchar_t win_char[200];
mbstowcs(win_char, vst_path, 200);
HMODULE modulePtr = LoadLibrary(win_char);
modulePtr = LoadLibrary(dll_fn_w);
if(modulePtr == NULL) {
DWORD dll_err = GetLastError();
dout << "[ERROR] Failed to load VST" << vst_path << "-" << dll_err;
if (dll_err == 193) dout << " Mixing 32-bit and 64-bit?";
dout << "[ERROR] Failed to load VST" << dll_fn_w << "-" << dll_err;
QString msg_err = "Failed to load VST plugin \"" + dll_fn + "\": " + QString::number(dll_err);
if (dll_err == 193) {
#ifdef _WIN64
msg_err += "\n\nNOTE: 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\nNOTE: 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
}
QMessageBox::critical(mainWindow, "Error loading VST plugin", msg_err);
return;
}
@@ -68,13 +74,14 @@ void VSTHostWin::loadPlugin() {
plugin = mainEntryPoint(hostCallback);
}
int VSTHostWin::configurePluginCallbacks() {
bool VSTHostWin::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.
if(plugin->magic != kEffectMagic) {
printf("Plugin's magic number is bad\n");
return -1;
dout << "[ERROR] Plugin's magic number is bad";
QMessageBox::critical(mainWindow, "VST Error", "Plugin's magic number is invalid");
return false;
}
// Create dispatcher handle
@@ -85,8 +92,7 @@ int VSTHostWin::configurePluginCallbacks() {
plugin->processReplacing = (processFuncPtr)plugin->processReplacing;
plugin->setParameter = (setParameterFuncPtr)plugin->setParameter;
//return plugin;
return 0;
return true;
}
void VSTHostWin::startPlugin() {
@@ -99,6 +105,12 @@ void VSTHostWin::startPlugin() {
resumePlugin();
}
void VSTHostWin::stopPlugin() {
suspendPlugin();
dispatcher(plugin, effClose, 0, 0, NULL, 0);
}
void VSTHostWin::resumePlugin() {
dispatcher(plugin, effMainsChanged, 0, 1, NULL, 0.0f);
}
@@ -125,42 +137,33 @@ void VSTHostWin::initializeIO() {
void VSTHostWin::processAudio(long numFrames) {
// Always reset the output array before processing.
silenceChannel(outputs, CHANNEL_COUNT, numFrames);
for (int i=0;i<CHANNEL_COUNT;i++) {
memset(outputs[i], 0, BLOCK_SIZE*sizeof(float));
}
plugin->processReplacing(plugin, inputs, outputs, numFrames);
}
void VSTHostWin::silenceChannel(float **channelData, int numChannels, long numFrames) {
for(int channel = 0; channel < numChannels; ++channel) {
for(long frame = 0; frame < numFrames; ++frame) {
channelData[channel][frame] = 0.0f;
}
}
}
VSTHostWin::VSTHostWin(Clip* c, const EffectMeta *em) : Effect(c, em) {
EffectRow* interface_row = add_row("Interface");
plugin = NULL;
initializeIO();
file_field = add_row("Plugin", true, false)->add_field(EFFECT_FIELD_FILE, "filename");
connect(file_field, SIGNAL(changed()), this, SLOT(change_plugin()));
EffectRow* interface_row = add_row("Interface", false, false);
show_interface_btn = new QPushButton("Show");
show_interface_btn->setCheckable(true);
show_interface_btn->setEnabled(false);
connect(show_interface_btn, SIGNAL(toggled(bool)), this, SLOT(show_interface(bool)));
interface_row->add_widget(show_interface_btn);
loadPlugin();
if (plugin != NULL) {
initializeIO();
configurePluginCallbacks();
startPlugin();
dialog = new QDialog(mainWindow);
dialog->setWindowTitle("VST Plugin");
dialog->setAttribute(Qt::WA_NativeWindow, true);
dialog->setWindowFlags(dialog->windowFlags() | Qt::MSWindowsFixedSizeDialogHint);
connect(dialog, SIGNAL(finished(int)), this, SLOT(uncheck_show_button()));
dispatcher(plugin, effEditOpen, 0, 0, reinterpret_cast<HWND>(dialog->winId()), 0);
ERect* eRect = NULL;
plugin->dispatcher(plugin, effEditGetRect, 0, 0, &eRect, 0);
dialog->setFixedWidth(eRect->right);
dialog->setFixedHeight(eRect->bottom);
}
dialog = new QDialog(mainWindow);
dialog->setWindowTitle("VST Plugin");
dialog->setAttribute(Qt::WA_NativeWindow, true);
dialog->setWindowFlags(dialog->windowFlags() | Qt::MSWindowsFixedSizeDialogHint);
connect(dialog, SIGNAL(finished(int)), this, SLOT(uncheck_show_button()));
}
void VSTHostWin::process_audio(double timecode_start, double timecode_end, quint8* samples, int nb_bytes, int) {
@@ -215,3 +218,26 @@ void VSTHostWin::show_interface(bool show) {
void VSTHostWin::uncheck_show_button() {
show_interface_btn->setChecked(false);
}
void VSTHostWin::change_plugin() {
if (plugin != NULL) {
stopPlugin();
FreeLibrary(modulePtr);
plugin = NULL;
}
loadPlugin();
if (plugin != NULL) {
if (configurePluginCallbacks()) {
startPlugin();
dispatcher(plugin, effEditOpen, 0, 0, reinterpret_cast<HWND>(dialog->winId()), 0);
ERect* eRect = NULL;
plugin->dispatcher(plugin, effEditGetRect, 0, 0, &eRect, 0);
dialog->setFixedWidth(eRect->right);
dialog->setFixedHeight(eRect->bottom);
} else {
FreeLibrary(modulePtr);
plugin = NULL;
}
}
show_interface_btn->setEnabled(plugin != NULL);
}