1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-28 02:30:05 +00:00

VST3: Fixed some build errors and warnings with JUCE_VST3_CAN_REPLACE_VST2=1 on Linux

This commit is contained in:
ed 2020-07-03 15:36:45 +01:00
parent 819ccc08ca
commit 31022e4521
6 changed files with 123 additions and 126 deletions

View file

@ -61,7 +61,7 @@ JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4996 4100)
#define PRAGMA_ALIGN_SUPPORTED 1
#endif
#ifndef _MSC_VER
#if ! JUCE_MSVC
#define __cdecl
#endif
@ -92,7 +92,7 @@ JUCE_END_IGNORE_WARNINGS_MSVC
JUCE_END_IGNORE_WARNINGS_GCC_LIKE
//==============================================================================
#ifdef _MSC_VER
#if JUCE_MSVC
#pragma pack (push, 8)
#endif
@ -109,13 +109,7 @@ using namespace juce;
#include <juce_audio_processors/format_types/juce_LegacyAudioParameter.cpp>
#include <juce_audio_processors/format_types/juce_VSTCommon.h>
#if JUCE_BIG_ENDIAN
#define JUCE_MULTICHAR_CONSTANT(a, b, c, d) (a | (((uint32) b) << 8) | (((uint32) c) << 16) | (((uint32) d) << 24))
#else
#define JUCE_MULTICHAR_CONSTANT(a, b, c, d) (d | (((uint32) c) << 8) | (((uint32) b) << 16) | (((uint32) a) << 24))
#endif
#ifdef _MSC_VER
#ifdef JUCE_MSVC
#pragma pack (pop)
#endif
@ -1872,8 +1866,8 @@ private:
if (handleManufacturerSpecificVST2Opcode (args.index, args.value, args.ptr, args.opt))
return 1;
if (args.index == (int32) JUCE_MULTICHAR_CONSTANT ('P', 'r', 'e', 'S')
&& args.value == (int32) JUCE_MULTICHAR_CONSTANT ('A', 'e', 'C', 's'))
if (args.index == (int32) ByteOrder::bigEndianInt ("PreS")
&& args.value == (int32) ByteOrder::bigEndianInt ("AeCs"))
return handleSetContentScaleFactor (args.opt);
if (args.index == Vst2::effGetParamDisplay)

View file

