update internal-send port-count when target port-count changes
[ardour.git] / libs / ardour / internal_send.cc
index dfb0204c8cb5c63cd6af2a03dd630b50be7486a9..dac1839a5ea07a89bfc2a0907a75be81281c800e 100644 (file)
@@ -25,7 +25,6 @@
 #include "ardour/internal_return.h"
 #include "ardour/internal_send.h"
 #include "ardour/meter.h"
-#include "ardour/panner.h"
 #include "ardour/panner_shell.h"
 #include "ardour/route.h"
 #include "ardour/session.h"
@@ -33,6 +32,8 @@
 
 #include "i18n.h"
 
+namespace ARDOUR { class MuteMaster; class Pannable; }
+
 using namespace PBD;
 using namespace ARDOUR;
 using namespace std;
@@ -94,11 +95,21 @@ InternalSend::use_target (boost::shared_ptr<Route> sendto)
         target_connections.drop_connections ();
 
         _send_to->DropReferences.connect_same_thread (target_connections, boost::bind (&InternalSend::send_to_going_away, this));
-        _send_to->PropertyChanged.connect_same_thread (target_connections, boost::bind (&InternalSend::send_to_property_changed, this, _1));;
+        _send_to->PropertyChanged.connect_same_thread (target_connections, boost::bind (&InternalSend::send_to_property_changed, this, _1));
+        _send_to->io_changed.connect_same_thread (target_connections, boost::bind (&InternalSend::target_io_changed, this));
 
         return 0;
 }
 
+void
+InternalSend::target_io_changed ()
+{
+       assert (_send_to);
+       mixbufs.ensure_buffers (_send_to->internal_return()->input_streams(), _session.get_block_size());
+       mixbufs.set_count (_send_to->internal_return()->input_streams());
+       reset_panner();
+}
+
 void
 InternalSend::send_to_going_away ()
 {
@@ -127,7 +138,19 @@ InternalSend::run (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame
                        uint32_t const bufs_audio = bufs.count().get (DataType::AUDIO);
                        uint32_t const mixbufs_audio = mixbufs.count().get (DataType::AUDIO);
                        
-                       assert (mixbufs.available().get (DataType::AUDIO) >= bufs_audio);
+                       /* monitor-section has same number of channels as master-bus (on creation).
+                        *
+                        * There is no clear answer what should happen when trying to PFL or AFL
+                        * a track that has more channels (bufs_audio from source-track is
+                        * larger than mixbufs).
+                        *
+                        * There are two options:
+                        *  1: discard additional channels    (current)
+                        * OR
+                        *  2: require the monitor-section to have at least as many channels
+                        * as the largest count of any route
+                        */
+                       //assert (mixbufs.available().get (DataType::AUDIO) >= bufs_audio);
 
                        /* Copy bufs into mixbufs, going round bufs more than once if necessary
                           to ensure that every mixbuf gets some data.
@@ -175,10 +198,8 @@ InternalSend::run (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame
                Amp::apply_simple_gain (mixbufs, nframes, tgain);
        }
 
-       // Can't automate gain for sends or returns yet because we need different buffers
-       // so that we don't overwrite the main automation data for the route amp
-       // _amp->setup_gain_automation (start_frame, end_frame, nframes);
-
+       _amp->set_gain_automation_buffer (_session.send_gain_automation_buffer ());
+       _amp->setup_gain_automation (start_frame, end_frame, nframes);
        _amp->run (mixbufs, start_frame, end_frame, nframes, true);
 
        /* consider metering */
@@ -285,7 +306,7 @@ InternalSend::connect_when_legal ()
 }
 
 bool
-InternalSend::can_support_io_configuration (const ChanCount& in, ChanCount& out) const
+InternalSend::can_support_io_configuration (const ChanCount& in, ChanCount& out)
 {
        out = in;
        return true;
@@ -311,7 +332,7 @@ bool
 InternalSend::configure_io (ChanCount in, ChanCount out)
 {
        bool ret = Send::configure_io (in, out);
-       set_block_size (_session.engine().frames_per_cycle());
+       set_block_size (_session.engine().samples_per_cycle());
        return ret;
 }