1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-09 23:34:20 +00:00

VSTPluginFormat: Extract headless plugin format type

This commit is contained in:
reuk 2025-08-20 19:33:06 +01:00
parent edcc699aa8
commit dd5ced96c1
No known key found for this signature in database
11 changed files with 3330 additions and 3136 deletions

View file

@ -119,7 +119,8 @@ using namespace juce;
#include <juce_audio_plugin_client/detail/juce_VSTWindowUtilities.h> #include <juce_audio_plugin_client/detail/juce_VSTWindowUtilities.h>
#include <juce_audio_processors_headless/format_types/juce_LegacyAudioParameter.h> #include <juce_audio_processors_headless/format_types/juce_LegacyAudioParameter.h>
#include <juce_audio_processors/format_types/juce_VSTCommon.h> #include <juce_audio_processors_headless/format_types/juce_VSTCommon.h>
#include <juce_audio_processors_headless/format_types/juce_VSTMidiEventList.h>
#ifdef JUCE_MSVC #ifdef JUCE_MSVC
#pragma pack (pop) #pragma pack (pop)

View file

@ -37,103 +37,20 @@
namespace juce namespace juce
{ {
//==============================================================================
/** /**
Implements a plugin format manager for VSTs. Implements a plugin format manager for VSTs.
@tags{Audio} @tags{Audio}
*/ */
class JUCE_API VSTPluginFormat : public AudioPluginFormat class JUCE_API VSTPluginFormat : public VSTPluginFormatHeadless
{ {
public: public:
//============================================================================== static std::unique_ptr<AudioPluginInstance> createCustomVSTFromMainCall (void* entryPointFunction,
VSTPluginFormat(); double initialSampleRate,
~VSTPluginFormat() override; int initialBufferSize);
//==============================================================================
/** Attempts to retrieve the VSTXML data from a plugin.
Will return nullptr if the plugin isn't a VST, or if it doesn't have any VSTXML.
*/
static const XmlElement* getVSTXML (AudioPluginInstance* plugin);
/** Attempts to reload a VST plugin's state from some FXB or FXP data. */
static bool loadFromFXBFile (AudioPluginInstance* plugin, const void* data, size_t dataSize);
/** Attempts to save a VST's state to some FXP or FXB data. */
static bool saveToFXBFile (AudioPluginInstance* plugin, MemoryBlock& result, bool asFXB);
/** Attempts to get a VST's state as a chunk of memory. */
static bool getChunkData (AudioPluginInstance* plugin, MemoryBlock& result, bool isPreset);
/** Attempts to set a VST's state from a chunk of memory. */
static bool setChunkData (AudioPluginInstance* plugin, const void* data, int size, bool isPreset);
/** Given a suitable function pointer to a VSTPluginMain function, this will attempt to
instantiate and return a plugin for it.
*/
static AudioPluginInstance* createCustomVSTFromMainCall (void* entryPointFunction,
double initialSampleRate,
int initialBufferSize);
//==============================================================================
/** Base class for some extra functions that can be attached to a VST plugin instance. */
class ExtraFunctions
{
public:
virtual ~ExtraFunctions() {}
/** This should return 10000 * the BPM at this position in the current edit. */
virtual int64 getTempoAt (int64 samplePos) = 0;
/** This should return the host's automation state.
@returns 0 = not supported, 1 = off, 2 = read, 3 = write, 4 = read/write
*/
virtual int getAutomationState() = 0;
};
/** Provides an ExtraFunctions callback object for a plugin to use.
The plugin will take ownership of the object and will delete it automatically.
*/
static void setExtraFunctions (AudioPluginInstance* plugin, ExtraFunctions* functions);
//==============================================================================
/** This simply calls directly to the VST's AEffect::dispatcher() function. */
static pointer_sized_int JUCE_CALLTYPE dispatcher (AudioPluginInstance*, int32, int32, pointer_sized_int, void*, float);
/** Given a VstEffectInterface* (aka vst::AEffect*), this will return the juce AudioPluginInstance
that is being used to wrap it
*/
static AudioPluginInstance* getPluginInstanceFromVstEffectInterface (void* aEffect);
//==============================================================================
static String getFormatName() { return "VST"; }
String getName() const override { return getFormatName(); }
bool canScanForPlugins() const override { return true; }
bool isTrivialToScan() const override { return false; }
void findAllTypesForFile (OwnedArray<PluginDescription>&, const String& fileOrIdentifier) override;
bool fileMightContainThisPluginType (const String& fileOrIdentifier) override;
String getNameOfPluginFromIdentifier (const String& fileOrIdentifier) override;
bool pluginNeedsRescanning (const PluginDescription&) override;
StringArray searchPathsForPlugins (const FileSearchPath&, bool recursive, bool) override;
bool doesPluginStillExist (const PluginDescription&) override;
FileSearchPath getDefaultLocationsToSearch() override;
/** Can be overridden to receive a callback when each member of a shell plugin is about to be
tested during a call to findAllTypesForFile().
Only the name and uid members of the PluginDescription are guaranteed to be valid when
this is called.
*/
virtual void aboutToScanVSTShellPlugin (const PluginDescription&);
private: private:
//============================================================================== void createPluginInstance (const PluginDescription&, double, int, PluginCreationCallback) override;
void createPluginInstance (const PluginDescription&, double initialSampleRate,
int initialBufferSize, PluginCreationCallback) override;
bool requiresUnblockedMessageThreadDuringCreation (const PluginDescription&) const override;
void recursiveFileSearch (StringArray&, const File&, bool recursive);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VSTPluginFormat)
}; };
} // namespace juce } // namespace juce

