From e96c36c1a7abb062e36efc0ac95c35fedcef922e Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 8 Apr 2007 06:04:32 +0000 Subject: De-template-ification of port types (req. for LV2 MIDI, but nice code size reduction). LV2 MIDI patching support (LV2 style MIDI throughout, inc. internal plugins). git-svn-id: http://svn.drobilla.net/lad/ingen@415 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/engine/InputPort.cpp | 86 ++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 51 deletions(-) (limited to 'src/libs/engine/InputPort.cpp') diff --git a/src/libs/engine/InputPort.cpp b/src/libs/engine/InputPort.cpp index 1a792c32..9326afd6 100644 --- a/src/libs/engine/InputPort.cpp +++ b/src/libs/engine/InputPort.cpp @@ -19,7 +19,8 @@ #include #include #include -#include "TypedConnection.h" +#include "AudioBuffer.h" +#include "Connection.h" #include "OutputPort.h" #include "Node.h" #include "util.h" @@ -30,13 +31,10 @@ using std::cerr; using std::cout; using std::endl; namespace Ingen { -template -InputPort::InputPort(Node* parent, const string& name, size_t index, size_t poly, DataType type, size_t buffer_size) -: TypedPort(parent, name, index, poly, type, buffer_size) +InputPort::InputPort(Node* parent, const string& name, size_t index, size_t poly, DataType type, size_t buffer_size) +: Port(parent, name, index, poly, type, buffer_size) { } -template InputPort::InputPort(Node* parent, const string& name, size_t index, size_t poly, DataType type, size_t buffer_size); -template InputPort::InputPort(Node* parent, const string& name, size_t index, size_t poly, DataType type, size_t buffer_size); /** Add a connection. Realtime safe. @@ -44,9 +42,8 @@ template InputPort::InputPort(Node* parent, const string& name, siz * The buffer of this port will be set directly to the connection's buffer * if there is only one connection, since no mixing needs to take place. */ -template void -InputPort::add_connection(Raul::ListNode*>* const c) +InputPort::add_connection(Raul::ListNode* const c) { _connections.push_back(c); @@ -61,7 +58,7 @@ InputPort::add_connection(Raul::ListNode*>* const c) _buffers.at(i)->join(c->elem()->buffer(i)); //if (_is_tied) // _tied_port->buffer(i)->join(_buffers.at(i)); - assert(_buffers.at(i)->data() == c->elem()->buffer(i)->data()); + //assert(_buffers.at(i)->data() == c->elem()->buffer(i)->data()); } } else if (_connections.size() == 2) { // Used to directly use single connection buffer, now there's two @@ -72,30 +69,26 @@ InputPort::add_connection(Raul::ListNode*>* const c) // _tied_port->buffer(i)->join(_buffers.at(i)); } } - TypedPort::connect_buffers(); + Port::connect_buffers(); } //assert( ! _is_tied || _tied_port != NULL); //assert( ! _is_tied || _buffers.at(0)->data() == _tied_port->buffer(0)->data()); } -template void InputPort::add_connection(Raul::ListNode*>* const c); -template void InputPort::add_connection(Raul::ListNode*>* const c); /** Remove a connection. Realtime safe. */ -template -Raul::ListNode*>* -InputPort::remove_connection(const OutputPort* const src_port) +Raul::ListNode* +InputPort::remove_connection(const OutputPort* src_port) { bool modify_buffers = !_fixed_buffers; //if (modify_buffers && _is_tied) // modify_buffers = !_tied_port->fixed_buffers(); - typedef typename Raul::List*>::iterator TypedConnectionListIterator; bool found = false; - Raul::ListNode*>* connection = NULL; - for (TypedConnectionListIterator i = _connections.begin(); i != _connections.end(); ++i) { + Raul::ListNode* connection = NULL; + for (Connections::iterator i = _connections.begin(); i != _connections.end(); ++i) { if ((*i)->src_port()->path() == src_port->path()) { connection = _connections.erase(i); found = true; @@ -103,7 +96,7 @@ InputPort::remove_connection(const OutputPort* const src_port) } if ( ! found) { - cerr << "WARNING: [InputPort::remove_connection] Connection not found !" << endl; + cerr << "WARNING: [InputPort::remove_connection] Connection not found !" << endl; exit(EXIT_FAILURE); } else { if (_connections.size() == 0) { @@ -126,63 +119,55 @@ InputPort::remove_connection(const OutputPort* const src_port) } if (modify_buffers) - TypedPort::connect_buffers(); + Port::connect_buffers(); //assert( ! _is_tied || _tied_port != NULL); //assert( ! _is_tied || _buffers.at(0)->data() == _tied_port->buffer(0)->data()); return connection; } -template Raul::ListNode*>* -InputPort::remove_connection(const OutputPort* const src_port); -template Raul::ListNode*>* -InputPort::remove_connection(const OutputPort* const src_port); /** Returns whether this port is connected to the passed port. */ -template bool -InputPort::is_connected_to(const OutputPort* const port) const +InputPort::is_connected_to(const OutputPort* port) const { - typedef typename Raul::List*>::const_iterator TypedConnectionListIterator; - for (TypedConnectionListIterator i = _connections.begin(); i != _connections.end(); ++i) + for (Connections::const_iterator i = _connections.begin(); i != _connections.end(); ++i) if ((*i)->src_port() == port) return true; return false; } -template bool InputPort::is_connected_to(const OutputPort* const port) const; -template bool InputPort::is_connected_to(const OutputPort* const port) const; /** Prepare buffer for access, mixing if necessary. Realtime safe. * FIXME: nframes parameter not used, */ -template<> void -InputPort::process(SampleCount nframes, FrameTime start, FrameTime end) +InputPort::process(SampleCount nframes, FrameTime start, FrameTime end) { + Port::process(nframes, start, end); + //assert(!_is_tied || _tied_port != NULL); - typedef Raul::List*>::iterator TypedConnectionListIterator; bool do_mixdown = true; if (_connections.size() == 0) return; - for (TypedConnectionListIterator c = _connections.begin(); c != _connections.end(); ++c) + for (Connections::iterator c = _connections.begin(); c != _connections.end(); ++c) (*c)->process(nframes, start, end); // If only one connection, buffer is (maybe) used directly (no copying) if (_connections.size() == 1) { // Buffer changed since connection - if (_buffers.at(0)->data() != (*_connections.begin())->buffer(0)->data()) { + if (!_buffers.at(0)->is_joined_to((*_connections.begin())->buffer(0))) { if (_fixed_buffers) { // || (_is_tied && _tied_port->fixed_buffers())) { // can't change buffer, must copy do_mixdown = true; } else { // zero-copy - assert(_buffers.at(0)->is_joined()); + //assert(_buffers.at(0)->is_joined()); _buffers.at(0)->join((*_connections.begin())->buffer(0)); do_mixdown = false; } @@ -195,7 +180,7 @@ InputPort::process(SampleCount nframes, FrameTime start, FrameTime end) //cerr << path() << " mixing: " << do_mixdown << endl; if (!do_mixdown) { - assert(_buffers.at(0)->data() == (*_connections.begin())->buffer(0)->data()); + assert(_buffers.at(0)->is_joined_to((*_connections.begin())->buffer(0))); return; } @@ -204,28 +189,30 @@ InputPort::process(SampleCount nframes, FrameTime start, FrameTime end) for (size_t voice=0; voice < _poly; ++voice) { // Copy first connection - _buffers.at(voice)->copy((*_connections.begin())->buffer(voice), 0, _buffer_size-1); + ((AudioBuffer*)_buffers.at(voice))->copy( + ((AudioBuffer*)(*_connections.begin())->buffer(voice)), 0, _buffer_size-1); // Accumulate the rest if (_connections.size() > 1) { - TypedConnectionListIterator c = _connections.begin(); + Connections::iterator c = _connections.begin(); for (++c; c != _connections.end(); ++c) - _buffers.at(voice)->accumulate((*c)->buffer(voice), 0, _buffer_size-1); + ((AudioBuffer*)_buffers.at(voice))->accumulate( + ((AudioBuffer*)(*c)->buffer(voice)), 0, _buffer_size-1); } } } +#if 0 /** Prepare buffer for access, realtime safe. * * MIDI mixing not yet implemented. */ -template <> void -InputPort::process(SampleCount nframes, FrameTime start, FrameTime end) -{ +InputPort::process(SampleCount nframes, FrameTime start, FrameTime end) +{ //assert(!_is_tied || _tied_port != NULL); const size_t num_ins = _connections.size(); @@ -233,10 +220,9 @@ InputPort::process(SampleCount nframes, FrameTime start, FrameTime assert(num_ins == 0 || num_ins == 1); - typedef Raul::List*>::iterator TypedConnectionListIterator; assert(_poly == 1); - for (TypedConnectionListIterator c = _connections.begin(); c != _connections.end(); ++c) + for (Connections::iterator c = _connections.begin(); c != _connections.end(); ++c) (*c)->process(nframes, start, end); @@ -298,21 +284,19 @@ InputPort::process(SampleCount nframes, FrameTime start, FrameTime for (size_t i=0; i < _buffers.at(0)->filled_size(); ++i) _buffers.at(0)[i] = (*_connections.begin())->buffer(0)[i]; } +#endif -template void -InputPort::set_buffer_size(size_t size) +InputPort::set_buffer_size(size_t size) { - TypedPort::set_buffer_size(size); + Port::set_buffer_size(size); assert(_buffer_size = size); - for (typename Raul::List*>::iterator c = _connections.begin(); c != _connections.end(); ++c) + for (Raul::List::iterator c = _connections.begin(); c != _connections.end(); ++c) (*c)->set_buffer_size(size); } -template void InputPort::set_buffer_size(size_t size); -template void InputPort::set_buffer_size(size_t size); } // namespace Ingen -- cgit v1.2.1