summaryrefslogtreecommitdiff
path: root/NT/src/rotor.cpp
blob: 5f7582618aa0a61c0163521d7b1deda78cd74e3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <stdio.h>

#include "rotor.h"
#include "factory.h"
#include "nodes.h"
#include "graph.h"
#include "rendercontext.h"

using namespace std;
using namespace Rotor;

std::istream& operator>> (std::istream &in, Rotor::Enum &en)
{
    in >> en.value;
    return in;
};

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(){
	Json::Value json;
	json["type"]=get_type();
	json["name"]=name;
	json["connectable"]=connectable?"yes":"no";
	json["input"]=connection?connection->get_id():"";
	return json;
}

template <class T>
Json::Value Variable_array_type<T>::to_json(){
	Json::Value json;
	json["type"]=get_type();
	json["name"]=name;
	json["connectable"]=connectable?"yes":"no";
	json["input"]=Json::arrayValue;
	for (auto& input: values) {
		json["input"].append(input.is_connected()?input.get_connection_id():"");
	}
	return json;
}

//explicit template instantiation to avoid linker errors
template class Variable_type<int>;
template class Variable_type<double>;
template class Variable_type<string>;

template class Variable_array_type<double>;


Json::Value Node::to_json(){
	Json::Value node;
	node["type"]=type;
	node["type_id"]=type_id;
	node["title"]=title;
	node["output_type"]=get_output_type();
	node["description"]=description;
	node["id"]=id;
	node["ui_type"]=ui_type;
	if (vars.size()){
		node["vars"]=Json::arrayValue;
		for (auto& var: vars) {
			node["vars"].append(var.second->to_json());
		}
	}
	return node;
};



//int main(){
//	Node_factory f;
/*
	map<string,string> settings={{"node_type","time"}};
	Node *t=f.create(settings);
	settings={{"value","2"},{"node_type","multiply"}};
	Node *m=f.create(settings);
	if (!m->connect("inlet",t)) printf("not connected...\n");
	settings={{"node_type","print"}};
	Node *p=f.create(settings);
	if (!p->connect("inlet",m)) printf("not connected...\n");
	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());
	}
	delete t;
	delete m;
	delete p;
*/
//	Rotor::Render_context r("dbbbb4ba-8430-11e3-9774-74d02b29f6a6");
//	cerr<<(r.graph.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

//	printf("%s\n",r.text_render().c_str());

//}