summaryrefslogtreecommitdiff
path: root/NT/src/rotor.cpp
blob: eeffab9afd146cc305a73316ee5929e8dff4d12b (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include <stdio.h>

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

using namespace std;
using namespace Rotor;

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->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.connection?input.connection->id:"");
	}
	return json;
}
Json::Value Node::to_json(){
	Json::Value node;
	node["type"]=type;
	node["type_id"]=type_id;
	node["title"]=title;
	node["output_type"]=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());
/*
			string type=var.second->get_type();
			Json::Value newvar;
			newvar["type"]=var.second->get_type();
			newvar["name"]=var.second->name;
			newvar["connectable"]=var.second->connectable?"yes":"no";
			if (dynamic_cast<Variable_array*>(var.second)){
				newvar["input"]=Json::arrayValue;
				for (auto& input: dynamic_cast<Variable_array*>(var.second)->values) {
					newvar["input"].append(input.to_json());
				}
			}
			else {
				newvar["input"]=var.second->to_json();
			}
			node["vars"].append(newvar);
*/
		}
	}
/*
	if (_node->inputs.size()){
		node["signal_inputs"]=Json::arrayValue;
		for (auto& input: _node->inputs) {
			Json::Value signal_input;
			signal_input["title"]=input->title;
			signal_input["description"]=input->description;
			node["signal_inputs"].append(signal_input);
		}
	}
	if (dynamic_cast<Image_node*> (_node)!=nullptr) {
		if ((dynamic_cast<Image_node*>(_node))->image_inputs.size()){
			node["image_inputs"]=Json::arrayValue;
			for (auto& input: (dynamic_cast<Image_node*>(_node))->image_inputs) {
				Json::Value image_input;
				image_input["title"]=input->title;
				image_input["description"]=input->description;
				node["image_inputs"].append(image_input);
			}
		}
	}
	if (_node->parameters.size()){
		node["parameters"]=Json::arrayValue;
		for (auto& param: _node->parameters) {
			Json::Value parameter;
			parameter["name"]=param.first;
			parameter["type"]=param.second->type;
			parameter["title"]=param.second->title;
			parameter["description"]=param.second->description;
			parameter["value"]=param.second->value;
			parameter["min"]=param.second->min;
			parameter["max"]=param.second->max;
			parameter["step"]=param.second->step;
			node["parameters"].append(parameter);
		}
	}
	if (_node->attributes.size()){
		node["attributes"]=Json::arrayValue;
		for (auto& attr: _node->attributes) {
			Json::Value attribute;
			attribute["name"]=attr.first;
			attribute["title"]=attr.second->title;
			attribute["description"]=attr.second->description;
			if (attr.second->vals.size()){ //document attribute enumeration
				attribute["value"]=attr.second->value;
				attribute["type"]="enum";
				attribute["options"]=Json::arrayValue;
				for (auto val: attr.second->vals){
					attribute["options"].append(val);
				}
			}
			else {
				attribute["type"]=attr.second->type;
				if (attr.second->type=="array"){
					attribute["value"]=Json::arrayValue;
				}
				else attribute["value"]=attr.second->value;
			}
			node["attributes"].append(attribute);
		}
	}
*/
	return node;
}

//factory generates linker errors if rotor.h implementation is seperated: why?

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;
*/
Json::Value js;
f.list_node("multiply",js);
Json::StyledWriter writer;
cerr<<writer.write(js)<<endl;
f.list_node("print",js);
cerr<<writer.write(js)<<endl;
}