Skip to content

Commit

Permalink
Suspend plugin when changing sample rate/buffer size
Browse files Browse the repository at this point in the history
Some plugins ignore updates to these values if they're changed while the plugin is in a "resumed" state, resulting in incorrect tuning after a change of sample rate.
  • Loading branch information
DomClark authored and PhysSong committed Sep 11, 2018
1 parent 6f32c96 commit de427bb
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions plugins/vst_base/RemoteVstPlugin.cpp
Expand Up @@ -147,16 +147,28 @@ class RemoteVstPlugin : public RemotePluginClient
// set given sample-rate for plugin
virtual void updateSampleRate()
{
SuspendPlugin suspend( this );
pluginDispatch( effSetSampleRate, 0, 0,
NULL, (float) sampleRate() );
}

// set given buffer-size for plugin
virtual void updateBufferSize()
{
SuspendPlugin suspend( this );
pluginDispatch( effSetBlockSize, 0, bufferSize() );
}

void setResumed( bool resumed )
{
m_resumed = resumed;
pluginDispatch( effMainsChanged, 0, resumed ? 1 : 0 );
}

inline bool isResumed() const
{
return m_resumed;
}

inline bool isInitialized() const
{
Expand Down Expand Up @@ -309,6 +321,24 @@ class RemoteVstPlugin : public RemotePluginClient
ClosePlugin
} ;

struct SuspendPlugin {
SuspendPlugin( RemoteVstPlugin * plugin ) :
m_plugin( plugin ),
m_resumed( plugin->isResumed() )
{
if( m_resumed ) { m_plugin->setResumed( false ); }
}

~SuspendPlugin()
{
if( m_resumed ) { m_plugin->setResumed( true ); }
}

private:
RemoteVstPlugin * m_plugin;
bool m_resumed;
};

// callback used by plugin for being able to communicate with it's host
static intptr_t hostCallback( AEffect * _effect, int32_t _opcode,
int32_t _index, intptr_t _value,
Expand Down Expand Up @@ -339,6 +369,7 @@ class RemoteVstPlugin : public RemotePluginClient
int m_windowHeight;

bool m_initialized;
bool m_resumed;

bool m_processing;

Expand Down Expand Up @@ -390,6 +421,7 @@ RemoteVstPlugin::RemoteVstPlugin( const char * socketPath ) :
m_windowWidth( 0 ),
m_windowHeight( 0 ),
m_initialized( false ),
m_resumed( false ),
m_processing( false ),
m_messageList(),
m_shouldGiveIdle( false ),
Expand Down Expand Up @@ -470,7 +502,7 @@ RemoteVstPlugin::RemoteVstPlugin( const char * socketPath ) :
RemoteVstPlugin::~RemoteVstPlugin()
{
destroyEditor();
pluginDispatch( effMainsChanged, 0, 0 );
setResumed( false );
pluginDispatch( effClose );
#ifndef USE_QT_SHMEM
// detach shared memory segment
Expand Down Expand Up @@ -648,7 +680,7 @@ void RemoteVstPlugin::init( const std::string & _plugin_file )
pluginDispatch( effSetProgram, 0, 0 ); */
// request rate and blocksize

pluginDispatch( effMainsChanged, 0, 1 );
setResumed( true );

debugMessage( "creating editor\n" );
initEditor();
Expand Down

0 comments on commit de427bb

Please sign in to comment.