Skip to content

Commit

Permalink
Added a handleVstHostCallbackAvailable method to the VSTCallbackHandl…
Browse files Browse the repository at this point in the history
…er interface
  • Loading branch information
tpoole committed Aug 6, 2018
1 parent 2f5cd88 commit 1d56cfe
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 45 deletions.
17 changes: 16 additions & 1 deletion modules/juce_audio_plugin_client/VST/juce_VSTCallbackHandler.h
Expand Up @@ -27,7 +27,7 @@
namespace juce
{

/** An interface to allow an AudioProcessor to receive VST specific calls from
/** An interface to allow an AudioProcessor to send and receive VST specific calls from
the host.
@tags{Audio}
Expand Down Expand Up @@ -55,6 +55,21 @@ struct VSTCallbackHandler
pointer_sized_int value,
void* ptr,
float opt) = 0;

/** The host callback function type. */
using VstHostCallbackType = pointer_sized_int (int32 opcode,
int32 index,
pointer_sized_int value,
void* ptr,
float opt);

/** This is called once by the VST plug-in wrapper after its constructor.
You can use the supplied function to query the VST host.
*/
virtual void handleVstHostCallbackAvailable (std::function<VstHostCallbackType>&& callback)
{
ignoreUnused (callback);
}
};

} // namespace juce
99 changes: 55 additions & 44 deletions modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp
Expand Up @@ -647,10 +647,10 @@ class JuceVSTWrapper : public AudioProcessorListener,

if (hostCallback != nullptr)
{
int32 flags = Vst2::kVstPpqPosValid | Vst2::kVstTempoValid
| Vst2::kVstBarsValid | Vst2::kVstCyclePosValid
| Vst2::kVstTimeSigValid | Vst2::kVstSmpteValid
| Vst2::kVstClockValid;
int32 flags = Vst2::kVstPpqPosValid | Vst2::kVstTempoValid
| Vst2::kVstBarsValid | Vst2::kVstCyclePosValid
| Vst2::kVstTimeSigValid | Vst2::kVstSmpteValid
| Vst2::kVstClockValid;

auto result = hostCallback (&vstEffect, Vst2::audioMasterGetTime, 0, flags, 0, 0);
ti = reinterpret_cast<Vst2::VstTimeInfo*> (result);
Expand Down Expand Up @@ -1493,38 +1493,6 @@ class JuceVSTWrapper : public AudioProcessorListener,

//==============================================================================
private:
Vst2::audioMasterCallback hostCallback;
AudioProcessor* processor = {};
double sampleRate = 44100.0;
int32 blockSize = 1024;
Vst2::AEffect vstEffect;
juce::MemoryBlock chunkMemory;
juce::uint32 chunkMemoryTime = 0;
std::unique_ptr<EditorCompWrapper> editorComp;
Vst2::ERect editorBounds;
MidiBuffer midiEvents;
VSTMidiEventList outgoingEvents;
float editorScaleFactor = 1.0f;

LegacyAudioParametersWrapper juceParameters;

bool isProcessing = false, isBypassed = false, hasShutdown = false;
bool firstProcessCallback = true, shouldDeleteEditor = false;

#if JUCE_64BIT
bool useNSView = true;
#else
bool useNSView = false;
#endif

VstTempBuffers<float> floatTempBuffers;
VstTempBuffers<double> doubleTempBuffers;
int maxNumInChannels = 0, maxNumOutChannels = 0;

HeapBlock<Vst2::VstSpeakerArrangement> cachedInArrangement, cachedOutArrangement;

ThreadLocalValue<bool> inParameterChangedCallback;

static JuceVSTWrapper* getWrapper (Vst2::AEffect* v) noexcept { return static_cast<JuceVSTWrapper*> (v->object); }

bool isProcessLevelOffline()
Expand Down Expand Up @@ -2009,8 +1977,8 @@ class JuceVSTWrapper : public AudioProcessorListener,
auto matches = [=](const char* s) { return strcmp (text, s) == 0; };

if (matches ("receiveVstEvents")
|| matches ("receiveVstMidiEvent")
|| matches ("receiveVstMidiEvents"))
|| matches ("receiveVstMidiEvent")
|| matches ("receiveVstMidiEvents"))
{
#if JucePlugin_WantsMidiInput || JucePlugin_IsMidiEffect
return 1;
Expand All @@ -2020,8 +1988,8 @@ class JuceVSTWrapper : public AudioProcessorListener,
}

if (matches ("sendVstEvents")
|| matches ("sendVstMidiEvent")
|| matches ("sendVstMidiEvents"))
|| matches ("sendVstMidiEvent")
|| matches ("sendVstMidiEvents"))
{
#if JucePlugin_ProducesMidiOutput || JucePlugin_IsMidiEffect
return 1;
Expand All @@ -2031,9 +1999,9 @@ class JuceVSTWrapper : public AudioProcessorListener,
}

if (matches ("receiveVstTimeInfo")
|| matches ("conformsToWindowRules")
|| matches ("supportsViewDpiScaling")
|| matches ("bypass"))
|| matches ("conformsToWindowRules")
|| matches ("supportsViewDpiScaling")
|| matches ("bypass"))
{
return 1;
}
Expand Down Expand Up @@ -2205,6 +2173,39 @@ class JuceVSTWrapper : public AudioProcessorListener,
#endif
}

//==============================================================================
Vst2::audioMasterCallback hostCallback;
AudioProcessor* processor = {};
double sampleRate = 44100.0;
int32 blockSize = 1024;
Vst2::AEffect vstEffect;
juce::MemoryBlock chunkMemory;
juce::uint32 chunkMemoryTime = 0;
std::unique_ptr<EditorCompWrapper> editorComp;
Vst2::ERect editorBounds;
MidiBuffer midiEvents;
VSTMidiEventList outgoingEvents;
float editorScaleFactor = 1.0f;

LegacyAudioParametersWrapper juceParameters;

bool isProcessing = false, isBypassed = false, hasShutdown = false;
bool firstProcessCallback = true, shouldDeleteEditor = false;

#if JUCE_64BIT
bool useNSView = true;
#else
bool useNSView = false;
#endif

VstTempBuffers<float> floatTempBuffers;
VstTempBuffers<double> doubleTempBuffers;
int maxNumInChannels = 0, maxNumOutChannels = 0;

HeapBlock<Vst2::VstSpeakerArrangement> cachedInArrangement, cachedOutArrangement;

ThreadLocalValue<bool> inParameterChangedCallback;

//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (JuceVSTWrapper)
};
Expand All @@ -2229,7 +2230,17 @@ namespace

auto* processor = createPluginFilterOfType (AudioProcessor::wrapperType_VST);
auto* wrapper = new JuceVSTWrapper (audioMaster, processor);
return wrapper->getAEffect();
auto* aEffect = wrapper->getAEffect();

if (auto* callbackHandler = dynamic_cast<VSTCallbackHandler*> (processor))
{
callbackHandler->handleVstHostCallbackAvailable ([audioMaster, aEffect](int32 opcode, int32 index, pointer_sized_int value, void* ptr, float opt)
{
return audioMaster (aEffect, opcode, index, value, ptr, opt);
});
}

return aEffect;
}
}
catch (...)
Expand Down

0 comments on commit 1d56cfe

Please sign in to comment.