Rework VST initialization:

Set the AEffect* plugin pointer before calling effOpen.
effOpen may call back into the host (masterCallback) and invoke
actions which depend on _plugin (eg. to call back into the plugin again)
This commit is contained in:
Robin Gareus
2017-03-06 23:49:40 +01:00
parent 589c13c0eb
commit e1095310a8
9 changed files with 66 additions and 36 deletions

View File

@@ -38,6 +38,8 @@ public:
~MacVSTPlugin ();
std::string state_node_name () const { return "mac-vst"; }
protected:
void open_plugin ();
};
class LIBARDOUR_API MacVSTPluginInfo : public PluginInfo

View File

@@ -103,7 +103,8 @@ public:
protected:
void parameter_changed_externally (uint32_t which, float val);
void set_plugin (AEffect *);
virtual void open_plugin ();
void init_plugin ();
gchar* get_chunk (bool) const;
int set_chunk (gchar const *, bool);
void add_state (XMLNode *) const;

View File

@@ -306,14 +306,16 @@ vstfx_instantiate (VSTHandle* fhandle, audioMasterCallback amc, void* userptr)
return 0;
}
vstfx->plugin->dispatcher (vstfx->plugin, effOpen, 0, 0, 0, 0);
/*May or May not need to 'switch the plugin on' here - unlikely
since FST doesn't and most plugins start up 'On' by default - I think this is the least of our worries*/
//vstfx->plugin->dispatcher (vstfx->plugin, effMainsChanged, 0, 1, 0, 0);
vstfx->vst_version = vstfx->plugin->dispatcher (vstfx->plugin, effGetVstVersion, 0, 0, 0, 0);
if (!userptr) {
/* scanning.. or w/o master-callback userptr == 0, open now.
*
* Session::vst_callback needs a pointer to the AEffect
* ((VSTPlugin*)userptr)->_plugin = vstfx->plugin
* before calling effOpen, because effOpen may call back
*/
vstfx->plugin->dispatcher (vstfx->plugin, effOpen, 0, 0, 0, 0);
vstfx->vst_version = vstfx->plugin->dispatcher (vstfx->plugin, effGetVstVersion, 0, 0, 0, 0);
}
vstfx->handle->plugincnt++;
vstfx->wantIdle = 0;

View File

@@ -40,9 +40,10 @@ LXVSTPlugin::LXVSTPlugin (AudioEngine& e, Session& session, VSTHandle* h, int un
if ((_state = vstfx_instantiate (_handle, Session::vst_callback, this)) == 0) {
throw failed_constructor();
}
open_plugin ();
Session::vst_current_loading_id = 0;
set_plugin (_state->plugin);
init_plugin ();
}
LXVSTPlugin::LXVSTPlugin (const LXVSTPlugin &other)
@@ -54,17 +55,16 @@ LXVSTPlugin::LXVSTPlugin (const LXVSTPlugin &other)
if ((_state = vstfx_instantiate (_handle, Session::vst_callback, this)) == 0) {
throw failed_constructor();
}
open_plugin ();
Session::vst_current_loading_id = 0;
_plugin = _state->plugin;
XMLNode* root = new XMLNode (other.state_node_name ());
LocaleGuard lg;
other.add_state (root);
set_state (*root, Stateful::loading_state_version);
delete root;
set_plugin (_state->plugin);
init_plugin ();
}
LXVSTPlugin::~LXVSTPlugin ()
@@ -120,6 +120,7 @@ LXVSTPluginInfo::get_presets (bool user_only) const
Session::vst_current_loading_id = atoi (unique_id);
AEffect* plugin = handle->main_entry (Session::vst_callback);
Session::vst_current_loading_id = 0;
plugin->user = NULL;
plugin->dispatcher (plugin, effOpen, 0, 0, 0, 0); // :(
int const vst_version = plugin->dispatcher (plugin, effGetVstVersion, 0, 0, NULL, 0);

View File

