From acbda29f838280ba98cf9e9e539e9d8a6e8fc6ad Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 9 Jun 2006 15:07:31 +0000 Subject: Added Om aka Graph aka god knows what git-svn-id: http://svn.drobilla.net/lad/grauph@9 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/ConnectionBase.cpp | 96 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/engine/ConnectionBase.cpp (limited to 'src/engine/ConnectionBase.cpp') diff --git a/src/engine/ConnectionBase.cpp b/src/engine/ConnectionBase.cpp new file mode 100644 index 00000000..c8936818 --- /dev/null +++ b/src/engine/ConnectionBase.cpp @@ -0,0 +1,96 @@ +/* This file is part of Om. Copyright (C) 2006 Dave Robillard. + * + * Om is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * Om is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "ConnectionBase.h" +#include "util.h" +#include "InputPort.h" +#include "OutputPort.h" +#include "Node.h" +#include "Om.h" +#include "Port.h" + +namespace Om { + + +/** Constructor for a connection from a node's output port. + * + * This handles both polyphonic and monophonic nodes, transparently to the + * user (InputPort). + */ +template +ConnectionBase::ConnectionBase(OutputPort* const src_port, InputPort* const dst_port) +: Connection(src_port, dst_port), + m_local_buffer(NULL), + m_is_poly_to_mono( (src_port->parent_node()->poly() > dst_port->parent_node()->poly()) ), + m_buffer_size(src_port->buffer_size()), + m_pending_disconnection(false) +{ + assert((src_port->parent_node()->poly() == dst_port->parent_node()->poly()) + || (src_port->parent_node()->poly() == 1 || dst_port->parent_node()->poly() == 1)); + + if (m_is_poly_to_mono) // Poly -> Mono connection, need a buffer to mix in to + m_local_buffer = new Buffer(m_buffer_size); +} +template ConnectionBase::ConnectionBase(OutputPort* const src_port, InputPort* const dst_port); +template ConnectionBase::ConnectionBase(OutputPort* const src_port, InputPort* const dst_port); + + +template +ConnectionBase::~ConnectionBase() +{ + delete m_local_buffer; +} +template ConnectionBase::~ConnectionBase(); +template ConnectionBase::~ConnectionBase(); + + +template +void +ConnectionBase::prepare_buffers() +{ + /* Thought: A poly output port can be connected to multiple mono input + * ports, which means this mix down would have to happen many times. + * Adding a method to OutputPort that mixes down all it's outputs into + * a buffer (if it hasn't been done already this cycle) and returns that + * would avoid having to mix multiple times. Probably not a very common + * case, but it would be faster anyway. */ + + if (m_is_poly_to_mono) { + m_local_buffer->copy(src_port()->buffer(0), 0, m_buffer_size-1); + + // Mix all the source's voices down into local buffer starting at the second + // voice (buffer is already set to first voice above) + for (size_t j=1; j < src_port()->poly(); ++j) + m_local_buffer->accumulate(src_port()->buffer(j), 0, m_buffer_size-1); + + // Scale the buffer down. + if (src_port()->poly() > 1) + m_local_buffer->scale(1.0f/(float)src_port()->poly(), 0, m_buffer_size-1); + } +} +template void ConnectionBase::prepare_buffers(); + + +// FIXME: MIDI mixing not implemented +template <> +void +ConnectionBase::prepare_buffers() +{ +} + + +} // namespace Om + -- cgit v1.2.1