summaryrefslogtreecommitdiff
path: root/NT/src
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2014-01-14 17:00:14 +0000
committerTim Redfern <tim@eclectronics.org>2014-01-14 17:00:14 +0000
commit874194d055d0c90a7874a06be95ca2e087616a9d (patch)
tree1ca94dde41b6046960475b2091d2b35043a161a5 /NT/src
parent52710ced0e723117afa2d40f3b21e1fa2d1ad2ad (diff)
converting settings initiaiers to json
Diffstat (limited to 'NT/src')
-rw-r--r--NT/src/factory.cpp10
-rw-r--r--NT/src/factory.h8
-rw-r--r--NT/src/nodes.h21
-rw-r--r--NT/src/rotor.cpp6
-rw-r--r--NT/src/rotor.h26
5 files changed, 46 insertions, 25 deletions
diff --git a/NT/src/factory.cpp b/NT/src/factory.cpp
index dd39533..c02bcee 100644
--- a/NT/src/factory.cpp
+++ b/NT/src/factory.cpp
@@ -9,6 +9,7 @@ Node_factory::Node_factory(){
add_type(new Multiply(),"nodes");
add_type(new Print(),"nodes");
}
+/*
bool Node_factory::list_node(const string &t,xmlIO XML){
for (auto& type: type_map) {
if (type.first==t) {
@@ -19,6 +20,7 @@ bool Node_factory::list_node(const string &t,xmlIO XML){
XML.addValue("error","Node /"+t+"/ not found");
return false;
};
+*/
bool Node_factory::list_node(const string &t,Json::Value &JSON){
for (auto& type: type_map) {
if (type.first==t) {
@@ -30,7 +32,7 @@ bool Node_factory::list_node(const string &t,Json::Value &JSON){
return false;
};
-
+/*
void Node_factory::list_node(Rotor::Node* type,xmlIO XML,int i){
XML.addTag("node");
XML.addAttribute("node","output_type",type->output_type(),i);
@@ -40,7 +42,7 @@ void Node_factory::list_node(Rotor::Node* type,xmlIO XML,int i){
XML.addAttribute("node","node_id",type->node_id,i);
XML.addAttribute("node","ui_type",type->ui_type,i);
XML.pushTag("node",i);
-/*
+
//if (type->description!="") {
// XML.addTag("description");
// XML.setValue("description",type->description,0);
@@ -103,6 +105,8 @@ void Node_factory::list_node(Rotor::Node* type,xmlIO XML,int i){
}
j++;
}
-*/
+
XML.popTag();
}
+
+*/
diff --git a/NT/src/factory.h b/NT/src/factory.h
index 88e166f..ae8ddc4 100644
--- a/NT/src/factory.h
+++ b/NT/src/factory.h
@@ -13,7 +13,7 @@ namespace Rotor {
for (auto t:type_map) delete t.second;
}
void add_type(Node* proto){
- type_map[proto->node_type]=proto;
+ type_map[proto->type]=proto;
};
void add_type(Node* proto,std::string category){
add_type(proto);
@@ -21,9 +21,9 @@ namespace Rotor {
category_map[category].push_back(proto);
};
Node *create(std::map<std::string,std::string> &settings){
- if (settings.find("node_type")!=settings.end()) {
- if (type_map.find(settings["node_type"])!=type_map.end()) {
- return type_map[settings["node_type"]]->clone(settings);
+ if (settings.find("type")!=settings.end()) {
+ if (type_map.find(settings["type"])!=type_map.end()) {
+ return type_map[settings["type"]]->clone(settings);
}
}
return NULL;
diff --git a/NT/src/nodes.h b/NT/src/nodes.h
index ddb1a3d..ede81eb 100644
--- a/NT/src/nodes.h
+++ b/NT/src/nodes.h
@@ -12,7 +12,7 @@ namespace Rotor{
};
class Time: public Double_node {
public:
- Time(){node_type="time";};
+ Time(){type="time";};
Time(map<string,string> &settings):Time() {
init(settings);
};
@@ -27,21 +27,24 @@ namespace Rotor{
class Multiply: public Double_node {
public:
Multiply(){
- inlets=create_array<double>("inlet");
- value=create_inlet<double>("value");
- node_type="multiply";
+ factors=create_array<double>("factors");
+ type="multiply";
+ description="multiplies numbers";
+ title="Multiply";
+ type_id="11c67850-7ce4-11e3-abf6-930ef8613c46";
+ ui_type="none";
}
Multiply(map<string,string> &settings):Multiply() {
init(settings);
};
const double &get_output(const Frame_parameters &frame){
- result=inlets->get(0,frame)*value->get(frame);
- return result;
+ double val=1.0f;
+ for (auto var:factors->values) val*=var.get(frame);
+ return val;
}
Multiply* clone(map<string,string> &_settings) { return new Multiply(_settings);};
private:
- Variable_array_type<double> *inlets;
- Variable_type<double> *value;
+ Variable_array_type<double> *factors;
double result;
};
class String_node: public Node_type<string> {
@@ -52,7 +55,7 @@ namespace Rotor{
public:
Print(){
inlet=create_inlet<double>("inlet");
- node_type="print";
+ type="print";
}
Print(map<string,string> &settings):Print() {
init(settings);
diff --git a/NT/src/rotor.cpp b/NT/src/rotor.cpp
index 33d52ad..96e4250 100644
--- a/NT/src/rotor.cpp
+++ b/NT/src/rotor.cpp
@@ -9,11 +9,12 @@ using namespace Rotor;
Json::Value Node::list_json(){
Json::Value node;
- node["node_type"]=node_type;
+ node["type"]=type;
+ node["type_id"]=type_id;
node["title"]=title;
node["output_type"]=output_type();
node["description"]=description;
- node["node_id"]=node_id;
+ node["id"]=id;
node["ui_type"]=ui_type;
if (vars.size()){
@@ -22,6 +23,7 @@ Json::Value Node::list_json(){
string type=var.second->get_type();
Json::Value newvar;
newvar["type"]=type;
+ newvar["name"]=name;
newvar["connectable"]=var.second->connectable?"yes":"no";
if (dynamic_cast<Variable_array*>(var.second)){
newvar["input"]=Json::arrayValue;
diff --git a/NT/src/rotor.h b/NT/src/rotor.h
index d261954..30b4ba1 100644
--- a/NT/src/rotor.h
+++ b/NT/src/rotor.h
@@ -30,7 +30,7 @@ struct TypeName<int> {
template <>
struct TypeName<double> {
static const char* Get() {
- return "double";
+ return "number";
}
};
@@ -71,23 +71,26 @@ namespace Rotor {
class Variable { //pure virtual base type for variable pointers
public:
Variable(){connection=nullptr;};
- virtual void init(std::string s)=0;
+ virtual void init(std::string n,std::string s)=0;
virtual ~Variable(){};
virtual bool connect(Node* target)=0;
virtual std::string get_type()=0;
Node* connection;
bool connectable;
+ std::string name;
};
template <class T> class Variable_type : public Variable {
public:
Variable_type(bool _c){connectable=_c;};
- void init(std::string s){
+ void init(std::string n,std::string s){
std::istringstream cur(s);
cur >> value;
+ name=n;
}
std::string get_type(){ //need this to output node templates
return TypeName<T>::Get();
}
+//have to cast connect and get_output to use templated return types
bool connect(Node* target){
if (connectable){
if (dynamic_cast<Node_type<T>*>(target)){
@@ -112,10 +115,11 @@ namespace Rotor {
};
template <class T> class Variable_array_type: public Variable_array {
public:
- Variable_array_type(){};
- void init(std::string s){
+ Variable_array_type(){connectable=true;};
+ void init(std::string n,std::string s){
std::istringstream cur(s);
cur >> value;
+ name=n;
}
std::string get_type(){ //need this to output node templates
return TypeName<T>::Get();
@@ -176,9 +180,9 @@ namespace Rotor {
Json::Value list_json();
virtual Node* clone(std::map<std::string,std::string> &_settings)=0;
virtual std::string output_type()=0;
- std::string node_type;
- std::string node_id;
+ std::string type;
std::string id;
+ std::string type_id;
std::string description;
std::string title;
std::string ui_type;
@@ -195,6 +199,14 @@ namespace Rotor {
}
}
}
+ void init(Json::Value settings){
+ for (auto s:settings["input"].Members) {
+ if (vars.find(s.first)!=vars.end()){
+ vars[s.first]->init(s.second);
+ //printf("set %s to %s\n",s.first.c_str(),s.second.c_str());
+ }
+ }
+ }
std::string output_type(){return TypeName<NT>::Get();};
template <class IT> Variable_type<IT>* create_inlet(std::string name){
vars[name]=new Variable_type<IT>(true);