diff options
| -rw-r--r-- | NT/NT.layout | 16 | ||||
| -rw-r--r-- | NT/src/graph.cpp | 12 | ||||
| -rw-r--r-- | NT/src/graph.h | 4 | ||||
| -rw-r--r-- | NT/src/nodes.h | 5 | ||||
| -rw-r--r-- | NT/src/rotor.cpp | 35 | ||||
| -rw-r--r-- | NT/src/rotor.h | 23 |
6 files changed, 62 insertions, 33 deletions
diff --git a/NT/NT.layout b/NT/NT.layout index 6d0700e..319c62d 100644 --- a/NT/NT.layout +++ b/NT/NT.layout @@ -1,14 +1,14 @@ <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <CodeBlocks_layout_file> <ActiveTarget name="Debug" /> - <File name="src/graph.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="-2" zoom_2="0"> + <File name="src/nodes.h" open="1" top="1" tabpos="4" split="0" active="1" splitpos="0" zoom_1="-2" zoom_2="0"> <Cursor> - <Cursor1 position="865" topLine="4" /> + <Cursor1 position="1197" topLine="19" /> </Cursor> </File> - <File name="src/rotor.cpp" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="-3" zoom_2="0"> + <File name="src/rotor.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="-2" zoom_2="0"> <Cursor> - <Cursor1 position="2357" topLine="32" /> + <Cursor1 position="3896" topLine="123" /> </Cursor> </File> <File name="src/factory.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> @@ -16,14 +16,14 @@ <Cursor1 position="722" topLine="0" /> </Cursor> </File> - <File name="src/rotor.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="-2" zoom_2="0"> + <File name="src/graph.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="-2" zoom_2="0"> <Cursor> - <Cursor1 position="6142" topLine="182" /> + <Cursor1 position="865" topLine="4" /> </Cursor> </File> - <File name="src/nodes.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="-2" zoom_2="0"> + <File name="src/rotor.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="-2" zoom_2="0"> <Cursor> - <Cursor1 position="459" topLine="0" /> + <Cursor1 position="2542" topLine="48" /> </Cursor> </File> </CodeBlocks_layout_file> diff --git a/NT/src/graph.cpp b/NT/src/graph.cpp index 87a7b87..65bd6c8 100644 --- a/NT/src/graph.cpp +++ b/NT/src/graph.cpp @@ -29,6 +29,12 @@ bool Graph::load_file(std::string filename,std::string media_path){ cerr<<"Rotor: graph "<<filename<<" not found"<<endl; return false; } +Node* Graph::find_node(const string &type){ + for (std::unordered_map<string,Node*>::iterator it=nodes.begin();it!=nodes.end();++it) { + if (it->second->get_type()==type) return it->second; + } + return nullptr; +}; bool Graph::parse_json(string &data,string &media_path){ Json::Value root; // will contain the root value after parsing. Json::Reader reader; @@ -62,8 +68,9 @@ bool Graph::parse_json(string &data,string &media_path){ // //node.create_links(nodes) //will allow the nodes to be passed into each member of a variable array - node->create_connections(nodes); nodes[node_id]=node; + nodes[node_id]->create_connections(nodes); + } else cerr << "ERROR: duplicate node '"<<node_id<<"' "<< endl; } @@ -74,3 +81,6 @@ bool Graph::parse_json(string &data,string &media_path){ } return true; } + +//should nodes be identified by uuid rather than name? +//array inlets can be identified by number as this is all they usually are diff --git a/NT/src/graph.h b/NT/src/graph.h index 05eaa04..76a4c1c 100644 --- a/NT/src/graph.h +++ b/NT/src/graph.h @@ -42,6 +42,10 @@ namespace Rotor { nodes.clear(); loaded=false; } + //how to do output? + //think video_render should be part of render context + //graph should just encapsulate the manipulation of the graph + //specific nodes can be created as output targets std::string uid; std::string description; std::unordered_map<std::string,Node*> nodes; diff --git a/NT/src/nodes.h b/NT/src/nodes.h index 4b1b2ac..0f885da 100644 --- a/NT/src/nodes.h +++ b/NT/src/nodes.h @@ -45,7 +45,10 @@ namespace Rotor{ }; const double &get_output(const Frame_parameters &frame){ result=1.0f; - for (auto var:factors->get_values()) result*=var.get(frame); + for (auto val:factors->get_values()) { + std::cerr<<"got value: "<<val.get(frame)<<std::endl; + result*=val.get(frame); + } return result; } Multiply* clone(Json::Value &_settings) { return new Multiply(_settings);}; diff --git a/NT/src/rotor.cpp b/NT/src/rotor.cpp index d280029..bf0c26a 100644 --- a/NT/src/rotor.cpp +++ b/NT/src/rotor.cpp @@ -82,17 +82,28 @@ int main(){ delete m; delete p; */ -Rotor::Graph g; -cerr<<(g.load_file("testgraph.json","./")?"loaded ":"could not load ")<<"testgraph.json"<<endl; -/* -Json::Value js; -f.list_node("time",js); -Json::StyledWriter writer; -cerr<<writer.write(js)<<endl; -f.list_node("multiply",js); -cerr<<writer.write(js)<<endl; -f.list_node("print",js); -cerr<<writer.write(js)<<endl; -*/ + Rotor::Graph g; + cerr<<(g.load_file("testgraph.json","./")?"loaded ":"could not load ")<<"testgraph.json"<<endl; + /* + Json::Value js; + f.list_node("time",js); + Json::StyledWriter writer; + cerr<<writer.write(js)<<endl; + f.list_node("multiply",js); + cerr<<writer.write(js)<<endl; + f.list_node("print",js); + cerr<<writer.write(js)<<endl; + */ + + //now need a way to grab output + + Node* p=g.find_node("print"); + + 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 0a016a2..96a89ef 100644 --- a/NT/src/rotor.h +++ b/NT/src/rotor.h @@ -89,7 +89,9 @@ namespace Rotor { }; class Variable { //pure virtual base type for variable pointers public: - Variable(){connection=nullptr;}; + Variable(){ + connection=nullptr; + }; virtual ~Variable(){}; virtual Json::Value to_json()=0; virtual void init(Json::Value s)=0; @@ -109,7 +111,11 @@ namespace Rotor { }; template <class T> class Variable_type : public Variable { public: - Variable_type(std::string _name="",std::string _input="",bool _connectable=true){name=_name;input=_input;connectable=_connectable;}; + Variable_type(std::string _name="",std::string _input="",bool _connectable=true){ + name=_name; + input=_input; + connectable=_connectable; + }; void init(Json::Value s){ std::istringstream cur(s["value"].asString()); cur >> value; @@ -131,7 +137,7 @@ namespace Rotor { return TypeName<T>::Get(); } //have to cast connect and get_output to use templated return types - bool connect(Node* target){ + bool connect(Node* target){ if (connectable){ if (dynamic_cast<Node_type<T>*>(target)){ connection=target; @@ -143,7 +149,7 @@ namespace Rotor { const T& get(const Frame_parameters &frame){ if (connection){ return (dynamic_cast<Node_type<T>*>(connection))->get_output(frame); - } + } return value; } protected: @@ -175,13 +181,8 @@ namespace Rotor { std::string get_type(){ return TypeName<T>::Get(); } - bool connect(Node* target){ - if (connectable){ - if (dynamic_cast<Node_type<T>*>(target)){ - connection=target; - return true; - } - } + bool connect(Node* target){ + //array does not connect this way return false; } void add(std::string _name,std::string _input,bool _connectable=true){ |
