diff options
author | David Robillard <d@drobilla.net> | 2006-12-12 12:45:33 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2006-12-12 12:45:33 +0000 |
commit | 71f632d459471c2e75ed04b808df9671539a182c (patch) | |
tree | 2fe3c25243e7b915656c02dd46bca5a0d317b599 /src/libs | |
parent | 9e2a757e026abf79d0cdcf12a18796fa89973356 (diff) | |
download | ingen-71f632d459471c2e75ed04b808df9671539a182c.tar.gz ingen-71f632d459471c2e75ed04b808df9671539a182c.tar.bz2 ingen-71f632d459471c2e75ed04b808df9671539a182c.zip |
Connection loading.
Command line parameter for server to allow connecting to specific JACK server.
git-svn-id: http://svn.drobilla.net/lad/ingen@217 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/libs')
-rw-r--r-- | src/libs/client/Loader.cpp | 44 | ||||
-rw-r--r-- | src/libs/client/RDFQuery.cpp | 8 | ||||
-rw-r--r-- | src/libs/engine/Engine.cpp | 44 | ||||
-rw-r--r-- | src/libs/engine/Engine.h | 35 | ||||
-rw-r--r-- | src/libs/engine/EventSource.h | 8 | ||||
-rw-r--r-- | src/libs/engine/JackAudioDriver.cpp | 31 | ||||
-rw-r--r-- | src/libs/engine/JackAudioDriver.h | 9 | ||||
-rw-r--r-- | src/libs/engine/Makefile.am | 2 | ||||
-rw-r--r-- | src/libs/engine/QueuedEngineInterface.cpp | 4 | ||||
-rw-r--r-- | src/libs/engine/events.h | 1 | ||||
-rw-r--r-- | src/libs/engine/events/ActivateEvent.cpp | 38 | ||||
-rw-r--r-- | src/libs/engine/events/ActivateEvent.h | 40 |
12 files changed, 137 insertions, 127 deletions
diff --git a/src/libs/client/Loader.cpp b/src/libs/client/Loader.cpp index fe1af795..e1590540 100644 --- a/src/libs/client/Loader.cpp +++ b/src/libs/client/Loader.cpp @@ -52,7 +52,7 @@ Loader::load(const Glib::ustring& filename, /* Load nodes */ RDFQuery query(Glib::ustring( - "SELECT DISTINCT ?name ?plugin ?floatkey ?floatval FROM <") + filename + "> WHERE {\n" + "SELECT DISTINCT ?patch ?name ?plugin ?floatkey ?floatval FROM <") + filename + "> WHERE {\n" "?patch ingen:node ?node .\n" "?node ingen:name ?name ;\n" " ingen:plugin ?plugin ;\n" @@ -63,8 +63,12 @@ Loader::load(const Glib::ustring& filename, RDFQuery::Results nodes = query.run(filename); for (RDFQuery::Results::iterator i = nodes.begin(); i != nodes.end(); ++i) { + + const Glib::ustring& patch = (*i)["patch"]; const Glib::ustring& name = (*i)["name"]; const Glib::ustring& plugin = (*i)["plugin"]; + + cerr << "LOADING NODE IN PATCH : " << patch << endl; if (created.find(name) == created.end()) { _engine->create_node(parent.base() + name, plugin, false); @@ -103,7 +107,7 @@ Loader::load(const Glib::ustring& filename, const Glib::ustring& datatype = (*i)["datatype"]; if (created.find(name) == created.end()) { - cerr << "TYPE: " << type << endl; + //cerr << "TYPE: " << type << endl; bool is_output = (type == "ingen:OutputPort"); // FIXME: check validity _engine->create_port(parent.base() + name, datatype, is_output); created[name] = true; @@ -117,6 +121,42 @@ Loader::load(const Glib::ustring& filename, _engine->set_metadata(parent.base() + name, floatkey, Atom(val)); } } + + /* Load connections */ + + query = RDFQuery(Glib::ustring( + "SELECT DISTINCT ?srcnode ?src ?dstnode ?dst FROM <") + filename + "> WHERE {\n" + "?srcnoderef ingen:port ?srcref .\n" + "?dstnoderef ingen:port ?dstref .\n" + "?dstref ingen:connectedTo ?srcref .\n" + "?srcref ingen:name ?src .\n" + "?dstref ingen:name ?dst .\n" + "OPTIONAL { ?srcnoderef ingen:name ?srcnode } .\n" + "OPTIONAL { ?dstnoderef ingen:name ?dstnode }\n" + "}\n"); + + cerr << "*************\n" << query.string() << "*****************\n"; + + RDFQuery::Results connections = query.run(filename); + + for (RDFQuery::Results::iterator i = connections.begin(); i != connections.end(); ++i) { + // FIXME: kludge + Path src_node = string("/"); + if ((*i).find("srcnode") != (*i).end()) + src_node += string((*i)["srcnode"]); + Path src_port = src_node.base() + string((*i)["src"]); + + Path dst_node = string("/"); + if ((*i).find("dstnode") != (*i).end()) + dst_node += string((*i)["dstnode"]); + Path dst_port = dst_node.base() + string((*i)["dst"]); + + cerr << "CONNECTION: " << src_port << " -> " << dst_port << endl; + + _engine->connect(src_port, dst_port); + } + + } diff --git a/src/libs/client/RDFQuery.cpp b/src/libs/client/RDFQuery.cpp index 02a491bb..3993de20 100644 --- a/src/libs/client/RDFQuery.cpp +++ b/src/libs/client/RDFQuery.cpp @@ -48,8 +48,12 @@ RDFQuery::run(const Glib::ustring filename) const rasqal_literal* rvalue = rasqal_query_results_get_binding_value(results, i); Glib::ustring name((const char*)rname); - Glib::ustring value((const char*)rasqal_literal_as_string(rvalue)); - bindings.insert(std::make_pair(name, value)); + const unsigned char* str = rasqal_literal_as_string(rvalue); + + if (str) { + Glib::ustring value((const char*)str); + bindings.insert(std::make_pair(name, value)); + } } result.push_back(bindings); diff --git a/src/libs/engine/Engine.cpp b/src/libs/engine/Engine.cpp index 6cf50f52..56245534 100644 --- a/src/libs/engine/Engine.cpp +++ b/src/libs/engine/Engine.cpp @@ -14,6 +14,7 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include <cassert> #include "Engine.h" #include "config.h" #include "tuning.h" @@ -48,16 +49,8 @@ using std::cout; using std::cerr; using std::endl; namespace Ingen { -Engine::Engine(AudioDriver* audio_driver) -: m_event_source(NULL), - m_audio_driver( (audio_driver) ? audio_driver : new JackAudioDriver(*this) ), -#ifdef HAVE_JACK_MIDI - m_midi_driver(new JackMidiDriver(((JackAudioDriver*)m_audio_driver)->jack_client())), -#elif HAVE_ALSA_MIDI - m_midi_driver(new AlsaMidiDriver(m_audio_driver)), -#else - m_midi_driver(new DummyMidiDriver()), -#endif +Engine::Engine() +: m_midi_driver(NULL), m_maid(new Maid(maid_queue_size)), m_post_processor(new PostProcessor(*m_maid, post_processor_queue_size)), m_broadcaster(new ClientBroadcaster()), @@ -88,7 +81,6 @@ Engine::~Engine() delete m_broadcaster; delete m_node_factory; delete m_midi_driver; - delete m_audio_driver; delete m_maid; @@ -105,7 +97,7 @@ Engine::~Engine() template<> Driver<MidiMessage>* Engine::driver<MidiMessage>() { return m_midi_driver; } template<> -Driver<Sample>* Engine::driver<Sample>() { return m_audio_driver; } +Driver<Sample>* Engine::driver<Sample>() { return m_audio_driver.get(); } int @@ -147,12 +139,28 @@ Engine::main_iteration() } -void -Engine::activate() +bool +Engine::activate(SharedPtr<AudioDriver> ad, SharedPtr<EventSource> es) { if (m_activated) - return; + return false; + + // Setup drivers + m_audio_driver = ad; +#ifdef HAVE_JACK_MIDI + m_midi_driver = new JackMidiDriver(((JackAudioDriver*)m_audio_driver.get())->jack_client()); +#elif HAVE_ALSA_MIDI + m_midi_driver = new AlsaMidiDriver(m_audio_driver); +#else + m_midi_driver = new DummyMidiDriver(); +#endif + // Set event source (FIXME: handle multiple sources) + m_event_source = es; + + m_audio_driver->activate(); + m_event_source->activate(); + // Create root patch CreatePatchEvent create_ev(*this, SharedPtr<Responder>(new Responder()), 0, "/", 1); create_ev.pre_process(); @@ -173,6 +181,8 @@ Engine::activate() m_post_processor->start(); m_activated = true; + + return true; } @@ -199,6 +209,10 @@ Engine::deactivate() m_post_processor->whip(); m_post_processor->stop(); + m_audio_driver.reset(); + + m_event_source.reset(); + m_activated = false; } diff --git a/src/libs/engine/Engine.h b/src/libs/engine/Engine.h index f584ee6d..01aaa3a1 100644 --- a/src/libs/engine/Engine.h +++ b/src/libs/engine/Engine.h @@ -19,6 +19,7 @@ #include <cassert> #include <boost/utility.hpp> +#include <raul/SharedPtr.h> template<typename T> class Queue; class Maid; @@ -41,17 +42,15 @@ template <typename T> class Driver; /** The main class for the Engine. * - * With access to this you can find any object that's a part of the engine. - * Access to this should be limited as possible, it basically exists so - * there's something to pass Event constructors so they can access what - * they need to perform their function. + * This is a (GoF) facade for the engine. Pointers to all components are + * available for more advanced control than this facade allows. * * \ingroup engine */ class Engine : boost::noncopyable { public: - Engine(AudioDriver* audio_driver = 0); + Engine(); ~Engine(); int main(); @@ -61,15 +60,13 @@ public: * Note that it will take some time. */ void quit() { m_quit_flag = true; } - void activate(); + bool activate(SharedPtr<AudioDriver> ad, SharedPtr<EventSource> es); void deactivate(); bool activated() { return m_activated; } - void set_event_source(EventSource* es) { m_event_source = es; } - - EventSource* event_source() const { return m_event_source; } - AudioDriver* audio_driver() const { return m_audio_driver; } + EventSource* event_source() const { return m_event_source.get(); } + AudioDriver* audio_driver() const { return m_audio_driver.get(); } MidiDriver* midi_driver() const { return m_midi_driver; } Maid* maid() const { return m_maid; } PostProcessor* post_processor() const { return m_post_processor; } @@ -82,15 +79,15 @@ public: template<typename T> Driver<T>* driver(); private: - EventSource* m_event_source; - AudioDriver* m_audio_driver; - MidiDriver* m_midi_driver; - Maid* m_maid; - PostProcessor* m_post_processor; - ClientBroadcaster* m_broadcaster; - ObjectStore* m_object_store; - NodeFactory* m_node_factory; - LashDriver* m_lash_driver; + SharedPtr<EventSource> m_event_source; + SharedPtr<AudioDriver> m_audio_driver; + MidiDriver* m_midi_driver; + Maid* m_maid; + PostProcessor* m_post_processor; + ClientBroadcaster* m_broadcaster; + ObjectStore* m_object_store; + NodeFactory* m_node_factory; + LashDriver* m_lash_driver; bool m_quit_flag; bool m_activated; diff --git a/src/libs/engine/EventSource.h b/src/libs/engine/EventSource.h index d251cac5..cb78e4dd 100644 --- a/src/libs/engine/EventSource.h +++ b/src/libs/engine/EventSource.h @@ -44,7 +44,13 @@ public: virtual ~EventSource() {} - virtual void process(PostProcessor& dest, SampleCount nframes, FrameTime cycle_start, FrameTime cycle_end) = 0; + virtual void activate() = 0; + virtual void deactivate() = 0; + + virtual void process(PostProcessor& dest, + SampleCount nframes, + FrameTime cycle_start, + FrameTime cycle_end) = 0; protected: EventSource() {} diff --git a/src/libs/engine/JackAudioDriver.cpp b/src/libs/engine/JackAudioDriver.cpp index 756cfd68..81f15a78 100644 --- a/src/libs/engine/JackAudioDriver.cpp +++ b/src/libs/engine/JackAudioDriver.cpp @@ -118,7 +118,9 @@ JackAudioPort::prepare_buffer(jack_nframes_t nframes) //// JackAudioDriver //// -JackAudioDriver::JackAudioDriver(Engine& engine, jack_client_t* jack_client) +JackAudioDriver::JackAudioDriver(Engine& engine, + std::string server_name, + jack_client_t* jack_client) : _engine(engine), _client(jack_client), _buffer_size(jack_client ? jack_get_buffer_size(jack_client) : 0), @@ -128,11 +130,29 @@ JackAudioDriver::JackAudioDriver(Engine& engine, jack_client_t* jack_client) _root_patch(NULL) { if (!_client) { - _client = jack_client_new("Ingen"); - if (_client == NULL) { + // Try supplied server name + if (server_name != "") { + _client = jack_client_open("Ingen", JackServerName, NULL, server_name.c_str()); + if (_client) + cerr << "[JackAudioDriver] Connected to JACK server '" << + server_name << "'" << endl; + } + + // Either server name not specified, or supplied server name does not exist + // Connect to default server + if (!_client) { + _client = jack_client_open("Ingen", JackNullOption, NULL); + + if (_client) + cerr << "[JackAudioDriver] Connected to default JACK server." << endl; + } + + // Still failed + if (!_client) { cerr << "[JackAudioDriver] Unable to connect to Jack. Exiting." << endl; exit(EXIT_FAILURE); } + _buffer_size = jack_get_buffer_size(_client); _sample_rate = jack_get_sample_rate(_client); } @@ -272,11 +292,14 @@ JackAudioDriver::_process_cb(jack_nframes_t nframes) if (_engine.event_source()) _engine.event_source()->process(*_engine.post_processor(), nframes, start_of_last_cycle, start_of_current_cycle); + assert(_engine.midi_driver()); _engine.midi_driver()->prepare_block(start_of_last_cycle, start_of_current_cycle); // Set buffers of patch ports to Jack port buffers (zero-copy processing) - for (List<JackAudioPort*>::iterator i = _ports.begin(); i != _ports.end(); ++i) + for (List<JackAudioPort*>::iterator i = _ports.begin(); i != _ports.end(); ++i) { + assert(*i); (*i)->prepare_buffer(nframes); + } // Run root patch assert(_root_patch != NULL); diff --git a/src/libs/engine/JackAudioDriver.h b/src/libs/engine/JackAudioDriver.h index 3780c180..15651c26 100644 --- a/src/libs/engine/JackAudioDriver.h +++ b/src/libs/engine/JackAudioDriver.h @@ -72,7 +72,10 @@ private: class JackAudioDriver : public AudioDriver { public: - JackAudioDriver(Engine& engine, jack_client_t *jack_client = 0); + JackAudioDriver(Engine& engine, + std::string server_name = "", + jack_client_t* jack_client = 0); + ~JackAudioDriver(); void activate(); @@ -136,23 +139,27 @@ private: inline int JackAudioDriver::process_cb(jack_nframes_t nframes, void* jack_driver) { + assert(jack_driver); return ((JackAudioDriver*)jack_driver)->_process_cb(nframes); } inline void JackAudioDriver::shutdown_cb(void* jack_driver) { + assert(jack_driver); return ((JackAudioDriver*)jack_driver)->_shutdown_cb(); } inline int JackAudioDriver::buffer_size_cb(jack_nframes_t nframes, void* jack_driver) { + assert(jack_driver); return ((JackAudioDriver*)jack_driver)->_buffer_size_cb(nframes); } inline int JackAudioDriver::sample_rate_cb(jack_nframes_t nframes, void* jack_driver) { + assert(jack_driver); return ((JackAudioDriver*)jack_driver)->_sample_rate_cb(nframes); } diff --git a/src/libs/engine/Makefile.am b/src/libs/engine/Makefile.am index 0b12e524..3e4edf2c 100644 --- a/src/libs/engine/Makefile.am +++ b/src/libs/engine/Makefile.am @@ -93,8 +93,6 @@ libingen_la_SOURCES = \ events/UnregisterClientEvent.h \ events/UnregisterClientEvent.cpp \ events/PingQueuedEvent.h \ - events/ActivateEvent.h \ - events/ActivateEvent.cpp \ events/DeactivateEvent.h \ events/DeactivateEvent.cpp \ events/SetPortValueEvent.h \ diff --git a/src/libs/engine/QueuedEngineInterface.cpp b/src/libs/engine/QueuedEngineInterface.cpp index 4628bdfd..ca6cf8cf 100644 --- a/src/libs/engine/QueuedEngineInterface.cpp +++ b/src/libs/engine/QueuedEngineInterface.cpp @@ -98,9 +98,9 @@ QueuedEngineInterface::load_plugins() void -QueuedEngineInterface::activate() +QueuedEngineInterface::activate() { - push_queued(new ActivateEvent(*_engine.get(), _responder, now())); + push_queued(new PingQueuedEvent(*_engine.get(), _responder, now())); } diff --git a/src/libs/engine/events.h b/src/libs/engine/events.h index 056c302d..73cd2ae8 100644 --- a/src/libs/engine/events.h +++ b/src/libs/engine/events.h @@ -19,7 +19,6 @@ #include "config.h" -#include "ActivateEvent.h" #include "DeactivateEvent.h" #include "EnablePatchEvent.h" #include "DisablePatchEvent.h" diff --git a/src/libs/engine/events/ActivateEvent.cpp b/src/libs/engine/events/ActivateEvent.cpp deleted file mode 100644 index 6c64f190..00000000 --- a/src/libs/engine/events/ActivateEvent.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* This file is part of Ingen. Copyright (C) 2006 Dave 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 - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "ActivateEvent.h" -#include "Responder.h" -#include "Engine.h" - -namespace Ingen { - - -ActivateEvent::ActivateEvent(Engine& engine, SharedPtr<Responder> responder, SampleCount timestamp) -: QueuedEvent(engine, responder, timestamp) -{ - _engine.activate(); -} - -void -ActivateEvent::post_process() -{ - _responder->respond_ok(); -} - - -} // namespace Ingen - diff --git a/src/libs/engine/events/ActivateEvent.h b/src/libs/engine/events/ActivateEvent.h deleted file mode 100644 index 642859a7..00000000 --- a/src/libs/engine/events/ActivateEvent.h +++ /dev/null @@ -1,40 +0,0 @@ -/* This file is part of Ingen. Copyright (C) 2006 Dave 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 - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef ACTIVATEEVENT_H -#define ACTIVATEEVENT_H - -#include "QueuedEvent.h" - -namespace Ingen { - - -/** Activates the engine. - * - * \ingroup engine - */ -class ActivateEvent : public QueuedEvent -{ -public: - ActivateEvent(Engine& engine, SharedPtr<Responder> responder, SampleCount timestamp); - - void post_process(); -}; - - -} // namespace Ingen - -#endif // ACTIVATEEVENT_H |