From 1a77934531b0ddfc4392ccffbdde0058c2dbab68 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 1 Aug 2007 04:42:09 +0000 Subject: Remove PostProcessor thread, post-process in main thread instead (solves scripting threading issues, and saves memory anyway). Revert saw_lp.ingen.ttl (version written by broken raptor committed by mistake). Working engine->script responses, nicer Python example. git-svn-id: http://svn.drobilla.net/lad/ingen@665 a436a847-0d15-0410-975c-d299462d15a1 --- src/bindings/Makefile.am | 5 +++++ src/bindings/ingen.i | 5 +++++ src/bindings/test_ingen.py | 35 +++++++++++++++-------------------- src/libs/engine/Engine.cpp | 9 +++++---- src/libs/engine/JackAudioDriver.cpp | 2 +- src/libs/engine/PostProcessor.cpp | 21 ++++++++++++++------- src/libs/engine/PostProcessor.hpp | 18 ++++++++++++------ src/libs/engine/QueuedEventSource.cpp | 4 ++-- src/libs/engine/tuning.hpp | 5 ++--- src/libs/module/World.hpp | 5 +++++ src/libs/module/module.cpp | 2 ++ src/progs/ingen/main.cpp | 1 + 12 files changed, 69 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/bindings/Makefile.am b/src/bindings/Makefile.am index 48a5ad4f..cb86a915 100644 --- a/src/bindings/Makefile.am +++ b/src/bindings/Makefile.am @@ -10,6 +10,11 @@ bindings_LTLIBRARIES = libingen_bindings.la libingen_bindings_la_LDFLAGS = -no-undefined -module -avoid-version libingen_bindings_la_LIBADD = @RAUL_LIBS@ @GLIBMM_LIBS@ #../libs/module/libingen_module.la libingen_bindings_la_SOURCES = ingen_wrap.cxx ingen_bindings.cpp ingen_bindings.hpp +libingen_bindings_la_CXXFLAGS = \ + @SLV2_CFLAGS@ @RAUL_CFLAGS@ @GLIBMM_CFLAGS@ \ + -I$(top_srcdir)/ingen/src/common \ + -I$(top_srcdir)/ingen/src/libs \ + -I/usr/include/python2.4 swig: ingen.i swig -c++ -Wall $(FLAGS) -python ingen.i diff --git a/src/bindings/ingen.i b/src/bindings/ingen.i index 719ece20..5eb942d9 100644 --- a/src/bindings/ingen.i +++ b/src/bindings/ingen.i @@ -42,6 +42,11 @@ namespace Ingen { namespace Shared { return Ingen::Shared::ingen_world; } } + + void iteration() { + Ingen::Shared::script_iteration($self); + } + /*SLV2World slv2() { return $self->me->slv2_world; }*/ }; diff --git a/src/bindings/test_ingen.py b/src/bindings/test_ingen.py index 4109dd21..9b925155 100755 --- a/src/bindings/test_ingen.py +++ b/src/bindings/test_ingen.py @@ -1,40 +1,34 @@ #!/usr/bin/env python + import ingen import time world = ingen.World() class PythonClient(ingen.Client): - #def __init__(self): - # ingen.Client(self) - # print "Client" - - def bundle_begin(): - print "Bundle {" + def error(self, msg): + print "*** Received error:", msg + def bundle_begin(self): + print "*** Receiving Bundle {" + + def bundle_end(self): + print "*** }" def new_port(self, path, data_type, is_output): - print "Port:", path, data_type, is_output + print "*** Received Port:", path, data_type, is_output + + def new_node(self, plugin_uri, path, polyphonic, nports): + print "*** Received Node:", plugin_uri, path, polyphonic, nports c = PythonClient() -c.thisown = 0 -print "C OWN", c.thisown -#print c.__base__ +c.enable() e = world.engine -print "E OWN", e.thisown -e.thisown = 0 -#print e - e.activate() -#e.register_client("foo", c) c.subscribe(e) -c.enable() -#c.new_patch("/foo/bar", 1) - - e.create_port("/I", "ingen:midi", False) e.create_port("/made", "ingen:audio", False) e.create_port("/these", "ingen:audio", False) @@ -43,5 +37,6 @@ e.create_port("/a", "ingen:audio", True) e.create_port("/script", "ingen:audio", True) while True: - time.sleep(1) + world.iteration() + time.sleep(0.1) diff --git a/src/libs/engine/Engine.cpp b/src/libs/engine/Engine.cpp index a77662a3..af4eca27 100644 --- a/src/libs/engine/Engine.cpp +++ b/src/libs/engine/Engine.cpp @@ -54,7 +54,7 @@ Engine::Engine(Ingen::Shared::World* world) _midi_driver(NULL), _osc_driver(NULL), _maid(new Raul::Maid(maid_queue_size)), - _post_processor(new PostProcessor(*_maid, post_processor_queue_size)), + _post_processor(new PostProcessor(/**_maid, */post_processor_queue_size)), _broadcaster(new ClientBroadcaster()), _object_store(new ObjectStore()), _node_factory(new NodeFactory(world)), @@ -142,6 +142,7 @@ Engine::main_iteration() lash_driver->process_events(); #endif*/ // Run the maid (garbage collector) + _post_processor->process(); _maid->cleanup(); return !_quit_flag; @@ -227,7 +228,7 @@ Engine::activate() _audio_driver->activate(); - _post_processor->start(); + //_post_processor->start(); _activated = true; @@ -254,8 +255,8 @@ Engine::deactivate() _audio_driver->root_patch()->deactivate(); // Finalize any lingering events (unlikely) - _post_processor->whip(); - _post_processor->stop(); + //_post_processor->whip(); + //_post_processor->stop(); _audio_driver.reset(); diff --git a/src/libs/engine/JackAudioDriver.cpp b/src/libs/engine/JackAudioDriver.cpp index ebb4708b..b9e89189 100644 --- a/src/libs/engine/JackAudioDriver.cpp +++ b/src/libs/engine/JackAudioDriver.cpp @@ -204,7 +204,7 @@ JackAudioDriver::deactivate() cout << "[JackAudioDriver] Deactivated Jack client." << endl; - _engine.post_processor()->stop(); + //_engine.post_processor()->stop(); } } diff --git a/src/libs/engine/PostProcessor.cpp b/src/libs/engine/PostProcessor.cpp index 64c106d8..109635df 100644 --- a/src/libs/engine/PostProcessor.cpp +++ b/src/libs/engine/PostProcessor.cpp @@ -19,7 +19,7 @@ #include #include #include -#include +//#include #include "Event.hpp" #include "PostProcessor.hpp" @@ -28,27 +28,34 @@ using std::cerr; using std::cout; using std::endl; namespace Ingen { -PostProcessor::PostProcessor(Raul::Maid& maid, size_t queue_size) -: _maid(maid), - _events(queue_size) +PostProcessor::PostProcessor(/*Raul::Maid& maid, */size_t queue_size) + //: _maid(maid) + : _events(queue_size) { - set_name("PostProcessor"); + //set_name("PostProcessor"); } - +#if 0 /** Post-Process every pending event. * * The PostProcessor should be whipped by the audio thread once every cycle */ void PostProcessor::_whipped() +{ + //process(); +} +#endif + +void +PostProcessor::process() { while ( ! _events.empty()) { Event* const ev = _events.front(); _events.pop(); assert(ev); ev->post_process(); - _maid.push(ev); + delete ev; } } diff --git a/src/libs/engine/PostProcessor.hpp b/src/libs/engine/PostProcessor.hpp index b77bda6e..114a8bef 100644 --- a/src/libs/engine/PostProcessor.hpp +++ b/src/libs/engine/PostProcessor.hpp @@ -21,9 +21,9 @@ #include #include "types.hpp" #include -#include +//#include -namespace Raul { class Maid; } +//namespace Raul { class Maid; } namespace Ingen { @@ -36,20 +36,26 @@ class Event; * is realtime-safe), which signals the processing thread through a semaphore * to handle the event and pass it on to the Maid. * + * Update: This is all run from main_iteration now to solve scripting + * thread issues. Not sure if this is permanent/ideal or not... + * * \ingroup engine */ -class PostProcessor : public Raul::Slave +class PostProcessor //: public Raul::Slave { public: - PostProcessor(Raul::Maid& maid, size_t queue_size); + PostProcessor(/*Raul::Maid& maid, */size_t queue_size); /** Push an event on to the process queue, realtime-safe, not thread-safe. */ inline void push(Event* const ev) { _events.push(ev); } + /** Post-process and delete all pending events */ + void process(); + private: - Raul::Maid& _maid; + //Raul::Maid& _maid; Raul::SRSWQueue _events; - virtual void _whipped(); + //virtual void _whipped(); }; diff --git a/src/libs/engine/QueuedEventSource.cpp b/src/libs/engine/QueuedEventSource.cpp index 6414a6e9..ac03ef16 100644 --- a/src/libs/engine/QueuedEventSource.cpp +++ b/src/libs/engine/QueuedEventSource.cpp @@ -106,8 +106,8 @@ QueuedEventSource::process(PostProcessor& dest, SampleCount nframes, FrameTime c ++num_events_processed; } - if (num_events_processed > 0) - dest.whip(); + /*if (num_events_processed > 0) + dest.whip();*/ //else // cerr << "NO PROC: queued: " << unprepared_events() << ", stamped: " << !_stamped_queue.empty() << endl; } diff --git a/src/libs/engine/tuning.hpp b/src/libs/engine/tuning.hpp index 25aa9eb0..7ec55ae4 100644 --- a/src/libs/engine/tuning.hpp +++ b/src/libs/engine/tuning.hpp @@ -30,9 +30,8 @@ static const size_t pre_processor_queue_size = 1024; static const size_t post_processor_queue_size = 1024; static const size_t maid_queue_size = 1024; -// This controls both the LASH event processing rate and the Maid cleanup rate -// (both of which are driven from the main thread) -static const timespec main_rate = { 0, 500000000 }; // 1/2 second +//static const timespec main_rate = { 0, 500000000 }; // 1/2 second +static const timespec main_rate = { 0, 125000000 }; // 1/8 second } // namespace Ingen diff --git a/src/libs/module/World.hpp b/src/libs/module/World.hpp index f665e6ad..1caa50ac 100644 --- a/src/libs/module/World.hpp +++ b/src/libs/module/World.hpp @@ -30,6 +30,9 @@ #endif namespace Ingen { + +class Engine; + namespace Shared { class EngineInterface; @@ -52,6 +55,8 @@ struct World { Raul::RDF::World* rdf_world; EngineInterface* engine; + + Engine* local_engine; }; diff --git a/src/libs/module/module.cpp b/src/libs/module/module.cpp index d169e546..2914907a 100644 --- a/src/libs/module/module.cpp +++ b/src/libs/module/module.cpp @@ -48,6 +48,8 @@ get_world() world->slv2_world = slv2_world_new_using_rdf_world(world->rdf_world->world()); slv2_world_load_all(world->slv2_world); #endif + world->engine = NULL; + world->local_engine = NULL; } return world; diff --git a/src/progs/ingen/main.cpp b/src/progs/ingen/main.cpp index 22ace336..f424eff0 100644 --- a/src/progs/ingen/main.cpp +++ b/src/progs/ingen/main.cpp @@ -88,6 +88,7 @@ main(int argc, char** argv) Engine* (*new_engine)(Ingen::Shared::World* world) = NULL; if (engine_module->get_symbol("new_engine", (void*&)new_engine)) { engine = SharedPtr(new_engine(world)); + world->local_engine = engine.get(); } else { engine_module.reset(); } -- cgit v1.2.1