From 732bfb33105b4a534bc17caae9a50a1ccfcd7570 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 24 Oct 2015 19:27:39 +0000 Subject: Zero-copy to/from driver ports where possible git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@5778 a436a847-0d15-0410-975c-d299462d15a1 --- src/server/events/Connect.cpp | 16 ++++++++++------ src/server/events/CreatePort.cpp | 18 ++++++++++++------ src/server/events/Disconnect.cpp | 35 +++++++++++++++++++++-------------- src/server/events/SetPortValue.cpp | 2 +- 4 files changed, 44 insertions(+), 27 deletions(-) (limited to 'src/server/events') diff --git a/src/server/events/Connect.cpp b/src/server/events/Connect.cpp index 1f22e6f2..5eff8854 100644 --- a/src/server/events/Connect.cpp +++ b/src/server/events/Connect.cpp @@ -123,11 +123,13 @@ Connect::pre_process() lock.unlock(); - _voices = new Raul::Array(_head->poly()); - _head->get_buffers(*_engine.buffer_factory(), - _voices, - _head->poly(), - false); + if (!_head->is_driver_port()) { + _voices = new Raul::Array(_head->poly()); + _head->get_buffers(*_engine.buffer_factory(), + _voices, + _head->poly(), + false); + } if (_graph->enabled()) { _compiled_graph = _graph->compile(); @@ -141,7 +143,9 @@ Connect::execute(ProcessContext& context) { if (_status == Status::SUCCESS) { _head->add_arc(context, _arc.get()); - _engine.maid()->dispose(_head->set_voices(context, _voices)); + if (!_head->is_driver_port()) { + _engine.maid()->dispose(_head->set_voices(context, _voices)); + } _head->connect_buffers(); _graph->set_compiled_graph(_compiled_graph); } diff --git a/src/server/events/CreatePort.cpp b/src/server/events/CreatePort.cpp index 173b8a73..0b58ee89 100644 --- a/src/server/events/CreatePort.cpp +++ b/src/server/events/CreatePort.cpp @@ -125,12 +125,19 @@ CreatePort::pre_process() poly_i->second.type() == uris.forge.Bool && poly_i->second.get()); - if (!(_graph_port = _graph->create_port( - bufs, Raul::Symbol(_path.symbol()), - _port_type, _buf_type, buf_size, _is_output, polyphonic))) { - return Event::pre_process_done(Status::CREATION_FAILED, _path); + // Create 0 value if the port requires one + Atom value; + if (_port_type == PortType::CONTROL || _port_type == PortType::CV) { + value = bufs.forge().make(0.0f); } + // Create port + _graph_port = new DuplexPort(bufs, _graph, Raul::Symbol(_path.symbol()), + _graph->num_ports_non_rt(), + polyphonic, + _port_type, _buf_type, buf_size, + value, _is_output); + _graph_port->properties().insert(_properties.begin(), _properties.end()); _engine.store()->add(_graph_port); @@ -141,8 +148,7 @@ CreatePort::pre_process() } if (!_graph->parent()) { - _engine_port = _engine.driver()->create_port( - dynamic_cast(_graph_port)); + _engine_port = _engine.driver()->create_port(_graph_port); } _ports_array = new Raul::Array(old_n_ports + 1, NULL); diff --git a/src/server/events/Disconnect.cpp b/src/server/events/Disconnect.cpp index 87c192b4..66aee38e 100644 --- a/src/server/events/Disconnect.cpp +++ b/src/server/events/Disconnect.cpp @@ -91,21 +91,25 @@ Disconnect::Impl::Impl(Engine& e, _dst_input_port->decrement_num_arcs(); if (_dst_input_port->num_arcs() == 0) { - _voices = new Raul::Array(_dst_input_port->poly()); - _dst_input_port->get_buffers(*_engine.buffer_factory(), - _voices, - _dst_input_port->poly(), - false); - - const bool is_control = _dst_input_port->is_a(PortType::CONTROL) || - _dst_input_port->is_a(PortType::CV); - const float value = is_control ? _dst_input_port->value().get() : 0; - for (uint32_t i = 0; i < _voices->size(); ++i) { - if (is_control) { - Buffer* buf = _voices->at(i).buffer.get(); - buf->set_block(value, 0, buf->nframes()); + if (!_dst_input_port->is_driver_port()) { + _voices = new Raul::Array(_dst_input_port->poly()); + _dst_input_port->get_buffers(*_engine.buffer_factory(), + _voices, + _dst_input_port->poly(), + false); + + if (_dst_input_port->is_a(PortType::CONTROL) || + _dst_input_port->is_a(PortType::CV)) { + // Reset buffer to control value + const float value = _dst_input_port->value().get(); + for (uint32_t i = 0; i < _voices->size(); ++i) { + Buffer* buf = _voices->at(i).buffer.get(); + buf->set_block(value, 0, buf->nframes()); + } } else { - _voices->at(i).buffer->clear(); + for (uint32_t i = 0; i < _voices->size(); ++i) { + _voices->at(i).buffer->clear(); + } } } } @@ -177,8 +181,11 @@ Disconnect::Impl::execute(ProcessContext& context, bool set_dst_buffers) { ArcImpl* const port_arc = _dst_input_port->remove_arc(context, _src_output_port); + if (!port_arc) { return false; + } else if (_dst_input_port->is_driver_port()) { + return true; } if (set_dst_buffers) { diff --git a/src/server/events/SetPortValue.cpp b/src/server/events/SetPortValue.cpp index e069e474..fd10c94f 100644 --- a/src/server/events/SetPortValue.cpp +++ b/src/server/events/SetPortValue.cpp @@ -107,7 +107,7 @@ SetPortValue::apply(Context& context) _status = Status::NO_SPACE; } } else if (buf->type() == uris.atom_URID) { - ((LV2_Atom_URID*)buf->atom())->body = _value.get(); + buf->get()->body = _value.get(); } else { _status = Status::BAD_VALUE_TYPE; } -- cgit v1.2.1