diff options
Diffstat (limited to 'src/server')
-rw-r--r-- | src/server/Engine.cpp | 59 | ||||
-rw-r--r-- | src/server/Event.hpp | 2 | ||||
-rw-r--r-- | src/server/LV2Plugin.cpp | 2 | ||||
-rw-r--r-- | src/server/PreProcessor.cpp | 2 | ||||
-rw-r--r-- | src/server/SocketListener.cpp | 4 | ||||
-rw-r--r-- | src/server/SocketServer.hpp | 6 | ||||
-rw-r--r-- | src/server/UndoStack.cpp | 153 | ||||
-rw-r--r-- | src/server/UndoStack.hpp | 22 | ||||
-rw-r--r-- | src/server/events/Copy.cpp | 5 | ||||
-rw-r--r-- | src/server/events/Delta.cpp | 8 | ||||
-rw-r--r-- | src/server/ingen_lv2.cpp | 24 | ||||
-rw-r--r-- | src/server/wscript | 2 |
12 files changed, 147 insertions, 142 deletions
diff --git a/src/server/Engine.cpp b/src/server/Engine.cpp index 8256981b..f1a86792 100644 --- a/src/server/Engine.cpp +++ b/src/server/Engine.cpp @@ -68,31 +68,37 @@ INGEN_THREAD_LOCAL unsigned ThreadManager::flags(0); bool ThreadManager::single_threaded(true); Engine::Engine(ingen::World& world) - : _world(world) - , _options(new LV2Options(world.uris())) - , _buffer_factory(new BufferFactory(*this, world.uris())) - , _maid(new Raul::Maid) - , _worker(new Worker(world.log(), event_queue_size())) - , _sync_worker(new Worker(world.log(), event_queue_size(), true)) - , _broadcaster(new Broadcaster()) - , _control_bindings(new ControlBindings(*this)) - , _block_factory(new BlockFactory(world)) - , _undo_stack(new UndoStack(world.uris(), world.uri_map())) - , _redo_stack(new UndoStack(world.uris(), world.uri_map())) - , _post_processor(new PostProcessor(*this)) - , _pre_processor(new PreProcessor(*this)) - , _event_writer(new EventWriter(*this)) - , _interface(_event_writer) - , _atom_interface( - new AtomReader(world.uri_map(), world.uris(), world.log(), *_interface)) - , _root_graph(nullptr) - , _cycle_start_time(0) - , _rand_engine(reinterpret_cast<uintptr_t>(this)) - , _uniform_dist(0.0f, 1.0f) - , _quit_flag(false) - , _reset_load_flag(false) - , _atomic_bundles(world.conf().option("atomic-bundles").get<int32_t>()) - , _activated(false) + : _world(world) + , _options(new LV2Options(world.uris())) + , _buffer_factory(new BufferFactory(*this, world.uris())) + , _maid(new Raul::Maid) + , _worker(new Worker(world.log(), event_queue_size())) + , _sync_worker(new Worker(world.log(), event_queue_size(), true)) + , _broadcaster(new Broadcaster()) + , _control_bindings(new ControlBindings(*this)) + , _block_factory(new BlockFactory(world)) + , _undo_stack(new UndoStack(world.rdf_world(), + world.uris(), + world.uri_map())) + , _redo_stack(new UndoStack(world.rdf_world(), + world.uris(), + world.uri_map())) + , _post_processor(new PostProcessor(*this)) + , _pre_processor(new PreProcessor(*this)) + , _event_writer(new EventWriter(*this)) + , _interface(_event_writer) + , _atom_interface(new AtomReader(world.uri_map(), + world.uris(), + world.log(), + *_interface)) + , _root_graph(nullptr) + , _cycle_start_time(0) + , _rand_engine(reinterpret_cast<uintptr_t>(this)) + , _uniform_dist(0.0f, 1.0f) + , _quit_flag(false) + , _reset_load_flag(false) + , _atomic_bundles(world.conf().option("atomic-bundles").get<int32_t>()) + , _activated(false) { if (!world.store()) { world.set_store(std::make_shared<ingen::Store>()); @@ -125,7 +131,8 @@ Engine::Engine(ingen::World& world) _interface = std::make_shared<Tee>( Tee::Sinks{ _event_writer, - std::make_shared<StreamWriter>(world.uri_map(), + std::make_shared<StreamWriter>(world.rdf_world(), + world.uri_map(), world.uris(), URI("ingen:/engine"), stderr, diff --git a/src/server/Event.hpp b/src/server/Event.hpp index 7da4b955..f5c826b4 100644 --- a/src/server/Event.hpp +++ b/src/server/Event.hpp @@ -133,7 +133,7 @@ protected: } inline bool pre_process_done(Status st, const URI& subject) { - _err_subject = subject; + _err_subject = std::string{subject}; return pre_process_done(st); } diff --git a/src/server/LV2Plugin.cpp b/src/server/LV2Plugin.cpp index 01357d8d..40ba34e7 100644 --- a/src/server/LV2Plugin.cpp +++ b/src/server/LV2Plugin.cpp @@ -68,7 +68,7 @@ LV2Plugin::update_properties() Raul::Symbol LV2Plugin::symbol() const { - std::string working = uri(); + std::string working(uri()); if (working.back() == '/') { working = working.substr(0, working.length() - 1); } diff --git a/src/server/PreProcessor.cpp b/src/server/PreProcessor.cpp index 872302c0..76e0ac73 100644 --- a/src/server/PreProcessor.cpp +++ b/src/server/PreProcessor.cpp @@ -176,8 +176,10 @@ PreProcessor::run() UndoStack& undo_stack = *_engine.undo_stack(); UndoStack& redo_stack = *_engine.redo_stack(); AtomWriter undo_writer( + _engine.world().rdf_world(), _engine.world().uri_map(), _engine.world().uris(), undo_stack); AtomWriter redo_writer( + _engine.world().rdf_world(), _engine.world().uri_map(), _engine.world().uris(), redo_stack); ThreadManager::set_flag(THREAD_PRE_PROCESS); diff --git a/src/server/SocketListener.cpp b/src/server/SocketListener.cpp index b4b50a14..51e07b2b 100644 --- a/src/server/SocketListener.cpp +++ b/src/server/SocketListener.cpp @@ -92,7 +92,7 @@ ingen_listen(Engine* engine, Raul::Socket* unix_sock, Raul::Socket* net_sock) // Bind UNIX socket and create PID-less symbolic link const URI unix_uri(unix_scheme + unix_path); bool make_link = true; - if (!unix_sock->bind(unix_uri) || !unix_sock->listen()) { + if (!unix_sock->bind(unix_uri.str()) || !unix_sock->listen()) { world.log().error("Failed to create UNIX socket\n"); unix_sock->close(); make_link = false; @@ -130,7 +130,7 @@ ingen_listen(Engine* engine, Raul::Socket* unix_sock, Raul::Socket* net_sock) const int port = world.conf().option("engine-port").get<int32_t>(); std::ostringstream ss; ss << "tcp://*:" << port; - if (!net_sock->bind(URI(ss.str())) || !net_sock->listen()) { + if (!net_sock->bind(ss.str()) || !net_sock->listen()) { world.log().error("Failed to create TCP socket\n"); net_sock->close(); } else { diff --git a/src/server/SocketServer.hpp b/src/server/SocketServer.hpp index f3f02a26..86f81d65 100644 --- a/src/server/SocketServer.hpp +++ b/src/server/SocketServer.hpp @@ -43,14 +43,16 @@ public: , _sink(world.conf().option("dump").get<int32_t>() ? SPtr<Interface>( new Tee({SPtr<Interface>(new EventWriter(engine)), - SPtr<Interface>(new StreamWriter(world.uri_map(), + SPtr<Interface>(new StreamWriter(world.rdf_world(), + world.uri_map(), world.uris(), URI("ingen:/engine"), stderr, ColorContext::Color::CYAN))})) : SPtr<Interface>(new EventWriter(engine))) , _reader(new SocketReader(world, *_sink.get(), sock)) - , _writer(new SocketWriter(world.uri_map(), + , _writer(new SocketWriter(world.rdf_world(), + world.uri_map(), world.uris(), URI(sock->uri()), sock)) diff --git a/src/server/UndoStack.cpp b/src/server/UndoStack.cpp index a94617a5..d6829200 100644 --- a/src/server/UndoStack.cpp +++ b/src/server/UndoStack.cpp @@ -23,15 +23,14 @@ #include "lv2/patch/patch.h" #include "lv2/urid/urid.h" #include "serd/serd.h" -#include "sratom/sratom.h" +#include "sratom/sratom.hpp" #include <ctime> +#include <fstream> #include <iterator> #include <memory> -#define NS_RDF (const uint8_t*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#" - -#define USTR(s) ((const uint8_t*)(s)) +#define NS_RDF "http://www.w3.org/1999/02/22-rdf-syntax-ns#" namespace ingen { namespace server { @@ -120,9 +119,9 @@ UndoStack::pop() struct BlankIDs { explicit BlankIDs(char c='b') : c(c) {} - SerdNode get() { + serd::Node get() { snprintf(buf, sizeof(buf), "%c%u", c, n++); - return serd_node_from_string(SERD_BLANK, USTR(buf)); + return serd::make_blank(buf); } char buf[16]{}; @@ -131,126 +130,120 @@ struct BlankIDs { }; struct ListContext { - explicit ListContext(BlankIDs& ids, unsigned flags, const SerdNode* s, const SerdNode* p) - : ids(ids) - , s(*s) - , p(*p) - , flags(flags | SERD_LIST_O_BEGIN) + explicit ListContext(BlankIDs& ids, + serd::StatementFlags flags, + const serd::Node& s, + const serd::Node& p) + : ids(ids) + , s(s) + , p(p) + , flags(flags | serd::StatementFlag::list_O) {} - SerdNode start_node(SerdWriter* writer) { - const SerdNode node = ids.get(); - serd_writer_write_statement(writer, flags, nullptr, &s, &p, &node, nullptr, nullptr); + serd::Node start_node(serd::Writer& writer) { + const serd::Node node = ids.get(); + writer.sink().write(flags, s, p, node); return node; } - void append(SerdWriter* writer, unsigned oflags, const SerdNode* value) { + void append(serd::Writer& writer, + serd::StatementFlags oflags, + const serd::Node& value) + { // s p node - const SerdNode node = start_node(writer); + const serd::Node node = start_node(writer); // node rdf:first value - p = serd_node_from_string(SERD_URI, NS_RDF "first"); - flags = SERD_LIST_CONT; - serd_writer_write_statement(writer, flags|oflags, nullptr, &node, &p, value, nullptr, nullptr); + p = serd::make_uri(NS_RDF "first"); + flags = {}; + writer.sink().write(flags | oflags, node, p, value); - end_node(writer, &node); + end_node(writer, node); } - void end_node(SerdWriter*, const SerdNode* node) { + void end_node(serd::Writer&, const serd::Node& node) { // Prepare for next call: node rdf:rest ... - s = *node; - p = serd_node_from_string(SERD_URI, NS_RDF "rest"); + s = node; + p = serd::make_uri(NS_RDF "rest"); } - void end(SerdWriter* writer) { - const SerdNode nil = serd_node_from_string(SERD_URI, NS_RDF "nil"); - serd_writer_write_statement(writer, flags, nullptr, &s, &p, &nil, nullptr, nullptr); + void end(serd::Writer& writer) { + const serd::Node nil = serd::make_uri(NS_RDF "nil"); + writer.sink().write(flags, s, p, nil); } - BlankIDs& ids; - SerdNode s; - SerdNode p; - unsigned flags; + BlankIDs& ids; + serd::Node s; + serd::Node p; + serd::StatementFlags flags; }; void -UndoStack::write_entry(Sratom* sratom, - SerdWriter* writer, - const SerdNode* const subject, +UndoStack::write_entry(sratom::Streamer& streamer, + serd::Writer& writer, + const serd::Node& subject, const UndoStack::Entry& entry) { char time_str[24]; strftime(time_str, sizeof(time_str), "%FT%T", gmtime(&entry.time)); - // entry rdf:type ingen:UndoEntry - SerdNode p = serd_node_from_string(SERD_URI, USTR(INGEN_NS "time")); - SerdNode o = serd_node_from_string(SERD_LITERAL, USTR(time_str)); - serd_writer_write_statement(writer, SERD_ANON_CONT, nullptr, subject, &p, &o, nullptr, nullptr); + writer.sink().write({}, + subject, + serd::make_uri(INGEN_NS "time"), + serd::make_string(time_str)); - p = serd_node_from_string(SERD_URI, USTR(INGEN_NS "events")); + serd::Node p = serd::make_uri(INGEN_NS "events"); BlankIDs ids('e'); - ListContext ctx(ids, SERD_ANON_CONT, subject, &p); + ListContext ctx(ids, {}, subject, p); for (const LV2_Atom* atom : entry.events) { - const SerdNode node = ctx.start_node(writer); - - p = serd_node_from_string(SERD_URI, NS_RDF "first"); - ctx.flags = SERD_LIST_CONT; - sratom_write(sratom, &_map.urid_unmap_feature()->urid_unmap, SERD_LIST_CONT, - &node, &p, - atom->type, atom->size, LV2_ATOM_BODY_CONST(atom)); + const serd::Node node = ctx.start_node(writer); - ctx.end_node(writer, &node); + p = serd::make_uri(NS_RDF "first"); + ctx.flags = {}; + streamer.write(writer.sink(), node, p, *atom); + ctx.end_node(writer, node); } ctx.end(writer); } void -UndoStack::save(FILE* stream, const char* name) +UndoStack::save(std::ofstream& stream, const char* name) { - SerdEnv* env = serd_env_new(nullptr); - serd_env_set_prefix_from_strings(env, USTR("atom"), USTR(LV2_ATOM_PREFIX)); - serd_env_set_prefix_from_strings(env, USTR("ingen"), USTR(INGEN_NS)); - serd_env_set_prefix_from_strings(env, USTR("patch"), USTR(LV2_PATCH_PREFIX)); - - const SerdNode base = serd_node_from_string(SERD_URI, USTR("ingen:/")); - SerdURI base_uri; - serd_uri_parse(base.buf, &base_uri); - - SerdWriter* writer = serd_writer_new( - SERD_TURTLE, - (SerdStyle)(SERD_STYLE_RESOLVED|SERD_STYLE_ABBREVIATED|SERD_STYLE_CURIED), - env, - &base_uri, - serd_file_sink, - stream); + serd::Env env; + env.set_prefix("atom", LV2_ATOM_PREFIX); + env.set_prefix("ingen", INGEN_NS); + env.set_prefix("patch", LV2_PATCH_PREFIX); + + const serd::Node base = serd::make_uri("ingen:/"); + + serd::Writer writer(_world, + serd::Syntax::Turtle, + {}, + env, + stream); // Configure sratom to write directly to the writer (and thus the socket) - Sratom* sratom = sratom_new(&_map.urid_map_feature()->urid_map); - sratom_set_sink(sratom, - (const char*)base.buf, - (SerdStatementSink)serd_writer_write_statement, - (SerdEndSink)serd_writer_end_anon, - writer); + sratom::Streamer streamer{_world, + _map.urid_map_feature()->urid_map, + _map.urid_unmap_feature()->urid_unmap}; - SerdNode s = serd_node_from_string(SERD_BLANK, (const uint8_t*)name); - SerdNode p = serd_node_from_string(SERD_URI, USTR(INGEN_NS "entries")); + serd::Node s = serd::make_blank(name); + serd::Node p = serd::make_uri(INGEN_NS "entries"); BlankIDs ids('u'); - ListContext ctx(ids, 0, &s, &p); + ListContext ctx(ids, {}, s, p); for (const Entry& e : _stack) { - const SerdNode entry = ids.get(); - ctx.append(writer, SERD_ANON_O_BEGIN, &entry); - write_entry(sratom, writer, &entry, e); - serd_writer_end_anon(writer, &entry); + const serd::Node entry = ids.get(); + ctx.append(writer, serd::StatementFlag::anon_O, entry); + write_entry(streamer, writer, entry, e); + writer.sink().end(entry); } ctx.end(writer); - sratom_free(sratom); - serd_writer_finish(writer); - serd_writer_free(writer); + writer.finish(); } } // namespace server diff --git a/src/server/UndoStack.hpp b/src/server/UndoStack.hpp index 04021b99..7d79e7fc 100644 --- a/src/server/UndoStack.hpp +++ b/src/server/UndoStack.hpp @@ -21,8 +21,7 @@ #include "ingen/ingen.h" #include "lv2/atom/atom.h" #include "lv2/atom/util.h" -#include "serd/serd.h" -#include "sratom/sratom.h" +#include "serd/serd.hpp" #include <cstdint> #include <cstdio> @@ -30,6 +29,9 @@ #include <cstring> #include <ctime> #include <deque> +#include <iosfwd> + +namespace sratom { class Streamer; } namespace ingen { @@ -80,7 +82,10 @@ public: std::deque<LV2_Atom*> events; }; - UndoStack(URIs& uris, URIMap& map) : _uris(uris), _map(map), _depth(0) {} + UndoStack(serd::World& world, URIs& uris, URIMap& map) + : _world(world), _uris(uris), _map(map), _depth(0) + { + } int start_entry(); bool write(const LV2_Atom* msg, int32_t default_id=0) override; @@ -89,17 +94,18 @@ public: bool empty() const { return _stack.empty(); } Entry pop(); - void save(FILE* stream, const char* name="undo"); + void save(std::ofstream& stream, const char* name="undo"); private: bool ignore_later_event(const LV2_Atom* first, const LV2_Atom* second) const; - void write_entry(Sratom* sratom, - SerdWriter* writer, - const SerdNode* subject, - const Entry& entry); + void write_entry(sratom::Streamer& streamer, + serd::Writer& writer, + const serd::Node& subject, + const Entry& entry); + serd::World& _world; URIs& _uris; URIMap& _map; std::deque<Entry> _stack; diff --git a/src/server/events/Copy.cpp b/src/server/events/Copy.cpp index 5418af4b..5ac31f55 100644 --- a/src/server/events/Copy.cpp +++ b/src/server/events/Copy.cpp @@ -131,9 +131,10 @@ Copy::engine_to_engine(PreProcessContext& ctx) } static bool -ends_with(const std::string& str, const std::string& end) +ends_with(const URI& uri, const std::string& end) { - if (str.length() >= end.length()) { + const auto& str = uri.str(); + if (str.length() >= end.length()) { return !str.compare(str.length() - end.length(), end.length(), end); } return false; diff --git a/src/server/events/Delta.cpp b/src/server/events/Delta.cpp index 0a7b05ea..ab751b76 100644 --- a/src/server/events/Delta.cpp +++ b/src/server/events/Delta.cpp @@ -35,6 +35,8 @@ #include "ingen/World.hpp" #include "raul/Maid.hpp" +#include <boost/optional/optional_io.hpp> + #include <mutex> #include <set> #include <string> @@ -364,7 +366,7 @@ Delta::pre_process(PreProcessContext& ctx) _status = Status::BAD_VALUE_TYPE; } } else if (key == uris.pset_preset) { - URI uri; + boost::optional<URI> uri; if (uris.forge.is_uri(value)) { const std::string uri_str = uris.forge.str(value, false); if (URI::is_valid(uri_str)) { @@ -374,9 +376,9 @@ Delta::pre_process(PreProcessContext& ctx) uri = URI(FilePath(value.ptr<char>())); } - if (!uri.empty()) { + if (uri) { op = SpecialType::PRESET; - if ((_state = block->load_preset(uri))) { + if ((_state = block->load_preset(*uri))) { lilv_state_emit_port_values( _state, s_add_set_event, this); } else { diff --git a/src/server/ingen_lv2.cpp b/src/server/ingen_lv2.cpp index 57663344..8a639765 100644 --- a/src/server/ingen_lv2.cpp +++ b/src/server/ingen_lv2.cpp @@ -60,8 +60,7 @@ #include "raul/RingBuffer.hpp" #include "raul/Semaphore.hpp" #include "raul/Symbol.hpp" -#include "serd/serd.h" -#include "sord/sordmm.hpp" +#include "serd/serd.hpp" #include <algorithm> #include <cstdint> @@ -123,7 +122,8 @@ public: engine.world().uris(), engine.world().log(), *engine.world().interface().get()) - , _writer(engine.world().uri_map(), + , _writer(engine.world().rdf_world(), + engine.world().uri_map(), engine.world().uris(), *this) , _from_ui(ui_ring_size(block_length)) @@ -460,11 +460,10 @@ struct IngenPlugin { static Lib::Graphs find_graphs(const URI& manifest_uri) { - Sord::World world; + serd::World world; Parser parser; const std::set<Parser::ResourceRecord> resources = parser.find_resources( - world, manifest_uri, URI(INGEN__Graph)); @@ -512,11 +511,8 @@ ingen_instantiate(const LV2_Descriptor* descriptor, set_bundle_path(bundle_path); const std::string manifest_path = ingen::bundle_file_path("manifest.ttl"); - SerdNode manifest_node = serd_node_new_file_uri( - (const uint8_t*)manifest_path.c_str(), nullptr, nullptr, true); - - Lib::Graphs graphs = find_graphs(URI((const char*)manifest_node.buf)); - serd_node_free(&manifest_node); + serd::Node manifest_node = serd::make_file_uri(manifest_path); + Lib::Graphs graphs = find_graphs(URI(manifest_node)); const LV2Graph* graph = nullptr; for (const auto& g : graphs) { @@ -823,13 +819,9 @@ LV2Graph::LV2Graph(Parser::ResourceRecord record) Lib::Lib(const char* bundle_path) { ingen::set_bundle_path(bundle_path); - const std::string manifest_path = ingen::bundle_file_path("manifest.ttl"); - SerdNode manifest_node = serd_node_new_file_uri( - (const uint8_t*)manifest_path.c_str(), nullptr, nullptr, true); - - graphs = find_graphs(URI((const char*)manifest_node.buf)); - serd_node_free(&manifest_node); + const auto manifest_path = ingen::bundle_file_path("manifest.ttl"); + graphs = find_graphs(serd::make_file_uri(manifest_path.string())); } static void diff --git a/src/server/wscript b/src/server/wscript index 00588915..137b85c9 100644 --- a/src/server/wscript +++ b/src/server/wscript @@ -53,7 +53,7 @@ def build(bld): mix.cpp ''' - core_libs = 'LV2 LILV RAUL SERD SORD SRATOM' + core_libs = 'LV2 LILV RAUL SERD SRATOM' bld(features = 'cxx cxxshlib', source = core_source, |