Browse Source

Implement loading of MacOS VST2 bundles

tags/1.9.8
falkTX 8 years ago
parent
commit
f88c0d5ab0
3 changed files with 95 additions and 12 deletions
  1. +81
    -12
      source/backend/plugin/CarlaPluginVST2.cpp
  2. +7
    -0
      source/backend/plugin/Makefile
  3. +7
    -0
      source/bridges-plugin/Makefile

+ 81
- 12
source/backend/plugin/CarlaPluginVST2.cpp View File

@@ -25,6 +25,10 @@

#include <pthread.h>

#ifdef CARLA_OS_MAC
# import <Foundation/Foundation.h>
#endif

#undef VST_FORCE_DEPRECATED
#define VST_FORCE_DEPRECATED 0

@@ -62,6 +66,10 @@ public:
fProcThread({nullptr, 0}),
#else
fProcThread(0),
#endif
#ifdef CARLA_OS_MAC
fMacBundleRef(nullptr),
fMacBundleRefNum(0),
#endif
fEvents(),
fUI(),
@@ -120,6 +128,21 @@ public:
}

clearBuffers();

#ifdef CARLA_OS_MAC
if (fMacBundleRef != nullptr)
{
CFBundleCloseBundleResourceMap(fMacBundleRef, fMacBundleRefNum);

if (CFGetRetainCount(fMacBundleRef) == 1)
CFBundleUnloadExecutable(fMacBundleRef);

if (CFGetRetainCount(fMacBundleRef) > 0)
CFRelease(fMacBundleRef);

fMacBundleRef = nullptr;
}
#endif
}

// -------------------------------------------------------------------
@@ -2072,28 +2095,69 @@ public:
}

// ---------------------------------------------------------------
// open DLL

if (! pData->libOpen(filename))
VST_Function vstFn;

#ifdef CARLA_OS_MAC
if (CarlaString(filename).toLower().endsWith(".vst"))
{
pData->engine->setLastError(pData->libError(filename));
return false;
}
// FIXME assert returns, set engine error
const CFURLRef urlRef = CFURLCreateFromFileSystemRepresentation(0, (const UInt8*)filename, (CFIndex)strlen(filename), true);
CARLA_SAFE_ASSERT_RETURN(urlRef != nullptr, false);

// ---------------------------------------------------------------
// get DLL main entry
fMacBundleRef = CFBundleCreate(kCFAllocatorDefault, urlRef);
CFRelease(urlRef);
CARLA_SAFE_ASSERT_RETURN(fMacBundleRef != nullptr, false);

if (! CFBundleLoadExecutable(fMacBundleRef))
{
CFRelease(fMacBundleRef);
pData->engine->setLastError("Failed to load VST bundle executable");
return false;
}

VST_Function vstFn = pData->libSymbol<VST_Function>("VSTPluginMain");
vstFn = (VST_Function)CFBundleGetFunctionPointerForName(fMacBundleRef, CFSTR("main_macho"));

if (vstFn == nullptr)
{
vstFn = pData->libSymbol<VST_Function>("main");
if (vstFn == nullptr)
vstFn = (VST_Function)CFBundleGetFunctionPointerForName(fMacBundleRef, CFSTR("VSTPluginMain"));

if (vstFn == nullptr)
{
pData->engine->setLastError("Could not find the VST main entry in the plugin library");
CFBundleUnloadExecutable(fMacBundleRef);
CFRelease(fMacBundleRef);
pData->engine->setLastError("Not a VST plugin");
return false;
}

fMacBundleRefNum = CFBundleOpenBundleResourceMap(fMacBundleRef);
}
else
#endif
{
// -----------------------------------------------------------
// open DLL

if (! pData->libOpen(filename))
{
pData->engine->setLastError(pData->libError(filename));
return false;
}

// -----------------------------------------------------------
// get DLL main entry

vstFn = pData->libSymbol<VST_Function>("VSTPluginMain");

if (vstFn == nullptr)
{
vstFn = pData->libSymbol<VST_Function>("main");

if (vstFn == nullptr)
{
pData->engine->setLastError("Could not find the VST main entry in the plugin library");
return false;
}
}
}

// ---------------------------------------------------------------
@@ -2233,6 +2297,11 @@ private:
pthread_t fMainThread;
pthread_t fProcThread;

#ifdef CARLA_OS_MAC
CFBundleRef fMacBundleRef;
CFBundleRefNum fMacBundleRefNum;
#endif

struct FixedVstEvents {
int32_t numEvents;
intptr_t reserved;


+ 7
- 0
source/backend/plugin/Makefile View File

@@ -57,6 +57,13 @@ $(OBJDIR)/CarlaPluginLinuxSampler.cpp.o: CarlaPluginLinuxSampler.cpp
@echo "Compiling $<"
@$(CXX) $< $(BUILD_CXX_FLAGS) $(LINUXSAMPLER_FLAGS) -c -o $@

ifeq ($(MACOS),true)
$(OBJDIR)/CarlaPluginVST2.cpp.o: CarlaPluginVST2.cpp
-@mkdir -p $(OBJDIR)
@echo "Compiling $<"
@$(CXX) $< $(BUILD_CXX_FLAGS) -ObjC++ -c -o $@
endif

$(OBJDIR)/%.cpp.o: %.cpp
-@mkdir -p $(OBJDIR)
@echo "Compiling $<"


+ 7
- 0
source/bridges-plugin/Makefile View File

@@ -221,6 +221,13 @@ $(OBJDIR)/CarlaEng%.cpp.o: $(CWD)/backend/engine/CarlaEng%.cpp
@echo "Compiling CarlaEng$*.cpp (bridge)"
@$(CXX) $< $(BUILD_CXX_FLAGS) $(NATIVE_BUILD_FLAGS) -c -o $@

ifeq ($(MACOS),true)
$(OBJDIR)/CarlaPluginVST2.cpp.o: $(CWD)/backend/plugin/CarlaPluginVST2.cpp
-@mkdir -p $(OBJDIR)
@echo "Compiling CarlaPluginVST2.cpp (bridge)"
@$(CXX) $< $(BUILD_CXX_FLAGS) $(NATIVE_BUILD_FLAGS) -ObjC++ -c -o $@
endif

$(OBJDIR)/CarlaPlug%.cpp.o: $(CWD)/backend/plugin/CarlaPlug%.cpp
-@mkdir -p $(OBJDIR)
@echo "Compiling CarlaPlug$*.cpp (bridge)"


Loading…
Cancel
Save