Consolidate plugin API to access parent insert

Previously this was special cased only for VST for callbacks
from the plugin (e.g. check pin connections), but it is generally
useful.
This commit is contained in:
Robin Gareus 2022-08-05 01:17:59 +02:00
parent 940c496f7b
commit c991016021
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
6 changed files with 24 additions and 16 deletions

View File

@ -24,6 +24,7 @@
#define __ardour_plugin_h__
#include <boost/shared_ptr.hpp>
#include <set>
#include <string>
@ -84,6 +85,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;
@ -412,6 +421,9 @@ private:
void invalidate_preset_cache (std::string const&, Plugin*, bool);
void resolve_midi ();
PluginInsert* _pi;
uint32_t _num;
};
struct PluginPreset {

View File

@ -28,6 +28,7 @@
#include <string>
#include <boost/weak_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include "pbd/stack_allocator.h"
#include "pbd/timing.h"
@ -57,7 +58,7 @@ class Plugin;
/** Plugin inserts: send data through a plugin
*/
class LIBARDOUR_API PluginInsert : public Processor, public PlugInsertBase
class LIBARDOUR_API PluginInsert : public Processor, public PlugInsertBase, public boost::enable_shared_from_this <PluginInsert>
{
public:
PluginInsert (Session&, Temporal::TimeDomain td, boost::shared_ptr<Plugin> = boost::shared_ptr<Plugin>());
@ -65,6 +66,10 @@ public:
void drop_references ();
boost::weak_ptr<PluginInsert> weak_ptr () {
return shared_from_this();
}
static const std::string port_automation_node_name;
int set_state(const XMLNode&, int version);

View File

@ -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;

View File

@ -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);

View File

@ -3127,12 +3127,8 @@ PluginInsert::add_plugin (boost::shared_ptr<Plugin> plugin)
}
}
}
#if (defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT || defined MACVST_SUPPORT)
boost::shared_ptr<VSTPlugin> vst = boost::dynamic_pointer_cast<VSTPlugin> (plugin);
if (vst) {
vst->set_insert (this, _plugins.size ());
}
#endif
plugin->set_insert (this, _plugins.size ());
_plugins.push_back (plugin);

View File

@ -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)