diff --git a/libs/ardour/ardour/plugin.h b/libs/ardour/ardour/plugin.h index 7a538c7244..48672d4c0f 100644 --- a/libs/ardour/ardour/plugin.h +++ b/libs/ardour/ardour/plugin.h @@ -24,6 +24,7 @@ #define __ardour_plugin_h__ #include + #include #include @@ -83,6 +84,14 @@ public: virtual void set_insert_id (PBD::ID id) {} virtual void set_state_dir (const std::string& d = "") {} + void set_insert (PluginInsert* pi, uint32_t num) { + _pi = pi; + _num = num; + } + + PluginInsert* plugin_insert () const { return _pi; } + uint32_t plugin_number () const { return _num; } + virtual std::string unique_id () const = 0; virtual const char* label () const = 0; virtual const char* name () const = 0; @@ -410,6 +419,9 @@ private: void invalidate_preset_cache (std::string const&, Plugin*, bool); void resolve_midi (); + + PluginInsert* _pi; + uint32_t _num; }; struct PluginPreset { diff --git a/libs/ardour/ardour/plugin_insert.h b/libs/ardour/ardour/plugin_insert.h index f3ebf5bde0..bb9f0de6a3 100644 --- a/libs/ardour/ardour/plugin_insert.h +++ b/libs/ardour/ardour/plugin_insert.h @@ -28,6 +28,7 @@ #include #include +#include #include "pbd/stack_allocator.h" #include "pbd/timing.h" @@ -56,7 +57,7 @@ class Plugin; /** Plugin inserts: send data through a plugin */ -class LIBARDOUR_API PluginInsert : public Processor +class LIBARDOUR_API PluginInsert : public Processor, public boost::enable_shared_from_this { public: PluginInsert (Session&, Temporal::TimeDomain td, boost::shared_ptr = boost::shared_ptr()); @@ -64,6 +65,10 @@ public: void drop_references (); + boost::weak_ptr weak_ptr () { + return shared_from_this(); + } + static const std::string port_automation_node_name; int set_state(const XMLNode&, int version); diff --git a/libs/ardour/ardour/vst_plugin.h b/libs/ardour/ardour/vst_plugin.h index 353c71b1fe..6b71d23131 100644 --- a/libs/ardour/ardour/vst_plugin.h +++ b/libs/ardour/ardour/vst_plugin.h @@ -98,9 +98,6 @@ public: int first_user_preset_index () const; - void set_insert (PluginInsert* pi, uint32_t num) { _pi = pi; _num = num; } - PluginInsert* plugin_insert () const { return _pi; } - uint32_t plugin_number () const { return _num; } VstTimeInfo* timeinfo () { return &_timeInfo; } samplepos_t transport_sample () const { return _transport_sample; } float transport_speed () const { return _transport_speed; } @@ -125,8 +122,6 @@ protected: VSTHandle* _handle; VSTState* _state; AEffect* _plugin; - PluginInsert* _pi; - uint32_t _num; MidiBuffer* _midi_out_buf; VstTimeInfo _timeInfo; diff --git a/libs/ardour/plugin.cc b/libs/ardour/plugin.cc index b5f7f59284..7cba593f8e 100644 --- a/libs/ardour/plugin.cc +++ b/libs/ardour/plugin.cc @@ -95,6 +95,8 @@ Plugin::Plugin (AudioEngine& e, Session& s) , _have_pending_stop_events (false) , _parameter_changed_since_last_preset (false) , _immediate_events(6096) // FIXME: size? + , _pi (0) + , _num (0) { _pending_stop_events.ensure_buffers (DataType::MIDI, 1, 4096); PresetsChanged.connect_same_thread(_preset_connection, boost::bind (&Plugin::invalidate_preset_cache, this, _1, _2, _3)); @@ -114,6 +116,8 @@ Plugin::Plugin (const Plugin& other) , _last_preset (other._last_preset) , _parameter_changed_since_last_preset (false) , _immediate_events(6096) // FIXME: size? + , _pi (other._pi) + , _num (other._num) { _pending_stop_events.ensure_buffers (DataType::MIDI, 1, 4096); diff --git a/libs/ardour/plugin_insert.cc b/libs/ardour/plugin_insert.cc index 5ef332b606..79995fc8cc 100644 --- a/libs/ardour/plugin_insert.cc +++ b/libs/ardour/plugin_insert.cc @@ -3243,12 +3243,8 @@ PluginInsert::add_plugin (boost::shared_ptr plugin) } } } -#if (defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT || defined MACVST_SUPPORT) - boost::shared_ptr vst = boost::dynamic_pointer_cast (plugin); - if (vst) { - vst->set_insert (this, _plugins.size ()); - } -#endif + + plugin->set_insert (this, _plugins.size ()); _plugins.push_back (plugin); diff --git a/libs/ardour/vst_plugin.cc b/libs/ardour/vst_plugin.cc index 845ee9d555..c9aa5b1807 100644 --- a/libs/ardour/vst_plugin.cc +++ b/libs/ardour/vst_plugin.cc @@ -52,8 +52,6 @@ VSTPlugin::VSTPlugin (AudioEngine& engine, Session& session, VSTHandle* handle) , _handle (handle) , _state (0) , _plugin (0) - , _pi (0) - , _num (0) , _transport_sample (0) , _transport_speed (0.f) , _eff_bypassed (false) @@ -66,8 +64,6 @@ VSTPlugin::VSTPlugin (const VSTPlugin& other) , _handle (other._handle) , _state (other._state) , _plugin (other._plugin) - , _pi (other._pi) - , _num (other._num) , _midi_out_buf (other._midi_out_buf) , _transport_sample (0) , _transport_speed (0.f)