commit a66c635a43fa428c35db440860c909afe3b271d7
parent 0793c3dbd71bdd685a95e8a5bf048a0b45c58747
Author: falkTX <falktx@gmail.com>
Date: Sat, 9 May 2015 19:53:31 +0200
Check if bufsize or srate changed in vst2 resume
Diffstat:
2 files changed, 83 insertions(+), 5 deletions(-)
diff --git a/distrho/src/DistrhoPluginInternal.hpp b/distrho/src/DistrhoPluginInternal.hpp
@@ -406,9 +406,15 @@ public:
// -------------------------------------------------------------------
+ bool isActive() const noexcept
+ {
+ return fIsActive;
+ }
+
void activate()
{
DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
+ DISTRHO_SAFE_ASSERT_RETURN(! fIsActive,);
fIsActive = true;
fPlugin->activate();
@@ -417,11 +423,23 @@ public:
void deactivate()
{
DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
+ DISTRHO_SAFE_ASSERT_RETURN(fIsActive,);
fIsActive = false;
fPlugin->deactivate();
}
+ void deactivateIfNeeded()
+ {
+ DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
+
+ if (fIsActive)
+ {
+ fIsActive = false;
+ fPlugin->deactivate();
+ }
+ }
+
#if DISTRHO_PLUGIN_IS_SYNTH
void run(const float** const inputs, float** const outputs, const uint32_t frames,
const MidiEvent* const midiEvents, const uint32_t midiEventCount)
@@ -429,6 +447,12 @@ public:
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr,);
DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
+ if (! fIsActive)
+ {
+ fIsActive = true;
+ fPlugin->activate();
+ }
+
fData->isProcessing = true;
fPlugin->run(inputs, outputs, frames, midiEvents, midiEventCount);
fData->isProcessing = false;
@@ -439,6 +463,12 @@ public:
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr,);
DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
+ if (! fIsActive)
+ {
+ fIsActive = true;
+ fPlugin->activate();
+ }
+
fData->isProcessing = true;
fPlugin->run(inputs, outputs, frames);
fData->isProcessing = false;
diff --git a/distrho/src/DistrhoPluginVST.cpp b/distrho/src/DistrhoPluginVST.cpp
@@ -170,14 +170,18 @@ public:
// -------------------------------------------------------------------
protected:
- intptr_t hostCallback(const int32_t opcode, const int32_t index, const intptr_t value, void* const ptr, const float opt)
+ intptr_t hostCallback(const int32_t opcode,
+ const int32_t index = 0,
+ const intptr_t value = 0,
+ void* const ptr = nullptr,
+ const float opt = 0.0f)
{
return fAudioMaster(fEffect, opcode, index, value, ptr, opt);
}
void editParameter(const uint32_t index, const bool started)
{
- hostCallback(started ? audioMasterBeginEdit : audioMasterEndEdit, index, 0, nullptr, 0.0f);
+ hostCallback(started ? audioMasterBeginEdit : audioMasterEndEdit, index);
}
void setParameterValue(const uint32_t index, const float realValue)
@@ -215,7 +219,7 @@ protected:
void setSize(const uint width, const uint height)
{
fUI.setWindowSize(width, height);
- hostCallback(audioMasterSizeWindow, width, height, nullptr, 0.0f);
+ hostCallback(audioMasterSizeWindow, width, height);
}
private:
@@ -389,10 +393,27 @@ public:
case effMainsChanged:
if (value != 0)
{
- fPlugin.activate();
#if DISTRHO_PLUGIN_WANT_MIDI_INPUT
fMidiEventCount = 0;
+
+ // tell host we want MIDI events
+ hostCallback(audioMasterWantMidi);
#endif
+
+ // deactivate for possible changes
+ fPlugin.deactivateIfNeeded();
+
+ // check if something changed
+ const uint32_t bufferSize = static_cast<uint32_t>(hostCallback(audioMasterGetBlockSize));
+ const double sampleRate = static_cast<double>(hostCallback(audioMasterGetSampleRate));
+
+ if (bufferSize != 0)
+ fPlugin.setBufferSize(bufferSize, true);
+
+ if (sampleRate != 0.0)
+ fPlugin.setSampleRate(sampleRate, true);
+
+ fPlugin.activate();
}
else
{
@@ -552,6 +573,12 @@ public:
#if DISTRHO_PLUGIN_WANT_MIDI_INPUT
case effProcessEvents:
+ if (! fPlugin.isActive())
+ {
+ // host has not activated the plugin yet, nasty!
+ vst_dispatcher(effMainsChanged, 0, 1, nullptr, 0.0f);
+ }
+
if (const VstEvents* const events = (const VstEvents*)ptr)
{
if (events->numEvents == 0)
@@ -648,10 +675,19 @@ public:
void vst_processReplacing(const float** const inputs, float** const outputs, const int32_t sampleFrames)
{
+ if (sampleFrames <= 0)
+ return;
+
+ if (! fPlugin.isActive())
+ {
+ // host has not activated the plugin yet, nasty!
+ vst_dispatcher(effMainsChanged, 0, 1, nullptr, 0.0f);
+ }
+
#if DISTRHO_PLUGIN_WANT_TIMEPOS
static const int kWantVstTimeFlags(kVstTransportPlaying|kVstPpqPosValid|kVstTempoValid|kVstTimeSigValid);
- if (const VstTimeInfo* const vstTimeInfo = (const VstTimeInfo*)fAudioMaster(fEffect, audioMasterGetTime, 0, kWantVstTimeFlags, nullptr, 0.0f))
+ if (const VstTimeInfo* const vstTimeInfo = (const VstTimeInfo*)hostCallback(audioMasterGetTime, 0, kWantVstTimeFlags))
{
fTimePosition.frame = vstTimeInfo->samplePos;
fTimePosition.playing = (vstTimeInfo->flags & kVstTransportPlaying);
@@ -750,6 +786,18 @@ private:
#endif
// -------------------------------------------------------------------
+ // host callback
+
+ intptr_t hostCallback(const int32_t opcode,
+ const int32_t index = 0,
+ const intptr_t value = 0,
+ void* const ptr = nullptr,
+ const float opt = 0.0f)
+ {
+ return fAudioMaster(fEffect, opcode, index, value, ptr, opt);
+ }
+
+ // -------------------------------------------------------------------
// functions called from the plugin side, RT no block
#if DISTRHO_PLUGIN_HAS_UI