Skip to content

Commit de427bb

Browse files
DomClarkPhysSong
authored andcommitted
Suspend plugin when changing sample rate/buffer size
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.
1 parent 6f32c96 commit de427bb

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

plugins/vst_base/RemoteVstPlugin.cpp

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,28 @@ class RemoteVstPlugin : public RemotePluginClient
147147
// set given sample-rate for plugin
148148
virtual void updateSampleRate()
149149
{
150+
SuspendPlugin suspend( this );
150151
pluginDispatch( effSetSampleRate, 0, 0,
151152
NULL, (float) sampleRate() );
152153
}
153154

154155
// set given buffer-size for plugin
155156
virtual void updateBufferSize()
156157
{
158+
SuspendPlugin suspend( this );
157159
pluginDispatch( effSetBlockSize, 0, bufferSize() );
158160
}
159161

162+
void setResumed( bool resumed )
163+
{
164+
m_resumed = resumed;
165+
pluginDispatch( effMainsChanged, 0, resumed ? 1 : 0 );
166+
}
167+
168+
inline bool isResumed() const
169+
{
170+
return m_resumed;
171+
}
160172

161173
inline bool isInitialized() const
162174
{
@@ -309,6 +321,24 @@ class RemoteVstPlugin : public RemotePluginClient
309321
ClosePlugin
310322
} ;
311323

324+
struct SuspendPlugin {
325+
SuspendPlugin( RemoteVstPlugin * plugin ) :
326+
m_plugin( plugin ),
327+
m_resumed( plugin->isResumed() )
328+
{
329+
if( m_resumed ) { m_plugin->setResumed( false ); }
330+
}
331+
332+
~SuspendPlugin()
333+
{
334+
if( m_resumed ) { m_plugin->setResumed( true ); }
335+
}
336+
337+
private:
338+
RemoteVstPlugin * m_plugin;
339+
bool m_resumed;
340+
};
341+
312342
// callback used by plugin for being able to communicate with it's host
313343
static intptr_t hostCallback( AEffect * _effect, int32_t _opcode,
314344
int32_t _index, intptr_t _value,
@@ -339,6 +369,7 @@ class RemoteVstPlugin : public RemotePluginClient
339369
int m_windowHeight;
340370

341371
bool m_initialized;
372+
bool m_resumed;
342373

343374
bool m_processing;
344375

@@ -390,6 +421,7 @@ RemoteVstPlugin::RemoteVstPlugin( const char * socketPath ) :
390421
m_windowWidth( 0 ),
391422
m_windowHeight( 0 ),
392423
m_initialized( false ),
424+
m_resumed( false ),
393425
m_processing( false ),
394426
m_messageList(),
395427
m_shouldGiveIdle( false ),
@@ -470,7 +502,7 @@ RemoteVstPlugin::RemoteVstPlugin( const char * socketPath ) :
470502
RemoteVstPlugin::~RemoteVstPlugin()
471503
{
472504
destroyEditor();
473-
pluginDispatch( effMainsChanged, 0, 0 );
505+
setResumed( false );
474506
pluginDispatch( effClose );
475507
#ifndef USE_QT_SHMEM
476508
// detach shared memory segment
@@ -648,7 +680,7 @@ void RemoteVstPlugin::init( const std::string & _plugin_file )
648680
pluginDispatch( effSetProgram, 0, 0 ); */
649681
// request rate and blocksize
650682

651-
pluginDispatch( effMainsChanged, 0, 1 );
683+
setResumed( true );
652684

653685
debugMessage( "creating editor\n" );
654686
initEditor();

0 commit comments

Comments
 (0)