aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/engine/Loader.cpp123
1 files changed, 55 insertions, 68 deletions
diff --git a/src/engine/Loader.cpp b/src/engine/Loader.cpp
index 2698491..070615a 100644
--- a/src/engine/Loader.cpp
+++ b/src/engine/Loader.cpp
@@ -34,6 +34,9 @@
using namespace Raul;
using namespace std;
+#define NS_MACHINA "http://drobilla.net/ns/machina#"
+#define NS_RDF "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+
namespace Machina {
@@ -53,8 +56,6 @@ Loader::Loader(Redland::World& rdf_world)
SharedPtr<Machine>
Loader::load(const Glib::ustring& uri)
{
- using Redland::Query;
- using Redland::QueryResults;
using Glib::ustring;
SharedPtr<Machine> machine;
@@ -82,74 +83,62 @@ Loader::load(const Glib::ustring& uri)
machine = SharedPtr<Machine>(new Machine(TimeUnit::beats(MACHINA_PPQN)));
- typedef std::map<string, SharedPtr<Node> > Created;
+ typedef std::map<Redland::Node, SharedPtr<Node> > Created;
Created created;
Redland::Model model(_rdf_world, document_uri);
- /* Get initial nodes */
+ Redland::Node nil;
- Query query = Query(_rdf_world, ustring(
- "SELECT DISTINCT ?node ?duration WHERE {\n") +
- machine_uri + " :initialNode ?node .\n"
- "?node :duration ?duration .\n"
- "}\n");
+ Redland::Resource rdf_type(_rdf_world, NS_RDF "type");
+ Redland::Resource machina_SelectorNode(_rdf_world, NS_MACHINA "initialNode");
+ Redland::Resource machina_node(_rdf_world, NS_MACHINA "node");
+ Redland::Resource machina_initialNode(_rdf_world, NS_MACHINA "initialNode");
+ Redland::Resource machina_duration(_rdf_world, NS_MACHINA "duration");
+ Redland::Resource machina_edge(_rdf_world, NS_MACHINA "edge");
+ Redland::Resource machina_tail(_rdf_world, NS_MACHINA "tail");
+ Redland::Resource machina_head(_rdf_world, NS_MACHINA "head");
+ Redland::Resource machina_probability(_rdf_world, NS_MACHINA "probability");
- SharedPtr<QueryResults> results = query.run(_rdf_world, model);
+ Redland::Node machine_node = Redland::Resource(_rdf_world, ".");
- for (; !results->finished(); results->next()) {
- const char* node_id = results->get("node");
+ /* Get initial nodes */
+ for (Redland::Iter i = model.find(machine_node, machina_initialNode, nil);
+ !i.end(); ++i) {
+ const Redland::Node& node_id = i.get_object();
+ Redland::Iter d = model.find(node_id, machina_duration, nil);
SharedPtr<Node> node(
new Node(
- TimeStamp(TimeUnit(TimeUnit::BEATS, MACHINA_PPQN), results->get("duration").to_float()),
+ TimeStamp(TimeUnit(TimeUnit::BEATS, MACHINA_PPQN),
+ d.get_object().to_float()),
true));
+
+ Redland::Iter s = model.find(node_id, rdf_type, machina_SelectorNode);
+ if (!s.end()) {
+ node->set_selector(true);
+ }
+
machine->add_node(node);
created[node_id] = node;
}
-
/* Get remaining (non-initial) nodes */
-
- query = Query(_rdf_world, ustring(
- "SELECT DISTINCT ?node ?duration WHERE {\n") +
- machine_uri + " :node ?node .\n"
- "?node :duration ?duration .\n"
- "}\n");
-
- results = query.run(_rdf_world, model);
-
- for (; !results->finished(); results->next()) {
- const char* node_id = results->get("node");
+ for (Redland::Iter i = model.find(machine_node, machina_node, nil);
+ !i.end(); ++i) {
+ const Redland::Node& node_id = i.get_object();
+ Redland::Iter d = model.find(node_id, machina_duration, nil);
if (created.find(node_id) == created.end()) {
SharedPtr<Node> node(new Node(
- TimeStamp(TimeUnit(TimeUnit::BEATS, MACHINA_PPQN), results->get("duration").to_float()),
+ TimeStamp(TimeUnit(TimeUnit::BEATS, MACHINA_PPQN),
+ d.get_object().to_float()),
false));
machine->add_node(node);
created[node_id] = node;
}
}
-
- /* Find out which nodes are selectors */
-
- query = Query(_rdf_world, ustring(
- "SELECT DISTINCT ?node WHERE {\n") +
- machine_uri + " :node ?node .\n"
- "?node a :SelectorNode .\n"
- "}\n");
-
- results = query.run(_rdf_world, model);
-
- for (; !results->finished(); results->next()) {
- const char* node_id = results->get("node");
- Created::iterator n = created.find(node_id);
- if (n != created.end())
- n->second->set_selector(true);
- else
- cerr << "WARNING: Selector node " << node_id << " not found" << endl;
- }
-
-
+#if 0
+ cerr << "FIXME: Load actions" << endl;
/* Get note actions */
query = Query(_rdf_world, ustring(
@@ -174,38 +163,36 @@ Loader::load(const Glib::ustring& uri)
cerr << "WARNING: Found note for unknown states. Ignoring." << endl;
}
}
-
+#endif
/* Get edges */
+ for (Redland::Iter i = model.find(machine_node, machina_edge, nil);
+ !i.end(); ++i) {
+ Redland::Node edge = i.get_object();
+ Redland::Iter t = model.find(edge, machina_tail, nil);
+ Redland::Iter h = model.find(edge, machina_head, nil);
+ Redland::Iter p = model.find(edge, machina_probability, nil);
- query = Query(_rdf_world, ustring(
- "SELECT DISTINCT ?edge ?src ?dst ?prob WHERE {\n" +
- machine_uri + " :edge ?edge .\n"
- "?edge :tail ?src ;\n"
- " :head ?dst ;\n"
- " :probability ?prob .\n }"));
+ Redland::Node tail = t.get_object();
+ Redland::Node head = h.get_object();
+ Redland::Node probability = p.get_object();
- results = query.run(_rdf_world, model);
-
- for (; !results->finished(); results->next()) {
- const char* src_uri = results->get("src");
- const char* dst_uri = results->get("dst");
- float prob = results->get("prob").to_float();
+ float prob = probability.to_float();
- Created::iterator src_i = created.find(src_uri);
- Created::iterator dst_i = created.find(dst_uri);
+ Created::iterator tail_i = created.find(tail);
+ Created::iterator head_i = created.find(head);
- if (src_i != created.end() && dst_i != created.end()) {
- const SharedPtr<Node> src = src_i->second;
- const SharedPtr<Node> dst = dst_i->second;
+ if (tail_i != created.end() && head_i != created.end()) {
+ const SharedPtr<Node> tail = tail_i->second;
+ const SharedPtr<Node> head = head_i->second;
- SharedPtr<Edge> edge(new Edge(src, dst));
+ SharedPtr<Edge> edge(new Edge(tail, head));
edge->set_probability(prob);
- src->add_edge(edge);
+ tail->add_edge(edge);
} else {
cerr << "[Loader] WARNING: Ignored edge between unknown nodes "
- << src_uri << " -> " << dst_uri << endl;
+ << tail << " -> " << head << endl;
}
}