View file

@ -146,7 +146,6 @@
#include "format_types/juce_LADSPAPluginFormat.h" #include "format_types/juce_LADSPAPluginFormat.h"
#include "format_types/juce_LV2PluginFormat.h" #include "format_types/juce_LV2PluginFormat.h"
#include "format_types/juce_VST3PluginFormat.h" #include "format_types/juce_VST3PluginFormat.h"
#include "format_types/juce_VSTMidiEventList.h"
#include "format_types/juce_VSTPluginFormat.h" #include "format_types/juce_VSTPluginFormat.h"
#include "scanning/juce_PluginDirectoryScanner.h" #include "scanning/juce_PluginDirectoryScanner.h"
#include "scanning/juce_PluginListComponent.h" #include "scanning/juce_PluginListComponent.h"

View file

@ -32,6 +32,8 @@
============================================================================== ==============================================================================
*/ */
#pragma once
namespace juce namespace juce
{ {

View file

@ -32,8 +32,7 @@
============================================================================== ==============================================================================
*/ */
// NB: this must come first, *before* the header-guard. #pragma once
#ifdef JUCE_VSTINTERFACE_H_INCLUDED
namespace juce namespace juce
{ {
@ -227,5 +226,3 @@ private:
}; };
} // namespace juce } // namespace juce
#endif // JUCE_VSTINTERFACE_H_INCLUDED

View file

@ -0,0 +1,278 @@
/*
==============================================================================
This file is part of the JUCE framework.
Copyright (c) Raw Material Software Limited
JUCE is an open source framework subject to commercial or open source
licensing.
By downloading, installing, or using the JUCE framework, or combining the
JUCE framework with any other source code, object code, content or any other
copyrightable work, you agree to the terms of the JUCE End User Licence
Agreement, and all incorporated terms including the JUCE Privacy Policy and
the JUCE Website Terms of Service, as applicable, which will bind you. If you
do not agree to the terms of these agreements, we will not license the JUCE
framework to you, and you must discontinue the installation or download
process and cease use of the JUCE framework.
JUCE End User Licence Agreement: https://juce.com/legal/juce-8-licence/
JUCE Privacy Policy: https://juce.com/juce-privacy-policy
JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/
Or:
You may also use this code under the terms of the AGPLv3:
https://www.gnu.org/licenses/agpl-3.0.en.html
THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
==============================================================================
*/
#if JUCE_PLUGINHOST_VST
#include <juce_audio_processors_headless/format_types/juce_VSTPluginFormatImpl.h>
#include <juce_audio_processors_headless/utilities/juce_CommonProcessorUtilities.h>
namespace juce
{
void VSTPluginFormatHeadless::findAllTypesForFile (OwnedArray<PluginDescription>& results,
const String& fileOrIdentifier)
{
if (! fileMightContainThisPluginType (fileOrIdentifier))
return;
PluginDescription desc;
desc.fileOrIdentifier = fileOrIdentifier;
desc.uniqueId = desc.deprecatedUid = 0;
auto instance = createAndUpdateDesc (*this, desc);
if (instance == nullptr)
return;
if (instance->getVstCategory() != Vst2::kPlugCategShell)
{
// Normal plugin...
results.add (new PluginDescription (desc));
instance->dispatch (Vst2::effOpen, 0, 0, nullptr, 0);
}
else
{
// It's a shell plugin, so iterate all the subtypes...
for (;;)
{
char shellEffectName [256] = { 0 };
auto uid = (int) instance->dispatch (Vst2::effShellGetNextPlugin, 0, 0, shellEffectName, 0);
if (uid == 0)
break;
desc.uniqueId = desc.deprecatedUid = uid;
desc.name = shellEffectName;
aboutToScanVSTShellPlugin (desc);
std::unique_ptr<VSTPluginInstanceHeadless> shellInstance (createAndUpdateDesc (*this, desc));
if (shellInstance != nullptr)
{
jassert (desc.deprecatedUid == uid);
jassert (desc.uniqueId == uid);
desc.hasSharedContainer = true;
desc.name = shellEffectName;
if (! arrayContainsPlugin (results, desc))
results.add (new PluginDescription (desc));
}
}
}
}
void VSTPluginFormatHeadless::createPluginInstance (const PluginDescription& desc,
double sampleRate,
int blockSize,
PluginCreationCallback callback)
{
createVstPluginInstance<VSTPluginInstanceHeadless> (*this, desc, sampleRate, blockSize, callback);
}
bool VSTPluginFormatHeadless::requiresUnblockedMessageThreadDuringCreation (const PluginDescription&) const
{
return false;
}
bool VSTPluginFormatHeadless::fileMightContainThisPluginType (const String& fileOrIdentifier)
{
auto f = File::createFileWithoutCheckingPath (fileOrIdentifier);
#if JUCE_MAC || JUCE_IOS
return f.isDirectory() && f.hasFileExtension (".vst");
#elif JUCE_WINDOWS
return f.existsAsFile() && f.hasFileExtension (".dll");
#elif JUCE_LINUX || JUCE_BSD || JUCE_ANDROID
return f.existsAsFile() && f.hasFileExtension (".so");
#endif
}
String VSTPluginFormatHeadless::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
{
return fileOrIdentifier;
}
bool VSTPluginFormatHeadless::pluginNeedsRescanning (const PluginDescription& desc)
{
return File (desc.fileOrIdentifier).getLastModificationTime() != desc.lastFileModTime;
}
bool VSTPluginFormatHeadless::doesPluginStillExist (const PluginDescription& desc)
{
return File (desc.fileOrIdentifier).exists();
}
StringArray VSTPluginFormatHeadless::searchPathsForPlugins (const FileSearchPath& directoriesToSearch, const bool recursive, bool)
{
StringArray results;
for (int j = 0; j < directoriesToSearch.getNumPaths(); ++j)
recursiveFileSearch (results, directoriesToSearch [j], recursive);
return results;
}
void VSTPluginFormatHeadless::recursiveFileSearch (StringArray& results, const File& dir, const bool recursive)
{
// avoid allowing the dir iterator to be recursive, because we want to avoid letting it delve inside
// .component or .vst directories.
for (const auto& iter : RangedDirectoryIterator (dir, false, "*", File::findFilesAndDirectories))
{
auto f = iter.getFile();
bool isPlugin = false;
if (fileMightContainThisPluginType (f.getFullPathName()))
{
isPlugin = true;
results.add (f.getFullPathName());
}
if (recursive && (! isPlugin) && f.isDirectory())
recursiveFileSearch (results, f, true);
}
}
FileSearchPath VSTPluginFormatHeadless::getDefaultLocationsToSearch()
{
#if JUCE_MAC
return FileSearchPath ("~/Library/Audio/Plug-Ins/VST;/Library/Audio/Plug-Ins/VST");
#elif JUCE_LINUX || JUCE_BSD || JUCE_ANDROID
return FileSearchPath (SystemStats::getEnvironmentVariable ("VST_PATH",
"/usr/lib/vst;/usr/local/lib/vst;~/.vst")
.replace (":", ";"));
#elif JUCE_WINDOWS
auto programFiles = File::getSpecialLocation (File::globalApplicationsDirectory).getFullPathName();
FileSearchPath paths;
paths.add (WindowsRegistry::getValue ("HKEY_LOCAL_MACHINE\\Software\\VST\\VSTPluginsPath"));
paths.addIfNotAlreadyThere (programFiles + "\\Steinberg\\VstPlugins");
paths.addIfNotAlreadyThere (programFiles + "\\VstPlugins");
paths.removeRedundantPaths();
return paths;
#elif JUCE_IOS
// on iOS you can only load plug-ins inside the hosts bundle folder
CFUniquePtr<CFURLRef> relativePluginDir (CFBundleCopyBuiltInPlugInsURL (CFBundleGetMainBundle()));
CFUniquePtr<CFURLRef> pluginDir (CFURLCopyAbsoluteURL (relativePluginDir.get()));
CFUniquePtr<CFStringRef> path (CFURLCopyFileSystemPath (pluginDir.get(), kCFURLPOSIXPathStyle));
FileSearchPath retval (String (CFStringGetCStringPtr (path.get(), kCFStringEncodingUTF8)));
return retval;
#endif
}
const XmlElement* VSTPluginFormatHeadless::getVSTXML (AudioPluginInstance* plugin)
{
if (auto* vst = dynamic_cast<VSTPluginInstanceHeadless*> (plugin))
if (vst->vstModule != nullptr)
return vst->vstModule->vstXml.get();
return nullptr;
}
bool VSTPluginFormatHeadless::loadFromFXBFile (AudioPluginInstance* plugin, const void* data, size_t dataSize)
{
if (auto* vst = dynamic_cast<VSTPluginInstanceHeadless*> (plugin))
return vst->loadFromFXBFile (data, dataSize);
return false;
}
bool VSTPluginFormatHeadless::saveToFXBFile (AudioPluginInstance* plugin, MemoryBlock& dest, bool asFXB)
{
if (auto* vst = dynamic_cast<VSTPluginInstanceHeadless*> (plugin))
return vst->saveToFXBFile (dest, asFXB);
return false;
}
bool VSTPluginFormatHeadless::getChunkData (AudioPluginInstance* plugin, MemoryBlock& result, bool isPreset)
{
if (auto* vst = dynamic_cast<VSTPluginInstanceHeadless*> (plugin))
return vst->getChunkData (result, isPreset, 128);
return false;
}
bool VSTPluginFormatHeadless::setChunkData (AudioPluginInstance* plugin, const void* data, int size, bool isPreset)
{
if (auto* vst = dynamic_cast<VSTPluginInstanceHeadless*> (plugin))
return vst->setChunkData (data, size, isPreset);
return false;
}
AudioPluginInstance* VSTPluginFormatHeadless::createCustomVSTFromMainCall (void* entryPointFunction,
double initialSampleRate,
int initialBufferSize)
{
return createCustomVSTFromMainCallImpl<VSTPluginInstanceHeadless> (entryPointFunction, initialSampleRate, initialBufferSize).release();
}
void VSTPluginFormatHeadless::setExtraFunctions (AudioPluginInstance* plugin, ExtraFunctions* functions)
{
std::unique_ptr<ExtraFunctions> f (functions);
if (auto* vst = dynamic_cast<VSTPluginInstanceHeadless*> (plugin))
std::swap (vst->extraFunctions, f);
}
AudioPluginInstance* VSTPluginFormatHeadless::getPluginInstanceFromVstEffectInterface (void* aEffect)
{
if (auto* vstAEffect = reinterpret_cast<Vst2::AEffect*> (aEffect))
if (auto* instanceVST = reinterpret_cast<VSTPluginInstanceHeadless*> (vstAEffect->resvd2))
return dynamic_cast<AudioPluginInstance*> (instanceVST);
return nullptr;
}
pointer_sized_int JUCE_CALLTYPE VSTPluginFormatHeadless::dispatcher (AudioPluginInstance* plugin,
int32 opcode,
int32 index,
pointer_sized_int value,
void* ptr,
float opt)
{
if (auto* vst = dynamic_cast<VSTPluginInstanceHeadless*> (plugin))
return vst->dispatch (opcode, index, value, ptr, opt);
return {};
}
void VSTPluginFormatHeadless::aboutToScanVSTShellPlugin (const PluginDescription&) {}
} // namespace juce
#endif

View file

@ -0,0 +1,140 @@
/*
==============================================================================
This file is part of the JUCE framework.
Copyright (c) Raw Material Software Limited
JUCE is an open source framework subject to commercial or open source
licensing.
By downloading, installing, or using the JUCE framework, or combining the
JUCE framework with any other source code, object code, content or any other
copyrightable work, you agree to the terms of the JUCE End User Licence
Agreement, and all incorporated terms including the JUCE Privacy Policy and
the JUCE Website Terms of Service, as applicable, which will bind you. If you
do not agree to the terms of these agreements, we will not license the JUCE
framework to you, and you must discontinue the installation or download
process and cease use of the JUCE framework.
JUCE End User Licence Agreement: https://juce.com/legal/juce-8-licence/
JUCE Privacy Policy: https://juce.com/juce-privacy-policy
JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/
Or:
You may also use this code under the terms of the AGPLv3:
https://www.gnu.org/licenses/agpl-3.0.en.html
THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
==============================================================================
*/
#if (JUCE_PLUGINHOST_VST || DOXYGEN)
namespace juce
{
//==============================================================================
/**
Implements a plugin format manager for VSTs.
@tags{Audio}
*/
class JUCE_API VSTPluginFormatHeadless : public AudioPluginFormat
{
public:
//==============================================================================
VSTPluginFormatHeadless() = default;
//==============================================================================
/** Attempts to retrieve the VSTXML data from a plugin.
Will return nullptr if the plugin isn't a VST, or if it doesn't have any VSTXML.
*/
static const XmlElement* getVSTXML (AudioPluginInstance* plugin);
/** Attempts to reload a VST plugin's state from some FXB or FXP data. */
static bool loadFromFXBFile (AudioPluginInstance* plugin, const void* data, size_t dataSize);
/** Attempts to save a VST's state to some FXP or FXB data. */
static bool saveToFXBFile (AudioPluginInstance* plugin, MemoryBlock& result, bool asFXB);
/** Attempts to get a VST's state as a chunk of memory. */
static bool getChunkData (AudioPluginInstance* plugin, MemoryBlock& result, bool isPreset);
/** Attempts to set a VST's state from a chunk of memory. */
static bool setChunkData (AudioPluginInstance* plugin, const void* data, int size, bool isPreset);
/** Given a suitable function pointer to a VSTPluginMain function, this will attempt to
instantiate and return a plugin for it.
*/
static AudioPluginInstance* createCustomVSTFromMainCall (void* entryPointFunction,
double initialSampleRate,
int initialBufferSize);
//==============================================================================
/** Base class for some extra functions that can be attached to a VST plugin instance. */
class ExtraFunctions
{
public:
virtual ~ExtraFunctions() {}
/** This should return 10000 * the BPM at this position in the current edit. */
virtual int64 getTempoAt (int64 samplePos) = 0;
/** This should return the host's automation state.
@returns 0 = not supported, 1 = off, 2 = read, 3 = write, 4 = read/write
*/
virtual int getAutomationState() = 0;
};
/** Provides an ExtraFunctions callback object for a plugin to use.
The plugin will take ownership of the object and will delete it automatically.
*/
static void setExtraFunctions (AudioPluginInstance* plugin, ExtraFunctions* functions);
//==============================================================================
/** This simply calls directly to the VST's AEffect::dispatcher() function. */
static pointer_sized_int JUCE_CALLTYPE dispatcher (AudioPluginInstance*, int32, int32, pointer_sized_int, void*, float);
/** Given a VstEffectInterface* (aka vst::AEffect*), this will return the juce AudioPluginInstance
that is being used to wrap it
*/
static AudioPluginInstance* getPluginInstanceFromVstEffectInterface (void* aEffect);
//==============================================================================
static String getFormatName() { return "VST"; }
String getName() const override { return getFormatName(); }
bool canScanForPlugins() const override { return true; }
bool isTrivialToScan() const override { return false; }
void findAllTypesForFile (OwnedArray<PluginDescription>&, const String& fileOrIdentifier) override;
bool fileMightContainThisPluginType (const String& fileOrIdentifier) override;
String getNameOfPluginFromIdentifier (const String& fileOrIdentifier) override;
bool pluginNeedsRescanning (const PluginDescription&) override;
StringArray searchPathsForPlugins (const FileSearchPath&, bool recursive, bool) override;
bool doesPluginStillExist (const PluginDescription&) override;
FileSearchPath getDefaultLocationsToSearch() override;
/** Can be overridden to receive a callback when each member of a shell plugin is about to be
tested during a call to findAllTypesForFile().
Only the name and uid members of the PluginDescription are guaranteed to be valid when
this is called.
*/
virtual void aboutToScanVSTShellPlugin (const PluginDescription&);
private:
//==============================================================================
void createPluginInstance (const PluginDescription&, double initialSampleRate,
int initialBufferSize, PluginCreationCallback) override;
bool requiresUnblockedMessageThreadDuringCreation (const PluginDescription&) const override;
void recursiveFileSearch (StringArray&, const File&, bool recursive);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VSTPluginFormatHeadless)
};
} // namespace juce
#endif

