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/events/ConnectionEvent.cpp | 146 +++++++---------------------- 1 file changed, 33 insertions(+), 113 deletions(-) (limited to 'src/libs/engine/events/ConnectionEvent.cpp') diff --git a/src/libs/engine/events/ConnectionEvent.cpp b/src/libs/engine/events/ConnectionEvent.cpp index da723a8c..af35265b 100644 --- a/src/libs/engine/events/ConnectionEvent.cpp +++ b/src/libs/engine/events/ConnectionEvent.cpp @@ -22,7 +22,7 @@ #include "Responder.h" #include "types.h" #include "Engine.h" -#include "TypedConnection.h" +#include "Connection.h" #include "InputPort.h" #include "OutputPort.h" #include "Patch.h" @@ -34,9 +34,6 @@ using std::string; namespace Ingen { -//// ConnectionEvent //// - - ConnectionEvent::ConnectionEvent(Engine& engine, SharedPtr responder, SampleCount timestamp, const string& src_port_path, const string& dst_port_path) : QueuedEvent(engine, responder, timestamp), _src_port_path(src_port_path), @@ -44,18 +41,15 @@ ConnectionEvent::ConnectionEvent(Engine& engine, SharedPtr responder, _patch(NULL), _src_port(NULL), _dst_port(NULL), - _typed_event(NULL), + _process_order(NULL), + _connection(NULL), + _patch_listnode(NULL), + _port_listnode(NULL), _error(NO_ERROR) { } -ConnectionEvent::~ConnectionEvent() -{ - delete _typed_event; -} - - void ConnectionEvent::pre_process() { @@ -67,14 +61,6 @@ ConnectionEvent::pre_process() return; } - /*_patch = _engine.object_store()->find_patch(_src_port_path.parent().parent()); - - if (_patch == NULL) { - _error = PORT_NOT_FOUND; - QueuedEvent::pre_process(); - return; - }*/ - _src_port = _engine.object_store()->find_port(_src_port_path); _dst_port = _engine.object_store()->find_port(_dst_port_path); @@ -84,96 +70,33 @@ ConnectionEvent::pre_process() return; } - if (_src_port->type() != _dst_port->type() || _src_port->buffer_size() != _dst_port->buffer_size()) { + if (_src_port->type() != _dst_port->type()) { _error = TYPE_MISMATCH; QueuedEvent::pre_process(); return; } - - /*if (port1->is_output() && port2->is_input()) { - _src_port = port1; - _dst_port = port2; - } else if (port2->is_output() && port1->is_input()) { - _src_port = port2; - _dst_port = port1; - } else { + + // FIXME: MIDI buffer size is a kluge all around + if (_src_port->type() == DataType::FLOAT + && _src_port->buffer_size() != _dst_port->buffer_size()) { _error = TYPE_MISMATCH; QueuedEvent::pre_process(); return; - }*/ - - // Create the typed event to actually do the work - const DataType type = _src_port->type(); - if (type == DataType::FLOAT) { - _typed_event = new TypedConnectionEvent(_engine, _responder, _time, - dynamic_cast*>(_src_port), dynamic_cast*>(_dst_port)); - } else if (type == DataType::MIDI) { - _typed_event = new TypedConnectionEvent(_engine, _responder, _time, - dynamic_cast*>(_src_port), dynamic_cast*>(_dst_port)); - } else { + } + + /*if ( !( _src_port->is_output() && _dst_port->is_input() ) ) { _error = TYPE_MISMATCH; QueuedEvent::pre_process(); return; - } - - assert(_typed_event); - _typed_event->pre_process(); - assert(_typed_event->is_prepared()); - - QueuedEvent::pre_process(); -} - - -void -ConnectionEvent::execute(SampleCount nframes, FrameTime start, FrameTime end) -{ - QueuedEvent::execute(nframes, start, end); - - if (_error == NO_ERROR) - _typed_event->execute(nframes, start, end); -} - - -void -ConnectionEvent::post_process() -{ - if (_error == NO_ERROR) { - _typed_event->post_process(); - } else { - // FIXME: better error messages - string msg = "Unable to make connection "; - msg.append(_src_port_path + " -> " + _dst_port_path); - _responder->respond_error(msg); - } -} - - - -//// TypedConnectionEvent //// - - -template -TypedConnectionEvent::TypedConnectionEvent(Engine& engine, SharedPtr responder, SampleCount timestamp, OutputPort* src_port, InputPort* dst_port) -: QueuedEvent(engine, responder, timestamp), - _src_port(src_port), - _dst_port(dst_port), - _patch(NULL), - _process_order(NULL), - _connection(NULL), - _port_listnode(NULL), - _succeeded(true) -{ - assert(src_port != NULL); - assert(dst_port != NULL); -} + }*/ + _dst_input_port = dynamic_cast(_dst_port); + _src_output_port = dynamic_cast(_src_port); + assert(_src_output_port); + assert(_dst_input_port); -template -void -TypedConnectionEvent::pre_process() -{ - if (_dst_port->is_connected_to(_src_port)) { - _succeeded = false; + if (_dst_input_port->is_connected_to(_src_output_port)) { + _error = ALREADY_CONNECTED; QueuedEvent::pre_process(); return; } @@ -202,19 +125,19 @@ TypedConnectionEvent::pre_process() assert(_patch); if (src_node == NULL || dst_node == NULL) { - _succeeded = false; + _error = PARENTS_NOT_FOUND; QueuedEvent::pre_process(); return; } if (_patch != src_node && src_node->parent() != _patch && dst_node->parent() != _patch) { - _succeeded = false; + _error = PARENTS_NOT_FOUND; QueuedEvent::pre_process(); return; } - _connection = new TypedConnection(_src_port, _dst_port); - _port_listnode = new Raul::ListNode*>(_connection); + _connection = new Connection(_src_port, _dst_port); + _port_listnode = new Raul::ListNode(_connection); _patch_listnode = new Raul::ListNode(_connection); // Need to be careful about patch port connections here and adding a node's @@ -227,20 +150,18 @@ TypedConnectionEvent::pre_process() if (_patch->enabled()) _process_order = _patch->build_process_order(); - _succeeded = true; QueuedEvent::pre_process(); } -template void -TypedConnectionEvent::execute(SampleCount nframes, FrameTime start, FrameTime end) +ConnectionEvent::execute(SampleCount nframes, FrameTime start, FrameTime end) { QueuedEvent::execute(nframes, start, end); - if (_succeeded) { + if (_error == NO_ERROR) { // These must be inserted here, since they're actually used by the audio thread - _dst_port->add_connection(_port_listnode); + _dst_input_port->add_connection(_port_listnode); _patch->add_connection(_patch_listnode); if (_patch->process_order() != NULL) _engine.maid()->push(_patch->process_order()); @@ -249,18 +170,17 @@ TypedConnectionEvent::execute(SampleCount nframes, FrameTime start, FrameTime } -template void -TypedConnectionEvent::post_process() +ConnectionEvent::post_process() { - if (_succeeded) { - assert(_connection != NULL); - + if (_error == NO_ERROR) { _responder->respond_ok(); - _engine.broadcaster()->send_connection(_connection); } else { - _responder->respond_error("Unable to make connection."); + // FIXME: better error messages + string msg = "Unable to make connection "; + msg.append(_src_port_path + " -> " + _dst_port_path); + _responder->respond_error(msg); } } -- cgit v1.2.1