1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +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

@ -0,0 +1,317 @@
/*
==============================================================================
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.
==============================================================================
*/
#pragma once
namespace juce
{
//==============================================================================
/** Structure for VST speaker mappings
@tags{Audio}
*/
struct SpeakerMappings : private AudioChannelSet // (inheritance only to give easier access to items in the namespace)
{
/** Structure describing a mapping */
struct Mapping
{
int32 vst2;
ChannelType channels[13];
bool matches (const Array<ChannelType>& chans) const noexcept
{
auto n = static_cast<int> (sizeof (channels) / sizeof (ChannelType));
for (int i = 0; i < n; ++i)
{
if (channels[i] == unknown) return (i == chans.size());
if (i == chans.size()) return (channels[i] == unknown);
if (channels[i] != chans.getUnchecked (i))
return false;
}
return true;
}
};
static AudioChannelSet vstArrangementTypeToChannelSet (int32 arr, int fallbackNumChannels)
{
if (arr == Vst2::kSpeakerArrEmpty) return AudioChannelSet::disabled();
else if (arr == Vst2::kSpeakerArrMono) return AudioChannelSet::mono();
else if (arr == Vst2::kSpeakerArrStereo) return AudioChannelSet::stereo();
else if (arr == Vst2::kSpeakerArr30Cine) return AudioChannelSet::createLCR();
else if (arr == Vst2::kSpeakerArr30Music) return AudioChannelSet::createLRS();
else if (arr == Vst2::kSpeakerArr40Cine) return AudioChannelSet::createLCRS();
else if (arr == Vst2::kSpeakerArr50) return AudioChannelSet::create5point0();
else if (arr == Vst2::kSpeakerArr51) return AudioChannelSet::create5point1();
else if (arr == Vst2::kSpeakerArr60Cine) return AudioChannelSet::create6point0();
else if (arr == Vst2::kSpeakerArr61Cine) return AudioChannelSet::create6point1();
else if (arr == Vst2::kSpeakerArr60Music) return AudioChannelSet::create6point0Music();
else if (arr == Vst2::kSpeakerArr61Music) return AudioChannelSet::create6point1Music();
else if (arr == Vst2::kSpeakerArr70Music) return AudioChannelSet::create7point0();
else if (arr == Vst2::kSpeakerArr70Cine) return AudioChannelSet::create7point0SDDS();
else if (arr == Vst2::kSpeakerArr71Music) return AudioChannelSet::create7point1();
else if (arr == Vst2::kSpeakerArr71Cine) return AudioChannelSet::create7point1SDDS();
else if (arr == Vst2::kSpeakerArr40Music) return AudioChannelSet::quadraphonic();
for (const Mapping* m = getMappings(); m->vst2 != Vst2::kSpeakerArrEmpty; ++m)
{
if (m->vst2 == arr)
{
AudioChannelSet s;
for (int i = 0; m->channels[i] != 0; ++i)
s.addChannel (m->channels[i]);
return s;
}
}
return AudioChannelSet::discreteChannels (fallbackNumChannels);
}
static AudioChannelSet vstArrangementTypeToChannelSet (const Vst2::VstSpeakerArrangement& arr)
{
return vstArrangementTypeToChannelSet (arr.type, arr.numChannels);
}
static int32 channelSetToVstArrangementType (AudioChannelSet channels)
{
if (channels == AudioChannelSet::disabled()) return Vst2::kSpeakerArrEmpty;
else if (channels == AudioChannelSet::mono()) return Vst2::kSpeakerArrMono;
else if (channels == AudioChannelSet::stereo()) return Vst2::kSpeakerArrStereo;
else if (channels == AudioChannelSet::createLCR()) return Vst2::kSpeakerArr30Cine;
else if (channels == AudioChannelSet::createLRS()) return Vst2::kSpeakerArr30Music;
else if (channels == AudioChannelSet::createLCRS()) return Vst2::kSpeakerArr40Cine;
else if (channels == AudioChannelSet::create5point0()) return Vst2::kSpeakerArr50;
else if (channels == AudioChannelSet::create5point1()) return Vst2::kSpeakerArr51;
else if (channels == AudioChannelSet::create6point0()) return Vst2::kSpeakerArr60Cine;
else if (channels == AudioChannelSet::create6point1()) return Vst2::kSpeakerArr61Cine;
else if (channels == AudioChannelSet::create6point0Music()) return Vst2::kSpeakerArr60Music;
else if (channels == AudioChannelSet::create6point1Music()) return Vst2::kSpeakerArr61Music;
else if (channels == AudioChannelSet::create7point0()) return Vst2::kSpeakerArr70Music;
else if (channels == AudioChannelSet::create7point0SDDS()) return Vst2::kSpeakerArr70Cine;
else if (channels == AudioChannelSet::create7point1()) return Vst2::kSpeakerArr71Music;
else if (channels == AudioChannelSet::create7point1SDDS()) return Vst2::kSpeakerArr71Cine;
else if (channels == AudioChannelSet::quadraphonic()) return Vst2::kSpeakerArr40Music;
if (channels == AudioChannelSet::disabled())
return Vst2::kSpeakerArrEmpty;
auto chans = channels.getChannelTypes();
for (auto* m = getMappings(); m->vst2 != Vst2::kSpeakerArrEmpty; ++m)
if (m->matches (chans))
return m->vst2;
return Vst2::kSpeakerArrUserDefined;
}
static void channelSetToVstArrangement (const AudioChannelSet& channels, Vst2::VstSpeakerArrangement& result)
{
result.type = channelSetToVstArrangementType (channels);
result.numChannels = channels.size();
for (int i = 0; i < result.numChannels; ++i)
{
auto& speaker = result.speakers[i];
zeromem (&speaker, sizeof (Vst2::VstSpeakerProperties));
speaker.type = getSpeakerType (channels.getTypeOfChannel (i));
}
}
/** Class to hold a speaker configuration */
class VstSpeakerConfigurationHolder
{
public:
VstSpeakerConfigurationHolder()
{
clear();
}
VstSpeakerConfigurationHolder (const Vst2::VstSpeakerArrangement& vstConfig)
{
operator= (vstConfig);
}
VstSpeakerConfigurationHolder (const VstSpeakerConfigurationHolder& other)
{
operator= (other.get());
}
VstSpeakerConfigurationHolder (VstSpeakerConfigurationHolder&& other)
: storage (std::move (other.storage))
{
other.clear();
}
VstSpeakerConfigurationHolder (const AudioChannelSet& channels)
{
auto numberOfChannels = channels.size();
Vst2::VstSpeakerArrangement& dst = *allocate (numberOfChannels);
dst.type = channelSetToVstArrangementType (channels);
dst.numChannels = numberOfChannels;
for (int i = 0; i < dst.numChannels; ++i)
{
Vst2::VstSpeakerProperties& speaker = dst.speakers[i];
zeromem (&speaker, sizeof (Vst2::VstSpeakerProperties));
speaker.type = getSpeakerType (channels.getTypeOfChannel (i));
}
}
VstSpeakerConfigurationHolder& operator= (const VstSpeakerConfigurationHolder& vstConfig) { return operator= (vstConfig.get()); }
VstSpeakerConfigurationHolder& operator= (const Vst2::VstSpeakerArrangement& vstConfig)
{
Vst2::VstSpeakerArrangement& dst = *allocate (vstConfig.numChannels);
dst.type = vstConfig.type;
dst.numChannels = vstConfig.numChannels;
for (int i = 0; i < dst.numChannels; ++i)
dst.speakers[i] = vstConfig.speakers[i];
return *this;
}
VstSpeakerConfigurationHolder& operator= (VstSpeakerConfigurationHolder && vstConfig)
{
storage = std::move (vstConfig.storage);
vstConfig.clear();
return *this;
}
const Vst2::VstSpeakerArrangement& get() const { return *storage.get(); }
private:
JUCE_LEAK_DETECTOR (VstSpeakerConfigurationHolder)
HeapBlock<Vst2::VstSpeakerArrangement> storage;
Vst2::VstSpeakerArrangement* allocate (int numChannels)
{
auto arrangementSize = (size_t) (jmax (8, numChannels) - 8) * sizeof (Vst2::VstSpeakerProperties)
+ sizeof (Vst2::VstSpeakerArrangement);
storage.malloc (1, arrangementSize);
return storage.get();
}
void clear()
{
Vst2::VstSpeakerArrangement& dst = *allocate (0);
dst.type = Vst2::kSpeakerArrEmpty;
dst.numChannels = 0;
}
};
static const Mapping* getMappings() noexcept
{
static const Mapping mappings[] =
{
{ Vst2::kSpeakerArrMono, { centre, unknown } },
{ Vst2::kSpeakerArrStereo, { left, right, unknown } },
{ Vst2::kSpeakerArrStereoSurround, { leftSurround, rightSurround, unknown } },
{ Vst2::kSpeakerArrStereoCenter, { leftCentre, rightCentre, unknown } },
{ Vst2::kSpeakerArrStereoSide, { leftSurroundRear, rightSurroundRear, unknown } },
{ Vst2::kSpeakerArrStereoCLfe, { centre, LFE, unknown } },
{ Vst2::kSpeakerArr30Cine, { left, right, centre, unknown } },
{ Vst2::kSpeakerArr30Music, { left, right, surround, unknown } },
{ Vst2::kSpeakerArr31Cine, { left, right, centre, LFE, unknown } },
{ Vst2::kSpeakerArr31Music, { left, right, LFE, surround, unknown } },
{ Vst2::kSpeakerArr40Cine, { left, right, centre, surround, unknown } },
{ Vst2::kSpeakerArr40Music, { left, right, leftSurround, rightSurround, unknown } },
{ Vst2::kSpeakerArr41Cine, { left, right, centre, LFE, surround, unknown } },
{ Vst2::kSpeakerArr41Music, { left, right, LFE, leftSurround, rightSurround, unknown } },
{ Vst2::kSpeakerArr50, { left, right, centre, leftSurround, rightSurround, unknown } },
{ Vst2::kSpeakerArr51, { left, right, centre, LFE, leftSurround, rightSurround, unknown } },
{ Vst2::kSpeakerArr60Cine, { left, right, centre, leftSurround, rightSurround, surround, unknown } },
{ Vst2::kSpeakerArr60Music, { left, right, leftSurround, rightSurround, leftSurroundRear, rightSurroundRear, unknown } },
{ Vst2::kSpeakerArr61Cine, { left, right, centre, LFE, leftSurround, rightSurround, surround, unknown } },
{ Vst2::kSpeakerArr61Music, { left, right, LFE, leftSurround, rightSurround, leftSurroundRear, rightSurroundRear, unknown } },
{ Vst2::kSpeakerArr70Cine, { left, right, centre, leftSurround, rightSurround, topFrontLeft, topFrontRight, unknown } },
{ Vst2::kSpeakerArr70Music, { left, right, centre, leftSurround, rightSurround, leftSurroundRear, rightSurroundRear, unknown } },
{ Vst2::kSpeakerArr71Cine, { left, right, centre, LFE, leftSurround, rightSurround, topFrontLeft, topFrontRight, unknown } },
{ Vst2::kSpeakerArr71Music, { left, right, centre, LFE, leftSurround, rightSurround, leftSurroundRear, rightSurroundRear, unknown } },
{ Vst2::kSpeakerArr80Cine, { left, right, centre, leftSurround, rightSurround, topFrontLeft, topFrontRight, surround, unknown } },
{ Vst2::kSpeakerArr80Music, { left, right, centre, leftSurround, rightSurround, surround, leftSurroundRear, rightSurroundRear, unknown } },
{ Vst2::kSpeakerArr81Cine, { left, right, centre, LFE, leftSurround, rightSurround, topFrontLeft, topFrontRight, surround, unknown } },
{ Vst2::kSpeakerArr81Music, { left, right, centre, LFE, leftSurround, rightSurround, surround, leftSurroundRear, rightSurroundRear, unknown } },
{ Vst2::kSpeakerArr102, { left, right, centre, LFE, leftSurround, rightSurround, topFrontLeft, topFrontCentre, topFrontRight, topRearLeft, topRearRight, LFE2, unknown } },
{ Vst2::kSpeakerArrEmpty, { unknown } }
};
return mappings;
}
static int32 getSpeakerType (AudioChannelSet::ChannelType type) noexcept
{
static const std::map<AudioChannelSet::ChannelType, int32> speakerTypeMap =
{
{ AudioChannelSet::left, Vst2::kSpeakerL },
{ AudioChannelSet::right, Vst2::kSpeakerR },
{ AudioChannelSet::centre, Vst2::kSpeakerC },
{ AudioChannelSet::LFE, Vst2::kSpeakerLfe },
{ AudioChannelSet::leftSurround, Vst2::kSpeakerLs },
{ AudioChannelSet::rightSurround, Vst2::kSpeakerRs },
{ AudioChannelSet::leftCentre, Vst2::kSpeakerLc },
{ AudioChannelSet::rightCentre, Vst2::kSpeakerRc },
{ AudioChannelSet::surround, Vst2::kSpeakerS },
{ AudioChannelSet::leftSurroundRear, Vst2::kSpeakerSl },
{ AudioChannelSet::rightSurroundRear, Vst2::kSpeakerSr },
{ AudioChannelSet::topMiddle, Vst2::kSpeakerTm },
{ AudioChannelSet::topFrontLeft, Vst2::kSpeakerTfl },
{ AudioChannelSet::topFrontCentre, Vst2::kSpeakerTfc },
{ AudioChannelSet::topFrontRight, Vst2::kSpeakerTfr },
{ AudioChannelSet::topRearLeft, Vst2::kSpeakerTrl },
{ AudioChannelSet::topRearCentre, Vst2::kSpeakerTrc },
{ AudioChannelSet::topRearRight, Vst2::kSpeakerTrr },
{ AudioChannelSet::LFE2, Vst2::kSpeakerLfe2 }
};
if (speakerTypeMap.find (type) == speakerTypeMap.end())
return 0;
return speakerTypeMap.at (type);
}
};
} // namespace juce