File diff suppressed because it is too large Load diff

View file

@ -68,4 +68,5 @@
#include <juce_audio_processors_headless/format_types/juce_LADSPAPluginFormatHeadless.cpp> #include <juce_audio_processors_headless/format_types/juce_LADSPAPluginFormatHeadless.cpp>
#include <juce_audio_processors_headless/format_types/juce_LV2PluginFormatHeadless.cpp> #include <juce_audio_processors_headless/format_types/juce_LV2PluginFormatHeadless.cpp>
#include <juce_audio_processors_headless/format_types/juce_VST3PluginFormatHeadless.cpp> #include <juce_audio_processors_headless/format_types/juce_VST3PluginFormatHeadless.cpp>
#include <juce_audio_processors_headless/format_types/juce_VSTPluginFormatHeadless.cpp>
#include <juce_audio_processors_headless/format_types/juce_ARAHosting.cpp> #include <juce_audio_processors_headless/format_types/juce_ARAHosting.cpp>

View file

@ -93,4 +93,5 @@
#include <juce_audio_processors_headless/format_types/juce_LADSPAPluginFormatHeadless.h> #include <juce_audio_processors_headless/format_types/juce_LADSPAPluginFormatHeadless.h>
#include <juce_audio_processors_headless/format_types/juce_LV2PluginFormatHeadless.h> #include <juce_audio_processors_headless/format_types/juce_LV2PluginFormatHeadless.h>
#include <juce_audio_processors_headless/format_types/juce_VST3PluginFormatHeadless.h> #include <juce_audio_processors_headless/format_types/juce_VST3PluginFormatHeadless.h>
#include <juce_audio_processors_headless/format_types/juce_VSTPluginFormatHeadless.h>
#include <juce_audio_processors_headless/format_types/juce_ARAHosting.h> #include <juce_audio_processors_headless/format_types/juce_ARAHosting.h>