jBridge (x64 bridge for x86 VST) support in Juce VST host (windows)

Hi

I had to evaluate the opportunities of handling 32 bits VST plug-ins in the x64 version of my DAW, and ended up using jBridge for this purpose.

So for whoever is interested about that, it's very simple to have jBridge's proxy working with the Juce plugin host without modifying the Juce code:

 - Download and install jBridge (demo version available)

 - in appconfig.h add the following:


#ifdef _M_AMD64
#ifndef JUCE_VST_WRAPPER_LOAD_CUSTOM_MAIN
// JBridge 
#define JUCE_VST_WRAPPER_LOAD_CUSTOM_MAIN    if(moduleMain == nullptr)\
                                            { \
                                                if(module.getNativeHandle() == nullptr && file.existsAsFile()) \
                                                { \
                                                    DynamicLibrary proxyModule(WindowsRegistry::getValue ("HKEY_LOCAL_MACHINE\\Software\\JBridge\\Proxy64", "")); \
                                                    if(proxyModule.getNativeHandle() != nullptr) \
                                                        *((unsigned __int64*)&customMain) = 0xfffffffffffffffe;\
                                                } \
                                                return customMain != nullptr;\
                                            }
                                            
#endif // JUCE_VST_WRAPPER_LOAD_CUSTOM_MAIN
#ifndef JUCE_VST_WRAPPER_INVOKE_MAIN
#define JUCE_VST_WRAPPER_INVOKE_MAIN    typedef AEffect * (VSTCALLBACK *PFNBRIDGEMAIN)( audioMasterCallback audiomaster_, char * pszPluginPath );\
                                        if(module->moduleMain)\
                                        {\
                                            effect = module->moduleMain (&audioMaster);\
                                        }\
                                        else if((unsigned __int64)(module->customMain) == 0xfffffffffffffffe)\
                                        {\
                                            PFNBRIDGEMAIN jBridgeMain = 0;\
                                            module->module.open(WindowsRegistry::getValue ("HKEY_LOCAL_MACHINE\\Software\\JBridge\\Proxy64", ""));\
                                            if(module->module.getNativeHandle() != nullptr)\
                                                jBridgeMain = (PFNBRIDGEMAIN) (module->module.getFunction("BridgeMain"));\
                                            char plug32bitPath[_MAX_PATH];\
                                            plug32bitPath[0] = 0;\
                                            strcpy(plug32bitPath, module->file.getFullPathName().toRawUTF8());\
                                            if(jBridgeMain)\
                                                effect = (AEffect*)(jBridgeMain(&audioMaster, plug32bitPath));\
                                        }
#endif // JUCE_VST_WRAPPER_INVOKE_MAIN
#endif // _AMD64_


That's it. Then you can select 32 bit VST folders and 64 bit VST folders and successfully scan and use them.

Cheers

Fred

 

1 Like

Neat trick!

Well the code above causes crash when add a second instance of a same 32 bit plug-in, hence here's the code addressing this issue:


#ifdef _M_AMD64
#ifndef JUCE_VST_WRAPPER_LOAD_CUSTOM_MAIN
// JBridge 
#define JUCE_VST_WRAPPER_LOAD_CUSTOM_MAIN    if(moduleMain == nullptr)\
                                            { \
                                                if(module.getNativeHandle() == nullptr && file.existsAsFile()) \
                                                { \
                                                    DynamicLibrary proxyModule(WindowsRegistry::getValue ("HKEY_LOCAL_MACHINE\\Software\\JBridge\\Proxy64", "")); \
                                                    if(proxyModule.getNativeHandle() != nullptr) \
                                                        *((unsigned __int64*)&customMain) = 0xfffffffffffffffe;\
                                                } \
                                                return customMain != nullptr;\
                                            }
                                            
