Add metadata file with DOAP and LV2 Host Info information.
[ardour.git] / libs / ardour / delivery.cc
index f8bba4c8e71bf58ca054971d2779c3eb2b332d63..5b063ad566c22aadc0d2972d2e105e74a9fcf894 100644 (file)
@@ -1,16 +1,16 @@
 /*
-    Copyright (C) 2009 Paul Davis 
-    
+    Copyright (C) 2009 Paul Davis
+
     This program is free software; you can redistribute it and/or modify it
     under the terms of the GNU General Public License as published by the Free
     Software Foundation; either version 2 of the License, or (at your option)
     any later version.
-    
+
     This program is distributed in the hope that it will be useful, but WITHOUT
     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     for more details.
-    
+
     You should have received a copy of the GNU General Public License along
     with this program; if not, write to the Free Software Foundation, Inc.,
     675 Mass Ave, Cambridge, MA 02139, USA.
@@ -22,6 +22,8 @@
 #include "pbd/enumwriter.h"
 #include "pbd/convert.h"
 
+#include "ardour/midi_buffer.h"
+
 #include "ardour/delivery.h"
 #include "ardour/audio_buffer.h"
 #include "ardour/amp.h"
@@ -47,7 +49,7 @@ bool                         Delivery::panners_legal = false;
 /* deliver to an existing IO object */
 
 Delivery::Delivery (Session& s, boost::shared_ptr<IO> io, boost::shared_ptr<MuteMaster> mm, const string& name, Role r)
-       : IOProcessor(s, boost::shared_ptr<IO>(), (r == Listen ? boost::shared_ptr<IO>() : io), name)
+       : IOProcessor(s, boost::shared_ptr<IO>(), (role_requires_output_ports (r) ? io : boost::shared_ptr<IO>()), name)
        , _role (r)
        , _output_buffers (new BufferSet())
        , _current_gain (1.0)
