1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

VST Client: Query processor instead of relying on JucePlugin_IsMidiEffect

This commit is contained in:
reuk 2024-10-17 16:30:51 +01:00
parent 64823f2d37
commit 499abb7637
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C

View file

@ -375,9 +375,7 @@ public:
#endif #endif
} }
#if JUCE_DEBUG && ! (JucePlugin_ProducesMidiOutput || JucePlugin_IsMidiEffect) const auto numMidiEventsComingIn = midiEvents.getNumEvents();
const int numMidiEventsComingIn = midiEvents.getNumEvents();
#endif
{ {
const int numIn = processor->getTotalNumInputChannels(); const int numIn = processor->getTotalNumInputChannels();
@ -462,38 +460,41 @@ public:
if (! midiEvents.isEmpty()) if (! midiEvents.isEmpty())
{ {
#if JucePlugin_ProducesMidiOutput || JucePlugin_IsMidiEffect if (supportsMidiOut)
auto numEvents = midiEvents.getNumEvents();
outgoingEvents.ensureSize (numEvents);
outgoingEvents.clear();
for (const auto metadata : midiEvents)
{ {
jassert (metadata.samplePosition >= 0 && metadata.samplePosition < numSamples); auto numEvents = midiEvents.getNumEvents();
outgoingEvents.addEvent (metadata.data, metadata.numBytes, metadata.samplePosition); outgoingEvents.ensureSize (numEvents);
outgoingEvents.clear();
for (const auto metadata : midiEvents)
{
jassert (metadata.samplePosition >= 0 && metadata.samplePosition < numSamples);
outgoingEvents.addEvent (metadata.data, metadata.numBytes, metadata.samplePosition);
}
// Send VST events to the host.
NullCheckedInvocation::invoke (hostCallback, &vstEffect, Vst2::audioMasterProcessEvents, 0, 0, outgoingEvents.events, 0.0f);
} }
else
{
/* This assertion is caused when you've added some events to the
midiMessages array in your processBlock() method, which usually means
that you're trying to send them somewhere. But in this case they're
getting thrown away.
// Send VST events to the host. If your plugin does want to send midi messages, you'll need to set
NullCheckedInvocation::invoke (hostCallback, &vstEffect, Vst2::audioMasterProcessEvents, 0, 0, outgoingEvents.events, 0.0f); the JucePlugin_ProducesMidiOutput macro to 1 in your
#elif JUCE_DEBUG JucePluginCharacteristics.h file.
/* This assertion is caused when you've added some events to the
midiMessages array in your processBlock() method, which usually means
that you're trying to send them somewhere. But in this case they're
getting thrown away.
If your plugin does want to send midi messages, you'll need to set If you don't want to produce any midi output, then you should clear the
the JucePlugin_ProducesMidiOutput macro to 1 in your midiMessages array at the end of your processBlock() method, to
JucePluginCharacteristics.h file. indicate that you don't want any of the events to be passed through
to the output.
If you don't want to produce any midi output, then you should clear the */
midiMessages array at the end of your processBlock() method, to jassertquiet (midiEvents.getNumEvents() <= numMidiEventsComingIn);
indicate that you don't want any of the events to be passed through }
to the output.
*/
jassert (midiEvents.getNumEvents() <= numMidiEventsComingIn);
#endif
midiEvents.clear(); midiEvents.clear();
} }
@ -553,7 +554,7 @@ public:
host that we want midi. In the SDK this method is marked as deprecated, but host that we want midi. In the SDK this method is marked as deprecated, but
some hosts rely on this behaviour. some hosts rely on this behaviour.
*/ */
if (vstEffect.flags & Vst2::effFlagsIsSynth || JucePlugin_WantsMidiInput || JucePlugin_IsMidiEffect) if (vstEffect.flags & Vst2::effFlagsIsSynth || supportsMidiIn)
NullCheckedInvocation::invoke (hostCallback, &vstEffect, Vst2::audioMasterWantMidi, 0, 1, nullptr, 0.0f); NullCheckedInvocation::invoke (hostCallback, &vstEffect, Vst2::audioMasterWantMidi, 0, 1, nullptr, 0.0f);
if (detail::PluginUtilities::getHostType().isAbletonLive() if (detail::PluginUtilities::getHostType().isAbletonLive()
@ -570,9 +571,8 @@ public:
hostCallback (&vstEffect, Vst2::audioMasterVendorSpecific, 0, 0, &hostCmd, 0.0f); hostCallback (&vstEffect, Vst2::audioMasterVendorSpecific, 0, 0, &hostCmd, 0.0f);
} }
#if JucePlugin_ProducesMidiOutput || JucePlugin_IsMidiEffect if (supportsMidiOut)
outgoingEvents.ensureSize (512); outgoingEvents.ensureSize (512);
#endif
} }
} }
@ -1680,12 +1680,13 @@ private:
pointer_sized_int handlePreAudioProcessingEvents ([[maybe_unused]] VstOpCodeArguments args) pointer_sized_int handlePreAudioProcessingEvents ([[maybe_unused]] VstOpCodeArguments args)
{ {
#if JucePlugin_WantsMidiInput || JucePlugin_IsMidiEffect if (supportsMidiIn)
VSTMidiEventList::addEventsToMidiBuffer ((Vst2::VstEvents*) args.ptr, midiEvents); {
return 1; VSTMidiEventList::addEventsToMidiBuffer ((Vst2::VstEvents*) args.ptr, midiEvents);
#else return 1;
}
return 0; return 0;
#endif
} }
pointer_sized_int handleIsParameterAutomatable (VstOpCodeArguments args) pointer_sized_int handleIsParameterAutomatable (VstOpCodeArguments args)
@ -1841,22 +1842,14 @@ private:
|| matches ("receiveVstMidiEvent") || matches ("receiveVstMidiEvent")
|| matches ("receiveVstMidiEvents")) || matches ("receiveVstMidiEvents"))
{ {
#if JucePlugin_WantsMidiInput || JucePlugin_IsMidiEffect return supportsMidiIn ? 1 : -1;
return 1;
#else
return -1;
#endif
} }
if (matches ("sendVstEvents") if (matches ("sendVstEvents")
|| matches ("sendVstMidiEvent") || matches ("sendVstMidiEvent")
|| matches ("sendVstMidiEvents")) || matches ("sendVstMidiEvents"))
{ {
#if JucePlugin_ProducesMidiOutput || JucePlugin_IsMidiEffect return supportsMidiOut ? 1 : -1;
return 1;
#else
return -1;
#endif
} }
if (matches ("receiveVstTimeInfo") if (matches ("receiveVstTimeInfo")
@ -2023,28 +2016,30 @@ private:
//============================================================================== //==============================================================================
pointer_sized_int handleGetNumMidiInputChannels() pointer_sized_int handleGetNumMidiInputChannels()
{ {
#if JucePlugin_WantsMidiInput || JucePlugin_IsMidiEffect if (supportsMidiIn)
#ifdef JucePlugin_VSTNumMidiInputs {
return JucePlugin_VSTNumMidiInputs; #ifdef JucePlugin_VSTNumMidiInputs
#else return JucePlugin_VSTNumMidiInputs;
return 16; #else
#endif return 16;
#else #endif
}
return 0; return 0;
#endif
} }
pointer_sized_int handleGetNumMidiOutputChannels() pointer_sized_int handleGetNumMidiOutputChannels()
{ {
#if JucePlugin_ProducesMidiOutput || JucePlugin_IsMidiEffect if (supportsMidiOut)
#ifdef JucePlugin_VSTNumMidiOutputs {
return JucePlugin_VSTNumMidiOutputs; #ifdef JucePlugin_VSTNumMidiOutputs
#else return JucePlugin_VSTNumMidiOutputs;
return 16; #else
#endif return 16;
#else #endif
}
return 0; return 0;
#endif
} }
pointer_sized_int handleEditIdle() pointer_sized_int handleEditIdle()
@ -2083,6 +2078,8 @@ private:
bool isProcessing = false, isBypassed = false, hasShutdown = false; bool isProcessing = false, isBypassed = false, hasShutdown = false;
bool firstProcessCallback = true, shouldDeleteEditor = false; bool firstProcessCallback = true, shouldDeleteEditor = false;
const bool supportsMidiIn = processor->isMidiEffect() || processor->acceptsMidi();
const bool supportsMidiOut = processor->isMidiEffect() || processor->producesMidi();
VstTempBuffers<float> floatTempBuffers; VstTempBuffers<float> floatTempBuffers;
VstTempBuffers<double> doubleTempBuffers; VstTempBuffers<double> doubleTempBuffers;