Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #17 from c3r1c3/master
Browse files Browse the repository at this point in the history
It's all in the code.
  • Loading branch information
DDRBoxman authored Jan 19, 2017
2 parents de30931 + c9c9b07 commit b87b55c
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 33 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ find_package(Qt5Widgets REQUIRED)
option(VST_USE_BUNDLED_HEADERS "Build with Bundled Headers" ON)

if(VST_USE_BUNDLED_HEADERS)
message(STATUS "Using the built-in VST header.")
message(STATUS "Using the bundled VST header.")
include_directories(vst_header)
set(vst_HEADER
vst_header/aeffectx.h)
else()
set(VST_INCLUDE_DIR "" CACHE PATH "Path to Steinburg headers (e.g. C:/VST3 SDK/pluginterfaces/vst2.x)")
message(WARNING "You should only use the steinburg headers for debugging or local builds. It is illegal to distribute the steinburg headers with anything, and possibly against the GPL to distribute the binaries from the resultant compile.")
message(WARNING "You should only use the Steinburg headers for debugging or local builds. It is illegal to distribute the Steinburg headers with anything, and possibly against the GPL to distribute the binaries from the resultant compile.")
include_directories(${VST_INCLUDE_DIR})
set(vst_HEADER
${VST_INCLUDE_DIR}/aeffectx.h)
Expand Down
40 changes: 20 additions & 20 deletions VSTPlugin.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "headers/VSTPlugin.h"

