itsy-bitsy freebsd compatibility fix.
[ardour.git] / libs / ardour / insert.cc
index 18727e8b5b952f3eb6db61eb62c5af7c93e73c97..0416d3e1e41355b40e56681934e994d7561facef 100644 (file)
@@ -35,7 +35,7 @@
 #include <ardour/vst_plugin.h>
 #endif
 
-#ifdef HAVE_COREAUDIO
+#ifdef HAVE_AUDIOUNITS
 #include <ardour/audio_unit.h>
 #endif
 
@@ -81,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 ());
@@ -100,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));
 
        {
@@ -125,8 +121,6 @@ PluginInsert::PluginInsert (const PluginInsert& other)
 
        init ();
 
-       save_state (_("initial state"));
-
        RedirectCreated (this); /* EMIT SIGNAL */
 }
 
@@ -172,7 +166,7 @@ PluginInsert::init ()
 
 PluginInsert::~PluginInsert ()
 {
-       GoingAway (this); /* EMIT SIGNAL */
+       GoingAway (); /* EMIT SIGNAL */
 }
 
 void
@@ -253,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);
@@ -277,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;
@@ -317,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;
        
@@ -334,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;
 
@@ -349,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;
@@ -365,7 +359,7 @@ PluginInsert::silence (jack_nframes_t nframes, jack_nframes_t 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()) {
 
@@ -404,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);
 
@@ -427,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);
                
@@ -468,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 ();
                }
        }
@@ -513,7 +506,7 @@ PluginInsert::plugin_factory (boost::shared_ptr<Plugin> other)
 #ifdef VST_SUPPORT
        boost::shared_ptr<VSTPlugin> vp;
 #endif
-#ifdef HAVE_COREAUDIO
+#ifdef HAVE_AUDIOUNITS
        boost::shared_ptr<AUPlugin> ap;
 #endif
 
@@ -523,7 +516,7 @@ PluginInsert::plugin_factory (boost::shared_ptr<Plugin> other)
        } else if ((vp = boost::dynamic_pointer_cast<VSTPlugin> (other)) != 0) {
                return boost::shared_ptr<Plugin> (new VSTPlugin (*vp));
 #endif
-#ifdef HAVE_COREAUDIO
+#ifdef HAVE_AUDIOUNITS
        } else if ((ap = boost::dynamic_pointer_cast<AUPlugin> (other)) != 0) {
                return boost::shared_ptr<Plugin> (new AUPlugin (*ap));
 #endif
@@ -621,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);
        }
 
@@ -732,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;
+               }
+
+               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 (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()) {
@@ -787,41 +793,12 @@ 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
-{
-       PluginInsertState* state = new PluginInsertState (why);
-
-       store_state (*state);
-
-       return state;
-}
-
 ARDOUR::PluginType
 PluginInsert::type ()
 {
@@ -829,7 +806,7 @@ PluginInsert::type ()
 #ifdef VST_SUPPORT
        boost::shared_ptr<VSTPlugin> vp;
 #endif
-#ifdef HAVE_COREAUDIO
+#ifdef HAVE_AUDIOUNITS
        boost::shared_ptr<AUPlugin> ap;
 #endif
        
@@ -841,7 +818,7 @@ PluginInsert::type ()
        } else if ((vp = boost::dynamic_pointer_cast<VSTPlugin> (other)) != 0) {
                return ARDOUR::VST;
 #endif
-#ifdef HAVE_COREAUDIO
+#ifdef HAVE_AUDIOUNITS
        } else if ((ap = boost::dynamic_pointer_cast<AUPlugin> (other)) != 0) {
                return ARDOUR::AudioUnit;
 #endif
@@ -859,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 */
 }
 
@@ -897,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;
@@ -981,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,
@@ -1068,3 +1044,4 @@ PortInsert::input_streams() const
 {
        return n_outputs ();
 }
+