From 1f2bc21fd5ee9bff4fce190d7bb0ee4462e76e87 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Fri, 24 Jan 2014 17:00:22 +0000 Subject: logging in nodes and text_render proof of concept --- NT/src/factory.cpp | 3 ++- NT/src/factory.h | 4 +++- NT/src/graph.cpp | 29 ++++++++++++----------------- NT/src/graph.h | 1 + NT/src/rendercontext.cpp | 35 ++++++++++++++++++++++++++++++++++- NT/src/rendercontext.h | 2 +- NT/src/rotor.cpp | 11 ++++------- NT/src/rotor.h | 34 +++++++++++++++++++++++----------- 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 type_map; std::map > 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 "<create_connections(nodes); nodes[node_id]=node; } - else cerr << "ERROR: duplicate 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* s=(dynamic_cast*>(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*>(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 Json::Value Variable_type::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*>(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 { 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 &nodes)=0; + virtual bool create_connection(std::unordered_map &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 &nodes){ + bool create_connection(std::unordered_map &nodes){ for (auto node:nodes){ if (node.first==input){ - if (connect(node.second)) { - if (connection) std::cerr<<"connected '"<::Get()<<"' input to '"<<(dynamic_cast*>(connection))->get_type()<<"' "<::Get()<<"'' input to '"< &nodes){ + bool create_connection(std::unordered_map &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 &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 vars; @@ -281,6 +290,7 @@ namespace Rotor { std::string description; std::string title; std::string ui_type; + std::string log_id; }; template 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::Get();}; template Variable_type* create_inlet(std::string name){ -- cgit v1.2.3