View file

@ -0,0 +1,228 @@
/*
==============================================================================
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.
==============================================================================
*/
#pragma once
namespace juce
{
//==============================================================================
/** Holds a set of VSTMidiEvent objects and makes it easy to add
events to the list.
This is used by both the VST hosting code and the plugin wrapper.
@tags{Audio}
*/
class VSTMidiEventList
{
// "events" is expected to be a const- or non-const-ref to Vst2::VstEvents.
template <typename Events>
static auto& getEvent (Events& events, int index)
{
using EventType = decltype (&*events.events);
static constexpr auto offset = offsetof (Vst2::VstEvents, events);
auto* bytes = reinterpret_cast<std::conditional_t<std::is_const_v<std::remove_pointer_t<EventType>>,
const std::byte*,
std::byte*>> (&events);
auto* array = reinterpret_cast<EventType> (bytes + offset);
return array[index];
}
Vst2::VstEvent* const& getEvent (int index) const { return getEvent (*events, index); }
Vst2::VstEvent* & getEvent (int index) { return getEvent (*events, index); }
public:
//==============================================================================
VSTMidiEventList()
: numEventsUsed (0), numEventsAllocated (0)
{
}
~VSTMidiEventList()
{
freeEvents();
}
//==============================================================================
void clear()
{
numEventsUsed = 0;
if (events != nullptr)
events->numEvents = 0;
}
void addEvent (const void* const midiData, int numBytes, int frameOffset)
{
ensureSize (numEventsUsed + 1);
void* const ptr = getEvent (numEventsUsed);
events->numEvents = ++numEventsUsed;
if (numBytes <= 4)
{
auto* const e = static_cast<Vst2::VstMidiEvent*> (ptr);
if (e->type == Vst2::kVstSysExType)
{
delete[] reinterpret_cast<Vst2::VstMidiSysexEvent*> (e)->sysexDump;
e->type = Vst2::kVstMidiType;
e->byteSize = sizeof (Vst2::VstMidiEvent);
e->noteLength = 0;
e->noteOffset = 0;
e->detune = 0;
e->noteOffVelocity = 0;
}
e->deltaFrames = frameOffset;
memcpy (e->midiData, midiData, (size_t) numBytes);
}
else
{
auto* const se = static_cast<Vst2::VstMidiSysexEvent*> (ptr);
if (se->type == Vst2::kVstSysExType)
delete[] se->sysexDump;
se->sysexDump = new char [(size_t) numBytes];
memcpy (se->sysexDump, midiData, (size_t) numBytes);
se->type = Vst2::kVstSysExType;
se->byteSize = sizeof (Vst2::VstMidiSysexEvent);
se->deltaFrames = frameOffset;
se->flags = 0;
se->dumpBytes = numBytes;
se->resvd1 = 0;
se->resvd2 = 0;
}
}
//==============================================================================
// Handy method to pull the events out of an event buffer supplied by the host
// or plugin.
static void addEventsToMidiBuffer (const Vst2::VstEvents* events, MidiBuffer& dest)
{
for (int i = 0; i < events->numEvents; ++i)
{
const auto* const e = getEvent (*events, i);
if (e != nullptr)
{
const void* const ptr = e;
if (e->type == Vst2::kVstMidiType)
{
dest.addEvent ((const juce::uint8*) static_cast<const Vst2::VstMidiEvent*> (ptr)->midiData,
4, e->deltaFrames);
}
else if (e->type == Vst2::kVstSysExType)
{
const auto* se = static_cast<const Vst2::VstMidiSysexEvent*> (ptr);
dest.addEvent ((const juce::uint8*) se->sysexDump,
(int) se->dumpBytes,
e->deltaFrames);
}
}
}
}
//==============================================================================
void ensureSize (int numEventsNeeded)
{
if (numEventsNeeded > numEventsAllocated)
{
numEventsNeeded = (numEventsNeeded + 32) & ~31;
const size_t size = 20 + (size_t) numEventsNeeded * sizeof (Vst2::VstEvent*);
if (events == nullptr)
events.calloc (size, 1);
else
events.realloc (size, 1);
for (int i = numEventsAllocated; i < numEventsNeeded; ++i)
getEvent (i) = allocateVSTEvent();
numEventsAllocated = numEventsNeeded;
}
}
void freeEvents()
{
if (events != nullptr)
{
for (int i = numEventsAllocated; --i >= 0;)
freeVSTEvent (getEvent (i));
events.free();
numEventsUsed = 0;
numEventsAllocated = 0;
}
}
//==============================================================================
HeapBlock<Vst2::VstEvents> events;
private:
int numEventsUsed, numEventsAllocated;
static Vst2::VstEvent* allocateVSTEvent()
{
constexpr auto size = jmax (sizeof (Vst2::VstMidiEvent), sizeof (Vst2::VstMidiSysexEvent));
if (auto* e = static_cast<Vst2::VstEvent*> (std::calloc (1, size)))
{
e->type = Vst2::kVstMidiType;
e->byteSize = sizeof (Vst2::VstMidiEvent);
return e;
}
return nullptr;
}
static void freeVSTEvent (Vst2::VstEvent* e)
{
if (e->type == Vst2::kVstSysExType)
{
delete[] (reinterpret_cast<Vst2::VstMidiSysexEvent*> (e)->sysexDump);
}
std::free (e);
}
};
} // namespace juce

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_LV2PluginFormatHeadless.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>

View file

@ -93,4 +93,5 @@
#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_VST3PluginFormatHeadless.h>
#include <juce_audio_processors_headless/format_types/juce_VSTPluginFormatHeadless.h>
#include <juce_audio_processors_headless/format_types/juce_ARAHosting.h>