@ -27,9 +27,9 @@
#include <juce_core/system/juce_TargetPlatform.h>
//==============================================================================
#if JucePlugin_Build_VST3 && (__APPLE_CPP__ || __APPLE_CC__ || _WIN32 || _WIN64 || LINUX || __linux__)
#if JucePlugin_Build_VST3 && (JUCE_MAC || JUCE_WINDOWS || JUCE_LINUX)
#if JUCE_PLUGINHOST_VST3 && (JUCE_MAC || JUCE_WINDOWS || JUCE_LINUX)
#if JUCE_PLUGINHOST_VST3
#if JUCE_MAC
#include <CoreFoundation/CoreFoundation.h>
#endif
@ -56,10 +56,16 @@
#endif
#if JUCE_VST3_CAN_REPLACE_VST2
namespace Vst2
{
#include "pluginterfaces/vst2.x/vstfxstore.h"
}
#if ! JUCE_MSVC
#define __cdecl
#endif
namespace Vst2
{
#include "pluginterfaces/vst2.x/vstfxstore.h"
}
#endif
#ifndef JUCE_VST3_EMULATE_MIDI_CC_WITH_PARAMETERS
@ -69,6 +75,8 @@ namespace Vst2
#endif
#if JUCE_LINUX
#include <unordered_map>
std::vector<std::pair<int, std::function<void (int)>>> getFdReadCallbacks();
#endif
@ -1951,10 +1959,10 @@ public:
#if JUCE_VST3_CAN_REPLACE_VST2
bool loadVST2VstWBlock (const char* data, int size)
{
jassert ('VstW' == htonl (readUnaligned<juce::int32> (data)));
jassert (1 == htonl (readUnaligned<juce::int32> (data + 8))); // version should be 1 according to Steinberg's docs
jassert (ByteOrder::bigEndianInt ("VstW") == htonl ((uint32) readUnaligned<int32> (data)));
jassert (1 == htonl ((uint32) readUnaligned<int32> (data + 8))); // version should be 1 according to Steinberg's docs
auto headerLen = (int) htonl (readUnaligned<juce::int32> (data + 4)) + 8;
auto headerLen = (int) htonl ((uint32) readUnaligned<int32> (data + 4)) + 8;
return loadVST2CcnKBlock (data + headerLen, size - headerLen);
}
@ -1962,14 +1970,14 @@ public:
{
auto* bank = reinterpret_cast<const Vst2::fxBank*> (data);
jassert ('CcnK' == htonl (bank->chunkMagic));
jassert ('FBCh' == htonl (bank->fxMagic));
jassert (htonl (bank->version) == 1 || htonl (bank->version) == 2);
jassert (JucePlugin_VSTUniqueID == htonl (bank->fxID));
jassert (ByteOrder::bigEndianInt ("CcnK") == htonl ((uint32) bank->chunkMagic));
jassert (ByteOrder::bigEndianInt ("FBCh") == htonl ((uint32) bank->fxMagic));
jassert (htonl ((uint32) bank->version) == 1 || htonl ((uint32) bank->version) == 2);
jassert (JucePlugin_VSTUniqueID == htonl ((uint32) bank->fxID));
setStateInformation (bank->content.data.chunk,
jmin ((int) (size - (bank->content.data.chunk - data)),
(int) htonl (bank->content.data.size)));
(int) htonl ((uint32) bank->content.data.size)));
return true;
}
@ -1998,7 +2006,7 @@ public:
auto chunkOffset = ByteOrder::littleEndianInt64 (data + entryOffset + 4);
auto chunkSize = ByteOrder::littleEndianInt64 (data + entryOffset + 12);
if (chunkOffset + chunkSize > static_cast<juce::uint64> (size))
if (static_cast<uint64> (chunkOffset + chunkSize) > static_cast<uint64> (size))
{
jassertfalse;
return false;
@ -2016,12 +2024,12 @@ public:
if (size < 4)
return false;
auto header = htonl (readUnaligned<juce::int32> (data));
auto header = htonl ((uint32) readUnaligned<int32> (data));
if (header == 'VstW')
if (header == ByteOrder::bigEndianInt ("VstW"))
return loadVST2VstWBlock (data, size);
if (header == 'CcnK')
if (header == ByteOrder::bigEndianInt ("CcnK"))
return loadVST2CcnKBlock (data, size);
if (memcmp (data, "VST3", 4) == 0)
@ -2132,19 +2140,19 @@ public:
}
#if JUCE_VST3_CAN_REPLACE_VST2
static tresult writeVST2Int (IBStream* state, int n)
{
juce::int32 t = (juce::int32) htonl (n);
return state->write (&t, 4);
}
static tresult writeVST2Header (IBStream* state, bool bypassed)
{
tresult status = writeVST2Int (state, 'VstW');
auto writeVST2IntToState = [state] (uint32 n)
{
auto t = (int32) htonl (n);
return state->write (&t, 4);
};
if (status == kResultOk) status = writeVST2Int (state, 8); // header size
if (status == kResultOk) status = writeVST2Int (state, 1); // version
if (status == kResultOk) status = writeVST2Int (state, bypassed ? 1 : 0); // bypass
auto status = writeVST2IntToState (ByteOrder::bigEndianInt ("VstW"));
if (status == kResultOk) status = writeVST2IntToState (8); // header size
if (status == kResultOk) status = writeVST2IntToState (1); // version
if (status == kResultOk) status = writeVST2IntToState (bypassed ? 1 : 0); // bypass
return status;
}
@ -2155,7 +2163,7 @@ public:
if (state == nullptr)
return kInvalidArgument;
juce::MemoryBlock mem;
MemoryBlock mem;
getStateInformation (mem);
#if JUCE_VST3_CAN_REPLACE_VST2
@ -2168,9 +2176,9 @@ public:
Vst2::fxBank bank;
zerostruct (bank);
bank.chunkMagic = (int32) htonl ('CcnK');
bank.chunkMagic = (int32) htonl (ByteOrder::bigEndianInt ("CcnK"));
bank.byteSize = (int32) htonl (bankBlockSize - 8 + (unsigned int) mem.getSize());
bank.fxMagic = (int32) htonl ('FBCh');
bank.fxMagic = (int32) htonl (ByteOrder::bigEndianInt ("FBCh"));
bank.version = (int32) htonl (2);
bank.fxID = (int32) htonl (JucePlugin_VSTUniqueID);
bank.fxVersion = (int32) htonl (JucePlugin_VersionCode);

