From 94f372e95ecd718b7d2ed4f2aa1f0437e7968efb Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 23 Mar 2012 13:56:39 +0000 Subject: Fix compilation with latest LV2. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4102 a436a847-0d15-0410-975c-d299462d15a1 --- src/server/ConnectionImpl.cpp | 4 ++- src/server/InputPort.cpp | 6 ++-- src/server/LV2Info.cpp | 4 +-- src/server/LV2Node.cpp | 55 +++++++++---------------------------- src/server/LV2Node.hpp | 6 ++-- src/server/LV2RequestRunFeature.hpp | 35 +++++++++++++---------- src/server/LV2ResizeFeature.hpp | 7 ++--- src/server/MessageContext.cpp | 25 ++--------------- src/server/MessageContext.hpp | 2 +- src/server/NodeImpl.cpp | 44 +++++------------------------ src/server/NodeImpl.hpp | 33 ++++++++++------------ src/server/PatchImpl.cpp | 7 ++--- src/server/PortImpl.cpp | 25 ++--------------- src/server/PortImpl.hpp | 4 --- src/server/events/SetPortValue.cpp | 5 ++-- 15 files changed, 78 insertions(+), 184 deletions(-) (limited to 'src') diff --git a/src/server/ConnectionImpl.cpp b/src/server/ConnectionImpl.cpp index 7a4d7dda..7abda828 100644 --- a/src/server/ConnectionImpl.cpp +++ b/src/server/ConnectionImpl.cpp @@ -30,6 +30,7 @@ #include "Engine.hpp" #include "InputPort.hpp" #include "MessageContext.hpp" +#include "NodeImpl.hpp" #include "OutputPort.hpp" #include "PortImpl.hpp" #include "ProcessContext.hpp" @@ -151,7 +152,8 @@ ConnectionImpl::must_mix() const bool ConnectionImpl::must_queue() const { - return _src_port->context() != _dst_port->context(); + return _src_port->parent_node()->context() + != _dst_port->parent_node()->context(); } bool diff --git a/src/server/InputPort.cpp b/src/server/InputPort.cpp index 42d6c83d..7e3a0fda 100644 --- a/src/server/InputPort.cpp +++ b/src/server/InputPort.cpp @@ -94,7 +94,8 @@ InputPort::get_buffers(BufferFactory& bufs, } else if (num_connections == 1) { if (ThreadManager::thread_is(THREAD_PROCESS)) { - if (!_connections.front().must_mix() && !_connections.front().must_queue()) { + if (!_connections.front().must_mix() && + !_connections.front().must_queue()) { // Single non-mixing conneciton, use buffers directly for (uint32_t v = 0; v < poly; ++v) buffers->at(v) = _connections.front().buffer(v); @@ -229,8 +230,7 @@ InputPort::post_process(Context& context) bool InputPort::direct_connect() const { - return (context() == Context::AUDIO) - && _connections.size() == 1 + return _connections.size() == 1 && !_connections.front().must_mix() && !_connections.front().must_queue(); } diff --git a/src/server/LV2Info.cpp b/src/server/LV2Info.cpp index 130d5dfe..07c9b2a7 100644 --- a/src/server/LV2Info.cpp +++ b/src/server/LV2Info.cpp @@ -17,12 +17,10 @@ #define __STDC_LIMIT_MACROS 1 +#include #include -#include - #include "lv2/lv2plug.in/ns/ext/atom/atom.h" -#include "lv2/lv2plug.in/ns/ext/contexts/contexts.h" #include "ingen/shared/World.hpp" #include "ingen/shared/LV2Features.hpp" diff --git a/src/server/LV2Node.cpp b/src/server/LV2Node.cpp index 4dc9de0c..d9934823 100644 --- a/src/server/LV2Node.cpp +++ b/src/server/LV2Node.cpp @@ -57,7 +57,7 @@ LV2Node::LV2Node(LV2Plugin* plugin, , _lv2_plugin(plugin) , _instances(NULL) , _prepared_instances(NULL) - , _message_funcs(NULL) + , _worker_iface(NULL) { assert(_lv2_plugin); } @@ -149,11 +149,12 @@ LV2Node::instantiate(BufferFactory& bufs) _ports = new Raul::Array(num_ports, NULL); _instances = new Instances(_polyphony, SharedPtr()); - _features = info->world().lv2_features()->lv2_features(&info->world(), this); + _features = info->world().lv2_features()->lv2_features(&info->world(), + this); uint32_t port_buffer_size = 0; - LilvNode* ctx_ext_uri = lilv_new_uri(info->lv2_world(), - LV2_CONTEXTS_URI "#messageContext"); + LilvNode* work_schedule = lilv_new_uri(info->lv2_world(), + LV2_WORKER__schedule); for (uint32_t i = 0; i < _polyphony; ++i) { (*_instances)[i] = SharedPtr( @@ -166,19 +167,14 @@ LV2Node::instantiate(BufferFactory& bufs) return false; } - if (!lilv_plugin_has_feature(plug, ctx_ext_uri)) - continue; - - const void* ctx_ext = lilv_instance_get_extension_data( - instance(i), LV2_CONTEXTS_URI "#messageContext"); - - if (i == 0 && ctx_ext) { - assert(!_message_funcs); - _message_funcs = (LV2_Contexts_MessageContext*)ctx_ext; + if (i == 0 && lilv_plugin_has_feature(plug, work_schedule)) { + _worker_iface = (LV2_Worker_Interface*) + lilv_instance_get_extension_data(instance(i), + LV2_WORKER__Interface); } } - lilv_node_free(ctx_ext_uri); + lilv_node_free(work_schedule); string port_name; Path port_path; @@ -342,23 +338,6 @@ LV2Node::instantiate(BufferFactory& bufs) } } - LilvNodes* contexts = lilv_port_get_value(plug, id, context_pred); - LILV_FOREACH(nodes, i, contexts) { - const LilvNode* c = lilv_nodes_get(contexts, i); - const char* context = lilv_node_as_string(c); - if (!strcmp(LV2_CONTEXTS_URI "#messageContext", context)) { - if (!_message_funcs) { - warn << _lv2_plugin->uri() - << " has a message port, but no context extension data." << endl; - } - port->set_context(Context::MESSAGE); - } else { - warn << _lv2_plugin->uri() << " port " << i << " has unknown context " - << lilv_node_as_string(c) - << endl; - } - } - _ports->at(j) = port; } @@ -399,19 +378,11 @@ LV2Node::deactivate() } void -LV2Node::message_run(MessageContext& context) +LV2Node::work(MessageContext& context, uint32_t size, const void* data) { - for (size_t i = 0; i < num_ports(); ++i) { - PortImpl* const port = _ports->at(i); - if (port->context() == Context::MESSAGE) - port->pre_process(context); + if (_worker_iface) { + _worker_iface->work(instance(0), NULL, NULL, size, data); } - - if (!_valid_ports) - _valid_ports = calloc(num_ports() / 8, 1); - - if (_message_funcs) - (*_message_funcs->run)(instance(0)->lv2_handle, _valid_ports, _valid_ports); } void diff --git a/src/server/LV2Node.hpp b/src/server/LV2Node.hpp index d668072f..3c593e4c 100644 --- a/src/server/LV2Node.hpp +++ b/src/server/LV2Node.hpp @@ -23,7 +23,7 @@ #include #include "lilv/lilv.h" -#include "lv2/lv2plug.in/ns/ext/contexts/contexts.h" +#include "lv2/lv2plug.in/ns/ext/worker/worker.h" #include "NodeImpl.hpp" #include "ingen/shared/LV2Features.hpp" @@ -57,7 +57,7 @@ public: void activate(BufferFactory& bufs); void deactivate(); - void message_run(MessageContext& context); + void work(MessageContext& context, uint32_t size, const void* data); void process(ProcessContext& context); @@ -74,7 +74,7 @@ protected: LV2Plugin* _lv2_plugin; Instances* _instances; Instances* _prepared_instances; - LV2_Contexts_MessageContext* _message_funcs; + LV2_Worker_Interface* _worker_iface; SharedPtr _features; }; diff --git a/src/server/LV2RequestRunFeature.hpp b/src/server/LV2RequestRunFeature.hpp index a14c7df0..7f007962 100644 --- a/src/server/LV2RequestRunFeature.hpp +++ b/src/server/LV2RequestRunFeature.hpp @@ -18,7 +18,7 @@ #ifndef INGEN_ENGINE_LV2_REQUEST_RUN_FEATURE_HPP #define INGEN_ENGINE_LV2_REQUEST_RUN_FEATURE_HPP -#include "lv2/lv2plug.in/ns/ext/contexts/contexts.h" +#include "lv2/lv2plug.in/ns/ext/worker/worker.h" #include "raul/log.hpp" @@ -37,22 +37,27 @@ namespace Ingen { namespace Server { struct RequestRunFeature : public Ingen::Shared::LV2Features::Feature { - struct Data { - inline Data(Shared::World* w, Node* n) : world(w), node(n) {} + struct Info { + inline Info(Shared::World* w, Node* n) : world(w), node(n) {} Shared::World* world; Node* node; }; - static void request_run(LV2_Contexts_Request_Run_Data data_ptr, - uint32_t context_uri) { - Data* data = reinterpret_cast(data_ptr); - if (!data->world->local_engine()) - return; + static LV2_Worker_Status + schedule_work(LV2_Worker_Schedule_Handle handle, + uint32_t size, + const void* data) + { + Info* info = reinterpret_cast(handle); + if (!info->world->local_engine()) + return LV2_WORKER_ERR_UNKNOWN; - Engine* engine = (Engine*)data->world->local_engine().get(); + Engine* engine = (Engine*)info->world->local_engine().get(); engine->message_context()->run( - dynamic_cast(data->node), + dynamic_cast(info->node), engine->driver()->frame_time()); + + return LV2_WORKER_SUCCESS; } static void delete_feature(LV2_Feature* feature) { @@ -65,13 +70,13 @@ struct RequestRunFeature : public Ingen::Shared::LV2Features::Feature { if (!node) return SharedPtr(); - typedef LV2_Contexts_Request_Run_Feature Feature; - Feature* data = (Feature*)malloc(sizeof(Feature)); - data->data = new Data(world, n); - data->request_run = &request_run; + LV2_Worker_Schedule* data = (LV2_Worker_Schedule*)malloc( + sizeof(LV2_Worker_Schedule)); + data->handle = new Info(world, n); + data->schedule_work = schedule_work; LV2_Feature* f = (LV2_Feature*)malloc(sizeof(LV2_Feature)); - f->URI = LV2_CONTEXTS_URI "#RequestRunFeature"; + f->URI = LV2_WORKER__schedule; f->data = data; return SharedPtr(f, &delete_feature); diff --git a/src/server/LV2ResizeFeature.hpp b/src/server/LV2ResizeFeature.hpp index 47a65dcc..3325c904 100644 --- a/src/server/LV2ResizeFeature.hpp +++ b/src/server/LV2ResizeFeature.hpp @@ -36,15 +36,12 @@ struct ResizeFeature : public Ingen::Shared::LV2Features::Feature { size_t size) { NodeImpl* node = (NodeImpl*)data; PortImpl* port = node->port_impl(index); - switch (port->context()) { - case Context::MESSAGE: + if (node->context() == Context::MESSAGE) { port->buffer(0)->resize(size); port->connect_buffers(); return true; - default: - // TODO: Implement realtime allocator and support this in audio thread - return false; } + return false; } static void delete_feature(LV2_Feature* feature) { diff --git a/src/server/MessageContext.cpp b/src/server/MessageContext.cpp index d24abba8..ab15ec8d 100644 --- a/src/server/MessageContext.cpp +++ b/src/server/MessageContext.cpp @@ -1,5 +1,5 @@ /* This file is part of Ingen. - * Copyright 2008-2011 David Robillard + * Copyright 2008-2012 David Robillard * * Ingen 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 @@ -16,7 +16,7 @@ */ #include -#include "lv2/lv2plug.in/ns/ext/contexts/contexts.h" +#include "lv2/lv2plug.in/ns/ext/worker/worker.h" #include "raul/log.hpp" #include "ConnectionImpl.hpp" #include "Engine.hpp" @@ -100,26 +100,7 @@ void MessageContext::execute(const Request& req) { NodeImpl* node = req.node; - node->message_run(*this); - - void* valid_ports = node->valid_ports(); - PatchImpl* patch = node->parent_patch(); - - for (uint32_t i = 0; i < node->num_ports(); ++i) { - PortImpl* p = node->port_impl(i); - if (p->is_output() && p->context() == Context::MESSAGE && - lv2_contexts_port_is_valid(valid_ports, i)) { - PatchImpl::Connections& wires = patch->connections(); - for (PatchImpl::Connections::iterator c = wires.begin(); c != wires.end(); ++c) { - ConnectionImpl* ci = (ConnectionImpl*)c->second.get(); - if (ci->src_port() == p && ci->dst_port()->context() == Context::MESSAGE) { - _queue.insert(Request(req.time, ci->dst_port()->parent_node())); - } - } - } - } - - node->reset_valid_ports(); + node->work(*this, 0, NULL); } } // namespace Server diff --git a/src/server/MessageContext.hpp b/src/server/MessageContext.hpp index d3bcfed6..239b38c7 100644 --- a/src/server/MessageContext.hpp +++ b/src/server/MessageContext.hpp @@ -33,7 +33,7 @@ namespace Server { class NodeImpl; -/** Context of a message_run() call. +/** Context of a work() call. * * The message context is a non-hard-realtime thread used to execute things * that can take too long to execute in an audio thread, and do sloppy timed diff --git a/src/server/NodeImpl.cpp b/src/server/NodeImpl.cpp index 12cf2d61..972dc40d 100644 --- a/src/server/NodeImpl.cpp +++ b/src/server/NodeImpl.cpp @@ -15,10 +15,10 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include +#include #include -#include "lv2/lv2plug.in/ns/ext/contexts/contexts.h" +#include "lv2/lv2plug.in/ns/ext/worker/worker.h" #include "raul/Array.hpp" #include "raul/List.hpp" @@ -45,7 +45,7 @@ NodeImpl::NodeImpl(PluginImpl* plugin, : GraphObjectImpl(plugin->uris(), parent, symbol) , _plugin(plugin) , _ports(NULL) - , _valid_ports(NULL) + , _context(Context::AUDIO) , _polyphony((polyphonic && parent) ? parent->internal_poly() : 1) , _srate(srate) , _input_ready(1) @@ -65,8 +65,6 @@ NodeImpl::~NodeImpl() deactivate(); delete _ports; - - free(_valid_ports); } Port* @@ -161,7 +159,7 @@ NodeImpl::set_buffer_size(Context& context, if (_ports) { for (size_t i = 0; i < _ports->size(); ++i) { PortImpl* const p = _ports->at(i); - if (p->buffer_type() == type && p->context() == context.id()) { + if (p->buffer_type() == type) { p->set_buffer_size(context, bufs, size); } } @@ -216,10 +214,8 @@ NodeImpl::pre_process(Context& context) // Mix down input ports for (uint32_t i = 0; i < num_ports(); ++i) { PortImpl* const port = _ports->at(i); - if (port->context() == Context::AUDIO) { - port->pre_process(context); - port->connect_buffers(context.offset()); - } + port->pre_process(context); + port->connect_buffers(context.offset()); } } @@ -232,36 +228,10 @@ NodeImpl::post_process(Context& context) // Write output ports for (size_t i = 0; _ports && i < _ports->size(); ++i) { - PortImpl* const port = _ports->at(i); - if (port->context() == Context::AUDIO) - _ports->at(i)->post_process(context); + _ports->at(i)->post_process(context); } } -/** Flag a port as set (for message context) - */ -void -NodeImpl::set_port_valid(uint32_t port_index) -{ - // Allocate enough space for one bit per port - if (!_valid_ports) - _valid_ports = calloc(num_ports() / 8, 1); - lv2_contexts_set_port_valid(_valid_ports, port_index); -} - -void* -NodeImpl::valid_ports() -{ - return _valid_ports; -} - -void -NodeImpl::reset_valid_ports() -{ - if (_valid_ports) - memset(_valid_ports, '\0', num_ports() / 8); -} - void NodeImpl::set_port_buffer(uint32_t voice, uint32_t port_num, diff --git a/src/server/NodeImpl.hpp b/src/server/NodeImpl.hpp index a5c619fa..c66d5a91 100644 --- a/src/server/NodeImpl.hpp +++ b/src/server/NodeImpl.hpp @@ -28,6 +28,7 @@ #include "raul/AtomicInt.hpp" #include "raul/Semaphore.hpp" +#include "Context.hpp" #include "GraphObjectImpl.hpp" #include "PortType.hpp" #include "types.hpp" @@ -118,17 +119,10 @@ public: /** Learn the next incoming MIDI event (for internals) */ virtual void learn() {} - /** Run the node for one instant in the message thread. */ - virtual void message_run(MessageContext& context) {} - - /** Flag a port as valid (for message context) */ - virtual void set_port_valid(uint32_t index); - - /** Return a bit vector of which ports are valid */ - virtual void* valid_ports(); - - /** Clear all bits in valid_ports() */ - virtual void reset_valid_ports(); + /** Run the node for one instant in the non-realtime worker thread. */ + virtual void work(MessageContext& context, + uint32_t size, + const void* data) {} /** Do whatever needs doing in the process thread before process() is called */ virtual void pre_process(Context& context); @@ -189,6 +183,7 @@ public: /** The Patch this Node belongs to. */ inline PatchImpl* parent_patch() const { return (PatchImpl*)_parent; } + Context::ID context() const { return _context; } SampleRate sample_rate() const { return _srate; } virtual uint32_t num_ports() const { return _ports ? _ports->size() : 0; } virtual uint32_t polyphony() const { return _polyphony; } @@ -199,18 +194,18 @@ public: protected: PluginImpl* _plugin; - Raul::Array* _ports; ///< Access in audio thread only - void* _valid_ports; ///< Valid port flags for message context + Raul::Array* _ports; ///< Access in audio thread only + Context::ID _context; ///< Context this node runs in uint32_t _polyphony; SampleRate _srate; - Raul::Semaphore _input_ready; ///< Parallelism: input ready signal - Raul::AtomicInt _process_lock; ///< Parallelism: Waiting on inputs 'lock' - Raul::AtomicInt _n_inputs_ready; ///< Parallelism: # input ready signals this cycle - std::list _providers; ///< Nodes connected to this one's input ports - std::list _dependants; ///< Nodes this one's output ports are connected to + Raul::Semaphore _input_ready; ///< Parallelism: input ready signal + Raul::AtomicInt _process_lock; ///< Parallelism: Waiting on inputs 'lock' + Raul::AtomicInt _n_inputs_ready; ///< Parallelism: # input ready signals this cycle + std::list _providers; ///< Nodes connected to this one's input ports + std::list _dependants; ///< Nodes this one's output ports are connected to bool _polyphonic; bool _activated; - bool _traversed; ///< Flag for process order algorithm + bool _traversed; ///< Flag for process order algorithm }; } // namespace Server diff --git a/src/server/PatchImpl.cpp b/src/server/PatchImpl.cpp index dca7f2ae..59a5e139 100644 --- a/src/server/PatchImpl.cpp +++ b/src/server/PatchImpl.cpp @@ -101,8 +101,7 @@ PatchImpl::disable() _process = false; for (Ports::iterator i = _outputs.begin(); i != _outputs.end(); ++i) - if ((*i)->context() == Context::AUDIO) - (*i)->clear_buffers(); + (*i)->clear_buffers(); } bool @@ -476,8 +475,8 @@ PatchImpl::compile() const for (Connections::const_iterator i = _connections.begin(); i != _connections.end(); ++i) { SharedPtr c = PtrCast(i->second); - if (c->src_port()->context() == Context::AUDIO && - c->dst_port()->context() == Context::MESSAGE) { + if (c->src_port()->parent_node()->context() == Context::AUDIO && + c->dst_port()->parent_node()->context() == Context::MESSAGE) { compiled_patch->queued_connections.push_back(c.get()); } } diff --git a/src/server/PortImpl.cpp b/src/server/PortImpl.cpp index 7720acc6..c414d99a 100644 --- a/src/server/PortImpl.cpp +++ b/src/server/PortImpl.cpp @@ -15,13 +15,11 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "lv2/lv2plug.in/ns/ext/contexts/contexts.h" - -#include "raul/Array.hpp" -#include "raul/Maid.hpp" - #include "ingen/shared/LV2URIMap.hpp" #include "ingen/shared/URIs.hpp" +#include "lv2/lv2plug.in/ns/ext/worker/worker.h" +#include "raul/Array.hpp" +#include "raul/Maid.hpp" #include "AudioBuffer.hpp" #include "BufferFactory.hpp" @@ -58,7 +56,6 @@ PortImpl::PortImpl(BufferFactory& bufs, , _min(bufs.forge().make(0.0f)) , _max(bufs.forge().make(1.0f)) , _last_broadcasted_value(value) - , _context(Context::AUDIO) , _buffers(new Array(static_cast(poly))) , _prepared_buffers(NULL) , _broadcast(false) @@ -89,7 +86,6 @@ PortImpl::PortImpl(BufferFactory& bufs, add_property(uris.rdf_type, bufs.forge().alloc_uri(type.uri().str())); set_property(uris.lv2_index, bufs.forge().make((int32_t)index)); - set_context(_context); } PortImpl::~PortImpl() @@ -261,20 +257,5 @@ PortImpl::broadcast_value(Context& context, bool force) } } -void -PortImpl::set_context(Context::ID c) -{ - const Ingen::Shared::URIs& uris = _bufs.uris(); - _context = c; - switch (c) { - case Context::AUDIO: - remove_property(uris.ctx_context, uris.wildcard); - break; - case Context::MESSAGE: - set_property(uris.ctx_context, uris.ctx_messageContext); - break; - } -} - } // namespace Server } // namespace Ingen diff --git a/src/server/PortImpl.hpp b/src/server/PortImpl.hpp index c67be49b..64dc961d 100644 --- a/src/server/PortImpl.hpp +++ b/src/server/PortImpl.hpp @@ -147,9 +147,6 @@ public: void raise_set_by_user_flag() { _set_by_user = true; } - Context::ID context() const { return _context; } - void set_context(Context::ID c); - BufferFactory& bufs() const { return _bufs; } protected: @@ -173,7 +170,6 @@ protected: Raul::Atom _min; Raul::Atom _max; Raul::Atom _last_broadcasted_value; - Context::ID _context; Raul::Array* _buffers; Raul::Array* _prepared_buffers; bool _broadcast; diff --git a/src/server/events/SetPortValue.cpp b/src/server/events/SetPortValue.cpp index 1c10abc5..6d088939 100644 --- a/src/server/events/SetPortValue.cpp +++ b/src/server/events/SetPortValue.cpp @@ -88,9 +88,8 @@ SetPortValue::pre_process() // Port is a message context port, set its value and // call the plugin's message run function once - if (_port && _port->context() == Context::MESSAGE) { + if (_port && _port->parent_node()->context() == Context::MESSAGE) { apply(*_engine.message_context()); - _port->parent_node()->set_port_valid(_port->index()); _engine.message_context()->run(_port->parent_node(), _engine.driver()->frame_time() + _engine.driver()->block_length()); } @@ -111,7 +110,7 @@ SetPortValue::execute(ProcessContext& context) Event::execute(context); assert(_time >= context.start() && _time <= context.end()); - if (_port && _port->context() == Context::MESSAGE) + if (_port && _port->parent_node()->context() == Context::MESSAGE) return; apply(context); -- cgit v1.2.1