From e479da3c26d41e977cf55b8e2355db45991be09f Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 22 Nov 2009 03:06:25 +0000 Subject: Partial support for message/value ports and the message context. This use case now works: - Add an event input and the "print" plugin from imum.lv2 to ingen - Connect the event input to the input of "print" - Hook Ingen up to JACK and play some MIDI events (or get events to the print plugin from anywhere else) - The "print" plugin will print the received events to the console in the message context (i.e. the audio thread is realtime safe) git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2281 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/MessageContext.hpp | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'src/engine/MessageContext.hpp') diff --git a/src/engine/MessageContext.hpp b/src/engine/MessageContext.hpp index 9d17d920..c871ad1c 100644 --- a/src/engine/MessageContext.hpp +++ b/src/engine/MessageContext.hpp @@ -18,7 +18,14 @@ #ifndef MESSAGECONTEXT_H #define MESSAGECONTEXT_H +#include +#include "raul/Thread.hpp" +#include "raul/Semaphore.hpp" +#include "raul/AtomicPtr.hpp" +#include "object.lv2/object.h" #include "Context.hpp" +#include "ThreadManager.hpp" +#include "tuning.hpp" namespace Ingen { @@ -33,14 +40,41 @@ class NodeImpl; * * \ingroup engine */ -class MessageContext : public Context +class MessageContext : public Context, public Raul::Thread { public: MessageContext(Engine& engine) : Context(engine, MESSAGE) - {} + , Raul::Thread("message-context") + , _sem(0) + , _requests(message_context_queue_size) + { + Thread::set_context(THREAD_MESSAGE); + } + /** Request a run starting at node. + * + * Safe to call from either process thread or pre-process thread. + */ void run(NodeImpl* node); + + inline void signal() { _sem.post(); } + inline bool has_requests() const { + return _requests.read_space() >= sizeof(NodeImpl*) || _request.get(); + } + +protected: + /** Thread run method (wait for and execute requests from process thread */ + void _run(); + + /** Actually execute and propagate from node */ + void run_node(NodeImpl* node); + + Raul::Semaphore _sem; + Raul::RingBuffer _requests; + Glib::Mutex _mutex; + Glib::Cond _cond; + Raul::AtomicPtr _request; }; -- cgit v1.2.1