View file

@ -39,6 +39,7 @@
#elif JUCE_LINUX
#include <float.h>
#include <sys/time.h>
#include <arpa/inet.h>
#elif JUCE_MAC || JUCE_IOS
#if ! (defined (JUCE_SUPPORT_CARBON) || defined (__LP64__))
#define JUCE_SUPPORT_CARBON 1

View file

@ -45,103 +45,104 @@ std::function<bool (AudioProcessor&)> PluginHostType::jucePlugInIsRunningInAudio
#define JUCE_VST3_CAN_REPLACE_VST2 1
#endif
#if JucePlugin_Build_VST3 && (__APPLE_CPP__ || __APPLE_CC__ || _WIN32 || _WIN64 || LINUX || __linux__) && JUCE_VST3_CAN_REPLACE_VST2
#define VST3_REPLACEMENT_AVAILABLE 1
#if JucePlugin_Build_VST3 && JUCE_VST3_CAN_REPLACE_VST2 && (JUCE_MAC || JUCE_WINDOWS || JUCE_LINUX)
#define VST3_REPLACEMENT_AVAILABLE 1
// NB: Nasty old-fashioned code in here because it's copied from the Steinberg example code.
void JUCE_API getUUIDForVST2ID (bool forControllerUID, uint8 uuid[16])
{
char uidString[33];
// NB: Nasty old-fashioned code in here because it's copied from the Steinberg example code.
void JUCE_API getUUIDForVST2ID (bool forControllerUID, uint8 uuid[16])
{
char uidString[33];
const int vstfxid = (('V' << 16) | ('S' << 8) | (forControllerUID ? 'E' : 'T'));
char vstfxidStr[7] = { 0 };
sprintf (vstfxidStr, "%06X", vstfxid);
const int vstfxid = (('V' << 16) | ('S' << 8) | (forControllerUID ? 'E' : 'T'));
char vstfxidStr[7] = { 0 };
sprintf (vstfxidStr, "%06X", vstfxid);
strcpy (uidString, vstfxidStr);
strcpy (uidString, vstfxidStr);
char uidStr[9] = { 0 };
sprintf (uidStr, "%08X", JucePlugin_VSTUniqueID);
strcat (uidString, uidStr);
char uidStr[9] = { 0 };
sprintf (uidStr, "%08X", JucePlugin_VSTUniqueID);
strcat (uidString, uidStr);
char nameidStr[3] = { 0 };
const size_t len = strlen (JucePlugin_Name);
char nameidStr[3] = { 0 };
const size_t len = strlen (JucePlugin_Name);
for (size_t i = 0; i <= 8; ++i)
{
juce::uint8 c = i < len ? static_cast<juce::uint8> (JucePlugin_Name[i]) : 0;
for (size_t i = 0; i <= 8; ++i)
{
juce::uint8 c = i < len ? static_cast<juce::uint8> (JucePlugin_Name[i]) : 0;
if (c >= 'A' && c <= 'Z')
c += 'a' - 'A';
if (c >= 'A' && c <= 'Z')
c += 'a' - 'A';
sprintf (nameidStr, "%02X", c);
strcat (uidString, nameidStr);
}
sprintf (nameidStr, "%02X", c);
strcat (uidString, nameidStr);
}
unsigned long p0;
unsigned int p1, p2;
unsigned int p3[8];
unsigned long p0;
unsigned int p1, p2;
unsigned int p3[8];
#ifndef _MSC_VER
sscanf
#else
sscanf_s
#endif
(uidString, "%08lX%04X%04X%02X%02X%02X%02X%02X%02X%02X%02X",
&p0, &p1, &p2, &p3[0], &p3[1], &p3[2], &p3[3], &p3[4], &p3[5], &p3[6], &p3[7]);
#if ! JUCE_MSVC
sscanf
#else
sscanf_s
#endif
(uidString, "%08lX%04X%04X%02X%02X%02X%02X%02X%02X%02X%02X",
&p0, &p1, &p2, &p3[0], &p3[1], &p3[2], &p3[3], &p3[4], &p3[5], &p3[6], &p3[7]);
union q0_u {
uint32 word;
uint8 bytes[4];
} q0;
union q0_u {
uint32 word;
uint8 bytes[4];
} q0;
union q1_u {
uint16 half;
uint8 bytes[2];
} q1, q2;
union q1_u {
uint16 half;
uint8 bytes[2];
} q1, q2;
q0.word = static_cast<uint32> (p0);
q1.half = static_cast<uint16> (p1);
q2.half = static_cast<uint16> (p2);
q0.word = static_cast<uint32> (p0);
q1.half = static_cast<uint16> (p1);
q2.half = static_cast<uint16> (p2);
// VST3 doesn't use COM compatible UUIDs on non windows platforms
#ifndef _WIN32
q0.word = ByteOrder::swap (q0.word);
q1.half = ByteOrder::swap (q1.half);
q2.half = ByteOrder::swap (q2.half);
#endif
// VST3 doesn't use COM compatible UUIDs on non windows platforms
#if ! JUCE_WINDOWS
q0.word = ByteOrder::swap (q0.word);
q1.half = ByteOrder::swap (q1.half);
q2.half = ByteOrder::swap (q2.half);
#endif
for (int i = 0; i < 4; ++i)
uuid[i+0] = q0.bytes[i];
for (int i = 0; i < 4; ++i)
uuid[i+0] = q0.bytes[i];
for (int i = 0; i < 2; ++i)
uuid[i+4] = q1.bytes[i];
for (int i = 0; i < 2; ++i)
uuid[i+4] = q1.bytes[i];
for (int i = 0; i < 2; ++i)
uuid[i+6] = q2.bytes[i];
for (int i = 0; i < 2; ++i)
uuid[i+6] = q2.bytes[i];
for (int i = 0; i < 8; ++i)
uuid[i+8] = static_cast<uint8> (p3[i]);
}
for (int i = 0; i < 8; ++i)
uuid[i+8] = static_cast<uint8> (p3[i]);
}
#else
#define VST3_REPLACEMENT_AVAILABLE 0
#define VST3_REPLACEMENT_AVAILABLE 0
#endif
#if JucePlugin_Build_VST
bool JUCE_API handleManufacturerSpecificVST2Opcode (int32 index, pointer_sized_int value, void* ptr, float)
{
#if VST3_REPLACEMENT_AVAILABLE
if ((index == 'stCA' || index == 'stCa') && value == 'FUID' && ptr != nullptr)
{
uint8 fuid[16];
getUUIDForVST2ID (false, fuid);
::memcpy (ptr, fuid, 16);
return true;
}
#else
ignoreUnused (index, value, ptr);
#endif
return false;
}
bool JUCE_API handleManufacturerSpecificVST2Opcode (int32 index, pointer_sized_int value, void* ptr, float)
{
#if VST3_REPLACEMENT_AVAILABLE
if ((index == (int32) ByteOrder::bigEndianInt ("stCA") || index == (int32) ByteOrder::bigEndianInt ("stCa"))
&& value == (int32) ByteOrder::bigEndianInt ("FUID") && ptr != nullptr)
{
uint8 fuid[16];
getUUIDForVST2ID (false, fuid);
::memcpy (ptr, fuid, 16);
return true;
}
#else
ignoreUnused (index, value, ptr);
#endif
return false;
}
#endif
} // namespace juce

View file

@ -26,13 +26,6 @@
namespace juce
{
//==============================================================================
#if JUCE_BIG_ENDIAN
#define JUCE_MULTICHAR_CONSTANT(a, b, c, d) (a | (((uint32) b) << 8) | (((uint32) c) << 16) | (((uint32) d) << 24))
#else
#define JUCE_MULTICHAR_CONSTANT(a, b, c, d) (d | (((uint32) c) << 8) | (((uint32) b) << 16) | (((uint32) a) << 24))
#endif
//==============================================================================
/** Structure for VST speaker mappings

View file

@ -2945,8 +2945,8 @@ public:
if (pluginRespondsToDPIChanges)
dispatch (Vst2::effVendorSpecific,
JUCE_MULTICHAR_CONSTANT ('P', 'r', 'e', 'S'),
JUCE_MULTICHAR_CONSTANT ('A', 'e', 'C', 's'),
(int) ByteOrder::bigEndianInt ("PreS"),
(int) ByteOrder::bigEndianInt ("AeCs"),
nullptr, nativeScaleFactor);
}
#endif