VSTPlugin::VSTPlugin(obs_source_t *sourceContext) : sourceContext{sourceContext} {
int numChannels = 8;
int numChannels = VST_MAX_CHANNELS;
int blocksize = 512;

inputs = (float **) malloc(sizeof(float **) * numChannels);
Expand All @@ -27,21 +27,21 @@ void VSTPlugin::loadEffectFromPath(std::string path) {
return;
}

// Check plugin's magic number
// Check plug-in's magic number
// If incorrect, then the file either was not loaded properly, is not a
// real VST plugin, or is otherwise corrupt.
// real VST plug-in, or is otherwise corrupt.
if (effect->magic != kEffectMagic) {
blog(LOG_WARNING, "VST Plugin's magic number is bad");
blog(LOG_WARNING, "VST Plug-in's magic number is bad");
return;
}

effect->dispatcher(effect, effOpen, 0, 0, NULL, 0.0f);
effect->dispatcher(effect, effOpen, 0, 0, nullptr, 0.0f);

// Set some default properties
size_t sampleRate = audio_output_get_sample_rate(obs_get_audio());
effect->dispatcher(effect, effSetSampleRate, 0, 0, NULL, sampleRate);
effect->dispatcher(effect, effSetSampleRate, 0, 0, nullptr, sampleRate);
int blocksize = 512;
effect->dispatcher(effect, effSetBlockSize, 0, blocksize, NULL, 0.0f);
effect->dispatcher(effect, effSetBlockSize, 0, blocksize, nullptr, 0.0f);

effect->dispatcher(effect, effMainsChanged, 0, 1, 0, 0);

Expand All @@ -59,16 +59,16 @@ void silenceChannel(float **channelData, int numChannels, long numFrames) {

obs_audio_data *VSTPlugin::process(struct obs_audio_data *audio) {
if (effect && effectReady) {
silenceChannel(outputs, 8, audio->frames);
silenceChannel(outputs, VST_MAX_CHANNELS, audio->frames);

float *adata[8] = {(float *) audio->data[0], (float *) audio->data[1],
(float *) audio->data[2], (float *) audio->data[3],
(float *) audio->data[4], (float *) audio->data[5],
(float *) audio->data[6], (float *) audio->data[7]};
float *adata[VST_MAX_CHANNELS];
for (size_t d = 0; d < VST_MAX_CHANNELS; d++) {
adata[d] = (float *) audio->data[d];
};

effect->processReplacing(effect, adata, outputs, audio->frames);

for (size_t c = 0; c < 8; c++) {
for (size_t c = 0; c < VST_MAX_CHANNELS; c++) {
if (audio->data[c]) {
for (size_t i = 0; i < audio->frames; i++) {
adata[c][i] = outputs[c][i];
Expand All @@ -84,18 +84,18 @@ void VSTPlugin::unloadEffect() {
effectReady = false;

if (effect) {
effect->dispatcher(effect, effMainsChanged, 0, 0, 0, 0);
effect->dispatcher(effect, effClose, 0, 0, NULL, 0.0f);
effect->dispatcher(effect, effMainsChanged, 0, 0, nullptr, 0);
effect->dispatcher(effect, effClose, 0, 0, nullptr, 0.0f);
}

effect = NULL;
effect = nullptr;

unloadLibrary();
}

void VSTPlugin::openEditor() {
if (effect && !editorWidget) {
editorWidget = new EditorWidget(0, this);
editorWidget = new EditorWidget(nullptr, this);

editorWidget->buildEffectContainer(effect);

Expand All @@ -105,7 +105,7 @@ void VSTPlugin::openEditor() {

void VSTPlugin::closeEditor() {
if (effect) {
effect->dispatcher(effect, effEditClose, 0, 0, 0, 0);
effect->dispatcher(effect, effEditClose, 0, 0, nullptr, 0);
}
if (editorWidget) {
editorWidget->close();
Expand Down Expand Up @@ -151,7 +151,7 @@ std::string VSTPlugin::getChunk() {
return "";
}
if (effect->flags & effFlagsProgramChunks) {
void *buf = NULL;
void *buf = nullptr;

intptr_t chunkSize = effect->dispatcher(effect, effGetChunk, 1, 0, &buf, 0.0);

Expand Down Expand Up @@ -179,7 +179,7 @@ void VSTPlugin::setChunk(std::string data) {
QByteArray base64Data = QByteArray(data.c_str(), data.length());
QByteArray chunkData = QByteArray::fromBase64(base64Data);

void *buf = NULL;
void *buf = nullptr;

buf = chunkData.data();
effect->dispatcher(effect, effSetChunk, 0, chunkData.length(), buf, 0);
Expand Down
8 changes: 5 additions & 3 deletions headers/VSTPlugin.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef OBS_STUDIO_VSTPLUGIN_H
#define OBS_STUDIO_VSTPLUGIN_H

#define VST_MAX_CHANNELS 8

#include <string>
#include "aeffectx.h"
#include <obs-module.h>
Expand All @@ -14,14 +16,14 @@
class EditorWidget;

class VSTPlugin {
AEffect *effect = NULL;
AEffect *effect = nullptr;
obs_source_t *sourceContext;
std::string pluginPath;

float **inputs;
float **outputs;

EditorWidget *editorWidget = NULL;
EditorWidget *editorWidget = nullptr;

AEffect* loadEffect();

Expand All @@ -30,7 +32,7 @@ class VSTPlugin {
#ifdef __APPLE__
CFBundleRef bundle = NULL;
#elif WIN32
HINSTANCE dllHandle = NULL;
HINSTANCE dllHandle = nullptr;
#endif

void unloadLibrary();
Expand Down
12 changes: 11 additions & 1 deletion obs-vst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ static struct obs_audio_data *vst_filter_audio(void *data,
static void fill_out_plugins(obs_property_t *list)
{
QStringList dir_list;

#ifdef __APPLE__
dir_list << "/Library/Audio/Plug-Ins/VST/";
dir_list << "~/Library/Audio/Plug-ins/VST/";
#elif WIN32
dir_list << "C:/Program Files/Steinberg/VstPlugins/"
<< "C:/Program Files/Common Files/Steinberg/Shared Components/"
Expand All @@ -91,10 +93,18 @@ static void fill_out_plugins(obs_property_t *list)
<< "C:/Program Files/VSTPlugins/";
// If VST3 support is added....
// << "C:/Program Files/Common Files/VST3";
#elif LINUX
dir_list << "/usr/lib/vst"
dir_list << "/usr/lib/lxvst"
dir_list << "/usr/local/lib/vst"
dir_list << "/usr/local/lib/lxvst"
dir_list << "~/.vst"
dir_list << "~/.lxvst";
#endif

QStringList filters;
filters << "*.vst" << "*.dll";
obs_property_list_add_string(list, "{Please select a plugin}", nullptr);
filters << "*.vst" << "*.dll" << "*.so";
for (int a = 0; a < dir_list.size(); ++a)
{
QDir search_dir(dir_list[a]);
Expand Down
2 changes: 1 addition & 1 deletion win/EditorWidget-win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void EditorWidget::buildEffectContainer(AEffect *effect) {

effect->dispatcher(effect, effEditOpen, 0, 0, hwnd, 0);

VstRect* vstRect = 0;
VstRect* vstRect = nullptr;
effect->dispatcher(effect, effEditGetRect, 0, 0, &vstRect, 0);
if (vstRect)
{
Expand Down
12 changes: 6 additions & 6 deletions win/VSTPlugin-win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
#include <windows.h>

AEffect* VSTPlugin::loadEffect() {
AEffect *plugin = NULL;
AEffect *plugin = nullptr;

wchar_t *wpath;
os_utf8_to_wcs_ptr(pluginPath.c_str(), 0, &wpath);
dllHandle = LoadLibraryW(wpath);
bfree(wpath);
if(dllHandle == NULL) {
if(dllHandle == nullptr) {
printf("Failed trying to load VST from '%s', error %d\n",
pluginPath, GetLastError());
return NULL;
return nullptr;
}

vstPluginMain mainEntryPoint =
(vstPluginMain)GetProcAddress(dllHandle, "VSTPluginMain");

if (!mainEntryPoint) {
return NULL;
return nullptr;
}

// Instantiate the plugin
// Instantiate the plug-in
plugin = mainEntryPoint(hostCallback_static);
plugin->user = this;
return plugin;
Expand All @@ -33,6 +33,6 @@ AEffect* VSTPlugin::loadEffect() {
void VSTPlugin::unloadLibrary() {
if (dllHandle) {
FreeLibrary(dllHandle);
dllHandle = NULL;
dllHandle = nullptr;
}
}

0 comments on commit b87b55c

Please sign in to comment.