From 30ab1fd61569f9d7fb7410d483fa68cbf9865c37 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 12 Aug 2006 08:20:24 +0000 Subject: Towards MIDI: - Converted vector to BufferList and numerous counts from int to ChanCount (and related changes) - Added fancy type-generic iterators to BufferList, PortIterator (see IO::collect_input for a good example of the idea - the same code will work to read all input (of various types in a single IO, eg instruments) without modification no matter how many types we add) - Fixed comparison operator bugs with ChanCount (screwed up metering among other things) - Moved peak metering into it's own object, and moved most of the pan related code out of IO to panner (still a touch more to be done here for MIDI playback) Not directly MIDI related fixes for problems in trunk: - Fixed varispeed gain/pan automation to work properly (was reading the wrong range of automation data, probably causing nasty clicks?) - Fixed crash on varispeed looping (possibly only a 64-bit problem). It still doesn't work, but at least it doesn't die Quite a few things broken, and the new classes are pretty filthy still, but I think the direction is a lot better than all my previous plans... git-svn-id: svn://localhost/ardour2/branches/midi@795 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/buffer_set.cc | 87 +++++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 37 deletions(-) (limited to 'libs/ardour/buffer_set.cc') diff --git a/libs/ardour/buffer_set.cc b/libs/ardour/buffer_set.cc index c479b6c405..3989df2ad2 100644 --- a/libs/ardour/buffer_set.cc +++ b/libs/ardour/buffer_set.cc @@ -18,26 +18,12 @@ #include #include +#include +#include +#include namespace ARDOUR { - -/** Create a BufferSet to mirror a PortSet */ -BufferSet::BufferSet(const PortSet& ports) - : _count(ports.chan_count()) - , _is_mirror(true) -{ - for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) { - BufferVec v; - - for (size_t j=0; j < ports.num_ports(*t); ++j) { - v.push_back(&ports.nth_port_of_type(*t, j)->get_buffer()); - } - - _buffers.push_back(v); - } -} - /** Create a new, empty BufferSet */ BufferSet::BufferSet() : _is_mirror(false) @@ -46,36 +32,60 @@ BufferSet::BufferSet() _buffers.push_back( BufferVec() ); _count.reset(); + _available.reset(); } - BufferSet::~BufferSet() { - if (!_is_mirror) - clear(); + clear(); } - /** Destroy all contained buffers. */ void BufferSet::clear() { - for (std::vector::iterator i = _buffers.begin(); i != _buffers.end(); ++i) { - for (BufferVec::iterator j = (*i).begin(); j != (*i).end(); ++j) { - delete *j; + if (!_is_mirror) { + for (std::vector::iterator i = _buffers.begin(); i != _buffers.end(); ++i) { + for (BufferVec::iterator j = (*i).begin(); j != (*i).end(); ++j) { + delete *j; + } + (*i).clear(); } - (*i).clear(); } _buffers.clear(); + _count.reset(); + _available.reset(); } +/** Make this BufferSet a direct mirror of a PortSet's buffers. + */ +void +BufferSet::attach_buffers(PortSet& ports) +{ + clear(); + + for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) { + _buffers.push_back(BufferVec()); + BufferVec& v = _buffers[(*t).to_index()]; + + for (PortSet::iterator p = ports.begin(*t); p != ports.end(*t); ++p) { + assert(p->type() == *t); + v.push_back(&(p->get_buffer())); + } + + } + + _count = ports.count(); + + _is_mirror = true; +} void -BufferSet::ensure_buffers(const ChanCount& chan_count, size_t buffer_capacity) +BufferSet::ensure_buffers(const ChanCount& count, size_t buffer_capacity) { for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) { - ensure_buffers(chan_count.get(*t), *t, buffer_capacity); + ensure_buffers(*t, count.get(*t), buffer_capacity); } } @@ -84,7 +94,7 @@ BufferSet::ensure_buffers(const ChanCount& chan_count, size_t buffer_capacity) * each of size at least @a buffer_size */ void -BufferSet::ensure_buffers(size_t num_buffers, DataType type, size_t buffer_capacity) +BufferSet::ensure_buffers(DataType type, size_t num_buffers, size_t buffer_capacity) { assert(type != DataType::NIL); assert(type.to_index() < _buffers.size()); @@ -94,6 +104,13 @@ BufferSet::ensure_buffers(size_t num_buffers, DataType type, size_t buffer_capac // The vector of buffers of the type we care about BufferVec& bufs = _buffers[type.to_index()]; + + // If we're a mirror just make sure we're ok + if (_is_mirror) { + assert(_count.get(type) >= num_buffers); + assert(bufs[0]->type() == type); + return; + } // If there's not enough or they're too small, just nuke the whole thing and // rebuild it (so I'm lazy..) @@ -110,21 +127,17 @@ BufferSet::ensure_buffers(size_t num_buffers, DataType type, size_t buffer_capac for (size_t i=0; i < num_buffers; ++i) { bufs.push_back(Buffer::create(type, buffer_capacity)); } + + _available.set(type, num_buffers); } // Post-conditions + assert(bufs[0]->type() == type); assert(bufs.size() >= num_buffers); - assert((bufs[0])->type() == type); + assert(bufs.size() == _available.get(type)); assert(bufs[0]->capacity() >= buffer_capacity); } -size_t -BufferSet::available_buffers(DataType type) const -{ - return _buffers[type.to_symbol()-1].size(); -} - - /** Get the capacity (size) of the available buffers of the given type. * * All buffers of a certain type always have the same capacity. @@ -132,7 +145,7 @@ BufferSet::available_buffers(DataType type) const size_t BufferSet::buffer_capacity(DataType type) const { - assert(available_buffers(type) > 0); + assert(_available.get(type) > 0); return _buffers[type.to_index()][0]->capacity(); } -- cgit v1.2.3