@@ -40,9 +40,10 @@ MacVSTPlugin::MacVSTPlugin (AudioEngine& e, Session& session, VSTHandle* h, int
if ((_state = mac_vst_instantiate (_handle, Session::vst_callback, this)) == 0) {
throw failed_constructor ();
}
open_plugin ();
Session::vst_current_loading_id = 0;
set_plugin (_state->plugin);
init_plugin ();
}
MacVSTPlugin::MacVSTPlugin (const MacVSTPlugin &other)
@@ -54,17 +55,16 @@ MacVSTPlugin::MacVSTPlugin (const MacVSTPlugin &other)
if ((_state = mac_vst_instantiate (_handle, Session::vst_callback, this)) == 0) {
throw failed_constructor ();
}
open_plugin ();
Session::vst_current_loading_id = 0;
_plugin = _state->plugin;
XMLNode* root = new XMLNode (other.state_node_name ());
LocaleGuard lg;
other.add_state (root);
set_state (*root, Stateful::loading_state_version);
delete root;
set_plugin (_state->plugin);
init_plugin ();
}
MacVSTPlugin::~MacVSTPlugin ()
@@ -72,6 +72,13 @@ MacVSTPlugin::~MacVSTPlugin ()
mac_vst_close (_state);
}
void
MacVSTPlugin::open_plugin ()
{
VSTPlugin::open_plugin ();
_plugin->dispatcher (mac_vst->plugin, effCanDo, 0, 0, const_cast<char*> ("hasCockosViewAsConfig"), 0.0f);
}
PluginPtr
MacVSTPluginInfo::load (Session& session)
{
@@ -120,6 +127,7 @@ MacVSTPluginInfo::get_presets (bool user_only) const
Session::vst_current_loading_id = atoi (unique_id);
AEffect* plugin = handle->main_entry (Session::vst_callback);
Session::vst_current_loading_id = 0;
plugin->user = NULL;
plugin->dispatcher (plugin, effOpen, 0, 0, 0, 0); // :(
int const vst_version = plugin->dispatcher (plugin, effGetVstVersion, 0, 0, NULL, 0);

View File

@@ -203,17 +203,19 @@ mac_vst_instantiate (VSTHandle* fhandle, audioMasterCallback amc, void* userptr)
return 0;
}
mac_vst->plugin->dispatcher (mac_vst->plugin, effOpen, 0, 0, 0, 0);
if (!userptr) {
/* scanning.. or w/o master-callback userptr == 0, open now.
*
* Session::vst_callback needs a pointer to the AEffect
* ((VSTPlugin*)userptr)->_plugin = vstfx->plugin
* before calling effOpen, because effOpen may call back
*/
mac_vst->plugin->dispatcher (mac_vst->plugin, effOpen, 0, 0, 0, 0);
mac_vst->vst_version = mac_vst->plugin->dispatcher (mac_vst->plugin, effGetVstVersion, 0, 0, 0, 0);
/*May or May not need to 'switch the plugin on' here - unlikely
since FST doesn't and most plugins start up 'On' by default - I think this is the least of our worries*/
//mac_vst->plugin->dispatcher (mac_vst->plugin, effMainsChanged, 0, 1, 0, 0);
/* configure plugin to use Cocoa View */
mac_vst->plugin->dispatcher (mac_vst->plugin, effCanDo, 0, 0, const_cast<char*> ("hasCockosViewAsConfig"), 0.0f);
mac_vst->vst_version = mac_vst->plugin->dispatcher (mac_vst->plugin, effGetVstVersion, 0, 0, 0, 0);
/* configure plugin to use Cocoa View */
mac_vst->plugin->dispatcher (mac_vst->plugin, effCanDo, 0, 0, const_cast<char*> ("hasCockosViewAsConfig"), 0.0f);
}
mac_vst->handle->plugincnt++;
mac_vst->wantIdle = 0;

View File

@@ -76,13 +76,19 @@ VSTPlugin::~VSTPlugin ()
}
void
VSTPlugin::set_plugin (AEffect* e)
VSTPlugin::open_plugin ()
{
_plugin = e;
_plugin = _state->plugin;
assert (_plugin->user == this); // should have been set by {mac_vst|fst|lxvst}_instantiate
_plugin->user = this;
_state->plugin->dispatcher (_plugin, effOpen, 0, 0, 0, 0);
_state->vst_version = _plugin->dispatcher (_plugin, effGetVstVersion, 0, 0, 0, 0);
}
void
VSTPlugin::init_plugin ()
{
/* set rate and blocksize */
_plugin->dispatcher (_plugin, effSetSampleRate, 0, 0, NULL, (float) _session.frame_rate());
_plugin->dispatcher (_plugin, effSetBlockSize, 0, _session.get_block_size(), NULL, 0.0f);
}

View File

@@ -39,9 +39,10 @@ WindowsVSTPlugin::WindowsVSTPlugin (AudioEngine& e, Session& session, VSTHandle*
if ((_state = fst_instantiate (_handle, Session::vst_callback, this)) == 0) {
throw failed_constructor();
}
open_plugin ();
Session::vst_current_loading_id = 0;
set_plugin (_state->plugin);
init_plugin ();
}
WindowsVSTPlugin::WindowsVSTPlugin (const WindowsVSTPlugin &other)
@@ -53,17 +54,16 @@ WindowsVSTPlugin::WindowsVSTPlugin (const WindowsVSTPlugin &other)
if ((_state = fst_instantiate (_handle, Session::vst_callback, this)) == 0) {
throw failed_constructor();
}
open_plugin ();
Session::vst_current_loading_id = 0;
_plugin = _state->plugin;
XMLNode* root = new XMLNode (other.state_node_name ());
LocaleGuard lg;
other.add_state (root);
set_state (*root, Stateful::loading_state_version);
delete root;
set_plugin (_state->plugin);
init_plugin ();
}
WindowsVSTPlugin::~WindowsVSTPlugin ()

View File

@@ -550,8 +550,16 @@ fst_instantiate (VSTHandle* fhandle, audioMasterCallback amc, void* userptr)
return NULL;
}
fst->plugin->dispatcher (fst->plugin, effOpen, 0, 0, 0, 0);
fst->vst_version = fst->plugin->dispatcher (fst->plugin, effGetVstVersion, 0, 0, 0, 0);
if (!userptr) {
/* scanning.. or w/o master-callback userptr == 0, open now.
*
* Session::vst_callback needs a pointer to the AEffect
* ((VSTPlugin*)userptr)->_plugin = vstfx->plugin
* before calling effOpen, because effOpen may call back
*/
fst->plugin->dispatcher (fst->plugin, effOpen, 0, 0, 0, 0);
fst->vst_version = fst->plugin->dispatcher (fst->plugin, effGetVstVersion, 0, 0, 0, 0);
}
fst->handle->plugincnt++;
fst->wantIdle = 0;