Remove unused method in RouteTimeAxisView. Fix bug with switching to layered region...
[ardour.git] / libs / ardour / audio_port.cc
index 55d65d850d6a69ebf564998bb644ff136ae78282..f69d6685ff3b6c504f636711956aeb10cb75da24 100644 (file)
 */
 
 #include <cassert>
-#include <ardour/audio_port.h>
-#include <ardour/audioengine.h>
-#include <ardour/data_type.h>
-#include <ardour/audio_buffer.h>
+#include "ardour/audio_port.h"
+#include "ardour/audioengine.h"
+#include "ardour/data_type.h"
+#include "ardour/audio_buffer.h"
 
 using namespace ARDOUR;
 using namespace std;
 
-AudioPort::AudioPort (const std::string& name, Flags flags, bool ext, nframes_t capacity)
-       : Port (name, DataType::AUDIO, flags, ext)
-       , _has_been_mixed_down (false)
-       , _buffer (0)
+AudioPort::AudioPort (const std::string& name, Flags flags)
+       : Port (name, DataType::AUDIO, flags)
+       , _buffer (new AudioBuffer (0))
 {
        assert (name.find_first_of (':') == string::npos);
-       
-       if (external ()) {
-               
-               /* external ports use the external port buffer */
-               _buffer = new AudioBuffer (0);
-
-       } else {
-
-               /* internal ports need their own buffers */
-               _buffer = new AudioBuffer (capacity);
-               
-       }
-       
 }
 
-AudioPort::~AudioPort()
+AudioPort::~AudioPort ()
 {
        delete _buffer;
 }
 
 void
-AudioPort::cycle_start (nframes_t nframes, nframes_t offset)
+AudioPort::cycle_start (nframes_t nframes)
 {
        /* caller must hold process lock */
 
-       _has_been_mixed_down = false;
+       /* get_buffer() must only be run on outputs here in cycle_start().
 
-       if (external ()) {
-               /* external ports use JACK's memory */
-               _buffer->set_data ((Sample *) jack_port_get_buffer (_jack_port, nframes), nframes + offset);
+          Inputs must be done in the correct processing order, which 
+          requires interleaving with route processing. that will 
+          happen when Port::get_buffer() is called.
+       */
+
+       if (sends_output()) {
+
+               /* Notice that cycle_start() is always run with the *entire* process cycle frame count,
+                  so we do not bother to apply _port_offset here - we always want the address of the
+                  entire JACK port buffer. We are not collecting data here - just noting the
+                  address where we will write data later in the process cycle.
+               */
+
+               _buffer->set_data ((Sample *) jack_port_get_buffer (_jack_port, nframes), nframes);
+               _buffer->prepare ();
        }
 }
 
-AudioBuffer &
+void
+AudioPort::cycle_end (nframes_t nframes)
+{
+       if (sends_output() && !_buffer->written()) {
+               _buffer->silence (nframes);
+       }
+}
+
+void
+AudioPort::cycle_split ()
+{
+}
+
+AudioBuffer&
 AudioPort::get_audio_buffer (nframes_t nframes, nframes_t offset)
 {
        /* caller must hold process lock */
 
-       if (_has_been_mixed_down) {
-               return *_buffer;
-       }
-
        if (receives_input ()) {
 
-               /* INPUT */
+               /* Get a pointer to the audio data @ offset + _port_offset within the JACK port buffer and store
+                  it in our _buffer member.
 
-               /* If we're external (), we have some data in our buffer set up by JACK;
-                  otherwise, we have an undefined buffer.  In either case we mix down
-                  our non-JACK inputs; either accumulating into the JACK data or
-                  overwriting the undefined data */
-                  
-               mixdown (nframes, offset, !external ());
-               
-       } else {
+                  Note that offset is expected to be zero in almost all cases.
+               */
 
-               /* OUTPUT */
-
-               if (!external ()) {
-                       /* start internal output buffers with silence */
-                       _buffer->silence (nframes, offset);
-               }
-               
-       }
+               _buffer->set_data ((Sample *) jack_port_get_buffer (_jack_port, nframes) + offset + _port_offset, nframes);
+       } 
        
-       if (nframes) {
-               _has_been_mixed_down = true;
-       }
+       /* output ports set their _buffer data information during ::cycle_start()
+        */
 
        return *_buffer;
 }
 
-void
-AudioPort::cycle_end (nframes_t nframes, nframes_t offset)
+size_t
+AudioPort::raw_buffer_size(nframes_t nframes) const
 {
-       _has_been_mixed_down = false;
+       return nframes * sizeof(float);
 }
 
-void
-AudioPort::mixdown (nframes_t cnt, nframes_t offset, bool first_overwrite)
-{
-       if (_connections.empty()) {
-               if (first_overwrite) {
-                       _buffer->silence (cnt, offset);
-               }
-               return;
-       }
-       
-       set<Port*>::const_iterator p = _connections.begin();
-
-       if (first_overwrite) {
-               _buffer->read_from (dynamic_cast<AudioPort*>(*p)->get_audio_buffer (cnt, offset), cnt, offset);
-               ++p;
-       }
-
-       for (; p != _connections.end (); ++p) {
-               _buffer->accumulate_from (dynamic_cast<AudioPort*>(*p)->get_audio_buffer (cnt, offset), cnt, offset);
-       }
-}
-
-void
-AudioPort::reset ()
-{
-       Port::reset ();
-       
-       if (_buffer->capacity () != 0) {
-               _buffer->resize (_engine->frames_per_cycle ());
-               _buffer->clear ();
-       }
-}