From 8d92e5a38e141236b3687e8d775ee5d034127fb8 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 14 Oct 2016 15:07:57 -0400 Subject: Fix communication with connected sequence ports --- src/server/InputPort.cpp | 32 ++++++++++++++------------------ src/server/PortImpl.cpp | 1 - src/server/PortImpl.hpp | 8 +++++--- src/server/events/SetPortValue.cpp | 31 ++++++++++++++++++++++++------- src/server/events/SetPortValue.hpp | 2 ++ 5 files changed, 45 insertions(+), 29 deletions(-) (limited to 'src/server') diff --git a/src/server/InputPort.cpp b/src/server/InputPort.cpp index c4f44440..7754a809 100644 --- a/src/server/InputPort.cpp +++ b/src/server/InputPort.cpp @@ -143,12 +143,7 @@ InputPort::max_tail_poly(RunContext& context) const void InputPort::pre_process(RunContext& context) { - if (_set_by_user) { - // Value has been set (e.g. events pushed) by the user, don't smash it - for (uint32_t v = 0; v < _poly; ++v) { - buffer(v)->update_value_buffer(context.offset()); - } - } else if (_arcs.empty()) { + if (_arcs.empty()) { // No incoming arcs, just handle user-set value for (uint32_t v = 0; v < _poly; ++v) { // Update set state @@ -175,14 +170,20 @@ InputPort::pre_process(RunContext& context) void InputPort::pre_run(RunContext& context) { - if (!_set_by_user && !_arcs.empty() && !direct_connect()) { + if ((_user_buffer || !_arcs.empty()) && !direct_connect()) { const uint32_t src_poly = max_tail_poly(context); - const uint32_t max_n_srcs = _arcs.size() * src_poly; + const uint32_t max_n_srcs = _arcs.size() * src_poly + 1; for (uint32_t v = 0; v < _poly; ++v) { // Get all sources for this voice const Buffer* srcs[max_n_srcs]; uint32_t n_srcs = 0; + + if (_user_buffer) { + // Add buffer with user/UI input for this cycle + srcs[n_srcs++] = _user_buffer.get(); + } + for (const auto& arc : _arcs) { if (_poly == 1) { // P -> 1 or 1 -> 1: all tail voices => each head voice @@ -234,15 +235,9 @@ InputPort::post_process(RunContext& context) _force_monitor_update = false; } - if (_set_by_user) { - if (_buffer_type == _bufs.uris().atom_Sequence) { - // Clear events received via a SetPortValue - for (uint32_t v = 0; v < _poly; ++v) { - buffer(v)->prepare_write(context); - } - } - _set_by_user = false; - } + /* Finished processing any user/UI messages for this cycle, drop reference + to user buffer. */ + _user_buffer.reset(); } bool @@ -250,7 +245,8 @@ InputPort::direct_connect() const { return _arcs.size() == 1 && !_parent->path().is_root() - && !_arcs.front().must_mix(); + && !_arcs.front().must_mix() + && buffer(0)->type() != _bufs.uris().atom_Sequence; } } // namespace Server diff --git a/src/server/PortImpl.cpp b/src/server/PortImpl.cpp index f09cfd6e..c99a26fb 100644 --- a/src/server/PortImpl.cpp +++ b/src/server/PortImpl.cpp @@ -69,7 +69,6 @@ PortImpl::PortImpl(BufferFactory& bufs, , _prepared_voices(NULL) , _monitored(false) , _force_monitor_update(false) - , _set_by_user(false) , _is_morph(false) , _is_auto_morph(false) , _is_logarithmic(false) diff --git a/src/server/PortImpl.hpp b/src/server/PortImpl.hpp index 41666523..e497176c 100644 --- a/src/server/PortImpl.hpp +++ b/src/server/PortImpl.hpp @@ -196,6 +196,7 @@ public: bool has_value() const; PortType type() const { return _type; } + LV2_URID value_type() const { return _value.is_valid() ? _value.type() : 0; } LV2_URID buffer_type() const { return _buffer_type; } bool supports(const URIs::Quark& value_type) const; @@ -225,12 +226,13 @@ public: /** Monitor port value and broadcast to clients periodically. */ void monitor(RunContext& context, bool send_now=false); - void raise_set_by_user_flag() { _set_by_user = true; } - BufferFactory& bufs() const { return _bufs; } BufferRef value_buffer(uint32_t voice); + BufferRef user_buffer(RunContext&) const { return _user_buffer; } + void set_user_buffer(RunContext&, BufferRef b) { _user_buffer = b; } + /** Return offset of the first value change after `offset`. */ virtual SampleCount next_value_offset(SampleCount offset, SampleCount end) const; @@ -280,9 +282,9 @@ protected: Atom _max; Raul::Array* _voices; Raul::Array* _prepared_voices; + BufferRef _user_buffer; bool _monitored; bool _force_monitor_update; - bool _set_by_user; bool _is_morph; bool _is_auto_morph; bool _is_logarithmic; diff --git a/src/server/events/SetPortValue.cpp b/src/server/events/SetPortValue.cpp index 9530e2d3..2af9841b 100644 --- a/src/server/events/SetPortValue.cpp +++ b/src/server/events/SetPortValue.cpp @@ -55,6 +55,7 @@ SetPortValue::~SetPortValue() bool SetPortValue::pre_process(PreProcessContext& ctx) { + Ingen::URIs& uris = _engine.world()->uris(); if (_port->is_output()) { return Event::pre_process_done(Status::DIRECTION_MISMATCH, _port->path()); } @@ -65,6 +66,15 @@ SetPortValue::pre_process(PreProcessContext& ctx) _binding = _engine.control_bindings()->port_binding(_port); + if (_port->buffer_type() == uris.atom_Sequence) { + _buffer = _engine.buffer_factory()->get_buffer( + _port->buffer_type(), + _port->value_type(), + _engine.buffer_factory()->default_size(_port->buffer_type()), + false, + false); + } + return Event::pre_process_done(Status::SUCCESS); } @@ -84,7 +94,16 @@ SetPortValue::apply(RunContext& context) } Ingen::URIs& uris = _engine.world()->uris(); - Buffer* const buf = _port->buffer(0).get(); + Buffer* buf = _port->buffer(0).get(); + + if (_buffer) { + if (_port->user_buffer(context)) { + buf = _port->user_buffer(context).get(); + } else { + _port->set_user_buffer(context, _buffer); + buf = _buffer.get(); + } + } if (buf->type() == uris.atom_Sound || buf->type() == uris.atom_Float) { if (_value.type() == uris.forge.Float) { @@ -93,12 +112,10 @@ SetPortValue::apply(RunContext& context) _status = Status::TYPE_MISMATCH; } } else if (buf->type() == uris.atom_Sequence) { - if (buf->append_event(_time - context.start(), - _value.size(), - _value.type(), - (const uint8_t*)_value.get_body())) { - _port->raise_set_by_user_flag(); - } else { + if (!buf->append_event(_time - context.start(), + _value.size(), + _value.type(), + (const uint8_t*)_value.get_body())) { _status = Status::NO_SPACE; } } else if (buf->type() == uris.atom_URID) { diff --git a/src/server/events/SetPortValue.hpp b/src/server/events/SetPortValue.hpp index aac5e033..03902acb 100644 --- a/src/server/events/SetPortValue.hpp +++ b/src/server/events/SetPortValue.hpp @@ -19,6 +19,7 @@ #include "ingen/Atom.hpp" +#include "BufferRef.hpp" #include "ControlBindings.hpp" #include "Event.hpp" #include "types.hpp" @@ -58,6 +59,7 @@ private: PortImpl* _port; const Atom _value; + BufferRef _buffer; ControlBindings::Key _binding; bool _synthetic; }; -- cgit v1.2.1