From 153fe99497a7ccc91aac6082b29748a66792d374 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 10 Aug 2007 21:44:30 +0000 Subject: Fix loading control values from deprecated Om patches. Eliminate parallel processing overhead if running single threaded. git-svn-id: http://svn.drobilla.net/lad/ingen@693 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/client/DeprecatedLoader.cpp | 40 +++++++++++++++++++------------- src/libs/client/DeprecatedLoader.hpp | 3 ++- src/libs/client/Store.cpp | 2 +- src/libs/engine/CompiledPatch.hpp | 4 +--- src/libs/engine/Patch.cpp | 44 ++++++++++++++++++++++++++---------- src/libs/engine/Patch.hpp | 2 ++ 6 files changed, 62 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/libs/client/DeprecatedLoader.cpp b/src/libs/client/DeprecatedLoader.cpp index e33a6b5c..19ce6b7e 100644 --- a/src/libs/client/DeprecatedLoader.cpp +++ b/src/libs/client/DeprecatedLoader.cpp @@ -104,7 +104,10 @@ DeprecatedLoader::nameify_if_invalid(const string& name) return name; } else { const string new_name = Path::nameify(name); - cerr << "WARNING: Illegal name '" << name << "' converted to '" << name << "'" << endl; + assert(Path::is_valid_name(new_name)); + if (new_name != name) + cerr << "WARNING: Illegal name '" << name << "' converted to '" + << new_name << "'" << endl; return new_name; } } @@ -293,20 +296,24 @@ DeprecatedLoader::load_patch(const Glib::ustring& filename, cur = cur->next; } - // Load presets (control values) - cerr << "FIXME: load preset\n"; - /*cur = xmlDocGetRootElement(doc)->xmlChildrenNode; + cur = xmlDocGetRootElement(doc)->xmlChildrenNode; while (cur != NULL) { + // I don't think Om ever wrote any preset other than "default"... if ((!xmlStrcmp(cur->name, (const xmlChar*)"preset"))) { - load_preset(pm, doc, cur); - assert(preset_model != NULL); - if (preset_model->name() == "default") - _engine->set_preset(pm->path(), preset_model); + SharedPtr pm = load_preset(path, doc, cur); + assert(pm != NULL); + if (pm->name() == "default") { + list::const_iterator i = pm->controls().begin(); + for ( ; i != pm->controls().end(); ++i) { + _engine->set_port_value(i->port_path(), i->value()); + } + } else { + cerr << "WARNING: Unknown preset: \"" << pm->name() << endl; + } } cur = cur->next; } - */ xmlFreeDoc(doc); xmlCleanupParser(); @@ -634,15 +641,15 @@ DeprecatedLoader::load_connection(const Path& parent, xmlDocPtr doc, const xmlNo /** Build a PresetModel given a pointer to a preset in a patch file. */ -bool +SharedPtr DeprecatedLoader::load_preset(const Path& parent, xmlDocPtr doc, const xmlNodePtr node) { - cerr << "FIXME: load preset\n"; -#if 0 + cerr << "LOAD PRESET" << endl; + xmlNodePtr cur = node->xmlChildrenNode; xmlChar* key; - PresetModel* pm = new PresetModel(patch->path().base()); + SharedPtr pm(new PresetModel(parent.base())); while (cur != NULL) { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); @@ -674,7 +681,8 @@ DeprecatedLoader::load_preset(const Path& parent, xmlDocPtr doc, const xmlNodePt } // Compatibility fixes for old patch files - node_name = nameify_if_invalid(node_name); + if (node_name != "") + node_name = nameify_if_invalid(node_name); port_name = nameify_if_invalid(port_name); if (port_name == "") { @@ -688,6 +696,8 @@ DeprecatedLoader::load_preset(const Path& parent, xmlDocPtr doc, const xmlNodePt string::size_type slash_index; while ((slash_index = port_name.find("/")) != string::npos) port_name[slash_index] = '-'; + + cerr << "ADDING CONTROL: " << node_name << " / " << port_name << " = " << val << endl; pm->add_control(node_name, port_name, val); } } @@ -702,8 +712,6 @@ DeprecatedLoader::load_preset(const Path& parent, xmlDocPtr doc, const xmlNodePt } return pm; -#endif - return false; } } // namespace Client diff --git a/src/libs/client/DeprecatedLoader.hpp b/src/libs/client/DeprecatedLoader.hpp index e3397de6..fd1be335 100644 --- a/src/libs/client/DeprecatedLoader.hpp +++ b/src/libs/client/DeprecatedLoader.hpp @@ -81,8 +81,9 @@ private: bool load_node(const Path& parent, xmlDocPtr doc, const xmlNodePtr cur); bool load_connection(const Path& parent, xmlDocPtr doc, const xmlNodePtr cur); - bool load_preset(const Path& parent, xmlDocPtr doc, const xmlNodePtr cur); bool load_subpatch(const Path& parent, xmlDocPtr doc, const xmlNodePtr cur); + + SharedPtr load_preset(const Path& parent, xmlDocPtr doc, const xmlNodePtr cur); }; diff --git a/src/libs/client/Store.cpp b/src/libs/client/Store.cpp index 360b1053..f5cead13 100644 --- a/src/libs/client/Store.cpp +++ b/src/libs/client/Store.cpp @@ -260,7 +260,7 @@ Store::add_object(SharedPtr object) } - cout << "[Store] Added " << object->path() << endl; + //cout << "[Store] Added " << object->path() << endl; } diff --git a/src/libs/engine/CompiledPatch.hpp b/src/libs/engine/CompiledPatch.hpp index 9ab252b3..f5de52e1 100644 --- a/src/libs/engine/CompiledPatch.hpp +++ b/src/libs/engine/CompiledPatch.hpp @@ -31,9 +31,7 @@ using namespace std; namespace Ingen { -/** A node, and it's providers/dependants. - * - * This is all the information required to execute a node in a process thread. +/** All information required about a node to execute it in an audio thread. */ struct CompiledNode { CompiledNode(Node* n, size_t np, List* d) diff --git a/src/libs/engine/Patch.cpp b/src/libs/engine/Patch.cpp index ad1459e8..8e0b8862 100644 --- a/src/libs/engine/Patch.cpp +++ b/src/libs/engine/Patch.cpp @@ -118,8 +118,6 @@ Patch::process(SampleCount nframes, FrameTime start, FrameTime end) if (_compiled_patch == NULL || _compiled_patch->size() == 0 || !_process) return; - CompiledPatch* const cp = _compiled_patch; - /* Prepare input ports */ // This breaks MIDI input, somehow (?) @@ -129,10 +127,30 @@ Patch::process(SampleCount nframes, FrameTime start, FrameTime end) (*i)->pre_process(nframes, start, end); - /* Start p-1 slaves */ + if (_engine.process_slaves().size() > 0) + process_parallel(nframes, start, end); + else + process_single(nframes, start, end); + + + /* Write output ports */ + + for (Raul::List::iterator i = _input_ports.begin(); i != _input_ports.end(); ++i) + (*i)->post_process(nframes, start, end); + for (Raul::List::iterator i = _output_ports.begin(); i != _output_ports.end(); ++i) + (*i)->post_process(nframes, start, end); +} + +void +Patch::process_parallel(SampleCount nframes, FrameTime start, FrameTime end) +{ size_t n_slaves = _engine.process_slaves().size(); + CompiledPatch* const cp = _compiled_patch; + + /* Start p-1 slaves */ + if (n_slaves >= cp->size()) n_slaves = cp->size()-1; @@ -186,6 +204,8 @@ Patch::process(SampleCount nframes, FrameTime start, FrameTime end) index = (index + 1) % cp->size(); } + + //cout << "Main Thread ran \t" << run_count << " nodes this cycle." << endl; /* Tell slaves we're done in case we beat them, and pray they're * really done by the start of next cycle. @@ -193,18 +213,19 @@ Patch::process(SampleCount nframes, FrameTime start, FrameTime end) */ for (size_t i=0; i < n_slaves; ++i) _engine.process_slaves()[i]->finish(); - - //cout << "Main Thread ran \t" << run_count << " nodes this cycle." << endl; +} - /* Write output ports */ + +void +Patch::process_single(SampleCount nframes, FrameTime start, FrameTime end) +{ + CompiledPatch* const cp = _compiled_patch; - for (Raul::List::iterator i = _input_ports.begin(); i != _input_ports.end(); ++i) - (*i)->post_process(nframes, start, end); - for (Raul::List::iterator i = _output_ports.begin(); i != _output_ports.end(); ++i) - (*i)->post_process(nframes, start, end); + for (size_t i=0; i < cp->size(); ++i) + (*cp)[i].node()->process(nframes, start, end); } - + void Patch::set_buffer_size(size_t size) { @@ -368,7 +389,6 @@ Patch::compile() const CompiledPatch* const compiled_patch = new CompiledPatch();//_nodes.size()); - // FIXME: tweak algorithm so it just ends up like this and save the cost of iteration? for (Raul::List::const_iterator i = _nodes.begin(); i != _nodes.end(); ++i) (*i)->traversed(false); diff --git a/src/libs/engine/Patch.hpp b/src/libs/engine/Patch.hpp index 7780c60b..8d17ee7c 100644 --- a/src/libs/engine/Patch.hpp +++ b/src/libs/engine/Patch.hpp @@ -97,6 +97,8 @@ public: private: inline void compile_recursive(Node* n, CompiledPatch* output) const; + void process_parallel(SampleCount nframes, FrameTime start, FrameTime end); + void process_single(SampleCount nframes, FrameTime start, FrameTime end); Engine& _engine; uint32_t _internal_poly; -- cgit v1.2.1