replace fixed-point linear interpolation with double-based version, thereby removing...
[ardour.git] / libs / ardour / delivery.cc
index 1b1f62c4b207c17d43d980a96befc7063fe6c862..efe123c059cde652862ab13d86f8326ce5ea8a00 100644 (file)
@@ -47,40 +47,48 @@ 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)
+       , _output_offset (0)
+       , _no_outs_cuz_we_no_monitor (false)
        , _solo_level (0)
        , _solo_isolated (false)
        , _mute_master (mm)
+       , no_panner_reset (false)
 
 {
-       _output_offset = 0;
-       _current_gain = 1.0;
        _panner = boost::shared_ptr<Panner>(new Panner (_name, _session));
        
        if (_output) {
                _output->changed.connect (mem_fun (*this, &Delivery::output_changed));
        }
+
+       CycleStart.connect (mem_fun (*this, &Delivery::cycle_start));
 }
 
 /* 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)
+       , _output_offset (0)
+       , _no_outs_cuz_we_no_monitor (false)
        , _solo_level (0)
        , _solo_isolated (false)
        , _mute_master (mm)
+       , no_panner_reset (false)
 {
-       _output_offset = 0;
-       _current_gain = 1.0;
        _panner = boost::shared_ptr<Panner>(new Panner (_name, _session));
 
        if (_output) {
                _output->changed.connect (mem_fun (*this, &Delivery::output_changed));
        }
+
+       CycleStart.connect (mem_fun (*this, &Delivery::cycle_start));
 }
 
 /* deliver to a new IO object, reconstruct from XML */
@@ -89,12 +97,14 @@ Delivery::Delivery (Session& s, boost::shared_ptr<MuteMaster> mm, const XMLNode&
        : IOProcessor (s, false, true, "reset")
        , _role (Role (0))
        , _output_buffers (new BufferSet())
+       , _current_gain (1.0)
+       , _output_offset (0)
+       , _no_outs_cuz_we_no_monitor (false)
        , _solo_level (0)
        , _solo_isolated (false)
        , _mute_master (mm)
+       , no_panner_reset (false)
 {
-       _output_offset = 0;
-       _current_gain = 1.0;
        _panner = boost::shared_ptr<Panner>(new Panner (_name, _session));
 
        if (set_state (node)) {
@@ -104,6 +114,8 @@ Delivery::Delivery (Session& s, boost::shared_ptr<MuteMaster> mm, const XMLNode&
        if (_output) {
                _output->changed.connect (mem_fun (*this, &Delivery::output_changed));
        }
+
+       CycleStart.connect (mem_fun (*this, &Delivery::cycle_start));
 }
 
 /* deliver to an existing IO object, reconstruct from XML */
@@ -112,12 +124,14 @@ Delivery::Delivery (Session& s, boost::shared_ptr<IO> out, boost::shared_ptr<Mut
        : IOProcessor (s, boost::shared_ptr<IO>(), out, "reset")
        , _role (Role (0))
        , _output_buffers (new BufferSet())
+       , _current_gain (1.0)
+       , _output_offset (0)
+       , _no_outs_cuz_we_no_monitor (false)
        , _solo_level (0)
        , _solo_isolated (false)
        , _mute_master (mm)
+       , no_panner_reset (false)
 {
-       _output_offset = 0;
-       _current_gain = 1.0;
        _panner = boost::shared_ptr<Panner>(new Panner (_name, _session));
 
        if (set_state (node)) {
@@ -127,6 +141,25 @@ Delivery::Delivery (Session& s, boost::shared_ptr<IO> out, boost::shared_ptr<Mut
        if (_output) {
                _output->changed.connect (mem_fun (*this, &Delivery::output_changed));
        }
+
+       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
@@ -145,36 +178,109 @@ 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
+       /* 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;
        }
 
        reset_panner ();
-       
-       return Processor::configure_io (in, out);
+
+       return true;
 }
 
 void
 Delivery::run (BufferSet& bufs, sframes_t start_frame, sframes_t end_frame, nframes_t nframes)
 {
-       if (_output->n_ports ().get (_output->default_type()) == 0) {
+       assert (_output);
+
+       if (!_active || _output->n_ports ().get (_output->default_type()) == 0) {
                return;
        }
 
@@ -237,7 +343,6 @@ Delivery::run (BufferSet& bufs, sframes_t start_frame, sframes_t end_frame, nfra
        }
 }
 
-
 XMLNode&
 Delivery::state (bool full_state)
 {
@@ -399,30 +504,28 @@ Delivery::target_gain ()
        }
 
        gain_t desired_gain;
-       MuteMaster::MutePoint mp;
-
-       switch (_role) {
-       case Main:
-               mp = MuteMaster::Main;
-               break;
-       case Listen:
-               mp = MuteMaster::Listen;
-               break;
-       case Send:
-       case Insert:
-               if (_placement == PreFader) {
-                       mp = MuteMaster::PreFader;
-               } else {
-                       mp = MuteMaster::PostFader;
-               }
-               break;
-       }
-
 
        if (_solo_level) {
                desired_gain = 1.0;
        } else {
 
+               MuteMaster::MutePoint mp;
+               
+               switch (_role) {
+               case Main:
+                       mp = MuteMaster::Main;
+                       break;
+               case Listen:
+                       mp = MuteMaster::Listen;
+                       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 */