@@ -60,7 +62,7 @@ Delivery::Delivery (Session& s, boost::shared_ptr<IO> io, boost::shared_ptr<Mute
 
 {
        _panner = boost::shared_ptr<Panner>(new Panner (_name, _session));
-       
+
        if (_output) {
                _output->changed.connect (mem_fun (*this, &Delivery::output_changed));
        }
@@ -71,7 +73,7 @@ Delivery::Delivery (Session& s, boost::shared_ptr<IO> io, boost::shared_ptr<Mute
 /* deliver to a new IO object */
 
 Delivery::Delivery (Session& s, boost::shared_ptr<MuteMaster> mm, const string& name, Role r)
-       : IOProcessor(s, false, (r == Listen ? false : true), name)
+       : IOProcessor(s, false, (role_requires_output_ports (r) ? true : false), name)
        , _role (r)
        , _output_buffers (new BufferSet())
        , _current_gain (1.0)
@@ -107,7 +109,7 @@ Delivery::Delivery (Session& s, boost::shared_ptr<MuteMaster> mm, const XMLNode&
 {
        _panner = boost::shared_ptr<Panner>(new Panner (_name, _session));
 
-       if (set_state (node)) {
+       if (set_state (node, Stateful::loading_state_version)) {
                throw failed_constructor ();
        }
 
@@ -134,7 +136,7 @@ Delivery::Delivery (Session& s, boost::shared_ptr<IO> out, boost::shared_ptr<Mut
 {
        _panner = boost::shared_ptr<Panner>(new Panner (_name, _session));
 
-       if (set_state (node)) {
+       if (set_state (node, Stateful::loading_state_version)) {
                throw failed_constructor ();
        }
 
@@ -145,8 +147,25 @@ Delivery::Delivery (Session& s, boost::shared_ptr<IO> out, boost::shared_ptr<Mut
        CycleStart.connect (mem_fun (*this, &Delivery::cycle_start));
 }
 
+std::string
+Delivery::display_name () const
+{
+       switch (_role) {
+       case Main:
+               return _("main outs");
+               break;
+       case Listen:
+               return _("listen");
+               break;
+       case Send:
+       case Insert:
+       default:
+               return name();
+       }
+}
+
 void
-Delivery::cycle_start (nframes_t nframes)
+Delivery::cycle_start (nframes_t /*nframes*/)
 {
        _output_offset = 0;
        _no_outs_cuz_we_no_monitor = false;
@@ -161,27 +180,94 @@ Delivery::increment_output_offset (nframes_t n)
 bool
 Delivery::visible () const
 {
-       if (_role & Main) {
-               return false;
-       }
-
        return true;
 }
 
 bool
 Delivery::can_support_io_configuration (const ChanCount& in, ChanCount& out) const
 {
-       out = in;
-       return true;
+       if (_role == Main) {
+
+               /* the out buffers will be set to point to the port output buffers
+                  of our output object.
+               */
+
+               if (_output) {
+                       if (_output->n_ports() != ChanCount::ZERO) {
+                               out = _output->n_ports();
+                               return true;
+                       } else {
+                               /* not configured yet - we will passthru */
+                               out = in;
+                               return true;
+                       }
+               } else {
+                       fatal << "programming error: this should never be reached" << endmsg;
+                       /*NOTREACHED*/
+               }
+
+
+       } else if (_role == Insert) {
+
+               /* the output buffers will be filled with data from the *input* ports
+                  of this Insert.
+               */
+
+               if (_input) {
+                       if (_input->n_ports() != ChanCount::ZERO) {
+                               out = _input->n_ports();
+                               return true;
+                       } else {
+                               /* not configured yet - we will passthru */
+                               out = in;
+                               return true;
+                       }
+               } else {
+                       fatal << "programming error: this should never be reached" << endmsg;
+                       /*NOTREACHED*/
+               }
+
+       } else {
+               fatal << "programming error: this should never be reached" << endmsg;
+       }
+
+       return false;
 }
 
 bool
 Delivery::configure_io (ChanCount in, ChanCount out)
 {
-       if (out != in) { // always 1:1
-               return false;
+       /* check configuration by comparison with our I/O port configuration, if appropriate.
+          see ::can_support_io_configuration() for comments
+       */
+
+       if (_role == Main) {
+
+               if (_output) {
+                       if (_output->n_ports() != out) {
+                               if (_output->n_ports() != ChanCount::ZERO) {
+                                       fatal << _name << " programming error: configure_io with nports = " << _output->n_ports() << " called with " << in << " and " << out << " with " << _output->n_ports() << " output ports" << endmsg;
+                                       /*NOTREACHED*/
+                               } else {
+                                       /* I/O not yet configured */
+                               }
+                       }
+               }
+
+       } else if (_role == Insert) {
+
+               if (_input) {
+                       if (_input->n_ports() != in) {
+                               if (_input->n_ports() != ChanCount::ZERO) {
+                                       fatal << _name << " programming error: configure_io called with " << in << " and " << out << " with " << _input->n_ports() << " input ports" << endmsg;
+                                       /*NOTREACHED*/
+                               } else {
+                                       /* I/O not yet configured */
+                               }
+                       }
+               }
        }
-       
+
        if (!Processor::configure_io (in, out)) {
                return false;
        }
@@ -194,15 +280,24 @@ Delivery::configure_io (ChanCount in, ChanCount out)
 void
 Delivery::run (BufferSet& bufs, sframes_t start_frame, sframes_t end_frame, nframes_t nframes)
 {
+       assert (_output);
+
+       PortSet& ports (_output->ports());
+       gain_t tgain;
+
        if (_output->n_ports ().get (_output->default_type()) == 0) {
-               return;
+               goto out;
+       }
+
+       if (!_active && !_pending_active) {
+               _output->silence (nframes);
+               goto out;
        }
 
-       /* this setup is not just for our purposes, but for anything that comes after us in the 
+       /* this setup is not just for our purposes, but for anything that comes after us in the
           processing pathway that wants to use this->output_buffers() for some reason.
        */
 
-       PortSet& ports (_output->ports());
        output_buffers().attach_buffers (ports, nframes, _output_offset);
 
        // this Delivery processor is not a derived type, and thus we assume
@@ -210,10 +305,10 @@ Delivery::run (BufferSet& bufs, sframes_t start_frame, sframes_t end_frame, nfra
        // the main output stage of a Route). Contrast with Send::run()
        // which cannot do this.
 
-       gain_t tgain = target_gain ();
-       
+       tgain = target_gain ();
+
        if (tgain != _current_gain) {
-               
+
                /* target gain has changed */
 
                Amp::apply_gain (bufs, nframes, _current_gain, tgain);
@@ -227,8 +322,7 @@ Delivery::run (BufferSet& bufs, sframes_t start_frame, sframes_t end_frame, nfra
 
                _output->silence (nframes);
                Amp::apply_simple_gain (bufs, nframes, 0.0);
-               
-               return;
+               goto out;
 
        } else if (tgain != 1.0) {
 
@@ -236,8 +330,6 @@ Delivery::run (BufferSet& bufs, sframes_t start_frame, sframes_t end_frame, nfra
                Amp::apply_simple_gain (bufs, nframes, tgain);
        }
 
-       // Attach output buffers to port buffers
-
        if (_panner && _panner->npanners() && !_panner->bypassed()) {
 
                // Use the panner to distribute audio to output port buffers
@@ -255,8 +347,10 @@ Delivery::run (BufferSet& bufs, sframes_t start_frame, sframes_t end_frame, nfra
                        _output->copy_to_outputs (bufs, DataType::MIDI, nframes, _output_offset);
                }
        }
-}
 
+  out:
+       _active = _pending_active;
+}
 
 XMLNode&
 Delivery::state (bool full_state)
@@ -278,14 +372,14 @@ Delivery::state (bool full_state)
 }
 
 int
-Delivery::set_state (const XMLNode& node)
+Delivery::set_state (const XMLNode& node, int version)
 {
        const XMLProperty* prop;
 
-       if (IOProcessor::set_state (node)) {
+       if (IOProcessor::set_state (node, version)) {
                return -1;
        }
-       
+
        if ((prop = node.property ("role")) != 0) {
                _role = Role (string_2_enum (prop->value(), _role));
                // std::cerr << this << ' ' << _name << " set role to " << enum_2_string (_role) << std::endl;
@@ -294,10 +388,10 @@ Delivery::set_state (const XMLNode& node)
        }
 
        XMLNode* pan_node = node.child (X_("Panner"));
-       
+
        if (pan_node) {
-               _panner->set_state (*pan_node);
-       } 
+               _panner->set_state (*pan_node, version);
+       }
 
        reset_panner ();
 
@@ -311,7 +405,7 @@ Delivery::reset_panner ()
                if (!no_panner_reset) {
 
                        uint32_t ntargets;
-                       
+
                        if (_output) {
                                ntargets = _output->n_ports().n_audio();
                        } else {
@@ -396,20 +490,38 @@ Delivery::transport_stopped (sframes_t frame)
 }
 
 void
-Delivery::flush (nframes_t nframes)
+Delivery::flush (nframes_t nframes, nframes64_t time)
 {
        /* io_lock, not taken: function must be called from Session::process() calltree */
-       
+
        PortSet& ports (_output->ports());
 
        for (PortSet::iterator i = ports.begin(); i != ports.end(); ++i) {
-               (*i).flush_buffers (nframes, _output_offset);
+               (*i).flush_buffers (nframes, time, _output_offset);
+       }
+}
+
+void
+Delivery::transport_stopped ()
+{
+       /* turn off any notes that are on */
+
+       PortSet& ports (_output->ports());
+
+       for (PortSet::iterator i = ports.begin(); i != ports.end(); ++i) {
+               (*i).transport_stopped ();
        }
 }
 
 gain_t
 Delivery::target_gain ()
 {
+       /* if we've been requested to deactivate, our target gain is zero */
+
+       if (!_pending_active) {
+               return 0.0;
+       }
+
        /* if we've been told not to output because its a monitoring situation and
           we're not monitoring, then be quiet.
        */
@@ -425,7 +537,7 @@ Delivery::target_gain ()
        } else {
 
                MuteMaster::MutePoint mp;
-               
+
                switch (_role) {
                case Main:
                        mp = MuteMaster::Main;
@@ -435,15 +547,16 @@ Delivery::target_gain ()
                        break;
                case Send:
                case Insert:
+               case Aux:
                        /* XXX FIX ME this is wrong, we need per-delivery muting */
                        mp = MuteMaster::PreFader;
                        break;
                }
 
                if (_solo_isolated) {
-               
+
                        /* ... but we are isolated from all that nonsense */
-                       
+
                        desired_gain = _mute_master->mute_gain_at (mp);
 
                } else if (_session.soloing()) {
@@ -477,7 +590,7 @@ Delivery::set_name (const std::string& name)
 }
 
 void
-Delivery::output_changed (IOChange change, void* src)
+Delivery::output_changed (IOChange change, void* /*src*/)
 {
        if (change & ARDOUR::ConfigurationChanged) {
                reset_panner ();