*** NEW CODING POLICY ***
[ardour.git] / libs / ardour / buffer_set.cc
index 24af224845e08165e3d3f38761d49002a8c9fe4f..a2dd1109413e67d9c32c6b507397c5220ce9765d 100644 (file)
     675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
+#include <iostream>
 #include <algorithm>
-#include <ardour/buffer_set.h>
-#include <ardour/buffer.h>
-#include <ardour/port.h>
-#include <ardour/port_set.h>
+#include "ardour/buffer_set.h"
+#include "ardour/buffer.h"
+#include "ardour/port.h"
+#include "ardour/port_set.h"
 
 namespace ARDOUR {
 
@@ -61,19 +62,18 @@ BufferSet::clear()
 /** Make this BufferSet a direct mirror of a PortSet's buffers.
  */
 void
-BufferSet::attach_buffers(PortSet& ports)
+BufferSet::attach_buffers(PortSet& ports, nframes_t nframes, nframes_t offset)
 {
        clear();
 
        for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
                _buffers.push_back(BufferVec());
-               BufferVec& v = _buffers[(*t).to_index()];
+               BufferVec& v = _buffers[*t];
 
                for (PortSet::iterator p = ports.begin(*t); p != ports.end(*t); ++p) {
                        assert(p->type() == *t);
-                       v.push_back(&(p->get_buffer()));
+                       v.push_back(&(p->get_buffer(nframes, offset)));
                }
-
        }
        
        _count = ports.count();
@@ -97,13 +97,20 @@ void
 BufferSet::ensure_buffers(DataType type, size_t num_buffers, size_t buffer_capacity)
 {
        assert(type != DataType::NIL);
-       assert(type.to_index() < _buffers.size());
+       assert(type < _buffers.size());
+       assert(buffer_capacity > 0);
 
        if (num_buffers == 0)
                return;
 
+       // FIXME: Kludge to make MIDI buffers larger (size is bytes, not frames)
+       // See MidiPort::MidiPort
+       // We probably need a map<DataType, size_t> parameter for capacity
+       if (type == DataType::MIDI)
+               buffer_capacity *= 8;
+
        // The vector of buffers of the type we care about
-       BufferVec& bufs = _buffers[type.to_index()];
+       BufferVec& bufs = _buffers[type];
        
        // If we're a mirror just make sure we're ok
        if (_is_mirror) {
@@ -146,7 +153,7 @@ size_t
 BufferSet::buffer_capacity(DataType type) const
 {
        assert(_available.get(type) > 0);
-       return _buffers[type.to_index()][0]->capacity();
+       return _buffers[type][0]->capacity();
 }
 
 // FIXME: make 'in' const