diff options
Diffstat (limited to 'src/engine/Loader.cpp')
-rw-r--r-- | src/engine/Loader.cpp | 72 |
1 files changed, 38 insertions, 34 deletions
diff --git a/src/engine/Loader.cpp b/src/engine/Loader.cpp index 1ce8fae..1a85e29 100644 --- a/src/engine/Loader.cpp +++ b/src/engine/Loader.cpp @@ -69,27 +69,27 @@ Loader::load(const Glib::ustring& uri) cout << "[Loader] Loading " << document_uri << endl; machine = SharedPtr<Machine>( - new Machine(TimeUnit::beats(MACHINA_PPQN))); + new Machine(TimeUnit::beats(MACHINA_PPQN))); typedef std::map<Sord::Node, SharedPtr<Node> > Created; Created created; Sord::Model model(_rdf_world, document_uri); - SerdEnv* env = serd_env_new(NULL); + SerdEnv* env = serd_env_new(NULL); model.load_file(env, SERD_TURTLE, document_uri); serd_env_free(env); Sord::Node nil; - Sord::URI rdf_type(_rdf_world, NS_RDF "type"); + Sord::URI rdf_type(_rdf_world, NS_RDF "type"); Sord::URI machina_SelectorNode(_rdf_world, NS_MACHINA "initialNode"); - Sord::URI machina_node(_rdf_world, NS_MACHINA "node"); - Sord::URI machina_initialNode(_rdf_world, NS_MACHINA "initialNode"); - Sord::URI machina_duration(_rdf_world, NS_MACHINA "duration"); - Sord::URI machina_edge(_rdf_world, NS_MACHINA "edge"); - Sord::URI machina_tail(_rdf_world, NS_MACHINA "tail"); - Sord::URI machina_head(_rdf_world, NS_MACHINA "head"); - Sord::URI machina_probability(_rdf_world, NS_MACHINA "probability"); + Sord::URI machina_node(_rdf_world, NS_MACHINA "node"); + Sord::URI machina_initialNode(_rdf_world, NS_MACHINA "initialNode"); + Sord::URI machina_duration(_rdf_world, NS_MACHINA "duration"); + Sord::URI machina_edge(_rdf_world, NS_MACHINA "edge"); + Sord::URI machina_tail(_rdf_world, NS_MACHINA "tail"); + Sord::URI machina_head(_rdf_world, NS_MACHINA "head"); + Sord::URI machina_probability(_rdf_world, NS_MACHINA "probability"); Sord::Node machine_node = Sord::URI(_rdf_world, "."); @@ -97,12 +97,12 @@ Loader::load(const Glib::ustring& uri) for (Sord::Iter i = model.find(machine_node, machina_initialNode, nil); !i.end(); ++i) { const Sord::Node& node_id = i.get_object(); - Sord::Iter d = model.find(node_id, machina_duration, nil); - SharedPtr<Node> node( + Sord::Iter d = model.find(node_id, machina_duration, nil); + SharedPtr<Node> node( new Node( - TimeStamp(TimeUnit(TimeUnit::BEATS, MACHINA_PPQN), - d.get_object().to_float()), - true)); + TimeStamp(TimeUnit(TimeUnit::BEATS, MACHINA_PPQN), + d.get_object().to_float()), + true)); Sord::Iter s = model.find(node_id, rdf_type, machina_SelectorNode); if (!s.end()) { @@ -117,12 +117,12 @@ Loader::load(const Glib::ustring& uri) for (Sord::Iter i = model.find(machine_node, machina_node, nil); !i.end(); ++i) { const Sord::Node& node_id = i.get_object(); - Sord::Iter d = model.find(node_id, machina_duration, nil); + Sord::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), - d.get_object().to_float()), - false)); + TimeStamp(TimeUnit(TimeUnit::BEATS, MACHINA_PPQN), + d.get_object().to_float()), + false)); machine->add_node(node); created[node_id] = node; } @@ -133,25 +133,30 @@ Loader::load(const Glib::ustring& uri) /* Get note actions */ query = Query(_rdf_world, ustring( - "SELECT DISTINCT ?node ?note WHERE {\n" - " ?node :enterAction [ a :MidiAction; :midiNote ?note ] ;\n" - " :exitAction [ a :MidiAction; :midiNote ?note ] .\n" - "}\n")); + "SELECT DISTINCT ?node ?note WHERE {\n" + " ?node :enterAction [ a :MidiAction; :midiNote ?note ] ;\n" + " :exitAction [ a :MidiAction; :midiNote ?note ] .\n" + "}\n")); results = query.run(_rdf_world, model); for (; !results->finished(); results->next()) { - Created::iterator node_i = created.find((const char*)results->get("node")); + Created::iterator node_i + = created.find((const char*)results->get("node")); if (node_i != created.end()) { - SharedPtr<Node> node = node_i->second; - const int note_num = results->get("note").to_int(); + SharedPtr<Node> node = node_i->second; + const int note_num = results->get("note").to_int(); if (note_num >= 0 && note_num <= 127) { - node->set_enter_action(ActionFactory::note_on((unsigned char)note_num)); - node->set_exit_action(ActionFactory::note_off((unsigned char)note_num)); + node->set_enter_action( + ActionFactory::note_on((uint8_t)note_num)); + node->set_exit_action( + ActionFactory::note_off((uint8_t)note_num)); } else { - cerr << "WARNING: MIDI note number out of range, ignoring." << endl; + cerr << "WARNING: MIDI note number out of range, ignoring." + << endl; } } else { - cerr << "WARNING: Found note for unknown states. Ignoring." << endl; + cerr << "WARNING: Found note for unknown states. Ignoring." + << endl; } } #endif @@ -173,7 +178,7 @@ Loader::load(const Glib::ustring& uri) Created::iterator tail_i = created.find(tail); Created::iterator head_i = created.find(head); - if (tail_i != created.end() && head_i != created.end()) { + if (( tail_i != created.end()) && ( head_i != created.end()) ) { const SharedPtr<Node> tail = tail_i->second; const SharedPtr<Node> head = head_i->second; @@ -183,12 +188,12 @@ Loader::load(const Glib::ustring& uri) } else { cerr << "[Loader] WARNING: Ignored edge between unknown nodes " - << tail << " -> " << head << endl; + << tail << " -> " << head << endl; } } - if (machine && machine->nodes().size() > 0) { + if (machine && ( machine->nodes().size() > 0) ) { machine->reset(NULL, machine->time()); return machine; } else { @@ -197,4 +202,3 @@ Loader::load(const Glib::ustring& uri) } } // namespace Machina - |