This repository has been archived by the owner on Jul 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from c3r1c3/master
Fixes, clean up, and an attempt at Linux support.
- Loading branch information
Showing
9 changed files
with
186 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/***************************************************************************** | ||
Copyright (C) 2016-2017 by Colin Edwards. | ||
Additional Code Copyright (C) 2016-2017 by c3r1c3 <[email protected]> | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
|
@@ -75,6 +76,7 @@ void silenceChannel(float **channelData, int numChannels, long numFrames) { | |
} | ||
|
||
obs_audio_data *VSTPlugin::process(struct obs_audio_data *audio) { | ||
|
||
if (effect && effectReady) { | ||
silenceChannel(outputs, VST_MAX_CHANNELS, audio->frames); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
OpenPluginInterface="Open Plug-in Interface" | ||
ClosePluginInterface="Close Plug-in Interface" | ||
VstPlugin="VST Plug-in" | ||
VstPlugin="VST 2.x Plug-in" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/***************************************************************************** | ||
Copyright (C) 2016-2017 by Colin Edwards. | ||
Additional Code Copyright (C) 2016-2017 by c3r1c3 <[email protected]> | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
/***************************************************************************** | ||
Copyright (C) 2016-2017 by Colin Edwards. | ||
Additional Code Copyright (C) 2016-2017 by c3r1c3 <[email protected]> | ||
Special thanks to Nik Reiman for sharing his awesome code with the world. | ||
Some of the original code can be found here: | ||
https://github.com/teragonaudio/MrsWatson/blob/master/source/plugin/PluginVst2xLinux.cpp | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
|
@@ -17,12 +22,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |
|
||
#include "../headers/EditorWidget.h" | ||
|
||
#include <QWindow> | ||
#include <X11/Xlib.h> | ||
#include <QWindow> | ||
|
||
|
||
void EditorWidget::buildEffectContainer(AEffect *effect) { | ||
WNDCLASSEX wcex{ sizeof(wcex) }; | ||
wcex.lpfnWndProc = DefWindowProc; | ||
//WNDCLASSEX wcex{sizeof(wcex)}; | ||
/*wcex.lpfnWndProc = DefWindowProc; | ||
wcex.hInstance = GetModuleHandle(0); | ||
wcex.lpszClassName = L"Minimal VST host - Guest VST Window Frame"; | ||
RegisterClassEx(&wcex); | ||
|
@@ -31,23 +37,82 @@ void EditorWidget::buildEffectContainer(AEffect *effect) { | |
HWND hwnd = CreateWindow( | ||
wcex.lpszClassName, TEXT(""), style | ||
, 0, 0, 0, 0, 0, 0, 0, 0 | ||
); | ||
);*/ | ||
|
||
|
||
Display *display; | ||
Window window; | ||
XEvent event; | ||
int screenNumber; | ||
printf("Opening X display"); | ||
display = XOpenDisplay(NULL); | ||
if (display == NULL) { | ||
printf("Can't open default display"); | ||
return; | ||
} | ||
|
||
printf("Acquiring default screen for X display"); | ||
screenNumber = DefaultScreen(display); | ||
Screen *screen = DefaultScreenOfDisplay(display); | ||
int screenWidth = WidthOfScreen(screen); | ||
int screenHeight = HeightOfScreen(screen); | ||
printf("Screen dimensions: %dx%d", screenWidth, screenHeight); | ||
|
||
// Default size is 300x300 pixels | ||
int windowX = (screenWidth - 300) / 2; | ||
int windowY = (screenHeight - 300) / 2; | ||
|
||
printf("Creating window at %dx%d", windowX, windowY); | ||
window = XCreateSimpleWindow(display, RootWindow(display, screenNumber), 0, 0, | ||
300, 300, 1, | ||
BlackPixel(display, screenNumber), | ||
BlackPixel(display, screenNumber)); | ||
|
||
//XStoreName(display, window, pluginName->data); | ||
/* | ||
XSelectInput(display, window, ExposureMask | KeyPressMask); | ||
XMapWindow(display, window); | ||
XMoveWindow(display, window, windowX, windowY); | ||
printf("Opening plugin editor window"); | ||
effect->dispatcher(effect, effEditOpen, 0, 0, (void *) window, 0); | ||
while (true) { | ||
XNextEvent(display, &event); | ||
if (event.type == Expose) { | ||
} | ||
if (event.type == KeyPress) { | ||
break; | ||
} | ||
} | ||
QWidget *widget = QWidget::createWindowContainer(QWindow::fromWinId((WId)hwnd), this); | ||
printf("Closing plugin editor window"); | ||
effect->dispatcher(effect, effEditClose, 0, 0, 0, 0); | ||
XDestroyWindow(display, window); | ||
XCloseDisplay(display); | ||
*/ | ||
/* | ||
QWidget *widget = QWidget::createWindowContainer(QWindow::window); | ||
widget->move(0, 0); | ||
widget->resize(300, 300); | ||
effect->dispatcher(effect, effEditOpen, 0, 0, hwnd, 0); | ||
effect->dispatcher(effect, effEditOpen, 0, 0, window, 0); | ||
VstRect* vstRect = nullptr; | ||
effect->dispatcher(effect, effEditGetRect, 0, 0, &vstRect, 0); | ||
if (vstRect) | ||
{ | ||
widget->resize(vstRect->right - vstRect->left, vstRect->bottom - vstRect->top); | ||
widget->resize(vstRect->right - vstRect->left, | ||
vstRect->bottom - vstRect->top); | ||
} | ||
*/ | ||
} | ||
|
||
void EditorWidget::handleResizeRequest(int width, int height) { | ||
// We don't have to do anything here as far as I can tell. The widget will resize the HWIND itself and then | ||
// We don't have to do anything here as far as I can tell. | ||
// The widget will resize the HWIND itself and then | ||
// this widget will automatically size depending on that. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/***************************************************************************** | ||
Copyright (C) 2016-2017 by Colin Edwards. | ||
Additional Code Copyright (C) 2016-2017 by c3r1c3 <[email protected]> | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
|
@@ -15,28 +16,56 @@ You should have received a copy of the GNU General Public License | |
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*****************************************************************************/ | ||
#include "../headers/VSTPlugin.h" | ||
#include "../headers/vst-plugin-callbacks.hpp" | ||
|
||
#include <util/platform.h> | ||
#include <X11/Xlib.h> | ||
|
||
AEffect* VSTPlugin::loadEffect() { | ||
AEffect *plugin = nullptr; | ||
|
||
wchar_t *wpath; | ||
os_utf8_to_wcs_ptr(pluginPath.c_str(), 0, &wpath); | ||
soHandle = LoadLibraryW(wpath); | ||
// Why is this a (non-portable) wide char? | ||
wchar_t *wpath = NULL; | ||
|
||
// We need to convert the above wide char to a 'normal' char | ||
// 4096 elements should be enough to contain it... I hope. | ||
// We also initialize the array with NULLs to prevent issues | ||
// down the road. | ||
char charPath[4096] = {NULL}; | ||
uint32_t wcs_returnValue; | ||
//os_utf8_to_wcs_ptr(pluginPath.c_str(), 0, &wpath); | ||
wcs_returnValue = wcstombs(charPath, wpath, sizeof(charPath)); | ||
|
||
// Now check for errors in the conversion before trying to open | ||
// the file/path. | ||
if (wcs_returnValue < 4) { | ||
wprintf(L"Path conversion error from '%s'", wpath); | ||
printf(", to '%s'\n", charPath); | ||
return nullptr; | ||
} | ||
|
||
soHandle = os_dlopen(charPath); | ||
bfree(wpath); | ||
bfree(charPath); | ||
if(soHandle == nullptr) { | ||
printf("Failed trying to load VST from '%s', error %d\n", | ||
pluginPath, GetLastError()); | ||
pluginPath.c_str(), errno); | ||
return nullptr; | ||
} | ||
|
||
vstPluginMain mainEntryPoint = | ||
(vstPluginMain)GetProcAddress(soHandle, "VSTPluginMain"); | ||
(vstPluginMain)(soHandle, "VSTPluginMain"); | ||
|
||
if (mainEntryPoint == nullptr) { | ||
mainEntryPoint = | ||
(vstPluginMain)os_dlsym(soHandle, "VstPluginMain()"); | ||
} | ||
|
||
if (mainEntryPoint == nullptr) { | ||
mainEntryPoint = (vstPluginMain)os_dlsym(soHandle, "main"); | ||
} | ||
|
||
if (!mainEntryPoint) { | ||
if (mainEntryPoint == nullptr) { | ||
printf("Couldn't get a pointer to plugin's main()"); | ||
return nullptr; | ||
} | ||
|
||
|
@@ -48,7 +77,7 @@ AEffect* VSTPlugin::loadEffect() { | |
|
||
void VSTPlugin::unloadLibrary() { | ||
if (soHandle) { | ||
FreeLibrary(soHandle); | ||
os_dlclose(soHandle); | ||
soHandle = nullptr; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/***************************************************************************** | ||
Copyright (C) 2016-2017 by Colin Edwards. | ||
Additional Code Copyright (C) 2016-2017 by c3r1c3 <[email protected]> | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
|
@@ -28,15 +29,33 @@ AEffect* VSTPlugin::loadEffect() { | |
dllHandle = LoadLibraryW(wpath); | ||
bfree(wpath); | ||
if(dllHandle == nullptr) { | ||
printf("Failed trying to load VST from '%s', error %d\n", | ||
pluginPath, GetLastError()); | ||
|
||
DWORD errorCode = GetLastError(); | ||
|
||
// Display the error message and exit the process | ||
if (errorCode == ERROR_BAD_EXE_FORMAT) { | ||
printf("Could not open library, wrong architecture."); | ||
} else { | ||
printf("Failed trying to load VST from '%s', error %d\n", | ||
pluginPath, GetLastError()); | ||
} | ||
return nullptr; | ||
} | ||
|
||
vstPluginMain mainEntryPoint = | ||
(vstPluginMain)GetProcAddress(dllHandle, "VSTPluginMain"); | ||
|
||
if (!mainEntryPoint) { | ||
if (mainEntryPoint == nullptr) { | ||
mainEntryPoint = | ||
(vstPluginMain)GetProcAddress(dllHandle, "VstPluginMain()"); | ||
} | ||
|
||
if (mainEntryPoint == nullptr) { | ||
mainEntryPoint = (vstPluginMain)GetProcAddress(dllHandle, "main"); | ||
} | ||
|
||
if (mainEntryPoint == nullptr) { | ||
printf("Couldn't get a pointer to plug-in's main()"); | ||
return nullptr; | ||
} | ||
|
||
|