diff options
-rw-r--r-- | Namespaces.cpp | 43 | ||||
-rw-r--r-- | RDFQuery.cpp | 80 | ||||
-rw-r--r-- | raul/JackDriver.h | 109 | ||||
-rw-r--r-- | raul/Makefile.am | 5 | ||||
-rw-r--r-- | raul/Namespaces.h | 38 | ||||
-rw-r--r-- | raul/RDFQuery.h | 77 | ||||
-rw-r--r-- | src/JackDriver.cpp | 209 | ||||
-rw-r--r-- | src/Makefile.am | 5 |
8 files changed, 564 insertions, 2 deletions
diff --git a/Namespaces.cpp b/Namespaces.cpp new file mode 100644 index 0000000..545e1db --- /dev/null +++ b/Namespaces.cpp @@ -0,0 +1,43 @@ +/* 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 "Namespaces.h" + +namespace Ingen { +namespace Client { + + +/** Create a prefixed qname from @a uri, if possible. + * + * If @a uri can not be qualified with the namespaces currently in this + * Namespaces, @a uri will be returned unmodified. + */ +std::string +Namespaces::qualify(std::string uri) +{ + for (iterator i = begin(); i != end(); ++i) { + size_t ns_len = i->second.length(); + + if (uri.substr(0, ns_len) == i->second) + return i->first + ":" + uri.substr(ns_len); + } + + return uri; +} + + +} // namespace Client +} // namespace Ingen diff --git a/RDFQuery.cpp b/RDFQuery.cpp new file mode 100644 index 0000000..196868b --- /dev/null +++ b/RDFQuery.cpp @@ -0,0 +1,80 @@ +/* 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 <iostream> +#include <cassert> +#include <rasqal.h> +#include "RDFQuery.h" + +#include <iostream> +using std::cerr; using std::endl; + +namespace Ingen { +namespace Client { + + +RDFQuery::Results +RDFQuery::run(const Glib::ustring base_uri_str) const +{ + Results result; + + rasqal_init(); + + rasqal_query *rq = rasqal_new_query("sparql", NULL); + + raptor_uri* base_uri = NULL; + if (base_uri_str != "") + base_uri = raptor_new_uri((const unsigned char*)base_uri_str.c_str()); + rasqal_query_prepare(rq, (unsigned char*)_query.c_str(), base_uri); + + rasqal_query_results* results = rasqal_query_execute(rq); + assert(results); + + while (!rasqal_query_results_finished(results)) { + + Bindings bindings; + + for (int i=0; i < rasqal_query_results_get_bindings_count(results); i++) { + const unsigned char* rname = rasqal_query_results_get_binding_name(results, i); + rasqal_literal* rvalue = rasqal_query_results_get_binding_value(results, i); + Glib::ustring name((const char*)rname); + + 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); + rasqal_query_results_next(results); + } + + rasqal_free_query_results(results); + rasqal_free_query(rq); + + if (base_uri) + raptor_free_uri(base_uri); + + rasqal_finish(); + + return result; +} + + +} // namespace Client +} // namespace Ingen diff --git a/raul/JackDriver.h b/raul/JackDriver.h new file mode 100644 index 0000000..52e22cd --- /dev/null +++ b/raul/JackDriver.h @@ -0,0 +1,109 @@ +/* This file is part of Patchage. Copyright (C) 2005 Dave Robillard. + * + * Patchage 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. + * + * Patchage 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., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef RAUL_JACKDRIVER_H +#define RAUL_JACKDRIVER_H + +#include <iostream> +#include <string> +#include <jack/jack.h> +#include <jack/statistics.h> + +using std::string; + + +/** Handles all externally driven functionality, registering ports etc. + * + * Jack callbacks and connect methods and things like that live here. + * Right now just for jack ports, but that will change... + */ +class JackDriver +{ +public: + JackDriver(); + virtual ~JackDriver(); + + void attach(const string& client_name); + void detach(); + + bool is_attached() const { return (m_client != NULL); } + bool is_realtime() const { return m_client && jack_is_realtime(m_client); } + + void start_transport() { jack_transport_start(m_client); } + void stop_transport() { jack_transport_stop(m_client); } + + void rewind_transport() { + jack_position_t zero; + zero.frame = 0; + zero.valid = (jack_position_bits_t)0; + jack_transport_reposition(m_client, &zero); + } + + jack_nframes_t buffer_size(); + bool set_buffer_size(jack_nframes_t size); + + inline float sample_rate() { return jack_get_sample_rate(m_client); } + + inline size_t xruns() { return m_xruns; } + void reset_xruns(); + + inline float max_delay() { return jack_get_max_delayed_usecs(m_client); } + inline void reset_delay() { jack_reset_max_delayed_usecs(m_client); } + +protected: + /** Process callback. Derived classes should do all audio processing here. */ + virtual void on_process(jack_nframes_t nframes) {} + + /** Graph order change callback. */ + virtual void on_graph_order_changed() {} + + /** Buffer size changed callback. + * At the time this is called, buffer_size() will still return the old + * size. Immediately afterwards, it will be set to the new value. + */ + virtual void on_buffer_size_changed(jack_nframes_t size) {} + + virtual void on_xrun() {} + virtual void on_shutdown() {} + virtual void on_error() {} + +private: + + static void error_cb(const char* msg); + + void destroy_all_ports(); + + void update_time(); + + + + static void jack_port_registration_cb(jack_port_id_t port_id, int registered, void* me); + static int jack_graph_order_cb(void* me); + static int jack_buffer_size_cb(jack_nframes_t buffer_size, void* me); + static int jack_xrun_cb(void* me); + static void jack_shutdown_cb(void* me); + + jack_client_t* m_client; + + bool m_is_activated; + jack_position_t m_last_pos; + jack_nframes_t m_buffer_size; + size_t m_xruns; + float m_xrun_delay; +}; + + +#endif // RAUL_JACKDRIVER_H diff --git a/raul/Makefile.am b/raul/Makefile.am index fa79ae3..64cc7ed 100644 --- a/raul/Makefile.am +++ b/raul/Makefile.am @@ -11,7 +11,10 @@ raulinclude_HEADERS = \ Process.h \ Thread.h \ Slave.h \ - Atom.h + Atom.h \ + JackDriver.h \ + RDFQuery.h \ + Namespaces.h if WITH_LIBLO raulinclude_HEADERS += AtomLiblo.h diff --git a/raul/Namespaces.h b/raul/Namespaces.h new file mode 100644 index 0000000..ab2c45a --- /dev/null +++ b/raul/Namespaces.h @@ -0,0 +1,38 @@ +/* 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 RAUL_NAMESPACES_H +#define RAUL_NAMESPACES_H + +#include <map> +#include <string> + +namespace Ingen { +namespace Client { + + +/** Collection of RDF namespaces with prefixes. + */ +class Namespaces : public std::map<std::string, std::string> { +public: + std::string qualify(std::string uri); +}; + + +} // namespace Client +} // namespace Ingen + +#endif // RAUL_NAMESPACES_H diff --git a/raul/RDFQuery.h b/raul/RDFQuery.h new file mode 100644 index 0000000..5e972ca --- /dev/null +++ b/raul/RDFQuery.h @@ -0,0 +1,77 @@ +/* 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 RAUL_RDFQUERY_H +#define RAUL_RDFQUERY_H + +#include <map> +#include <list> +#include <glibmm/ustring.h> +#include "raul/Namespaces.h" + +namespace Ingen { +namespace Client { + + +/** Pretty wrapper for a SPARQL query. + * + * Automatically handles things like prepending prefixes, etc. Ingen specific. + */ +class RDFQuery { +public: + typedef std::map<Glib::ustring, Glib::ustring> Bindings; + typedef std::list<Bindings> Results; + + RDFQuery(const Namespaces& prefixes, Glib::ustring query) + { + // Prepend prefix header + for (Namespaces::const_iterator i = prefixes.begin(); + i != prefixes.end(); ++i) { + _query = "PREFIX "; + _query += i->first + ": <" + i->second + ">\n"; + } + _query += "\n"; + _query += query; + + /*const char* const prefix_header = + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n" + "PREFIX ingen: <http://codeson.net/ns/ingen#>\n" + "PREFIX lv2: <http://lv2plug.in/ontology#>\n"; + + _query = _prefix_header + query;*/ + } + + /*RDFQuery(Glib::ustring query) + { + _query = _prefix_header + query; + }*/ + + Results run(const Glib::ustring base_uri) const; + + Glib::ustring string() const { return _query; }; + +private: + + Glib::ustring _query; +}; + + +} // namespace Client +} // namespace Ingen + +#endif // RAUL_RDFQUERY_H + diff --git a/src/JackDriver.cpp b/src/JackDriver.cpp new file mode 100644 index 0000000..0bbc24b --- /dev/null +++ b/src/JackDriver.cpp @@ -0,0 +1,209 @@ +/* This file is part of Patchage. Copyright (C) 2005 Dave Robillard. + * + * Patchage 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. + * + * Patchage 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., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <cassert> +#include <cstring> +#include <string> +#include <iostream> +#include <jack/jack.h> +#include <jack/statistics.h> +#include <jack/thread.h> +#include "raul/JackDriver.h" + +using std::cerr; using std::endl; +using std::string; + + +JackDriver::JackDriver() +//: m_app(app) +: m_client(NULL) +, m_is_activated(false) +, m_xruns(0) +, m_xrun_delay(0) +{ + m_last_pos.frame = 0; + m_last_pos.valid = (jack_position_bits_t)0; +} + + +JackDriver::~JackDriver() +{ + detach(); +} + + +/** Connect to Jack. + */ +void +JackDriver::attach(const string& client_name) +{ + // Already connected + if (m_client) + return; + + jack_set_error_function(error_cb); + + m_client = jack_client_open(client_name.c_str(), JackNullOption, NULL); + if (m_client == NULL) { + //m_app->status_message("[JACK] Unable to create client"); + m_is_activated = false; + } else { + jack_set_error_function(error_cb); + jack_on_shutdown(m_client, jack_shutdown_cb, this); + jack_set_port_registration_callback(m_client, jack_port_registration_cb, this); + jack_set_graph_order_callback(m_client, jack_graph_order_cb, this); + jack_set_buffer_size_callback(m_client, jack_buffer_size_cb, this); + jack_set_xrun_callback(m_client, jack_xrun_cb, this); + + //m_is_dirty = true; + m_buffer_size = jack_get_buffer_size(m_client); + + if (!jack_activate(m_client)) { + m_is_activated = true; + //signal_attached.emit(); + //m_app->status_message("[JACK] Attached"); + } else { + //m_app->status_message("[JACK] ERROR: Failed to attach"); + m_is_activated = false; + } + } +} + + +void +JackDriver::detach() +{ + if (m_client) { + jack_deactivate(m_client); + jack_client_close(m_client); + m_client = NULL; + m_is_activated = false; + //signal_detached.emit(); + } +} + + +void +JackDriver::jack_port_registration_cb(jack_port_id_t port_id, int registered, void* jack_driver) +{ + /* shrug. */ +} + + +int +JackDriver::jack_graph_order_cb(void* jack_driver) +{ + JackDriver* me = reinterpret_cast<JackDriver*>(jack_driver); + + assert(me); + me->on_graph_order_changed(); + + return 0; +} + + +int +JackDriver::jack_buffer_size_cb(jack_nframes_t buffer_size, void* jack_driver) +{ + JackDriver* me = reinterpret_cast<JackDriver*>(jack_driver); + + assert(me); + me->reset_xruns(); + me->reset_delay(); + me->on_buffer_size_changed(buffer_size); + me->m_buffer_size = buffer_size; + + return 0; +} + + +int +JackDriver::jack_xrun_cb(void* jack_driver) +{ + JackDriver* me = reinterpret_cast<JackDriver*>(jack_driver); + + assert(me); + + me->m_xruns++; + me->m_xrun_delay = jack_get_xrun_delayed_usecs(me->m_client); + me->reset_delay(); + + me->on_xrun(); + + return 0; +} + + +void +JackDriver::jack_shutdown_cb(void* jack_driver) +{ + JackDriver* me = reinterpret_cast<JackDriver*>(jack_driver); + assert(me); + + me->reset_delay(); + me->reset_xruns(); + + me->on_shutdown(); + + me->m_client = NULL; +} + + +void +JackDriver::error_cb(const char* msg) +{ + cerr << "JACK ERROR: " << msg << endl; +} + + +jack_nframes_t +JackDriver::buffer_size() +{ + if (m_is_activated) + return m_buffer_size; + else + return jack_get_buffer_size(m_client); +} + + +void +JackDriver::reset_xruns() +{ + m_xruns = 0; + m_xrun_delay = 0; +} + + +bool +JackDriver::set_buffer_size(jack_nframes_t size) +{ + if (buffer_size() == size) { + return true; + } + + if (!m_client) { + m_buffer_size = size; + return true; + } + + if (jack_set_buffer_size(m_client, size)) { + //m_app->status_message("[JACK] ERROR: Unable to set buffer size"); + return false; + } else { + return true; + } +} + diff --git a/src/Makefile.am b/src/Makefile.am index bbbad24..d0cef87 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,6 +8,9 @@ lib_LTLIBRARIES = libraul.la libraul_la_SOURCES = \ Thread.cpp \ Path.cpp \ - RDFWriter.cpp + RDFWriter.cpp \ + JackDriver.cpp \ + RDFQuery.cpp \ + Namespaces.cpp |