#endif // JUCE_VST_WRAPPER_LOAD_CUSTOM_MAIN
#ifndef JUCE_VST_WRAPPER_INVOKE_MAIN
#define JUCE_VST_WRAPPER_INVOKE_MAIN    typedef AEffect * (VSTCALLBACK *PFNBRIDGEMAIN)( audioMasterCallback audiomaster_, char * pszPluginPath );\
                                        if(module->moduleMain)\
                                        {\
                                            effect = module->moduleMain (&audioMaster);\
                                        }\
                                        else if((unsigned __int64)(module->customMain) == 0xfffffffffffffffe)\
                                        {\
                                            PFNBRIDGEMAIN jBridgeMain = 0;\
                                            if(module->module.getNativeHandle() == nullptr)\
                                                module->module.open(WindowsRegistry::getValue ("HKEY_LOCAL_MACHINE\\Software\\JBridge\\Proxy64", ""));\
                                            if(module->module.getNativeHandle() != nullptr)\
                                                jBridgeMain = (PFNBRIDGEMAIN) (module->module.getFunction("BridgeMain"));\
                                            char plug32bitPath[_MAX_PATH];\
                                            plug32bitPath[0] = 0;\
                                            strcpy(plug32bitPath, module->file.getFullPathName().toRawUTF8());\
                                            if(jBridgeMain)\
                                                effect = (AEffect*)(jBridgeMain(&audioMaster, plug32bitPath));\
                                        }
#endif // JUCE_VST_WRAPPER_INVOKE_MAIN
#endif // _AMD64_

 

Huge thanks to @fbeguec for this. For anyone trying to use this in JUCE 5, note the prefix Vst2:: must be added to AEffect and audioMasterCallback. The revised code is as follows:

#ifdef _M_AMD64
#ifndef JUCE_VST_WRAPPER_LOAD_CUSTOM_MAIN
// JBridge 
#define JUCE_VST_WRAPPER_LOAD_CUSTOM_MAIN    if(moduleMain == nullptr)\
                                            { \
                                                if(module.getNativeHandle() == nullptr && file.existsAsFile()) \
                                                { \
                                                    DynamicLibrary proxyModule(WindowsRegistry::getValue ("HKEY_LOCAL_MACHINE\\Software\\JBridge\\Proxy64", "")); \
                                                    if(proxyModule.getNativeHandle() != nullptr) \
                                                        *((unsigned __int64*)&customMain) = 0xfffffffffffffffe;\
                                                } \
                                                return customMain != nullptr;\
                                            }

#endif // JUCE_VST_WRAPPER_LOAD_CUSTOM_MAIN
#ifndef JUCE_VST_WRAPPER_INVOKE_MAIN
#define JUCE_VST_WRAPPER_INVOKE_MAIN    typedef Vst2::AEffect * (VSTCALLBACK *PFNBRIDGEMAIN)( Vst2::audioMasterCallback audiomaster_, char * pszPluginPath );\
                                        if(module->moduleMain)\
                                        {\
                                            effect = module->moduleMain (&audioMaster);\
                                        }\
                                        else if((unsigned __int64)(module->customMain) == 0xfffffffffffffffe)\
                                        {\
                                            PFNBRIDGEMAIN jBridgeMain = 0;\
                                            if(module->module.getNativeHandle() == nullptr)\
                                                module->module.open(WindowsRegistry::getValue ("HKEY_LOCAL_MACHINE\\Software\\JBridge\\Proxy64", ""));\
                                            if(module->module.getNativeHandle() != nullptr)\
                                                jBridgeMain = (PFNBRIDGEMAIN) (module->module.getFunction("BridgeMain"));\
                                            char plug32bitPath[_MAX_PATH];\
                                            plug32bitPath[0] = 0;\
                                            strcpy(plug32bitPath, module->file.getFullPathName().toRawUTF8());\
                                            if(jBridgeMain)\
                                                effect = (Vst2::AEffect*)(jBridgeMain(&audioMaster, plug32bitPath));\
                                        }
#endif // JUCE_VST_WRAPPER_INVOKE_MAIN
#endif // _AMD64_
2 Likes