summaryrefslogtreecommitdiff
path: root/NT
diff options
context:
space:
mode:
Diffstat (limited to 'NT')
-rw-r--r--NT/src/factory.cpp3
-rw-r--r--NT/src/factory.h4
-rw-r--r--NT/src/graph.cpp29
-rw-r--r--NT/src/graph.h1
-rw-r--r--NT/src/rendercontext.cpp35
-rw-r--r--NT/src/rendercontext.h2
-rw-r--r--NT/src/rotor.cpp11
-rw-r--r--NT/src/rotor.h34
8 files changed, 80 insertions, 39 deletions
diff --git a/NT/src/factory.cpp b/NT/src/factory.cpp
index 9706af7..b8f4642 100644
--- a/NT/src/factory.cpp
+++ b/NT/src/factory.cpp
@@ -3,7 +3,8 @@
using namespace Rotor;
using namespace std;
-Node_factory::Node_factory(){
+Node_factory::Node_factory(std::string _log_id){
+ log_id=_log_id;
//for now, statically load prototype map in constructor
add_type(new Time(),"nodes");
add_type(new Multiply(),"nodes");
diff --git a/NT/src/factory.h b/NT/src/factory.h
index 2938144..006db02 100644
--- a/NT/src/factory.h
+++ b/NT/src/factory.h
@@ -7,7 +7,7 @@
namespace Rotor {
class Node_factory{
public:
- Node_factory();
+ Node_factory(std::string _log_id=std::string("Rotor"));
~Node_factory(){
for (auto t:type_map) delete t.second;
}
@@ -20,6 +20,7 @@ namespace Rotor {
category_map[category].push_back(proto);
};
Node *create(Json::Value &settings){
+ settings["log_id"]=log_id;
if (type_map.find(settings["type"].asString())!=type_map.end()) {
return type_map[settings["type"].asString()]->clone(settings);
}
@@ -29,6 +30,7 @@ namespace Rotor {
void list_nodes(Json::Value &json);
void list_categories(Json::Value &json);
private:
+ std::string log_id;
std::map<std::string,Node*> type_map;
std::map<std::string,std::vector<Rotor::Node*> > category_map;
};
diff --git a/NT/src/graph.cpp b/NT/src/graph.cpp
index e671238..50db271 100644
--- a/NT/src/graph.cpp
+++ b/NT/src/graph.cpp
@@ -19,6 +19,7 @@ bool Graph::check_audio(string audio,string path){
return false;
}
bool Graph::load_file(std::string filename,std::string media_path){
+ Logger& logger = Logger::get(id);
Poco::File f=Poco::File(filename);
if (f.exists()) {
Poco::FileInputStream fis(filename);
@@ -27,7 +28,7 @@ bool Graph::load_file(std::string filename,std::string media_path){
Poco::StreamCopier::copyToString(countingIstr, str);
return parse_json(str,media_path);
}
- cerr<<"Rotor: graph "<<filename<<" not found"<<endl;
+ logger.error("Graph "+filename+" not found");
return false;
}
Node* Graph::find_node(const string &type){
@@ -36,20 +37,24 @@ Node* Graph::find_node(const string &type){
}
return nullptr;
};
+Node* Graph::get_node(const std::string &id){
+ if (nodes.find(id)!=nodes.end()) return nodes[id];
+ return nullptr;
+}
bool Graph::parse_json(string &data,string &media_path){
+ Logger& logger = Logger::get(id);
Json::Value root; // will contain the root value after parsing.
Json::Reader reader;
bool parsing_successful = reader.parse( data, root );
if ( !parsing_successful )
{
- std::cout << "Failed to parse configuration\n"
- << reader.getFormattedErrorMessages();
+ logger.error("Failed to parse configuration: "+reader.getFormattedErrorMessages());
return false;
}
//The json validates, now we should attempt to retain nodes which haven't changed
//for now just clear the existing graph
clear();
- Node_factory factory;
+ Node_factory factory(id);
check_audio(root["audio"].asString(),media_path);
init(root["id"].asString());
Json::Value jnodes = root["nodes"];
@@ -58,24 +63,14 @@ bool Graph::parse_json(string &data,string &media_path){
Node* node=factory.create(jnodes[i]);
if (node) {
if (nodes.find(node_id)==nodes.end()){
- cerr << "Rotor: creating node '"<<node_id<<"': '"<<jnodes[i]["type"].asString()<< "'" << endl;
- //kind of have to do the links from outside thus
- //how do deal with variable arrays?
- //
- //on our left.. an array of pointers to variables..
- //some of which contain arrays of pointers to variables
- //
- //on our right.. an unordered map of nodes to be linked to
- //
- //node.create_links(nodes)
- //will allow the nodes to be passed into each member of a variable array
+ logger.information("Creating node '"+node_id+"'': '"+jnodes[i]["type"].asString()+"'");
node->create_connections(nodes);
nodes[node_id]=node;
}
- else cerr << "ERROR: duplicate node '"<<node_id<<"' "<< endl;
+ else logger.error("ERROR: duplicate node '"+node_id+"' ");
}
else {
- cerr << "ERROR: graph loader cannot find node '" <<jnodes[i]["type"].asString()<< "'" << endl;
+ logger.error("ERROR: graph loader cannot find node '"+jnodes[i]["type"].asString()+"'");
return false;
}
}
diff --git a/NT/src/graph.h b/NT/src/graph.h
index 7aa0318..cef2fb8 100644
--- a/NT/src/graph.h
+++ b/NT/src/graph.h
@@ -48,6 +48,7 @@ namespace Rotor {
std::vector<Node*> find_nodes(const std::string &type);
Node* find_node(const std::string &type);
+ Node* get_node(const std::string &id);
//--context// Json::Value signal_render(const std::string &node,const double framerate);
//--context// bool video_render(const std::string &output_filename,const double framerate,int start, int end);
bool load_file(std::string filename,std::string media_path);
diff --git a/NT/src/rendercontext.cpp b/NT/src/rendercontext.cpp
index 8c6f970..ffc55ed 100644
--- a/NT/src/rendercontext.cpp
+++ b/NT/src/rendercontext.cpp
@@ -1 +1,34 @@
-#include "rendercontext.h" \ No newline at end of file
+#include "rendercontext.h"
+
+using namespace Rotor;
+using namespace std;
+
+string Render_context::text_render(string node_id){
+ Logger& logger = Logger::get(id);
+ Node* p;
+ if (node_id==""){
+ p=graph.find_node("print");
+ if (!p){
+ logger.error("text_render: Print node not found");
+ return "";
+ }
+ }
+ else {
+ p=graph.get_node(id);
+ if (!p){
+ logger.error("text_render: node '"+id+"' not found");
+ return "";
+ }
+ }
+ Node_type<string>* s=(dynamic_cast<Node_type<string>*>(p));
+ if (!s) {
+ logger.error("text_render: node '"+id+"' is not a text node");
+ return "";
+ }
+ string st="";
+ for (double t=0;t<10.0;t+=0.765){
+ Frame_parameters f=Frame_parameters(t,25.0,10.0,640,360);
+ st+=(dynamic_cast<Node_type<string>*>(p))->get_output(f)+"\n";
+ }
+ return st;
+} \ No newline at end of file
diff --git a/NT/src/rendercontext.h b/NT/src/rendercontext.h
index 10332df..6501c66 100644
--- a/NT/src/rendercontext.h
+++ b/NT/src/rendercontext.h
@@ -38,11 +38,11 @@ namespace Rotor {
logger.information("stopped thread");
}
void runTask() {
- Logger& logger = Logger::get(id);
while (!isCancelled()) {
sleep(100);
}
}
+ std::string text_render(std::string node_id="");
Graph graph;
private:
std::string id;
diff --git a/NT/src/rotor.cpp b/NT/src/rotor.cpp
index f600c7f..6380f28 100644
--- a/NT/src/rotor.cpp
+++ b/NT/src/rotor.cpp
@@ -13,6 +13,9 @@ string Variable::get_connection_id(){
if (connection) return connection->get_id();
return "";
}
+string Variable::get_name(){
+ return name;
+}
template <class T>
Json::Value Variable_type<T>::to_json(){
@@ -98,13 +101,7 @@ int main(){
//now need a way to grab output
- Node* p=r.graph.find_node("print");
+ printf("%s\n",r.text_render().c_str());
- if (p){
- for (double t=0;t<10.0;t+=0.765){
- Frame_parameters f=Frame_parameters(t,25.0,10.0,640,360);
- printf("%04f %s\n",t,(dynamic_cast<Node_type<string>*>(p))->get_output(f).c_str());
- }
- }
}
diff --git a/NT/src/rotor.h b/NT/src/rotor.h
index 5023a95..4a9eb70 100644
--- a/NT/src/rotor.h
+++ b/NT/src/rotor.h
@@ -7,6 +7,8 @@ ROTORD rewrite
TJR-Jan-2014
NB when plugging in to framework - convert all cerr messages to logged
+
+What next?
*/
#define ENABLE_TYPENAME(A) template<> struct TypeName<A> { static const char *Get() { return #A; }};
@@ -119,14 +121,15 @@ namespace Rotor {
virtual void init(Json::Value s)=0;
virtual bool connect(Node* target)=0;
virtual std::string get_type()=0;
- virtual void create_connection(std::unordered_map<std::string,Node*> &nodes)=0;
+ virtual bool create_connection(std::unordered_map<std::string,Node*> &nodes)=0;
bool is_connected(){
if (connection) return true;
return false;
}
std::string get_connection_id();
- std::string name;
+ std::string get_name();
protected:
+ std::string name;
Node* connection;
bool connectable;
std::string input;
@@ -144,16 +147,13 @@ namespace Rotor {
name=s["name"].asString();
input=s["input"].asString();
}
- void create_connection(std::unordered_map<std::string,Node*> &nodes){
+ bool create_connection(std::unordered_map<std::string,Node*> &nodes){
for (auto node:nodes){
if (node.first==input){
- if (connect(node.second)) {
- if (connection) std::cerr<<"connected '"<<TypeName<T>::Get()<<"' input to '"<<(dynamic_cast<Node_type<T>*>(connection))->get_type()<<"' "<<input<<std::endl;
- //else std::cerr<<"connection disappeared"<<std::endl;
- }
- //else std::cerr<<"could not connect '"<<TypeName<T>::Get()<<"'' input to '"<<input<<"'"<<std::endl;
+ if (connect(node.second)) return true;
}
}
+ return false;
}
Json::Value to_json();
std::string get_type(){ //need this to output node templates
@@ -199,11 +199,15 @@ namespace Rotor {
}
}
}
- void create_connection(std::unordered_map<std::string,Node*> &nodes){
+ bool create_connection(std::unordered_map<std::string,Node*> &nodes){
+ bool success=true;
//for (auto v:values){ //weirdly does not work even though it seems to! maybe it returns a copy of of the object?
// v.create_connection(nodes);
//}
- for (uint32_t i=0;i<values.size();i++) values[i].create_connection(nodes);
+ for (uint32_t i=0;i<values.size();i++) {
+ if (!values[i].create_connection(nodes)) success=false;
+ }
+ return success;
}
Json::Value to_json();
std::string get_type(){
@@ -271,7 +275,12 @@ namespace Rotor {
virtual Node* clone(Json::Value &_settings)=0;
virtual std::string get_output_type()=0;
void create_connections(std::unordered_map<std::string,Node*> &nodes){
- for (auto var:vars) var.second->create_connection(nodes);
+ Logger& logger = Logger::get(log_id);
+ for (auto var:vars) {
+ if (var.second->create_connection(nodes)) {
+ logger.information("Connected input '"+var.second->get_name()+"' of node '"+id+"' to node "+var.second->get_connection_id());
+ }
+ }
}
protected:
std::unordered_map<std::string,Variable*> vars;
@@ -281,6 +290,7 @@ namespace Rotor {
std::string description;
std::string title;
std::string ui_type;
+ std::string log_id;
};
template <class NT> class Node_type : public Node {
public:
@@ -288,10 +298,12 @@ namespace Rotor {
void init(Json::Value settings){
if (!settings["vars"].empty()){
for ( uint32_t i = 0; i < settings["vars"].size(); ++i ) {
+ if (!settings["id"].empty()) settings["vars"][i]["log_id"]=settings["log_id"].asString();
vars[settings["vars"][i]["name"].asString()]->init(settings["vars"][i]);
}
}
if (!settings["id"].empty()) id=settings["id"].asString();
+ if (!settings["log_id"].empty()) log_id=settings["log_id"].asString();
}
std::string get_output_type(){return TypeName<NT>::Get();};
template <class IT> Variable_type<IT>* create_inlet(std::string name){