X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Finsert.cc;h=1c3ce510f31d243a5136ffe32e3482013980e65f;hb=9bc22f6f86deb4258faf298b45cb117f09af8f96;hp=fc05355d4ae821ec39fc4f13cbef4bb0b9996e7d;hpb=7ff370e79895d7eb293e7214689b791bd98415fb;p=ardour.git diff --git a/libs/ardour/insert.cc b/libs/ardour/insert.cc index fc05355d4a..1c3ce510f3 100644 --- a/libs/ardour/insert.cc +++ b/libs/ardour/insert.cc @@ -30,9 +30,18 @@ #include #include #include + +#ifdef VST_SUPPORT #include +#endif + +#ifdef HAVE_AUDIOUNITS +#include +#endif + #include #include +#include #include "i18n.h" @@ -45,7 +54,6 @@ Insert::Insert(Session& s, Placement p) { } - Insert::Insert(Session& s, Placement p, int imin, int imax, int omin, int omax) : Redirect (s, s.next_insert_name(), p, imin, imax, omin, omax) { @@ -62,12 +70,12 @@ Insert::Insert(Session& s, string name, Placement p) const string PluginInsert::port_automation_node_name = "PortAutomation"; -PluginInsert::PluginInsert (Session& s, Plugin& plug, Placement placement) - : Insert (s, plug.name(), placement) +PluginInsert::PluginInsert (Session& s, boost::shared_ptr plug, Placement placement) + : Insert (s, plug->name(), placement) { /* the first is the master */ - _plugins.push_back(&plug); + _plugins.push_back (plug); _plugins[0]->ParameterChanged.connect (mem_fun (*this, &PluginInsert::parameter_changed)); @@ -103,13 +111,13 @@ PluginInsert::PluginInsert (Session& s, const XMLNode& node) } PluginInsert::PluginInsert (const PluginInsert& other) - : Insert (other._session, other.plugin().name(), other.placement()) + : Insert (other._session, other.plugin()->name(), other.placement()) { uint32_t count = other._plugins.size(); /* make as many copies as requested */ for (uint32_t n = 0; n < count; ++n) { - _plugins.push_back (plugin_factory (other.plugin())); + _plugins.push_back (plugin_factory (other.plugin (n))); } @@ -137,7 +145,7 @@ PluginInsert::set_count (uint32_t num) uint32_t diff = num - _plugins.size(); for (uint32_t n = 0; n < diff; ++n) { - _plugins.push_back (plugin_factory (*_plugins[0])); + _plugins.push_back (plugin_factory (_plugins[0])); if (require_state) { /* XXX do something */ @@ -147,9 +155,7 @@ PluginInsert::set_count (uint32_t num) } else if (num < _plugins.size()) { uint32_t diff = _plugins.size() - num; for (uint32_t n= 0; n < diff; ++n) { - Plugin * plug = _plugins.back(); _plugins.pop_back(); - delete plug; } } @@ -166,13 +172,7 @@ PluginInsert::init () PluginInsert::~PluginInsert () { - GoingAway (this); /* EMIT SIGNAL */ - - while (!_plugins.empty()) { - Plugin* p = _plugins.back(); - _plugins.pop_back(); - delete p; - } + GoingAway (); /* EMIT SIGNAL */ } void @@ -194,25 +194,25 @@ PluginInsert::auto_state_changed (uint32_t which) uint32_t PluginInsert::output_streams() const { - return _plugins[0]->get_info().n_outputs * _plugins.size(); + return _plugins[0]->get_info()->n_outputs * _plugins.size(); } uint32_t PluginInsert::input_streams() const { - return _plugins[0]->get_info().n_inputs * _plugins.size(); + return _plugins[0]->get_info()->n_inputs * _plugins.size(); } uint32_t PluginInsert::natural_output_streams() const { - return _plugins[0]->get_info().n_outputs; + return _plugins[0]->get_info()->n_outputs; } uint32_t PluginInsert::natural_input_streams() const { - return _plugins[0]->get_info().n_inputs; + return _plugins[0]->get_info()->n_inputs; } bool @@ -222,7 +222,7 @@ PluginInsert::is_generator() const a specific "instrument" flag, for example. */ - return _plugins[0]->get_info().n_inputs == 0; + return _plugins[0]->get_info()->n_inputs == 0; } void @@ -240,7 +240,7 @@ PluginInsert::set_automatable () void PluginInsert::parameter_changed (uint32_t which, float val) { - vector::iterator i = _plugins.begin(); + vector >::iterator i = _plugins.begin(); /* don't set the first plugin, just all the slaves */ @@ -255,7 +255,7 @@ PluginInsert::parameter_changed (uint32_t which, float val) void PluginInsert::set_block_size (jack_nframes_t nframes) { - for (vector::iterator i = _plugins.begin(); i != _plugins.end(); ++i) { + for (vector >::iterator i = _plugins.begin(); i != _plugins.end(); ++i) { (*i)->set_block_size (nframes); } } @@ -263,7 +263,7 @@ PluginInsert::set_block_size (jack_nframes_t nframes) void PluginInsert::activate () { - for (vector::iterator i = _plugins.begin(); i != _plugins.end(); ++i) { + for (vector >::iterator i = _plugins.begin(); i != _plugins.end(); ++i) { (*i)->activate (); } } @@ -271,7 +271,7 @@ PluginInsert::activate () void PluginInsert::deactivate () { - for (vector::iterator i = _plugins.begin(); i != _plugins.end(); ++i) { + for (vector >::iterator i = _plugins.begin(); i != _plugins.end(); ++i) { (*i)->deactivate (); } } @@ -309,7 +309,7 @@ PluginInsert::connect_and_run (vector& bufs, uint32_t nbufs, jack_nfram } } - for (vector::iterator i = _plugins.begin(); i != _plugins.end(); ++i) { + for (vector >::iterator i = _plugins.begin(); i != _plugins.end(); ++i) { (*i)->connect_and_run (bufs, nbufs, in_index, out_index, nframes, offset); } @@ -357,8 +357,8 @@ PluginInsert::silence (jack_nframes_t nframes, jack_nframes_t offset) uint32_t n; if (active()) { - for (vector::iterator i = _plugins.begin(); i != _plugins.end(); ++i) { - n = (*i) -> get_info().n_inputs; + for (vector >::iterator i = _plugins.begin(); i != _plugins.end(); ++i) { + n = (*i) -> get_info()->n_inputs; (*i)->connect_and_run (_session.get_silent_buffers (n), n, in_index, out_index, nframes, offset); } } @@ -375,8 +375,8 @@ PluginInsert::run (vector& bufs, uint32_t nbufs, jack_nframes_t nframe connect_and_run (bufs, nbufs, nframes, offset, false); } } else { - uint32_t in = _plugins[0]->get_info().n_inputs; - uint32_t out = _plugins[0]->get_info().n_outputs; + uint32_t in = _plugins[0]->get_info()->n_inputs; + uint32_t out = _plugins[0]->get_info()->n_outputs; if (out > in) { @@ -506,19 +506,26 @@ PluginInsert::protect_automation () } } -Plugin* -PluginInsert::plugin_factory (Plugin& other) +boost::shared_ptr +PluginInsert::plugin_factory (boost::shared_ptr other) { - LadspaPlugin* lp; + boost::shared_ptr lp; #ifdef VST_SUPPORT - VSTPlugin* vp; + boost::shared_ptr vp; +#endif +#ifdef HAVE_AUDIOUNITS + boost::shared_ptr ap; #endif - if ((lp = dynamic_cast (&other)) != 0) { - return new LadspaPlugin (*lp); + if ((lp = boost::dynamic_pointer_cast (other)) != 0) { + return boost::shared_ptr (new LadspaPlugin (*lp)); #ifdef VST_SUPPORT - } else if ((vp = dynamic_cast (&other)) != 0) { - return new VSTPlugin (*vp); + } else if ((vp = boost::dynamic_pointer_cast (other)) != 0) { + return boost::shared_ptr (new VSTPlugin (*vp)); +#endif +#ifdef HAVE_AUDIOUNITS + } else if ((ap = boost::dynamic_pointer_cast (other)) != 0) { + return boost::shared_ptr (new AUPlugin (*ap)); #endif } @@ -526,13 +533,13 @@ PluginInsert::plugin_factory (Plugin& other) X_("unknown plugin type in PluginInsert::plugin_factory")) << endmsg; /*NOTREACHED*/ - return 0; + return boost::shared_ptr ((Plugin*) 0); } int32_t PluginInsert::compute_output_streams (int32_t cnt) const { - return _plugins[0]->get_info().n_outputs * cnt; + return _plugins[0]->get_info()->n_outputs * cnt; } int32_t @@ -544,8 +551,8 @@ PluginInsert::configure_io (int32_t magic, int32_t in, int32_t out) int32_t PluginInsert::can_support_input_configuration (int32_t in) const { - int32_t outputs = _plugins[0]->get_info().n_outputs; - int32_t inputs = _plugins[0]->get_info().n_inputs; + int32_t outputs = _plugins[0]->get_info()->n_outputs; + int32_t inputs = _plugins[0]->get_info()->n_inputs; if (inputs == 0) { @@ -599,7 +606,7 @@ PluginInsert::state (bool full) node->add_property("id", string(buf)); if (_plugins[0]->state_node_name() == "ladspa") { char buf[32]; - snprintf (buf, 31, "%ld", _plugins[0]->get_info().unique_id); + snprintf (buf, sizeof (buf), "%ld", _plugins[0]->get_info()->unique_id); node->add_property("unique-id", string(buf)); } node->add_property("count", string_compose("%1", _plugins.size())); @@ -638,7 +645,7 @@ PluginInsert::set_state(const XMLNode& node) XMLPropertyList plist; const XMLProperty *prop; long unique = 0; - PluginInfo::Type type; + ARDOUR::PluginType type; if ((prop = node.property ("type")) == 0) { error << _("XML node describing insert is missing the `type' field") << endmsg; @@ -646,9 +653,9 @@ PluginInsert::set_state(const XMLNode& node) } if (prop->value() == X_("ladspa") || prop->value() == X_("Ladspa")) { /* handle old school sessions */ - type = PluginInfo::LADSPA; + type = ARDOUR::LADSPA; } else if (prop->value() == X_("vst")) { - type = PluginInfo::VST; + type = ARDOUR::VST; } else { error << string_compose (_("unknown plugin type %1 in plugin insert state"), prop->value()) @@ -666,7 +673,7 @@ PluginInsert::set_state(const XMLNode& node) return -1; } - Plugin* plugin; + boost::shared_ptr plugin; if (unique != 0) { plugin = find_plugin (_session, "", unique, type); @@ -692,13 +699,13 @@ PluginInsert::set_state(const XMLNode& node) _plugins.push_back (plugin); for (uint32_t n=1; n < count; ++n) { - _plugins.push_back (plugin_factory (*plugin)); + _plugins.push_back (plugin_factory (plugin)); } } for (niter = nlist.begin(); niter != nlist.end(); ++niter) { if ((*niter)->name() == plugin->state_node_name()) { - for (vector::iterator i = _plugins.begin(); i != _plugins.end(); ++i) { + for (vector >::iterator i = _plugins.begin(); i != _plugins.end(); ++i) { (*i)->set_state (**niter); } break; @@ -769,7 +776,7 @@ PluginInsert::set_state(const XMLNode& node) } // The name of the PluginInsert comes from the plugin, nothing else - set_name(plugin->get_info().name,this); + set_name(plugin->get_info()->name,this); return 0; } @@ -780,18 +787,6 @@ PluginInsert::describe_parameter (uint32_t what) return _plugins[0]->describe_parameter (what); } -void -PluginInsert::reset_midi_control (MIDI::Port* port, bool on) -{ - _plugins[0]->reset_midi_control (port, on); -} - -void -PluginInsert::send_all_midi_feedback () -{ - _plugins[0]->send_all_midi_feedback(); -} - jack_nframes_t PluginInsert::latency() { @@ -827,6 +822,35 @@ PluginInsert::state_factory (std::string why) const return state; } +ARDOUR::PluginType +PluginInsert::type () +{ + boost::shared_ptr lp; +#ifdef VST_SUPPORT + boost::shared_ptr vp; +#endif +#ifdef HAVE_AUDIOUNITS + boost::shared_ptr ap; +#endif + + PluginPtr other = plugin (); + + if ((lp = boost::dynamic_pointer_cast (other)) != 0) { + return ARDOUR::LADSPA; +#ifdef VST_SUPPORT + } else if ((vp = boost::dynamic_pointer_cast (other)) != 0) { + return ARDOUR::VST; +#endif +#ifdef HAVE_AUDIOUNITS + } else if ((ap = boost::dynamic_pointer_cast (other)) != 0) { + return ARDOUR::AudioUnit; +#endif + } else { + /* NOT REACHED */ + return (ARDOUR::PluginType) 0; + } +} + /*************************************************************** Port inserts: send output to a port, pick up input at a port ***************************************************************/ @@ -873,7 +897,7 @@ PortInsert::PortInsert (Session& s, const XMLNode& node) PortInsert::~PortInsert () { - GoingAway (this); + GoingAway (); } void @@ -1044,3 +1068,4 @@ PortInsert::input_streams() const { return n_outputs (); } +