replace fixed-point linear interpolation with double-based version, thereby removing...
[ardour.git] / libs / ardour / delivery.cc
index 4d79aad2b97f6808d522a325a8ee5d55699dc191..efe123c059cde652862ab13d86f8326ce5ea8a00 100644 (file)
@@ -47,35 +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>(), 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));
        
-       _output->changed.connect (mem_fun (*this, &Delivery::output_changed));
+       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, 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));
 
-       _output->changed.connect (mem_fun (*this, &Delivery::output_changed));
+       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 */
@@ -84,19 +97,69 @@ 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)
+{
+       _panner = boost::shared_ptr<Panner>(new Panner (_name, _session));
+
+       if (set_state (node)) {
+               throw failed_constructor ();
+       }
+
+       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 */
+
+Delivery::Delivery (Session& s, boost::shared_ptr<IO> out, boost::shared_ptr<MuteMaster> mm, const XMLNode& node)
+       : 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)) {
                throw failed_constructor ();
        }
 
-       _output->changed.connect (mem_fun (*this, &Delivery::output_changed));
+       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
@@ -115,45 +178,122 @@ 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_in_place (BufferSet& bufs, sframes_t start_frame, sframes_t end_frame, nframes_t nframes)
+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;
        }
 
+       /* 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
        // we really can modify the buffers passed in (it is almost certainly
-       // the main output stage of a Route). Contrast with Send::run_in_place()
+       // the main output stage of a Route). Contrast with Send::run()
        // which cannot do this.
 
        gain_t tgain = target_gain ();
@@ -203,7 +343,6 @@ Delivery::run_in_place (BufferSet& bufs, sframes_t start_frame, sframes_t end_fr
        }
 }
 
-
 XMLNode&
 Delivery::state (bool full_state)
 {
@@ -234,15 +373,9 @@ Delivery::set_state (const XMLNode& node)
        
        if ((prop = node.property ("role")) != 0) {
                _role = Role (string_2_enum (prop->value(), _role));
-       }
-
-       if ((prop = node.property ("solo_level")) != 0) {
-               _solo_level = 0; // needed for the reset to work
-               mod_solo_level (atoi (prop->value()));
-       }
-
-       if ((prop = node.property ("solo-isolated")) != 0) {
-               set_solo_isolated (prop->value() == "yes");
+               // std::cerr << this << ' ' << _name << " set role to " << enum_2_string (_role) << std::endl;
+       } else {
+               // std::cerr << this << ' ' << _name << " NO ROLE INFO\n";
        }
 
        XMLNode* pan_node = node.child (X_("Panner"));
@@ -261,7 +394,16 @@ Delivery::reset_panner ()
 {
        if (panners_legal) {
                if (!no_panner_reset) {
-                       _panner->reset (_output->n_ports().n_audio(), pans_required());
+
+                       uint32_t ntargets;
+                       
+                       if (_output) {
+                               ntargets = _output->n_ports().n_audio();
+                       } else {
+                               ntargets = _configured_output.n_audio();
+                       }
+
+                       _panner->reset (ntargets, pans_required());
                }
        } else {
                panner_legal_c.disconnect ();
@@ -272,7 +414,15 @@ Delivery::reset_panner ()
 int
 Delivery::panners_became_legal ()
 {
-       _panner->reset (_output->n_ports().n_audio(), pans_required());
+       uint32_t ntargets;
+
+       if (_output) {
+               ntargets = _output->n_ports().n_audio();
+       } else {
+               ntargets = _configured_output.n_audio();
+       }
+
+       _panner->reset (ntargets, pans_required());
        _panner->load (); // automation
        panner_legal_c.disconnect ();
        return 0;
@@ -354,30 +504,32 @@ 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 {
-               if (_solo_isolated) {
 
+               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 */
+                       
                        desired_gain = _mute_master->mute_gain_at (mp);
 
                } else if (_session.soloing()) {
@@ -392,26 +544,6 @@ Delivery::target_gain ()
        return desired_gain;
 }
 
-void
-Delivery::mod_solo_level (int32_t delta)
-{
-       if (delta < 0) {
-               if (_solo_level >= (uint32_t) delta) {
-                       _solo_level += delta;
-               } else {
-                       _solo_level = 0;
-               }
-       } else {
-               _solo_level += delta;
-       }
-}
-
-void
-Delivery::set_solo_isolated (bool yn)
-{
-       _solo_isolated = yn;
-}
-
 void
 Delivery::no_outs_cuz_we_no_monitor (bool yn)
 {
@@ -437,3 +569,4 @@ Delivery::output_changed (IOChange change, void* src)
                reset_panner ();
        }
 }
+