itsy-bitsy freebsd compatibility fix.
[ardour.git] / libs / ardour / insert.cc
index 11b1e25a743f01c744028310b71f375ae045bc8e..0416d3e1e41355b40e56681934e994d7561facef 100644 (file)
 #include <ardour/port.h>
 #include <ardour/route.h>
 #include <ardour/ladspa_plugin.h>
+
+#ifdef VST_SUPPORT
 #include <ardour/vst_plugin.h>
+#endif
+
+#ifdef HAVE_AUDIOUNITS
+#include <ardour/audio_unit.h>
+#endif
+
 #include <ardour/audioengine.h>
 #include <ardour/session.h>
+#include <ardour/types.h>
 
 #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)
 {
@@ -73,8 +81,6 @@ PluginInsert::PluginInsert (Session& s, boost::shared_ptr<Plugin> plug, Placemen
        
        init ();
 
-       save_state (_("initial state"));
-
        {
                Glib::Mutex::Lock em (_session.engine().process_lock());
                IO::MoreOutputs (output_streams ());
@@ -92,8 +98,6 @@ PluginInsert::PluginInsert (Session& s, const XMLNode& node)
 
        set_automatable ();
 
-       save_state (_("initial state"));
-
        _plugins[0]->ParameterChanged.connect (mem_fun (*this, &PluginInsert::parameter_changed));
 
        {
@@ -117,8 +121,6 @@ PluginInsert::PluginInsert (const PluginInsert& other)
 
        init ();
 
-       save_state (_("initial state"));
-
        RedirectCreated (this); /* EMIT SIGNAL */
 }
 
@@ -164,7 +166,7 @@ PluginInsert::init ()
 
 PluginInsert::~PluginInsert ()
 {
-       GoingAway (this); /* EMIT SIGNAL */
+       GoingAway (); /* EMIT SIGNAL */
 }
 
 void
@@ -186,25 +188,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
@@ -214,7 +216,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
@@ -245,7 +247,7 @@ PluginInsert::parameter_changed (uint32_t which, float val)
 }
 
 void
-PluginInsert::set_block_size (jack_nframes_t nframes)
+PluginInsert::set_block_size (nframes_t nframes)
 {
        for (vector<boost::shared_ptr<Plugin> >::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
                (*i)->set_block_size (nframes);
@@ -269,7 +271,7 @@ PluginInsert::deactivate ()
 }
 
 void
-PluginInsert::connect_and_run (vector<Sample*>& bufs, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset, bool with_auto, jack_nframes_t now)
+PluginInsert::connect_and_run (vector<Sample*>& bufs, uint32_t nbufs, nframes_t nframes, nframes_t offset, bool with_auto, nframes_t now)
 {
        int32_t in_index = 0;
        int32_t out_index = 0;
@@ -309,7 +311,7 @@ PluginInsert::connect_and_run (vector<Sample*>& bufs, uint32_t nbufs, jack_nfram
 }
 
 void
-PluginInsert::automation_snapshot (jack_nframes_t now)
+PluginInsert::automation_snapshot (nframes_t now)
 {
        map<uint32_t,AutomationList*>::iterator li;
        
@@ -326,7 +328,7 @@ PluginInsert::automation_snapshot (jack_nframes_t now)
 }
 
 void
-PluginInsert::transport_stopped (jack_nframes_t now)
+PluginInsert::transport_stopped (nframes_t now)
 {
        map<uint32_t,AutomationList*>::iterator li;
 
@@ -341,7 +343,7 @@ PluginInsert::transport_stopped (jack_nframes_t now)
 }
 
 void
-PluginInsert::silence (jack_nframes_t nframes, jack_nframes_t offset)
+PluginInsert::silence (nframes_t nframes, nframes_t offset)
 {
        int32_t in_index = 0;
        int32_t out_index = 0;
@@ -350,14 +352,14 @@ PluginInsert::silence (jack_nframes_t nframes, jack_nframes_t offset)
 
        if (active()) {
                for (vector<boost::shared_ptr<Plugin> >::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
-                       n = (*i) -> get_info().n_inputs;
+                       n = (*i) -> get_info()->n_inputs;
                        (*i)->connect_and_run (_session.get_silent_buffers (n), n, in_index, out_index, nframes, offset);
                }
        }
 }
        
 void
-PluginInsert::run (vector<Sample *>& bufs, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset)
+PluginInsert::run (vector<Sample *>& bufs, uint32_t nbufs, nframes_t nframes, nframes_t offset)
 {
        if (active()) {
 
@@ -367,8 +369,8 @@ PluginInsert::run (vector<Sample *>& 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) {
 
@@ -396,11 +398,11 @@ PluginInsert::set_parameter (uint32_t port, float val)
 }
 
 void
-PluginInsert::automation_run (vector<Sample *>& bufs, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset)
+PluginInsert::automation_run (vector<Sample *>& bufs, uint32_t nbufs, nframes_t nframes, nframes_t offset)
 {
        ControlEvent next_event (0, 0.0f);
-       jack_nframes_t now = _session.transport_frame ();
-       jack_nframes_t end = now + nframes;
+       nframes_t now = _session.transport_frame ();
+       nframes_t end = now + nframes;
 
        Glib::Mutex::Lock lm (_automation_lock, Glib::TRY_LOCK);
 
@@ -419,7 +421,7 @@ PluginInsert::automation_run (vector<Sample *>& bufs, uint32_t nbufs, jack_nfram
        
        while (nframes) {
 
-               jack_nframes_t cnt = min (((jack_nframes_t) floor (next_event.when) - now), nframes);
+               nframes_t cnt = min (((nframes_t) floor (next_event.when) - now), nframes);
   
                connect_and_run (bufs, nbufs, cnt, offset, true, now);
                
@@ -460,7 +462,6 @@ PluginInsert::set_port_automation_state (uint32_t port, AutoState s)
 
                if (s != al.automation_state()) {
                        al.set_automation_state (s);
-                       last_automation_snapshot = 0;
                        _session.set_dirty ();
                }
        }
@@ -505,12 +506,19 @@ PluginInsert::plugin_factory (boost::shared_ptr<Plugin> other)
 #ifdef VST_SUPPORT
        boost::shared_ptr<VSTPlugin> vp;
 #endif
+#ifdef HAVE_AUDIOUNITS
+       boost::shared_ptr<AUPlugin> ap;
+#endif
 
        if ((lp = boost::dynamic_pointer_cast<LadspaPlugin> (other)) != 0) {
                return boost::shared_ptr<Plugin> (new LadspaPlugin (*lp));
 #ifdef VST_SUPPORT
        } else if ((vp = boost::dynamic_pointer_cast<VSTPlugin> (other)) != 0) {
                return boost::shared_ptr<Plugin> (new VSTPlugin (*vp));
+#endif
+#ifdef HAVE_AUDIOUNITS
+       } else if ((ap = boost::dynamic_pointer_cast<AUPlugin> (other)) != 0) {
+               return boost::shared_ptr<Plugin> (new AUPlugin (*ap));
 #endif
        }
 
@@ -524,7 +532,7 @@ PluginInsert::plugin_factory (boost::shared_ptr<Plugin> other)
 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
@@ -536,8 +544,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) {
 
@@ -591,7 +599,7 @@ PluginInsert::state (bool full)
        node->add_property("id", string(buf));
        if (_plugins[0]->state_node_name() == "ladspa") {
                char buf[32];
-               snprintf (buf, sizeof (buf), "%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()));
@@ -606,14 +614,8 @@ PluginInsert::state (bool full)
                XMLNode* child = new XMLNode("port");
                snprintf(buf, sizeof(buf), "%" PRIu32, *x);
                child->add_property("number", string(buf));
-               
-               if (full) {
-                       snprintf(buf, sizeof(buf), "0x%x", automation_list (*x).automation_state ());
-               } else {
-                       snprintf(buf, sizeof(buf), "0x%x", ARDOUR::Off);
-               }
-               child->add_property("auto", string(buf));
-               
+
+               child->add_child_nocopy (automation_list (*x).state (full));
                autonode->add_child_nocopy (*child);
        }
 
@@ -630,7 +632,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;
@@ -638,9 +640,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())
@@ -717,43 +719,62 @@ PluginInsert::set_state(const XMLNode& node)
        /* look for port automation node */
        
        for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
-               if ((*niter)->name() == port_automation_node_name) {
-                       XMLNodeList cnodes;
-                       XMLProperty *cprop;
-                       XMLNodeConstIterator iter;
-                       XMLNode *child;
-                       const char *port;
-                       uint32_t port_id;
-
-                       cnodes = (*niter)->children ("port");
-       
-                       for(iter = cnodes.begin(); iter != cnodes.end(); ++iter){
-                               
-                               child = *iter;
-                               
-                               if ((cprop = child->property("number")) != 0) {
-                                       port = cprop->value().c_str();
-                               } else {
-                                       warning << _("PluginInsert: Auto: no ladspa port number") << endmsg;
-                                       continue;
-                               }
 
-                               sscanf (port, "%" PRIu32, &port_id);
+               if ((*niter)->name() != port_automation_node_name) {
+                       continue;
+               }
 
-                               if (port_id >= _plugins[0]->parameter_count()) {
-                                       warning << _("PluginInsert: Auto: port id out of range") << endmsg;
-                                       continue;
-                               }
-                               
+               XMLNodeList cnodes;
+               XMLProperty *cprop;
+               XMLNodeConstIterator iter;
+               XMLNode *child;
+               const char *port;
+               uint32_t port_id;
+               
+               cnodes = (*niter)->children ("port");
+               
+               for(iter = cnodes.begin(); iter != cnodes.end(); ++iter){
+                       
+                       child = *iter;
+                       
+                       if ((cprop = child->property("number")) != 0) {
+                               port = cprop->value().c_str();
+                       } else {
+                               warning << _("PluginInsert: Auto: no ladspa port number") << endmsg;
+                               continue;
+                       }
+                       
+                       sscanf (port, "%" PRIu32, &port_id);
+                       
+                       if (port_id >= _plugins[0]->parameter_count()) {
+                               warning << _("PluginInsert: Auto: port id out of range") << endmsg;
+                               continue;
+                       }
+
+                       if (!child->children().empty()) {
+                               automation_list (port_id).set_state (*child->children().front());
+                       } else {
                                if ((cprop = child->property("auto")) != 0) {
+                                       
+                                       /* old school */
+
                                        int x;
                                        sscanf (cprop->value().c_str(), "0x%x", &x);
                                        automation_list (port_id).set_automation_state (AutoState (x));
+
+                               } else {
+                                       
+                                       /* missing */
+                                       
+                                       automation_list (port_id).set_automation_state (Off);
                                }
                        }
-                       
-                       break;
+
                }
+
+               /* done */
+
+               break;
        } 
 
        if (niter == nlist.end()) {
@@ -761,7 +782,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;
 }
@@ -772,39 +793,39 @@ PluginInsert::describe_parameter (uint32_t what)
        return _plugins[0]->describe_parameter (what);
 }
 
-jack_nframes_t 
+nframes_t 
 PluginInsert::latency() 
 {
        return _plugins[0]->latency ();
 }
        
-void
-PluginInsert::store_state (PluginInsertState& state) const
-{
-       Redirect::store_state (state);
-       _plugins[0]->store_state (state.plugin_state);
-}
-
-Change
-PluginInsert::restore_state (StateManager::State& state)
-{
-       PluginInsertState* pistate = dynamic_cast<PluginInsertState*> (&state);
-
-       Redirect::restore_state (state);
-
-       _plugins[0]->restore_state (pistate->plugin_state);
-
-       return Change (0);
-}
-
-StateManager::State*
-PluginInsert::state_factory (std::string why) const
+ARDOUR::PluginType
+PluginInsert::type ()
 {
-       PluginInsertState* state = new PluginInsertState (why);
-
-       store_state (*state);
+       boost::shared_ptr<LadspaPlugin> lp;
+#ifdef VST_SUPPORT
+       boost::shared_ptr<VSTPlugin> vp;
+#endif
+#ifdef HAVE_AUDIOUNITS
+       boost::shared_ptr<AUPlugin> ap;
+#endif
+       
+       PluginPtr other = plugin ();
 
-       return state;
+       if ((lp = boost::dynamic_pointer_cast<LadspaPlugin> (other)) != 0) {
+               return ARDOUR::LADSPA;
+#ifdef VST_SUPPORT
+       } else if ((vp = boost::dynamic_pointer_cast<VSTPlugin> (other)) != 0) {
+               return ARDOUR::VST;
+#endif
+#ifdef HAVE_AUDIOUNITS
+       } else if ((ap = boost::dynamic_pointer_cast<AUPlugin> (other)) != 0) {
+               return ARDOUR::AudioUnit;
+#endif
+       } else {
+               /* NOT REACHED */
+               return (ARDOUR::PluginType) 0;
+       }
 }
 
 /***************************************************************
@@ -815,15 +836,14 @@ PortInsert::PortInsert (Session& s, Placement p)
        : Insert (s, p, 1, -1, 1, -1)
 {
        init ();
-       save_state (_("initial state"));
        RedirectCreated (this); /* EMIT SIGNAL */
+
 }
 
 PortInsert::PortInsert (const PortInsert& other)
        : Insert (other._session, other.placement(), 1, -1, 1, -1)
 {
        init ();
-       save_state (_("initial state"));
        RedirectCreated (this); /* EMIT SIGNAL */
 }
 
@@ -853,11 +873,11 @@ PortInsert::PortInsert (Session& s, const XMLNode& node)
 
 PortInsert::~PortInsert ()
 {
-       GoingAway (this);
+       GoingAway ();
 }
 
 void
-PortInsert::run (vector<Sample *>& bufs, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset)
+PortInsert::run (vector<Sample *>& bufs, uint32_t nbufs, nframes_t nframes, nframes_t offset)
 {
        if (n_outputs() == 0) {
                return;
@@ -937,7 +957,7 @@ PortInsert::set_state(const XMLNode& node)
        return 0;
 }
 
-jack_nframes_t 
+nframes_t 
 PortInsert::latency() 
 {
        /* because we deliver and collect within the same cycle,
@@ -1024,3 +1044,4 @@ PortInsert::input_streams() const
 {
        return n_outputs ();
 }
+